mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +00:00
Pass TestContext.CancellationToken to async invocations
This commit is contained in:
parent
ce87dc8a36
commit
c49f4c79ca
2 changed files with 23 additions and 19 deletions
|
|
@ -8,9 +8,9 @@ public class FFProbeTests
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task Audio_FromStream_Duration()
|
public async Task Audio_FromStream_Duration()
|
||||||
{
|
{
|
||||||
var fileAnalysis = await FFProbe.AnalyseAsync(TestResources.WebmVideo);
|
var fileAnalysis = await FFProbe.AnalyseAsync(TestResources.WebmVideo, cancellationToken: TestContext.CancellationToken);
|
||||||
await using var inputStream = File.OpenRead(TestResources.WebmVideo);
|
await using var inputStream = File.OpenRead(TestResources.WebmVideo);
|
||||||
var streamAnalysis = await FFProbe.AnalyseAsync(inputStream);
|
var streamAnalysis = await FFProbe.AnalyseAsync(inputStream, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsTrue(fileAnalysis.Duration == streamAnalysis.Duration);
|
Assert.IsTrue(fileAnalysis.Duration == streamAnalysis.Duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class FFProbeTests
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task FrameAnalysis_Async()
|
public async Task FrameAnalysis_Async()
|
||||||
{
|
{
|
||||||
var frameAnalysis = await FFProbe.GetFramesAsync(TestResources.WebmVideo);
|
var frameAnalysis = await FFProbe.GetFramesAsync(TestResources.WebmVideo, cancellationToken: TestContext.CancellationToken);
|
||||||
|
|
||||||
Assert.HasCount(90, frameAnalysis.Frames);
|
Assert.HasCount(90, frameAnalysis.Frames);
|
||||||
Assert.IsTrue(frameAnalysis.Frames.All(f => f.PixelFormat == "yuv420p"));
|
Assert.IsTrue(frameAnalysis.Frames.All(f => f.PixelFormat == "yuv420p"));
|
||||||
|
|
@ -41,7 +41,7 @@ public class FFProbeTests
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task PacketAnalysis_Async()
|
public async Task PacketAnalysis_Async()
|
||||||
{
|
{
|
||||||
var packetAnalysis = await FFProbe.GetPacketsAsync(TestResources.WebmVideo);
|
var packetAnalysis = await FFProbe.GetPacketsAsync(TestResources.WebmVideo, cancellationToken: TestContext.CancellationToken);
|
||||||
var packets = packetAnalysis.Packets;
|
var packets = packetAnalysis.Packets;
|
||||||
Assert.HasCount(96, packets);
|
Assert.HasCount(96, packets);
|
||||||
Assert.IsTrue(packets.All(f => f.CodecType == "video"));
|
Assert.IsTrue(packets.All(f => f.CodecType == "video"));
|
||||||
|
|
@ -97,7 +97,7 @@ public class FFProbeTests
|
||||||
[Ignore("Consistently fails on GitHub Workflow ubuntu agents")]
|
[Ignore("Consistently fails on GitHub Workflow ubuntu agents")]
|
||||||
public async Task Uri_Duration()
|
public async Task Uri_Duration()
|
||||||
{
|
{
|
||||||
var fileAnalysis = await FFProbe.AnalyseAsync(new Uri("https://github.com/rosenbjerg/FFMpegCore/raw/master/FFMpegCore.Test/Resources/input_3sec.webm"));
|
var fileAnalysis = await FFProbe.AnalyseAsync(new Uri("https://github.com/rosenbjerg/FFMpegCore/raw/master/FFMpegCore.Test/Resources/input_3sec.webm"), cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(fileAnalysis);
|
Assert.IsNotNull(fileAnalysis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,7 +161,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Async_Success()
|
public async Task Probe_Async_Success()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.Mp4Video);
|
var info = await FFProbe.AnalyseAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.AreEqual(3, info.Duration.Seconds);
|
Assert.AreEqual(3, info.Duration.Seconds);
|
||||||
Assert.IsNotNull(info.PrimaryVideoStream);
|
Assert.IsNotNull(info.PrimaryVideoStream);
|
||||||
Assert.AreEqual(8, info.PrimaryVideoStream.BitDepth);
|
Assert.AreEqual(8, info.PrimaryVideoStream.BitDepth);
|
||||||
|
|
@ -186,7 +186,7 @@ public class FFProbeTests
|
||||||
public async Task Probe_Success_FromStream_Async()
|
public async Task Probe_Success_FromStream_Async()
|
||||||
{
|
{
|
||||||
await using var stream = File.OpenRead(TestResources.WebmVideo);
|
await using var stream = File.OpenRead(TestResources.WebmVideo);
|
||||||
var info = await FFProbe.AnalyseAsync(stream);
|
var info = await FFProbe.AnalyseAsync(stream, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.AreEqual(3, info.Duration.Seconds);
|
Assert.AreEqual(3, info.Duration.Seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,7 +207,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_Subtitle_Async()
|
public async Task Probe_Success_Subtitle_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.SrtSubtitle);
|
var info = await FFProbe.AnalyseAsync(TestResources.SrtSubtitle, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimarySubtitleStream);
|
Assert.IsNotNull(info.PrimarySubtitleStream);
|
||||||
Assert.HasCount(1, info.SubtitleStreams);
|
Assert.HasCount(1, info.SubtitleStreams);
|
||||||
Assert.IsEmpty(info.AudioStreams);
|
Assert.IsEmpty(info.AudioStreams);
|
||||||
|
|
@ -220,7 +220,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_Disposition_Async()
|
public async Task Probe_Success_Disposition_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.Mp4Video);
|
var info = await FFProbe.AnalyseAsync(TestResources.Mp4Video, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimaryAudioStream);
|
Assert.IsNotNull(info.PrimaryAudioStream);
|
||||||
Assert.IsNotNull(info.PrimaryAudioStream.Disposition);
|
Assert.IsNotNull(info.PrimaryAudioStream.Disposition);
|
||||||
Assert.IsTrue(info.PrimaryAudioStream.Disposition["default"]);
|
Assert.IsTrue(info.PrimaryAudioStream.Disposition["default"]);
|
||||||
|
|
@ -231,7 +231,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_Mp3AudioBitDepthNull_Async()
|
public async Task Probe_Success_Mp3AudioBitDepthNull_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.Mp3Audio);
|
var info = await FFProbe.AnalyseAsync(TestResources.Mp3Audio, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimaryAudioStream);
|
Assert.IsNotNull(info.PrimaryAudioStream);
|
||||||
// mp3 is lossy, so bit depth is meaningless.
|
// mp3 is lossy, so bit depth is meaningless.
|
||||||
Assert.IsNull(info.PrimaryAudioStream.BitDepth);
|
Assert.IsNull(info.PrimaryAudioStream.BitDepth);
|
||||||
|
|
@ -241,7 +241,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_VocAudioBitDepth_Async()
|
public async Task Probe_Success_VocAudioBitDepth_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.AiffAudio);
|
var info = await FFProbe.AnalyseAsync(TestResources.AiffAudio, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimaryAudioStream);
|
Assert.IsNotNull(info.PrimaryAudioStream);
|
||||||
Assert.AreEqual(16, info.PrimaryAudioStream.BitDepth);
|
Assert.AreEqual(16, info.PrimaryAudioStream.BitDepth);
|
||||||
}
|
}
|
||||||
|
|
@ -250,7 +250,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_MkvVideoBitDepth_Async()
|
public async Task Probe_Success_MkvVideoBitDepth_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.MkvVideo);
|
var info = await FFProbe.AnalyseAsync(TestResources.MkvVideo, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimaryVideoStream);
|
Assert.IsNotNull(info.PrimaryVideoStream);
|
||||||
Assert.AreEqual(8, info.PrimaryVideoStream.BitDepth);
|
Assert.AreEqual(8, info.PrimaryVideoStream.BitDepth);
|
||||||
|
|
||||||
|
|
@ -262,7 +262,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_24BitWavBitDepth_Async()
|
public async Task Probe_Success_24BitWavBitDepth_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.Wav24Bit);
|
var info = await FFProbe.AnalyseAsync(TestResources.Wav24Bit, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimaryAudioStream);
|
Assert.IsNotNull(info.PrimaryAudioStream);
|
||||||
Assert.AreEqual(24, info.PrimaryAudioStream.BitDepth);
|
Assert.AreEqual(24, info.PrimaryAudioStream.BitDepth);
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +271,7 @@ public class FFProbeTests
|
||||||
[Timeout(10000, CooperativeCancellation = true)]
|
[Timeout(10000, CooperativeCancellation = true)]
|
||||||
public async Task Probe_Success_32BitWavBitDepth_Async()
|
public async Task Probe_Success_32BitWavBitDepth_Async()
|
||||||
{
|
{
|
||||||
var info = await FFProbe.AnalyseAsync(TestResources.Wav32Bit);
|
var info = await FFProbe.AnalyseAsync(TestResources.Wav32Bit, cancellationToken: TestContext.CancellationToken);
|
||||||
Assert.IsNotNull(info.PrimaryAudioStream);
|
Assert.IsNotNull(info.PrimaryAudioStream);
|
||||||
Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth);
|
Assert.AreEqual(32, info.PrimaryAudioStream.BitDepth);
|
||||||
}
|
}
|
||||||
|
|
@ -282,4 +282,6 @@ public class FFProbeTests
|
||||||
var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\"");
|
var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\"");
|
||||||
Assert.AreEqual(3, info.Duration.Seconds);
|
Assert.AreEqual(3, info.Duration.Seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -907,7 +907,7 @@ public class VideoTest
|
||||||
.CancellableThrough(out var cancel)
|
.CancellableThrough(out var cancel)
|
||||||
.ProcessAsynchronously(false);
|
.ProcessAsynchronously(false);
|
||||||
|
|
||||||
await Task.Delay(300);
|
await Task.Delay(300, TestContext.CancellationToken);
|
||||||
cancel();
|
cancel();
|
||||||
|
|
||||||
var result = await task;
|
var result = await task;
|
||||||
|
|
@ -930,7 +930,7 @@ public class VideoTest
|
||||||
.WithSpeedPreset(Speed.VeryFast))
|
.WithSpeedPreset(Speed.VeryFast))
|
||||||
.CancellableThrough(out var cancel);
|
.CancellableThrough(out var cancel);
|
||||||
|
|
||||||
Task.Delay(300).ContinueWith(_ => cancel());
|
Task.Delay(300, TestContext.CancellationToken).ContinueWith(_ => cancel(), TestContext.CancellationToken);
|
||||||
|
|
||||||
var result = task.ProcessSynchronously(false);
|
var result = task.ProcessSynchronously(false);
|
||||||
|
|
||||||
|
|
@ -954,12 +954,12 @@ public class VideoTest
|
||||||
.CancellableThrough(out var cancel, 10000)
|
.CancellableThrough(out var cancel, 10000)
|
||||||
.ProcessAsynchronously(false);
|
.ProcessAsynchronously(false);
|
||||||
|
|
||||||
await Task.Delay(300);
|
await Task.Delay(300, TestContext.CancellationToken);
|
||||||
cancel();
|
cancel();
|
||||||
|
|
||||||
await task;
|
await task;
|
||||||
|
|
||||||
var outputInfo = await FFProbe.AnalyseAsync(outputFile);
|
var outputInfo = await FFProbe.AnalyseAsync(outputFile, cancellationToken: TestContext.CancellationToken);
|
||||||
|
|
||||||
Assert.IsNotNull(outputInfo);
|
Assert.IsNotNull(outputInfo);
|
||||||
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
||||||
|
|
@ -1064,7 +1064,7 @@ public class VideoTest
|
||||||
|
|
||||||
await task;
|
await task;
|
||||||
|
|
||||||
var outputInfo = await FFProbe.AnalyseAsync(outputFile);
|
var outputInfo = await FFProbe.AnalyseAsync(outputFile, cancellationToken: TestContext.CancellationToken);
|
||||||
|
|
||||||
Assert.IsNotNull(outputInfo);
|
Assert.IsNotNull(outputInfo);
|
||||||
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
Assert.AreEqual(320, outputInfo.PrimaryVideoStream!.Width);
|
||||||
|
|
@ -1072,4 +1072,6 @@ public class VideoTest
|
||||||
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
||||||
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestContext TestContext { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue