mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-30 12:10:37 +00:00
215 lines
5.2 KiB
Text
215 lines
5.2 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 (IntPtr data, uint size) : this () {
|
|
SetData (data, size);
|
|
}
|
|
|
|
public Buffer (byte[] data) : this () {
|
|
SetData (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 IntPtr Data {
|
|
get {
|
|
IntPtr raw_ptr;
|
|
unsafe {
|
|
raw_ptr = * ( (IntPtr *) ( ( (byte*) Handle) + data_offset));
|
|
}
|
|
|
|
return raw_ptr;
|
|
}
|
|
}
|
|
|
|
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 (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") ]
|
|
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_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 ();
|
|
|
|
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));
|
|
}
|