From 1544b7bf9ce3221aec47da22a76e171f6714ce26 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 24 Apr 2014 22:45:06 -0400 Subject: [PATCH] display timestamp info --- .../Playback/BaseStreamingService.cs | 3 ++- MediaBrowser.Api/Playback/StreamState.cs | 4 ++-- MediaBrowser.Controller/Entities/Video.cs | 2 +- MediaBrowser.Model/Dlna/ConditionProcessor.cs | 10 ++++++++-- .../Dlna/MediaFormatProfileResolver.cs | 10 +++++----- MediaBrowser.Model/Dlna/StreamBuilder.cs | 2 +- MediaBrowser.Model/Dlna/StreamInfo.cs | 6 +++--- MediaBrowser.Model/Dto/MediaVersionInfo.cs | 2 +- MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs | 6 +++--- .../MediaInfo/FFProbeProvider.cs | 9 ++++++--- .../MediaInfo/FFProbeVideoInfo.cs | 17 ++++++++++------- 11 files changed, 42 insertions(+), 29 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index ac7dab080..aafda7812 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -24,6 +24,7 @@ using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.MediaInfo; namespace MediaBrowser.Api.Playback { @@ -1437,7 +1438,7 @@ namespace MediaBrowser.Api.Playback : video.PlayableStreamFileNames.ToList(); state.DeInterlace = string.Equals(video.Container, "wtv", StringComparison.OrdinalIgnoreCase); - state.InputTimestamp = video.Timestamp; + state.InputTimestamp = video.Timestamp ?? TransportStreamTimestamp.None; } state.RunTimeTicks = item.RunTimeTicks; diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index 051413259..c7a62a332 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -273,8 +273,8 @@ namespace MediaBrowser.Api.Playback get { var defaultValue = string.Equals(OutputContainer, "m2ts", StringComparison.OrdinalIgnoreCase) ? - TransportStreamTimestamp.VALID : - TransportStreamTimestamp.NONE; + TransportStreamTimestamp.Valid : + TransportStreamTimestamp.None; return !Request.Static ? defaultValue diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index bfb306b31..d4547c713 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.Controller.Entities /// Gets or sets the timestamp. /// /// The timestamp. - public TransportStreamTimestamp Timestamp { get; set; } + public TransportStreamTimestamp? Timestamp { get; set; } public Video() { diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index 2e337982f..3577c6f01 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Model.Dlna double? videoLevel, double? videoFramerate, int? packetLength, - TransportStreamTimestamp timestamp) + TransportStreamTimestamp? timestamp) { switch (condition.Property) { @@ -176,8 +176,14 @@ namespace MediaBrowser.Model.Dlna return false; } - private bool IsConditionSatisfied(ProfileCondition condition, TransportStreamTimestamp timestamp) + private bool IsConditionSatisfied(ProfileCondition condition, TransportStreamTimestamp? timestamp) { + if (!timestamp.HasValue) + { + // If the value is unknown, it satisfies if not marked as required + return !condition.IsRequired; + } + var expected = (TransportStreamTimestamp)Enum.Parse(typeof(TransportStreamTimestamp), condition.Value, true); switch (condition.Condition) diff --git a/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs b/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs index 589dc3376..a62508fb1 100644 --- a/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs +++ b/MediaBrowser.Model/Dlna/MediaFormatProfileResolver.cs @@ -67,10 +67,10 @@ namespace MediaBrowser.Model.Dlna switch (timestampType) { - case TransportStreamTimestamp.NONE: + case TransportStreamTimestamp.None: suffix = "_ISO"; break; - case TransportStreamTimestamp.VALID: + case TransportStreamTimestamp.Valid: suffix = "_T"; break; } @@ -89,7 +89,7 @@ namespace MediaBrowser.Model.Dlna list.Add(ValueOf("MPEG_TS_SD_EU" + suffix)); list.Add(ValueOf("MPEG_TS_SD_KO" + suffix)); - if ((timestampType == TransportStreamTimestamp.VALID) && string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase)) + if ((timestampType == TransportStreamTimestamp.Valid) && string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase)) { list.Add(MediaFormatProfile.MPEG_TS_JP_T); } @@ -102,7 +102,7 @@ namespace MediaBrowser.Model.Dlna if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase)) { - if (timestampType == TransportStreamTimestamp.NONE) + if (timestampType == TransportStreamTimestamp.None) { return new[] { MediaFormatProfile.AVC_TS_HD_DTS_ISO }; } @@ -111,7 +111,7 @@ namespace MediaBrowser.Model.Dlna if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase)) { - if (timestampType == TransportStreamTimestamp.NONE) + if (timestampType == TransportStreamTimestamp.None) { return new[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_ISO", resolution)) }; } diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 13c698ded..40b1e140b 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -286,7 +286,7 @@ namespace MediaBrowser.Model.Dlna var audioBitrate = audioStream == null ? null : audioStream.BitRate; var audioChannels = audioStream == null ? null : audioStream.Channels; - var timestamp = videoStream == null ? TransportStreamTimestamp.NONE : mediaSource.Timestamp; + var timestamp = videoStream == null ? TransportStreamTimestamp.None : mediaSource.Timestamp; var packetLength = videoStream == null ? null : videoStream.PacketLength; // Check container conditions diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index e49c31947..1e8ca6f20 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -341,12 +341,12 @@ namespace MediaBrowser.Model.Dlna get { var defaultValue = string.Equals(Container, "m2ts", StringComparison.OrdinalIgnoreCase) - ? TransportStreamTimestamp.VALID - : TransportStreamTimestamp.NONE; + ? TransportStreamTimestamp.Valid + : TransportStreamTimestamp.None; return !IsDirectStream ? defaultValue - : MediaSource == null ? defaultValue : MediaSource.Timestamp; + : MediaSource == null ? defaultValue : MediaSource.Timestamp ?? TransportStreamTimestamp.None; } } diff --git a/MediaBrowser.Model/Dto/MediaVersionInfo.cs b/MediaBrowser.Model/Dto/MediaVersionInfo.cs index e2b197213..c2215fd6a 100644 --- a/MediaBrowser.Model/Dto/MediaVersionInfo.cs +++ b/MediaBrowser.Model/Dto/MediaVersionInfo.cs @@ -31,7 +31,7 @@ namespace MediaBrowser.Model.Dto public int? Bitrate { get; set; } - public TransportStreamTimestamp Timestamp { get; set; } + public TransportStreamTimestamp? Timestamp { get; set; } public MediaSourceInfo() { diff --git a/MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs b/MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs index 35000ca39..01e75e6f8 100644 --- a/MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs +++ b/MediaBrowser.Model/MediaInfo/BlurayDiscInfo.cs @@ -37,8 +37,8 @@ namespace MediaBrowser.Model.MediaInfo public enum TransportStreamTimestamp { - NONE, - ZERO, - VALID + None, + Zero, + Valid } } diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs index 55d09b68b..7a71a7551 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; @@ -43,6 +44,7 @@ namespace MediaBrowser.Providers.MediaInfo private readonly IApplicationPaths _appPaths; private readonly IJsonSerializer _json; private readonly IEncodingManager _encodingManager; + private readonly IFileSystem _fileSystem; public string Name { @@ -94,7 +96,7 @@ namespace MediaBrowser.Providers.MediaInfo return FetchAudioInfo(item, cancellationToken); } - public FFProbeProvider(ILogger logger, IIsoManager isoManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, IBlurayExaminer blurayExaminer, ILocalizationManager localization, IApplicationPaths appPaths, IJsonSerializer json, IEncodingManager encodingManager) + public FFProbeProvider(ILogger logger, IIsoManager isoManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, IBlurayExaminer blurayExaminer, ILocalizationManager localization, IApplicationPaths appPaths, IJsonSerializer json, IEncodingManager encodingManager, IFileSystem fileSystem) { _logger = logger; _isoManager = isoManager; @@ -105,6 +107,7 @@ namespace MediaBrowser.Providers.MediaInfo _appPaths = appPaths; _json = json; _encodingManager = encodingManager; + _fileSystem = fileSystem; } private readonly Task _cachedTask = Task.FromResult(ItemUpdateType.None); @@ -131,7 +134,7 @@ namespace MediaBrowser.Providers.MediaInfo return _cachedTask; } - var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager); + var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem); return prober.ProbeVideo(item, directoryService, cancellationToken); } @@ -162,7 +165,7 @@ namespace MediaBrowser.Providers.MediaInfo if (video != null && !video.IsPlaceHolder) { - var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager); + var prober = new FFProbeVideoInfo(_logger, _isoManager, _mediaEncoder, _itemRepo, _blurayExaminer, _localization, _appPaths, _json, _encodingManager, _fileSystem); return !video.SubtitleFiles.SequenceEqual(prober.GetSubtitleFiles(video, directoryService).Select(i => i.FullName).OrderBy(i => i), StringComparer.OrdinalIgnoreCase); } diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs index 4f47edee0..a7d4a480e 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs @@ -1,5 +1,6 @@ using DvdLib.Ifo; using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -7,7 +8,6 @@ using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; @@ -20,7 +20,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Common.Extensions; namespace MediaBrowser.Providers.MediaInfo { @@ -39,7 +38,7 @@ namespace MediaBrowser.Providers.MediaInfo private readonly CultureInfo _usCulture = new CultureInfo("en-US"); - public FFProbeVideoInfo(ILogger logger, IIsoManager isoManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, IBlurayExaminer blurayExaminer, ILocalizationManager localization, IApplicationPaths appPaths, IJsonSerializer json, IEncodingManager encodingManager) + public FFProbeVideoInfo(ILogger logger, IIsoManager isoManager, IMediaEncoder mediaEncoder, IItemRepository itemRepo, IBlurayExaminer blurayExaminer, ILocalizationManager localization, IApplicationPaths appPaths, IJsonSerializer json, IEncodingManager encodingManager, IFileSystem fileSystem) { _logger = logger; _isoManager = isoManager; @@ -50,6 +49,7 @@ namespace MediaBrowser.Providers.MediaInfo _appPaths = appPaths; _json = json; _encodingManager = encodingManager; + _fileSystem = fileSystem; } public async Task ProbeVideo(T item, IDirectoryService directoryService, CancellationToken cancellationToken) @@ -584,10 +584,13 @@ namespace MediaBrowser.Providers.MediaInfo try { video.Timestamp = GetMpegTimestamp(video.Path); + + _logger.Debug("Video has {0} timestamp", video.Timestamp); } catch (Exception ex) { _logger.ErrorException("Error extracting timestamp info from {0}", ex, video.Path); + video.Timestamp = null; } } } @@ -604,20 +607,20 @@ namespace MediaBrowser.Providers.MediaInfo if (packetBuffer[0] == 71) { - return TransportStreamTimestamp.NONE; + return TransportStreamTimestamp.None; } if ((packetBuffer[4] == 71) && (packetBuffer['Ä'] == 71)) { if ((packetBuffer[0] == 0) && (packetBuffer[1] == 0) && (packetBuffer[2] == 0) && (packetBuffer[3] == 0)) { - return TransportStreamTimestamp.ZERO; + return TransportStreamTimestamp.Zero; } - return TransportStreamTimestamp.VALID; + return TransportStreamTimestamp.Valid; } - return TransportStreamTimestamp.NONE; + return TransportStreamTimestamp.None; } private void FetchFromDvdLib(Video item, IIsoMount mount)