update stream selection

pull/702/head
Luke Pulverenti 9 years ago
parent e34dc6701b
commit 57e3bb72f9

@ -86,9 +86,8 @@ namespace MediaBrowser.Api.Playback.Hls
// See if we can save come cpu cycles by avoiding encoding // See if we can save come cpu cycles by avoiding encoding
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase)) if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
{ {
return state.VideoStream != null && IsH264(state.VideoStream) ? // if h264_mp4toannexb is ever added, do not use it for live tv
args + " -bsf:v h264_mp4toannexb" : return args;
args;
} }
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"", var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",

@ -227,7 +227,7 @@ namespace MediaBrowser.Api.Playback
SetDeviceSpecificData(item, mediaSource, profile, auth, maxBitrate, startTimeTicks, mediaSourceId, audioStreamIndex, subtitleStreamIndex, result.PlaySessionId); SetDeviceSpecificData(item, mediaSource, profile, auth, maxBitrate, startTimeTicks, mediaSourceId, audioStreamIndex, subtitleStreamIndex, result.PlaySessionId);
} }
SortMediaSources(result); SortMediaSources(result, maxBitrate);
} }
private void SetDeviceSpecificData(BaseItem item, private void SetDeviceSpecificData(BaseItem item,
@ -375,7 +375,7 @@ namespace MediaBrowser.Api.Playback
} }
} }
private void SortMediaSources(PlaybackInfoResponse result) private void SortMediaSources(PlaybackInfoResponse result, int? maxBitrate)
{ {
var originalList = result.MediaSources.ToList(); var originalList = result.MediaSources.ToList();
@ -409,6 +409,23 @@ namespace MediaBrowser.Api.Playback
return 1; return 1;
} }
}).ThenBy(i =>
{
if (maxBitrate.HasValue)
{
if (i.Bitrate.HasValue)
{
if (i.Bitrate.Value <= maxBitrate.Value)
{
return 0;
}
return 2;
}
}
return 1;
}).ThenBy(originalList.IndexOf) }).ThenBy(originalList.IndexOf)
.ToList(); .ToList();
} }

@ -55,7 +55,7 @@ namespace MediaBrowser.Model.Dlna
stream.DeviceProfileId = options.Profile.Id; stream.DeviceProfileId = options.Profile.Id;
} }
return GetOptimalStream(streams); return GetOptimalStream(streams, options.GetMaxBitrate());
} }
public StreamInfo BuildVideoItem(VideoOptions options) public StreamInfo BuildVideoItem(VideoOptions options)
@ -88,12 +88,12 @@ namespace MediaBrowser.Model.Dlna
stream.DeviceProfileId = options.Profile.Id; stream.DeviceProfileId = options.Profile.Id;
} }
return GetOptimalStream(streams); return GetOptimalStream(streams, options.GetMaxBitrate());
} }
private StreamInfo GetOptimalStream(List<StreamInfo> streams) private StreamInfo GetOptimalStream(List<StreamInfo> streams, int? maxBitrate)
{ {
streams = StreamInfoSorter.SortMediaSources(streams); streams = StreamInfoSorter.SortMediaSources(streams, maxBitrate);
foreach (StreamInfo stream in streams) foreach (StreamInfo stream in streams)
{ {
@ -424,7 +424,7 @@ namespace MediaBrowser.Model.Dlna
playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength; playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
// TODO: We should probably preserve the full list and sent it tp the server that way // TODO: We should probably preserve the full list and sent it to the server that way
string[] supportedAudioCodecs = transcodingProfile.AudioCodec.Split(','); string[] supportedAudioCodecs = transcodingProfile.AudioCodec.Split(',');
string inputAudioCodec = audioStream == null ? null : audioStream.Codec; string inputAudioCodec = audioStream == null ? null : audioStream.Codec;
foreach (string supportedAudioCodec in supportedAudioCodecs) foreach (string supportedAudioCodec in supportedAudioCodecs)

@ -7,7 +7,7 @@ namespace MediaBrowser.Model.Dlna
{ {
public class StreamInfoSorter public class StreamInfoSorter
{ {
public static List<StreamInfo> SortMediaSources(List<StreamInfo> streams) public static List<StreamInfo> SortMediaSources(List<StreamInfo> streams, int? maxBitrate)
{ {
return streams.OrderBy(i => return streams.OrderBy(i =>
{ {
@ -41,6 +41,23 @@ namespace MediaBrowser.Model.Dlna
return 1; return 1;
} }
}).ThenBy(i =>
{
if (maxBitrate.HasValue)
{
if (i.MediaSource.Bitrate.HasValue)
{
if (i.MediaSource.Bitrate.Value <= maxBitrate.Value)
{
return 0;
}
return 2;
}
}
return 1;
}).ToList(); }).ToList();
} }
} }

@ -246,6 +246,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
string audioCodec = "ac3"; string audioCodec = "ac3";
int? videoBitrate = null; int? videoBitrate = null;
int? audioBitrate = null;
if (string.Equals(profile, "mobile", StringComparison.OrdinalIgnoreCase)) if (string.Equals(profile, "mobile", StringComparison.OrdinalIgnoreCase))
{ {
@ -306,6 +307,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
audioCodec = channel.AudioCodec; audioCodec = channel.AudioCodec;
videoBitrate = (channel.IsHD ?? true) ? 15000000 : 2000000; videoBitrate = (channel.IsHD ?? true) ? 15000000 : 2000000;
audioBitrate = (channel.IsHD ?? true) ? 448000 : 192000;
} }
} }
@ -346,7 +348,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
// Set the index to -1 because we don't know the exact index of the audio stream within the container // Set the index to -1 because we don't know the exact index of the audio stream within the container
Index = -1, Index = -1,
Codec = audioCodec, Codec = audioCodec,
BitRate = 192000 BitRate = audioBitrate
} }
}, },
RequiresOpening = false, RequiresOpening = false,

Loading…
Cancel
Save