gstreamer/auto/
buffer_pool.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, Buffer, Object};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    /// A [`BufferPool`][crate::BufferPool] is an object that can be used to pre-allocate and recycle
11    /// buffers of the same size and with the same properties.
12    ///
13    /// A [`BufferPool`][crate::BufferPool] is created with [`new()`][Self::new()].
14    ///
15    /// Once a pool is created, it needs to be configured. A call to
16    /// [`BufferPoolExtManual::config()`][crate::prelude::BufferPoolExtManual::config()] returns the current configuration structure from
17    /// the pool. With `gst_buffer_pool_config_set_params()` and
18    /// `gst_buffer_pool_config_set_allocator()` the bufferpool parameters and
19    /// allocator can be configured. Other properties can be configured in the pool
20    /// depending on the pool implementation.
21    ///
22    /// A bufferpool can have extra options that can be enabled with
23    /// `gst_buffer_pool_config_add_option()`. The available options can be retrieved
24    /// with [`BufferPoolExt::options()`][crate::prelude::BufferPoolExt::options()]. Some options allow for additional
25    /// configuration properties to be set.
26    ///
27    /// After the configuration structure has been configured,
28    /// [`BufferPoolExtManual::set_config()`][crate::prelude::BufferPoolExtManual::set_config()] updates the configuration in the pool. This can
29    /// fail when the configuration structure is not accepted.
30    ///
31    /// After the pool has been configured, it can be activated with
32    /// [`BufferPoolExt::set_active()`][crate::prelude::BufferPoolExt::set_active()]. This will preallocate the configured resources
33    /// in the pool.
34    ///
35    /// When the pool is active, [`BufferPoolExtManual::acquire_buffer()`][crate::prelude::BufferPoolExtManual::acquire_buffer()] can be used to
36    /// retrieve a buffer from the pool.
37    ///
38    /// Buffers allocated from a bufferpool will automatically be returned to the
39    /// pool with [`BufferPoolExt::release_buffer()`][crate::prelude::BufferPoolExt::release_buffer()] when their refcount drops to 0.
40    ///
41    /// The bufferpool can be deactivated again with [`BufferPoolExt::set_active()`][crate::prelude::BufferPoolExt::set_active()].
42    /// All further [`BufferPoolExtManual::acquire_buffer()`][crate::prelude::BufferPoolExtManual::acquire_buffer()] calls will return an error. When
43    /// all buffers are returned to the pool they will be freed.
44    ///
45    /// # Implements
46    ///
47    /// [`BufferPoolExt`][trait@crate::prelude::BufferPoolExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`BufferPoolExtManual`][trait@crate::prelude::BufferPoolExtManual]
48    #[doc(alias = "GstBufferPool")]
49    pub struct BufferPool(Object<ffi::GstBufferPool, ffi::GstBufferPoolClass>) @extends Object;
50
51    match fn {
52        type_ => || ffi::gst_buffer_pool_get_type(),
53    }
54}
55
56impl BufferPool {
57    pub const NONE: Option<&'static BufferPool> = None;
58
59    /// Creates a new [`BufferPool`][crate::BufferPool] instance.
60    ///
61    /// # Returns
62    ///
63    /// a new [`BufferPool`][crate::BufferPool] instance
64    #[doc(alias = "gst_buffer_pool_new")]
65    pub fn new() -> BufferPool {
66        assert_initialized_main_thread!();
67        unsafe { from_glib_full(ffi::gst_buffer_pool_new()) }
68    }
69}
70
71impl Default for BufferPool {
72    fn default() -> Self {
73        Self::new()
74    }
75}
76
77unsafe impl Send for BufferPool {}
78unsafe impl Sync for BufferPool {}
79
80/// Trait containing all [`struct@BufferPool`] methods.
81///
82/// # Implementors
83///
84/// [`BufferPool`][struct@crate::BufferPool]
85pub trait BufferPoolExt: IsA<BufferPool> + 'static {
86    /// Gets a [`None`] terminated array of string with supported bufferpool options for
87    /// `self`. An option would typically be enabled with
88    /// `gst_buffer_pool_config_add_option()`.
89    ///
90    /// # Returns
91    ///
92    /// a [`None`] terminated array
93    ///  of strings.
94    #[doc(alias = "gst_buffer_pool_get_options")]
95    #[doc(alias = "get_options")]
96    fn options(&self) -> Vec<glib::GString> {
97        unsafe {
98            FromGlibPtrContainer::from_glib_none(ffi::gst_buffer_pool_get_options(
99                self.as_ref().to_glib_none().0,
100            ))
101        }
102    }
103
104    /// Checks if the bufferpool supports `option`.
105    /// ## `option`
106    /// an option
107    ///
108    /// # Returns
109    ///
110    /// [`true`] if the buffer pool contains `option`.
111    #[doc(alias = "gst_buffer_pool_has_option")]
112    fn has_option(&self, option: &str) -> bool {
113        unsafe {
114            from_glib(ffi::gst_buffer_pool_has_option(
115                self.as_ref().to_glib_none().0,
116                option.to_glib_none().0,
117            ))
118        }
119    }
120
121    /// Checks if `self` is active. A pool can be activated with the
122    /// [`set_active()`][Self::set_active()] call.
123    ///
124    /// # Returns
125    ///
126    /// [`true`] when the pool is active.
127    #[doc(alias = "gst_buffer_pool_is_active")]
128    fn is_active(&self) -> bool {
129        unsafe {
130            from_glib(ffi::gst_buffer_pool_is_active(
131                self.as_ref().to_glib_none().0,
132            ))
133        }
134    }
135
136    /// Releases `buffer` to `self`. `buffer` should have previously been allocated from
137    /// `self` with [`BufferPoolExtManual::acquire_buffer()`][crate::prelude::BufferPoolExtManual::acquire_buffer()].
138    ///
139    /// This function is usually called automatically when the last ref on `buffer`
140    /// disappears.
141    /// ## `buffer`
142    /// a [`Buffer`][crate::Buffer]
143    #[doc(alias = "gst_buffer_pool_release_buffer")]
144    fn release_buffer(&self, buffer: Buffer) {
145        unsafe {
146            ffi::gst_buffer_pool_release_buffer(
147                self.as_ref().to_glib_none().0,
148                buffer.into_glib_ptr(),
149            );
150        }
151    }
152
153    /// Controls the active state of `self`. When the pool is inactive, new calls to
154    /// [`BufferPoolExtManual::acquire_buffer()`][crate::prelude::BufferPoolExtManual::acquire_buffer()] will return with [`FlowReturn::Flushing`][crate::FlowReturn::Flushing].
155    ///
156    /// Activating the bufferpool will preallocate all resources in the pool based on
157    /// the configuration of the pool.
158    ///
159    /// Deactivating will free the resources again when there are no outstanding
160    /// buffers. When there are outstanding buffers, they will be freed as soon as
161    /// they are all returned to the pool.
162    /// ## `active`
163    /// the new active state
164    ///
165    /// # Returns
166    ///
167    /// [`false`] when the pool was not configured or when preallocation of the
168    /// buffers failed.
169    #[doc(alias = "gst_buffer_pool_set_active")]
170    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError> {
171        unsafe {
172            glib::result_from_gboolean!(
173                ffi::gst_buffer_pool_set_active(self.as_ref().to_glib_none().0, active.into_glib()),
174                "Failed to activate buffer pool"
175            )
176        }
177    }
178
179    /// Enables or disables the flushing state of a `self` without freeing or
180    /// allocating buffers.
181    /// ## `flushing`
182    /// whether to start or stop flushing
183    #[doc(alias = "gst_buffer_pool_set_flushing")]
184    fn set_flushing(&self, flushing: bool) {
185        unsafe {
186            ffi::gst_buffer_pool_set_flushing(self.as_ref().to_glib_none().0, flushing.into_glib());
187        }
188    }
189}
190
191impl<O: IsA<BufferPool>> BufferPoolExt for O {}