2013-12-15 14:39:21 -05:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2015-01-20 00:19:13 -05:00
|
|
|
using MediaBrowser.Controller.Devices;
|
2014-03-25 01:25:03 -04:00
|
|
|
using MediaBrowser.Controller.Dlna;
|
2013-02-27 18:33:40 -05:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-20 11:37:41 -05:00
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2013-08-09 21:16:31 -04:00
|
|
|
using MediaBrowser.Model.IO;
|
2015-05-04 13:44:25 -04:00
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-07-02 14:24:29 -04:00
|
|
|
using System;
|
2016-11-10 09:41:24 -05:00
|
|
|
using MediaBrowser.Controller.Net;
|
2016-03-07 13:50:58 -05:00
|
|
|
using MediaBrowser.Model.Dlna;
|
2016-10-25 15:02:04 -04:00
|
|
|
using MediaBrowser.Model.Services;
|
2013-02-27 18:33:40 -05:00
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
{
|
2014-07-01 17:13:32 -04:00
|
|
|
[Route("/Videos/{Id}/live.m3u8", "GET")]
|
|
|
|
|
public class GetLiveHlsStream : VideoStreamRequest
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-09-18 00:50:21 -04:00
|
|
|
|
2013-04-29 12:01:23 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Class VideoHlsService
|
|
|
|
|
/// </summary>
|
2013-02-27 18:33:40 -05:00
|
|
|
public class VideoHlsService : BaseHlsService
|
|
|
|
|
{
|
2014-07-01 17:13:32 -04:00
|
|
|
public object Get(GetLiveHlsStream request)
|
|
|
|
|
{
|
|
|
|
|
return ProcessRequest(request, true);
|
2013-03-09 01:13:10 -05:00
|
|
|
}
|
2013-04-29 12:01:23 -04:00
|
|
|
|
2013-02-27 18:33:40 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the audio arguments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected override string GetAudioArguments(StreamState state)
|
|
|
|
|
{
|
2017-02-02 11:02:01 -05:00
|
|
|
var codec = EncodingHelper.GetAudioEncoder(state);
|
2013-03-20 10:27:56 -04:00
|
|
|
|
2015-06-02 23:15:46 -04:00
|
|
|
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
2013-02-27 18:33:40 -05:00
|
|
|
{
|
|
|
|
|
return "-codec:a:0 copy";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var args = "-codec:a:0 " + codec;
|
|
|
|
|
|
2014-06-23 12:05:19 -04:00
|
|
|
var channels = state.OutputAudioChannels;
|
2013-02-27 18:33:40 -05:00
|
|
|
|
2014-06-23 12:05:19 -04:00
|
|
|
if (channels.HasValue)
|
|
|
|
|
{
|
|
|
|
|
args += " -ac " + channels.Value;
|
|
|
|
|
}
|
2013-02-27 18:33:40 -05:00
|
|
|
|
2014-06-23 12:05:19 -04:00
|
|
|
var bitrate = state.OutputAudioBitrate;
|
2013-03-20 10:27:56 -04:00
|
|
|
|
2014-06-23 12:05:19 -04:00
|
|
|
if (bitrate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
2013-02-27 18:33:40 -05:00
|
|
|
}
|
|
|
|
|
|
2017-04-15 15:45:33 -04:00
|
|
|
if (state.OutputAudioSampleRate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
args += " -ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 11:02:01 -05:00
|
|
|
args += " " + EncodingHelper.GetAudioFilterParam(state, ApiEntryPoint.Instance.GetEncodingOptions(), true);
|
2014-06-23 12:05:19 -04:00
|
|
|
|
2013-02-27 18:33:40 -05:00
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the video arguments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
2014-06-10 13:36:06 -04:00
|
|
|
protected override string GetVideoArguments(StreamState state)
|
2013-02-27 18:33:40 -05:00
|
|
|
{
|
2017-02-02 11:02:01 -05:00
|
|
|
var codec = EncodingHelper.GetVideoEncoder(state, ApiEntryPoint.Instance.GetEncodingOptions());
|
2013-02-27 18:33:40 -05:00
|
|
|
|
2014-12-26 12:45:06 -05:00
|
|
|
var args = "-codec:v:0 " + codec;
|
|
|
|
|
|
|
|
|
|
if (state.EnableMpegtsM2TsMode)
|
|
|
|
|
{
|
|
|
|
|
args += " -mpegts_m2ts_mode 1";
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 18:33:40 -05:00
|
|
|
// See if we can save come cpu cycles by avoiding encoding
|
|
|
|
|
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-04-14 15:12:00 -04:00
|
|
|
// if h264_mp4toannexb is ever added, do not use it for live tv
|
2017-04-09 17:38:59 -04:00
|
|
|
if (state.VideoStream != null && EncodingHelper.IsH264(state.VideoStream) &&
|
|
|
|
|
!string.Equals(state.VideoStream.NalLengthSize, "0", StringComparison.OrdinalIgnoreCase))
|
2016-04-17 23:50:44 -04:00
|
|
|
{
|
|
|
|
|
args += " -bsf:v h264_mp4toannexb";
|
|
|
|
|
}
|
2013-02-27 18:33:40 -05:00
|
|
|
}
|
2017-04-09 17:38:59 -04:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
|
|
|
|
|
state.SegmentLength.ToString(UsCulture));
|
2016-04-14 15:12:00 -04:00
|
|
|
|
2017-04-09 17:38:59 -04:00
|
|
|
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
|
2013-03-28 11:22:05 -04:00
|
|
|
|
2017-04-09 17:38:59 -04:00
|
|
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
|
|
|
|
args += " " + EncodingHelper.GetVideoQualityParam(state, codec, encodingOptions, GetDefaultH264Preset()) + keyFrameArg;
|
2013-12-05 22:39:44 -05:00
|
|
|
|
2017-04-09 17:38:59 -04:00
|
|
|
// Add resolution params, if specified
|
|
|
|
|
if (!hasGraphicalSubs)
|
|
|
|
|
{
|
|
|
|
|
args += EncodingHelper.GetOutputSizeParam(state, codec);
|
|
|
|
|
}
|
2013-12-05 22:39:44 -05:00
|
|
|
|
2017-04-09 17:38:59 -04:00
|
|
|
// This is for internal graphical subs
|
|
|
|
|
if (hasGraphicalSubs)
|
|
|
|
|
{
|
|
|
|
|
args += EncodingHelper.GetGraphicalSubtitleParam(state, codec);
|
|
|
|
|
}
|
2013-02-27 18:33:40 -05:00
|
|
|
}
|
|
|
|
|
|
2017-04-09 17:38:59 -04:00
|
|
|
args += " -flags -global_header";
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(state.OutputVideoSync))
|
2013-03-23 23:56:01 -04:00
|
|
|
{
|
2017-04-09 17:38:59 -04:00
|
|
|
args += " -vsync " + state.OutputVideoSync;
|
2013-03-23 23:56:01 -04:00
|
|
|
}
|
2013-12-05 22:39:44 -05:00
|
|
|
|
2013-02-27 18:33:40 -05:00
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 09:41:24 -05:00
|
|
|
public VideoHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer, IAuthorizationContext authorizationContext) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer, authorizationContext)
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-02-27 18:33:40 -05:00
|
|
|
}
|
|
|
|
|
}
|