Slight renaming

This commit is contained in:
Malte Rosenbjerg 2020-05-11 00:50:49 +02:00
parent b854d5b43b
commit f896ec126f
7 changed files with 16 additions and 39 deletions

View file

@ -24,7 +24,7 @@ public override async Task ProcessDataAsync(CancellationToken token)
await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false);
if (!Pipe.IsConnected) if (!Pipe.IsConnected)
throw new TaskCanceledException(); throw new TaskCanceledException();
await Writer.WriteDataAsync(Pipe, token).ConfigureAwait(false); await Writer.CopyAsync(Pipe, token).ConfigureAwait(false);
} }
} }
} }

View file

@ -21,7 +21,7 @@ public override async Task ProcessDataAsync(CancellationToken token)
await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false);
if (!Pipe.IsConnected) if (!Pipe.IsConnected)
throw new TaskCanceledException(); throw new TaskCanceledException();
await Reader.ReadDataAsync(Pipe, token).ConfigureAwait(false); await Reader.CopyAsync(Pipe, token).ConfigureAwait(false);
} }
} }
} }

View file

@ -5,8 +5,7 @@ namespace FFMpegCore.Pipes
{ {
public interface IPipeDataReader public interface IPipeDataReader
{ {
void ReadData(System.IO.Stream stream); Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken);
Task ReadDataAsync(System.IO.Stream stream, CancellationToken token);
string GetFormat(); string GetFormat();
} }
} }

View file

@ -9,7 +9,6 @@ namespace FFMpegCore.Pipes
public interface IPipeDataWriter public interface IPipeDataWriter
{ {
string GetFormat(); string GetFormat();
void WriteData(System.IO.Stream pipe); Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken);
Task WriteDataAsync(System.IO.Stream pipe, CancellationToken token);
} }
} }

View file

@ -45,31 +45,18 @@ public string GetFormat()
return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}"; 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) if (_framesEnumerator.Current != null)
{ {
CheckFrameAndThrow(_framesEnumerator.Current); CheckFrameAndThrow(_framesEnumerator.Current);
_framesEnumerator.Current.Serialize(stream); await _framesEnumerator.Current.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false);
} }
while (_framesEnumerator.MoveNext()) while (_framesEnumerator.MoveNext())
{ {
CheckFrameAndThrow(_framesEnumerator.Current!); CheckFrameAndThrow(_framesEnumerator.Current!);
_framesEnumerator.Current!.Serialize(stream); await _framesEnumerator.Current!.SerializeAsync(outputStream, cancellationToken).ConfigureAwait(false);
}
}
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);
} }
} }

View file

@ -5,24 +5,18 @@ namespace FFMpegCore.Pipes
{ {
public class StreamPipeDataReader : IPipeDataReader 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 int BlockSize { get; set; } = 4096;
public string Format { get; set; } = string.Empty; 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) => public Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken) =>
stream.CopyTo(DestanationStream, BlockSize); inputStream.CopyToAsync(Destination, BlockSize, cancellationToken);
public Task ReadDataAsync(System.IO.Stream stream, CancellationToken token) => public string GetFormat() => Format;
stream.CopyToAsync(DestanationStream, BlockSize, token);
public string GetFormat()
{
return Format;
}
} }
} }

View file

@ -12,14 +12,12 @@ public class StreamPipeDataWriter : IPipeDataWriter
public int BlockSize { get; } = 4096; public int BlockSize { get; } = 4096;
public string StreamFormat { get; } = string.Empty; 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 CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken);
public Task WriteDataAsync(System.IO.Stream pipe, CancellationToken token) => Source.CopyToAsync(pipe, BlockSize, token);
public string GetFormat() => StreamFormat; public string GetFormat() => StreamFormat;
} }