gstreamer/gstreamer-sharp/Buffer.custom

216 lines
5.2 KiB
Text
Raw Normal View History

2009-09-20 08:19:49 +00:00
[DllImport ("libgstreamer-0.10.dll") ]
2009-04-13 11:27:26 +00:00
static extern IntPtr gst_buffer_try_new_and_alloc (uint size);
public Buffer (Gst.GLib.Value val) : base (val) { }
2009-04-13 11:27:26 +00:00
public Buffer (uint size) {
IntPtr raw = gst_buffer_try_new_and_alloc (size);
if (raw == IntPtr.Zero)
throw new OutOfMemoryException ();
Raw = raw;
}
2009-09-22 05:40:57 +00:00
public Buffer (IntPtr data, uint size) : this () {
SetData (data, size);
}
2009-04-13 11:27:26 +00:00
public Buffer (byte[] data) : this () {
2009-09-22 05:40:57 +00:00
SetData (data);
2009-04-13 11:27:26 +00:00
}
[DllImport ("gstreamersharpglue-0.10.dll") ]
2009-04-13 11:27:26 +00:00
extern static uint gstsharp_gst_buffer_get_data_offset ();
[DllImport ("gstreamersharpglue-0.10.dll") ]
2009-04-13 11:27:26 +00:00
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 ();
2009-09-22 05:40:57 +00:00
public IntPtr Data {
2009-04-13 11:27:26 +00:00
get {
IntPtr raw_ptr;
unsafe {
raw_ptr = * ( (IntPtr *) ( ( (byte*) Handle) + data_offset));
}
2009-09-22 05:40:57 +00:00
return raw_ptr;
2009-04-13 11:27:26 +00:00
}
2009-09-22 05:40:57 +00:00
}
2009-04-13 11:27:26 +00:00
2009-09-22 05:40:57 +00:00
public void SetData (IntPtr data, uint size) {
2009-04-13 11:27:26 +00:00
if (!IsWritable)
throw new ApplicationException ();
2009-09-22 05:40:57 +00:00
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);
2009-04-13 11:27:26 +00:00
if (raw_ptr == IntPtr.Zero)
throw new OutOfMemoryException ();
2009-09-22 05:40:57 +00:00
Marshal.Copy (data, 0, raw_ptr, data.Length);
gstsharp_gst_buffer_set_data (Handle, raw_ptr, (uint) data.Length);
2009-04-13 11:27:26 +00:00
}
2009-09-22 05:40:57 +00:00
public byte[] ToByteArray () {
byte[] data = new byte[Size];
Marshal.Copy (Data, data, 0, (int) Size);
2009-04-13 11:27:26 +00:00
2009-09-22 05:40:57 +00:00
return data;
2009-04-13 11:27:26 +00:00
}
[DllImport ("libgstreamer-0.10.dll") ]
static extern void gst_mini_object_unref (IntPtr raw);
2009-04-13 11:27:26 +00:00
/* FIXME: This is not optimal */
public void MakeMetadataWritable() {
if (IsMetadataWritable)
return;
IntPtr old = Handle;
IntPtr sub = gst_buffer_create_sub (Handle, 0, Size);
2009-04-13 11:27:26 +00:00
Raw = sub;
gst_mini_object_unref (old);
2009-04-13 11:27:26 +00:00
}
2009-09-20 08:19:49 +00:00
[DllImport ("libgstreamer-0.10.dll") ]
2009-04-13 11:27:26 +00:00
static extern IntPtr gst_buffer_get_caps (IntPtr raw);
2009-09-20 08:19:49 +00:00
[DllImport ("libgstreamer-0.10.dll") ]
2009-04-13 11:27:26 +00:00
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);
2009-04-13 11:27:26 +00:00
return ret;
2009-09-20 08:19:49 +00:00
} set {
2009-04-13 11:27:26 +00:00
if (!IsMetadataWritable)
throw new ApplicationException ();
gst_buffer_set_caps (Handle, value == null ? IntPtr.Zero : value.Handle);
}
}
2009-09-22 05:40:57 +00:00
[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") ]
2009-04-13 11:27:26 +00:00
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") ]
2009-04-13 11:27:26 +00:00
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") ]
2009-04-13 11:27:26 +00:00
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") ]
2009-04-13 11:27:26 +00:00
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));
}