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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue