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 /gstreamer-sharp/Buffer.custom | |
parent | 80a5794fc1eef8f54b21b9792cd1fb6f85fb7df0 (diff) |
Update Gst.Buffer bindings
Diffstat (limited to 'gstreamer-sharp/Buffer.custom')
-rw-r--r-- | gstreamer-sharp/Buffer.custom | 77 |
1 files changed, 47 insertions, 30 deletions
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 (); |