瀏覽代碼

adjust live tv stream selection

Luke Pulverenti 10 年之前
父節點
當前提交
477a182efd

+ 2 - 1
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.

+ 16 - 5
MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs

@@ -330,12 +330,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
         public 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.LiveTv
             return _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.LiveTv
                     isVideo = 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.LiveTv
                     stream.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)

+ 5 - 3
MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs

@@ -84,6 +84,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 var 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.LiveTv
         public 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
             {