diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-28 15:35:30 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-28 15:35:30 -0400 |
| commit | 608ebf4829e7e394170bb2dec8a33c83600e9c08 (patch) | |
| tree | c8b37e92ca12f4ab50378a03b2a9ec20fbe57940 /MediaBrowser.Api/Playback | |
| parent | b1dd6365da6a2212555946d95b5d698a8af1ea4c (diff) | |
update video player layout
Diffstat (limited to 'MediaBrowser.Api/Playback')
| -rw-r--r-- | MediaBrowser.Api/Playback/BaseStreamingService.cs | 109 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/StreamRequest.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Api/Playback/StreamState.cs | 4 |
4 files changed, 77 insertions, 40 deletions
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 235675b983..3cb7b914ad 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -123,7 +123,11 @@ namespace MediaBrowser.Api.Playback var outputFileExtension = GetOutputFileExtension(state); - return Path.Combine(folder, GetCommandLineArguments("dummy\\dummy", state, false).GetMD5() + (outputFileExtension ?? string.Empty).ToLower()); + var data = GetCommandLineArguments("dummy\\dummy", state, false); + + data += "-" + (state.Request.DeviceId ?? string.Empty); + + return Path.Combine(folder, data.GetMD5().ToString("N") + (outputFileExtension ?? string.Empty).ToLower()); } protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); @@ -772,7 +776,7 @@ namespace MediaBrowser.Api.Playback /// </summary> /// <param name="state">The state.</param> /// <returns>System.String.</returns> - protected string GetInputArgument(StreamState state) + protected virtual string GetInputArgument(StreamState state) { var protocol = state.InputProtocol; @@ -789,6 +793,58 @@ namespace MediaBrowser.Api.Playback return MediaEncoder.GetInputArgument(inputPath, protocol); } + private async Task AcquireResources(StreamState state, CancellationTokenSource cancellationTokenSource) + { + if (state.VideoType == VideoType.Iso && state.IsoType.HasValue && IsoManager.CanMount(state.MediaPath)) + { + state.IsoMount = await IsoManager.Mount(state.MediaPath, cancellationTokenSource.Token).ConfigureAwait(false); + } + + if (string.IsNullOrEmpty(state.MediaPath)) + { + if (string.Equals(state.ItemType, typeof(LiveTvChannel).Name)) + { + var streamInfo = await LiveTvManager.GetChannelStream(state.Request.Id, cancellationTokenSource.Token).ConfigureAwait(false); + + state.LiveTvStreamId = streamInfo.Id; + + if (!string.IsNullOrEmpty(streamInfo.Path)) + { + state.MediaPath = streamInfo.Path; + state.InputProtocol = MediaProtocol.File; + + await Task.Delay(1000, cancellationTokenSource.Token).ConfigureAwait(false); + } + else if (!string.IsNullOrEmpty(streamInfo.Url)) + { + state.MediaPath = streamInfo.Url; + state.InputProtocol = MediaProtocol.Http; + } + } + + else if (string.Equals(state.ItemType, typeof(LiveTvVideoRecording).Name) || + string.Equals(state.ItemType, typeof(LiveTvAudioRecording).Name)) + { + var streamInfo = await LiveTvManager.GetRecordingStream(state.Request.Id, cancellationTokenSource.Token).ConfigureAwait(false); + + state.LiveTvStreamId = streamInfo.Id; + + if (!string.IsNullOrEmpty(streamInfo.Path)) + { + state.MediaPath = streamInfo.Path; + state.InputProtocol = MediaProtocol.File; + + await Task.Delay(1000, cancellationTokenSource.Token).ConfigureAwait(false); + } + else if (!string.IsNullOrEmpty(streamInfo.Url)) + { + state.MediaPath = streamInfo.Url; + state.InputProtocol = MediaProtocol.Http; + } + } + } + } + /// <summary> /// Starts the FFMPEG. /// </summary> @@ -806,10 +862,7 @@ namespace MediaBrowser.Api.Playback Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); - if (state.VideoType == VideoType.Iso && state.IsoType.HasValue && IsoManager.CanMount(state.MediaPath)) - { - state.IsoMount = await IsoManager.Mount(state.MediaPath, cancellationTokenSource.Token).ConfigureAwait(false); - } + await AcquireResources(state, cancellationTokenSource).ConfigureAwait(false); var commandLineArgs = GetCommandLineArguments(outputPath, state, true); @@ -1363,6 +1416,8 @@ namespace MediaBrowser.Api.Playback List<MediaStream> mediaStreams = null; + state.ItemType = item.GetType().Name; + if (item is ILiveTvRecording) { var recording = await LiveTvManager.GetInternalRecording(request.Id, cancellationToken).ConfigureAwait(false); @@ -1379,16 +1434,8 @@ namespace MediaBrowser.Api.Playback mediaStreams = source.MediaStreams; - if (string.IsNullOrWhiteSpace(path) && string.IsNullOrWhiteSpace(mediaUrl)) - { - var streamInfo = await LiveTvManager.GetRecordingStream(request.Id, cancellationToken).ConfigureAwait(false); - - state.LiveTvStreamId = streamInfo.Id; - mediaStreams = streamInfo.MediaStreams; - - path = streamInfo.Path; - mediaUrl = streamInfo.Url; - } + // Just to prevent this from being null and causing other methods to fail + state.MediaPath = string.Empty; if (!string.IsNullOrEmpty(path)) { @@ -1421,30 +1468,16 @@ namespace MediaBrowser.Api.Playback state.VideoType = VideoType.VideoFile; state.IsInputVideo = string.Equals(channel.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase); - - var streamInfo = await LiveTvManager.GetChannelStream(request.Id, cancellationToken).ConfigureAwait(false); - - state.LiveTvStreamId = streamInfo.Id; - mediaStreams = streamInfo.MediaStreams; - - if (!string.IsNullOrEmpty(streamInfo.Path)) - { - state.MediaPath = streamInfo.Path; - state.InputProtocol = MediaProtocol.File; - - await Task.Delay(1000, cancellationToken).ConfigureAwait(false); - } - else if (!string.IsNullOrEmpty(streamInfo.Url)) - { - state.MediaPath = streamInfo.Url; - state.InputProtocol = MediaProtocol.Http; - } + mediaStreams = new List<MediaStream>(); state.ReadInputAtNativeFramerate = true; state.OutputAudioSync = "1000"; state.DeInterlace = true; state.InputVideoSync = "-1"; state.InputAudioSync = "1"; + + // Just to prevent this from being null and causing other methods to fail + state.MediaPath = string.Empty; } else if (item is IChannelMediaItem) { @@ -1500,7 +1533,7 @@ namespace MediaBrowser.Api.Playback AttachMediaStreamInfo(state, mediaStreams, videoRequest, url); - state.SegmentLength = state.ReadInputAtNativeFramerate ? 5 : 10; + state.SegmentLength = state.ReadInputAtNativeFramerate ? 5 : 7; state.HlsListSize = state.ReadInputAtNativeFramerate ? 100 : 1440; var container = Path.GetExtension(state.RequestedUrl); @@ -1928,7 +1961,7 @@ namespace MediaBrowser.Api.Playback videoRequest.Height = null; } - protected string GetInputModifier(StreamState state) + protected string GetInputModifier(StreamState state, bool genPts = true) { var inputModifier = string.Empty; @@ -1948,9 +1981,9 @@ namespace MediaBrowser.Api.Playback inputModifier += " " + GetFastSeekCommandLineParameter(state.Request); inputModifier = inputModifier.Trim(); - if (state.VideoRequest != null) + if (state.VideoRequest != null && genPts) { - inputModifier += " -fflags genpts"; + inputModifier += " -fflags +genpts"; } if (!string.IsNullOrEmpty(state.InputAudioSync)) diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 8957d9fa1c..e41a331be9 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -272,7 +272,7 @@ namespace MediaBrowser.Api.Playback.Hls // If isEncoding is true we're actually starting ffmpeg var startNumberParam = isEncoding ? GetStartNumber(state).ToString(UsCulture) : "0"; - var args = string.Format("{0} {1} -i {2} -map_metadata -1 -threads {3} {4} {5} {6} -hls_time {7} -start_number {8} -hls_list_size {9} -y \"{10}\"", + var args = string.Format("{0} {1} -i {2} -map_metadata -1 -threads {3} {4} {5} -sc_threshold 0 {6} -hls_time {7} -start_number {8} -hls_list_size {9} -y \"{10}\"", itsOffset, inputModifier, GetInputArgument(state), diff --git a/MediaBrowser.Api/Playback/StreamRequest.cs b/MediaBrowser.Api/Playback/StreamRequest.cs index 0e4db45e31..dfb57ef0d7 100644 --- a/MediaBrowser.Api/Playback/StreamRequest.cs +++ b/MediaBrowser.Api/Playback/StreamRequest.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Api.Playback /// <value>The start time ticks.</value> [ApiMember(Name = "StartTimeTicks", Description = "Optional. Specify a starting offset, in ticks. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] public long? StartTimeTicks { get; set; } - + /// <summary> /// Gets or sets the audio bit rate. /// </summary> diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index 4737097cb4..c6f4544477 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -94,6 +94,10 @@ namespace MediaBrowser.Api.Playback public bool EnableMpegtsM2TsMode { get; set; } public TranscodeSeekInfo TranscodeSeekInfo { get; set; } + public long? EncodingDurationTicks { get; set; } + + public string ItemType { get; set; } + public string GetMimeType(string outputPath) { if (!string.IsNullOrEmpty(MimeType)) |
