Update dependencies and add StreamPipeSink constructor

Former-commit-id: 5ba2ed97cf
This commit is contained in:
Malte Rosenbjerg 2020-11-25 16:15:16 +01:00
parent 56746915d8
commit 717d61dd07
12 changed files with 28 additions and 22 deletions

View file

@ -36,8 +36,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="1.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
</ItemGroup>

View file

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

View file

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

View file

@ -98,7 +98,7 @@ public async Task<bool> ProcessAsynchronously(bool throwOnError = true)
void OnCancelEvent(object sender, EventArgs args)
{
instance?.SendInput("q");
instance.SendInput("q");
cancellationTokenSource.Cancel();
instance.Started = false;
}

View file

@ -32,7 +32,7 @@ static FFMpegOptions()
{
if (File.Exists(ConfigFile))
{
Options = JsonSerializer.Deserialize<FFMpegOptions>(File.ReadAllText(ConfigFile));
Options = JsonSerializer.Deserialize<FFMpegOptions>(File.ReadAllText(ConfigFile))!;
foreach (var pair in DefaultExtensionsOverrides)
if (!Options.ExtensionOverrides.ContainsKey(pair.Key)) Options.ExtensionOverrides.Add(pair.Key, pair.Value);
}

View file

@ -5,7 +5,7 @@ namespace FFMpegCore.Pipes
{
public interface IPipeSink
{
Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken);
Task ReadAsync(System.IO.Stream inputStream, CancellationToken cancellationToken);
string GetFormat();
}
}

View file

@ -9,6 +9,6 @@ namespace FFMpegCore.Pipes
public interface IPipeSource
{
string GetFormat();
Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken);
Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken);
}
}

View file

@ -45,7 +45,7 @@ public string GetFormat()
return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}";
}
public async Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken)
public async Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken)
{
if (_framesEnumerator.Current != null)
{

View file

@ -1,21 +1,27 @@
using System.Threading;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace FFMpegCore.Pipes
{
public class StreamPipeSink : IPipeSink
{
public System.IO.Stream Destination { get; }
public Func<Stream, CancellationToken, Task> Writer { get; }
public int BlockSize { get; set; } = 4096;
public string Format { get; set; } = string.Empty;
public StreamPipeSink(System.IO.Stream destination)
public StreamPipeSink(Func<Stream, CancellationToken, Task> writer)
{
Destination = destination;
Writer = writer;
}
public StreamPipeSink(Stream destination)
{
Writer = (inputStream, cancellationToken) => inputStream.CopyToAsync(destination, BlockSize, cancellationToken);
}
public Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken) =>
inputStream.CopyToAsync(Destination, BlockSize, cancellationToken);
public Task ReadAsync(System.IO.Stream inputStream, CancellationToken cancellationToken)
=> Writer(inputStream, cancellationToken);
public string GetFormat() => Format;
}

View file

@ -17,7 +17,7 @@ public StreamPipeSource(System.IO.Stream source)
Source = source;
}
public Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken);
public Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken);
public string GetFormat() => StreamFormat;
}

View file

@ -9,10 +9,10 @@
<Version>3.0.0.0</Version>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion>
<PackageReleaseNotes>- Fix hanging pipes on unix sockets
- Internal API cleanup</PackageReleaseNotes>
<PackageReleaseNotes>- Updated dependencies
- Additional StreamPipeSink constructor</PackageReleaseNotes>
<LangVersion>8</LangVersion>
<PackageVersion>3.1.0</PackageVersion>
<PackageVersion>3.2.0</PackageVersion>
<Authors>Malte Rosenbjerg, Vlad Jerca</Authors>
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>
<RepositoryType>GitHub</RepositoryType>
@ -29,8 +29,8 @@
<ItemGroup>
<PackageReference Include="Instances" Version="1.6.0" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="5.0.0" />
</ItemGroup>
</Project>

View file

@ -98,7 +98,7 @@ private static IMediaAnalysis ParseOutput(string filePath, Instance instance)
var ffprobeAnalysis = JsonSerializer.Deserialize<FFProbeAnalysis>(json, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
})!;
return new MediaAnalysis(filePath, ffprobeAnalysis);
}