HlsSegmentService.cs 3.0 KB

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