gstreamer/gstreamer-sharp/Buffer.custom
2009-04-16 21:52:21 +02:00

202 lines
4.9 KiB
Text

[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_buffer_try_new_and_alloc (uint size);
public Buffer (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") ]
extern static uint gstsharp_gst_buffer_get_data_offset ();
[DllImport ("gstreamersharpglue-0.10") ]
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 ("gstreamer-0.10.dll") ]
static extern IntPtr gst_buffer_make_metadata_writable (IntPtr raw);
/* FIXME: This is not optimal */
public void MakeMetadataWritable() {
if (IsMetadataWritable)
return;
IntPtr sub = gst_buffer_create_sub (Raw, 0, Size);
Raw = sub;
/* ^--- Takes a second ref, not good */
Unref (Raw);
/* ^--- Sets Owned = false, wrong! */
Owned = true;
}
[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_buffer_get_caps (IntPtr raw);
[DllImport ("gstreamer-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) 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") ]
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") ]
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") ]
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") ]
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 () {
GLib.GType.Register (Buffer.GType, typeof (Buffer));
}