mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-16 02:55:44 +00:00
* Move PosterWithAudio to FFMpegCore
* Reduce windows only tests
* Update Directory.Build.props
* Create .editorconfig
* More cleanup
* Enable implicit usings
* Remove unused method
* Apply dotnet format
* Fix unused variable in AudioGateArgument
* Fix boolean conditions in AudioGateArgument
* Merge boolean conditions into pattern
* Use target-typed new
* Add linting to CI
* Add CUDA to HardwareAccelerationDevice enum
* Increase timeout for Video_Join_Image_Sequence
* Adjust Video_Join_Image_Sequence timeout
* Fix expected seconds in Video_Join_Image_Sequence
* Increase timeout for Video_TranscodeToMemory due to macos agents
Former-commit-id: f9f7161686
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System.Diagnostics;
|
|
using System.IO.Pipes;
|
|
using FFMpegCore.Pipes;
|
|
|
|
namespace FFMpegCore.Arguments
|
|
{
|
|
public abstract class PipeArgument
|
|
{
|
|
private string PipeName { get; }
|
|
public string PipePath => PipeHelpers.GetPipePath(PipeName);
|
|
|
|
protected NamedPipeServerStream Pipe { get; private set; } = null!;
|
|
private readonly PipeDirection _direction;
|
|
|
|
protected PipeArgument(PipeDirection direction)
|
|
{
|
|
PipeName = PipeHelpers.GetUnqiuePipeName();
|
|
_direction = direction;
|
|
}
|
|
|
|
public void Pre()
|
|
{
|
|
if (Pipe != null)
|
|
{
|
|
throw new InvalidOperationException("Pipe already has been opened");
|
|
}
|
|
|
|
Pipe = new NamedPipeServerStream(PipeName, _direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
|
|
}
|
|
|
|
public void Post()
|
|
{
|
|
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
|
|
Pipe?.Dispose();
|
|
Pipe = null!;
|
|
}
|
|
|
|
public async Task During(CancellationToken cancellationToken = default)
|
|
{
|
|
try
|
|
{
|
|
await ProcessDataAsync(cancellationToken).ConfigureAwait(false);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
Debug.WriteLine($"ProcessDataAsync on {GetType().Name} cancelled");
|
|
}
|
|
finally
|
|
{
|
|
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
|
|
if (Pipe is { IsConnected: true })
|
|
{
|
|
Pipe.Disconnect();
|
|
}
|
|
}
|
|
}
|
|
|
|
protected abstract Task ProcessDataAsync(CancellationToken token);
|
|
public abstract string Text { get; }
|
|
}
|
|
}
|