gstreamer/
allocator.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, Allocator};
6
7impl Allocator {
8    pub fn memory_type(&self) -> &'static glib::GStr {
9        let obj: *const ffi::GstAllocator = self.to_glib_none().0;
10        unsafe { glib::GStr::from_ptr((*obj).mem_type) }
11    }
12
13    /// Registers the memory `allocator` with `name`.
14    /// ## `name`
15    /// the name of the allocator
16    /// ## `allocator`
17    /// [`Allocator`][crate::Allocator]
18    #[doc(alias = "gst_allocator_register")]
19    pub fn register(name: &str, allocator: impl IsA<Allocator>) {
20        skip_assert_initialized!();
21        unsafe {
22            #[cfg(not(feature = "v1_22"))]
23            {
24                // See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3364
25                if crate::version() < (1, 20, 5, 0) {
26                    ffi::gst_allocator_register(
27                        name.to_glib_full(),
28                        allocator.upcast().into_glib_ptr(),
29                    );
30                } else {
31                    ffi::gst_allocator_register(
32                        name.to_glib_none().0,
33                        allocator.upcast().into_glib_ptr(),
34                    );
35                }
36            }
37            #[cfg(feature = "v1_22")]
38            {
39                ffi::gst_allocator_register(
40                    name.to_glib_none().0,
41                    allocator.upcast().into_glib_ptr(),
42                );
43            }
44        }
45    }
46}