update stream selection

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

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

@ -227,7 +227,7 @@ namespace MediaBrowser.Api.Playback
SetDeviceSpecificData(item, mediaSource, profile, auth, maxBitrate, startTimeTicks, mediaSourceId, audioStreamIndex, subtitleStreamIndex, result.PlaySessionId);
}
SortMediaSources(result);
SortMediaSources(result, maxBitrate);
}
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();
@ -409,6 +409,23 @@ namespace MediaBrowser.Api.Playback
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)
.ToList();
}

@ -55,7 +55,7 @@ namespace MediaBrowser.Model.Dlna
stream.DeviceProfileId = options.Profile.Id;
}
return GetOptimalStream(streams);
return GetOptimalStream(streams, options.GetMaxBitrate());
}
public StreamInfo BuildVideoItem(VideoOptions options)
@ -88,12 +88,12 @@ namespace MediaBrowser.Model.Dlna
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)
{
@ -424,7 +424,7 @@ namespace MediaBrowser.Model.Dlna
playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength;
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 inputAudioCodec = audioStream == null ? null : audioStream.Codec;
foreach (string supportedAudioCodec in supportedAudioCodecs)

@ -7,7 +7,7 @@ namespace MediaBrowser.Model.Dlna
{
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 =>
{
@ -41,6 +41,23 @@ namespace MediaBrowser.Model.Dlna
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();
}
}

@ -246,6 +246,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
string audioCodec = "ac3";
int? videoBitrate = null;
int? audioBitrate = null;
if (string.Equals(profile, "mobile", StringComparison.OrdinalIgnoreCase))
{
@ -306,6 +307,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
audioCodec = channel.AudioCodec;
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
Index = -1,
Codec = audioCodec,
BitRate = 192000
BitRate = audioBitrate
}
},
RequiresOpening = false,

Loading…
Cancel
Save