From 881928323e16b1cf9a4831753a3da521c38b6e47 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Mar 2015 01:40:51 -0400 Subject: [PATCH] update ILiveTvService --- .../Playback/BaseStreamingService.cs | 4 +- .../LiveTv/ILiveTvManager.cs | 4 +- .../LiveTv/ILiveTvService.cs | 23 +++- .../Encoder/BaseEncoder.cs | 5 +- .../LiveTv/LiveTvManager.cs | 112 ++++++++++++------ Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Model.Signed.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 9 files changed, 105 insertions(+), 55 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 7115ddffd..5c857aa37 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1816,12 +1816,10 @@ namespace MediaBrowser.Api.Playback } private void AttachMediaStreamInfo(StreamState state, - ChannelMediaInfo mediaInfo, + MediaSourceInfo mediaSource, VideoStreamRequest videoRequest, string requestedUrl) { - var mediaSource = mediaInfo.ToMediaSource(); - state.InputProtocol = mediaSource.Protocol; state.MediaPath = mediaSource.Path; state.RunTimeTicks = mediaSource.RunTimeTicks; diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 9b36454d2..0b58a9232 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -149,7 +149,7 @@ namespace MediaBrowser.Controller.LiveTv /// The identifier. /// The cancellation token. /// Task{Stream}. - Task GetRecordingStream(string id, CancellationToken cancellationToken); + Task GetRecordingStream(string id, CancellationToken cancellationToken); /// /// Gets the channel stream. @@ -157,7 +157,7 @@ namespace MediaBrowser.Controller.LiveTv /// The identifier. /// The cancellation token. /// Task{StreamResponseInfo}. - Task GetChannelStream(string id, CancellationToken cancellationToken); + Task GetChannelStream(string id, CancellationToken cancellationToken); /// /// Gets the program. diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index 993db0004..d7e3df4e2 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Drawing; +using MediaBrowser.Model.Dto; namespace MediaBrowser.Controller.LiveTv { @@ -172,18 +173,36 @@ namespace MediaBrowser.Controller.LiveTv /// Gets the recording stream. /// /// The recording identifier. + /// The stream identifier. /// The cancellation token. /// Task{Stream}. - Task GetRecordingStream(string recordingId, CancellationToken cancellationToken); + Task GetRecordingStream(string recordingId, string streamId, CancellationToken cancellationToken); /// /// Gets the channel stream. /// /// The channel identifier. + /// The stream identifier. /// The cancellation token. /// Task{Stream}. - Task GetChannelStream(string channelId, CancellationToken cancellationToken); + Task GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken); + /// + /// Gets the channel stream media sources. + /// + /// The channel identifier. + /// The cancellation token. + /// Task<List<MediaSourceInfo>>. + Task> GetChannelStreamMediaSources(string channelId, CancellationToken cancellationToken); + + /// + /// Gets the recording stream media sources. + /// + /// The recording identifier. + /// The cancellation token. + /// Task<List<MediaSourceInfo>>. + Task> GetRecordingStreamMediaSources(string recordingId, CancellationToken cancellationToken); + /// /// Closes the live stream. /// diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index 6ddc3487d..44e0d1517 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -10,6 +10,7 @@ using MediaBrowser.MediaEncoding.Subtitles; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Drawing; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; @@ -527,11 +528,9 @@ namespace MediaBrowser.MediaEncoding.Encoder } private void AttachMediaStreamInfo(EncodingJob state, - ChannelMediaInfo mediaInfo, + MediaSourceInfo mediaSource, EncodingJobOptions videoRequest) { - var mediaSource = mediaInfo.ToMediaSource(); - state.InputProtocol = mediaSource.Protocol; state.MediaPath = mediaSource.Path; state.RunTimeTicks = mediaSource.RunTimeTicks; diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 777a8936b..075451146 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common; +using System.Globalization; +using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Progress; @@ -14,6 +15,7 @@ using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; @@ -304,12 +306,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1); - public async Task GetRecordingStream(string id, CancellationToken cancellationToken) + public async Task GetRecordingStream(string id, CancellationToken cancellationToken) { return await GetLiveStream(id, false, cancellationToken).ConfigureAwait(false); } - public async Task GetChannelStream(string id, CancellationToken cancellationToken) + public async Task GetChannelStream(string id, CancellationToken cancellationToken) { return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false); } @@ -324,20 +326,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv return _services.FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); } - private async Task GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken) + private async Task GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken) { await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { - ChannelMediaInfo info; + MediaSourceInfo info; if (isChannel) { var channel = GetInternalChannel(id); 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, cancellationToken).ConfigureAwait(false); + info = await service.GetChannelStream(channel.ExternalId, null, cancellationToken).ConfigureAwait(false); } else { @@ -345,7 +347,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(recording); _logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.RecordingInfo.Id); - info = await service.GetRecordingStream(recording.RecordingInfo.Id, cancellationToken).ConfigureAwait(false); + info = await service.GetRecordingStream(recording.RecordingInfo.Id, null, cancellationToken).ConfigureAwait(false); } _logger.Info("Live stream info: {0}", _jsonSerializer.SerializeToString(info)); @@ -375,41 +377,73 @@ namespace MediaBrowser.Server.Implementations.LiveTv } } - private void Sanitize(ChannelMediaInfo info) + private void Sanitize(MediaSourceInfo mediaSource) { - // Clean some bad data coming from providers + if (mediaSource.MediaStreams.Count == 0) + { + mediaSource.MediaStreams.AddRange(new List + { + new MediaStream + { + Type = MediaStreamType.Video, + // Set the index to -1 because we don't know the exact index of the video stream within the container + Index = -1 + }, + new MediaStream + { + Type = MediaStreamType.Audio, + // Set the index to -1 because we don't know the exact index of the audio stream within the container + Index = -1 + } + }); + } - if (info.AudioBitrate.HasValue && info.AudioBitrate <= 0) + // Clean some bad data coming from providers + foreach (var stream in mediaSource.MediaStreams) { - info.AudioBitrate = null; + if (stream.BitRate.HasValue && stream.BitRate <= 0) + { + stream.BitRate = null; + } + if (stream.Channels.HasValue && stream.Channels <= 0) + { + stream.Channels = null; + } + if (stream.AverageFrameRate.HasValue && stream.AverageFrameRate <= 0) + { + stream.AverageFrameRate = null; + } + if (stream.RealFrameRate.HasValue && stream.RealFrameRate <= 0) + { + stream.RealFrameRate = null; + } + if (stream.Width.HasValue && stream.Width <= 0) + { + stream.Width = null; + } + if (stream.Height.HasValue && stream.Height <= 0) + { + stream.Height = null; + } + if (stream.SampleRate.HasValue && stream.SampleRate <= 0) + { + stream.SampleRate = null; + } + if (stream.Level.HasValue && stream.Level <= 0) + { + stream.Level = null; + } } - if (info.VideoBitrate.HasValue && info.VideoBitrate <= 0) + + var indexes = mediaSource.MediaStreams.Select(i => i.Index).Distinct().ToList(); + + // If there are duplicate stream indexes, set them all to unknown + if (indexes.Count != mediaSource.MediaStreams.Count) { - info.VideoBitrate = null; - } - if (info.AudioChannels.HasValue && info.AudioChannels <= 0) - { - info.AudioChannels = null; - } - if (info.Framerate.HasValue && info.Framerate <= 0) - { - info.Framerate = null; - } - if (info.Width.HasValue && info.Width <= 0) - { - info.Width = null; - } - if (info.Height.HasValue && info.Height <= 0) - { - info.Height = null; - } - if (info.AudioSampleRate.HasValue && info.AudioSampleRate <= 0) - { - info.AudioSampleRate = null; - } - if (info.VideoLevel.HasValue && info.VideoLevel <= 0) - { - info.VideoLevel = null; + foreach (var stream in mediaSource.MediaStreams) + { + stream.Index = -1; + } } } @@ -1433,7 +1467,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return program; } - private async Task> GetNewTimerDefaultsInternal(CancellationToken cancellationToken, LiveTvProgram program = null) + private async Task> GetNewTimerDefaultsInternal(CancellationToken cancellationToken, LiveTvProgram program = null) { var service = program != null && !string.IsNullOrWhiteSpace(program.ServiceName) ? GetService(program) : @@ -1679,7 +1713,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv class LiveStreamData { - internal ChannelMediaInfo Info; + internal MediaSourceInfo Info; internal int ConsumerCount; internal string ItemId; internal bool IsChannel; diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index bbdce1f11..ea30ffd4f 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.593 + 3.0.594 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 7aa7a9f69..1802aaf87 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.593 + 3.0.594 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index b33205c1e..2a0d38bbf 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.593 + 3.0.594 MediaBrowser.Model - Signed Edition Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 9d6ad279c..4fd30306b 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.593 + 3.0.594 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +