Commit e17dd7b6 authored by Martin Finkel's avatar Martin Finkel

Add texture d3d sample

parent ed702068
......@@ -91,6 +91,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.MediaPlayerElement.i
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.MediaPlayerElement.UWP", "Samples\Uno\Sample.MediaPlayerElement\Sample.MediaPlayerElement.UWP\Sample.MediaPlayerElement.UWP.csproj", "{3CCE13EB-C3E6-491A-BEDD-7B3EDDB12549}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibVLCSharp.D3DCallbacks.Texture", "Samples\LibVLCSharp.D3DCallbacks.Texture\LibVLCSharp.D3DCallbacks.Texture.csproj", "{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Samples\Uno\LibVLCSharp.Uno.Sample.Shared\LibVLCSharp.Uno.Sample.Shared.projitems*{328e54f9-528f-4b00-a44c-aad35376d808}*SharedItemsImports = 4
......@@ -2053,6 +2055,62 @@ Global
{3CCE13EB-C3E6-491A-BEDD-7B3EDDB12549}.Release|x86.ActiveCfg = Release|x86
{3CCE13EB-C3E6-491A-BEDD-7B3EDDB12549}.Release|x86.Build.0 = Release|x86
{3CCE13EB-C3E6-491A-BEDD-7B3EDDB12549}.Release|x86.Deploy.0 = Release|x86
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|ARM64.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|ARM64.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|ARM.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|ARM64.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|ARM64.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|iPhone.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|x64.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|x64.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|x86.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.AppStore|x86.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|ARM.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|ARM64.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|iPhone.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|x64.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|x86.ActiveCfg = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Debug|x86.Build.0 = Debug|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|Any CPU.Build.0 = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|ARM.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|ARM.Build.0 = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|ARM64.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|ARM64.Build.0 = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|iPhone.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|iPhone.Build.0 = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|x64.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|x64.Build.0 = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|x86.ActiveCfg = Release|Any CPU
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -2088,6 +2146,7 @@ Global
{7C954316-4FCC-4FF4-B86A-7640DD857842} = {A5558B4F-67BD-4FDC-82F5-D82A6564CD7B}
{EF68D2A7-067D-427C-9690-5E0F0DD06F2B} = {A5558B4F-67BD-4FDC-82F5-D82A6564CD7B}
{3CCE13EB-C3E6-491A-BEDD-7B3EDDB12549} = {A5558B4F-67BD-4FDC-82F5-D82A6564CD7B}
{4E422789-97C8-4E84-BE3A-0CF61FF49E8F} = {799A84A2-2161-4676-878B-5610E3586137}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB1424F9-871B-444A-9278-18227672889C}
......
......@@ -41,7 +41,7 @@ LibVLC needs to be installed separately, see VideoLAN.LibVLC.* packages.</Descri
<Owners>VideoLAN</Owners>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!--<TreatWarningsAsErrors>true</TreatWarningsAsErrors>-->
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<PackageLicenseExpression>LGPL-2.1-or-later</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
......
......@@ -605,6 +605,11 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.UnityPlugin, EntryPoint = "getVideoFrameVLC")]
internal static extern IntPtr GetFrame(IntPtr mediaPlayer, out bool updated);
#endif
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_direct3d_set_callbacks")]
internal static extern bool LibVLCVideoDirect3DSetCallbacks(IntPtr mediaplayer, Direct3DEngine engine,
IntPtr setupCb, IntPtr cleanupCb, IntPtr resizeCb, IntPtr updateOutputCb,
IntPtr swapCb, IntPtr startEndRenderingCb, IntPtr selectPlaneCb, IntPtr opaque);
}
MediaPlayerEventManager _eventManager;
......@@ -1709,6 +1714,62 @@ namespace LibVLCSharp.Shared
public bool SetRenderer(RendererItem rendererItem) =>
Native.LibVLCMediaPlayerSetRenderer(NativeReference, rendererItem?.NativeReference ?? IntPtr.Zero) == 0;
/// <summary>
/// Set callbacks and data to render decoded video to a custom Direct3D output <para/>
/// warning: VLC will perform video rendering in its own thread and at its own rate,
/// You need to provide your own synchronisation mechanism.
/// <para/>LibVLC 4.0.0 or later
/// </summary>
/// <param name="engine">the GPU engine to use</param>
/// <param name="setupCb">callback to setup and return the device to use (cannot be NULL)</param>
/// <param name="cleanupCb">callback to cleanup the device given by the <see cref="LibVLCD3DSetupCb"/> callback</param>
/// <param name="updateOutputCb">callback to notify of the source format and get the rendering format used by the host (cannot be NULL)</param>
/// <param name="swapCb">callback to tell the host it should display the rendered picture (cannot be NULL)</param>
/// <param name="startEndRenderingCb">callback to tell the host the rendering is starting/ended (cannot be NULL)</param>
/// <param name="selectPlaneCb">callback to select different D3D11 rendering targets</param>
/// <param name="opaque">private pointer passed to the <see cref="LibVLCD3DCleanupCb"/> callback</param>
/// <returns>true Direct3D selected and callbacks set, false otherwise</returns>
public bool SetDirect3DCallbacks(Direct3DEngine engine, LibVLCD3DSetupCb setupCb, LibVLCD3DCleanupCb cleanupCb, LibVLCD3DResize resizeCb,
LibVLCD3DUpdateOutputCb updateOutputCb, LibVLCSwapCb swapCb, LibVLCD3DStartEndRenderingCb startEndRenderingCb,
LibVLCD3DSelectPlaneCb selectPlaneCb, IntPtr opaque)
{
setup = setupCb;
cleanup = cleanupCb;
resize = resizeCb;
updateOutput = updateOutputCb;
swap = swapCb;
startEndRendering = startEndRenderingCb;
selectPlane = selectPlaneCb;
var setupPtr = setup == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(setup);
var cleanupPtr = cleanup == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(cleanup);
var resizePtr = resize == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(resize);
var updateOutputPtr = updateOutput == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(updateOutput);
var swapPtr = swap == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(swap);
var startEndRenderingPtr = startEndRendering == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(startEndRendering);
var selectPlanePtr = selectPlane == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(selectPlane);
return Native.LibVLCVideoDirect3DSetCallbacks(NativeReference,
engine,
setupPtr,
cleanupPtr,
resizePtr,
updateOutputPtr,
swapPtr,
startEndRenderingPtr,
selectPlanePtr,
opaque);
}
LibVLCD3DSetupCb setup;
LibVLCD3DCleanupCb cleanup;
LibVLCD3DResize resize;
LibVLCD3DUpdateOutputCb updateOutput;
LibVLCSwapCb swap;
LibVLCD3DStartEndRenderingCb startEndRendering;
LibVLCD3DSelectPlaneCb selectPlane;
/// <summary>Gets the media role.
/// <para/> version LibVLC 3.0.0 and later.
/// </summary>
......@@ -1950,8 +2011,133 @@ namespace LibVLCSharp.Shared
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCVolumeCb(IntPtr data, float volume, [MarshalAs(UnmanagedType.I1)] bool mute);
#endregion
/// <summary>
/// Setup the rendering environment. <para/>
/// For <see cref="Direct3DEngine.D3D9"/>, the output must be a IDirect3D9*.
/// A reference to this object is held until <see cref="LibVLCD3DSetupCb"/> is called.
/// the device must be created with D3DPRESENT_PARAMETERS.hDeviceWindow set to 0.
/// <para/>
/// For <see cref="Direct3DEngine.D3D11"/>, the output must be a ID3D11DeviceContext*.
/// A reference to this object is held until <see cref="LibVLCD3DSetupCb"/> is called.
/// The ID3D11Device used to create ID3D11DeviceContext must have multithreading enabled.
/// <para/>
/// version LibVLC 4.0.0 or later
/// </summary>
/// <param name="opaque">private pointer passed to the <see cref="SetDirect3DCallbacks"/>
/// on input. The callback can change this value on output to be passed to all the other callbacks set on <see cref="SetDirect3DCallbacks"/>. [IN/OUT]
/// </param>
/// <param name="config">requested <see cref="D3DConfig"/> of the video device</param>
/// <param name="setup"><see cref="D3DSetup"/> to fill</param>
/// <returns>true on success</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public delegate bool LibVLCD3DSetupCb(IntPtr opaque, IntPtr config, IntPtr setup);
/// <summary>
/// Cleanup the rendering environment initialized during <see cref="LibVLCD3DSetupCb"/>.
/// <para/>
/// version LibVLC 4.0.0 or later
/// </summary>
/// <param name="opaque">private pointer set on the opaque parameter of <see cref="LibVLCD3DSetupCb"/> [IN]</param>
/// <returns></returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCD3DCleanupCb(IntPtr opaque);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ResizeReport(IntPtr report_opaque, uint width, uint height);
/// <summary>
/// Set the callback to call when the host app resizes the rendering area.
/// <para/>
/// This allows text rendering and aspect ratio to be handled properly when the host
/// rendering size changes.
/// <para/>
/// It may be called before the <see cref="LibVLCD3DSetupCb"/> callback.
/// <para/>
/// version LibVLC 4.0.0 or later
/// </summary>
/// <param name="opaque">private pointer set on the opaque parameter of <see cref="LibVLCD3DSetupCb"/></param>
/// <param name="report_size_change">callback which must be called when the host size changes.
/// <para/>The callback is valid until another call to <see cref="LibVLCD3DResize"/>
/// is done. This may be called from any thread.</param>
/// <param name="report_opaque">private pointer to pass to the <see cref="ResizeReport"/> callback</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCD3DResize(IntPtr opaque, ResizeReport report_size_change, IntPtr report_opaque);
/// <summary>
/// Update the rendering output setup. <para/>
/// Note: the configuration device for Direct3D9 is the IDirect3DDevice9 that VLC
/// uses to render. The host must set a Render target and call Present()
/// when it needs the drawing from VLC to be done.This object is not valid
/// anymore after Cleanup is called. <para/>
/// Tone mapping, range and color conversion will be done depending on the values set in the output structure.
/// </summary>
/// <param name="opaque">private pointer passed to the <see cref="SetDirect3DCallbacks"/>[IN]</param>
/// <param name="config">configuration of the video that will be rendered [IN]</param>
/// <param name="output">output configuration describing with how the rendering is setup [OUT]</param>
/// <returns>true on success</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public delegate bool LibVLCD3DUpdateOutputCb(IntPtr opaque, IntPtr config, IntPtr output);
/// <summary>
/// Callback prototype called after performing drawing calls.
/// <para/> LibVLC 4.0.0 or later
/// </summary>
/// <param name="opaque">private pointer passed to the @a libvlc_video_set_output_callbacks() [IN]</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void LibVLCSwapCb(IntPtr opaque);
/// <summary>
/// Tell the host the rendering is about to start/has finished. <para/>
/// LibVLC 4.0.0 or later
/// <para/>
/// On Direct3D11 the following may change on the provided ID3D11DeviceContext*
/// between \ref enter being true and \ref enter being false:<para/>
/// IASetPrimitiveTopology()<para/>
/// IASetInputLayout()<para/>
/// IASetVertexBuffers()<para/>
/// IASetIndexBuffer()<para/>
/// VSSetConstantBuffers()<para/>
/// VSSetShader()<para/>
/// PSSetSamplers()<para/>
/// PSSetConstantBuffers()<para/>
/// PSSetShaderResources()<para/>
/// PSSetShader()<para/>
/// RSSetViewports()<para/>
/// DrawIndexed()
/// </summary>
/// <param name="opaque">private pointer set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [IN]</param>
/// <param name="enter">true if the rendering is about to start, false if it's finished</param>
/// <param name="hdr">libvlc_video_direct3d_hdr10_metadata_t* or NULL [IN]</param>
/// <returns>true on success</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public delegate bool LibVLCD3DStartEndRenderingCb(IntPtr opaque, [MarshalAs(UnmanagedType.I1)] bool enter, IntPtr hdr);
/// <summary>
/// Tell the host the rendering for the given plane is about to start
/// note This is only used with <see cref="Direct3DEngine.D3D11"/>.
/// <para/>
/// The host should call OMSetRenderTargets for Direct3D11.If this callback is
/// not used (set to NULL in <see cref="SetDirect3DCallbacks"/>) OMSetRenderTargets
/// has to be set during the <see cref="LibVLCD3DStartEndRenderingCb"/> entering call.
/// <para/>
/// The number of planes depend on the DXGI_FORMAT returned during the
/// \ref LIBVLC_VIDEO_UPDATE_OUTPUT call.It's usually one plane except for
/// semi-planar formats like DXGI_FORMAT_NV12 or DXGI_FORMAT_P010.
/// <para/>LibVLC 4.0.0 or later
/// </summary>
/// <param name="opaque">private pointer set on the opaque parameter of <see cref="LibVLCD3DSetupCb"/> [IN]</param>
/// <param name="plane">number of the rendering plane to select</param>
/// <returns>true on success</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public delegate bool LibVLCD3DSelectPlaneCb(IntPtr opaque, ulong plane);
#endregion
/// <summary>
/// Get the Event Manager from which the media player send event.
/// </summary>
......@@ -2270,6 +2456,132 @@ namespace LibVLCSharp.Shared
}
}
[StructLayout(LayoutKind.Explicit, Size = 1)]
public readonly struct D3DDeviceConfig
{
/// <summary>
/// set if D3D11_CREATE_DEVICE_VIDEO_SUPPORT is needed for D3D11
/// </summary>
[FieldOffset(0)]
public readonly byte HardwareDecoding;
}
[StructLayout(LayoutKind.Sequential)]
public readonly struct D3DConfig
{
/// <summary>
/// rendering video width in pixel
/// </summary>
public readonly uint Width;
/// <summary>
/// rendering video height in pixel
/// </summary>
public readonly uint Height;
/// <summary>
/// rendering video bit depth in bits per channel
/// </summary>
public readonly uint BitDepth;
/// <summary>
/// video is full range or studio/limited range
/// </summary>
public readonly bool FullRange;
/// <summary>
/// video color space
/// </summary>
public readonly ColorSpace ColorSpace;
/// <summary>
/// video color primaries
/// </summary>
public readonly ColorPrimaries Primaries;
/// <summary>
/// video transfer function
/// </summary>
public readonly TransferFunction Transfer;
/// <summary>
/// device used for rendering, IDirect3DDevice9* for D3D9
/// </summary>
public readonly IntPtr Device;
}
[StructLayout(LayoutKind.Sequential)]
public struct D3DSetup
{
/// <summary>
/// ID3D11DeviceContext* for D3D11, IDirect3D9* for D3D9
/// </summary>
public IntPtr DeviceContext;
/// <summary>
/// Adapter to use with the IDirect3D9 for D3D9
/// </summary>
public int Adapter;
}
[StructLayout(LayoutKind.Explicit, Size = 20)]
public struct OutputConfig
{
/// <summary>
/// the rendering DXGI_FORMAT for \ref libvlc_video_direct3d_engine_d3d11,
// D3DFORMAT for \ref libvlc_video_direct3d_engine_d3d9
/// </summary>
[FieldOffset(0)]
public int SurfaceFormat;
/// <summary>
/// video is full range or studio/limited range
/// </summary>
[FieldOffset(4)]
public bool FullRange;
/// <summary>
/// video color space
/// </summary>
[FieldOffset(8)]
public ColorSpace ColorSpace;
/// <summary>
/// video color primaries
/// </summary>
[FieldOffset(12)]
public ColorPrimaries ColorPrimaries;
/// <summary>
/// video transfer function
/// </summary>
[FieldOffset(16)]
public TransferFunction TransferFunction;
}
/// <summary>
/// Metadata for HDR10 medias
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct D3DHDR10Metadata
{
[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;
}
/// <summary>Description for titles</summary>
public enum Title
{
......@@ -2603,5 +2915,61 @@ namespace LibVLCSharp.Shared
Accessibility = 8,
/// <summary>Testing</summary>
Test = 9
}
}
/// <summary>
/// Enumeration of the Video engine to be used on output.
/// can be passed to <see cref="SetDirect3DCallbacks"/>
/// </summary>
public enum Direct3DEngine
{
/// <summary>
/// Direct3D11 rendering engine
/// </summary>
D3D11,
/// <summary>
/// Direct3D9 rendering engine
/// </summary>
D3D9
}
/// <summary>
/// Enumeration of the Video color spaces.
/// </summary>
public enum ColorSpace
{
BT601 = 1,
BT709 = 2,
BT2020 = 3
}
/// <summary>
/// Enumeration of the Video color primaries.
/// </summary>
public enum ColorPrimaries
{
BT601_525 = 1,
BT601_625 = 2,
BT709 = 3,
BT2020 = 4,
DCI_P3 = 5,
BT470_M = 6
}
/// <summary>
/// Enumeration of the Video transfer functions.
/// </summary>
public enum TransferFunction
{
LINEAR = 1,
SRGB = 2,
BT470_BG = 3,
BT470_M = 4,
BT709 = 5,
PQ = 6,
SMPTE_240 = 7,
HLG = 8
}
}
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net471</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<VlcWindowsX64Enabled>true</VlcWindowsX64Enabled>
<VlcWindowsX86Enabled>false</VlcWindowsX86Enabled>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<None Remove="shader.fx" />
</ItemGroup>
<ItemGroup>
<Content Include="shader.fx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.D3DCompiler" Version="4.2.0" />
<PackageReference Include="SharpDX.Desktop" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="SharpDX.DXGI" Version="4.2.0" />
<PackageReference Include="SharpDX.Mathematics" Version="4.2.0" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\LibVLCSharp\LibVLCSharp.csproj" />
</ItemGroup>
</Project>
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using LibVLCSharp.Shared;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using static LibVLCSharp.Shared.MediaPlayer;
using Device = SharpDX.Direct3D11.Device;
using Buffer = SharpDX.Direct3D11.Buffer;
using SharpDX.Mathematics.Interop;
using System.Threading.Tasks;
namespace LibVLCSharp.D3DCallbacks.Texture
{
internal static class Program
{
static bool Setup(IntPtr opaque, IntPtr config, IntPtr setupPtr)
{
var setup = Marshal.PtrToStructure<D3DSetup>(setupPtr);
setup.DeviceContext = context.NativePointer;
Marshal.StructureToPtr(setup, setupPtr, false);
return true;
}
private static void Cleanup(IntPtr opaque)
{
}
private static void Resize(IntPtr opaque, ResizeReport report_size_change, IntPtr report_opaque)
{
reportSize = report_size_change;
reportOpaque = report_opaque;
//reportSize?.Invoke(reportOpaque, Convert.ToUInt32(form.ClientRectangle.Width), Convert.ToUInt32(form.ClientRectangle.Height));
reportSize?.Invoke(reportOpaque, Convert.ToUInt32(WIDTH), Convert.ToUInt32(HEIGHT));
}
private static bool UpdateOutput(IntPtr opaque, IntPtr configPtr, IntPtr outputPtr)
{
if (texture != null)
{
texture.Dispose();
texture = null;
}
if (textureShaderInput != null)
{
textureShaderInput.Dispose();
textureShaderInput = null;
}
if (textureRenderTarget != null)
{
textureRenderTarget.Dispose();
textureRenderTarget = null;
}
var config = Marshal.PtrToStructure<D3DConfig>(configPtr);
var textureDesc = new Texture2DDescription
{
MipLevels = 1,
SampleDescription = new SampleDescription { Count = 1 },
OptionFlags = ResourceOptionFlags.None,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
Usage = ResourceUsage.Default,
CpuAccessFlags = 0,
ArraySize = 1,
Format = Format.R8G8B8A8_UNorm,
Height = (int)config.Height,
Width = (int)config.Width
};
texture = new Texture2D(device, textureDesc);
if (texture == null)
throw new Exception("new texture failed");
var resviewDesc = new ShaderResourceViewDescription
{
Dimension = ShaderResourceViewDimension.Texture2D,
Texture2D = new ShaderResourceViewDescription.Texture2DResource { MipLevels = 1 },
Format = textureDesc.Format
};
textureShaderInput = new ShaderResourceView(device, texture, resviewDesc);
if (textureShaderInput == null)
throw new Exception("new textureShaderInput failed");
var renderTargetViewDesc = new RenderTargetViewDescription
{
Format = textureDesc.Format,
Dimension = RenderTargetViewDimension.Texture2D
};
textureRenderTarget = new RenderTargetView(device, texture, renderTargetViewDesc);