1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::ffi;
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// Private intance object for [`DRMDumbAllocator`][crate::DRMDumbAllocator].
    ///
    /// ## Properties
    ///
    ///
    /// #### `drm-device-path`
    ///  Readable | Writeable | Construct Only
    ///
    ///
    /// #### `drm-fd`
    ///  Readable | Writeable | Construct Only
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `name`
    ///  Readable | Writeable | Construct
    ///
    ///
    /// #### `parent`
    ///  The parent of the object. Please note, that when changing the 'parent'
    /// property, we don't emit `GObject::notify` and `GstObject::deep-notify`
    /// signals due to locking issues. In some cases one can use
    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
    /// achieve a similar effect.
    ///
    /// Readable | Writeable
    /// </details>
    ///
    /// # Implements
    ///
    /// [`trait@gst::prelude::AllocatorExt`]
    #[doc(alias = "GstDRMDumbAllocator")]
    pub struct DRMDumbAllocator(Object<ffi::GstDRMDumbAllocator, ffi::GstDRMDumbAllocatorClass>) @extends gst::Allocator;

    match fn {
        type_ => || ffi::gst_drm_dumb_allocator_get_type(),
    }
}

impl DRMDumbAllocator {
    /// Creates a new [`DRMDumbAllocator`][crate::DRMDumbAllocator] for the specific device path. This
    /// function can fail if the path does not exist, is not a DRM device or if
    /// the DRM device doesnot support DUMB allocation.
    /// ## `drm_device_path`
    /// path to the DRM device to open
    ///
    /// # Returns
    ///
    /// a new DRM Dumb allocator. Use `gst_object_unref()`
    ///  to release the allocator after usage.
    #[doc(alias = "gst_drm_dumb_allocator_new_with_device_path")]
    #[doc(alias = "new_with_device_path")]
    pub fn with_device_path(
        drm_device_path: impl AsRef<std::path::Path>,
    ) -> Result<DRMDumbAllocator, glib::BoolError> {
        assert_initialized_main_thread!();
        unsafe {
            Option::<gst::Allocator>::from_glib_full(
                ffi::gst_drm_dumb_allocator_new_with_device_path(
                    drm_device_path.as_ref().to_glib_none().0,
                ),
            )
            .map(|o| o.unsafe_cast())
            .ok_or_else(|| glib::bool_error!("Failed to create allocator"))
        }
    }

    /// This function allow verifying if the driver support dma-buf exportation.
    ///
    /// # Returns
    ///
    /// [`true`] if the allocator support exporting dma-buf.
    #[doc(alias = "gst_drm_dumb_allocator_has_prime_export")]
    pub fn has_prime_export(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_drm_dumb_allocator_has_prime_export(
                self.to_glib_none().0,
            ))
        }
    }

    #[cfg(feature = "v1_24")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
    #[doc(alias = "drm-device-path")]
    pub fn drm_device_path(&self) -> Option<std::path::PathBuf> {
        ObjectExt::property(self, "drm-device-path")
    }

    #[cfg(feature = "v1_24")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
    #[doc(alias = "drm-fd")]
    pub fn drm_fd(&self) -> i32 {
        ObjectExt::property(self, "drm-fd")
    }
}

unsafe impl Send for DRMDumbAllocator {}
unsafe impl Sync for DRMDumbAllocator {}