re-enable sync

This commit is contained in:
Luke Pulverenti
2015-01-05 01:00:13 -05:00
parent e9fd871069
commit 00b5150999
7 changed files with 128 additions and 23 deletions

View File

@@ -82,5 +82,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
return null;
}
protected override bool IsVideoEncoder
{
get { return false; }
}
}
}

View File

@@ -142,6 +142,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
throw;
}
cancellationToken.Register(() => Cancel(process, encodingJob));
// MUST read both stdout and stderr asynchronously or a deadlock may occurr
process.BeginOutputReadLine();
@@ -157,6 +159,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
return encodingJob;
}
private void Cancel(Process process, EncodingJob job)
{
Logger.Info("Killing ffmpeg process for {0}", job.OutputFilePath);
//process.Kill();
process.StandardInput.WriteLine("q");
job.IsCancelled = true;
}
/// <summary>
/// Processes the exited.
/// </summary>
@@ -169,25 +181,53 @@ namespace MediaBrowser.MediaEncoding.Encoder
Logger.Debug("Disposing stream resources");
job.Dispose();
var isSuccesful = false;
try
{
Logger.Info("FFMpeg exited with code {0}", process.ExitCode);
var exitCode = process.ExitCode;
Logger.Info("FFMpeg exited with code {0}", exitCode);
isSuccesful = exitCode == 0;
}
catch
{
Logger.Error("FFMpeg exited with an error.");
}
if (isSuccesful && !job.IsCancelled)
{
job.TaskCompletionSource.TrySetResult(true);
}
else if (job.IsCancelled)
{
try
{
job.TaskCompletionSource.TrySetResult(true);
DeleteFiles(job);
}
catch
{
}
try
{
job.TaskCompletionSource.TrySetException(new OperationCanceledException());
}
catch
{
}
}
catch
else
{
Logger.Error("FFMpeg exited with an error.");
try
{
job.TaskCompletionSource.TrySetException(new ApplicationException());
DeleteFiles(job);
}
catch
{
}
try
{
job.TaskCompletionSource.TrySetException(new ApplicationException("Encoding failed"));
}
catch
{
@@ -206,6 +246,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
//}
}
protected virtual void DeleteFiles(EncodingJob job)
{
File.Delete(job.OutputFilePath);
}
private void OnTranscodeBeginning(EncodingJob job)
{
job.ReportTranscodingProgress(null, null, null, null);
@@ -219,10 +264,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
}
protected virtual bool IsVideoEncoder
{
get { return false; }
}
protected abstract bool IsVideoEncoder { get; }
protected virtual string GetWorkingDirectory(EncodingJobOptions options)
{
@@ -263,6 +305,12 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <returns>System.Int32.</returns>
protected int GetNumberOfThreads(EncodingJob job, bool isWebm)
{
// Only need one thread for sync
if (job.Options.Context == EncodingContext.Static)
{
return 1;
}
if (isWebm)
{
// Recommended per docs

View File

@@ -18,6 +18,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
public class EncodingJob : IDisposable
{
public bool HasExited { get; internal set; }
public bool IsCancelled { get; internal set; }
public Stream LogFileStream { get; set; }
public IProgress<double> Progress { get; set; }
@@ -399,6 +400,12 @@ namespace MediaBrowser.MediaEncoding.Encoder
// job.Framerate = framerate;
if (!percentComplete.HasValue && ticks.HasValue && RunTimeTicks.HasValue)
{
var pct = ticks.Value/RunTimeTicks.Value;
percentComplete = pct*100;
}
if (percentComplete.HasValue)
{
Progress.Report(percentComplete.Value);

View File

@@ -173,5 +173,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
return null;
}
protected override bool IsVideoEncoder
{
get { return true; }
}
}
}