2013-10-31 14:03:23 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Common.MediaInfo;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-09-04 17:02:19 +00:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
2013-02-27 23:33:40 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-08-10 01:16:31 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2013-03-09 06:05:52 +00:00
|
|
|
|
using ServiceStack.ServiceHost;
|
2013-02-27 23:33:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback.Hls
|
|
|
|
|
{
|
2013-03-09 06:05:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetHlsAudioStream
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Audio/{Id}/stream.m3u8", "GET")]
|
2013-04-10 15:32:09 +00:00
|
|
|
|
[Api(Description = "Gets an audio stream using HTTP live streaming.")]
|
2013-03-09 06:05:52 +00:00
|
|
|
|
public class GetHlsAudioStream : StreamRequest
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 23:33:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class AudioHlsService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AudioHlsService : BaseHlsService
|
|
|
|
|
{
|
2013-04-29 16:01:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="AudioHlsService" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="appPaths">The app paths.</param>
|
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
|
|
|
/// <param name="isoManager">The iso manager.</param>
|
|
|
|
|
/// <param name="mediaEncoder">The media encoder.</param>
|
2013-10-31 14:03:23 +00:00
|
|
|
|
public AudioHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IDtoService dtoService, IFileSystem fileSystem)
|
|
|
|
|
: base(appPaths, userManager, libraryManager, isoManager, mediaEncoder, dtoService, fileSystem)
|
2013-02-27 23:33:40 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-09 06:05:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetHlsAudioStream request)
|
|
|
|
|
{
|
|
|
|
|
return ProcessRequest(request);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 23:33:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the audio arguments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected override string GetAudioArguments(StreamState state)
|
|
|
|
|
{
|
|
|
|
|
var codec = GetAudioCodec(state.Request);
|
|
|
|
|
|
|
|
|
|
var args = "-codec:a " + codec;
|
|
|
|
|
|
|
|
|
|
var channels = GetNumAudioChannelsParam(state.Request, state.AudioStream);
|
|
|
|
|
|
|
|
|
|
if (channels.HasValue)
|
|
|
|
|
{
|
|
|
|
|
args += " -ac " + channels.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.Request.AudioSampleRate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
args += " -ar " + state.Request.AudioSampleRate.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state.Request.AudioBitRate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
args += " -ab " + state.Request.AudioBitRate.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the video arguments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
2013-04-29 16:01:23 +00:00
|
|
|
|
/// <param name="performSubtitleConversion">if set to <c>true</c> [perform subtitle conversion].</param>
|
2013-02-27 23:33:40 +00:00
|
|
|
|
/// <returns>System.String.</returns>
|
2013-04-29 16:01:23 +00:00
|
|
|
|
protected override string GetVideoArguments(StreamState state, bool performSubtitleConversion)
|
2013-02-27 23:33:40 +00:00
|
|
|
|
{
|
|
|
|
|
// No video
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the segment file extension.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
2013-04-29 16:01:23 +00:00
|
|
|
|
/// <exception cref="System.ArgumentException">Must specify either aac or mp3 audio codec.</exception>
|
2013-02-27 23:33:40 +00:00
|
|
|
|
/// <exception cref="System.InvalidOperationException">Only aac and mp3 audio codecs are supported.</exception>
|
|
|
|
|
protected override string GetSegmentFileExtension(StreamState state)
|
|
|
|
|
{
|
|
|
|
|
if (state.Request.AudioCodec == AudioCodecs.Aac)
|
|
|
|
|
{
|
|
|
|
|
return ".aac";
|
|
|
|
|
}
|
|
|
|
|
if (state.Request.AudioCodec == AudioCodecs.Mp3)
|
|
|
|
|
{
|
|
|
|
|
return ".mp3";
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-09 06:05:52 +00:00
|
|
|
|
throw new ArgumentException("Must specify either aac or mp3 audio codec.");
|
2013-02-27 23:33:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the map args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="state">The state.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected override string GetMapArgs(StreamState state)
|
|
|
|
|
{
|
|
|
|
|
return string.Format("-map 0:{0}", state.AudioStream.Index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|