aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2019-11-07 14:24:49 -0500
committerAndrew Mahone <andrew.mahone@gmail.com>2019-11-07 14:24:49 -0500
commit79858eb26c60aa7ad8b6e63ee90fbd2e0727d594 (patch)
tree79f001c7daa8494e3610865d17bc3a453ad08054
parent380d02335151b5d84b537110c47915613e24dd3b (diff)
Remove use of ProcessFactory, as well as arbitrary timeout in AttachmentExtractor.
-rw-r--r--MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs31
-rw-r--r--MediaBrowser.MediaEncoding/packages.config3
2 files changed, 18 insertions, 16 deletions
diff --git a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
index f5f5d213f..369e597ea 100644
--- a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
+++ b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics;
using System.Collections.Concurrent;
using System.Globalization;
using System.IO;
@@ -31,7 +32,6 @@ namespace MediaBrowser.MediaEncoding.Attachments
private readonly IFileSystem _fileSystem;
private readonly IMediaEncoder _mediaEncoder;
private readonly IMediaSourceManager _mediaSourceManager;
- private readonly IProcessFactory _processFactory;
public AttachmentExtractor(
ILibraryManager libraryManager,
@@ -39,8 +39,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
IApplicationPaths appPaths,
IFileSystem fileSystem,
IMediaEncoder mediaEncoder,
- IMediaSourceManager mediaSourceManager,
- IProcessFactory processFactory)
+ IMediaSourceManager mediaSourceManager)
{
_libraryManager = libraryManager;
_logger = logger;
@@ -48,7 +47,6 @@ namespace MediaBrowser.MediaEncoding.Attachments
_fileSystem = fileSystem;
_mediaEncoder = mediaEncoder;
_mediaSourceManager = mediaSourceManager;
- _processFactory = processFactory;
}
private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
@@ -167,16 +165,19 @@ namespace MediaBrowser.MediaEncoding.Attachments
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
var processArgs = string.Format("-dump_attachment:{1} {2} -i {0} -t 0 -f null null", inputPath, attachmentStreamIndex, outputPath);
- var process = _processFactory.Create(new ProcessOptions
+ var startInfo = new ProcessStartInfo
{
- CreateNoWindow = true,
- UseShellExecute = false,
- EnableRaisingEvents = true,
- FileName = _mediaEncoder.EncoderPath,
Arguments = processArgs,
- IsHidden = true,
+ FileName = _mediaEncoder.EncoderPath,
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false
- });
+ };
+ var process = new Process
+ {
+ StartInfo = startInfo
+ };
_logger.LogInformation("{File} {Arguments}", process.StartInfo.FileName, process.StartInfo.Arguments);
@@ -191,7 +192,12 @@ namespace MediaBrowser.MediaEncoding.Attachments
throw;
}
- var ranToCompletion = await process.WaitForExitAsync(300000).ConfigureAwait(false);
+ var processTcs = new TaskCompletionSource<bool>();
+ process.EnableRaisingEvents = true;
+ process.Exited += (sender, args) => processTcs.TrySetResult(true);
+ var unregister = cancellationToken.Register(() => processTcs.TrySetResult(process.HasExited));
+ var ranToCompletion = await processTcs.Task.ConfigureAwait(false);
+ unregister.Dispose();
if (!ranToCompletion)
{
@@ -205,7 +211,6 @@ namespace MediaBrowser.MediaEncoding.Attachments
_logger.LogError(ex, "Error killing attachment extraction process");
}
}
-
var exitCode = ranToCompletion ? process.ExitCode : -1;
process.Dispose();
diff --git a/MediaBrowser.MediaEncoding/packages.config b/MediaBrowser.MediaEncoding/packages.config
deleted file mode 100644
index bbeaf5f00..000000000
--- a/MediaBrowser.MediaEncoding/packages.config
+++ /dev/null
@@ -1,3 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-</packages> \ No newline at end of file