re-org scripts

pull/702/head
Luke Pulverenti 10 years ago
parent d157c1278b
commit ad52df6be0

@ -274,32 +274,37 @@ namespace MediaBrowser.Api
return null;
}
job.ActiveRequestCount++;
job.DisposeKillTimer();
OnTranscodeBeginRequest(job);
return job;
}
}
public void OnTranscodeBeginRequest(TranscodingJob job)
{
job.ActiveRequestCount++;
job.DisposeKillTimer();
}
public void OnTranscodeEndRequest(TranscodingJob job)
{
job.ActiveRequestCount--;
if (job.ActiveRequestCount == 0)
{
if (job.Type == TranscodingJobType.Progressive)
{
const int timerDuration = 1000;
// TODO: Lower this hls timeout
var timerDuration = job.Type == TranscodingJobType.Progressive ?
1000 :
14400000;
if (job.KillTimer == null)
{
job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
}
else
{
job.KillTimer.Change(timerDuration, Timeout.Infinite);
}
if (job.KillTimer == null)
{
job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
}
else
{
job.KillTimer.Change(timerDuration, Timeout.Infinite);
}
}
}
@ -498,7 +503,7 @@ namespace MediaBrowser.Api
.ToList();
Exception e = null;
foreach (var file in filesToDelete)
{
try

@ -114,7 +114,7 @@ namespace MediaBrowser.Api.Playback.Hls
if (File.Exists(segmentPath))
{
job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType);
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false);
}
@ -123,7 +123,7 @@ namespace MediaBrowser.Api.Playback.Hls
{
if (File.Exists(segmentPath))
{
job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType);
job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false);
}
else
@ -145,6 +145,7 @@ namespace MediaBrowser.Api.Playback.Hls
request.StartTimeTicks = GetSeekPositionTicks(state, requestedIndex);
job = await StartFfMpeg(state, playlistPath, cancellationTokenSource).ConfigureAwait(false);
ApiEntryPoint.Instance.OnTranscodeBeginRequest(job);
}
catch
{
@ -168,7 +169,7 @@ namespace MediaBrowser.Api.Playback.Hls
}
Logger.Info("returning {0}", segmentPath);
job = job ?? ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType);
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false);
}
@ -368,8 +369,8 @@ namespace MediaBrowser.Api.Playback.Hls
if (transcodingJob != null)
{
transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks);
ApiEntryPoint.Instance.OnTranscodeEndRequest(transcodingJob);
}
}
});
}

@ -1,6 +1,10 @@
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
using ServiceStack;
using System;
using System.IO;
using System.Linq;
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.")]
public class GetHlsPlaylist
{
// TODO: Deprecate with new iOS app
/// <summary>
/// Gets or sets the id.
/// </summary>
@ -52,22 +58,39 @@ namespace MediaBrowser.Api.Playback.Hls
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
{
private readonly IServerApplicationPaths _appPaths;
private readonly IServerConfigurationManager _config;
public HlsSegmentService(IServerApplicationPaths appPaths)
public HlsSegmentService(IServerApplicationPaths appPaths, IServerConfigurationManager config)
{
_appPaths = appPaths;
_config = config;
}
public object Get(GetHlsPlaylist request)
{
var file = request.PlaylistId + Path.GetExtension(Request.PathInfo);
file = Path.Combine(_appPaths.TranscodingTempPath, file);
return ResultFactory.GetStaticFileResult(Request, file, FileShare.ReadWrite);
return GetFileResult(file, file);
}
public void Delete(StopEncodingProcess request)
@ -80,13 +103,49 @@ namespace MediaBrowser.Api.Playback.Hls
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetHlsAudioSegment request)
public object Get(GetHlsVideoSegment request)
{
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);
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);
}
}
});
}
}
}

@ -19,6 +19,8 @@ namespace MediaBrowser.Api.Playback.Hls
[Api(Description = "Gets a video stream using HTTP live streaming.")]
public class GetHlsVideoStream : VideoStreamRequest
{
// TODO: Deprecate with new iOS app
[ApiMember(Name = "BaselineStreamAudioBitRate", Description = "Optional. Specify the audio bitrate for the baseline stream.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? BaselineStreamAudioBitRate { get; set; }
@ -35,22 +37,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 : VideoStreamRequest
{
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>
@ -60,20 +46,6 @@ namespace MediaBrowser.Api.Playback.Hls
{
}
/// <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);
return ResultFactory.GetStaticFileResult(Request, file);
}
/// <summary>
/// Gets the specified request.
/// </summary>

@ -288,7 +288,7 @@ namespace MediaBrowser.WebDashboard.Api
"thirdparty/apiclient/ajax.js",
"thirdparty/apiclient/events.js",
"thirdparty/apiclient/deferred.js",
"thirdparty/apiclient/mediabrowser.apiclient.js",
"thirdparty/apiclient/apiclient.js",
"thirdparty/apiclient/connectservice.js",
"thirdparty/apiclient/serverdiscovery.js",
"thirdparty/apiclient/connectionmanager.js"

@ -190,7 +190,7 @@
<Content Include="dashboard-ui\thirdparty\apiclient\deferred.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\thirdparty\apiclient\deferredAlt.js">
<Content Include="dashboard-ui\thirdparty\apiclient\alt\deferred.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\thirdparty\apiclient\device.js">
@ -202,7 +202,7 @@
<Content Include="dashboard-ui\thirdparty\apiclient\logger.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\thirdparty\apiclient\mediabrowser.apiclient.js">
<Content Include="dashboard-ui\thirdparty\apiclient\apiclient.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\channelitems.html">

Loading…
Cancel
Save