Merge pull request #134 from rosenbjerg/master

Fix null reference exception on disconnect after dispose

Former-commit-id: 28b70d879d
This commit is contained in:
Malte Rosenbjerg 2020-12-06 00:51:18 +01:00 committed by GitHub
commit a20ca1ce11
8 changed files with 31 additions and 14 deletions

View file

@ -17,9 +17,5 @@ jobs:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Prepare FFMpeg - name: Prepare FFMpeg
run: sudo apt-get update && sudo apt-get install -y ffmpeg run: sudo apt-get update && sudo apt-get install -y ffmpeg
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Test with dotnet - name: Test with dotnet
run: dotnet test --logger GitHubActions run: dotnet test --logger GitHubActions

View file

@ -8,10 +8,6 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1
- name: Build solution - name: Build solution
run: dotnet build --output build run: dotnet build --output build
- name: Publish NuGet package - name: Publish NuGet package

View file

@ -3,6 +3,8 @@
using FFMpegCore.Test.Resources; using FFMpegCore.Test.Resources;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO; using System.IO;
using System.Threading.Tasks;
using FFMpegCore.Pipes;
namespace FFMpegCore.Test namespace FFMpegCore.Test
{ {
@ -40,6 +42,22 @@ public void Audio_Save()
if (File.Exists(output)) File.Delete(output); if (File.Exists(output)) File.Delete(output);
} }
} }
[TestMethod]
public async Task Audio_FromRaw()
{
await using var file = File.Open(VideoLibrary.LocalAudioRaw.FullName, FileMode.Open);
var memoryStream = new MemoryStream();
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(file), options => options.ForceFormat("s16le"))
.OutputToPipe(new StreamPipeSink(memoryStream), options =>
{
options.WithAudioSamplingRate(48000);
options.WithAudioCodec("libopus");
options.WithCustomArgument("-ac 2");
options.ForceFormat("opus");
})
.ProcessAsynchronously();
}
[TestMethod] [TestMethod]
public void Audio_Add() public void Audio_Add()

View file

@ -27,6 +27,9 @@
<None Update="Resources\input_video_only_3sec.mp4"> <None Update="Resources\input_video_only_3sec.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Resources\audio.raw">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -37,7 +40,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="1.1.2" /> <PackageReference Include="GitHubActionsTestLogger" Version="1.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" /> <PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" /> <PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
</ItemGroup> </ItemGroup>

View file

@ -21,6 +21,7 @@ public static class VideoLibrary
public static readonly FileInfo LocalVideoAudioOnly = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input_audio_only_10sec.mp4"); public static readonly FileInfo LocalVideoAudioOnly = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input_audio_only_10sec.mp4");
public static readonly FileInfo LocalVideoNoAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input_video_only_3sec.mp4"); public static readonly FileInfo LocalVideoNoAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input_video_only_3sec.mp4");
public static readonly FileInfo LocalAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio.mp3"); public static readonly FileInfo LocalAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio.mp3");
public static readonly FileInfo LocalAudioRaw = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio.raw");
public static readonly FileInfo LocalCover = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}cover.png"); public static readonly FileInfo LocalCover = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}cover.png");
public static readonly FileInfo ImageDirectory = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images"); public static readonly FileInfo ImageDirectory = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images");
public static readonly FileInfo ImageJoinOutput = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}output.mp4"); public static readonly FileInfo ImageJoinOutput = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}output.mp4");

Binary file not shown.

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO.Pipes; using System.IO.Pipes;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -30,6 +31,7 @@ public void Pre()
public void Post() public void Post()
{ {
Debug.WriteLine($"Disposing NamedPipeServerStream on {GetType().Name}");
Pipe?.Dispose(); Pipe?.Dispose();
Pipe = null!; Pipe = null!;
} }
@ -39,11 +41,13 @@ public async Task During(CancellationToken cancellationToken = default)
try try
{ {
await ProcessDataAsync(cancellationToken); await ProcessDataAsync(cancellationToken);
Debug.WriteLine($"Disconnecting NamedPipeServerStream on {GetType().Name}");
Pipe.Disconnect();
} }
catch (TaskCanceledException) catch (TaskCanceledException)
{ {
Debug.WriteLine($"ProcessDataAsync on {GetType().Name} cancelled");
} }
Pipe.Disconnect();
} }
protected abstract Task ProcessDataAsync(CancellationToken token); protected abstract Task ProcessDataAsync(CancellationToken token);

View file

@ -9,10 +9,9 @@
<Version>3.0.0.0</Version> <Version>3.0.0.0</Version>
<AssemblyVersion>3.0.0.0</AssemblyVersion> <AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0.0</FileVersion> <FileVersion>3.0.0.0</FileVersion>
<PackageReleaseNotes>- Updated dependencies <PackageReleaseNotes>- Fix NullReferenceException on Disconnect after Dispose</PackageReleaseNotes>
- Additional StreamPipeSink constructor</PackageReleaseNotes>
<LangVersion>8</LangVersion> <LangVersion>8</LangVersion>
<PackageVersion>3.2.0</PackageVersion> <PackageVersion>3.2.1</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Malte Rosenbjerg, Vlad Jerca</Authors> <Authors>Malte Rosenbjerg, Vlad Jerca</Authors>
<PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags> <PackageTags>ffmpeg ffprobe convert video audio mediafile resize analyze muxing</PackageTags>