Skip to content

Commit 61ef3b9

Browse files
committed
Updating to 3.4.3
-= Video Acceleration Performance Improvements =- * Introduces Config.Decoder.ZeroCopy (enabled by default) to use the decoder's texture directly to the renderer's pipeline * Introduces Config.Decoder.VAPoolSize to pre-allocate the hardware frames on the ffmpeg decoder (it was re-allocating them on every flush causing serious performance issues) * Adds support for streams that change codecs live/dynamically (still in progress) * Improves Player.Stop() with interrupt while opening [Issues] * Fixes a crashing issue during renderer's disposal * Fixes an issue on audio device removal (by resetting players' with this device to default) * Fixes an issue with VolumeMax * Fixes an issue with Volume's value accuracy on get * Fixes UI update issues with Volume and Mute * Fixes an issue with AddFirewallRule and findstr (uses literal strings now) * Prevents Youtube-DL from opening some radio stations and mp3 (to avoid the delay) [Important/Breaking Changes] Drops support for MaxVideoFramesReverse, will use MaxVideoFrames instead (cannot be different at the moment)
1 parent 36c87d4 commit 61ef3b9

12 files changed

Lines changed: 360 additions & 142 deletions

File tree

FlyleafLib.Controls.WPF/FlyleafLib.Controls.WPF.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net6.0-windows;net5.0-windows;net472</TargetFrameworks>
55
<UseWindowsForms>true</UseWindowsForms>
66
<UseWPF>true</UseWPF>
7-
<Version>1.1.16</Version>
7+
<Version>1.1.17</Version>
88
<Authors>SuRGeoNix</Authors>
99
<Copyright>SuRGeoNix © 2021</Copyright>
1010
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
@@ -14,7 +14,7 @@
1414
<PackageTags>flyleaf flyleaflib video audio media player element control</PackageTags>
1515
<Description>WPF Media Player Control/Element (based on FlyleafLib)</Description>
1616
<PackageReleaseNotes>
17-
Updates FlyleafLib to v3.4.2
17+
Updates FlyleafLib to v3.4.3
1818
</PackageReleaseNotes>
1919
</PropertyGroup>
2020

FlyleafLib.Controls.WPF/Settings.xaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
<RowDefinition Height="30"/>
264264
<RowDefinition Height="30"/>
265265
<RowDefinition Height="30"/>
266+
<RowDefinition Height="30"/>
266267
</Grid.RowDefinitions>
267268

268269
<TextBlock Text="Aspect Ratio" VerticalAlignment="Center"/>
@@ -301,20 +302,23 @@
301302
<TextBlock Grid.Row="3" Text="Video Acceleration" VerticalAlignment="Center"/>
302303
<ToggleButton Grid.Row="3" Grid.Column="1" Tag="_save" IsChecked="{Binding Config.Video.VideoAcceleration, UpdateSourceTrigger=Explicit}" HorizontalAlignment="Left" Style="{StaticResource MaterialDesignSwitchDarkToggleButton}"/>
303304

304-
<TextBlock Grid.Row="4" Text="Decoder Threads" VerticalAlignment="Center"/>
305-
<TextBox Grid.Row="4" Grid.Column="1" Style="{StaticResource FLTextboxNP}" Text="{Binding Config.Decoder.VideoThreads, UpdateSourceTrigger=Explicit}"/>
305+
<TextBlock Grid.Row="4" Text="Zero Copy" VerticalAlignment="Center"/>
306+
<ToggleButton Grid.Row="4" Grid.Column="1" Tag="_save" IsChecked="{Binding Config.Decoder.ZeroCopy, UpdateSourceTrigger=Explicit}" HorizontalAlignment="Left" Style="{StaticResource MaterialDesignSwitchDarkToggleButton}"/>
307+
308+
<TextBlock Grid.Row="5" Text="Decoder Threads" VerticalAlignment="Center"/>
309+
<TextBox Grid.Row="5" Grid.Column="1" Style="{StaticResource FLTextboxNP}" Text="{Binding Config.Decoder.VideoThreads, UpdateSourceTrigger=Explicit}"/>
306310

307-
<TextBlock Grid.Row="5" Text="HDR to SDR Method" VerticalAlignment="Center"/>
308-
<ComboBox Grid.Row="5" x:Name="cmbHDRtoSDRMethod" Grid.Column="1" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Config.Video.HDRtoSDRMethod}"/>
311+
<TextBlock Grid.Row="6" Text="HDR to SDR Method" VerticalAlignment="Center"/>
312+
<ComboBox Grid.Row="6" x:Name="cmbHDRtoSDRMethod" Grid.Column="1" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" SelectedItem="{Binding Config.Video.HDRtoSDRMethod}"/>
309313

