diff --git a/configure.ac b/configure.ac
index 5d95e1c89a..b4773f85ea 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 ac98a90db5..c01f9e67ca 100644
--- a/doc/en/Gst/Buffer.xml
+++ b/doc/en/Gst/Buffer.xml
@@ -111,6 +111,23 @@
To be added.
+
+
+ Constructor
+
+ 0.9.1.0
+
+
+
+
+
+
+ To be added.
+ To be added.
+ To be added.
+ To be added.
+
+
Property
@@ -174,7 +191,7 @@
-
+
Property
0.9.0.0
@@ -182,7 +199,7 @@
0.9.5.99
- System.Byte[]
+ System.IntPtr
To be added.
@@ -267,7 +284,6 @@
Property
0.9.0.0
- 0.9.1.0
0.9.5.99
@@ -355,8 +371,46 @@
To be added.
+
+
+ Method
+
+ 0.9.1.0
+
+
+ System.Void
+
+
+
+
+
+ To be added.
+ To be added.
+ To be added.
+
+
+
+
+ Method
+
+ 0.9.1.0
+
+
+ System.Void
+
+
+
+
+
+
+ To be added.
+ To be added.
+ To be added.
+ To be added.
+
+
-
+
Property
0.9.0.0
@@ -414,5 +468,21 @@
To be added.
+
+
+ Method
+
+ 0.9.1.0
+
+
+ System.Byte[]
+
+
+
+ To be added.
+ To be added.
+ To be added.
+
+
diff --git a/gstreamer-sharp/Buffer.custom b/gstreamer-sharp/Buffer.custom
index 8bb3ae231b..3b72ccde84 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;
- }
-
- set {
- if (!IsWritable)
- throw new ApplicationException ();
-
- IntPtr raw_ptr = g_try_malloc (value.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);
+ return raw_ptr;
}
}
-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 ();
+public void SetData (IntPtr data, uint size) {
if (!IsWritable)
throw new ApplicationException ();
- unsafe {
- byte **raw_ptr = (byte **) ( ( (byte*) Handle) + data_offset);
- * ( (*raw_ptr) + index) = value;
- }
- }
+ gstsharp_gst_buffer_set_data (Handle, data, size);
+}
+
+public void SetData (byte[] data) {
+ if (!IsWritable)
+ throw new ApplicationException ();
+
+ IntPtr raw_ptr = g_try_malloc (data.Length);
+ if (raw_ptr == IntPtr.Zero)
+ throw new OutOfMemoryException ();
+
+ Marshal.Copy (data, 0, raw_ptr, data.Length);
+ gstsharp_gst_buffer_set_data (Handle, raw_ptr, (uint) data.Length);
+}
+
+public byte[] ToByteArray () {
+ byte[] data = new byte[Size];
+ Marshal.Copy (Data, data, 0, (int) Size);
+
+ 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 ();
diff --git a/gstreamer-sharp/Gstreamer.metadata b/gstreamer-sharp/Gstreamer.metadata
index 32fa22e1c7..f3963e0834 100644
--- a/gstreamer-sharp/Gstreamer.metadata
+++ b/gstreamer-sharp/Gstreamer.metadata
@@ -56,6 +56,7 @@
1
1
1
+ 1
1
1
1
diff --git a/gstreamer-sharp/glue/buffer.c b/gstreamer-sharp/glue/buffer.c
index 081eeef107..144f328d41 100644
--- a/gstreamer-sharp/glue/buffer.c
+++ b/gstreamer-sharp/glue/buffer.c
@@ -15,6 +15,12 @@ gstsharp_gst_buffer_set_data (GstBuffer * buffer, guint8 * new_data, guint size)
buffer->free_func = g_free;
}
+guint
+gstsharp_gst_buffer_get_size_offset (void)
+{
+ return (guint)G_STRUCT_OFFSET (GstBuffer, size);
+}
+
guint
gstsharp_gst_buffer_get_data_offset (void)
{
diff --git a/samples/AppSrc.cs b/samples/AppSrc.cs
index 7a9a3dffb4..da7f676b68 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 b0f2d7005d..9123d419ca 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 ());
}
}