mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
Merge pull request #600 from rosenbjerg/ensure-cancellationtoken-passed-to-cancellablethrough-is-not-already-cancelled
Throw if CancellationToken passed to CancellableThrough is not already cancelled
This commit is contained in:
commit
e12bc2a148
2 changed files with 25 additions and 4 deletions
|
|
@ -1122,13 +1122,12 @@ public class VideoTest
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
||||||
public void Video_Cancel_CancellationToken_Before_Throws()
|
public void Video_Cancel_CancellationToken_BeforeProcessing_Throws()
|
||||||
{
|
{
|
||||||
using var outputFile = new TemporaryFile("out.mp4");
|
using var outputFile = new TemporaryFile("out.mp4");
|
||||||
|
|
||||||
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken);
|
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken);
|
||||||
|
|
||||||
cts.Cancel();
|
|
||||||
var task = FFMpegArguments
|
var task = FFMpegArguments
|
||||||
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
||||||
.WithCustomArgument("-re")
|
.WithCustomArgument("-re")
|
||||||
|
|
@ -1139,8 +1138,29 @@ public class VideoTest
|
||||||
.WithSpeedPreset(Speed.VeryFast))
|
.WithSpeedPreset(Speed.VeryFast))
|
||||||
.CancellableThrough(cts.Token);
|
.CancellableThrough(cts.Token);
|
||||||
|
|
||||||
Assert.ThrowsExactly<OperationCanceledException>(() => task.CancellableThrough(TestContext.CancellationToken)
|
cts.Cancel();
|
||||||
.ProcessSynchronously());
|
Assert.ThrowsExactly<OperationCanceledException>(() => task.ProcessSynchronously());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
||||||
|
public void Video_Cancel_CancellationToken_BeforePassing_Throws()
|
||||||
|
{
|
||||||
|
using var outputFile = new TemporaryFile("out.mp4");
|
||||||
|
|
||||||
|
using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken);
|
||||||
|
cts.Cancel();
|
||||||
|
|
||||||
|
var task = FFMpegArguments
|
||||||
|
.FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args
|
||||||
|
.WithCustomArgument("-re")
|
||||||
|
.ForceFormat("lavfi"))
|
||||||
|
.OutputToFile(outputFile, false, opt => opt
|
||||||
|
.WithAudioCodec(AudioCodec.Aac)
|
||||||
|
.WithVideoCodec(VideoCodec.LibX264)
|
||||||
|
.WithSpeedPreset(Speed.VeryFast));
|
||||||
|
|
||||||
|
Assert.ThrowsExactly<OperationCanceledException>(() => task.CancellableThrough(cts.Token));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ public class FFMpegArgumentProcessor
|
||||||
|
|
||||||
public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0)
|
public FFMpegArgumentProcessor CancellableThrough(CancellationToken token, int timeout = 0)
|
||||||
{
|
{
|
||||||
|
token.ThrowIfCancellationRequested();
|
||||||
_cancellationTokenRegistration?.Dispose();
|
_cancellationTokenRegistration?.Dispose();
|
||||||
_cancellationTokenRegistration = token.Register(() => Cancel(timeout));
|
_cancellationTokenRegistration = token.Register(() => Cancel(timeout));
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue