update ILiveTvService

This commit is contained in:
Luke Pulverenti 2015-03-20 01:40:51 -04:00
parent 0564d454e5
commit 881928323e
9 changed files with 105 additions and 55 deletions

View File

@ -1816,12 +1816,10 @@ namespace MediaBrowser.Api.Playback
} }
private void AttachMediaStreamInfo(StreamState state, private void AttachMediaStreamInfo(StreamState state,
ChannelMediaInfo mediaInfo, MediaSourceInfo mediaSource,
VideoStreamRequest videoRequest, VideoStreamRequest videoRequest,
string requestedUrl) string requestedUrl)
{ {
var mediaSource = mediaInfo.ToMediaSource();
state.InputProtocol = mediaSource.Protocol; state.InputProtocol = mediaSource.Protocol;
state.MediaPath = mediaSource.Path; state.MediaPath = mediaSource.Path;
state.RunTimeTicks = mediaSource.RunTimeTicks; state.RunTimeTicks = mediaSource.RunTimeTicks;

View File

@ -149,7 +149,7 @@ namespace MediaBrowser.Controller.LiveTv
/// <param name="id">The identifier.</param> /// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns> /// <returns>Task{Stream}.</returns>
Task<ChannelMediaInfo> GetRecordingStream(string id, CancellationToken cancellationToken); Task<MediaSourceInfo> GetRecordingStream(string id, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Gets the channel stream. /// Gets the channel stream.
@ -157,7 +157,7 @@ namespace MediaBrowser.Controller.LiveTv
/// <param name="id">The identifier.</param> /// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{StreamResponseInfo}.</returns> /// <returns>Task{StreamResponseInfo}.</returns>
Task<ChannelMediaInfo> GetChannelStream(string id, CancellationToken cancellationToken); Task<MediaSourceInfo> GetChannelStream(string id, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Gets the program. /// Gets the program.

View File

@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Dto;
namespace MediaBrowser.Controller.LiveTv namespace MediaBrowser.Controller.LiveTv
{ {
@ -172,17 +173,35 @@ namespace MediaBrowser.Controller.LiveTv
/// Gets the recording stream. /// Gets the recording stream.
/// </summary> /// </summary>
/// <param name="recordingId">The recording identifier.</param> /// <param name="recordingId">The recording identifier.</param>
/// <param name="streamId">The stream identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns> /// <returns>Task{Stream}.</returns>
Task<ChannelMediaInfo> GetRecordingStream(string recordingId, CancellationToken cancellationToken); Task<MediaSourceInfo> GetRecordingStream(string recordingId, string streamId, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Gets the channel stream. /// Gets the channel stream.
/// </summary> /// </summary>
/// <param name="channelId">The channel identifier.</param> /// <param name="channelId">The channel identifier.</param>
/// <param name="streamId">The stream identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns> /// <returns>Task{Stream}.</returns>
Task<ChannelMediaInfo> GetChannelStream(string channelId, CancellationToken cancellationToken); Task<MediaSourceInfo> GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken);
/// <summary>
/// Gets the channel stream media sources.
/// </summary>
/// <param name="channelId">The channel identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task&lt;List&lt;MediaSourceInfo&gt;&gt;.</returns>
Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(string channelId, CancellationToken cancellationToken);
/// <summary>
/// Gets the recording stream media sources.
/// </summary>
/// <param name="recordingId">The recording identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task&lt;List&lt;MediaSourceInfo&gt;&gt;.</returns>
Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(string recordingId, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Closes the live stream. /// Closes the live stream.

View File

@ -10,6 +10,7 @@ using MediaBrowser.MediaEncoding.Subtitles;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
@ -527,11 +528,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
} }
private void AttachMediaStreamInfo(EncodingJob state, private void AttachMediaStreamInfo(EncodingJob state,
ChannelMediaInfo mediaInfo, MediaSourceInfo mediaSource,
EncodingJobOptions videoRequest) EncodingJobOptions videoRequest)
{ {
var mediaSource = mediaInfo.ToMediaSource();
state.InputProtocol = mediaSource.Protocol; state.InputProtocol = mediaSource.Protocol;
state.MediaPath = mediaSource.Path; state.MediaPath = mediaSource.Path;
state.RunTimeTicks = mediaSource.RunTimeTicks; state.RunTimeTicks = mediaSource.RunTimeTicks;

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common; using System.Globalization;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Progress; using MediaBrowser.Common.Progress;
@ -14,6 +15,7 @@ using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.LiveTv;
@ -304,12 +306,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv
private readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1);
public async Task<ChannelMediaInfo> GetRecordingStream(string id, CancellationToken cancellationToken) public async Task<MediaSourceInfo> GetRecordingStream(string id, CancellationToken cancellationToken)
{ {
return await GetLiveStream(id, false, cancellationToken).ConfigureAwait(false); return await GetLiveStream(id, false, cancellationToken).ConfigureAwait(false);
} }
public async Task<ChannelMediaInfo> GetChannelStream(string id, CancellationToken cancellationToken) public async Task<MediaSourceInfo> GetChannelStream(string id, CancellationToken cancellationToken)
{ {
return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false); 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)); return _services.FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase));
} }
private async Task<ChannelMediaInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken) private async Task<MediaSourceInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken)
{ {
await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try try
{ {
ChannelMediaInfo info; MediaSourceInfo info;
if (isChannel) if (isChannel)
{ {
var channel = GetInternalChannel(id); var channel = GetInternalChannel(id);
var service = GetService(channel); var service = GetService(channel);
_logger.Info("Opening channel stream from {0}, external channel Id: {1}", service.Name, channel.ExternalId); _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 else
{ {
@ -345,7 +347,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var service = GetService(recording); var service = GetService(recording);
_logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.RecordingInfo.Id); _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)); _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<MediaStream>
{
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 (info.VideoBitrate.HasValue && info.VideoBitrate <= 0) if (stream.Channels.HasValue && stream.Channels <= 0)
{ {
info.VideoBitrate = null; stream.Channels = null;
} }
if (info.AudioChannels.HasValue && info.AudioChannels <= 0) if (stream.AverageFrameRate.HasValue && stream.AverageFrameRate <= 0)
{ {
info.AudioChannels = null; stream.AverageFrameRate = null;
} }
if (info.Framerate.HasValue && info.Framerate <= 0) if (stream.RealFrameRate.HasValue && stream.RealFrameRate <= 0)
{ {
info.Framerate = null; stream.RealFrameRate = null;
} }
if (info.Width.HasValue && info.Width <= 0) if (stream.Width.HasValue && stream.Width <= 0)
{ {
info.Width = null; stream.Width = null;
} }
if (info.Height.HasValue && info.Height <= 0) if (stream.Height.HasValue && stream.Height <= 0)
{ {
info.Height = null; stream.Height = null;
} }
if (info.AudioSampleRate.HasValue && info.AudioSampleRate <= 0) if (stream.SampleRate.HasValue && stream.SampleRate <= 0)
{ {
info.AudioSampleRate = null; stream.SampleRate = null;
} }
if (info.VideoLevel.HasValue && info.VideoLevel <= 0) if (stream.Level.HasValue && stream.Level <= 0)
{ {
info.VideoLevel = null; stream.Level = null;
}
}
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)
{
foreach (var stream in mediaSource.MediaStreams)
{
stream.Index = -1;
}
} }
} }
@ -1433,7 +1467,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return program; return program;
} }
private async Task<Tuple<SeriesTimerInfo,ILiveTvService>> GetNewTimerDefaultsInternal(CancellationToken cancellationToken, LiveTvProgram program = null) private async Task<Tuple<SeriesTimerInfo, ILiveTvService>> GetNewTimerDefaultsInternal(CancellationToken cancellationToken, LiveTvProgram program = null)
{ {
var service = program != null && !string.IsNullOrWhiteSpace(program.ServiceName) ? var service = program != null && !string.IsNullOrWhiteSpace(program.ServiceName) ?
GetService(program) : GetService(program) :
@ -1679,7 +1713,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
class LiveStreamData class LiveStreamData
{ {
internal ChannelMediaInfo Info; internal MediaSourceInfo Info;
internal int ConsumerCount; internal int ConsumerCount;
internal string ItemId; internal string ItemId;
internal bool IsChannel; internal bool IsChannel;

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Common.Internal</id> <id>MediaBrowser.Common.Internal</id>
<version>3.0.593</version> <version>3.0.594</version>
<title>MediaBrowser.Common.Internal</title> <title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors> <authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description> <description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright> <copyright>Copyright © Media Browser 2013</copyright>
<dependencies> <dependencies>
<dependency id="MediaBrowser.Common" version="3.0.593" /> <dependency id="MediaBrowser.Common" version="3.0.594" />
<dependency id="NLog" version="3.2.0.0" /> <dependency id="NLog" version="3.2.0.0" />
<dependency id="SimpleInjector" version="2.7.0" /> <dependency id="SimpleInjector" version="2.7.0" />
</dependencies> </dependencies>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Common</id> <id>MediaBrowser.Common</id>
<version>3.0.593</version> <version>3.0.594</version>
<title>MediaBrowser.Common</title> <title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors> <authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Model.Signed</id> <id>MediaBrowser.Model.Signed</id>
<version>3.0.593</version> <version>3.0.594</version>
<title>MediaBrowser.Model - Signed Edition</title> <title>MediaBrowser.Model - Signed Edition</title>
<authors>Media Browser Team</authors> <authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Server.Core</id> <id>MediaBrowser.Server.Core</id>
<version>3.0.593</version> <version>3.0.594</version>
<title>Media Browser.Server.Core</title> <title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors> <authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description> <description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright> <copyright>Copyright © Media Browser 2013</copyright>
<dependencies> <dependencies>
<dependency id="MediaBrowser.Common" version="3.0.593" /> <dependency id="MediaBrowser.Common" version="3.0.594" />
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>