aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Playback/Hls
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/Playback/Hls')
-rw-r--r--MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs53
-rw-r--r--MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs38
-rw-r--r--MediaBrowser.Api/Playback/Hls/VideoHlsService.cs65
3 files changed, 65 insertions, 91 deletions
diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs
deleted file mode 100644
index 10ea6bc63..000000000
--- a/MediaBrowser.Api/Playback/Hls/HlsSegmentResponseFilter.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using MediaBrowser.Controller;
-using MediaBrowser.Model.Logging;
-using ServiceStack.Text.Controller;
-using ServiceStack.Web;
-using System;
-using System.IO;
-using System.Linq;
-
-namespace MediaBrowser.Api.Playback.Hls
-{
- public class HlsSegmentResponseFilter : Attribute, IHasResponseFilter
- {
- public ILogger Logger { get; set; }
- public IServerApplicationPaths ApplicationPaths { get; set; }
-
- public void ResponseFilter(IRequest req, IResponse res, object response)
- {
- var pathInfo = PathInfo.Parse(req.PathInfo);
- var itemId = pathInfo.GetArgumentValue<string>(1);
- var playlistId = pathInfo.GetArgumentValue<string>(3);
-
- OnEndRequest(itemId, playlistId);
- }
-
- public IHasResponseFilter Copy()
- {
- return this;
- }
-
- public int Priority
- {
- get { return -1; }
- }
-
- /// <summary>
- /// Called when [end request].
- /// </summary>
- /// <param name="itemId">The item id.</param>
- /// <param name="playlistId">The playlist id.</param>
- protected void OnEndRequest(string itemId, string playlistId)
- {
- Logger.Info("OnEndRequest " + playlistId);
- var normalizedPlaylistId = playlistId.Replace("-low", string.Empty);
-
- foreach (var playlist in Directory.EnumerateFiles(ApplicationPaths.TranscodingTempPath, "*.m3u8")
- .Where(i => i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1)
- .ToList())
- {
- ApiEntryPoint.Instance.OnTranscodeEndRequest(playlist, TranscodingJobType.Hls);
- }
- }
- }
-}
diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs
index 31583ac19..5d2dd07c7 100644
--- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs
+++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs
@@ -31,28 +31,6 @@ namespace MediaBrowser.Api.Playback.Hls
/// <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
- {
- /// <summary>
- /// Gets or sets the id.
- /// </summary>
- /// <value>The id.</value>
- public string Id { get; set; }
-
- public string PlaylistId { get; set; }
-
- /// <summary>
- /// Gets or sets the segment id.
- /// </summary>
- /// <value>The segment id.</value>
- public string SegmentId { get; set; }
- }
-
- /// <summary>
- /// Class GetHlsVideoSegment
- /// </summary>
[Route("/Videos/{Id}/hls/{PlaylistId}/stream.m3u8", "GET")]
[Api(Description = "Gets an Http live streaming segment file. Internal use only.")]
public class GetHlsPlaylist
@@ -104,22 +82,6 @@ namespace MediaBrowser.Api.Playback.Hls
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
- public object Get(GetHlsVideoSegment request)
- {
- var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
-
- file = Path.Combine(_appPaths.TranscodingTempPath, file);
-
- OnBeginRequest(request.PlaylistId);
-
- return ResultFactory.GetStaticFileResult(Request, file);
- }
-
- /// <summary>
- /// Gets the specified request.
- /// </summary>
- /// <param name="request">The request.</param>
- /// <returns>System.Object.</returns>
public object Get(GetHlsAudioSegment request)
{
var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs
index fae9e26c6..174cbe9ba 100644
--- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs
+++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs
@@ -10,6 +10,8 @@ using MediaBrowser.Model.IO;
using ServiceStack;
using System;
using System.Collections.Generic;
+using System.IO;
+using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -57,6 +59,28 @@ namespace MediaBrowser.Api.Playback.Hls
}
/// <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
+ {
+ /// <summary>
+ /// Gets or sets the id.
+ /// </summary>
+ /// <value>The id.</value>
+ public string Id { get; set; }
+
+ public string PlaylistId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the segment id.
+ /// </summary>
+ /// <value>The segment id.</value>
+ public string SegmentId { get; set; }
+ }
+
+ /// <summary>
/// Class VideoHlsService
/// </summary>
public class VideoHlsService : BaseHlsService
@@ -87,6 +111,22 @@ namespace MediaBrowser.Api.Playback.Hls
return result;
}
+ /// <summary>
+ /// Gets the specified request.
+ /// </summary>
+ /// <param name="request">The request.</param>
+ /// <returns>System.Object.</returns>
+ public object Get(GetHlsVideoSegment request)
+ {
+ var file = request.SegmentId + Path.GetExtension(Request.PathInfo);
+
+ file = Path.Combine(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, file);
+
+ OnBeginRequest(request.PlaylistId);
+
+ return ResultFactory.GetStaticFileResult(Request, file);
+ }
+
private async Task<object> GetPlaylistAsync(VideoStreamRequest request, string name)
{
var state = await GetState(request, CancellationToken.None).ConfigureAwait(false);
@@ -313,5 +353,30 @@ namespace MediaBrowser.Api.Playback.Hls
{
return ".ts";
}
+
+ /// <summary>
+ /// Called when [begin request].
+ /// </summary>
+ /// <param name="playlistId">The playlist id.</param>
+ protected void OnBeginRequest(string playlistId)
+ {
+ var normalizedPlaylistId = playlistId.Replace("-low", string.Empty);
+
+ foreach (var playlist in Directory.EnumerateFiles(ServerConfigurationManager.ApplicationPaths.TranscodingTempPath, "*.m3u8")
+ .Where(i => i.IndexOf(normalizedPlaylistId, StringComparison.OrdinalIgnoreCase) != -1)
+ .ToList())
+ {
+ ExtendPlaylistTimer(playlist);
+ }
+ }
+
+ private async void ExtendPlaylistTimer(string playlist)
+ {
+ ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType.Hls);
+
+ await Task.Delay(20000).ConfigureAwait(false);
+
+ ApiEntryPoint.Instance.OnTranscodeEndRequest(playlist, TranscodingJobType.Hls);
+ }
}
}