310-
<TextBlock Grid.Row="6" Text="HDR to SDR Tone" VerticalAlignment="Center"/>
311-
<TextBox Grid.Row="6" Grid.Column="1" Style="{StaticResource FLTextbox}" Text="{Binding Config.Video.HDRtoSDRTone, UpdateSourceTrigger=LostFocus}"/>
314+
<TextBlock Grid.Row="7" Text="HDR to SDR Tone" VerticalAlignment="Center"/>
315+
<TextBox Grid.Row="7" Grid.Column="1" Style="{StaticResource FLTextbox}" Text="{Binding Config.Video.HDRtoSDRTone, UpdateSourceTrigger=LostFocus}"/>
312316

313-
<TextBlock Grid.Row="7" Text="Brightness" Margin="0,10,0,0" VerticalAlignment="Center"/>
314-
<Slider Grid.Row="7" Grid.Column="2" Margin="-78,10,0,0" Style="{StaticResource MaterialDesignDiscreteSlider}" Value="{Binding Config.Video.Brightness, Mode=TwoWay}" Minimum="0" Maximum="100"/>
317+
<TextBlock Grid.Row="8" Text="Brightness" Margin="0,10,0,0" VerticalAlignment="Center"/>
318+
<Slider Grid.Row="8" Grid.Column="2" Margin="-78,10,0,0" Style="{StaticResource MaterialDesignDiscreteSlider}" Value="{Binding Config.Video.Brightness, Mode=TwoWay}" Minimum="0" Maximum="100"/>
315319

316-
<TextBlock Grid.Row="8" Text="Contrast" Margin="0,10,0,0" VerticalAlignment="Center"/>
317-
<Slider Grid.Row="8" Grid.Column="2" Margin="-78,10,0,0" Style="{StaticResource MaterialDesignDiscreteSlider}" HorizontalAlignment="Stretch" Value="{Binding Config.Video.Contrast, Mode=TwoWay}" Minimum="0" Maximum="100"/>
320+
<TextBlock Grid.Row="9" Text="Contrast" Margin="0,10,0,0" VerticalAlignment="Center"/>
321+
<Slider Grid.Row="9" Grid.Column="2" Margin="-78,10,0,0" Style="{StaticResource MaterialDesignDiscreteSlider}" HorizontalAlignment="Stretch" Value="{Binding Config.Video.Contrast, Mode=TwoWay}" Minimum="0" Maximum="100"/>
318322

319323
</Grid>
320324
<StackPanel Margin="0, 0, 0, 10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom">
@@ -343,7 +347,6 @@
343347
<RowDefinition Height="30"/>
344348
<RowDefinition Height="30"/>
345349
<RowDefinition Height="30"/>
346-
<RowDefinition Height="30"/>
347350
</Grid.RowDefinitions>
348351

349352
<TextBlock Grid.Row="0" Text="Buffer Duration Min. (ms)" VerticalAlignment="Center"/>
@@ -357,9 +360,6 @@
357360

358361
<TextBlock Grid.Row="3" Text="Video Frames Max." VerticalAlignment="Center"/>
359362
<TextBox Grid.Row="3" Grid.Column="1" Style="{StaticResource FLTextboxNP}" Text="{Binding Config.Decoder.MaxVideoFrames, UpdateSourceTrigger=Explicit}"/>
360-
361-
<TextBlock Grid.Row="4" Text="Reverse Frames Max." VerticalAlignment="Center"/>
362-
<TextBox Grid.Row="4" Grid.Column="1" Style="{StaticResource FLTextboxNP}" Text="{Binding Config.Decoder.MaxVideoFramesReverse, UpdateSourceTrigger=Explicit}"/>
363363
</Grid>
364364
<StackPanel Margin="0, 0, 0, 10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom">
365365
<Button Style="{StaticResource SaveButton}"/>

FlyleafLib/Config.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,13 @@ public class DecoderConfig : NotifyPropertyChanged
346346
/// <summary>
347347
/// Maximum video frames to be decoded and processed for rendering
348348
/// </summary>
349-
public int MaxVideoFrames { get; set; } = 4;
349+
public int MaxVideoFrames { get => _MaxVideoFrames; set { if (Set(ref _MaxVideoFrames, value)) { player?.Video?.Disable(); player?.Video?.Enable(); } } }
350+
int _MaxVideoFrames = 4;
350351

351352
/// <summary>
352-
/// Maximum video frames to be decoded and processed for rendering (reverse playback)
353-
/// Larger values will reduce GPU/CPU and increase VRAM/RAM
353+
/// Initial hardware frames pool size for the decoder (MaxVideoFrames will be added to this)
354354
/// </summary>
355-
public int MaxVideoFramesReverse
356-
{ get; set; } = Math.Max(30, Environment.ProcessorCount * 3);
355+
public int VAPoolSize { get; set; } = 15;
357356

