Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="VideoLAN.LibVLC.Windows" Version="4.0.0-alpha-20240819" />
<PackageReference Condition="$([MSBuild]::IsOsPlatform('Windows'))" Include="VideoLAN.LibVLC.Windows" Version="4.0.0-alpha-20251027" />
<PackageReference Condition="$([MSBuild]::IsOsPlatform('OSX'))" Include="VideoLAN.LibVLC.Mac" Version="3.1.3" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/LibVLCSharp/Helpers/MarshalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static RendererDescription Build(this RendererDescriptionStructure s) =
/// <returns>a ptr to the UTF8 string that needs to be freed after use</returns>
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);
Expand Down
129 changes: 122 additions & 7 deletions src/LibVLCSharp/MediaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -1594,7 +1598,7 @@ public float SpuTextScale

/// <summary>
/// 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.
/// </summary>
public string? AspectRatio
Expand Down Expand Up @@ -1699,15 +1703,34 @@ public Task<bool> TakeSnapshotAsync(uint num, string? filePath, uint width, uint
/// <summary>
/// Enable or disable deinterlace filter
/// </summary>
/// <param name="deinterlace">deinterlace state -1: auto (default), 0: disabled, 1: enabled</param>
/// <param name="deinterlaceType">type of deinterlace filter, empty string to disable</param>
public void SetDeinterlace(int deinterlace, string deinterlaceType = "")
/// <param name="deinterlace">deinterlace state: auto (default), disabled or enabled</param>
/// <param name="deinterlaceType">type of deinterlace filter from <see cref="DeinterlaceFilter"/>, empty string to disable</param>
/// <returns>true on success, false if the mode was not recognised</returns>
public bool SetDeinterlace(Deinterlace deinterlace, string? deinterlaceType = "")
{
var deinterlaceTypeUtf8 = deinterlaceType.ToUtf8();

MarshalUtils.PerformInteropAndFree(() =>
return MarshalUtils.PerformInteropAndFree(() =>
Native.LibVLCVideoSetDeinterlace(NativeReference, deinterlace, deinterlaceTypeUtf8),
deinterlaceTypeUtf8);
deinterlaceTypeUtf8) == 0;
}

/// <summary>
/// Enable or disable deinterlace filter
/// </summary>
/// <param name="deinterlace">deinterlace state: auto (default), disabled or enabled</param>
/// <param name="deinterlaceType">type of deinterlace filter</param>
/// <returns>true on success, false if the mode was not recognised</returns>
public bool SetDeinterlace(Deinterlace deinterlace, DeinterlaceFilter deinterlaceType)
=> SetDeinterlace(deinterlace, deinterlaceType.ToFilterString());

/// <summary>
/// Gets the deinterlacing parameters.
/// </summary>
public (string? deinterlaceMode, Deinterlace deinterlaceState) GetDeinterlace()
{
var result = Native.LibVLCVideoGetDeinterlace(NativeReference, out var deinterlaceMode);
return (deinterlaceMode: deinterlaceMode.FromUtf8(true), deinterlaceState: result);
}

/// <summary>
Expand Down Expand Up @@ -3912,4 +3935,96 @@ public enum VideoStereoMode
/// </summary>
SideBySide
}

/// <summary>
/// Deinterlacing state
/// </summary>
public enum Deinterlace
{
/// <summary>
/// Selected automatically
/// </summary>
Auto = -1,

/// <summary>
/// Forcefully disabled
/// </summary>
ForceDisabled = 0,

/// <summary>
/// Forcefully enabled
/// </summary>
ForceEnabled = 1
}

/// <summary>
/// Deinterlace filter modes
/// </summary>
public enum DeinterlaceFilter
{
/// <summary>
///
/// </summary>
Blend,

/// <summary>
///
/// </summary>
Discard,

/// <summary>
///
/// </summary>
Bob,

/// <summary>
///
/// </summary>
Linear,

/// <summary>
///
/// </summary>
Mean,

/// <summary>
///
/// </summary>
X,

/// <summary>
///
/// </summary>
Yadif2x,

/// <summary>
///
/// </summary>
Phosphor,

/// <summary>
///
/// </summary>
Ivtc,

/// <summary>
///
/// </summary>
Auto
}

/// <summary>
/// Extension methods for <see cref="DeinterlaceFilter"/>
/// </summary>
internal static class DeinterlaceFilterExtensions
{
/// <summary>
/// Converts the <see cref="DeinterlaceFilter"/> to its lowercase string representation
/// used by the native libVLC API.
/// </summary>
/// <param name="filter">The deinterlace filter</param>
/// <returns>The lowercase filter name</returns>
internal static string ToFilterString(this DeinterlaceFilter filter)
=> filter.ToString().ToLowerInvariant();
}
}