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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib;
use glib::object::IsA;
use glib::translate::*;
use glib::GString;
use gst_sys;
use Object;

glib_wrapper! {
    /// A `BufferPool` is an object that can be used to pre-allocate and recycle
    /// buffers of the same size and with the same properties.
    ///
    /// A `BufferPool` is created with `BufferPool::new`.
    ///
    /// Once a pool is created, it needs to be configured. A call to
    /// `BufferPool::get_config` returns the current configuration structure from
    /// the pool. With `BufferPool::config_set_params` and
    /// `BufferPool::config_set_allocator` the bufferpool parameters and
    /// allocator can be configured. Other properties can be configured in the pool
    /// depending on the pool implementation.
    ///
    /// A bufferpool can have extra options that can be enabled with
    /// `BufferPool::config_add_option`. The available options can be retrieved
    /// with `BufferPoolExt::get_options`. Some options allow for additional
    /// configuration properties to be set.
    ///
    /// After the configuration structure has been configured,
    /// `BufferPool::set_config` updates the configuration in the pool. This can
    /// fail when the configuration structure is not accepted.
    ///
    /// After the a pool has been configured, it can be activated with
    /// `BufferPoolExt::set_active`. This will preallocate the configured resources
    /// in the pool.
    ///
    /// When the pool is active, `BufferPool::acquire_buffer` can be used to
    /// retrieve a buffer from the pool.
    ///
    /// Buffers allocated from a bufferpool will automatically be returned to the
    /// pool with `BufferPool::release_buffer` when their refcount drops to 0.
    ///
    /// The bufferpool can be deactivated again with `BufferPoolExt::set_active`.
    /// All further `BufferPool::acquire_buffer` calls will return an error. When
    /// all buffers are returned to the pool they will be freed.
    ///
    /// Use `GstObjectExt::unref` to release the reference to a bufferpool. If the
    /// refcount of the pool reaches 0, the pool will be freed.
    ///
    /// # Implements
    ///
    /// [`BufferPoolExt`](trait.BufferPoolExt.html), [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`BufferPoolExtManual`](prelude/trait.BufferPoolExtManual.html)
    pub struct BufferPool(Object<gst_sys::GstBufferPool, gst_sys::GstBufferPoolClass, BufferPoolClass>) @extends Object;

    match fn {
        get_type => || gst_sys::gst_buffer_pool_get_type(),
    }
}

unsafe impl Send for BufferPool {}
unsafe impl Sync for BufferPool {}

pub const NONE_BUFFER_POOL: Option<&BufferPool> = None;

/// Trait containing all `BufferPool` methods.
///
/// # Implementors
///
/// [`BufferPool`](struct.BufferPool.html)
pub trait BufferPoolExt: 'static {
    /// Get a `None` terminated array of string with supported bufferpool options for
    /// `self`. An option would typically be enabled with
    /// `BufferPool::config_add_option`.
    ///
    /// # Returns
    ///
    /// a `None` terminated array
    ///  of strings.
    fn get_options(&self) -> Vec<GString>;

    /// Check if the bufferpool supports `option`.
    /// ## `option`
    /// an option
    ///
    /// # Returns
    ///
    /// `true` if the buffer pool contains `option`.
    fn has_option(&self, option: &str) -> bool;

    /// Check if `self` is active. A pool can be activated with the
    /// `BufferPoolExt::set_active` call.
    ///
    /// # Returns
    ///
    /// `true` when the pool is active.
    fn is_active(&self) -> bool;

    /// Control the active state of `self`. When the pool is inactive, new calls to
    /// `BufferPool::acquire_buffer` will return with `FlowReturn::Flushing`.
    ///
    /// Activating the bufferpool will preallocate all resources in the pool based on
    /// the configuration of the pool.
    ///
    /// Deactivating will free the resources again when there are no outstanding
    /// buffers. When there are outstanding buffers, they will be freed as soon as
    /// they are all returned to the pool.
    /// ## `active`
    /// the new active state
    ///
    /// # Returns
    ///
    /// `false` when the pool was not configured or when preallocation of the
    /// buffers failed.
    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError>;

    /// Enable or disable the flushing state of a `self` without freeing or
    /// allocating buffers.
    /// ## `flushing`
    /// whether to start or stop flushing
    fn set_flushing(&self, flushing: bool);
}

impl<O: IsA<BufferPool>> BufferPoolExt for O {
    fn get_options(&self) -> Vec<GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(gst_sys::gst_buffer_pool_get_options(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn has_option(&self, option: &str) -> bool {
        unsafe {
            from_glib(gst_sys::gst_buffer_pool_has_option(
                self.as_ref().to_glib_none().0,
                option.to_glib_none().0,
            ))
        }
    }

    fn is_active(&self) -> bool {
        unsafe {
            from_glib(gst_sys::gst_buffer_pool_is_active(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                gst_sys::gst_buffer_pool_set_active(
                    self.as_ref().to_glib_none().0,
                    active.to_glib()
                ),
                "Failed to activate buffer pool"
            )
        }
    }

    fn set_flushing(&self, flushing: bool) {
        unsafe {
            gst_sys::gst_buffer_pool_set_flushing(
                self.as_ref().to_glib_none().0,
                flushing.to_glib(),
            );
        }
    }
}