diff options
Diffstat (limited to 'MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs')
| -rw-r--r-- | MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs | 120 |
1 files changed, 95 insertions, 25 deletions
diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs index 351eca5be..b2bbe3b14 100644 --- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs +++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Model.Dlna { @@ -11,13 +13,45 @@ namespace MediaBrowser.Model.Dlna _profile = profile; } - public string BuildAudioHeader(string container, + public string BuildImageHeader(string container, + int? width, + int? height) + { + var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetImageOrgOpValue(); + + // 0 = native, 1 = transcoded + const string orgCi = ";DLNA.ORG_CI=0"; + + var flagValue = DlnaFlags.StreamingTransferMode | + DlnaFlags.BackgroundTransferMode | + DlnaFlags.DlnaV15; + + var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", + FlagsToString(flagValue)); + + var mediaProfile = _profile.GetImageMediaProfile(container, + width, + height); + + var orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; + + if (string.IsNullOrEmpty(orgPn)) + { + orgPn = GetImageOrgPnValue(container, width, height); + } + + var contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; + + return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); + } + + public string BuildAudioHeader(string container, string audioCodec, - int? audioBitrate, - int? audioSampleRate, - int? audioChannels, - bool isDirectStream, - long? runtimeTicks, + int? audioBitrate, + int? audioSampleRate, + int? audioChannels, + bool isDirectStream, + long? runtimeTicks, TranscodeSeekInfo transcodeSeekInfo) { // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none @@ -42,7 +76,10 @@ namespace MediaBrowser.Model.Dlna var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", FlagsToString(flagValue)); - var mediaProfile = _profile.GetAudioMediaProfile(container, audioCodec); + var mediaProfile = _profile.GetAudioMediaProfile(container, + audioCodec, + audioChannels, + audioBitrate); var orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; @@ -62,15 +99,22 @@ namespace MediaBrowser.Model.Dlna return string.Format("{0:X8}{1:D24}", (ulong)flags, 0); } - public string BuildVideoHeader(string container, - string videoCodec, - string audioCodec, - int? width, - int? height, - int? bitrate, - TransportStreamTimestamp timestamp, - bool isDirectStream, - long? runtimeTicks, + public string BuildVideoHeader(string container, + string videoCodec, + string audioCodec, + int? width, + int? height, + int? bitDepth, + int? videoBitrate, + int? audioChannels, + int? audioBitrate, + TransportStreamTimestamp timestamp, + bool isDirectStream, + long? runtimeTicks, + string videoProfile, + double? videoLevel, + double? videoFramerate, + int? packetLength, TranscodeSeekInfo transcodeSeekInfo) { // first bit means Time based seek supported, second byte range seek supported (not sure about the order now), so 01 = only byte seek, 10 = time based, 11 = both, 00 = none @@ -95,12 +139,30 @@ namespace MediaBrowser.Model.Dlna var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}000000000000000000000000", Enum.Format(typeof(DlnaFlags), flagValue, "x")); - var mediaProfile = _profile.GetVideoMediaProfile(container, audioCodec, videoCodec); + var mediaProfile = _profile.GetVideoMediaProfile(container, + audioCodec, + videoCodec, + audioBitrate, + audioChannels, + width, + height, + bitDepth, + videoBitrate, + videoProfile, + videoLevel, + videoFramerate, + packetLength, + timestamp); + var orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; - + if (string.IsNullOrEmpty(orgPn)) { - orgPn = GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, bitrate, timestamp); + orgPn = GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp) + .FirstOrDefault(); + + // TODO: Support multiple values and return multiple headers? + orgPn = (orgPn ?? string.Empty).Split(',').FirstOrDefault(); } var contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; @@ -108,6 +170,16 @@ namespace MediaBrowser.Model.Dlna return (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); } + private string GetImageOrgPnValue(string container, int? width, int? height) + { + var format = new MediaFormatProfileResolver() + .ResolveImageFormat(container, + width, + height); + + return format.HasValue ? format.Value.ToString() : null; + } + private string GetAudioOrgPnValue(string container, int? audioBitrate, int? audioSampleRate, int? audioChannels) { var format = new MediaFormatProfileResolver() @@ -119,18 +191,16 @@ namespace MediaBrowser.Model.Dlna return format.HasValue ? format.Value.ToString() : null; } - private string GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestamp) + private IEnumerable<string> GetVideoOrgPnValue(string container, string videoCodec, string audioCodec, int? width, int? height, TransportStreamTimestamp timestamp) { - var videoFormat = new MediaFormatProfileResolver() + return new MediaFormatProfileResolver() .ResolveVideoFormat(container, videoCodec, audioCodec, width, height, - bitrate, - timestamp); - - return videoFormat.HasValue ? videoFormat.Value.ToString() : null; + timestamp) + .Select(i => i.ToString()); } } } |
