HlsSegmentService.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Model.Dlna;
  3. using ServiceStack;
  4. using System;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Api.Playback.Hls
  9. {
  10. /// <summary>
  11. /// Class GetHlsAudioSegment
  12. /// </summary>
  13. [Route("/Audio/{Id}/hls/{SegmentId}/stream.mp3", "GET")]
  14. [Route("/Audio/{Id}/hls/{SegmentId}/stream.aac", "GET")]
  15. [Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
  16. public class GetHlsAudioSegment
  17. {
  18. /// <summary>
  19. /// Gets or sets the id.
  20. /// </summary>
  21. /// <value>The id.</value>
  22. public string Id { get; set; }
  23. /// <summary>
  24. /// Gets or sets the segment id.
  25. /// </summary>
  26. /// <value>The segment id.</value>
  27. public string SegmentId { get; set; }
  28. }
  29. /// <summary>
  30. /// Class GetHlsVideoSegment
  31. /// </summary>
  32. [Route("/Videos/{Id}/hls/{PlaylistId}/stream.m3u8", "GET")]
  33. [Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
  34. public class GetHlsPlaylist
  35. {
  36. /// <summary>
  37. /// Gets or sets the id.
  38. /// </summary>
  39. /// <value>The id.</value>
  40. public string Id { get; set; }
  41. public string PlaylistId { get; set; }
  42. }
  43. [Route("/Videos/ActiveEncodings", "DELETE")]
  44. [Api(Description = "Stops an encoding process")]
  45. public class StopEncodingProcess
  46. {
  47. [ApiMember(Name = "DeviceId", Description = "The device id of the client requesting. Used to stop encoding processes when needed.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
  48. public string DeviceId { get; set; }
  49. }
  50. public class HlsSegmentService : BaseApiService
  51. {
  52. private readonly IServerApplicationPaths _appPaths;
  53. public HlsSegmentService(IServerApplicationPaths appPaths)
  54. {
  55. _appPaths = appPaths;
  56. }
  57. public object Get(GetHlsPlaylist request)
  58. {
  59. var file = request.PlaylistId + Path.GetExtension(Request.PathInfo);
  60. file = Path.Combine(_appPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower(), file);
  61. return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);
  62. }
  63. public void Delete(StopEncodingProcess request)
  64. {
  65. ApiEntryPoint.Instance.KillTranscodingJobs(request.DeviceId, path => true);
  66. }
  67. /// <summary>
  68. /// Gets the specified request.
  69. /// </summary>
  70. /// <param name="request">The request.</param>
  71. /// <returns>System.Object.</returns>
  72. public object Get(GetHlsAudioSegment request)
  73. {
  74. var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
  75. file = Path.Combine(_appPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower(), file);
  76. return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);
  77. }
  78. }
  79. }