diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-08-04 16:30:15 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-04 16:30:15 -0400 |
| commit | e169eaee6cb2f91e4102f4fe7ac9075659feba95 (patch) | |
| tree | a143a29cc50b65fd059727ad8f687ad32e42cecb /MediaBrowser.Model | |
| parent | db9176521c324452ea6c4c4566d54eed5329780f (diff) | |
| parent | 3fe1c25c3ea8d6519aba3b5c3ef0d6a9154413b2 (diff) | |
Merge pull request #2794 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Model')
| -rw-r--r-- | MediaBrowser.Model/Dlna/CodecProfile.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.Model/Dlna/ContainerProfile.cs | 39 | ||||
| -rw-r--r-- | MediaBrowser.Model/Dlna/DeviceProfile.cs | 31 | ||||
| -rw-r--r-- | MediaBrowser.Model/Dlna/DirectPlayProfile.cs | 20 | ||||
| -rw-r--r-- | MediaBrowser.Model/Dlna/ResponseProfile.cs | 7 | ||||
| -rw-r--r-- | MediaBrowser.Model/Dlna/StreamBuilder.cs | 91 | ||||
| -rw-r--r-- | MediaBrowser.Model/Net/MimeTypes.cs | 18 |
7 files changed, 128 insertions, 87 deletions
diff --git a/MediaBrowser.Model/Dlna/CodecProfile.cs b/MediaBrowser.Model/Dlna/CodecProfile.cs index e04e04d21..979cd343f 100644 --- a/MediaBrowser.Model/Dlna/CodecProfile.cs +++ b/MediaBrowser.Model/Dlna/CodecProfile.cs @@ -42,16 +42,9 @@ namespace MediaBrowser.Model.Dlna return SplitValue(Codec); } - public List<string> GetContainers() - { - return SplitValue(Container); - } - private bool ContainsContainer(string container) { - List<string> containers = GetContainers(); - - return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty); + return ContainerProfile.ContainsContainer(Container, container); } public bool ContainsCodec(string codec, string container) diff --git a/MediaBrowser.Model/Dlna/ContainerProfile.cs b/MediaBrowser.Model/Dlna/ContainerProfile.cs index 35d7ada6b..2004cfc1f 100644 --- a/MediaBrowser.Model/Dlna/ContainerProfile.cs +++ b/MediaBrowser.Model/Dlna/ContainerProfile.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Xml.Serialization; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Extensions; @@ -21,10 +22,15 @@ namespace MediaBrowser.Model.Dlna public List<string> GetContainers() { + return SplitValue(Container); + } + + public static List<string> SplitValue(string value) + { List<string> list = new List<string>(); - foreach (string i in (Container ?? string.Empty).Split(',')) + foreach (string i in (value ?? string.Empty).Split(',')) { - if (!string.IsNullOrEmpty(i)) list.Add(i); + if (!string.IsNullOrWhiteSpace(i)) list.Add(i); } return list; } @@ -33,7 +39,32 @@ namespace MediaBrowser.Model.Dlna { List<string> containers = GetContainers(); - return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty); + return ContainsContainer(containers, container); + } + + public static bool ContainsContainer(string profileContainers, string inputContainer) + { + return ContainsContainer(SplitValue(profileContainers), inputContainer); + } + + public static bool ContainsContainer(List<string> profileContainers, string inputContainer) + { + if (profileContainers.Count == 0) + { + return true; + } + + var allInputContainers = SplitValue(inputContainer); + + foreach (var container in allInputContainers) + { + if (ListHelper.ContainsIgnoreCase(profileContainers, container)) + { + return true; + } + } + + return false; } } } diff --git a/MediaBrowser.Model/Dlna/DeviceProfile.cs b/MediaBrowser.Model/Dlna/DeviceProfile.cs index cd7ff08d6..5f9bd772c 100644 --- a/MediaBrowser.Model/Dlna/DeviceProfile.cs +++ b/MediaBrowser.Model/Dlna/DeviceProfile.cs @@ -187,17 +187,14 @@ namespace MediaBrowser.Model.Dlna public ResponseProfile GetAudioMediaProfile(string container, string audioCodec, int? audioChannels, int? audioBitrate, int? audioSampleRate, int? audioBitDepth) { - container = StringHelper.TrimStart(container ?? string.Empty, '.'); - foreach (var i in ResponseProfiles) { - if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Audio) + if (i.Type != DlnaProfileType.Audio) { continue; } - List<string> containers = i.GetContainers(); - if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container)) + if (!ContainerProfile.ContainsContainer(i.GetContainers(), container)) { continue; } @@ -208,7 +205,7 @@ namespace MediaBrowser.Model.Dlna continue; } - var conditionProcessor = new MediaBrowser.Model.Dlna.ConditionProcessor(); + var conditionProcessor = new ConditionProcessor(); var anyOff = false; foreach (ProfileCondition c in i.Conditions) @@ -230,9 +227,9 @@ namespace MediaBrowser.Model.Dlna return null; } - private MediaBrowser.Model.Dlna.ProfileCondition GetModelProfileCondition(ProfileCondition c) + private ProfileCondition GetModelProfileCondition(ProfileCondition c) { - return new MediaBrowser.Model.Dlna.ProfileCondition + return new ProfileCondition { Condition = c.Condition, IsRequired = c.IsRequired, @@ -243,22 +240,19 @@ namespace MediaBrowser.Model.Dlna public ResponseProfile GetImageMediaProfile(string container, int? width, int? height) { - container = StringHelper.TrimStart(container ?? string.Empty, '.'); - foreach (var i in ResponseProfiles) { - if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Photo) + if (i.Type != DlnaProfileType.Photo) { continue; } - List<string> containers = i.GetContainers(); - if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container)) + if (!ContainerProfile.ContainsContainer(i.GetContainers(), container)) { continue; } - var conditionProcessor = new MediaBrowser.Model.Dlna.ConditionProcessor(); + var conditionProcessor = new ConditionProcessor(); var anyOff = false; foreach (ProfileCondition c in i.Conditions) @@ -300,17 +294,14 @@ namespace MediaBrowser.Model.Dlna string videoCodecTag, bool? isAvc) { - container = StringHelper.TrimStart(container ?? string.Empty, '.'); - foreach (var i in ResponseProfiles) { - if (i.Type != MediaBrowser.Model.Dlna.DlnaProfileType.Video) + if (i.Type != DlnaProfileType.Video) { continue; } - List<string> containers = i.GetContainers(); - if (containers.Count > 0 && !ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty)) + if (!ContainerProfile.ContainsContainer(i.GetContainers(), container)) { continue; } @@ -327,7 +318,7 @@ namespace MediaBrowser.Model.Dlna continue; } - var conditionProcessor = new MediaBrowser.Model.Dlna.ConditionProcessor(); + var conditionProcessor = new ConditionProcessor(); var anyOff = false; foreach (ProfileCondition c in i.Conditions) diff --git a/MediaBrowser.Model/Dlna/DirectPlayProfile.cs b/MediaBrowser.Model/Dlna/DirectPlayProfile.cs index df511b0da..d99501875 100644 --- a/MediaBrowser.Model/Dlna/DirectPlayProfile.cs +++ b/MediaBrowser.Model/Dlna/DirectPlayProfile.cs @@ -19,27 +19,9 @@ namespace MediaBrowser.Model.Dlna [XmlAttribute("type")] public DlnaProfileType Type { get; set; } - public List<string> GetContainers() - { - List<string> list = new List<string>(); - foreach (string i in (Container ?? string.Empty).Split(',')) - { - if (!string.IsNullOrEmpty(i)) list.Add(i); - } - return list; - } - public bool SupportsContainer(string container) { - var all = GetContainers(); - - // Only allow unknown container if the profile is all inclusive - if (string.IsNullOrWhiteSpace(container)) - { - return all.Count == 0; - } - - return all.Count == 0 || all.Contains(container, StringComparer.OrdinalIgnoreCase); + return ContainerProfile.ContainsContainer(Container, container); } public List<string> GetAudioCodecs() diff --git a/MediaBrowser.Model/Dlna/ResponseProfile.cs b/MediaBrowser.Model/Dlna/ResponseProfile.cs index 1d4791b5c..f1a001bba 100644 --- a/MediaBrowser.Model/Dlna/ResponseProfile.cs +++ b/MediaBrowser.Model/Dlna/ResponseProfile.cs @@ -33,12 +33,7 @@ namespace MediaBrowser.Model.Dlna public List<string> GetContainers() { - List<string> list = new List<string>(); - foreach (string i in (Container ?? string.Empty).Split(',')) - { - if (!string.IsNullOrEmpty(i)) list.Add(i); - } - return list; + return ContainerProfile.SplitValue(Container); } public List<string> GetAudioCodecs() diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index b483d527c..189ed27e4 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -197,6 +197,40 @@ namespace MediaBrowser.Model.Dlna } } + public static string NormalizeMediaSourceFormatIntoSingleContainer(string inputContainer, DeviceProfile profile, DlnaProfileType type) + { + if (string.IsNullOrWhiteSpace(inputContainer)) + { + return null; + } + + var formats = ContainerProfile.SplitValue(inputContainer); + + if (formats.Count == 1) + { + return formats[0]; + } + + if (profile != null) + { + foreach (var format in formats) + { + foreach (var directPlayProfile in profile.DirectPlayProfiles) + { + if (directPlayProfile.Type == type) + { + if (directPlayProfile.SupportsContainer(format)) + { + return format; + } + } + } + } + } + + return formats[0]; + } + private StreamInfo BuildAudioItem(MediaSourceInfo item, AudioOptions options) { List<TranscodeReason> transcodeReasons = new List<TranscodeReason>(); @@ -214,14 +248,14 @@ namespace MediaBrowser.Model.Dlna if (options.ForceDirectPlay) { playlistItem.PlayMethod = PlayMethod.DirectPlay; - playlistItem.Container = item.Container; + playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio); return playlistItem; } if (options.ForceDirectStream) { playlistItem.PlayMethod = PlayMethod.DirectStream; - playlistItem.Container = item.Container; + playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio); return playlistItem; } @@ -295,7 +329,7 @@ namespace MediaBrowser.Model.Dlna playlistItem.PlayMethod = PlayMethod.DirectStream; } - playlistItem.Container = item.Container; + playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Audio); return playlistItem; } @@ -648,7 +682,7 @@ namespace MediaBrowser.Model.Dlna if (directPlay != null) { playlistItem.PlayMethod = directPlay.Value; - playlistItem.Container = item.Container; + playlistItem.Container = NormalizeMediaSourceFormatIntoSingleContainer(item.Container, options.Profile, DlnaProfileType.Video); if (subtitleStream != null) { @@ -1231,21 +1265,27 @@ namespace MediaBrowser.Model.Dlna private static bool IsSubtitleEmbedSupported(MediaStream subtitleStream, SubtitleProfile subtitleProfile, string transcodingSubProtocol, string transcodingContainer) { - if (string.Equals(transcodingContainer, "ts", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (string.Equals(transcodingContainer, "mpegts", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (string.Equals(transcodingContainer, "mp4", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - if (string.Equals(transcodingContainer, "mkv", StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrWhiteSpace(transcodingContainer)) { - return true; + var normalizedContainers = ContainerProfile.SplitValue(transcodingContainer); + + if (ContainerProfile.ContainsContainer(normalizedContainers, "ts")) + { + return false; + } + if (ContainerProfile.ContainsContainer(normalizedContainers, "mpegts")) + { + return false; + } + if (ContainerProfile.ContainsContainer(normalizedContainers, "mp4")) + { + return false; + } + if (ContainerProfile.ContainsContainer(normalizedContainers, "mkv") || + ContainerProfile.ContainsContainer(normalizedContainers, "matroska")) + { + return true; + } } return false; @@ -1572,14 +1612,17 @@ namespace MediaBrowser.Model.Dlna } // Check audio codec - List<string> audioCodecs = profile.GetAudioCodecs(); - if (audioCodecs.Count > 0) + if (audioStream != null) { - // Check audio codecs - string audioCodec = audioStream == null ? null : audioStream.Codec; - if (string.IsNullOrEmpty(audioCodec) || !ListHelper.ContainsIgnoreCase(audioCodecs, audioCodec)) + List<string> audioCodecs = profile.GetAudioCodecs(); + if (audioCodecs.Count > 0) { - return false; + // Check audio codecs + string audioCodec = audioStream == null ? null : audioStream.Codec; + if (string.IsNullOrEmpty(audioCodec) || !ListHelper.ContainsIgnoreCase(audioCodecs, audioCodec)) + { + return false; + } } } diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs index 2f132cb37..7a2e1f215 100644 --- a/MediaBrowser.Model/Net/MimeTypes.cs +++ b/MediaBrowser.Model/Net/MimeTypes.cs @@ -106,14 +106,15 @@ namespace MediaBrowser.Model.Net return dict; } + public static string GetMimeType(string path) + { + return GetMimeType(path, true); + } + /// <summary> /// Gets the type of the MIME. /// </summary> - /// <param name="path">The path.</param> - /// <returns>System.String.</returns> - /// <exception cref="ArgumentNullException">path</exception> - /// <exception cref="InvalidOperationException">Argument not supported: + path</exception> - public static string GetMimeType(string path) + public static string GetMimeType(string path, bool enableStreamDefault) { if (string.IsNullOrEmpty(path)) { @@ -329,7 +330,12 @@ namespace MediaBrowser.Model.Net return "application/ttml+xml"; } - return "application/octet-stream"; + if (enableStreamDefault) + { + return "application/octet-stream"; + } + + return null; } public static string ToExtension(string mimeType) |
