add correct media format profiles to res elements

pull/702/head
Luke Pulverenti 11 years ago
parent 54eb7cb855
commit fdd8c67162

@ -126,7 +126,7 @@ namespace MediaBrowser.Api.Playback
/// </summary> /// </summary>
/// <param name="state">The state.</param> /// <param name="state">The state.</param>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
protected virtual string GetOutputFilePath(StreamState state) protected string GetOutputFilePath(StreamState state)
{ {
var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath; var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath;
@ -137,11 +137,6 @@ namespace MediaBrowser.Api.Playback
protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
/// <summary>
/// The fast seek offset seconds
/// </summary>
private const int FastSeekOffsetSeconds = 1;
/// <summary> /// <summary>
/// Gets the fast seek command line parameter. /// Gets the fast seek command line parameter.
/// </summary> /// </summary>
@ -165,17 +160,6 @@ namespace MediaBrowser.Api.Playback
return string.Empty; return string.Empty;
} }
/// <summary>
/// Gets the slow seek command line parameter.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.String.</returns>
/// <value>The slow seek command line parameter.</value>
protected string GetSlowSeekCommandLineParameter(StreamRequest request)
{
return string.Empty;
}
/// <summary> /// <summary>
/// Gets the map args. /// Gets the map args.
/// </summary> /// </summary>
@ -415,9 +399,9 @@ namespace MediaBrowser.Api.Playback
param += string.Format(" -r {0}", framerate.Value.ToString(UsCulture)); param += string.Format(" -r {0}", framerate.Value.ToString(UsCulture));
} }
if (!string.IsNullOrEmpty(state.VideoSync)) if (!string.IsNullOrEmpty(state.OutputVideoSync))
{ {
param += " -vsync " + state.VideoSync; param += " -vsync " + state.OutputVideoSync;
} }
if (!string.IsNullOrEmpty(state.VideoRequest.Profile)) if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
@ -438,7 +422,7 @@ namespace MediaBrowser.Api.Playback
var volParam = string.Empty; var volParam = string.Empty;
var audioSampleRate = string.Empty; var audioSampleRate = string.Empty;
var channels = GetNumAudioChannelsParam(state.Request, state.AudioStream); var channels = state.OutputAudioChannels;
// Boost volume to 200% when downsampling from 6ch to 2ch // Boost volume to 200% when downsampling from 6ch to 2ch
if (channels.HasValue && channels.Value <= 2) if (channels.HasValue && channels.Value <= 2)
@ -449,9 +433,9 @@ namespace MediaBrowser.Api.Playback
} }
} }
if (state.Request.AudioSampleRate.HasValue) if (state.OutputAudioSampleRate.HasValue)
{ {
audioSampleRate = state.Request.AudioSampleRate.Value + ":"; audioSampleRate = state.OutputAudioSampleRate.Value + ":";
} }
var adelay = isHls ? "adelay=1," : string.Empty; var adelay = isHls ? "adelay=1," : string.Empty;
@ -478,7 +462,7 @@ namespace MediaBrowser.Api.Playback
audioSampleRate, audioSampleRate,
volParam, volParam,
pts, pts,
state.AudioSync); state.OutputAudioSync);
} }
/// <summary> /// <summary>
@ -746,7 +730,7 @@ namespace MediaBrowser.Api.Playback
/// <param name="request">The request.</param> /// <param name="request">The request.</param>
/// <param name="audioStream">The audio stream.</param> /// <param name="audioStream">The audio stream.</param>
/// <returns>System.Nullable{System.Int32}.</returns> /// <returns>System.Nullable{System.Int32}.</returns>
protected int? GetNumAudioChannelsParam(StreamRequest request, MediaStream audioStream) private int? GetNumAudioChannelsParam(StreamRequest request, MediaStream audioStream)
{ {
if (audioStream != null) if (audioStream != null)
{ {
@ -973,17 +957,17 @@ namespace MediaBrowser.Api.Playback
} }
} }
protected int? GetVideoBitrateParamValue(StreamState state) private int? GetVideoBitrateParamValue(VideoStreamRequest request, MediaStream videoStream)
{ {
var bitrate = state.VideoRequest.VideoBitRate; var bitrate = request.VideoBitRate;
if (state.VideoStream != null) if (videoStream != null)
{ {
var isUpscaling = state.VideoRequest.Height.HasValue && state.VideoStream.Height.HasValue && var isUpscaling = request.Height.HasValue && videoStream.Height.HasValue &&
state.VideoRequest.Height.Value > state.VideoStream.Height.Value; request.Height.Value > videoStream.Height.Value;
if (state.VideoRequest.Width.HasValue && state.VideoStream.Width.HasValue && if (request.Width.HasValue && videoStream.Width.HasValue &&
state.VideoRequest.Width.Value > state.VideoStream.Width.Value) request.Width.Value > videoStream.Width.Value)
{ {
isUpscaling = true; isUpscaling = true;
} }
@ -991,9 +975,9 @@ namespace MediaBrowser.Api.Playback
// Don't allow bitrate increases unless upscaling // Don't allow bitrate increases unless upscaling
if (!isUpscaling) if (!isUpscaling)
{ {
if (bitrate.HasValue && state.VideoStream.BitRate.HasValue) if (bitrate.HasValue && videoStream.BitRate.HasValue)
{ {
bitrate = Math.Min(bitrate.Value, state.VideoStream.BitRate.Value); bitrate = Math.Min(bitrate.Value, videoStream.BitRate.Value);
} }
} }
} }
@ -1003,7 +987,7 @@ namespace MediaBrowser.Api.Playback
protected string GetVideoBitrateParam(StreamState state, string videoCodec, bool isHls) protected string GetVideoBitrateParam(StreamState state, string videoCodec, bool isHls)
{ {
var bitrate = GetVideoBitrateParamValue(state); var bitrate = state.OutputVideoBitrate;
if (bitrate.HasValue) if (bitrate.HasValue)
{ {
@ -1045,14 +1029,14 @@ namespace MediaBrowser.Api.Playback
return string.Empty; return string.Empty;
} }
protected int? GetAudioBitrateParam(StreamState state) private int? GetAudioBitrateParam(StreamRequest request, MediaStream audioStream)
{ {
if (state.Request.AudioBitRate.HasValue) if (request.AudioBitRate.HasValue)
{ {
// Make sure we don't request a bitrate higher than the source // Make sure we don't request a bitrate higher than the source
var currentBitrate = state.AudioStream == null ? state.Request.AudioBitRate.Value : state.AudioStream.BitRate ?? state.Request.AudioBitRate.Value; var currentBitrate = audioStream == null ? request.AudioBitRate.Value : audioStream.BitRate ?? request.AudioBitRate.Value;
return Math.Min(currentBitrate, state.Request.AudioBitRate.Value); return Math.Min(currentBitrate, request.AudioBitRate.Value);
} }
return null; return null;
@ -1399,7 +1383,7 @@ namespace MediaBrowser.Api.Playback
} }
state.ReadInputAtNativeFramerate = recording.RecordingInfo.Status == RecordingStatus.InProgress; state.ReadInputAtNativeFramerate = recording.RecordingInfo.Status == RecordingStatus.InProgress;
state.AudioSync = "1000"; state.OutputAudioSync = "1000";
state.DeInterlace = true; state.DeInterlace = true;
state.InputVideoSync = "-1"; state.InputVideoSync = "-1";
state.InputAudioSync = "1"; state.InputAudioSync = "1";
@ -1430,7 +1414,7 @@ namespace MediaBrowser.Api.Playback
} }
state.ReadInputAtNativeFramerate = true; state.ReadInputAtNativeFramerate = true;
state.AudioSync = "1000"; state.OutputAudioSync = "1000";
state.DeInterlace = true; state.DeInterlace = true;
state.InputVideoSync = "-1"; state.InputVideoSync = "-1";
state.InputAudioSync = "1"; state.InputAudioSync = "1";
@ -1492,10 +1476,26 @@ namespace MediaBrowser.Api.Playback
state.SegmentLength = state.ReadInputAtNativeFramerate ? 5 : 10; state.SegmentLength = state.ReadInputAtNativeFramerate ? 5 : 10;
state.HlsListSize = state.ReadInputAtNativeFramerate ? 100 : 1440; state.HlsListSize = state.ReadInputAtNativeFramerate ? 100 : 1440;
var container = Path.GetExtension(state.RequestedUrl);
if (string.IsNullOrEmpty(container))
{
container = Path.GetExtension(GetOutputFilePath(state));
}
state.OutputContainer = (container ?? string.Empty).TrimStart('.');
ApplyDeviceProfileSettings(state); ApplyDeviceProfileSettings(state);
state.OutputContainer = GetOutputFileExtension(state).TrimStart('.');
state.OutputAudioBitrate = GetAudioBitrateParam(state.Request, state.AudioStream);
state.OutputAudioSampleRate = request.AudioSampleRate;
state.OutputAudioChannels = GetNumAudioChannelsParam(state.Request, state.AudioStream);
if (videoRequest != null) if (videoRequest != null)
{ {
state.OutputVideoBitrate = GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream);
if (state.VideoStream != null && CanStreamCopyVideo(videoRequest, state.VideoStream)) if (state.VideoStream != null && CanStreamCopyVideo(videoRequest, state.VideoStream))
{ {
videoRequest.VideoCodec = "copy"; videoRequest.VideoCodec = "copy";
@ -1649,13 +1649,6 @@ namespace MediaBrowser.Api.Playback
return; return;
} }
var container = Path.GetExtension(state.RequestedUrl);
if (string.IsNullOrEmpty(container))
{
container = Path.GetExtension(GetOutputFilePath(state));
}
var audioCodec = state.Request.AudioCodec; var audioCodec = state.Request.AudioCodec;
if (string.Equals(audioCodec, "copy", StringComparison.OrdinalIgnoreCase) && state.AudioStream != null) if (string.Equals(audioCodec, "copy", StringComparison.OrdinalIgnoreCase) && state.AudioStream != null)
@ -1671,8 +1664,8 @@ namespace MediaBrowser.Api.Playback
} }
var mediaProfile = state.VideoRequest == null ? var mediaProfile = state.VideoRequest == null ?
profile.GetAudioMediaProfile(container, audioCodec, state.AudioStream) : profile.GetAudioMediaProfile(state.OutputContainer, audioCodec, state.AudioStream) :
profile.GetVideoMediaProfile(container, audioCodec, videoCodec, state.AudioStream, state.VideoStream); profile.GetVideoMediaProfile(state.OutputContainer, audioCodec, videoCodec, state.AudioStream, state.VideoStream);
if (mediaProfile != null) if (mediaProfile != null)
{ {
@ -1681,8 +1674,8 @@ namespace MediaBrowser.Api.Playback
} }
var transcodingProfile = state.VideoRequest == null ? var transcodingProfile = state.VideoRequest == null ?
profile.GetAudioTranscodingProfile(container, audioCodec) : profile.GetAudioTranscodingProfile(state.OutputContainer, audioCodec) :
profile.GetVideoTranscodingProfile(container, audioCodec, videoCodec); profile.GetVideoTranscodingProfile(state.OutputContainer, audioCodec, videoCodec);
if (transcodingProfile != null) if (transcodingProfile != null)
{ {
@ -1710,9 +1703,6 @@ namespace MediaBrowser.Api.Playback
responseHeaders["transferMode.dlna.org"] = string.IsNullOrEmpty(transferMode) ? "Streaming" : transferMode; responseHeaders["transferMode.dlna.org"] = string.IsNullOrEmpty(transferMode) ? "Streaming" : transferMode;
responseHeaders["realTimeInfo.dlna.org"] = "DLNA.ORG_TLAG=*"; responseHeaders["realTimeInfo.dlna.org"] = "DLNA.ORG_TLAG=*";
var contentFeatures = string.Empty;
var extension = GetOutputFileExtension(state);
// 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 // 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
var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(state.RunTimeTicks.HasValue, isStaticallyStreamed, state.TranscodeSeekInfo); var orgOp = ";DLNA.ORG_OP=" + DlnaMaps.GetOrgOpValue(state.RunTimeTicks.HasValue, isStaticallyStreamed, state.TranscodeSeekInfo);
@ -1740,52 +1730,64 @@ namespace MediaBrowser.Api.Playback
var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}000000000000000000000000", var dlnaflags = string.Format(";DLNA.ORG_FLAGS={0}000000000000000000000000",
Enum.Format(typeof(DlnaFlags), flagValue, "x")); Enum.Format(typeof(DlnaFlags), flagValue, "x"));
if (!string.IsNullOrWhiteSpace(state.OrgPn)) var orgPn = GetOrgPnValue(state);
{
contentFeatures = "DLNA.ORG_PN=" + state.OrgPn; var contentFeatures = string.IsNullOrEmpty(orgPn) ? string.Empty :
} "DLNA.ORG_PN=" + orgPn;
else if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase))
{ if (!string.IsNullOrEmpty(contentFeatures))
contentFeatures = "DLNA.ORG_PN=MP3";
}
else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase))
{
contentFeatures = "DLNA.ORG_PN=AAC_ISO";
}
else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase))
{
contentFeatures = "DLNA.ORG_PN=WMABASE";
}
else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase))
{
contentFeatures = "DLNA.ORG_PN=AVI";
}
else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase))
{ {
contentFeatures = "DLNA.ORG_PN=MATROSKA"; responseHeaders["contentFeatures.dlna.org"] = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';');
} }
else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase))
foreach (var item in responseHeaders)
{ {
contentFeatures = "DLNA.ORG_PN=AVC_MP4_MP_HD_720p_AAC"; Request.Response.AddHeader(item.Key, item.Value);
} }
else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase)) }
private string GetOrgPnValue(StreamState state)
{
if (!string.IsNullOrWhiteSpace(state.OrgPn))
{ {
contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL"; return state.OrgPn;
} }
else if (string.Equals(extension, ".ts", StringComparison.OrdinalIgnoreCase))
if (state.VideoRequest == null)
{ {
contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL"; var format = new MediaFormatProfileResolver()
.ResolveAudioFormat(state.OutputContainer,
state.OutputAudioBitrate,
state.OutputAudioSampleRate,
state.OutputAudioChannels);
return format.HasValue ? format.Value.ToString() : null;
} }
if (!string.IsNullOrEmpty(contentFeatures)) var audioCodec = state.Request.AudioCodec;
if (string.Equals(audioCodec, "copy", StringComparison.OrdinalIgnoreCase) && state.AudioStream != null)
{ {
responseHeaders["contentFeatures.dlna.org"] = (contentFeatures + orgOp + orgCi + dlnaflags).Trim(';'); audioCodec = state.AudioStream.Codec;
} }
foreach (var item in responseHeaders) var videoCodec = state.VideoRequest == null ? null : state.VideoRequest.VideoCodec;
if (string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase) && state.VideoStream != null)
{ {
Request.Response.AddHeader(item.Key, item.Value); videoCodec = state.VideoStream.Codec;
} }
var videoFormat = new MediaFormatProfileResolver()
.ResolveVideoFormat(state.OutputContainer,
videoCodec,
audioCodec,
state.OutputWidth,
state.OutputHeight,
state.TotalOutputBitrate,
TransportStreamTimestamp.VALID);
return videoFormat.HasValue ? videoFormat.Value.ToString() : null;
} }
private void AddTimeSeekResponseHeaders(StreamState state, IDictionary<string, string> responseHeaders) private void AddTimeSeekResponseHeaders(StreamState state, IDictionary<string, string> responseHeaders)

