mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
27fc3eaa28
commit
ca86c86f44
7 changed files with 16 additions and 39 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue