The Free Software Media System - Server Backend & API
adjust live tv stream selection
Luke Pulverenti477a182efd63
diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.csindex 4ee0565f9b..53eb18e7a8 100644--- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs+++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs@@ -158,9 +158,10 @@ namespace MediaBrowser.Controller.LiveTv/// Gets the channel stream./// </summary>/// <param name="id">The identifier.</param>+ /// <param name="mediaSourceId">The media source identifier.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task{StreamResponseInfo}.</returns>- Task<MediaSourceInfo> GetChannelStream(string id, CancellationToken cancellationToken);+ Task<MediaSourceInfo> GetChannelStream(string id, string mediaSourceId, CancellationToken cancellationToken);/// <summary>/// Gets the program.diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.csindex f60a219875..48ad3505a1 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs@@ -330,12 +330,12 @@ namespace MediaBrowser.Server.Implementations.LiveTvpublic async Task<MediaSourceInfo> GetRecordingStream(string id, CancellationToken cancellationToken){- return await GetLiveStream(id, false, cancellationToken).ConfigureAwait(false);+ return await GetLiveStream(id, null, false, cancellationToken).ConfigureAwait(false);}- public async Task<MediaSourceInfo> GetChannelStream(string id, CancellationToken cancellationToken)+ public async Task<MediaSourceInfo> GetChannelStream(string id, string mediaSourceId, CancellationToken cancellationToken){- return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false);+ return await GetLiveStream(id, mediaSourceId, true, cancellationToken).ConfigureAwait(false);}public async Task<IEnumerable<MediaSourceInfo>> GetRecordingMediaSources(string id, CancellationToken cancellationToken)@@ -364,7 +364,7 @@ namespace MediaBrowser.Server.Implementations.LiveTvreturn _services.FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase));}- private async Task<MediaSourceInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken)+ private async Task<MediaSourceInfo> GetLiveStream(string id, string mediaSourceId, bool isChannel, CancellationToken cancellationToken){await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);@@ -379,7 +379,7 @@ namespace MediaBrowser.Server.Implementations.LiveTvisVideo = channel.ChannelType == ChannelType.TV;var service = GetService(channel);_logger.Info("Opening channel stream from {0}, external channel Id: {1}", service.Name, channel.ExternalId);- info = await service.GetChannelStream(channel.ExternalId, null, cancellationToken).ConfigureAwait(false);+ info = await service.GetChannelStream(channel.ExternalId, mediaSourceId, cancellationToken).ConfigureAwait(false);info.RequiresClosing = true;if (info.RequiresClosing)@@ -519,6 +519,17 @@ namespace MediaBrowser.Server.Implementations.LiveTvstream.Index = -1;}}++ // Set the total bitrate if not already supplied+ if (!mediaSource.Bitrate.HasValue)+ {+ var total = mediaSource.MediaStreams.Select(i => i.BitRate ?? 0).Sum();++ if (total > 0)+ {+ mediaSource.Bitrate = total;+ }+ }}private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.csindex 38c93a6964..46c186b0ac 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs@@ -84,6 +84,7 @@ namespace MediaBrowser.Server.Implementations.LiveTvvar openKeys = new List<string>();openKeys.Add(item.GetType().Name);openKeys.Add(item.Id.ToString("N"));+ openKeys.Add(source.Id ?? string.Empty);source.OpenToken = string.Join("|", openKeys.ToArray());}@@ -95,13 +96,14 @@ namespace MediaBrowser.Server.Implementations.LiveTvpublic async Task<MediaSourceInfo> OpenMediaSource(string openToken, CancellationToken cancellationToken){MediaSourceInfo stream;- var isAudio = false;+ const bool isAudio = false;- var keys = openToken.Split(new[] { '|' }, 2);+ var keys = openToken.Split(new[] { '|' }, 3);+ var mediaSourceId = keys.Length >= 3 ? keys[2] : null;if (string.Equals(keys[0], typeof(LiveTvChannel).Name, StringComparison.OrdinalIgnoreCase)){- stream = await _liveTvManager.GetChannelStream(keys[1], cancellationToken).ConfigureAwait(false);+ stream = await _liveTvManager.GetChannelStream(keys[1], mediaSourceId, cancellationToken).ConfigureAwait(false);}else{