I'm developing a C# WPF application using gstreamer-sharp-netcore(Mingw v1.19.1) on Windows. What we would like to achieve is to be able to render video with hardware acceleration. To avoid the airspace issue in WPF, we are using gstreamer-d3d11-overlay(https://github.com/berglie/gstreamer-d3d11-overlay/).
From the sample, there are 2 ways to initiate rendering the video(MainWindow.cs):
var windowHandle = new WindowInteropHelper(System.Windows.Application.Current.MainWindow).Handle;
_playback = new Playback(windowHandle, _enableOverlay);
_d3DImageEx = new D3DImageEx();
_D3D11Scene = new D3D11TestScene(1920, 1080);
d3dScene.Source = _d3DImageEx;
/* Set the backbuffer, which is a ID3D11Texture2D pointer */
IntPtr renderTarget = _D3D11Scene.GetRenderTarget();
IntPtr backBuffer = _d3DImageEx.CreateBackBuffer(D3DResourceTypeEx.ID3D11Texture2D, renderTarget);
_d3DImageEx.Lock();
_d3DImageEx.SetBackBuffer(D3DResourceType.IDirect3DSurface9, backBuffer, _enableSoftwareFallback);
_d3DImageEx.Unlock();
_playback = new Playback(IntPtr.Zero, _enableOverlay);
_playback.OnDrawSignalReceived += VideoSink_OnBeginDraw;
CompositionTarget.Rendering += CompositionTarget_Rendering;
When this is successfully initialized, Gstreamer will render the video and fire the OnDrawSignalReceived:
private void VideoSink_OnBeginDraw(Element sink, GLib.SignalArgs args)
{
var sharedHandle = _D3D11Scene.GetSharedHandle();
_ = sink.Emit("draw", sharedHandle, (UInt32)2, (UInt64)0, (UInt64)0);
}
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at Gst.DynamicSignal.OnMarshal(IntPtr closure, Value& retval, UInt32 argc, IntPtr argsPtr, IntPtr ihint, IntPtr data)
This exception was originally thrown at this call stack:
Gst.DynamicSignal.Emit(GLib.Object, string, object[])
Gst.Object.Emit(string, object[])
TestHacoustoGst2D3D11WpfApp.MainWindow.VideoSink_OnBeginDraw(Gst.Element, GLib.SignalArgs) in MainWindow.xaml.cs
TestHacoustoGst2D3D11WpfApp.Playback.VideoSink_OnBeginDraw(object, GLib.SignalArgs) in Playback.cs
Inner Exception 1:
ApplicationException: Invalid parameter type: expected , got System.IntPtr