diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/LiveTv')
| -rw-r--r-- | MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs | 32 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs | 47 |
2 files changed, 61 insertions, 18 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 6aea6fcaa..a82775de7 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -17,6 +17,7 @@ using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Serialization; using System; @@ -330,12 +331,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) @@ -351,7 +352,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv var item = GetInternalChannel(id); var service = GetService(item); - return await service.GetChannelStreamMediaSources(id, cancellationToken).ConfigureAwait(false); + var sources = await service.GetChannelStreamMediaSources(item.ExternalId, cancellationToken).ConfigureAwait(false); + var list = sources.ToList(); + + foreach (var source in list) + { + Normalize(source, item.ChannelType == ChannelType.TV); + } + + return list; } private ILiveTvService GetService(ILiveTvItem item) @@ -364,7 +373,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 +388,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 +528,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) diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs index 38c93a696..4a9028af4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvMediaSourceProvider.cs @@ -1,10 +1,12 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; @@ -21,13 +23,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly ILogger _logger; private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaEncoder _mediaEncoder; + private readonly IServerApplicationHost _appHost; - public LiveTvMediaSourceProvider(ILiveTvManager liveTvManager, IJsonSerializer jsonSerializer, ILogManager logManager, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder) + public LiveTvMediaSourceProvider(ILiveTvManager liveTvManager, IJsonSerializer jsonSerializer, ILogManager logManager, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder, IServerApplicationHost appHost) { _liveTvManager = liveTvManager; _jsonSerializer = jsonSerializer; _mediaSourceManager = mediaSourceManager; _mediaEncoder = mediaEncoder; + _appHost = appHost; _logger = logManager.GetLogger(GetType().Name); } @@ -74,6 +78,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } var list = sources.ToList(); + var serverUrl = _appHost.LocalApiUrl; foreach (var source in list) { @@ -84,7 +89,14 @@ 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()); + + // Dummy this up so that direct play checks can still run + if (string.IsNullOrEmpty(source.Path) && source.Protocol == MediaProtocol.Http) + { + source.Path = serverUrl; + } } _logger.Debug("MediaSources: {0}", _jsonSerializer.SerializeToString(list)); @@ -95,13 +107,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 { @@ -162,30 +175,40 @@ namespace MediaBrowser.Server.Implementations.LiveTv mediaSource.DefaultAudioStreamIndex = audioStream.Index; } - // Try to estimate this - if (!mediaSource.Bitrate.HasValue) + var videoStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == Model.Entities.MediaStreamType.Video); + if (videoStream != null) { - var videoStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == Model.Entities.MediaStreamType.Video); - if (videoStream != null) + if (!videoStream.BitRate.HasValue) { var width = videoStream.Width ?? 1920; if (width >= 1900) { - mediaSource.Bitrate = 10000000; + videoStream.BitRate = 8000000; } else if (width >= 1260) { - mediaSource.Bitrate = 6000000; + videoStream.BitRate = 3000000; } else if (width >= 700) { - mediaSource.Bitrate = 4000000; + videoStream.BitRate = 1000000; } } } + + // Try to estimate this + if (!mediaSource.Bitrate.HasValue) + { + var total = mediaSource.MediaStreams.Select(i => i.BitRate ?? 0).Sum(); + + if (total > 0) + { + mediaSource.Bitrate = total; + } + } } public Task CloseMediaSource(string liveStreamId, CancellationToken cancellationToken) |
