From c5090bdd21c271c0f336cfb335bc4fab6f9d1ab6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 28 Jan 2020 16:50:57 +0200 Subject: [PATCH] Declare GstVideoOverlayComposition/Rectangle as opaque type and subclasses of Gst.MiniObject This changes the API. Without this change all usage will cause memory corruption and simply does not work. --- sources/generated/Gst.Video/Global.cs | 6 +- .../generated/Gst.Video/VideoOverlayComposition.cs | 109 +++++++-------------- .../Gst.Video/VideoOverlayCompositionMeta.cs | 14 ++- .../generated/Gst.Video/VideoOverlayRectangle.cs | 7 +- sources/generated/gstreamer-sharp-api.xml | 4 +- sources/gstreamer-sharp.metadata | 6 ++ 6 files changed, 56 insertions(+), 90 deletions(-) diff --git a/sources/generated/Gst.Video/Global.cs b/sources/generated/Gst.Video/Global.cs index 1a392b0..240b9c5 100644 --- a/sources/generated/Gst.Video/Global.cs +++ b/sources/generated/Gst.Video/Global.cs @@ -52,15 +52,13 @@ namespace Gst.Video { static extern IntPtr gst_buffer_add_video_overlay_composition_meta(IntPtr buf, IntPtr comp); public static Gst.Video.VideoOverlayCompositionMeta BufferAddVideoOverlayCompositionMeta(Gst.Buffer buf, Gst.Video.VideoOverlayComposition comp) { - IntPtr native_comp = GLib.Marshaller.StructureToPtrAlloc (comp); - IntPtr raw_ret = gst_buffer_add_video_overlay_composition_meta(buf == null ? IntPtr.Zero : buf.Handle, native_comp); + IntPtr raw_ret = gst_buffer_add_video_overlay_composition_meta(buf == null ? IntPtr.Zero : buf.Handle, comp == null ? IntPtr.Zero : comp.Handle); Gst.Video.VideoOverlayCompositionMeta ret = Gst.Video.VideoOverlayCompositionMeta.New (raw_ret); - Marshal.FreeHGlobal (native_comp); return ret; } public static Gst.Video.VideoOverlayCompositionMeta BufferAddVideoOverlayCompositionMeta(Gst.Buffer buf) { - return BufferAddVideoOverlayCompositionMeta (buf, Gst.Video.VideoOverlayComposition.Zero); + return BufferAddVideoOverlayCompositionMeta (buf, null); } [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] diff --git a/sources/generated/Gst.Video/VideoOverlayComposition.cs b/sources/generated/Gst.Video/VideoOverlayComposition.cs index 4142d6b..d6f6b9d 100644 --- a/sources/generated/Gst.Video/VideoOverlayComposition.cs +++ b/sources/generated/Gst.Video/VideoOverlayComposition.cs @@ -9,26 +9,7 @@ namespace Gst.Video { using System.Runtime.InteropServices; #region Autogenerated code - [StructLayout(LayoutKind.Sequential)] - public partial struct VideoOverlayComposition : IEquatable { - - - public static Gst.Video.VideoOverlayComposition Zero = new Gst.Video.VideoOverlayComposition (); - - public static Gst.Video.VideoOverlayComposition New(IntPtr raw) { - if (raw == IntPtr.Zero) - return Gst.Video.VideoOverlayComposition.Zero; - return (Gst.Video.VideoOverlayComposition) Marshal.PtrToStructure (raw, typeof (Gst.Video.VideoOverlayComposition)); - } - - [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr gst_video_overlay_composition_new(IntPtr rectangle); - - public static VideoOverlayComposition New(Gst.Video.VideoOverlayRectangle rectangle) - { - VideoOverlayComposition result = VideoOverlayComposition.New (gst_video_overlay_composition_new(rectangle == null ? IntPtr.Zero : rectangle.Handle)); - return result; - } + public partial class VideoOverlayComposition : Gst.MiniObject { [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr gst_video_overlay_composition_get_type(); @@ -45,38 +26,35 @@ namespace Gst.Video { static extern void gst_video_overlay_composition_add_rectangle(IntPtr raw, IntPtr rectangle); public void AddRectangle(Gst.Video.VideoOverlayRectangle rectangle) { - IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this)); - System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false); - gst_video_overlay_composition_add_rectangle(this_as_native, rectangle == null ? IntPtr.Zero : rectangle.Handle); - ReadNative (this_as_native, ref this); - System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native); + gst_video_overlay_composition_add_rectangle(Handle, rectangle == null ? IntPtr.Zero : rectangle.Handle); } [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern bool gst_video_overlay_composition_blend(IntPtr raw, IntPtr video_buf); public bool Blend(Gst.Video.VideoFrame video_buf) { - IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this)); - System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false); IntPtr native_video_buf = GLib.Marshaller.StructureToPtrAlloc (video_buf); - bool raw_ret = gst_video_overlay_composition_blend(this_as_native, native_video_buf); + bool raw_ret = gst_video_overlay_composition_blend(Handle, native_video_buf); bool ret = raw_ret; - ReadNative (this_as_native, ref this); - System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native); Marshal.FreeHGlobal (native_video_buf); return ret; } [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr gst_video_overlay_composition_copy(IntPtr raw); + + public Gst.Video.VideoOverlayComposition Copy() { + IntPtr raw_ret = gst_video_overlay_composition_copy(Handle); + Gst.Video.VideoOverlayComposition ret = raw_ret == IntPtr.Zero ? null : (Gst.Video.VideoOverlayComposition) GLib.Opaque.GetOpaque (raw_ret, typeof (Gst.Video.VideoOverlayComposition), true); + return ret; + } + + [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr gst_video_overlay_composition_get_rectangle(IntPtr raw, uint n); public Gst.Video.VideoOverlayRectangle GetRectangle(uint n) { - IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this)); - System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false); - IntPtr raw_ret = gst_video_overlay_composition_get_rectangle(this_as_native, n); + IntPtr raw_ret = gst_video_overlay_composition_get_rectangle(Handle, n); Gst.Video.VideoOverlayRectangle ret = raw_ret == IntPtr.Zero ? null : (Gst.Video.VideoOverlayRectangle) GLib.Opaque.GetOpaque (raw_ret, typeof (Gst.Video.VideoOverlayRectangle), false); - ReadNative (this_as_native, ref this); - System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native); return ret; } @@ -85,12 +63,8 @@ namespace Gst.Video { public uint Seqnum { get { - IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this)); - System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false); - uint raw_ret = gst_video_overlay_composition_get_seqnum(this_as_native); + uint raw_ret = gst_video_overlay_composition_get_seqnum(Handle); uint ret = raw_ret; - ReadNative (this_as_native, ref this); - System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native); return ret; } } @@ -99,12 +73,8 @@ namespace Gst.Video { static extern IntPtr gst_video_overlay_composition_make_writable(IntPtr raw); public Gst.Video.VideoOverlayComposition MakeWritable() { - IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this)); - System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false); - IntPtr raw_ret = gst_video_overlay_composition_make_writable(this_as_native); - Gst.Video.VideoOverlayComposition ret = Gst.Video.VideoOverlayComposition.New (raw_ret); - ReadNative (this_as_native, ref this); - System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native); + IntPtr raw_ret = gst_video_overlay_composition_make_writable(Handle); + Gst.Video.VideoOverlayComposition ret = raw_ret == IntPtr.Zero ? null : (Gst.Video.VideoOverlayComposition) GLib.Opaque.GetOpaque (raw_ret, typeof (Gst.Video.VideoOverlayComposition), true); return ret; } @@ -112,47 +82,36 @@ namespace Gst.Video { static extern uint gst_video_overlay_composition_n_rectangles(IntPtr raw); public uint NRectangles() { - IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this)); - System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false); - uint raw_ret = gst_video_overlay_composition_n_rectangles(this_as_native); + uint raw_ret = gst_video_overlay_composition_n_rectangles(Handle); uint ret = raw_ret; - ReadNative (this_as_native, ref this); - System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native); return ret; } - static void ReadNative (IntPtr native, ref Gst.Video.VideoOverlayComposition target) - { - target = New (native); - } + public VideoOverlayComposition(IntPtr raw) : base(raw) {} - public bool Equals (VideoOverlayComposition other) - { - return true; - } + [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr gst_video_overlay_composition_new(IntPtr rectangle); - public override bool Equals (object other) + public VideoOverlayComposition (Gst.Video.VideoOverlayRectangle rectangle) { - return other is VideoOverlayComposition && Equals ((VideoOverlayComposition) other); + Raw = gst_video_overlay_composition_new(rectangle == null ? IntPtr.Zero : rectangle.Handle); } - public override int GetHashCode () - { - return this.GetType ().FullName.GetHashCode (); - } - public static explicit operator GLib.Value (Gst.Video.VideoOverlayComposition boxed) - { - GLib.Value val = GLib.Value.Empty; - val.Init (Gst.Video.VideoOverlayComposition.GType); - val.Val = boxed; - return val; - } + // Internal representation of the wrapped structure ABI. + static GLib.AbiStruct _abi_info = null; + static public new GLib.AbiStruct abi_info { + get { + if (_abi_info == null) + _abi_info = new GLib.AbiStruct (Gst.MiniObject.abi_info.Fields); - public static explicit operator Gst.Video.VideoOverlayComposition (GLib.Value val) - { - return (Gst.Video.VideoOverlayComposition) val.Val; + return _abi_info; + } } + + + // End of the ABI representation. + #endregion } } diff --git a/sources/generated/Gst.Video/VideoOverlayCompositionMeta.cs b/sources/generated/Gst.Video/VideoOverlayCompositionMeta.cs index a2faa85..87af214 100644 --- a/sources/generated/Gst.Video/VideoOverlayCompositionMeta.cs +++ b/sources/generated/Gst.Video/VideoOverlayCompositionMeta.cs @@ -14,9 +14,13 @@ namespace Gst.Video { public Gst.Meta Meta; private IntPtr _overlay; - - public Gst.Video.VideoOverlayComposition overlay { - get { return Gst.Video.VideoOverlayComposition.New (_overlay); } + public Gst.Video.VideoOverlayComposition Overlay { + get { + return _overlay == IntPtr.Zero ? null : (Gst.Video.VideoOverlayComposition) GLib.Opaque.GetOpaque (_overlay, typeof (Gst.Video.VideoOverlayComposition), false); + } + set { + _overlay = value == null ? IntPtr.Zero : value.Handle; + } } public static Gst.Video.VideoOverlayCompositionMeta Zero = new Gst.Video.VideoOverlayCompositionMeta (); @@ -40,7 +44,7 @@ namespace Gst.Video { public bool Equals (VideoOverlayCompositionMeta other) { - return true && Meta.Equals (other.Meta) && overlay.Equals (other.overlay); + return true && Meta.Equals (other.Meta) && Overlay.Equals (other.Overlay); } public override bool Equals (object other) @@ -50,7 +54,7 @@ namespace Gst.Video { public override int GetHashCode () { - return this.GetType ().FullName.GetHashCode () ^ Meta.GetHashCode () ^ overlay.GetHashCode (); + return this.GetType ().FullName.GetHashCode () ^ Meta.GetHashCode () ^ Overlay.GetHashCode (); } private static GLib.GType GType { diff --git a/sources/generated/Gst.Video/VideoOverlayRectangle.cs b/sources/generated/Gst.Video/VideoOverlayRectangle.cs index cc48d3f..9adefb7 100644 --- a/sources/generated/Gst.Video/VideoOverlayRectangle.cs +++ b/sources/generated/Gst.Video/VideoOverlayRectangle.cs @@ -9,7 +9,7 @@ namespace Gst.Video { using System.Runtime.InteropServices; #region Autogenerated code - public partial class VideoOverlayRectangle : GLib.Opaque { + public partial class VideoOverlayRectangle : Gst.MiniObject { [DllImport("gstvideo-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern IntPtr gst_video_overlay_rectangle_get_type(); @@ -153,11 +153,10 @@ namespace Gst.Video { // Internal representation of the wrapped structure ABI. static GLib.AbiStruct _abi_info = null; - static public GLib.AbiStruct abi_info { + static public new GLib.AbiStruct abi_info { get { if (_abi_info == null) - _abi_info = new GLib.AbiStruct (new List{ - }); + _abi_info = new GLib.AbiStruct (Gst.MiniObject.abi_info.Fields); return _abi_info; } diff --git a/sources/generated/gstreamer-sharp-api.xml b/sources/generated/gstreamer-sharp-api.xml index 6195792..a381805 100644 --- a/sources/generated/gstreamer-sharp-api.xml +++ b/sources/generated/gstreamer-sharp-api.xml @@ -28472,7 +28472,7 @@ - -