update live tv return object

pull/702/head
Luke Pulverenti 10 years ago
parent bd1bd5e87e
commit b7ed4df4fa

@ -859,19 +859,12 @@ namespace MediaBrowser.Api.Playback
state.LiveTvStreamId = streamInfo.Id;
if (!string.IsNullOrEmpty(streamInfo.Path))
{
state.MediaPath = streamInfo.Path;
}
else if (!string.IsNullOrEmpty(streamInfo.Url))
{
state.MediaPath = streamInfo.Url;
}
state.MediaPath = streamInfo.Path;
state.InputProtocol = streamInfo.Protocol;
await Task.Delay(1500, cancellationTokenSource.Token).ConfigureAwait(false);
state.InputProtocol = GetProtocol(state.MediaPath);
AttachMediaStreamInfo(state, streamInfo.MediaStreams, state.VideoRequest, state.RequestedUrl);
AttachMediaStreamInfo(state, streamInfo, state.VideoRequest, state.RequestedUrl);
checkCodecs = true;
}
@ -882,19 +875,12 @@ namespace MediaBrowser.Api.Playback
state.LiveTvStreamId = streamInfo.Id;
if (!string.IsNullOrEmpty(streamInfo.Path))
{
state.MediaPath = streamInfo.Path;
}
else if (!string.IsNullOrEmpty(streamInfo.Url))
{
state.MediaPath = streamInfo.Url;
}
state.MediaPath = streamInfo.Path;
state.InputProtocol = streamInfo.Protocol;
await Task.Delay(1500, cancellationTokenSource.Token).ConfigureAwait(false);
state.InputProtocol = GetProtocol(state.MediaPath);
AttachMediaStreamInfo(state, streamInfo.MediaStreams, state.VideoRequest, state.RequestedUrl);
AttachMediaStreamInfo(state, streamInfo, state.VideoRequest, state.RequestedUrl);
checkCodecs = true;
}
@ -1006,7 +992,7 @@ namespace MediaBrowser.Api.Playback
await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false);
}
if (state.IsInputVideo && transcodingJob.Type == Api.TranscodingJobType.Progressive)
if (state.IsInputVideo && transcodingJob.Type == TranscodingJobType.Progressive)
{
await Task.Delay(1000, cancellationTokenSource.Token).ConfigureAwait(false);
@ -1712,6 +1698,23 @@ namespace MediaBrowser.Api.Playback
return state;
}
private void AttachMediaStreamInfo(StreamState state,
ChannelMediaInfo mediaInfo,
VideoStreamRequest videoRequest,
string requestedUrl)
{
var mediaSource = mediaInfo.ToMediaSource();
state.InputProtocol = mediaSource.Protocol;
state.MediaPath = mediaSource.Path;
state.RunTimeTicks = mediaSource.RunTimeTicks;
state.RemoteHttpHeaders = mediaSource.RequiredHttpHeaders;
state.InputBitrate = mediaSource.Bitrate;
state.InputFileSize = mediaSource.Size;
AttachMediaStreamInfo(state, mediaSource.MediaStreams, videoRequest, requestedUrl);
}
private void AttachMediaStreamInfo(StreamState state,
List<MediaStream> mediaStreams,
VideoStreamRequest videoRequest,

@ -103,7 +103,9 @@ namespace MediaBrowser.Api.Playback.Hls
var builder = new StringBuilder();
var duration = "PT0H02M11.00S";
var time = TimeSpan.FromTicks(state.RunTimeTicks.Value);
var duration = "PT" + time.Hours.ToString("00", UsCulture) + "H" + time.Minutes.ToString("00", UsCulture) + "M" + time.Seconds.ToString("00", UsCulture) + ".00S";
builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
builder.AppendFormat(
@ -239,16 +241,17 @@ namespace MediaBrowser.Api.Playback.Hls
{
var seconds = TimeSpan.FromTicks(state.RunTimeTicks ?? 0).TotalSeconds;
builder.Append("<SegmentList timescale=\"1000\" duration=\"10000\">");
var queryStringIndex = Request.RawUrl.IndexOf('?');
var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex);
var index = 0;
builder.Append("<SegmentList timescale=\"1000\" duration=\"10000\">");
while (seconds > 0)
{
builder.AppendFormat("<SegmentURL media=\"{0}.ts{1}\"/>", index.ToString(UsCulture), SecurityElement.Escape(queryString));
var segmentUrl = string.Format("{0}.ts{1}", index.ToString(UsCulture), SecurityElement.Escape(queryString));
builder.AppendFormat("<SegmentURL media=\"{0}\"/>", segmentUrl);
seconds -= state.SegmentLength;
index++;

@ -1,6 +1,10 @@
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Controller.Channels
{
@ -31,6 +35,8 @@ namespace MediaBrowser.Controller.Channels
public long? RunTimeTicks { get; set; }
public string Id { get; set; }
public ChannelMediaInfo()
{
RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
@ -38,5 +44,67 @@ namespace MediaBrowser.Controller.Channels
// This is most common
Protocol = MediaProtocol.Http;
}
public MediaSourceInfo ToMediaSource()
{
var id = Path.GetMD5().ToString("N");
var source = new MediaSourceInfo
{
MediaStreams = GetMediaStreams(this).ToList(),
Container = Container,
Protocol = Protocol,
Path = Path,
RequiredHttpHeaders = RequiredHttpHeaders,
RunTimeTicks = RunTimeTicks,
Name = id,
Id = id
};
var bitrate = (AudioBitrate ?? 0) + (VideoBitrate ?? 0);
if (bitrate > 0)
{
source.Bitrate = bitrate;
}
return source;
}
private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)
{
var list = new List<MediaStream>();
if (!string.IsNullOrWhiteSpace(info.VideoCodec) &&
!string.IsNullOrWhiteSpace(info.AudioCodec))
{
list.Add(new MediaStream
{
Type = MediaStreamType.Video,
Width = info.Width,
RealFrameRate = info.Framerate,
Profile = info.VideoProfile,
Level = info.VideoLevel,
Index = -1,
Height = info.Height,
Codec = info.VideoCodec,
BitRate = info.VideoBitrate,
AverageFrameRate = info.Framerate
});
list.Add(new MediaStream
{
Type = MediaStreamType.Audio,
Index = -1,
Codec = info.AudioCodec,
BitRate = info.AudioBitrate,
Channels = info.AudioChannels,
SampleRate = info.AudioSampleRate
});
}
return list;
}
}
}

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Querying;
@ -154,7 +155,7 @@ namespace MediaBrowser.Controller.LiveTv
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
Task<LiveStreamInfo> GetRecordingStream(string id, CancellationToken cancellationToken);
Task<ChannelMediaInfo> GetRecordingStream(string id, CancellationToken cancellationToken);
/// <summary>
/// Gets the channel stream.
@ -162,7 +163,7 @@ namespace MediaBrowser.Controller.LiveTv
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{StreamResponseInfo}.</returns>
Task<LiveStreamInfo> GetChannelStream(string id, CancellationToken cancellationToken);
Task<ChannelMediaInfo> GetChannelStream(string id, CancellationToken cancellationToken);
/// <summary>
/// Gets the program.

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Channels;
namespace MediaBrowser.Controller.LiveTv
{
@ -172,7 +173,7 @@ namespace MediaBrowser.Controller.LiveTv
/// <param name="recordingId">The recording identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
Task<LiveStreamInfo> GetRecordingStream(string recordingId, CancellationToken cancellationToken);
Task<ChannelMediaInfo> GetRecordingStream(string recordingId, CancellationToken cancellationToken);
/// <summary>
/// Gets the channel stream.
@ -180,7 +181,7 @@ namespace MediaBrowser.Controller.LiveTv
/// <param name="channelId">The channel identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{Stream}.</returns>
Task<LiveStreamInfo> GetChannelStream(string channelId, CancellationToken cancellationToken);
Task<ChannelMediaInfo> GetChannelStream(string channelId, CancellationToken cancellationToken);
/// <summary>
/// Closes the live stream.

@ -1,43 +0,0 @@
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
namespace MediaBrowser.Controller.LiveTv
{
public class LiveStreamInfo
{
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
public string Path { get; set; }
/// <summary>
/// Gets or sets the URL.
/// </summary>
/// <value>The URL.</value>
public string Url { get; set; }
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>The identifier.</value>
public string Id { get; set; }
/// <summary>
/// Gets or sets the media container.
/// </summary>
/// <value>The media container.</value>
public string MediaContainer { get; set; }
/// <summary>
/// Gets or sets the media streams.
/// </summary>
/// <value>The media streams.</value>
public List<MediaStream> MediaStreams { get; set; }
public LiveStreamInfo()
{
MediaStreams = new List<MediaStream>();
}
}
}

@ -181,7 +181,6 @@
<Compile Include="LiveTv\RecordingGroup.cs" />
<Compile Include="LiveTv\RecordingStatusChangedEventArgs.cs" />
<Compile Include="LiveTv\ILiveTvRecording.cs" />
<Compile Include="LiveTv\LiveStreamInfo.cs" />
<Compile Include="LiveTv\LiveTvAudioRecording.cs" />
<Compile Include="LiveTv\LiveTvChannel.cs" />
<Compile Include="LiveTv\ChannelInfo.cs" />

@ -4,10 +4,10 @@ namespace MediaBrowser.Model.Connect
public class ConnectAuthenticationResult
{
/// <summary>
/// Gets or sets the user identifier.
/// Gets or sets the user.
/// </summary>
/// <value>The user identifier.</value>
public string UserId { get; set; }
/// <value>The user.</value>
public ConnectUser User { get; set; }
/// <summary>
/// Gets or sets the access token.
/// </summary>

@ -359,71 +359,13 @@ namespace MediaBrowser.Server.Implementations.Channels
private MediaSourceInfo GetMediaSource(IChannelMediaItem item, ChannelMediaInfo info)
{
var id = info.Path.GetMD5().ToString("N");
var source = info.ToMediaSource();
var source = new MediaSourceInfo
{
MediaStreams = GetMediaStreams(info).ToList(),
Container = info.Container,
Protocol = info.Protocol,
Path = info.Path,
RequiredHttpHeaders = info.RequiredHttpHeaders,
RunTimeTicks = item.RunTimeTicks,
Name = id,
Id = id
};
var bitrate = (info.AudioBitrate ?? 0) + (info.VideoBitrate ?? 0);
if (bitrate > 0)
{
source.Bitrate = bitrate;
}
if (item is ChannelVideoItem && info.Protocol != MediaProtocol.Rtmp)
{
}
source.RunTimeTicks = source.RunTimeTicks ?? item.RunTimeTicks;
return source;
}
private IEnumerable<MediaStream> GetMediaStreams(ChannelMediaInfo info)
{
var list = new List<MediaStream>();
if (!string.IsNullOrWhiteSpace(info.VideoCodec) &&
!string.IsNullOrWhiteSpace(info.AudioCodec))
{
list.Add(new MediaStream
{
Type = MediaStreamType.Video,
Width = info.Width,
RealFrameRate = info.Framerate,
Profile = info.VideoProfile,
Level = info.VideoLevel,
Index = -1,
Height = info.Height,
Codec = info.VideoCodec,
BitRate = info.VideoBitrate,
AverageFrameRate = info.Framerate
});
list.Add(new MediaStream
{
Type = MediaStreamType.Audio,
Index = -1,
Codec = info.AudioCodec,
BitRate = info.AudioBitrate,
Channels = info.AudioChannels,
SampleRate = info.AudioSampleRate
});
}
return list;
}
private IEnumerable<ChannelMediaInfo> SortMediaInfoResults(IEnumerable<ChannelMediaInfo> channelMediaSources)
{
var list = channelMediaSources.ToList();

@ -2,6 +2,7 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
@ -344,24 +345,24 @@ namespace MediaBrowser.Server.Implementations.LiveTv
private readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1);
public async Task<LiveStreamInfo> GetRecordingStream(string id, CancellationToken cancellationToken)
public async Task<ChannelMediaInfo> GetRecordingStream(string id, CancellationToken cancellationToken)
{
return await GetLiveStream(id, false, cancellationToken).ConfigureAwait(false);
}
public async Task<LiveStreamInfo> GetChannelStream(string id, CancellationToken cancellationToken)
public async Task<ChannelMediaInfo> GetChannelStream(string id, CancellationToken cancellationToken)
{
return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false);
}
private async Task<LiveStreamInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken)
private async Task<ChannelMediaInfo> GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken)
{
await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
var service = ActiveService;
LiveStreamInfo info;
ChannelMediaInfo info;
if (isChannel)
{
@ -406,55 +407,41 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
}
private void Sanitize(LiveStreamInfo info)
private void Sanitize(ChannelMediaInfo info)
{
// Clean some bad data coming from providers
foreach (var stream in info.MediaStreams)
if (info.AudioBitrate.HasValue && info.AudioBitrate <= 0)
{
if (stream.BitDepth.HasValue && stream.BitDepth <= 0)
{
stream.BitDepth = 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 (stream.PacketLength.HasValue && stream.PacketLength <= 0)
{
stream.PacketLength = null;
}
// Don't trust the provider values
stream.Index = -1;
info.AudioBitrate = null;
}
if (info.VideoBitrate.HasValue && info.VideoBitrate <= 0)
{
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;
}
}
@ -1702,7 +1689,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
class LiveStreamData
{
internal LiveStreamInfo Info;
internal ChannelMediaInfo Info;
internal int ConsumerCount;
internal string ItemId;
internal bool IsChannel;

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.484</version>
<version>3.0.486</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<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>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.484" />
<dependency id="MediaBrowser.Common" version="3.0.486" />
<dependency id="NLog" version="3.1.0.0" />
<dependency id="SimpleInjector" version="2.5.2" />
<dependency id="sharpcompress" version="0.10.2" />

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

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

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

Loading…
Cancel
Save