From 7f309400501fbec2cc00f01211994af38821ca1f Mon Sep 17 00:00:00 2001 From: Sebastian Dröge Date: Tue, 22 Sep 2009 07:40:57 +0200 Subject: Update Gst.Buffer bindings --- gstreamer-sharp/Buffer.custom | 77 ++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 30 deletions(-) (limited to 'gstreamer-sharp/Buffer.custom') 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") ] @@ -101,6 +94,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 (); -- cgit v1.2.3