@ -29,15 +29,6 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
} }
protected override string GetOutputFilePath(StreamState state)
{
var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath;
var outputFileExtension = GetOutputFileExtension(state);
return Path.Combine(folder, GetCommandLineArguments("dummy\\dummy", state, false).GetMD5() + (outputFileExtension ?? string.Empty).ToLower());
}
/// <summary> /// <summary>
/// Gets the audio arguments. /// Gets the audio arguments.
/// </summary> /// </summary>
@ -93,17 +84,6 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
var state = GetState(request, CancellationToken.None).Result; var state = GetState(request, CancellationToken.None).Result;
if (!state.VideoRequest.VideoBitRate.HasValue && (string.IsNullOrEmpty(state.VideoRequest.VideoCodec) || !string.Equals(state.VideoRequest.VideoCodec, "copy", StringComparison.OrdinalIgnoreCase)))
{
state.Dispose();
throw new ArgumentException("A video bitrate is required");
}
if (!state.Request.AudioBitRate.HasValue && (string.IsNullOrEmpty(state.Request.AudioCodec) || !string.Equals(state.Request.AudioCodec, "copy", StringComparison.OrdinalIgnoreCase)))
{
state.Dispose();
throw new ArgumentException("An audio bitrate is required");
}
var playlist = GetOutputFilePath(state); var playlist = GetOutputFilePath(state);
if (File.Exists(playlist)) if (File.Exists(playlist))
@ -192,8 +172,8 @@ namespace MediaBrowser.Api.Playback.Hls
/// <param name="videoBitrate">The video bitrate.</param> /// <param name="videoBitrate">The video bitrate.</param>
protected void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate) protected void GetPlaylistBitrates(StreamState state, out int audioBitrate, out int videoBitrate)
{ {
var audioBitrateParam = GetAudioBitrateParam(state); var audioBitrateParam = state.OutputAudioBitrate;
var videoBitrateParam = GetVideoBitrateParamValue(state); var videoBitrateParam = state.OutputVideoBitrate;
if (!audioBitrateParam.HasValue) if (!audioBitrateParam.HasValue)
{ {
@ -307,11 +287,10 @@ namespace MediaBrowser.Api.Playback.Hls
// If performSubtitleConversions is true we're actually starting ffmpeg // If performSubtitleConversions is true we're actually starting ffmpeg
var startNumberParam = performSubtitleConversions ? GetStartNumber(state).ToString(UsCulture) : "0"; var startNumberParam = performSubtitleConversions ? GetStartNumber(state).ToString(UsCulture) : "0";
var args = string.Format("{0} {1} -i {2}{3} -map_metadata -1 -threads {4} {5} {6} -sc_threshold 0 {7} -hls_time {8} -start_number {9} -hls_list_size {10} \"{11}\"", var args = string.Format("{0} {1} -i {2} -map_metadata -1 -threads {3} {4} {5} -sc_threshold 0 {6} -hls_time {7} -start_number {8} -hls_list_size {9} \"{10}\"",
itsOffset, itsOffset,
inputModifier, inputModifier,
GetInputArgument(state), GetInputArgument(state),
GetSlowSeekCommandLineParameter(state.Request),
threads, threads,
GetMapArgs(state), GetMapArgs(state),
GetVideoArguments(state, performSubtitleConversions), GetVideoArguments(state, performSubtitleConversions),

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
@ -64,17 +63,6 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
} }
protected override string GetOutputFilePath(StreamState state)
{
var folder = (state.MediaPath + state.Request.DeviceId).GetMD5().ToString("N");
folder = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, folder);
var outputFileExtension = GetOutputFileExtension(state);
return Path.Combine(folder, GetCommandLineArguments("dummy\\dummy", state, false).GetMD5() + (outputFileExtension ?? string.Empty).ToLower());
}
public object Get(GetMasterHlsVideoStream request) public object Get(GetMasterHlsVideoStream request)
{ {
var result = GetAsync(request).Result; var result = GetAsync(request).Result;
@ -136,15 +124,6 @@ namespace MediaBrowser.Api.Playback.Hls
{ {
var state = await GetState(request, CancellationToken.None).ConfigureAwait(false); var state = await GetState(request, CancellationToken.None).ConfigureAwait(false);
if (!state.VideoRequest.VideoBitRate.HasValue && (string.IsNullOrEmpty(state.VideoRequest.VideoCodec) || !string.Equals(state.VideoRequest.VideoCodec, "copy", StringComparison.OrdinalIgnoreCase)))
{
throw new ArgumentException("A video bitrate is required");
}
if (!state.Request.AudioBitRate.HasValue && (string.IsNullOrEmpty(state.Request.AudioCodec) || !string.Equals(state.Request.AudioCodec, "copy", StringComparison.OrdinalIgnoreCase)))
{
throw new ArgumentException("An audio bitrate is required");
}
int audioBitrate; int audioBitrate;
int videoBitrate; int videoBitrate;
GetPlaylistBitrates(state, out audioBitrate, out videoBitrate); GetPlaylistBitrates(state, out audioBitrate, out videoBitrate);
@ -260,14 +239,14 @@ namespace MediaBrowser.Api.Playback.Hls
if (state.AudioStream != null) if (state.AudioStream != null)
{ {
var channels = GetNumAudioChannelsParam(state.Request, state.AudioStream); var channels = state.OutputAudioChannels;
if (channels.HasValue) if (channels.HasValue)
{ {
args += " -ac " + channels.Value; args += " -ac " + channels.Value;
} }
var bitrate = GetAudioBitrateParam(state); var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue) if (bitrate.HasValue)
{ {

@ -126,14 +126,14 @@ namespace MediaBrowser.Api.Playback.Hls
if (state.AudioStream != null) if (state.AudioStream != null)
{ {
var channels = GetNumAudioChannelsParam(state.Request, state.AudioStream); var channels = state.OutputAudioChannels;
if (channels.HasValue) if (channels.HasValue)
{ {
args += " -ac " + channels.Value; args += " -ac " + channels.Value;
} }
var bitrate = GetAudioBitrateParam(state); var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue) if (bitrate.HasValue)
{ {

@ -82,23 +82,21 @@ namespace MediaBrowser.Api.Playback.Progressive
var audioTranscodeParams = new List<string>(); var audioTranscodeParams = new List<string>();
var bitrate = GetAudioBitrateParam(state); var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue) if (bitrate.HasValue)
{ {
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture)); audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
} }
var channels = GetNumAudioChannelsParam(request, state.AudioStream); if (state.OutputAudioChannels.HasValue)
if (channels.HasValue)
{ {
audioTranscodeParams.Add("-ac " + channels.Value); audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
} }
if (request.AudioSampleRate.HasValue) if (state.OutputAudioSampleRate.HasValue)
{ {
audioTranscodeParams.Add("-ar " + request.AudioSampleRate.Value); audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
} }
const string vn = " -vn"; const string vn = " -vn";
@ -107,10 +105,9 @@ namespace MediaBrowser.Api.Playback.Progressive
var inputModifier = GetInputModifier(state); var inputModifier = GetInputModifier(state);
return string.Format("{0} -i {1}{2} -threads {3}{4} {5} -id3v2_version 3 -write_id3v1 1 \"{6}\"", return string.Format("{0} -i {1} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1 \"{5}\"",
inputModifier, inputModifier,
GetInputArgument(state), GetInputArgument(state),
GetSlowSeekCommandLineParameter(request),
threads, threads,
vn, vn,
string.Join(" ", audioTranscodeParams.ToArray()), string.Join(" ", audioTranscodeParams.ToArray()),

@ -308,16 +308,7 @@ namespace MediaBrowser.Api.Playback.Progressive
/// <returns>System.Nullable{System.Int64}.</returns> /// <returns>System.Nullable{System.Int64}.</returns>
private long? GetEstimatedContentLength(StreamState state) private long? GetEstimatedContentLength(StreamState state)
{ {
var totalBitrate = 0; var totalBitrate = state.TotalOutputBitrate ?? 0;
if (state.Request.AudioBitRate.HasValue)
{
totalBitrate += state.Request.AudioBitRate.Value;
}
if (state.VideoRequest != null && state.VideoRequest.VideoBitRate.HasValue)
{
totalBitrate += state.VideoRequest.VideoBitRate.Value;
}
if (totalBitrate > 0 && state.RunTimeTicks.HasValue) if (totalBitrate > 0 && state.RunTimeTicks.HasValue)
{ {

@ -107,10 +107,9 @@ namespace MediaBrowser.Api.Playback.Progressive
var inputModifier = GetInputModifier(state); var inputModifier = GetInputModifier(state);
return string.Format("{0} -i {1}{2}{3} {4} {5} -map_metadata -1 -threads {6} {7}{8} \"{9}\"", return string.Format("{0} -i {1}{2} {3} {4} -map_metadata -1 -threads {5} {6}{7} \"{8}\"",
inputModifier, inputModifier,
GetInputArgument(state), GetInputArgument(state),
GetSlowSeekCommandLineParameter(state.Request),
keyFrame, keyFrame,
GetMapArgs(state), GetMapArgs(state),
GetVideoArguments(state, videoCodec, performSubtitleConversions), GetVideoArguments(state, videoCodec, performSubtitleConversions),
@ -204,14 +203,14 @@ namespace MediaBrowser.Api.Playback.Progressive
var args = "-acodec " + codec; var args = "-acodec " + codec;
// Add the number of audio channels // Add the number of audio channels
var channels = GetNumAudioChannelsParam(request, state.AudioStream); var channels = state.OutputAudioChannels;
if (channels.HasValue) if (channels.HasValue)
{ {
args += " -ac " + channels.Value; args += " -ac " + channels.Value;
} }
var bitrate = GetAudioBitrateParam(state); var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue) if (bitrate.HasValue)
{ {

@ -1,6 +1,7 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
@ -32,9 +33,7 @@ namespace MediaBrowser.Api.Playback
public Stream LogFileStream { get; set; } public Stream LogFileStream { get; set; }
public MediaStream AudioStream { get; set; } public MediaStream AudioStream { get; set; }
public MediaStream VideoStream { get; set; } public MediaStream VideoStream { get; set; }
public MediaStream SubtitleStream { get; set; } public MediaStream SubtitleStream { get; set; }
/// <summary> /// <summary>
@ -50,7 +49,6 @@ namespace MediaBrowser.Api.Playback
public bool IsInputVideo { get; set; } public bool IsInputVideo { get; set; }
public VideoType VideoType { get; set; } public VideoType VideoType { get; set; }
public IsoType? IsoType { get; set; } public IsoType? IsoType { get; set; }
public List<string> PlayableStreamFileNames { get; set; } public List<string> PlayableStreamFileNames { get; set; }
@ -64,8 +62,8 @@ namespace MediaBrowser.Api.Playback
public long? RunTimeTicks; public long? RunTimeTicks;
public string AudioSync = "1"; public string OutputAudioSync = "1";
public string VideoSync = "vfr"; public string OutputVideoSync = "vfr";
public List<string> SupportedAudioCodecs { get; set; } public List<string> SupportedAudioCodecs { get; set; }
@ -80,19 +78,14 @@ namespace MediaBrowser.Api.Playback
public string InputVideoSync { get; set; } public string InputVideoSync { get; set; }
public bool DeInterlace { get; set; } public bool DeInterlace { get; set; }
public bool ReadInputAtNativeFramerate { get; set; } public bool ReadInputAtNativeFramerate { get; set; }
public string InputFormat { get; set; } public string InputFormat { get; set; }
public string InputVideoCodec { get; set; } public string InputVideoCodec { get; set; }
public string InputAudioCodec { get; set; } public string InputAudioCodec { get; set; }
public string MimeType { get; set; } public string MimeType { get; set; }
public string OrgPn { get; set; } public string OrgPn { get; set; }
// DLNA Settings
public bool EstimateContentLength { get; set; } public bool EstimateContentLength { get; set; }
public bool EnableMpegtsM2TsMode { get; set; } public bool EnableMpegtsM2TsMode { get; set; }
public TranscodeSeekInfo TranscodeSeekInfo { get; set; } public TranscodeSeekInfo TranscodeSeekInfo { get; set; }
@ -162,5 +155,70 @@ namespace MediaBrowser.Api.Playback
} }
} }
} }
public int? OutputAudioChannels;
public int? OutputAudioSampleRate;
public int? OutputAudioBitrate;
public int? OutputVideoBitrate;
public string OutputContainer { get; set; }
public int? TotalOutputBitrate
{
get
{
return (OutputAudioBitrate ?? 0) + (OutputVideoBitrate ?? 0);
}
}
public int? OutputWidth
{
get
{
if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
{
var size = new ImageSize
{
Width = VideoStream.Width.Value,
Height = VideoStream.Height.Value
};
var newSize = DrawingUtils.Resize(size,
VideoRequest.Width,
VideoRequest.Height,
VideoRequest.MaxWidth,
VideoRequest.MaxHeight);
return Convert.ToInt32(newSize.Width);
}
return VideoRequest.MaxWidth ?? VideoRequest.Width;
}
}
public int? OutputHeight
{
get
{
if (VideoStream != null && VideoStream.Width.HasValue && VideoStream.Height.HasValue)
{
var size = new ImageSize
{
Width = VideoStream.Width.Value,
Height = VideoStream.Height.Value
};
var newSize = DrawingUtils.Resize(size,
VideoRequest.Width,
VideoRequest.Height,
VideoRequest.MaxWidth,
VideoRequest.MaxHeight);
return Convert.ToInt32(newSize.Height);
}
return VideoRequest.MaxHeight ?? VideoRequest.Height;
}
}
} }
} }

@ -630,24 +630,42 @@ namespace MediaBrowser.Dlna.Server
res.SetAttribute("bitrate", targetAudioBitrate.Value.ToString(_usCulture)); res.SetAttribute("bitrate", targetAudioBitrate.Value.ToString(_usCulture));
} }
var formatProfile = new MediaFormatProfileResolver().ResolveVideoFormat(streamInfo.Container, var mediaProfile = _profile.GetVideoMediaProfile(streamInfo.Container,
targetVideoCodec, streamInfo.AudioCodec,
targetAudioCodec, streamInfo.VideoCodec,
targetWidth, streamInfo.TargetAudioStream,
targetHeight, streamInfo.TargetVideoStream);
targetBitrate,
TransportStreamTimestamp.NONE); var formatProfile = mediaProfile == null ? null : mediaProfile.OrgPn;
if (string.IsNullOrEmpty(formatProfile))
{
var format = new MediaFormatProfileResolver().ResolveVideoFormat(streamInfo.Container,
targetVideoCodec,
targetAudioCodec,
targetWidth,
targetHeight,
targetBitrate,
TransportStreamTimestamp.VALID);
formatProfile = format.HasValue ? format.Value.ToString() : null;
}
var filename = url.Substring(0, url.IndexOf('?')); var filename = url.Substring(0, url.IndexOf('?'));
var mimeType = mediaProfile == null || string.IsNullOrEmpty(mediaProfile.MimeType)
? MimeTypes.GetMimeType(filename)
: mediaProfile.MimeType;
var orgOpValue = DlnaMaps.GetOrgOpValue(mediaSource.RunTimeTicks.HasValue, streamInfo.IsDirectStream, streamInfo.TranscodeSeekInfo); var orgOpValue = DlnaMaps.GetOrgOpValue(mediaSource.RunTimeTicks.HasValue, streamInfo.IsDirectStream, streamInfo.TranscodeSeekInfo);
var orgCi = streamInfo.IsDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; var orgCi = streamInfo.IsDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
var orgPn = !string.IsNullOrEmpty(formatProfile) ? "DLNA.ORG_PN=:" + formatProfile + ";" : string.Empty;
res.SetAttribute("protocolInfo", String.Format( res.SetAttribute("protocolInfo", String.Format(
"http-get:*:{0}:DLNA.ORG_PN={1};DLNA.ORG_OP={2};DLNA.ORG_CI={3};DLNA.ORG_FLAGS={4}", "http-get:*:{0}:{1}DLNA.ORG_OP={2};DLNA.ORG_CI={3};DLNA.ORG_FLAGS={4}",
MimeTypes.GetMimeType(filename), mimeType,
formatProfile, orgPn,
orgOpValue, orgOpValue,
orgCi, orgCi,
DlnaMaps.DefaultStreaming DlnaMaps.DefaultStreaming
@ -712,18 +730,36 @@ namespace MediaBrowser.Dlna.Server
res.SetAttribute("bitrate", targetAudioBitrate.Value.ToString(_usCulture)); res.SetAttribute("bitrate", targetAudioBitrate.Value.ToString(_usCulture));
} }
var formatProfile = new MediaFormatProfileResolver().ResolveAudioFormat(streamInfo.Container, targetAudioBitrate, targetSampleRate, targetChannels); var mediaProfile = _profile.GetAudioMediaProfile(streamInfo.Container,
streamInfo.AudioCodec,
streamInfo.TargetAudioStream);
var formatProfile = mediaProfile == null ? null : mediaProfile.OrgPn;
if (string.IsNullOrEmpty(formatProfile))
{
var format = new MediaFormatProfileResolver().ResolveAudioFormat(streamInfo.Container,
targetAudioBitrate, targetSampleRate, targetChannels);
formatProfile = format.HasValue ? format.Value.ToString() : null;
}
var filename = url.Substring(0, url.IndexOf('?')); var filename = url.Substring(0, url.IndexOf('?'));
var mimeType = mediaProfile == null || string.IsNullOrEmpty(mediaProfile.MimeType)
? MimeTypes.GetMimeType(filename)
: mediaProfile.MimeType;
var orgOpValue = DlnaMaps.GetOrgOpValue(mediaSource.RunTimeTicks.HasValue, streamInfo.IsDirectStream, streamInfo.TranscodeSeekInfo); var orgOpValue = DlnaMaps.GetOrgOpValue(mediaSource.RunTimeTicks.HasValue, streamInfo.IsDirectStream, streamInfo.TranscodeSeekInfo);
var orgCi = streamInfo.IsDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1"; var orgCi = streamInfo.IsDirectStream ? ";DLNA.ORG_CI=0" : ";DLNA.ORG_CI=1";
var orgPn = !string.IsNullOrEmpty(formatProfile) ? "DLNA.ORG_PN=:" + formatProfile + ";" : string.Empty;
res.SetAttribute("protocolInfo", String.Format( res.SetAttribute("protocolInfo", String.Format(
"http-get:*:{0}:DLNA.ORG_PN={1};DLNA.ORG_OP={2};DLNA.ORG_CI={3};DLNA.ORG_FLAGS={4}", "http-get:*:{0}:{1}DLNA.ORG_OP={2};DLNA.ORG_CI={3};DLNA.ORG_FLAGS={4}",
MimeTypes.GetMimeType(filename), mimeType,
formatProfile, orgPn,
orgOpValue, orgOpValue,
orgCi, orgCi,
DlnaMaps.DefaultStreaming DlnaMaps.DefaultStreaming
@ -815,7 +851,7 @@ namespace MediaBrowser.Dlna.Server
} }
element.AppendChild(CreateObjectClass(element.OwnerDocument, item)); element.AppendChild(CreateObjectClass(element.OwnerDocument, item));
if (filter.Contains("dc:date")) if (filter.Contains("dc:date"))
{ {
if (item.PremiereDate.HasValue) if (item.PremiereDate.HasValue)
@ -962,9 +998,13 @@ namespace MediaBrowser.Dlna.Server
var mediaProfile = new MediaFormatProfileResolver().ResolveImageFormat("jpg", width, height); var mediaProfile = new MediaFormatProfileResolver().ResolveImageFormat("jpg", width, height);
var orgPn = mediaProfile.HasValue ? "DLNA.ORG_PN=:" + mediaProfile.Value + ";" : string.Empty;
res.SetAttribute("protocolInfo", string.Format( res.SetAttribute("protocolInfo", string.Format(
"http-get:*:{1}DLNA.ORG_PN=:{0};DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS={2}", "http-get:*:{1}:{0}DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS={2}",
mediaProfile, "image/jpeg", DlnaMaps.DefaultStreaming orgPn,
"image/jpeg",
DlnaMaps.DefaultStreaming
)); ));
if (width.HasValue && height.HasValue) if (width.HasValue && height.HasValue)

@ -262,31 +262,31 @@ namespace MediaBrowser.MediaEncoding.Encoder
videoCodec = state.VideoStream.Codec; videoCodec = state.VideoStream.Codec;
} }
var mediaProfile = state.VideoRequest == null ? //var mediaProfile = state.VideoRequest == null ?
profile.GetAudioMediaProfile(container, audioCodec, state.AudioStream) : // profile.GetAudioMediaProfile(container, audioCodec) :
profile.GetVideoMediaProfile(container, audioCodec, videoCodec, state.AudioStream, state.VideoStream); // profile.GetVideoMediaProfile(container, audioCodec, videoCodec, state.AudioStream, state.VideoStream);
if (mediaProfile != null) //if (mediaProfile != null)
{ //{
state.MimeType = mediaProfile.MimeType; // state.MimeType = mediaProfile.MimeType;
state.OrgPn = mediaProfile.OrgPn; // state.OrgPn = mediaProfile.OrgPn;
} //}
var transcodingProfile = state.VideoRequest == null ? //var transcodingProfile = state.VideoRequest == null ?
profile.GetAudioTranscodingProfile(container, audioCodec) : // profile.GetAudioTranscodingProfile(container, audioCodec) :
profile.GetVideoTranscodingProfile(container, audioCodec, videoCodec); // profile.GetVideoTranscodingProfile(container, audioCodec, videoCodec);
if (transcodingProfile != null) //if (transcodingProfile != null)
{ //{
//state.EstimateContentLength = transcodingProfile.EstimateContentLength; // //state.EstimateContentLength = transcodingProfile.EstimateContentLength;
state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode; // state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode;
//state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; // //state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
if (state.VideoRequest != null && string.IsNullOrWhiteSpace(state.VideoRequest.VideoProfile)) // if (state.VideoRequest != null && string.IsNullOrWhiteSpace(state.VideoRequest.VideoProfile))
{ // {
state.VideoRequest.VideoProfile = transcodingProfile.VideoProfile; // state.VideoRequest.VideoProfile = transcodingProfile.VideoProfile;
} // }
} //}
} }
private EncodingQuality GetQualitySetting() private EncodingQuality GetQualitySetting()

@ -1,39 +1,60 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Model.Dlna namespace MediaBrowser.Model.Dlna
{ {
public class MediaFormatProfileResolver public class MediaFormatProfileResolver
{ {
public MediaFormatProfile ResolveVideoFormat(string container, string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestampType) public MediaFormatProfile? ResolveVideoFormat(string container, string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestampType)
{ {
if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))
return ResolveVideoASFFormat(videoCodec, audioCodec, width, height, bitrate); return ResolveVideoASFFormat(videoCodec, audioCodec, width, height);
if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase))
return ResolveVideoMP4Format(videoCodec, audioCodec, width, height, bitrate); return ResolveVideoMP4Format(videoCodec, audioCodec, width, height, bitrate);
if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "avi", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.AVI; return MediaFormatProfile.AVI;
if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "mkv", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.MATROSKA; return MediaFormatProfile.MATROSKA;
if (string.Equals(container, "mpeg2ps", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
if (string.Equals(container, "mpeg2ps", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "ts", StringComparison.OrdinalIgnoreCase))
// MediaFormatProfile.MPEG_PS_PAL, MediaFormatProfile.MPEG_PS_NTSC // MediaFormatProfile.MPEG_PS_PAL, MediaFormatProfile.MPEG_PS_NTSC
return MediaFormatProfile.MPEG_PS_NTSC; return MediaFormatProfile.MPEG_PS_NTSC;
if (string.Equals(container, "mpeg1video", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "mpeg1video", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.MPEG1; return MediaFormatProfile.MPEG1;
if (string.Equals(container, "mpeg2ts", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "m2ts", StringComparison.OrdinalIgnoreCase))
return ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, bitrate, timestampType); if (string.Equals(container, "mpeg2ts", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "m2ts", StringComparison.OrdinalIgnoreCase))
{
var list = ResolveVideoMPEG2TSFormat(videoCodec, audioCodec, width, height, bitrate, timestampType)
.ToList();
return list.Count > 0 ? list[0] : (MediaFormatProfile?)null;
}
if (string.Equals(container, "flv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "flv", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.FLV; return MediaFormatProfile.FLV;
if (string.Equals(container, "wtv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "wtv", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.WTV; return MediaFormatProfile.WTV;
if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "3gp", StringComparison.OrdinalIgnoreCase))
return ResolveVideo3GPFormat(videoCodec, audioCodec, width, height, bitrate); return ResolveVideo3GPFormat(videoCodec, audioCodec);
if (string.Equals(container, "ogv", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "ogv", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.OGV; return MediaFormatProfile.OGV;
throw new ArgumentException("Unsupported container: " + container); return null;
} }
private MediaFormatProfile ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestampType) private IEnumerable<MediaFormatProfile> ResolveVideoMPEG2TSFormat(string videoCodec, string audioCodec, int? width, int? height, int? bitrate, TransportStreamTimestamp timestampType)
{ {
var suffix = ""; var suffix = "";
@ -47,48 +68,59 @@ namespace MediaBrowser.Model.Dlna
break; break;
} }
String resolution = "S"; var resolution = "S";
if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576)) if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
{ {
resolution = "H"; resolution = "H";
} }
// if (videoCodec == VideoCodec.MPEG2) if (string.Equals(videoCodec, "mpeg2video", StringComparison.OrdinalIgnoreCase))
// { {
// List!(MediaFormatProfile) profiles = Arrays.asList(cast(MediaFormatProfile[])[ MediaFormatProfile.valueOf("MPEG_TS_SD_EU" + suffix), MediaFormatProfile.valueOf("MPEG_TS_SD_NA" + suffix), MediaFormatProfile.valueOf("MPEG_TS_SD_KO" + suffix) ]); var list = new List<MediaFormatProfile>();
list.Add(ValueOf("MPEG_TS_SD_NA" + suffix));
list.Add(ValueOf("MPEG_TS_SD_EU" + suffix));
list.Add(ValueOf("MPEG_TS_SD_KO" + suffix));
// if ((timestampType == TransportStreamTimestamp.VALID) && (audioCodec == AudioCodec.AAC)) { if ((timestampType == TransportStreamTimestamp.VALID) && string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
// profiles.add(MediaFormatProfile.MPEG_TS_JP_T); {
// } list.Add(MediaFormatProfile.MPEG_TS_JP_T);
// return profiles; }
// } return list;
}
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{ {
if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase)) if (string.Equals(audioCodec, "lpcm", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.AVC_TS_HD_50_LPCM_T; return new[] { MediaFormatProfile.AVC_TS_HD_50_LPCM_T };
if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase)) if (string.Equals(audioCodec, "dts", StringComparison.OrdinalIgnoreCase))
{ {
if (timestampType == TransportStreamTimestamp.NONE) if (timestampType == TransportStreamTimestamp.NONE)
{ {
return MediaFormatProfile.AVC_TS_HD_DTS_ISO; return new[] { MediaFormatProfile.AVC_TS_HD_DTS_ISO };
} }
return MediaFormatProfile.AVC_TS_HD_DTS_T; return new[] { MediaFormatProfile.AVC_TS_HD_DTS_T };
} }
//if (audioCodec == AudioCodec.MP2) {
// if (isNoTimestamp(timestampType)) { if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
// return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_HP_%sD_MPEG1_L2_ISO", cast(Object[])[ resolution ]))); {
// } if (timestampType == TransportStreamTimestamp.NONE)
// return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_HP_%sD_MPEG1_L2_T", cast(Object[])[ resolution ]))); {
//} return new[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_ISO", resolution)) };
}
//if (audioCodec == AudioCodec.AAC)
// return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_MP_%sD_AAC_MULT5%s", cast(Object[])[ resolution, suffix ]))); return new[] { ValueOf(string.Format("AVC_TS_HP_{0}D_MPEG1_L2_T", resolution)) };
//if (audioCodec == AudioCodec.MP3) }
// return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_MP_%sD_MPEG1_L3%s", cast(Object[])[ resolution, suffix ])));
//if ((audioCodec is null) || (audioCodec == AudioCodec.AC3)) { if (string.Equals(audioCodec, "aac", StringComparison.OrdinalIgnoreCase))
// return Collections.singletonList(MediaFormatProfile.valueOf(String.format("AVC_TS_MP_%sD_AC3%s", cast(Object[])[ resolution, suffix ]))); return new[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AAC_MULT5{1}", resolution, suffix)) };
//}
if (string.Equals(audioCodec, "mp3", StringComparison.OrdinalIgnoreCase))
return new[] { ValueOf(string.Format("AVC_TS_MP_{0}D_MPEG1_L3{1}", resolution, suffix)) };
if (string.IsNullOrEmpty(audioCodec) ||
string.Equals(audioCodec, "ac3", StringComparison.OrdinalIgnoreCase))
return new[] { ValueOf(string.Format("AVC_TS_MP_{0}D_AC3{1}", resolution, suffix)) };
} }
else if (string.Equals(videoCodec, "vc1", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(videoCodec, "vc1", StringComparison.OrdinalIgnoreCase))
{ {
@ -96,9 +128,9 @@ namespace MediaBrowser.Model.Dlna
{ {
if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576)) if ((width.HasValue && width.Value > 720) || (height.HasValue && height.Value > 576))
{ {
return MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO; return new[] { MediaFormatProfile.VC1_TS_AP_L2_AC3_ISO };
} }
return MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO; return new[] { MediaFormatProfile.VC1_TS_AP_L1_AC3_ISO };
} }
// if (audioCodec == AudioCodec.DTS) { // if (audioCodec == AudioCodec.DTS) {
// suffix = suffix.equals("_ISO") ? suffix : "_T"; // suffix = suffix.equals("_ISO") ? suffix : "_T";
@ -116,10 +148,15 @@ namespace MediaBrowser.Model.Dlna
// } // }
} }
throw new ArgumentException("Mpeg video file does not match any supported DLNA profile"); return new List<MediaFormatProfile>();
}
private MediaFormatProfile ValueOf(string value)
{
return (MediaFormatProfile)Enum.Parse(typeof(MediaFormatProfile), value, true);
} }
private MediaFormatProfile ResolveVideoMP4Format(string videoCodec, string audioCodec, int? width, int? height, int? bitrate) private MediaFormatProfile? ResolveVideoMP4Format(string videoCodec, string audioCodec, int? width, int? height, int? bitrate)
{ {
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{ {
@ -177,10 +214,10 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.MPEG4_H263_MP4_P0_L10_AAC; return MediaFormatProfile.MPEG4_H263_MP4_P0_L10_AAC;
} }
throw new ArgumentException("MP4 video file does not match any supported DLNA profile"); return null;
} }
private MediaFormatProfile ResolveVideo3GPFormat(string videoCodec, string audioCodec, int? width, int? height, int? bitrate) private MediaFormatProfile? ResolveVideo3GPFormat(string videoCodec, string audioCodec)
{ {
if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase))
{ {
@ -200,9 +237,10 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.MPEG4_H263_3GPP_P0_L10_AMR; return MediaFormatProfile.MPEG4_H263_3GPP_P0_L10_AMR;
} }
throw new ArgumentException("3GP video file does not match any supported DLNA profile"); return null;
} }
private MediaFormatProfile ResolveVideoASFFormat(string videoCodec, string audioCodec, int? width, int? height, int? bitrate)
private MediaFormatProfile? ResolveVideoASFFormat(string videoCodec, string audioCodec, int? width, int? height)
{ {
if (string.Equals(videoCodec, "wmv", StringComparison.OrdinalIgnoreCase) && if (string.Equals(videoCodec, "wmv", StringComparison.OrdinalIgnoreCase) &&
(string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "wma", StringComparison.OrdinalIgnoreCase) || string.Equals(videoCodec, "wmapro", StringComparison.OrdinalIgnoreCase))) (string.IsNullOrEmpty(audioCodec) || string.Equals(audioCodec, "wma", StringComparison.OrdinalIgnoreCase) || string.Equals(videoCodec, "wmapro", StringComparison.OrdinalIgnoreCase)))
@ -244,29 +282,38 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.DVR_MS; return MediaFormatProfile.DVR_MS;
} }
throw new ArgumentException("ASF video file does not match any supported DLNA profile"); return null;
} }
public MediaFormatProfile ResolveAudioFormat(string container, int? bitrate, int? frequency, int? channels) public MediaFormatProfile? ResolveAudioFormat(string container, int? bitrate, int? frequency, int? channels)
{ {
if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "asf", StringComparison.OrdinalIgnoreCase))
return ResolveAudioASFFormat(bitrate, frequency, channels); return ResolveAudioASFFormat(bitrate);
if (string.Equals(container, "mp3", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "mp3", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.MP3; return MediaFormatProfile.MP3;
if (string.Equals(container, "lpcm", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "lpcm", StringComparison.OrdinalIgnoreCase))
return ResolveAudioLPCMFormat(bitrate, frequency, channels); return ResolveAudioLPCMFormat(frequency, channels);
if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase))
return ResolveAudioMP4Format(bitrate, frequency, channels); if (string.Equals(container, "mp4", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "aac", StringComparison.OrdinalIgnoreCase))
return ResolveAudioMP4Format(bitrate);
if (string.Equals(container, "adts", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "adts", StringComparison.OrdinalIgnoreCase))
return ResolveAudioADTSFormat(bitrate, frequency, channels); return ResolveAudioADTSFormat(bitrate);
if (string.Equals(container, "flac", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "flac", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.FLAC; return MediaFormatProfile.FLAC;
if (string.Equals(container, "oga", StringComparison.OrdinalIgnoreCase) || string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
if (string.Equals(container, "oga", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "ogg", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.OGG; return MediaFormatProfile.OGG;
throw new ArgumentException("Unsupported container: " + container);
return null;
} }
private MediaFormatProfile ResolveAudioASFFormat(int? bitrate, int? frequency, int? channels) private MediaFormatProfile ResolveAudioASFFormat(int? bitrate)
{ {
if (bitrate.HasValue && bitrate.Value <= 193) if (bitrate.HasValue && bitrate.Value <= 193)
{ {
@ -275,7 +322,7 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.WMA_FULL; return MediaFormatProfile.WMA_FULL;
} }
private MediaFormatProfile ResolveAudioLPCMFormat(int? bitrate, int? frequency, int? channels) private MediaFormatProfile? ResolveAudioLPCMFormat(int? frequency, int? channels)
{ {
if (frequency.HasValue && channels.HasValue) if (frequency.HasValue && channels.HasValue)
{ {
@ -296,13 +343,13 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.LPCM16_48_STEREO; return MediaFormatProfile.LPCM16_48_STEREO;
} }
throw new ArgumentException("Unsupported LPCM format of file %s. Only 44100 / 48000 Hz and Mono / Stereo files are allowed."); return null;
} }
return MediaFormatProfile.LPCM16_48_STEREO; return MediaFormatProfile.LPCM16_48_STEREO;
} }
private MediaFormatProfile ResolveAudioMP4Format(int? bitrate, int? frequency, int? channels) private MediaFormatProfile ResolveAudioMP4Format(int? bitrate)
{ {
if (bitrate.HasValue && bitrate.Value <= 320) if (bitrate.HasValue && bitrate.Value <= 320)
{ {
@ -311,7 +358,7 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.AAC_ISO; return MediaFormatProfile.AAC_ISO;
} }
private MediaFormatProfile ResolveAudioADTSFormat(int? bitrate, int? frequency, int? channels) private MediaFormatProfile ResolveAudioADTSFormat(int? bitrate)
{ {
if (bitrate.HasValue && bitrate.Value <= 320) if (bitrate.HasValue && bitrate.Value <= 320)
{ {
@ -320,19 +367,22 @@ namespace MediaBrowser.Model.Dlna
return MediaFormatProfile.AAC_ADTS; return MediaFormatProfile.AAC_ADTS;
} }
public MediaFormatProfile ResolveImageFormat(string container, int? width, int? height) public MediaFormatProfile? ResolveImageFormat(string container, int? width, int? height)
{ {
if (string.Equals(container, "jpeg", StringComparison.OrdinalIgnoreCase) || if (string.Equals(container, "jpeg", StringComparison.OrdinalIgnoreCase) ||
string.Equals(container, "jpg", StringComparison.OrdinalIgnoreCase)) string.Equals(container, "jpg", StringComparison.OrdinalIgnoreCase))
return ResolveImageJPGFormat(width, height); return ResolveImageJPGFormat(width, height);
if (string.Equals(container, "png", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "png", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.PNG_LRG; return MediaFormatProfile.PNG_LRG;
if (string.Equals(container, "gif", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "gif", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.GIF_LRG; return MediaFormatProfile.GIF_LRG;
if (string.Equals(container, "raw", StringComparison.OrdinalIgnoreCase)) if (string.Equals(container, "raw", StringComparison.OrdinalIgnoreCase))
return MediaFormatProfile.RAW; return MediaFormatProfile.RAW;
throw new ArgumentException("Unsupported container: " + container); return null;
} }
private MediaFormatProfile ResolveImageJPGFormat(int? width, int? height) private MediaFormatProfile ResolveImageJPGFormat(int? width, int? height)

Loading…
Cancel
Save