public static string BuildAudioHeader( DeviceProfile profile, string container, string audioCodec, int?audioBitrate, int?audioSampleRate, int?audioChannels, int?audioBitDepth, 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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; var flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.InteractiveTransferMode | DlnaFlags.DlnaV15; // if (isDirectStream) // { // flagValue = flagValue | DlnaFlags.ByteBasedSeek; // } // else if (runtimeTicks.HasValue) // { // flagValue = flagValue | DlnaFlags.TimeBasedSeek; // } string dlnaflags = string.Format( CultureInfo.InvariantCulture, ";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = profile.GetAudioMediaProfile( container, audioCodec, audioChannels, audioBitrate, audioSampleRate, audioBitDepth); string orgPn = mediaProfile?.OrgPn; if (string.IsNullOrEmpty(orgPn)) { orgPn = GetAudioOrgPnValue(container, audioBitrate, audioSampleRate, audioChannels); } if (string.IsNullOrEmpty(orgPn)) { return(orgOp.TrimStart(';') + orgCi + dlnaflags); } return("DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags); }
public string BuildAudioHeader(string container, string audioCodec, 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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.InteractiveTransferMode | DlnaFlags.DlnaV15; //if (isDirectStream) //{ // flagValue = flagValue | DlnaFlags.ByteBasedSeek; //} //else if (runtimeTicks.HasValue) //{ // flagValue = flagValue | DlnaFlags.TimeBasedSeek; //} string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = _profile.GetAudioMediaProfile(container, audioCodec, audioChannels, audioBitrate); string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; if (string.IsNullOrEmpty(orgPn)) { orgPn = GetAudioOrgPnValue(container, audioBitrate, audioSampleRate, audioChannels); } string 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, 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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.DlnaV15; if (isDirectStream) { //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_BYTE_BASED_SEEK; } else if (runtimeTicks.HasValue) { //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_TIME_BASED_SEEK; } string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = _profile.GetAudioMediaProfile(container, audioCodec, audioChannels, audioBitrate); string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; if (string.IsNullOrEmpty(orgPn)) { orgPn = GetAudioOrgPnValue(container, audioBitrate, audioSampleRate, audioChannels); } string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; return((contentFeatures + orgOp + orgCi + dlnaflags).Trim(';')); }
public static string GetOrgOpValue(bool hasKnownRuntime, bool isDirectStream, TranscodeSeekInfo profileTranscodeSeekInfo) { if (hasKnownRuntime) { string orgOp = string.Empty; // Time-based seeking currently only possible when transcoding orgOp += isDirectStream ? "0" : "1"; // Byte-based seeking only possible when not transcoding orgOp += isDirectStream || profileTranscodeSeekInfo == TranscodeSeekInfo.Bytes ? "1" : "0"; return orgOp; } // No seeking is available if we don't know the content runtime return "00"; }
public List <string> BuildVideoHeader( string container, string videoCodec, string audioCodec, int?width, int?height, int?bitDepth, int?videoBitrate, TransportStreamTimestamp timestamp, bool isDirectStream, long?runtimeTicks, string videoProfile, double?videoLevel, float?videoFramerate, int?packetLength, TranscodeSeekInfo transcodeSeekInfo, bool?isAnamorphic, bool?isInterlaced, int?refFrames, int?numVideoStreams, int?numAudioStreams, string videoCodecTag, bool?isAvc) { // 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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; var flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.InteractiveTransferMode | DlnaFlags.DlnaV15; // if (isDirectStream) //{ // flagValue = flagValue | DlnaFlags.ByteBasedSeek; //} // else if (runtimeTicks.HasValue) //{ // flagValue = flagValue | DlnaFlags.TimeBasedSeek; //} string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = _profile.GetVideoMediaProfile(container, audioCodec, videoCodec, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isInterlaced, refFrames, numVideoStreams, numAudioStreams, videoCodecTag, isAvc); var orgPnValues = new List <string>(); if (mediaProfile != null && !string.IsNullOrEmpty(mediaProfile.OrgPn)) { orgPnValues.AddRange(mediaProfile.OrgPn.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } else { foreach (string s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp)) { orgPnValues.Add(s); break; } } var contentFeatureList = new List <string>(); foreach (string orgPn in orgPnValues) { string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; var value = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); contentFeatureList.Add(value); } if (orgPnValues.Count == 0) { string contentFeatures = string.Empty; var value = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); contentFeatureList.Add(value); } return(contentFeatureList); }
public static IEnumerable <string> BuildVideoHeader( DeviceProfile profile, string container, string videoCodec, string audioCodec, int?width, int?height, int?bitDepth, int?videoBitrate, TransportStreamTimestamp timestamp, bool isDirectStream, long?runtimeTicks, string videoProfile, double?videoLevel, float?videoFramerate, int?packetLength, TranscodeSeekInfo transcodeSeekInfo, bool?isAnamorphic, bool?isInterlaced, int?refFrames, int?numVideoStreams, int?numAudioStreams, string videoCodecTag, bool?isAvc) { // 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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks > 0, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; var flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.InteractiveTransferMode | DlnaFlags.DlnaV15; if (isDirectStream) { flagValue |= DlnaFlags.ByteBasedSeek; } // Time based seek is curently disabled when streaming. On LG CX3 adding DlnaFlags.TimeBasedSeek and orgPn causes the DLNA playback to fail (format not supported). Further investigations are needed before enabling the remaining code paths. // else if (runtimeTicks.HasValue) // { // flagValue = flagValue | DlnaFlags.TimeBasedSeek; // } string dlnaflags = string.Format( CultureInfo.InvariantCulture, ";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = profile.GetVideoMediaProfile( container, audioCodec, videoCodec, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isInterlaced, refFrames, numVideoStreams, numAudioStreams, videoCodecTag, isAvc); var orgPnValues = new List <string>(); if (mediaProfile != null && !string.IsNullOrEmpty(mediaProfile.OrgPn)) { orgPnValues.AddRange(mediaProfile.OrgPn.Split(',', StringSplitOptions.RemoveEmptyEntries)); } else { foreach (var s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp)) { orgPnValues.Add(s.ToString()); break; } } var contentFeatureList = new List <string>(); foreach (string orgPn in orgPnValues) { if (string.IsNullOrEmpty(orgPn)) { contentFeatureList.Add(orgOp.TrimStart(';') + orgCi + dlnaflags); } else if (isDirectStream) { // orgOp should be added all the time once the time based seek is resolved for transcoded streams contentFeatureList.Add("DLNA.ORG_PN=" + orgPn + orgOp + orgCi + dlnaflags); } else { contentFeatureList.Add("DLNA.ORG_PN=" + orgPn + orgCi + dlnaflags); } } if (orgPnValues.Count == 0) { contentFeatureList.Add(orgOp.TrimStart(';') + orgCi + dlnaflags); } return(contentFeatureList); }
public static string GetOrgOpValue(bool hasKnownRuntime, bool isDirectStream, TranscodeSeekInfo profileTranscodeSeekInfo) { if (hasKnownRuntime) { string orgOp = string.Empty; // Time-based seeking currently only possible when transcoding orgOp += isDirectStream ? "0" : "1"; // Byte-based seeking only possible when not transcoding orgOp += isDirectStream || profileTranscodeSeekInfo == TranscodeSeekInfo.Bytes ? "1" : "0"; return(orgOp); } // No seeking is available if we don't know the content runtime return("00"); }
public List<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, float? videoFramerate, int? packetLength, TranscodeSeekInfo transcodeSeekInfo, bool? isAnamorphic, int? refFrames) { // 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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.InteractiveTransferMode | DlnaFlags.DlnaV15; //if (isDirectStream) //{ // flagValue = flagValue | DlnaFlags.ByteBasedSeek; //} //else if (runtimeTicks.HasValue) //{ // flagValue = flagValue | DlnaFlags.TimeBasedSeek; //} string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = _profile.GetVideoMediaProfile(container, audioCodec, videoCodec, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames); List<string> orgPnValues = new List<string>(); if (mediaProfile != null && !string.IsNullOrEmpty(mediaProfile.OrgPn)) { orgPnValues.Add(mediaProfile.OrgPn); } else { foreach (string s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp)) { orgPnValues.Add(s); break; } } List<string> contentFeatureList = new List<string>(); foreach (string orgPn in orgPnValues) { string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; var value = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); contentFeatureList.Add(value); } if (orgPnValues.Count == 0) { string contentFeatures = string.Empty; var value = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); contentFeatureList.Add(value); } return contentFeatureList; }
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 string orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(runtimeTicks.HasValue, isDirectStream, transcodeSeekInfo); // 0 = native, 1 = transcoded string orgCi = isDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; DlnaFlags flagValue = DlnaFlags.StreamingTransferMode | DlnaFlags.BackgroundTransferMode | DlnaFlags.DlnaV15; if (isDirectStream) { //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_BYTE_BASED_SEEK; } else if (runtimeTicks.HasValue) { //flagValue = flagValue | DlnaFlags.DLNA_ORG_FLAG_TIME_BASED_SEEK; } string dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}", DlnaMaps.FlagsToString(flagValue)); ResponseProfile mediaProfile = _profile.GetVideoMediaProfile(container, audioCodec, videoCodec, audioBitrate, audioChannels, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp); string orgPn = mediaProfile == null ? null : mediaProfile.OrgPn; if (string.IsNullOrEmpty(orgPn)) { foreach (string s in GetVideoOrgPnValue(container, videoCodec, audioCodec, width, height, timestamp)) { orgPn = s; break; } } if (string.IsNullOrEmpty(orgPn)) { // TODO: Support multiple values and return multiple headers? foreach (string s in (orgPn ?? string.Empty).Split(',')) { orgPn = s; break; } } string contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty : "DLNA.ORG_PN=" + orgPn; return((contentFeatures + orgOp + orgCi + dlnaflags).Trim(';')); }