From 9feb9f5a22e7a4f2a9ed481fce0ed75f18bbfc57 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Tue, 27 Oct 2020 00:49:49 +0100 Subject: [PATCH] Fix output pipe hanging on unix sockets --- FFMpegCore/FFMpeg/Arguments/PipeArgument.cs | 4 ++-- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs index 16f9674..4a6113a 100644 --- a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs @@ -38,12 +38,12 @@ public async Task During(CancellationToken cancellationToken = default) { try { - await ProcessDataAsync(cancellationToken ?? CancellationToken.None).ConfigureAwait(false); + await ProcessDataAsync(cancellationToken); } catch (TaskCanceledException) { } - Post(); + Pipe.Disconnect(); } protected abstract Task ProcessDataAsync(CancellationToken token); diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 0f39b71..2307787 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -63,9 +63,8 @@ void OnCancelEvent(object sender, EventArgs args) Task.WaitAll(instance.FinishedRunning().ContinueWith(t => { errorCode = t.Result; - cancellationTokenSource.Cancel(); + _ffMpegArguments.Post(); }), _ffMpegArguments.During(cancellationTokenSource.Token)); - _ffMpegArguments.Post(); } catch (Exception e) { @@ -108,7 +107,7 @@ void OnCancelEvent(object sender, EventArgs args) await Task.WhenAll(instance.FinishedRunning().ContinueWith(t => { errorCode = t.Result; - cancellationTokenSource.Cancel(); + _ffMpegArguments.Post(); }), _ffMpegArguments.During(cancellationTokenSource.Token)).ConfigureAwait(false); } catch (Exception e) @@ -118,7 +117,6 @@ await Task.WhenAll(instance.FinishedRunning().ContinueWith(t => finally { CancelEvent -= OnCancelEvent; - _ffMpegArguments.Post(); } return HandleCompletion(throwOnError, errorCode, instance.ErrorData);