fixed dlna port

This commit is contained in:
Luke Pulverenti 2014-03-17 00:25:11 -04:00
parent f1acaaee3e
commit f12d8b0c18
5 changed files with 42 additions and 27 deletions

View File

@ -25,5 +25,11 @@ namespace MediaBrowser.Controller
/// </summary>
/// <value><c>true</c> if [supports automatic run at startup]; otherwise, <c>false</c>.</value>
bool SupportsAutoRunAtStartup { get; }
/// <summary>
/// Gets the HTTP server port.
/// </summary>
/// <value>The HTTP server port.</value>
int HttpServerPort { get; }
}
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
@ -13,7 +14,6 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using Timer = System.Timers.Timer;
namespace MediaBrowser.Dlna.PlayTo
{
@ -29,8 +29,11 @@ namespace MediaBrowser.Dlna.PlayTo
private readonly ILogger _logger;
private readonly IDlnaManager _dlnaManager;
private readonly IUserManager _userManager;
private readonly IServerApplicationHost _appHost;
private bool _playbackStarted = false;
private int UpdateTimerIntervalMs = 1000;
public bool SupportsMediaRemoteControl
{
get { return true; }
@ -47,7 +50,7 @@ namespace MediaBrowser.Dlna.PlayTo
}
}
public PlayToController(SessionInfo session, ISessionManager sessionManager, IItemRepository itemRepository, ILibraryManager libraryManager, ILogger logger, INetworkManager networkManager, IDlnaManager dlnaManager, IUserManager userManager)
public PlayToController(SessionInfo session, ISessionManager sessionManager, IItemRepository itemRepository, ILibraryManager libraryManager, ILogger logger, INetworkManager networkManager, IDlnaManager dlnaManager, IUserManager userManager, IServerApplicationHost appHost)
{
_session = session;
_itemRepository = itemRepository;
@ -56,6 +59,7 @@ namespace MediaBrowser.Dlna.PlayTo
_networkManager = networkManager;
_dlnaManager = dlnaManager;
_userManager = userManager;
_appHost = appHost;
_logger = logger;
}
@ -66,14 +70,12 @@ namespace MediaBrowser.Dlna.PlayTo
_device.CurrentIdChanged += Device_CurrentIdChanged;
_device.Start();
_updateTimer = new Timer(1000);
_updateTimer.Elapsed += updateTimer_Elapsed;
_updateTimer.Start();
_updateTimer = new System.Threading.Timer(updateTimer_Elapsed, null, UpdateTimerIntervalMs, UpdateTimerIntervalMs);
}
#region Device EventHandlers & Update Timer
Timer _updateTimer;
System.Threading.Timer _updateTimer;
async void Device_PlaybackChanged(object sender, TransportStateEventArgs e)
{
@ -124,27 +126,23 @@ namespace MediaBrowser.Dlna.PlayTo
/// <summary>
/// Handles the Elapsed event of the updateTimer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param>
async void updateTimer_Elapsed(object sender, ElapsedEventArgs e)
/// <param name="state">The state.</param>
private async void updateTimer_Elapsed(object state)
{
if (_disposed)
return;
((Timer)sender).Stop();
if (!IsSessionActive)
if (IsSessionActive)
{
//Session is inactive, mark it for Disposal and don't start the elapsed timer.
await _sessionManager.ReportSessionEnded(this._session.Id);
return;
await ReportProgress().ConfigureAwait(false);
}
else
{
_updateTimer.Change(Timeout.Infinite, Timeout.Infinite);
await ReportProgress().ConfigureAwait(false);
if (!_disposed && IsSessionActive)
((Timer)sender).Start();
//Session is inactive, mark it for Disposal and don't start the elapsed timer.
await _sessionManager.ReportSessionEnded(_session.Id);
}
}
/// <summary>
@ -387,7 +385,7 @@ namespace MediaBrowser.Dlna.PlayTo
"http",
_networkManager.GetLocalIpAddresses().FirstOrDefault() ?? "localhost",
"8096"
_appHost.HttpServerPort
);
}
@ -493,8 +491,8 @@ namespace MediaBrowser.Dlna.PlayTo
{
if (!_disposed)
{
_updateTimer.Stop();
_disposed = true;
_updateTimer.Dispose();
_device.Dispose();
_logger.Log(LogSeverity.Debug, "Controller disposed");
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Library;
@ -32,8 +33,9 @@ namespace MediaBrowser.Dlna.PlayTo
private readonly IUserManager _userManager;
private readonly IDlnaManager _dlnaManager;
private readonly IServerConfigurationManager _config;
private readonly IServerApplicationHost _appHost;
public PlayToManager(ILogger logger, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager)
public PlayToManager(ILogger logger, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepository, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost)
{
_locations = new ConcurrentDictionary<string, DateTime>();
_tokenSource = new CancellationTokenSource();
@ -46,6 +48,7 @@ namespace MediaBrowser.Dlna.PlayTo
_networkManager = networkManager;
_userManager = userManager;
_dlnaManager = dlnaManager;
_appHost = appHost;
_config = config;
}
@ -227,7 +230,7 @@ namespace MediaBrowser.Dlna.PlayTo
if (controller == null)
{
sessionInfo.SessionController = controller = new PlayToController(sessionInfo, _sessionManager, _itemRepository, _libraryManager, _logger, _networkManager, _dlnaManager, _userManager);
sessionInfo.SessionController = controller = new PlayToController(sessionInfo, _sessionManager, _itemRepository, _libraryManager, _logger, _networkManager, _dlnaManager, _userManager, _appHost);
}
controller.Init(device);

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Library;
@ -22,8 +23,9 @@ namespace MediaBrowser.Dlna.PlayTo
private readonly INetworkManager _networkManager;
private readonly IUserManager _userManager;
private readonly IDlnaManager _dlnaManager;
private readonly IServerApplicationHost _appHost;
public PlayToServerEntryPoint(ILogManager logManager, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepo, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager)
public PlayToServerEntryPoint(ILogManager logManager, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepo, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost)
{
_config = config;
_sessionManager = sessionManager;
@ -33,6 +35,7 @@ namespace MediaBrowser.Dlna.PlayTo
_networkManager = networkManager;
_userManager = userManager;
_dlnaManager = dlnaManager;
_appHost = appHost;
_logger = logManager.GetLogger("PlayTo");
}
@ -69,7 +72,7 @@ namespace MediaBrowser.Dlna.PlayTo
{
try
{
_manager = new PlayToManager(_logger, _config, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager, _dlnaManager);
_manager = new PlayToManager(_logger, _config, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager, _dlnaManager, _appHost);
_manager.Start();
}
catch (Exception ex)

View File

@ -861,7 +861,7 @@ namespace MediaBrowser.ServerApplication
ItemsByNamePath = ApplicationPaths.ItemsByNamePath,
CachePath = ApplicationPaths.CachePath,
MacAddress = GetMacAddress(),
HttpServerPortNumber = ServerConfigurationManager.Configuration.HttpServerPortNumber,
HttpServerPortNumber = HttpServerPort,
OperatingSystem = Environment.OSVersion.ToString(),
CanSelfRestart = CanSelfRestart,
CanSelfUpdate = CanSelfUpdate,
@ -874,6 +874,11 @@ namespace MediaBrowser.ServerApplication
};
}
public int HttpServerPort
{
get { return ServerConfigurationManager.Configuration.HttpServerPortNumber; }
}
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private string GetWanAddress()
{