AudioService.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Common.Net;
  3. using MediaBrowser.Controller.Configuration;
  4. using MediaBrowser.Controller.Devices;
  5. using MediaBrowser.Controller.Diagnostics;
  6. using MediaBrowser.Controller.Dlna;
  7. using MediaBrowser.Controller.Drawing;
  8. using MediaBrowser.Controller.Library;
  9. using MediaBrowser.Controller.LiveTv;
  10. using MediaBrowser.Controller.MediaEncoding;
  11. using MediaBrowser.Model.IO;
  12. using ServiceStack;
  13. using System.Collections.Generic;
  14. namespace MediaBrowser.Api.Playback.Progressive
  15. {
  16. /// <summary>
  17. /// Class GetAudioStream
  18. /// </summary>
  19. [Route("/Audio/{Id}/stream.{Container}", "GET", Summary = "Gets an audio stream")]
  20. [Route("/Audio/{Id}/stream", "GET", Summary = "Gets an audio stream")]
  21. [Route("/Audio/{Id}/stream.{Container}", "HEAD", Summary = "Gets an audio stream")]
  22. [Route("/Audio/{Id}/stream", "HEAD", Summary = "Gets an audio stream")]
  23. public class GetAudioStream : StreamRequest
  24. {
  25. [ApiMember(Name = "Container", Description = "Container", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
  26. public string Container { get; set; }
  27. }
  28. /// <summary>
  29. /// Class AudioService
  30. /// </summary>
  31. public class AudioService : BaseProgressiveStreamingService
  32. {
  33. public AudioService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, ILiveTvManager liveTvManager, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IProcessManager processManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IImageProcessor imageProcessor, IHttpClient httpClient) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, liveTvManager, dlnaManager, subtitleEncoder, deviceManager, processManager, mediaSourceManager, zipClient, imageProcessor, httpClient)
  34. {
  35. }
  36. /// <summary>
  37. /// Gets the specified request.
  38. /// </summary>
  39. /// <param name="request">The request.</param>
  40. /// <returns>System.Object.</returns>
  41. public object Get(GetAudioStream request)
  42. {
  43. return ProcessRequest(request, false);
  44. }
  45. /// <summary>
  46. /// Gets the specified request.
  47. /// </summary>
  48. /// <param name="request">The request.</param>
  49. /// <returns>System.Object.</returns>
  50. public object Head(GetAudioStream request)
  51. {
  52. return ProcessRequest(request, true);
  53. }
  54. protected override string GetCommandLineArguments(string outputPath, string transcodingJobId, StreamState state, bool isEncoding)
  55. {
  56. var audioTranscodeParams = new List<string>();
  57. var bitrate = state.OutputAudioBitrate;
  58. if (bitrate.HasValue)
  59. {
  60. audioTranscodeParams.Add("-ab " + bitrate.Value.ToString(UsCulture));
  61. }
  62. if (state.OutputAudioChannels.HasValue)
  63. {
  64. audioTranscodeParams.Add("-ac " + state.OutputAudioChannels.Value.ToString(UsCulture));
  65. }
  66. if (state.OutputAudioSampleRate.HasValue)
  67. {
  68. audioTranscodeParams.Add("-ar " + state.OutputAudioSampleRate.Value.ToString(UsCulture));
  69. }
  70. const string vn = " -vn";
  71. var threads = GetNumberOfThreads(state, false);
  72. var inputModifier = GetInputModifier(state);
  73. return string.Format("{0} {1} -threads {2}{3} {4} -id3v2_version 3 -write_id3v1 1 -y \"{5}\"",
  74. inputModifier,
  75. GetInputArgument(transcodingJobId, state),
  76. threads,
  77. vn,
  78. string.Join(" ", audioTranscodeParams.ToArray()),
  79. outputPath).Trim();
  80. }
  81. }
  82. }