2013-11-01 16:59:42 +01:00
|
|
|
using MediaBrowser.Common.IO;
|
2013-12-15 20:39:21 +01:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2015-01-20 06:19:13 +01:00
|
|
|
using MediaBrowser.Controller.Devices;
|
2014-03-25 06:25:03 +01:00
|
|
|
using MediaBrowser.Controller.Dlna;
|
2013-02-28 00:33:40 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-02-20 17:37:41 +01:00
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
2013-08-10 03:16:31 +02:00
|
|
|
using MediaBrowser.Model.IO;
|
2015-05-04 19:44:25 +02:00
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-12-07 16:52:38 +01:00
|
|
|
using ServiceStack;
|
2013-07-02 20:24:29 +02:00
|
|
|
using System;
|
2013-02-28 00:33:40 +01:00
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
{
|
2014-07-01 23:13:32 +02:00
|
|
|
[Route("/Videos/{Id}/live.m3u8", "GET")]
|
|
|
|
[Api(Description = "Gets a video stream using HTTP live streaming.")]
|
|
|
|
public class GetLiveHlsStream : VideoStreamRequest
|
|
|
|
{
|
|
|
|
}
|
2014-09-18 06:50:21 +02:00
|
|
|
|
2013-04-29 18:01:23 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Class VideoHlsService
|
|
|
|
/// </summary>
|
2013-02-28 00:33:40 +01:00
|
|
|
public class VideoHlsService : BaseHlsService
|
|
|
|
{
|
2015-05-04 19:44:25 +02: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) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer)
|
2013-02-28 00:33:40 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-09 07:13:10 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
/// <returns>System.Object.</returns>
|
2015-05-24 20:33:28 +02:00
|
|
|
public object Get(GetHlsVideoStreamLegacy request)
|
2013-03-09 07:13:10 +01:00
|
|
|
{
|
2014-07-01 23:13:32 +02:00
|
|
|
return ProcessRequest(request, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public object Get(GetLiveHlsStream request)
|
|
|
|
{
|
|
|
|
return ProcessRequest(request, true);
|
2013-03-09 07:13:10 +01:00
|
|
|
}
|
2013-04-29 18:01:23 +02:00
|
|
|
|
2013-02-28 00:33:40 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the audio arguments.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
protected override string GetAudioArguments(StreamState state)
|
|
|
|
{
|
2015-07-25 19:21:10 +02:00
|
|
|
var codec = GetAudioEncoder(state);
|
2013-03-20 15:27:56 +01:00
|
|
|
|
2015-06-03 05:15:46 +02:00
|
|
|
if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase))
|
2013-02-28 00:33:40 +01:00
|
|
|
{
|
|
|
|
return "-codec:a:0 copy";
|
|
|
|
}
|
|
|
|
|
|
|
|
var args = "-codec:a:0 " + codec;
|
|
|
|
|
2014-06-23 18:05:19 +02:00
|
|
|
var channels = state.OutputAudioChannels;
|
2013-02-28 00:33:40 +01:00
|
|
|
|
2014-06-23 18:05:19 +02:00
|
|
|
if (channels.HasValue)
|
|
|
|
{
|
|
|
|
args += " -ac " + channels.Value;
|
|
|
|
}
|
2013-02-28 00:33:40 +01:00
|
|
|
|
2014-06-23 18:05:19 +02:00
|
|
|
var bitrate = state.OutputAudioBitrate;
|
2013-03-20 15:27:56 +01:00
|
|
|
|
2014-06-23 18:05:19 +02:00
|
|
|
if (bitrate.HasValue)
|
|
|
|
{
|
|
|
|
args += " -ab " + bitrate.Value.ToString(UsCulture);
|
2013-02-28 00:33:40 +01:00
|
|
|
}
|
|
|
|
|
2014-06-23 18:05:19 +02:00
|
|
|
args += " " + GetAudioFilterParam(state, true);
|
|
|
|
|
2013-02-28 00:33:40 +01:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the video arguments.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
2014-06-10 19:36:06 +02:00
|
|
|
protected override string GetVideoArguments(StreamState state)
|
2013-02-28 00:33:40 +01:00
|
|
|
{
|
2015-07-25 19:21:10 +02:00
|
|
|
var codec = GetVideoEncoder(state);
|
2013-02-28 00:33:40 +01:00
|
|
|
|
2014-12-26 18:45:06 +01:00
|
|
|
var args = "-codec:v:0 " + codec;
|
|
|
|
|
|
|
|
if (state.EnableMpegtsM2TsMode)
|
|
|
|
{
|
|
|
|
args += " -mpegts_m2ts_mode 1";
|
|
|
|
}
|
|
|
|
|
2013-02-28 00:33:40 +01:00
|
|
|
// See if we can save come cpu cycles by avoiding encoding
|
|
|
|
if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase))
|
|
|
|
{
|
2014-12-26 18:45:06 +01:00
|
|
|
return state.VideoStream != null && IsH264(state.VideoStream) ?
|
|
|
|
args + " -bsf:v h264_mp4toannexb" :
|
|
|
|
args;
|
2013-02-28 00:33:40 +01:00
|
|
|
}
|
2014-12-26 18:45:06 +01:00
|
|
|
|
2015-08-09 18:35:27 +02:00
|
|
|
var keyFrameArg = string.Format(" -force_key_frames \"expr:gte(t,n_forced*{0})\"",
|
2014-06-26 19:04:11 +02:00
|
|
|
state.SegmentLength.ToString(UsCulture));
|
2013-03-28 16:22:05 +01:00
|
|
|
|
2014-06-11 22:57:18 +02:00
|
|
|
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream;
|
2013-12-06 04:39:44 +01:00
|
|
|
|
2014-12-26 18:45:06 +01:00
|
|
|
args += " " + GetVideoQualityParam(state, H264Encoder, true) + keyFrameArg;
|
2013-12-06 04:39:44 +01:00
|
|
|
|
2013-02-28 00:33:40 +01:00
|
|
|
// Add resolution params, if specified
|
2013-11-20 16:50:54 +01:00
|
|
|
if (!hasGraphicalSubs)
|
2013-02-28 00:33:40 +01:00
|
|
|
{
|
2014-08-17 07:38:13 +02:00
|
|
|
args += GetOutputSizeParam(state, codec);
|
2013-02-28 00:33:40 +01:00
|
|
|
}
|
|
|
|
|
2013-11-20 16:50:54 +01:00
|
|
|
// This is for internal graphical subs
|
|
|
|
if (hasGraphicalSubs)
|
2013-03-24 04:56:01 +01:00
|
|
|
{
|
2014-07-30 05:31:35 +02:00
|
|
|
args += GetGraphicalSubtitleParam(state, codec);
|
2013-03-24 04:56:01 +01:00
|
|
|
}
|
2013-12-06 04:39:44 +01:00
|
|
|
|
2013-02-28 00:33:40 +01:00
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the segment file extension.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
protected override string GetSegmentFileExtension(StreamState state)
|
|
|
|
{
|
|
|
|
return ".ts";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|