mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +00:00
FFProbe: Do not throw FFMpegException if cancellation was requested.
Throw OperationCancelledException in this case to provide more uniform and expected behavior. Fixes #594
This commit is contained in:
parent
930d493b8c
commit
b863f5d19e
2 changed files with 8 additions and 5 deletions
|
|
@ -84,7 +84,7 @@ public static class FFProbe
|
||||||
|
|
||||||
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
var instance = PrepareStreamAnalysisInstance(filePath, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
ThrowIfExitCodeNotZero(result);
|
ThrowIfExitCodeNotZero(result, cancellationToken);
|
||||||
|
|
||||||
return ParseOutput(result);
|
return ParseOutput(result);
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ public static class FFProbe
|
||||||
{
|
{
|
||||||
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
var instance = PrepareStreamAnalysisInstance(uri.AbsoluteUri, ffOptions ?? GlobalFFOptions.Current, customArguments);
|
||||||
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
var result = await instance.StartAndWaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
ThrowIfExitCodeNotZero(result);
|
ThrowIfExitCodeNotZero(result, cancellationToken);
|
||||||
|
|
||||||
return ParseOutput(result);
|
return ParseOutput(result);
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +150,7 @@ public static class FFProbe
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = await task.ConfigureAwait(false);
|
var result = await task.ConfigureAwait(false);
|
||||||
ThrowIfExitCodeNotZero(result);
|
ThrowIfExitCodeNotZero(result, cancellationToken);
|
||||||
|
|
||||||
pipeArgument.Post();
|
pipeArgument.Post();
|
||||||
return ParseOutput(result);
|
return ParseOutput(result);
|
||||||
|
|
@ -212,8 +212,11 @@ public static class FFProbe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ThrowIfExitCodeNotZero(IProcessResult result)
|
private static void ThrowIfExitCodeNotZero(IProcessResult result, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
// if cancellation requested, then we are not interested in the exit code, just throw the cancellation exception
|
||||||
|
// to get consistent and expected behavior.
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
if (result.ExitCode != 0)
|
if (result.ExitCode != 0)
|
||||||
{
|
{
|
||||||
var message = $"ffprobe exited with non-zero exit-code ({result.ExitCode} - {string.Join("\n", result.ErrorData)})";
|
var message = $"ffprobe exited with non-zero exit-code ({result.ExitCode} - {string.Join("\n", result.ErrorData)})";
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,6 @@ public static class ProcessArgumentsExtensions
|
||||||
public static async Task<IProcessResult> StartAndWaitForExitAsync(this ProcessArguments processArguments, CancellationToken cancellationToken = default)
|
public static async Task<IProcessResult> StartAndWaitForExitAsync(this ProcessArguments processArguments, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
using var instance = processArguments.Start();
|
using var instance = processArguments.Start();
|
||||||
return await instance.WaitForExitAsync(cancellationToken);
|
return await instance.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue