Commit 0ecc7e83 authored by Martin Finkel's avatar Martin Finkel

remove unsafe code

parent d2c46a65
......@@ -48,7 +48,6 @@ LibVLC needs to be installed separately, see VideoLAN.LibVLC.* packages.</Descri
<PackageIconUrl>https://code.videolan.org/videolan/LibVLCSharp/raw/master/Assets/icon.png</PackageIconUrl>
<PackageReleaseNotes>https://code.videolan.org/videolan/LibVLCSharp/blob/master/NEWS</PackageReleaseNotes>
<PackageTags>libvlc;vlc;videolan;native;c/c++;video;audio;player;media;mediaplayer;codec;ffmpeg;xamarin;graphics;ios;android;linux;windows;macos;cross-platform</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="$(UNITY_ANDROID)=='true'">
<TargetFramework>netstandard2.0</TargetFramework>
......
......@@ -1948,7 +1948,7 @@ namespace LibVLCSharp.Shared
/// <returns>true on success</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public unsafe delegate bool LibVLCD3DSetupCb(void** opaque, IntPtr config, IntPtr setup);
public delegate bool LibVLCD3DSetupCb(IntPtr opaque, IntPtr config, IntPtr setup);
/// <summary>
/// Cleanup the rendering environment initialized during <see cref="LibVLCD3DSetupCb"/>.
......@@ -1961,10 +1961,10 @@ namespace LibVLCSharp.Shared
public delegate void LibVLCD3DCleanupCb(IntPtr opaque);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Action_IntPtr_uint_uint(IntPtr report_opaque, uint width, uint height);
public delegate void ResizeReport(IntPtr report_opaque, uint width, uint height);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCD3DResize(IntPtr opaque, Action_IntPtr_uint_uint report_size_change, IntPtr report_opaque);
public delegate void LibVLCD3DResize(IntPtr opaque, ResizeReport report_size_change, IntPtr report_opaque);
/// <summary>
......@@ -2319,7 +2319,7 @@ namespace LibVLCSharp.Shared
/// video is full range or studio/limited range
/// </summary>
[FieldOffset(4)]
public byte FullRange;
public bool FullRange;
/// <summary>
/// video color space
......@@ -2341,34 +2341,23 @@ namespace LibVLCSharp.Shared
}
/// <summary>
///
/// Metadata for HDR10 medias
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 28)]
public unsafe struct D3DHDR10Metadata
[StructLayout(LayoutKind.Sequential)]
public struct D3DHDR10Metadata
{
[FieldOffset(0)]
internal fixed ushort RedPrimary[2];
[FieldOffset(4)]
internal fixed ushort GreenPrimary[2];
[FieldOffset(8)]
internal fixed ushort BluePrimary[2];
[FieldOffset(12)]
internal fixed ushort WhitePoint[2];
[FieldOffset(16)]
internal uint MaxMasteringLuminance;
[FieldOffset(20)]
internal uint MinMasteringLuminance;
[FieldOffset(24)]
internal ushort MaxContentLightLevel;
[FieldOffset(26)]
internal ushort MaxFrameAverageLightLevel;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public ushort[] RedPrimary;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public ushort[] GreenPrimary;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public ushort[] BluePrimary;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public ushort[] WhitePoint;
public uint MaxMasteringLuminance;
public uint MinMasteringLuminance;
public ushort MaxContentLightLevel;
public ushort MaxFrameAverageLightLevel;
}
......
......@@ -7,7 +7,6 @@
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<VlcWindowsX64Enabled>true</VlcWindowsX64Enabled>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
......
......@@ -16,7 +16,7 @@ namespace LibVLCSharp.D3DCallbacks
{
internal static class Program
{
unsafe static bool Setup(void** opaque, IntPtr config, IntPtr setupPtr)
static bool Setup(IntPtr opaque, IntPtr config, IntPtr setupPtr)
{
//Debug.WriteLine("Setup CALLED");
......@@ -29,12 +29,12 @@ namespace LibVLCSharp.D3DCallbacks
return true;
}
private static void Cleanup( IntPtr opaque)
private static void Cleanup(IntPtr opaque)
{
//Debug.WriteLine("Cleanup CALLED");
}
private static void Resize(IntPtr opaque, Action_IntPtr_uint_uint report_size_change, IntPtr report_opaque)
private static void Resize(IntPtr opaque, ResizeReport report_size_change, IntPtr report_opaque)
{
//Debug.WriteLine("Resize CALLED");
......@@ -44,7 +44,7 @@ namespace LibVLCSharp.D3DCallbacks
reportSize?.Invoke(reportOpaque, Convert.ToUInt32(form.ClientSize.Width), Convert.ToUInt32(form.ClientSize.Height));
}
private static unsafe bool UpdateOutput(IntPtr opaque, IntPtr configPtr, IntPtr outputPtr)
private static bool UpdateOutput(IntPtr opaque, IntPtr configPtr, IntPtr outputPtr)
{
//Debug.WriteLine("UpdateOutput CALLED");
......@@ -96,8 +96,7 @@ namespace LibVLCSharp.D3DCallbacks
var output = Marshal.PtrToStructure<OutputConfig>(outputPtr);
output.SurfaceFormat = 28;
bool enabled = true;
output.FullRange = *(byte*)&enabled;
output.FullRange = true;
output.ColorSpace = ColorSpace.BT709;
output.ColorPrimaries = ColorPrimaries.BT709;
output.TransferFunction = TransferFunction.SRGB;
......@@ -114,10 +113,32 @@ namespace LibVLCSharp.D3DCallbacks
swapChain.Present(0, PresentFlags.None);
}
private static bool StartEndRendering(IntPtr opaque, [MarshalAs(UnmanagedType.I1)] bool enter, IntPtr hdr)
private static bool StartEndRendering(IntPtr opaque, [MarshalAs(UnmanagedType.I1)] bool enter, IntPtr hdrPtr)
{
//Debug.WriteLine("StartEndRendering CALLED");
if (hdrPtr != IntPtr.Zero)
{
//var hdr = Marshal.PtrToStructure<D3DHDR10Metadata>(hdrPtr);
//foreach (var rp in hdr.RedPrimary)
// Debug.WriteLine($"{nameof(hdr.RedPrimary)}: {rp}");
//foreach (var rp in hdr.GreenPrimary)
// Debug.WriteLine($"{nameof(hdr.GreenPrimary)}: {rp}");
//foreach (var rp in hdr.BluePrimary)
// Debug.WriteLine($"{nameof(hdr.BluePrimary)}: {rp}");
//foreach (var rp in hdr.WhitePoint)
// Debug.WriteLine($"{nameof(hdr.WhitePoint)}: {rp}");
//Debug.WriteLine($"{nameof(hdr.MaxMasteringLuminance)}: {hdr.MaxMasteringLuminance}");
//Debug.WriteLine($"{nameof(hdr.MinMasteringLuminance)}: {hdr.MinMasteringLuminance}");
//Debug.WriteLine($"{nameof(hdr.MaxContentLightLevel)}: {hdr.MaxContentLightLevel}");
//Debug.WriteLine($"{nameof(hdr.MaxFrameAverageLightLevel)}: {hdr.MaxFrameAverageLightLevel}");
}
return true;
}
......@@ -133,7 +154,7 @@ namespace LibVLCSharp.D3DCallbacks
return true;
}
static Action_IntPtr_uint_uint reportSize;
static ResizeReport reportSize;
static IntPtr reportOpaque;
static Texture2D texture;
......@@ -230,11 +251,11 @@ namespace LibVLCSharp.D3DCallbacks
var libvlc = new LibVLC();
var mp = new MediaPlayer(libvlc);
mp.Media = new Media(libvlc, "C:\\Users\\Martin\\Videos\\[pseudo] Rick and Morty S01E08 - Rixty Minutes [1080p] [h.265].mkv");
unsafe
{
mp.SetDirect3DCallbacks(Direct3DEngine.D3D11, Setup, Cleanup, Resize, UpdateOutput, Swap, StartEndRendering, SelectPlane, IntPtr.Zero);
}
mp.Media = new Media(libvlc, "C:\\Users\\Martin\\Videos\\sample-Lucy 2014 2160p 4K UHD BluRay HDR10 HEVC BT2020 DTS-HD 5.1 Subs -DDR.mkv");
//mp.Media = new Media(libvlc, "C:\\Users\\Martin\\Videos\\[pseudo] Rick and Morty S01E08 - Rixty Minutes [1080p] [h.265].mkv");
mp.SetDirect3DCallbacks(Direct3DEngine.D3D11, Setup, Cleanup, Resize, UpdateOutput, Swap, StartEndRendering, SelectPlane, IntPtr.Zero);
mp.Play();
Console.ReadKey();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment