From f896ec126f010c00eab22cad0c63eebff1b4a19f Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Mon, 11 May 2020 00:50:49 +0200 Subject: [PATCH] Slight renaming --- .../FFMpeg/Arguments/InputPipeArgument.cs | 2 +- .../FFMpeg/Arguments/OutputPipeArgument.cs | 2 +- FFMpegCore/FFMpeg/Pipes/IPipeDataReader.cs | 3 +-- FFMpegCore/FFMpeg/Pipes/IPipeDataWriter.cs | 3 +-- .../FFMpeg/Pipes/RawVideoPipeDataWriter.cs | 19 +++---------------- .../FFMpeg/Pipes/StreamPipeDataReader.cs | 18 ++++++------------ .../FFMpeg/Pipes/StreamPipeDataWriter.cs | 8 +++----- 7 files changed, 16 insertions(+), 39 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs index 23d915d..3d3b525 100644 --- a/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs @@ -24,7 +24,7 @@ public override async Task ProcessDataAsync(CancellationToken token) await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); if (!Pipe.IsConnected) throw new TaskCanceledException(); - await Writer.WriteDataAsync(Pipe, token).ConfigureAwait(false); + await Writer.CopyAsync(Pipe, token).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs index ca75775..40475fc 100644 --- a/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs @@ -21,7 +21,7 @@ public override async Task ProcessDataAsync(CancellationToken token) await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); if (!Pipe.IsConnected) throw new TaskCanceledException(); - await Reader.ReadDataAsync(Pipe, token).ConfigureAwait(false); + await Reader.CopyAsync(Pipe, token).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMpeg/Pipes/IPipeDataReader.cs b/FFMpegCore/FFMpeg/Pipes/IPipeDataReader.cs index ae616a1..030b5e9 100644 --- a/FFMpegCore/FFMpeg/Pipes/IPipeDataReader.cs +++ b/FFMpegCore/FFMpeg/Pipes/IPipeDataReader.cs @@ -5,8 +5,7 @@ namespace FFMpegCore.Pipes { public interface IPipeDataReader { - void ReadData(System.IO.Stream stream); - Task ReadDataAsync(System.IO.Stream stream, CancellationToken token); + Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken); string GetFormat(); } } diff --git a/FFMpegCore/FFMpeg/Pipes/IPipeDataWriter.cs b/FFMpegCore/FFMpeg/Pipes/IPipeDataWriter.cs index ff40272..594a27a 100644 --- a/FFMpegCore/FFMpeg/Pipes/IPipeDataWriter.cs +++ b/FFMpegCore/FFMpeg/Pipes/IPipeDataWriter.cs @@ -9,7 +9,6 @@ namespace FFMpegCore.Pipes public interface IPipeDataWriter { string GetFormat(); - void WriteData(System.IO.Stream pipe); - Task WriteDataAsync(System.IO.Stream pipe, CancellationToken token); + Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken); } } diff --git a/FFMpegCore/FFMpeg/Pipes/RawVideoPipeDataWriter.cs b/FFMpegCore/FFMpeg/Pipes/RawVideoPipeDataWriter.cs index 4261d49..d35e7d5 100644 --- a/FFMpegCore/FFMpeg/Pipes/RawVideoPipeDataWriter.cs +++ b/FFMpegCore/FFMpeg/Pipes/RawVideoPipeDataWriter.cs @@ -45,31 +45,18 @@ public string GetFormat() return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}"; } - public void WriteData(System.IO.Stream stream) + public async Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) { if (_framesEnumerator.Current != null) { CheckFrameAndThrow(_framesEnumerator.Current); - _framesEnumerator.Current.Serialize(stream); + await _framesEnumerator.Current.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false); } while (_framesEnumerator.MoveNext()) { CheckFrameAndThrow(_framesEnumerator.Current!); - _framesEnumerator.Current!.Serialize(stream); - } - } - - public async Task WriteDataAsync(System.IO.Stream stream, CancellationToken token) - { - if (_framesEnumerator.Current != null) - { - await _framesEnumerator.Current.SerializeAsync(stream, token).ConfigureAwait(false); - } - - while (_framesEnumerator.MoveNext()) - { - await _framesEnumerator.Current!.SerializeAsync(stream, token).ConfigureAwait(false); + await _framesEnumerator.Current!.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false); } } diff --git a/FFMpegCore/FFMpeg/Pipes/StreamPipeDataReader.cs b/FFMpegCore/FFMpeg/Pipes/StreamPipeDataReader.cs index 79aaea6..1e2d4c5 100644 --- a/FFMpegCore/FFMpeg/Pipes/StreamPipeDataReader.cs +++ b/FFMpegCore/FFMpeg/Pipes/StreamPipeDataReader.cs @@ -5,24 +5,18 @@ namespace FFMpegCore.Pipes { public class StreamPipeDataReader : IPipeDataReader { - public System.IO.Stream DestanationStream { get; private set; } + public System.IO.Stream Destination { get; } public int BlockSize { get; set; } = 4096; public string Format { get; set; } = string.Empty; - public StreamPipeDataReader(System.IO.Stream destanationStream) + public StreamPipeDataReader(System.IO.Stream destination) { - DestanationStream = destanationStream; + Destination = destination; } - public void ReadData(System.IO.Stream stream) => - stream.CopyTo(DestanationStream, BlockSize); + public Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken) => + inputStream.CopyToAsync(Destination, BlockSize, cancellationToken); - public Task ReadDataAsync(System.IO.Stream stream, CancellationToken token) => - stream.CopyToAsync(DestanationStream, BlockSize, token); - - public string GetFormat() - { - return Format; - } + public string GetFormat() => Format; } } diff --git a/FFMpegCore/FFMpeg/Pipes/StreamPipeDataWriter.cs b/FFMpegCore/FFMpeg/Pipes/StreamPipeDataWriter.cs index 752d163..c2e3d83 100644 --- a/FFMpegCore/FFMpeg/Pipes/StreamPipeDataWriter.cs +++ b/FFMpegCore/FFMpeg/Pipes/StreamPipeDataWriter.cs @@ -12,14 +12,12 @@ public class StreamPipeDataWriter : IPipeDataWriter public int BlockSize { get; } = 4096; public string StreamFormat { get; } = string.Empty; - public StreamPipeDataWriter(System.IO.Stream stream) + public StreamPipeDataWriter(System.IO.Stream source) { - Source = stream; + Source = source; } - public void WriteData(System.IO.Stream pipe) => Source.CopyTo(pipe, BlockSize); - - public Task WriteDataAsync(System.IO.Stream pipe, CancellationToken token) => Source.CopyToAsync(pipe, BlockSize, token); + public Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken); public string GetFormat() => StreamFormat; }