diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs
index c51d9e7c01..b49fbce486 100644
--- a/MediaBrowser.Api/ApiEntryPoint.cs
+++ b/MediaBrowser.Api/ApiEntryPoint.cs
@@ -120,12 +120,15 @@ namespace MediaBrowser.Api
/// Called when [transcode beginning].
///
/// The path.
+ /// The transcoding job identifier.
/// The type.
/// The process.
/// The device id.
/// The state.
/// The cancellation token source.
- public void OnTranscodeBeginning(string path,
+ /// TranscodingJob.
+ public TranscodingJob OnTranscodeBeginning(string path,
+ string transcodingJobId,
TranscodingJobType type,
Process process,
string deviceId,
@@ -134,22 +137,37 @@ namespace MediaBrowser.Api
{
lock (_activeTranscodingJobs)
{
- _activeTranscodingJobs.Add(new TranscodingJob
+ var job = new TranscodingJob
{
Type = type,
Path = path,
Process = process,
ActiveRequestCount = 1,
DeviceId = deviceId,
- CancellationTokenSource = cancellationTokenSource
- });
+ CancellationTokenSource = cancellationTokenSource,
+ Id = transcodingJobId
+ };
- ReportTranscodingProgress(state, null, null);
+ _activeTranscodingJobs.Add(job);
+
+ ReportTranscodingProgress(job, state, null, null, null, null);
+
+ return job;
}
}
- public void ReportTranscodingProgress(StreamState state, float? framerate, double? percentComplete)
+ public void ReportTranscodingProgress(TranscodingJob job, StreamState state, TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded)
{
+ var ticks = transcodingPosition.HasValue ? transcodingPosition.Value.Ticks : (long?)null;
+
+ if (job != null)
+ {
+ job.Framerate = framerate;
+ job.CompletionPercentage = percentComplete;
+ job.TranscodingPositionTicks = ticks;
+ job.BytesTranscoded = bytesTranscoded;
+ }
+
var deviceId = state.Request.DeviceId;
if (!string.IsNullOrWhiteSpace(deviceId))
@@ -226,12 +244,20 @@ namespace MediaBrowser.Api
}
}
+ public TranscodingJob GetTranscodingJob(string id)
+ {
+ lock (_activeTranscodingJobs)
+ {
+ return _activeTranscodingJobs.FirstOrDefault(j => j.Id.Equals(id, StringComparison.OrdinalIgnoreCase));
+ }
+ }
+
///
/// Called when [transcode begin request].
///
/// The path.
/// The type.
- public void OnTranscodeBeginRequest(string path, TranscodingJobType type)
+ public TranscodingJob OnTranscodeBeginRequest(string path, TranscodingJobType type)
{
lock (_activeTranscodingJobs)
{
@@ -239,7 +265,7 @@ namespace MediaBrowser.Api
if (job == null)
{
- return;
+ return null;
}
job.ActiveRequestCount++;
@@ -249,40 +275,27 @@ namespace MediaBrowser.Api
job.KillTimer.Dispose();
job.KillTimer = null;
}
+
+ return job;
}
}
- ///
- /// Called when [transcode end request].
- ///
- /// The path.
- /// The type.
- public void OnTranscodeEndRequest(string path, TranscodingJobType type)
+ public void OnTranscodeEndRequest(TranscodingJob job)
{
- lock (_activeTranscodingJobs)
+ job.ActiveRequestCount--;
+
+ if (job.ActiveRequestCount == 0)
{
- var job = _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && j.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
+ // The HLS kill timer is long - 1/2 hr. clients should use the manual kill command when stopping.
+ var timerDuration = job.Type == TranscodingJobType.Progressive ? 1000 : 1800000;
- if (job == null)
+ if (job.KillTimer == null)
{
- return;
+ job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
}
-
- job.ActiveRequestCount--;
-
- if (job.ActiveRequestCount == 0)
+ else
{
- // The HLS kill timer is long - 1/2 hr. clients should use the manual kill command when stopping.
- var timerDuration = type == TranscodingJobType.Progressive ? 1000 : 1800000;
-
- if (job.KillTimer == null)
- {
- job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
- }
- else
- {
- job.KillTimer.Change(timerDuration, Timeout.Infinite);
- }
+ job.KillTimer.Change(timerDuration, Timeout.Infinite);
}
}
}
@@ -306,7 +319,6 @@ namespace MediaBrowser.Api
/// if set to true [acquire lock].
/// Task.
/// deviceId
- /// sourcePath
internal Task KillTranscodingJobs(string deviceId, Func deleteFiles, bool acquireLock)
{
if (string.IsNullOrEmpty(deviceId))
@@ -324,8 +336,7 @@ namespace MediaBrowser.Api
/// The delete files.
/// if set to true [acquire lock].
/// Task.
- /// deviceId
- internal async Task KillTranscodingJobs(Func killJob, Func deleteFiles, bool acquireLock)
+ internal async Task KillTranscodingJobs(Func killJob, Func deleteFiles, bool acquireLock)
{
var jobs = new List();
@@ -542,6 +553,17 @@ namespace MediaBrowser.Api
public object ProcessLock = new object();
public bool HasExited { get; set; }
+
+ public string Id { get; set; }
+
+ public float? Framerate { get; set; }
+ public double? CompletionPercentage { get; set; }
+
+ public long? BytesDownloaded { get; set; }
+ public long? BytesTranscoded { get; set; }
+
+ public long? TranscodingPositionTicks { get; set; }
+ public long? DownloadPositionTicks { get; set; }
}
///
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
index b0131b5c26..5cb9ebb1b0 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -169,7 +169,7 @@
-
+