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 /// Memory is usually created by allocators with a [`AllocatorExt::alloc()`][crate::prelude::AllocatorExt::alloc()]
11 /// method call. When [`None`] is used as the allocator, the default allocator will
12 /// be used.
13 ///
14 /// New allocators can be registered with [`register()`][Self::register()].
15 /// Allocators are identified by name and can be retrieved with
16 /// [`find()`][Self::find()]. [`AllocatorExt::set_default()`][crate::prelude::AllocatorExt::set_default()] can be used to change the
17 /// default allocator.
18 ///
19 /// New memory can be created with [`Memory::new_wrapped()`][crate::Memory::new_wrapped()] that wraps the memory
20 /// allocated elsewhere.
21 ///
22 /// This is an Abstract Base Class, you cannot instantiate it.
23 ///
24 /// # Implements
25 ///
26 /// [`AllocatorExt`][trait@crate::prelude::AllocatorExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`]
27 #[doc(alias = "GstAllocator")]
28 pub struct Allocator(Object<ffi::GstAllocator, ffi::GstAllocatorClass>) @extends Object;
29
30 match fn {
31 type_ => || ffi::gst_allocator_get_type(),
32 }
33}
34
35impl Allocator {
36 pub const NONE: Option<&'static Allocator> = None;
37
38 /// Find a previously registered allocator with `name`. When `name` is [`None`], the
39 /// default allocator will be returned.
40 /// ## `name`
41 /// the name of the allocator
42 ///
43 /// # Returns
44 ///
45 /// a [`Allocator`][crate::Allocator] or [`None`] when
46 /// the allocator with `name` was not registered.
47 #[doc(alias = "gst_allocator_find")]
48 pub fn find(name: Option<&str>) -> Option<Allocator> {
49 assert_initialized_main_thread!();
50 unsafe { from_glib_full(ffi::gst_allocator_find(name.to_glib_none().0)) }
51 }
52}
53
54unsafe impl Send for Allocator {}
55unsafe impl Sync for Allocator {}
56
57/// Trait containing all [`struct@Allocator`] methods.
58///
59/// # Implementors
60///
61/// [`Allocator`][struct@crate::Allocator]
62pub trait AllocatorExt: IsA<Allocator> + 'static {
63 /// Use `self` to allocate a new memory block with memory that is at least
64 /// `size` big.
65 ///
66 /// The optional `params` can specify the prefix and padding for the memory. If
67 /// [`None`] is passed, no flags, no extra prefix/padding and a default alignment is
68 /// used.
69 ///
70 /// The prefix/padding will be filled with 0 if flags contains
71 /// [`MemoryFlags::ZERO_PREFIXED`][crate::MemoryFlags::ZERO_PREFIXED] and [`MemoryFlags::ZERO_PADDED`][crate::MemoryFlags::ZERO_PADDED] respectively.
72 ///
73 /// When `self` is [`None`], the default allocator will be used.
74 ///
75 /// The alignment in `params` is given as a bitmask so that `align` + 1 equals
76 /// the amount of bytes to align to. For example, to align to 8 bytes,
77 /// use an alignment of 7.
78 /// ## `size`
79 /// size of the visible memory area
80 /// ## `params`
81 /// optional parameters
82 ///
83 /// # Returns
84 ///
85 /// a new [`Memory`][crate::Memory].
86 #[doc(alias = "gst_allocator_alloc")]
87 fn alloc(
88 &self,
89 size: usize,
90 params: Option<&AllocationParams>,
91 ) -> Result<Memory, glib::BoolError> {
92 unsafe {
93 Option::<_>::from_glib_full(ffi::gst_allocator_alloc(
94 self.as_ref().to_glib_none().0,
95 size,
96 mut_override(params.to_glib_none().0),
97 ))
98 .ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
99 }
100 }
101
102 /// Set the default allocator.
103 #[doc(alias = "gst_allocator_set_default")]
104 fn set_default(self) {
105 unsafe {
106 ffi::gst_allocator_set_default(self.upcast().into_glib_ptr());
107 }
108 }
109}
110
111impl<O: IsA<Allocator>> AllocatorExt for O {}