358357
/// <summary>
359358
/// Maximum audio frames to be decoded and processed for playback
@@ -369,6 +368,13 @@ public int MaxVideoFramesReverse
369368
/// Maximum allowed errors before stopping
370369
/// </summary>
371370
public int MaxErrors { get; set; } = 200;
371+
372+
/// <summary>
373+
/// Whether or not to use decoder's textures directly as shader resources
374+
/// (TBR: Better performance but might need to be disabled while video input has padding or not supported by older Direct3D versions)
375+
/// </summary>
376+
public bool ZeroCopy { get => _ZeroCopy; set { if (Set(ref _ZeroCopy, value)) player?.renderer?.FrameResized(); } }
377+
bool _ZeroCopy = true;
372378
}
373379
public class VideoConfig : NotifyPropertyChanged
374380
{

FlyleafLib/FlyleafLib.csproj

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageIconUrl />
99
<RepositoryUrl></RepositoryUrl>
1010
<Description>Media Player .NET Library for WPF/WinForms (based on FFmpeg/DirectX)</Description>
11-
<Version>3.4.2</Version>
11+
<Version>3.4.3</Version>
1212
<Authors>SuRGeoNix</Authors>
1313
<Copyright>SuRGeoNix © 2021</Copyright>
1414
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
@@ -17,19 +17,25 @@
1717
<IncludeSymbols>true</IncludeSymbols>
1818
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1919
<PackageReleaseNotes>
20-
-= Re-design audio implementation from the decoder's to the player's layer =-
20+
-= Video Acceleration Performance Improvements =-
2121

22-
* Replaces NAudio's Core/Wasapi with Vortice's XAudio2/MediaFoundation (Direct COM Interops)
23-
* Performance and memory improvements for audio processing by using a single custom circular buffer
24-
* Better audio/video sync and more accurate timestamps as now audio plays with zero latency
25-
* More clear sound with no gaps between audio frames (it was happening at the beginning and after seeking)
26-
* Possible fixes for audio bluetooth devices and few other NAudio issues with dead locks and threading
22+
* Introduces Config.Decoder.ZeroCopy (enabled by default) to use the decoder's texture directly to the renderer's pipeline
23+
* Introduces Config.Decoder.VAPoolSize to pre-allocate the hardware frames on the ffmpeg decoder (it was re-allocating them on every flush causing serious performance issues)
24+
* Adds support for streams that change codecs live/dynamically (still in progress)
25+
* Improves Player.Stop() with interrupt while opening
26+
27+
[Issues]
28+
29+
* Fixes a crashing issue during renderer's disposal
30+
* Fixes an issue on audio device removal (by resetting players' with this device to default)
31+
* Fixes an issue with VolumeMax
32+
* Fixes an issue with Volume's value accuracy on get
33+
* Fixes UI update issues with Volume and Mute
34+
* Fixes an issue with AddFirewallRule and findstr (uses literal strings now)
2735

2836
[Important/Breaking Changes]
2937

30-
* Audio output format changed from 32-bit to 16-bit (faster processing/less memory as currenlty 32-bit not required)
31-
* AudioMaster handles only the audio devices now (everything else has been removed, e.g. master/session's volume/mute etc.)
32-
* Config.Audio.Latency has been removed
38+
* Drops support for MaxVideoFramesReverse, will use MaxVideoFrames instead
3339
</PackageReleaseNotes>
3440
</PropertyGroup>
3541

FlyleafLib/MediaFramework/MediaDecoder/AudioDecoder.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,27 @@ protected override void RunInternal()
244244
[SecurityCritical]
245245
private AudioFrame ProcessAudioFrame(AVFrame* frame)
246246
{
247+
// TBR: AVStream doesn't refresh, we can get the updated info only from codecCtx (what about timebase, what about re-opening the codec?)
248+
if (AudioStream.SampleRate != codecCtx->sample_rate || AudioStream.CodecID != codecCtx->codec_id || AudioStream.Channels != codecCtx->channels)
249+
{
250+
if (Disposed)
251+
return null;
252+
253+
Log($"Codec changed {AudioStream.CodecID} {AudioStream.SampleRate} => {codecCtx->codec_id} {codecCtx->sample_rate}");
254+
255+
DisposeInternal();
256+
257+
AudioStream.SampleFormat = (AVSampleFormat) Enum.ToObject(typeof(AVSampleFormat), codecCtx->sample_fmt);
258+
AudioStream.SampleFormatStr = AudioStream.SampleFormat.ToString().Replace("AV_SAMPLE_FMT_","").ToLower();
259+
AudioStream.SampleRate = codecCtx->sample_rate;
260+
AudioStream.ChannelLayout = codecCtx->channel_layout;
261+
AudioStream.Channels = codecCtx->channels;
262+
AudioStream.Bits = codecCtx->bits_per_coded_sample;
263+
264+
Setup(codecCtx->codec);
265+
CodecChanged?.Invoke(this);
266+
}
267+
247268
if (Speed != 1)
248269
{
249270
curSpeedFrame++;

0 commit comments

Comments
 (0)