The Free Software Media System - Server Backend & API
update stream selection
Luke Pulverenti57e3bb72f93b
diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.csindex 610628ced9..5f427146e3 100644--- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs+++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs@@ -86,11 +86,10 @@ namespace MediaBrowser.Api.Playback.Hls// See if we can save come cpu cycles by avoiding encodingif (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));diff --git a/MediaBrowser.Api/Playback/MediaInfoService.cs b/MediaBrowser.Api/Playback/MediaInfoService.csindex 2bf61f90bd..ffe7c50c8e 100644--- a/MediaBrowser.Api/Playback/MediaInfoService.cs+++ b/MediaBrowser.Api/Playback/MediaInfoService.cs@@ -227,7 +227,7 @@ namespace MediaBrowser.Api.PlaybackSetDeviceSpecificData(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.Playbackreturn 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();}diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.csindex 09d762aaef..1e6b7c729d 100644--- a/MediaBrowser.Model/Dlna/StreamBuilder.cs+++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs@@ -55,7 +55,7 @@ namespace MediaBrowser.Model.Dlnastream.DeviceProfileId = options.Profile.Id;}- return GetOptimalStream(streams);+ return GetOptimalStream(streams, options.GetMaxBitrate());}public StreamInfo BuildVideoItem(VideoOptions options)@@ -88,12 +88,12 @@ namespace MediaBrowser.Model.Dlnastream.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.DlnaplaylistItem.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 waystring[] supportedAudioCodecs = transcodingProfile.AudioCodec.Split(',');string inputAudioCodec = audioStream == null ? null : audioStream.Codec;foreach (string supportedAudioCodec in supportedAudioCodecs)diff --git a/MediaBrowser.Model/Dlna/StreamInfoSorter.cs b/MediaBrowser.Model/Dlna/StreamInfoSorter.csindex 0cccd80804..293054e5b3 100644--- a/MediaBrowser.Model/Dlna/StreamInfoSorter.cs+++ b/MediaBrowser.Model/Dlna/StreamInfoSorter.cs@@ -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.Dlnareturn 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();}}diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.csindex 638b4b9afe..3499fad413 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs@@ -246,6 +246,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerunstring 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.HdHomerunaudioCodec = 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 containerIndex = -1,Codec = audioCodec,- BitRate = 192000+ BitRate = audioBitrate}},RequiresOpening = false,