2014-07-18 00:39:07 +00:00
|
|
|
|
using MediaBrowser.Controller.Channels;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-18 19:07:28 +00:00
|
|
|
|
using MediaBrowser.Dlna.PlayTo;
|
|
|
|
|
using MediaBrowser.Dlna.Ssdp;
|
2014-07-18 00:39:07 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-18 19:07:28 +00:00
|
|
|
|
using MediaBrowser.Model.Events;
|
|
|
|
|
using System;
|
2014-07-18 00:39:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-07-18 19:07:28 +00:00
|
|
|
|
using System.Linq;
|
2014-07-18 00:39:07 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Dlna.Channels
|
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
public class DlnaChannelFactory : IChannelFactory, IDisposable
|
2014-07-18 00:39:07 +00:00
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
private DeviceDiscovery _deviceDiscovery;
|
|
|
|
|
|
|
|
|
|
private readonly object _syncLock = new object();
|
|
|
|
|
private readonly List<Device> _servers = new List<Device>();
|
|
|
|
|
|
|
|
|
|
public static DlnaChannelFactory Instance;
|
|
|
|
|
|
|
|
|
|
public DlnaChannelFactory()
|
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Start(DeviceDiscovery deviceDiscovery)
|
|
|
|
|
{
|
|
|
|
|
_deviceDiscovery = deviceDiscovery;
|
|
|
|
|
deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deviceDiscovery_DeviceDiscovered(object sender, GenericEventArgs<DeviceDiscoveryInfo> e)
|
|
|
|
|
{
|
|
|
|
|
var usn = e.Argument.Usn;
|
|
|
|
|
var nt = e.Argument.Nt;
|
|
|
|
|
|
|
|
|
|
// It has to report that it's a media renderer
|
|
|
|
|
if (usn.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 &&
|
|
|
|
|
nt.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_servers.Any(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock (_syncLock)
|
|
|
|
|
{
|
|
|
|
|
_servers.Add(e.Argument.Device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 00:39:07 +00:00
|
|
|
|
public IEnumerable<IChannel> GetChannels()
|
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
return _servers.Select(i => new ServerChannel(i)).ToList();
|
|
|
|
|
}
|
2014-07-18 00:39:07 +00:00
|
|
|
|
|
2014-07-18 19:07:28 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (_deviceDiscovery != null)
|
2014-07-18 00:39:07 +00:00
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
_deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered;
|
|
|
|
|
}
|
2014-07-18 00:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-18 19:07:28 +00:00
|
|
|
|
public class ServerChannel : IChannel, IFactoryChannel
|
2014-07-18 00:39:07 +00:00
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
private readonly Device _device;
|
2014-07-18 00:39:07 +00:00
|
|
|
|
|
2014-07-18 19:07:28 +00:00
|
|
|
|
public ServerChannel(Device device)
|
2014-07-18 00:39:07 +00:00
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
_device = device;
|
2014-07-18 00:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
get { return _device.Properties.Name; }
|
2014-07-18 00:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Description
|
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
get { return _device.Properties.ModelDescription; }
|
2014-07-18 00:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string DataVersion
|
|
|
|
|
{
|
|
|
|
|
get { return "1"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string HomePageUrl
|
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
get { return _device.Properties.ModelUrl; }
|
2014-07-18 00:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChannelParentalRating ParentalRating
|
|
|
|
|
{
|
|
|
|
|
get { return ChannelParentalRating.GeneralAudience; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public InternalChannelFeatures GetChannelFeatures()
|
|
|
|
|
{
|
|
|
|
|
return new InternalChannelFeatures
|
|
|
|
|
{
|
2014-07-18 19:07:28 +00:00
|
|
|
|
|
2014-07-18 00:39:07 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsEnabledFor(string userId)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(new ChannelItemResult());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(new DynamicImageResponse());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ImageType> GetSupportedChannelImages()
|
|
|
|
|
{
|
|
|
|
|
return new List<ImageType>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|