forked from mirrors/gstreamer-rs
Add Buffer::copy_into() and add flags parameter to ::copy_region()
Also ::copy_deep() can fail, return an Option<_>
This commit is contained in:
parent
18f99073c1
commit
3de73d89f2
4 changed files with 85 additions and 3 deletions
|
@ -48,6 +48,7 @@ generate = [
|
||||||
"Gst.PadProbeReturn",
|
"Gst.PadProbeReturn",
|
||||||
"Gst.CapsIntersectMode",
|
"Gst.CapsIntersectMode",
|
||||||
"Gst.BufferFlags",
|
"Gst.BufferFlags",
|
||||||
|
"Gst.BufferCopyFlags",
|
||||||
"Gst.SegmentFlags",
|
"Gst.SegmentFlags",
|
||||||
"Gst.PadMode",
|
"Gst.PadMode",
|
||||||
"Gst.SchedulingFlags",
|
"Gst.SchedulingFlags",
|
||||||
|
|
|
@ -8,6 +8,59 @@ use glib::value::{Value, SetValue, FromValue, FromValueOptional};
|
||||||
use gobject_ffi;
|
use gobject_ffi;
|
||||||
use glib::translate::*;
|
use glib::translate::*;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
pub struct BufferCopyFlags: u32 {
|
||||||
|
const NONE = 0;
|
||||||
|
const FLAGS = 1;
|
||||||
|
const TIMESTAMPS = 2;
|
||||||
|
const META = 4;
|
||||||
|
const MEMORY = 8;
|
||||||
|
const MERGE = 16;
|
||||||
|
const DEEP = 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
impl ToGlib for BufferCopyFlags {
|
||||||
|
type GlibType = ffi::GstBufferCopyFlags;
|
||||||
|
|
||||||
|
fn to_glib(&self) -> ffi::GstBufferCopyFlags {
|
||||||
|
ffi::GstBufferCopyFlags::from_bits_truncate(self.bits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
impl FromGlib<ffi::GstBufferCopyFlags> for BufferCopyFlags {
|
||||||
|
fn from_glib(value: ffi::GstBufferCopyFlags) -> BufferCopyFlags {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
BufferCopyFlags::from_bits_truncate(value.bits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StaticType for BufferCopyFlags {
|
||||||
|
fn static_type() -> Type {
|
||||||
|
unsafe { from_glib(ffi::gst_buffer_copy_flags_get_type()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> FromValueOptional<'a> for BufferCopyFlags {
|
||||||
|
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
|
||||||
|
Some(FromValue::from_value(value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> FromValue<'a> for BufferCopyFlags {
|
||||||
|
unsafe fn from_value(value: &Value) -> Self {
|
||||||
|
from_glib(ffi::GstBufferCopyFlags::from_bits_truncate(gobject_ffi::g_value_get_flags(value.to_glib_none().0)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SetValue for BufferCopyFlags {
|
||||||
|
unsafe fn set_value(value: &mut Value, this: &Self) {
|
||||||
|
gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
pub struct BufferFlags: u32 {
|
pub struct BufferFlags: u32 {
|
||||||
const LIVE = 16;
|
const LIVE = 16;
|
||||||
|
|
|
@ -143,6 +143,7 @@ pub use self::enums::URIError;
|
||||||
pub use self::enums::URIType;
|
pub use self::enums::URIType;
|
||||||
|
|
||||||
mod flags;
|
mod flags;
|
||||||
|
pub use self::flags::BufferCopyFlags;
|
||||||
pub use self::flags::BufferFlags;
|
pub use self::flags::BufferFlags;
|
||||||
pub use self::flags::DebugColorFlags;
|
pub use self::flags::DebugColorFlags;
|
||||||
pub use self::flags::DebugGraphDetails;
|
pub use self::flags::DebugGraphDetails;
|
||||||
|
|
|
@ -199,18 +199,45 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_region(&self, offset: usize, size: Option<usize>) -> Option<Buffer> {
|
pub fn copy_region(
|
||||||
|
&self,
|
||||||
|
flags: ::BufferCopyFlags,
|
||||||
|
offset: usize,
|
||||||
|
size: Option<usize>,
|
||||||
|
) -> Option<Buffer> {
|
||||||
let size_real = size.unwrap_or(usize::MAX);
|
let size_real = size.unwrap_or(usize::MAX);
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib_full(ffi::gst_buffer_copy_region(
|
from_glib_full(ffi::gst_buffer_copy_region(
|
||||||
self.as_mut_ptr(),
|
self.as_mut_ptr(),
|
||||||
ffi::GST_BUFFER_COPY_ALL,
|
flags.to_glib(),
|
||||||
offset,
|
offset,
|
||||||
size_real,
|
size_real,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn copy_into(
|
||||||
|
&self,
|
||||||
|
dest: &mut BufferRef,
|
||||||
|
flags: ::BufferCopyFlags,
|
||||||
|
offset: usize,
|
||||||
|
size: Option<usize>,
|
||||||
|
) -> Result<(), glib::BoolError> {
|
||||||
|
let size_real = size.unwrap_or(usize::MAX);
|
||||||
|
unsafe {
|
||||||
|
glib::BoolError::from_glib(
|
||||||
|
ffi::gst_buffer_copy_into(
|
||||||
|
dest.as_mut_ptr(),
|
||||||
|
self.as_mut_ptr(),
|
||||||
|
flags.to_glib(),
|
||||||
|
offset,
|
||||||
|
size_real,
|
||||||
|
),
|
||||||
|
"Failed to copy into destination buffer",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn copy_from_slice(&mut self, offset: usize, slice: &[u8]) -> Result<(), usize> {
|
pub fn copy_from_slice(&mut self, offset: usize, slice: &[u8]) -> Result<(), usize> {
|
||||||
let maxsize = self.get_maxsize();
|
let maxsize = self.get_maxsize();
|
||||||
let size = slice.len();
|
let size = slice.len();
|
||||||
|
@ -252,7 +279,7 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_deep(&self) -> Buffer {
|
pub fn copy_deep(&self) -> Option<Buffer> {
|
||||||
unsafe { from_glib_full(ffi::gst_buffer_copy_deep(self.as_ptr())) }
|
unsafe { from_glib_full(ffi::gst_buffer_copy_deep(self.as_ptr())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue