You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Api/Playback/Progressive/AudioService.cs

101 lines
4.0 KiB

using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
10 years ago
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
11 years ago
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using ServiceStack;
12 years ago
using System.Collections.Generic;
using CommonIO;
12 years ago
namespace MediaBrowser.Api.Playback.Progressive
{
/// <summary>
/// Class GetAudioStream
/// </summary>
11 years ago
[Route("/Audio/{Id}/stream.{Container}", "GET", Summary = "Gets an audio stream")]
[Route("/Audio/{Id}/stream", "GET", Summary = "Gets an audio stream")]
11 years ago
[Route("/Audio/{Id}/stream.{Container}", "HEAD", Summary = "Gets an audio stream")]
[Route("/Audio/{Id}/stream", "HEAD", Summary = "Gets an audio stream")]
12 years ago
public class GetAudioStream : StreamRequest
{
11 years ago
[ApiMember(Name = "Container", Description = "Container", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Container { get; set; }
12 years ago
}
/// <summary>
/// Class AudioService
/// </summary>
public class AudioService : BaseProgressiveStreamingService
{
public AudioService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer, IImageProcessor imageProcessor, IHttpClient httpClient) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer, imageProcessor, httpClient)
12 years ago
{
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetAudioStream request)
{
return ProcessRequest(request, false);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Head(GetAudioStream request)
{
return ProcessRequest(request, true);
12 years ago
}
protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding)
12 years ago
{
var audioTranscodeParams = new List<string>();
var bitrate = state.OutputAudioBitrate;
if (bitrate.HasValue)
12 years ago
{
audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
12 years ago
}
if (state.OutputAudioChannels.HasValue)
12 years ago
{
audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
12 years ago
}
// opus will fail on 44100
if (!string.Equals(state.OutputAudioCodec, "opus", global::System.StringComparison.OrdinalIgnoreCase))
12 years ago
{
if (state.OutputAudioSampleRate.HasValue)
{
audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
}
12 years ago
}
const string vn = " -vn";
var threads = GetNumberOfThreads(state, false);
var inputModifier = GetInputModifier(state);
return string.Format("{0} {1} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1 -y \"{5}\"",
inputModifier,
GetInputArgument(state),
threads,
vn,
12 years ago
string.Join(" ", audioTranscodeParams.ToArray()),
outputPath).Trim();
12 years ago
}
}
}