diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-09-22 07:40:57 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-09-22 07:40:57 +0200 |
commit | 7f309400501fbec2cc00f01211994af38821ca1f (patch) | |
tree | 6dbcd1a8df888950d67eeb3766e5f6995eff18ad | |
parent | 80a5794fc1eef8f54b21b9792cd1fb6f85fb7df0 (diff) |
Update Gst.Buffer bindings
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/en/Gst/Buffer.xml | 78 | ||||
-rw-r--r-- | gstreamer-sharp/Buffer.custom | 77 | ||||
-rw-r--r-- | gstreamer-sharp/Gstreamer.metadata | 1 | ||||
-rw-r--r-- | gstreamer-sharp/glue/buffer.c | 6 | ||||
-rw-r--r-- | samples/AppSrc.cs | 15 | ||||
-rw-r--r-- | tests/BufferTest.cs | 5 |
7 files changed, 136 insertions, 48 deletions
diff --git a/configure.ac b/configure.ac index 5d95e1c..b4773f8 100644 --- a/configure.ac +++ b/configure.ac @@ -14,7 +14,7 @@ AC_HEADER_STDC PACKAGE_VERSION=gstreamer-sharp-0.10 AC_SUBST(PACKAGE_VERSION) -API_VERSION=0.9.1.0 +API_VERSION=0.9.2.0 AC_SUBST(API_VERSION) MONO_REQUIRED_VERSION=2.4 diff --git a/doc/en/Gst/Buffer.xml b/doc/en/Gst/Buffer.xml index ac98a90..c01f9e6 100644 --- a/doc/en/Gst/Buffer.xml +++ b/doc/en/Gst/Buffer.xml @@ -111,6 +111,23 @@ <remarks>To be added.</remarks> </Docs> </Member> + <Member MemberName=".ctor"> + <MemberSignature Language="C#" Value="public Buffer (IntPtr data, uint size);" /> + <MemberType>Constructor</MemberType> + <AssemblyInfo> + <AssemblyVersion>0.9.1.0</AssemblyVersion> + </AssemblyInfo> + <Parameters> + <Parameter Name="data" Type="System.IntPtr" /> + <Parameter Name="size" Type="System.UInt32" /> + </Parameters> + <Docs> + <param name="data">To be added.</param> + <param name="size">To be added.</param> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member> <Member MemberName="Caps"> <MemberSignature Language="C#" Value="public Gst.Caps Caps { set; get; }" /> <MemberType>Property</MemberType> @@ -174,7 +191,7 @@ </Docs> </Member> <Member MemberName="Data"> - <MemberSignature Language="C#" Value="public byte[] Data { set; get; }" /> + <MemberSignature Language="C#" Value="public IntPtr Data { get; }" /> <MemberType>Property</MemberType> <AssemblyInfo> <AssemblyVersion>0.9.0.0</AssemblyVersion> @@ -182,7 +199,7 @@ <AssemblyVersion>0.9.5.99</AssemblyVersion> </AssemblyInfo> <ReturnValue> - <ReturnType>System.Byte[]</ReturnType> + <ReturnType>System.IntPtr</ReturnType> </ReturnValue> <Docs> <summary>To be added.</summary> @@ -267,7 +284,6 @@ <MemberType>Property</MemberType> <AssemblyInfo> <AssemblyVersion>0.9.0.0</AssemblyVersion> - <AssemblyVersion>0.9.1.0</AssemblyVersion> <AssemblyVersion>0.9.5.99</AssemblyVersion> </AssemblyInfo> <ReturnValue> @@ -355,8 +371,46 @@ <remarks>To be added.</remarks> </Docs> </Member> + <Member MemberName="SetData"> + <MemberSignature Language="C#" Value="public void SetData (byte[] data);" /> + <MemberType>Method</MemberType> + <AssemblyInfo> + <AssemblyVersion>0.9.1.0</AssemblyVersion> + </AssemblyInfo> + <ReturnValue> + <ReturnType>System.Void</ReturnType> + </ReturnValue> + <Parameters> + <Parameter Name="data" Type="System.Byte[]" /> + </Parameters> + <Docs> + <param name="data">To be added.</param> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member> + <Member MemberName="SetData"> + <MemberSignature Language="C#" Value="public void SetData (IntPtr data, uint size);" /> + <MemberType>Method</MemberType> + <AssemblyInfo> + <AssemblyVersion>0.9.1.0</AssemblyVersion> + </AssemblyInfo> + <ReturnValue> + <ReturnType>System.Void</ReturnType> + </ReturnValue> + <Parameters> + <Parameter Name="data" Type="System.IntPtr" /> + <Parameter Name="size" Type="System.UInt32" /> + </Parameters> + <Docs> + <param name="data">To be added.</param> + <param name="size">To be added.</param> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member> <Member MemberName="Size"> - <MemberSignature Language="C#" Value="public uint Size { get; }" /> + <MemberSignature Language="C#" Value="public uint Size { set; get; }" /> <MemberType>Property</MemberType> <AssemblyInfo> <AssemblyVersion>0.9.0.0</AssemblyVersion> @@ -414,5 +468,21 @@ <remarks>To be added.</remarks> </Docs> </Member> + <Member MemberName="ToByteArray"> + <MemberSignature Language="C#" Value="public byte[] ToByteArray ();" /> + <MemberType>Method</MemberType> + <AssemblyInfo> + <AssemblyVersion>0.9.1.0</AssemblyVersion> + </AssemblyInfo> + <ReturnValue> + <ReturnType>System.Byte[]</ReturnType> + </ReturnValue> + <Parameters /> + <Docs> + <summary>To be added.</summary> + <returns>To be added.</returns> + <remarks>To be added.</remarks> + </Docs> + </Member> </Members> </Type> diff --git a/gstreamer-sharp/Buffer.custom b/gstreamer-sharp/Buffer.custom index 8bb3ae2..3b72ccd 100644 --- a/gstreamer-sharp/Buffer.custom +++ b/gstreamer-sharp/Buffer.custom @@ -10,8 +10,12 @@ public Buffer (uint size) { Raw = raw; } +public Buffer (IntPtr data, uint size) : this () { + SetData (data, size); +} + public Buffer (byte[] data) : this () { - Data = data; + SetData (data); } [DllImport ("gstreamersharpglue-0.10.dll") ] @@ -22,52 +26,41 @@ extern static void gstsharp_gst_buffer_set_data (IntPtr handle, IntPtr data, uin extern static IntPtr g_try_malloc (int size); static uint data_offset = gstsharp_gst_buffer_get_data_offset (); -public byte[] Data { +public IntPtr Data { get { IntPtr raw_ptr; unsafe { raw_ptr = * ( (IntPtr *) ( ( (byte*) Handle) + data_offset)); } - byte[] data = new byte[Size]; - Marshal.Copy (raw_ptr, data, 0, (int) Size); - - return data; + return raw_ptr; } +} - set { +public void SetData (IntPtr data, uint size) { + if (!IsWritable) + throw new ApplicationException (); + + gstsharp_gst_buffer_set_data (Handle, data, size); +} + +public void SetData (byte[] data) { if (!IsWritable) throw new ApplicationException (); - IntPtr raw_ptr = g_try_malloc (value.Length); + IntPtr raw_ptr = g_try_malloc (data.Length); if (raw_ptr == IntPtr.Zero) throw new OutOfMemoryException (); - Marshal.Copy (value, 0, raw_ptr, value.Length); - gstsharp_gst_buffer_set_data (Handle, raw_ptr, (uint) value.Length); - } + Marshal.Copy (data, 0, raw_ptr, data.Length); + gstsharp_gst_buffer_set_data (Handle, raw_ptr, (uint) data.Length); } -public byte this [uint index] { - get { - if (index >= Size) - throw new ArgumentOutOfRangeException (); - - unsafe { - byte **raw_ptr = (byte **) ( ( (byte*) Handle) + data_offset); - return * ( (*raw_ptr) + index); - } - } set { - if (index >= Size) - throw new ArgumentOutOfRangeException (); - if (!IsWritable) - throw new ApplicationException (); +public byte[] ToByteArray () { + byte[] data = new byte[Size]; + Marshal.Copy (Data, data, 0, (int) Size); - unsafe { - byte **raw_ptr = (byte **) ( ( (byte*) Handle) + data_offset); - * ( (*raw_ptr) + index) = value; - } - } + return data; } [DllImport ("libgstreamer-0.10.dll") ] @@ -102,6 +95,30 @@ public Gst.Caps Caps { } [DllImport ("gstreamersharpglue-0.10.dll") ] +extern static uint gstsharp_gst_buffer_get_size_offset (); +static uint size_offset = gstsharp_gst_buffer_get_size_offset (); + +public uint Size { + get { + unsafe { + uint *raw_ptr = ( (uint*) ( ( (byte*) Handle) + size_offset)); + return *raw_ptr; + } + } + + set { + if (!IsMetadataWritable) + throw new ApplicationException (); + + unsafe { + uint *raw_ptr = ( (uint*) ( ( (byte*) Handle) + size_offset)); + *raw_ptr = value; + } + } +} + + +[DllImport ("gstreamersharpglue-0.10.dll") ] extern static uint gstsharp_gst_buffer_get_timestamp_offset (); static uint timestamp_offset = gstsharp_gst_buffer_get_timestamp_offset (); diff --git a/gstreamer-sharp/Gstreamer.metadata b/gstreamer-sharp/Gstreamer.metadata index 32fa22e..f3963e0 100644 --- a/gstreamer-sharp/Gstreamer.metadata +++ b/gstreamer-sharp/Gstreamer.metadata @@ -56,6 +56,7 @@ <attr path="/api/namespace/mini-object[@name='Buffer']/field[@name='Timestamp']" name="hidden">1</attr> <attr path="/api/namespace/mini-object[@name='Buffer']/field[@name='Caps']" name="hidden">1</attr> <attr path="/api/namespace/mini-object[@name='Buffer']/field[@name='FreeFunc']" name="hidden">1</attr> + <attr path="/api/namespace/mini-object[@name='Buffer']/field[@name='Size']" name="hidden">1</attr> <attr path="/api/namespace/mini-object[@name='Buffer']/method[@cname='gst_buffer_get_caps']" name="hidden">1</attr> <attr path="/api/namespace/mini-object[@name='Buffer']/method[@cname='gst_buffer_set_caps']" name="hidden">1</attr> <attr path="/api/namespace/mini-object[@name='Buffer']/method[@cname='gst_buffer_stamp']" name="hidden">1</attr> diff --git a/gstreamer-sharp/glue/buffer.c b/gstreamer-sharp/glue/buffer.c index 081eeef..144f328 100644 --- a/gstreamer-sharp/glue/buffer.c +++ b/gstreamer-sharp/glue/buffer.c @@ -16,6 +16,12 @@ gstsharp_gst_buffer_set_data (GstBuffer * buffer, guint8 * new_data, guint size) } guint +gstsharp_gst_buffer_get_size_offset (void) +{ + return (guint)G_STRUCT_OFFSET (GstBuffer, size); +} + +guint gstsharp_gst_buffer_get_data_offset (void) { return (guint) G_STRUCT_OFFSET (GstBuffer, data); diff --git a/samples/AppSrc.cs b/samples/AppSrc.cs index 7a9a3df..da7f676 100644 --- a/samples/AppSrc.cs +++ b/samples/AppSrc.cs @@ -52,15 +52,14 @@ public class AppSrcDemo { ulong mseconds = 0; if (appsrc.Clock != null) mseconds = appsrc.Clock.Time / Clock.MSecond; - byte[] data = DrawData (mseconds); - - Gst.Buffer buffer = new Gst.Buffer (data); + Gst.Buffer buffer = DrawData (mseconds); appsrc.PushBuffer (buffer); } - // Returns a byte[] presentation of one 640x480 BGRA frame using Cairo - static byte[] DrawData (ulong seconds) { - Cairo.ImageSurface img = new Cairo.ImageSurface (Cairo.Format.Argb32, 640, 480); + // Returns a Gst.Buffer presentation of one 640x480 BGRA frame using Cairo + static Gst.Buffer DrawData (ulong seconds) { + Gst.Buffer buffer = new Gst.Buffer (640*480*4); + Cairo.ImageSurface img = new Cairo.ImageSurface (buffer.Data, Cairo.Format.Argb32, 640, 480, 640*4); using (Cairo.Context context = new Cairo.Context (img)) { double dx = (double) (seconds % 2180) / 5; context.Color = new Color (1.0, 1.0, 0); @@ -71,10 +70,8 @@ public class AppSrcDemo { context.Color = new Color (0, 0, 1.0); context.Stroke(); } - - byte[] data = img.Data; img.Destroy(); - return data; + return buffer; } static void MessageHandler (object sender, MessageArgs args) { diff --git a/tests/BufferTest.cs b/tests/BufferTest.cs index b0f2d70..9123d41 100644 --- a/tests/BufferTest.cs +++ b/tests/BufferTest.cs @@ -69,9 +69,6 @@ public class BufferTest { Gst.Buffer buffer = new Gst.Buffer (data); - ArrayIsEqual (data, buffer.Data); - for (uint i = 0; i < buffer.Size; i++) - Assert.IsTrue (buffer[i] == data[i]); - + ArrayIsEqual (data, buffer.ToByteArray ()); } } |