gstreamer/gstreamer-sharp/Buffer.custom
2009-09-20 10:22:16 +02:00

198 lines
4.9 KiB
Text

[DllImport ("libgstreamer-0.10.dll") ]
static extern IntPtr gst_buffer_try_new_and_alloc (uint size);
public Buffer (Gst.GLib.Value val) : base (val) { }
public Buffer (uint size) {
IntPtr raw = gst_buffer_try_new_and_alloc (size);
if (raw == IntPtr.Zero)
throw new OutOfMemoryException ();
Raw = raw;
}
public Buffer (byte[] data) : this () {
Data = data;
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gstsharp_gst_buffer_get_data_offset ();
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static void gstsharp_gst_buffer_set_data (IntPtr handle, IntPtr data, uint size);
[DllImport ("libglib-2.0-0.dll") ]
extern static IntPtr g_try_malloc (int size);
static uint data_offset = gstsharp_gst_buffer_get_data_offset ();
public byte[] 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);
}
}
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 ();
unsafe {
byte **raw_ptr = (byte **) ( ( (byte*) Handle) + data_offset);
* ( (*raw_ptr) + index) = value;
}
}
}
[DllImport ("libgstreamer-0.10.dll") ]
static extern void gst_mini_object_unref (IntPtr raw);
/* FIXME: This is not optimal */
public void MakeMetadataWritable() {
if (IsMetadataWritable)
return;
IntPtr old = Handle;
IntPtr sub = gst_buffer_create_sub (Handle, 0, Size);
Raw = sub;
gst_mini_object_unref (old);
}
[DllImport ("libgstreamer-0.10.dll") ]
static extern IntPtr gst_buffer_get_caps (IntPtr raw);
[DllImport ("libgstreamer-0.10.dll") ]
static extern void gst_buffer_set_caps (IntPtr raw, IntPtr caps);
public Gst.Caps Caps {
get {
IntPtr raw_ret = gst_buffer_get_caps (Handle);
Gst.Caps ret = raw_ret == IntPtr.Zero ? null : (Gst.Caps) Gst.GLib.Opaque.GetOpaque (raw_ret, typeof (Gst.Caps), true);
return ret;
} set {
if (!IsMetadataWritable)
throw new ApplicationException ();
gst_buffer_set_caps (Handle, value == null ? IntPtr.Zero : value.Handle);
}
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gstsharp_gst_buffer_get_timestamp_offset ();
static uint timestamp_offset = gstsharp_gst_buffer_get_timestamp_offset ();
public ulong Timestamp {
get {
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + timestamp_offset));
return *raw_ptr;
}
}
set {
if (!IsMetadataWritable)
throw new ApplicationException ();
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + timestamp_offset));
*raw_ptr = value;
}
}
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gstsharp_gst_buffer_get_duration_offset ();
static uint duration_offset = gstsharp_gst_buffer_get_duration_offset ();
public ulong Duration {
get {
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + duration_offset));
return *raw_ptr;
}
}
set {
if (!IsMetadataWritable)
throw new ApplicationException ();
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + duration_offset));
*raw_ptr = value;
}
}
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gstsharp_gst_buffer_get_offset_offset ();
static uint offset_offset = gstsharp_gst_buffer_get_offset_offset ();
public ulong Offset {
get {
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + offset_offset));
return *raw_ptr;
}
}
set {
if (!IsMetadataWritable)
throw new ApplicationException ();
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + offset_offset));
*raw_ptr = value;
}
}
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
extern static uint gstsharp_gst_buffer_get_offset_end_offset ();
static uint offset_end_offset = gstsharp_gst_buffer_get_offset_end_offset ();
public ulong OffsetEnd {
get {
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + offset_end_offset));
return *raw_ptr;
}
}
set {
if (!IsMetadataWritable)
throw new ApplicationException ();
unsafe {
ulong *raw_ptr = ( (ulong*) ( ( (byte*) Handle) + offset_end_offset));
*raw_ptr = value;
}
}
}
static Buffer () {
Gst.GLib.GType.Register (Buffer.GType, typeof (Buffer));
}