2014-07-20 01:32:48 +00:00
|
|
|
// Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com>
|
2023-03-01 09:55:38 +00:00
|
|
|
//
|
2014-07-20 01:32:48 +00:00
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
// 02110-1301 USA
|
|
|
|
|
|
|
|
namespace Gst {
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
partial class Buffer {
|
2019-10-24 14:00:17 +00:00
|
|
|
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2014-07-20 01:32:48 +00:00
|
|
|
static extern UIntPtr gst_buffer_extract(IntPtr raw, UIntPtr offset, byte[] dest, UIntPtr size);
|
|
|
|
|
|
|
|
public ulong Extract(ulong offset, ref byte[] dest) {
|
2021-09-30 11:02:26 +00:00
|
|
|
UIntPtr raw_ret = gst_buffer_extract(Handle, new UIntPtr(offset), dest, new UIntPtr((ulong)dest.Length));
|
|
|
|
ulong ret = (ulong)raw_ret;
|
2014-07-20 01:32:48 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-10-24 14:00:17 +00:00
|
|
|
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2014-07-20 01:32:48 +00:00
|
|
|
static extern void gst_buffer_extract_dup(IntPtr raw, UIntPtr offset, UIntPtr size, out IntPtr dest, out UIntPtr dest_size);
|
|
|
|
|
|
|
|
public ulong ExtractDup(ulong offset, ulong size, out byte[] dest) {
|
|
|
|
UIntPtr native_dest_size;
|
|
|
|
IntPtr ptr;
|
2021-09-30 11:02:26 +00:00
|
|
|
gst_buffer_extract_dup(Handle, new UIntPtr(offset), new UIntPtr(size), out ptr, out native_dest_size);
|
2014-07-20 01:32:48 +00:00
|
|
|
|
|
|
|
byte[] bytes = new byte[(ulong)native_dest_size];
|
2021-09-30 11:02:26 +00:00
|
|
|
Marshal.Copy(ptr, bytes, 0, (int)native_dest_size);
|
2014-07-20 01:32:48 +00:00
|
|
|
|
|
|
|
dest = bytes;
|
2021-09-30 11:02:26 +00:00
|
|
|
GLib.Marshaller.Free(ptr);
|
2014-07-20 01:32:48 +00:00
|
|
|
|
2021-09-30 11:02:26 +00:00
|
|
|
return (ulong)native_dest_size;
|
2014-07-20 01:32:48 +00:00
|
|
|
}
|
2020-01-29 10:58:59 +00:00
|
|
|
|
|
|
|
[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
static extern IntPtr gst_buffer_new_wrapped(IntPtr data, UIntPtr n_length);
|
|
|
|
|
2023-03-01 09:55:38 +00:00
|
|
|
public Buffer(byte[] data) : base(IntPtr.Zero) {
|
2021-09-30 11:02:26 +00:00
|
|
|
IntPtr ptr = GLib.Marshaller.Malloc((ulong)data.Length);
|
2020-01-29 10:58:59 +00:00
|
|
|
Marshal.Copy(data, 0, ptr, data.Length);
|
2021-09-30 11:02:26 +00:00
|
|
|
Raw = gst_buffer_new_wrapped(ptr, new UIntPtr((ulong)data.Length));
|
2020-01-29 10:58:59 +00:00
|
|
|
}
|
2014-07-20 01:32:48 +00:00
|
|
|
}
|
2021-09-30 11:02:26 +00:00
|
|
|
}
|