From 0f4c28c120751e1cf6e0562ef0445c7fa46cf0a4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 28 Apr 2014 11:05:28 -0400 Subject: [PATCH] expose more dlna profile properties --- .../ScheduledTasks/Tasks/SystemUpdateTask.cs | 5 +-- MediaBrowser.Dlna/Ssdp/SsdpHandler.cs | 39 ++++++++++++++----- MediaBrowser.Model/Dlna/ConditionProcessor.cs | 3 ++ MediaBrowser.Model/Dlna/StreamInfo.cs | 27 +++++-------- .../EntryPoints/Notifications/Notifier.cs | 7 ++++ .../ApplicationHost.cs | 4 ++ 6 files changed, 54 insertions(+), 31 deletions(-) diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs index cf22f8e9a3..641d402bda 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs @@ -67,9 +67,6 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// Task. public async Task Execute(CancellationToken cancellationToken, IProgress progress) { - if (!_appHost.CanSelfUpdate) return; - if (!ConfigurationManager.CommonConfiguration.EnableAutoUpdate) return; - EventHandler innerProgressHandler = (sender, e) => progress.Report(e * .1); // Create a progress object for the update check @@ -92,6 +89,8 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks cancellationToken.ThrowIfCancellationRequested(); + if (!_appHost.CanSelfUpdate) return; + if (ConfigurationManager.CommonConfiguration.EnableAutoUpdate) { Logger.Info("Update Revision {0} available. Updating...", updateInfo.AvailableVersion); diff --git a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs index 14643f4683..c6d1b70539 100644 --- a/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs +++ b/MediaBrowser.Dlna/Ssdp/SsdpHandler.cs @@ -40,6 +40,13 @@ namespace MediaBrowser.Dlna.Ssdp _logger = logger; _config = config; _serverSignature = serverSignature; + + _config.ConfigurationUpdated += _config_ConfigurationUpdated; + } + + void _config_ConfigurationUpdated(object sender, EventArgs e) + { + ReloadAliveNotifier(); } public event EventHandler MessageReceived; @@ -69,7 +76,7 @@ namespace MediaBrowser.Dlna.Ssdp _logger.Info("SSDP service started"); Receive(); - StartNotificationTimer(); + ReloadAliveNotifier(); } public void SendDatagram(string header, @@ -249,6 +256,8 @@ namespace MediaBrowser.Dlna.Ssdp public void Dispose() { + _config.ConfigurationUpdated -= _config_ConfigurationUpdated; + _isDisposed = true; while (_messageQueue.Count != 0) { @@ -365,25 +374,34 @@ namespace MediaBrowser.Dlna.Ssdp } private readonly object _notificationTimerSyncLock = new object(); - private void StartNotificationTimer() + private int _aliveNotifierIntervalMs; + private void ReloadAliveNotifier() { if (!_config.Configuration.DlnaOptions.BlastAliveMessages) { + DisposeNotificationTimer(); return; } - const int initialDelayMs = 3000; var intervalMs = _config.Configuration.DlnaOptions.BlastAliveMessageIntervalSeconds * 1000; - lock (_notificationTimerSyncLock) + if (_notificationTimer == null || _aliveNotifierIntervalMs != intervalMs) { - if (_notificationTimer == null) - { - _notificationTimer = new Timer(state => NotifyAll(), null, initialDelayMs, intervalMs); - } - else + lock (_notificationTimerSyncLock) { - _notificationTimer.Change(initialDelayMs, intervalMs); + if (_notificationTimer == null) + { + _logger.Debug("Starting alive notifier"); + const int initialDelayMs = 3000; + _notificationTimer = new Timer(state => NotifyAll(), null, initialDelayMs, intervalMs); + } + else + { + _logger.Debug("Updating alive notifier"); + _notificationTimer.Change(intervalMs, intervalMs); + } + + _aliveNotifierIntervalMs = intervalMs; } } } @@ -394,6 +412,7 @@ namespace MediaBrowser.Dlna.Ssdp { if (_notificationTimer != null) { + _logger.Debug("Stopping alive notifier"); _notificationTimer.Dispose(); _notificationTimer = null; } diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index 3577c6f018..d5e1f6686f 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -87,6 +87,9 @@ namespace MediaBrowser.Model.Dlna { switch (condition.Property) { + case ProfileConditionValue.AudioProfile: + // TODO: Implement + return true; case ProfileConditionValue.AudioBitrate: return IsConditionSatisfied(condition, audioBitrate); case ProfileConditionValue.AudioChannels: diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index b6bf9b183d..fe49227e40 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -267,10 +267,11 @@ namespace MediaBrowser.Model.Dlna get { var stream = TargetAudioStream; + var streamChannels = stream == null ? null : stream.Channels; return MaxAudioChannels.HasValue && !IsDirectStream - ? (stream.Channels.HasValue ? Math.Min(MaxAudioChannels.Value, stream.Channels.Value) : MaxAudioChannels.Value) - : stream == null ? null : stream.Channels; + ? (streamChannels.HasValue ? Math.Min(MaxAudioChannels.Value, streamChannels.Value) : MaxAudioChannels.Value) + : stream == null ? null : streamChannels; } } @@ -303,24 +304,14 @@ namespace MediaBrowser.Model.Dlna if (RunTimeTicks.HasValue) { - var totalBitrate = 0; + var totalBitrate = TargetTotalBitrate; - if (AudioBitrate.HasValue) - { - totalBitrate += AudioBitrate.Value; - } - if (VideoBitrate.HasValue) - { - totalBitrate += VideoBitrate.Value; - } - - return Convert.ToInt64(totalBitrate * TimeSpan.FromTicks(RunTimeTicks.Value).TotalSeconds); + return totalBitrate.HasValue ? + Convert.ToInt64(totalBitrate * TimeSpan.FromTicks(RunTimeTicks.Value).TotalSeconds) : + (long?)null; } - var stream = TargetAudioStream; - return MaxAudioChannels.HasValue && !IsDirectStream - ? (stream.Channels.HasValue ? Math.Min(MaxAudioChannels.Value, stream.Channels.Value) : MaxAudioChannels.Value) - : stream == null ? null : stream.Channels; + return null; } } @@ -343,7 +334,7 @@ namespace MediaBrowser.Model.Dlna var defaultValue = string.Equals(Container, "m2ts", StringComparison.OrdinalIgnoreCase) ? TransportStreamTimestamp.Valid : TransportStreamTimestamp.None; - + return !IsDirectStream ? defaultValue : MediaSource == null ? defaultValue : MediaSource.Timestamp ?? TransportStreamTimestamp.None; diff --git a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs index 217b068bf1..9aa28809fd 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/Notifications/Notifier.cs @@ -147,6 +147,13 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications var item = e.MediaInfo; + if (e.Item !=null && e.Item.Parent == null) + { + // Don't report theme song or local trailer playback + // TODO: This will also cause movie specials to not be reported + return; + } + var notification = new NotificationRequest { NotificationType = GetPlaybackNotificationType(item.MediaType), diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 157f397550..ce85a0964f 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -1026,6 +1026,10 @@ namespace MediaBrowser.ServerApplication /// Task{CheckForUpdateResult}. public override async Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) { +#if DEBUG + return new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false }; +#endif + var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, null, ApplicationVersion,