2014-02-27 02:44:00 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
2014-03-10 17:38:53 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2014-03-13 19:08:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Dlna;
|
2014-02-27 02:44:00 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Controller.Session;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-03-10 17:38:53 +00:00
|
|
|
|
using System;
|
2014-02-27 02:44:00 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Dlna.PlayTo
|
|
|
|
|
{
|
|
|
|
|
public class PlayToServerEntryPoint : IServerEntryPoint
|
|
|
|
|
{
|
2014-03-13 19:08:02 +00:00
|
|
|
|
private PlayToManager _manager;
|
2014-03-10 17:38:53 +00:00
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
|
private readonly IHttpClient _httpClient;
|
|
|
|
|
private readonly IItemRepository _itemRepo;
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly INetworkManager _networkManager;
|
|
|
|
|
private readonly IUserManager _userManager;
|
2014-03-13 19:08:02 +00:00
|
|
|
|
private readonly IDlnaManager _dlnaManager;
|
2014-02-27 18:00:49 +00:00
|
|
|
|
|
2014-03-13 19:08:02 +00:00
|
|
|
|
public PlayToServerEntryPoint(ILogManager logManager, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepo, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager)
|
2014-02-27 02:44:00 +00:00
|
|
|
|
{
|
2014-03-10 17:38:53 +00:00
|
|
|
|
_config = config;
|
|
|
|
|
_sessionManager = sessionManager;
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
_itemRepo = itemRepo;
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_networkManager = networkManager;
|
|
|
|
|
_userManager = userManager;
|
2014-03-13 19:08:02 +00:00
|
|
|
|
_dlnaManager = dlnaManager;
|
2014-03-10 17:38:53 +00:00
|
|
|
|
_logger = logManager.GetLogger("PlayTo");
|
2014-02-27 02:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-27 18:00:49 +00:00
|
|
|
|
public void Run()
|
2014-02-27 02:44:00 +00:00
|
|
|
|
{
|
2014-03-10 17:38:53 +00:00
|
|
|
|
_config.ConfigurationUpdated += ConfigurationUpdated;
|
2014-03-13 14:54:11 +00:00
|
|
|
|
|
2014-03-10 17:38:53 +00:00
|
|
|
|
ReloadPlayToManager();
|
2014-02-27 02:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-10 17:38:53 +00:00
|
|
|
|
void ConfigurationUpdated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ReloadPlayToManager();
|
|
|
|
|
}
|
2014-02-27 02:44:00 +00:00
|
|
|
|
|
2014-03-10 17:38:53 +00:00
|
|
|
|
private void ReloadPlayToManager()
|
|
|
|
|
{
|
|
|
|
|
var isStarted = _manager != null;
|
|
|
|
|
|
|
|
|
|
if (_config.Configuration.DlnaOptions.EnablePlayTo && !isStarted)
|
|
|
|
|
{
|
|
|
|
|
StartPlayToManager();
|
|
|
|
|
}
|
|
|
|
|
else if (!_config.Configuration.DlnaOptions.EnablePlayTo && isStarted)
|
|
|
|
|
{
|
|
|
|
|
DisposePlayToManager();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly object _syncLock = new object();
|
|
|
|
|
private void StartPlayToManager()
|
|
|
|
|
{
|
|
|
|
|
lock (_syncLock)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-03-13 19:08:02 +00:00
|
|
|
|
_manager = new PlayToManager(_logger, _config, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager, _dlnaManager);
|
2014-03-10 17:38:53 +00:00
|
|
|
|
_manager.Start();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error starting PlayTo manager", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposePlayToManager()
|
2014-02-27 02:44:00 +00:00
|
|
|
|
{
|
2014-03-10 17:38:53 +00:00
|
|
|
|
lock (_syncLock)
|
2014-02-27 02:44:00 +00:00
|
|
|
|
{
|
2014-03-10 17:38:53 +00:00
|
|
|
|
if (_manager != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_manager.Stop();
|
|
|
|
|
_manager.Dispose();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Error disposing PlayTo manager", ex);
|
|
|
|
|
}
|
|
|
|
|
_manager = null;
|
|
|
|
|
}
|
2014-02-27 02:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-10 17:38:53 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
DisposePlayToManager();
|
|
|
|
|
}
|
2014-02-27 02:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|