gstreamer/auto/
allocator.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, AllocationParams, Memory, Object};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    #[doc(alias = "GstAllocator")]
11    pub struct Allocator(Object<ffi::GstAllocator, ffi::GstAllocatorClass>) @extends Object;
12
13    match fn {
14        type_ => || ffi::gst_allocator_get_type(),
15    }
16}
17
18impl Allocator {
19    pub const NONE: Option<&'static Allocator> = None;
20
21    #[doc(alias = "gst_allocator_find")]
22    pub fn find(name: Option<&str>) -> Option<Allocator> {
23        assert_initialized_main_thread!();
24        unsafe { from_glib_full(ffi::gst_allocator_find(name.to_glib_none().0)) }
25    }
26}
27
28unsafe impl Send for Allocator {}
29unsafe impl Sync for Allocator {}
30
31pub trait AllocatorExt: IsA<Allocator> + 'static {
32    #[doc(alias = "gst_allocator_alloc")]
33    fn alloc(
34        &self,
35        size: usize,
36        params: Option<&AllocationParams>,
37    ) -> Result<Memory, glib::BoolError> {
38        unsafe {
39            Option::<_>::from_glib_full(ffi::gst_allocator_alloc(
40                self.as_ref().to_glib_none().0,
41                size,
42                mut_override(params.to_glib_none().0),
43            ))
44            .ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
45        }
46    }
47
48    #[doc(alias = "gst_allocator_set_default")]
49    fn set_default(self) {
50        unsafe {
51            ffi::gst_allocator_set_default(self.upcast().into_glib_ptr());
52        }
53    }
54}
55
56impl<O: IsA<Allocator>> AllocatorExt for O {}