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
80mod sealed {
81    pub trait Sealed {}
82    impl<T: super::IsA<super::BufferPool>> Sealed for T {}
83}
84
85/// Trait containing all [`struct@BufferPool`] methods.
86///
87/// # Implementors
88///
89/// [`BufferPool`][struct@crate::BufferPool]
90pub trait BufferPoolExt: IsA<BufferPool> + sealed::Sealed + 'static {
91    /// Gets a [`None`] terminated array of string with supported bufferpool options for
92    /// `self`. An option would typically be enabled with
93    /// `gst_buffer_pool_config_add_option()`.
94    ///
95    /// # Returns
96    ///
97    /// a [`None`] terminated array
98    ///  of strings.
99    #[doc(alias = "gst_buffer_pool_get_options")]
100    #[doc(alias = "get_options")]
101    fn options(&self) -> Vec<glib::GString> {
102        unsafe {
103            FromGlibPtrContainer::from_glib_none(ffi::gst_buffer_pool_get_options(
104                self.as_ref().to_glib_none().0,
105            ))
106        }
107    }
108
109    /// Checks if the bufferpool supports `option`.
110    /// ## `option`
111    /// an option
112    ///
113    /// # Returns
114    ///
115    /// [`true`] if the buffer pool contains `option`.
116    #[doc(alias = "gst_buffer_pool_has_option")]
117    fn has_option(&self, option: &str) -> bool {
118        unsafe {
119            from_glib(ffi::gst_buffer_pool_has_option(
120                self.as_ref().to_glib_none().0,
121                option.to_glib_none().0,
122            ))
123        }
124    }
125
126    /// Checks if `self` is active. A pool can be activated with the
127    /// [`set_active()`][Self::set_active()] call.
128    ///
129    /// # Returns
130    ///
131    /// [`true`] when the pool is active.
132    #[doc(alias = "gst_buffer_pool_is_active")]
133    fn is_active(&self) -> bool {
134        unsafe {
135            from_glib(ffi::gst_buffer_pool_is_active(
136                self.as_ref().to_glib_none().0,
137            ))
138        }
139    }
140
141    /// Releases `buffer` to `self`. `buffer` should have previously been allocated from
142    /// `self` with [`BufferPoolExtManual::acquire_buffer()`][crate::prelude::BufferPoolExtManual::acquire_buffer()].
143    ///
144    /// This function is usually called automatically when the last ref on `buffer`
145    /// disappears.
146    /// ## `buffer`
147    /// a [`Buffer`][crate::Buffer]
148    #[doc(alias = "gst_buffer_pool_release_buffer")]
149    fn release_buffer(&self, buffer: Buffer) {
150        unsafe {
151            ffi::gst_buffer_pool_release_buffer(
152                self.as_ref().to_glib_none().0,
153                buffer.into_glib_ptr(),
154            );
155        }
156    }
157
158    /// Controls the active state of `self`. When the pool is inactive, new calls to
159    /// [`BufferPoolExtManual::acquire_buffer()`][crate::prelude::BufferPoolExtManual::acquire_buffer()] will return with [`FlowReturn::Flushing`][crate::FlowReturn::Flushing].
160    ///
161    /// Activating the bufferpool will preallocate all resources in the pool based on
162    /// the configuration of the pool.
163    ///
164    /// Deactivating will free the resources again when there are no outstanding
165    /// buffers. When there are outstanding buffers, they will be freed as soon as
166    /// they are all returned to the pool.
167    /// ## `active`
168    /// the new active state
169    ///
170    /// # Returns
171    ///
172    /// [`false`] when the pool was not configured or when preallocation of the
173    /// buffers failed.
174    #[doc(alias = "gst_buffer_pool_set_active")]
175    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError> {
176        unsafe {
177            glib::result_from_gboolean!(
178                ffi::gst_buffer_pool_set_active(self.as_ref().to_glib_none().0, active.into_glib()),
179                "Failed to activate buffer pool"
180            )
181        }
182    }
183
184    /// Enables or disables the flushing state of a `self` without freeing or
185    /// allocating buffers.
186    /// ## `flushing`
187    /// whether to start or stop flushing
188    #[doc(alias = "gst_buffer_pool_set_flushing")]
189    fn set_flushing(&self, flushing: bool) {
190        unsafe {
191            ffi::gst_buffer_pool_set_flushing(self.as_ref().to_glib_none().0, flushing.into_glib());
192        }
193    }
194}
195
196impl<O: IsA<BufferPool>> BufferPoolExt for O {}