diff --git a/samples/LibVLCSharp.NetCore.Sample/LibVLCSharp.NetCore.Sample.csproj b/samples/LibVLCSharp.NetCore.Sample/LibVLCSharp.NetCore.Sample.csproj index 6f012047..d0c0fdab 100644 --- a/samples/LibVLCSharp.NetCore.Sample/LibVLCSharp.NetCore.Sample.csproj +++ b/samples/LibVLCSharp.NetCore.Sample/LibVLCSharp.NetCore.Sample.csproj @@ -5,7 +5,7 @@ 8.0 - + diff --git a/src/LibVLCSharp/Helpers/MarshalExtensions.cs b/src/LibVLCSharp/Helpers/MarshalExtensions.cs index 592ef81d..6c861286 100644 --- a/src/LibVLCSharp/Helpers/MarshalExtensions.cs +++ b/src/LibVLCSharp/Helpers/MarshalExtensions.cs @@ -89,7 +89,7 @@ internal static RendererDescription Build(this RendererDescriptionStructure s) = /// a ptr to the UTF8 string that needs to be freed after use internal static IntPtr ToUtf8(this string? str) { - if (str == null) + if (str == null || str.Length == 0) return IntPtr.Zero; var bytes = Encoding.UTF8.GetBytes(str); diff --git a/src/LibVLCSharp/MediaPlayer.cs b/src/LibVLCSharp/MediaPlayer.cs index 02e1d740..cd3797a4 100644 --- a/src/LibVLCSharp/MediaPlayer.cs +++ b/src/LibVLCSharp/MediaPlayer.cs @@ -439,7 +439,11 @@ internal static extern int LibVLCVideoTakeSnapshot(IntPtr mediaPlayer, uint num, [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "libvlc_video_set_deinterlace")] - internal static extern void LibVLCVideoSetDeinterlace(IntPtr mediaPlayer, int deinterlace, IntPtr deinterlaceType); + internal static extern int LibVLCVideoSetDeinterlace(IntPtr mediaPlayer, Deinterlace deinterlace, IntPtr deinterlaceType); + + [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "libvlc_video_get_deinterlace")] + internal static extern Deinterlace LibVLCVideoGetDeinterlace(IntPtr mediaPlayer, out IntPtr deinterlaceMode); [DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "libvlc_video_get_marquee_int")] @@ -1594,7 +1598,7 @@ public float SpuTextScale /// /// Get/set current video aspect ratio. - /// Set to null to reset to source aspect ratio + /// "fill" to fill the window or null to reset to source aspect ratio /// Invalid aspect ratios are ignored. /// public string? AspectRatio @@ -1699,15 +1703,34 @@ public Task TakeSnapshotAsync(uint num, string? filePath, uint width, uint /// /// Enable or disable deinterlace filter /// - /// deinterlace state -1: auto (default), 0: disabled, 1: enabled - /// type of deinterlace filter, empty string to disable - public void SetDeinterlace(int deinterlace, string deinterlaceType = "") + /// deinterlace state: auto (default), disabled or enabled + /// type of deinterlace filter from , empty string to disable + /// true on success, false if the mode was not recognised + public bool SetDeinterlace(Deinterlace deinterlace, string? deinterlaceType = "") { var deinterlaceTypeUtf8 = deinterlaceType.ToUtf8(); - MarshalUtils.PerformInteropAndFree(() => + return MarshalUtils.PerformInteropAndFree(() => Native.LibVLCVideoSetDeinterlace(NativeReference, deinterlace, deinterlaceTypeUtf8), - deinterlaceTypeUtf8); + deinterlaceTypeUtf8) == 0; + } + + /// + /// Enable or disable deinterlace filter + /// + /// deinterlace state: auto (default), disabled or enabled + /// type of deinterlace filter + /// true on success, false if the mode was not recognised + public bool SetDeinterlace(Deinterlace deinterlace, DeinterlaceFilter deinterlaceType) + => SetDeinterlace(deinterlace, deinterlaceType.ToFilterString()); + + /// + /// Gets the deinterlacing parameters. + /// + public (string? deinterlaceMode, Deinterlace deinterlaceState) GetDeinterlace() + { + var result = Native.LibVLCVideoGetDeinterlace(NativeReference, out var deinterlaceMode); + return (deinterlaceMode: deinterlaceMode.FromUtf8(true), deinterlaceState: result); } /// @@ -3912,4 +3935,96 @@ public enum VideoStereoMode /// SideBySide } + + /// + /// Deinterlacing state + /// + public enum Deinterlace + { + /// + /// Selected automatically + /// + Auto = -1, + + /// + /// Forcefully disabled + /// + ForceDisabled = 0, + + /// + /// Forcefully enabled + /// + ForceEnabled = 1 + } + + /// + /// Deinterlace filter modes + /// + public enum DeinterlaceFilter + { + /// + /// + /// + Blend, + + /// + /// + /// + Discard, + + /// + /// + /// + Bob, + + /// + /// + /// + Linear, + + /// + /// + /// + Mean, + + /// + /// + /// + X, + + /// + /// + /// + Yadif2x, + + /// + /// + /// + Phosphor, + + /// + /// + /// + Ivtc, + + /// + /// + /// + Auto + } + + /// + /// Extension methods for + /// + internal static class DeinterlaceFilterExtensions + { + /// + /// Converts the to its lowercase string representation + /// used by the native libVLC API. + /// + /// The deinterlace filter + /// The lowercase filter name + internal static string ToFilterString(this DeinterlaceFilter filter) + => filter.ToString().ToLowerInvariant(); + } }