From 5f2147e20708a3475f32616bb34d8b684ed91987 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 16 Oct 2025 13:03:26 +0200 Subject: [PATCH] Fix formatting --- FFMpegCore.Test/FFProbeTests.cs | 7 +- FFMpegCore.Test/VideoTest.cs | 4 +- FFMpegCore/FFMpeg/Arguments/PipeArgument.cs | 93 ++++++++++----------- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 049fc2e..a702eed 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -5,6 +5,8 @@ namespace FFMpegCore.Test; [TestClass] public class FFProbeTests { + public TestContext TestContext { get; set; } + [TestMethod] public async Task Audio_FromStream_Duration() { @@ -97,7 +99,8 @@ public class FFProbeTests [Ignore("Consistently fails on GitHub Workflow ubuntu agents")] 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"), cancellationToken: TestContext.CancellationToken); + 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); } @@ -282,6 +285,4 @@ public class FFProbeTests var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\""); Assert.AreEqual(3, info.Duration.Seconds); } - - public TestContext TestContext { get; set; } } diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index dadb26e..9bcca7c 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -19,6 +19,8 @@ public class VideoTest { private const int BaseTimeoutMilliseconds = 15_000; + public TestContext TestContext { get; set; } + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public void Video_ToOGV() @@ -1072,6 +1074,4 @@ public class VideoTest Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName); Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName); } - - public TestContext TestContext { get; set; } } diff --git a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs index 0fa0f7c..ee2d6f7 100644 --- a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs @@ -2,70 +2,69 @@ using System.IO.Pipes; using FFMpegCore.Pipes; -namespace FFMpegCore.Arguments +namespace FFMpegCore.Arguments; + +public abstract class PipeArgument { - public abstract class PipeArgument + private readonly PipeDirection _direction; + + protected PipeArgument(PipeDirection direction) { - private string PipeName { get; } - public string PipePath => PipeHelpers.GetPipePath(PipeName); + PipeName = PipeHelpers.GetUnqiuePipeName(); + _direction = direction; + } - protected NamedPipeServerStream Pipe { get; private set; } = null!; - private readonly PipeDirection _direction; + private string PipeName { get; } + public string PipePath => PipeHelpers.GetPipePath(PipeName); - protected PipeArgument(PipeDirection direction) + protected NamedPipeServerStream Pipe { get; private set; } = null!; + public abstract string Text { get; } + + public void Pre() + { + if (Pipe != null) { - PipeName = PipeHelpers.GetUnqiuePipeName(); - _direction = direction; + throw new InvalidOperationException("Pipe already has been opened"); } - public void Pre() - { - if (Pipe != null) - { - throw new InvalidOperationException("Pipe already has been opened"); - } + Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); + } - Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); + public void Post() + { + Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}"); + lock (Pipe) + { + Pipe?.Dispose(); + Pipe = null!; } + } - public void Post() + public async Task During(CancellationToken cancellationToken = default) + { + try { - Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}"); - lock(Pipe) - { - - Pipe?.Dispose(); - Pipe = null!; - } + await ProcessDataAsync(cancellationToken).ConfigureAwait(false); } - - public async Task During(CancellationToken cancellationToken = default) + catch (OperationCanceledException) { - try + Debug.WriteLine($"ProcessDataAsync on {GetType().Name} cancelled"); + } + finally + { + Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}"); + lock (Pipe ?? new object()) + //if Pipe is null, then the lock doesnt matter, + //Because the next code will not execute anyways. + //so we can use a new object { - await ProcessDataAsync(cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - Debug.WriteLine($"ProcessDataAsync on {GetType().Name} cancelled"); - } - finally - { - Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}"); - lock (Pipe ?? new object()) - //if Pipe is null, then the lock doesnt matter, - //Because the next code will not execute anyways. - //so we can use a new object + if (Pipe is { IsConnected: true }) { - if (Pipe is { IsConnected: true }) - { - Pipe.Disconnect(); - } + Pipe.Disconnect(); } } } - - protected abstract Task ProcessDataAsync(CancellationToken token); - public abstract string Text { get; } } + + protected abstract Task ProcessDataAsync(CancellationToken token); }