|
@@ -1,6 +1,10 @@
|
|
using MediaBrowser.Controller;
|
|
using MediaBrowser.Controller;
|
|
|
|
+using MediaBrowser.Controller.Configuration;
|
|
|
|
+using MediaBrowser.Controller.Net;
|
|
using ServiceStack;
|
|
using ServiceStack;
|
|
|
|
+using System;
|
|
using System.IO;
|
|
using System.IO;
|
|
|
|
+using System.Linq;
|
|
|
|
|
|
namespace MediaBrowser.Api.Playback.Hls
|
|
namespace MediaBrowser.Api.Playback.Hls
|
|
{
|
|
{
|
|
@@ -32,6 +36,8 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
[Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
|
|
[Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
|
|
public class GetHlsPlaylist
|
|
public class GetHlsPlaylist
|
|
{
|
|
{
|
|
|
|
+ // TODO: Deprecate with new iOS app
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets the id.
|
|
/// Gets or sets the id.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -52,22 +58,39 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
public string StreamId { get; set; }
|
|
public string StreamId { get; set; }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Class GetHlsVideoSegment
|
|
|
|
+ /// </summary>
|
|
|
|
+ [Route("/Videos/{Id}/hls/{PlaylistId}/{SegmentId}.ts", "GET")]
|
|
|
|
+ [Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
|
|
|
|
+ public class GetHlsVideoSegment : VideoStreamRequest
|
|
|
|
+ {
|
|
|
|
+ public string PlaylistId { get; set; }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets or sets the segment id.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <value>The segment id.</value>
|
|
|
|
+ public string SegmentId { get; set; }
|
|
|
|
+ }
|
|
|
|
+
|
|
public class HlsSegmentService : BaseApiService
|
|
public class HlsSegmentService : BaseApiService
|
|
{
|
|
{
|
|
private readonly IServerApplicationPaths _appPaths;
|
|
private readonly IServerApplicationPaths _appPaths;
|
|
|
|
+ private readonly IServerConfigurationManager _config;
|
|
|
|
|
|
- public HlsSegmentService(IServerApplicationPaths appPaths)
|
|
|
|
|
|
+ public HlsSegmentService(IServerApplicationPaths appPaths, IServerConfigurationManager config)
|
|
{
|
|
{
|
|
_appPaths = appPaths;
|
|
_appPaths = appPaths;
|
|
|
|
+ _config = config;
|
|
}
|
|
}
|
|
|
|
|
|
public object Get(GetHlsPlaylist request)
|
|
public object Get(GetHlsPlaylist request)
|
|
{
|
|
{
|
|
var file = request.PlaylistId + Path.GetExtension(Request.PathInfo);
|
|
var file = request.PlaylistId + Path.GetExtension(Request.PathInfo);
|
|
-
|
|
|
|
file = Path.Combine(_appPaths.TranscodingTempPath, file);
|
|
file = Path.Combine(_appPaths.TranscodingTempPath, file);
|
|
|
|
|
|
- return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);
|
|
|
|
|
|
+ return GetFileResult(file, file);
|
|
}
|
|
}
|
|
|
|
|
|
public void Delete(StopEncodingProcess request)
|
|
public void Delete(StopEncodingProcess request)
|
|
@@ -80,13 +103,49 @@ namespace MediaBrowser.Api.Playback.Hls
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="request">The request.</param>
|
|
/// <param name="request">The request.</param>
|
|
/// <returns>System.Object.</returns>
|
|
/// <returns>System.Object.</returns>
|
|
- public object Get(GetHlsAudioSegment request)
|
|
|
|
|
|
+ public object Get(GetHlsVideoSegment request)
|
|
{
|
|
{
|
|
var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
|
|
var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
|
|
|
|
+ file = Path.Combine(_config.ApplicationPaths.TranscodingTempPath, file);
|
|
|
|
+
|
|
|
|
+ var normalizedPlaylistId = request.PlaylistId.Replace("-low", string.Empty);
|
|
|
|
+
|
|
|
|
+ var playlistPath = Directory.EnumerateFiles(_config.ApplicationPaths.TranscodingTempPath, "*")
|
|
|
|
+ .FirstOrDefault(i => string.Equals(Path.GetExtension(i), ".m3u8", StringComparison.OrdinalIgnoreCase) && i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1);
|
|
|
|
+
|
|
|
|
+ return GetFileResult(file, playlistPath);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets the specified request.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="request">The request.</param>
|
|
|
|
+ /// <returns>System.Object.</returns>
|
|
|
|
+ public object Get(GetHlsAudioSegment request)
|
|
|
|
+ {
|
|
|
|
+ // TODO: Deprecate with new iOS app
|
|
|
|
+ var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
|
|
file = Path.Combine(_appPaths.TranscodingTempPath, file);
|
|
file = Path.Combine(_appPaths.TranscodingTempPath, file);
|
|
|
|
|
|
return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);
|
|
return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private object GetFileResult(string path, string playlistPath)
|
|
|
|
+ {
|
|
|
|
+ var transcodingJob = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType.Hls);
|
|
|
|
+
|
|
|
|
+ return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
|
|
|
|
+ {
|
|
|
|
+ Path = path,
|
|
|
|
+ FileShare = FileShare.ReadWrite,
|
|
|
|
+ OnComplete = () =>
|
|
|
|
+ {
|
|
|
|
+ if (transcodingJob != null)
|
|
|
|
+ {
|
|
|
|
+ ApiEntryPoint.Instance.OnTranscodeEndRequest(transcodingJob);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|