objc2_core_video/generated/
CVPixelBufferPool.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvpixelbufferpool?language=objc)
14#[doc(alias = "CVPixelBufferPoolRef")]
15#[repr(C)]
16pub struct CVPixelBufferPool {
17    inner: [u8; 0],
18    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21cf_type!(
22    unsafe impl CVPixelBufferPool {}
23);
24#[cfg(feature = "objc2")]
25cf_objc2_type!(
26    unsafe impl RefEncode<"__CVPixelBufferPool"> for CVPixelBufferPool {}
27);
28
29extern "C" {
30    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvpixelbufferpoolminimumbuffercountkey?language=objc)
31    pub static kCVPixelBufferPoolMinimumBufferCountKey: &'static CFString;
32}
33
34extern "C" {
35    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvpixelbufferpoolmaximumbufferagekey?language=objc)
36    pub static kCVPixelBufferPoolMaximumBufferAgeKey: &'static CFString;
37}
38
39unsafe impl ConcreteType for CVPixelBufferPool {
40    #[doc(alias = "CVPixelBufferPoolGetTypeID")]
41    #[inline]
42    fn type_id() -> CFTypeID {
43        extern "C-unwind" {
44            fn CVPixelBufferPoolGetTypeID() -> CFTypeID;
45        }
46        unsafe { CVPixelBufferPoolGetTypeID() }
47    }
48}
49
50impl CVPixelBufferPool {
51    /// Creates a new Pixel Buffer pool.
52    ///
53    /// Parameter `allocator`: The CFAllocatorRef to use for allocating this buffer pool.  May be NULL.
54    ///
55    /// Parameter `attributes`: A CFDictionaryRef containing the attributes to be used for creating new PixelBuffers within the pool.
56    ///
57    /// Parameter `poolOut`: The newly created pool will be placed here
58    ///
59    /// Returns: Returns kCVReturnSuccess on success
60    ///
61    /// # Safety
62    ///
63    /// - `pool_attributes` generics must be of the correct type.
64    /// - `pixel_buffer_attributes` generics must be of the correct type.
65    /// - `pool_out` must be a valid pointer.
66    #[doc(alias = "CVPixelBufferPoolCreate")]
67    #[cfg(feature = "CVReturn")]
68    #[inline]
69    pub unsafe fn create(
70        allocator: Option<&CFAllocator>,
71        pool_attributes: Option<&CFDictionary>,
72        pixel_buffer_attributes: Option<&CFDictionary>,
73        pool_out: NonNull<*mut CVPixelBufferPool>,
74    ) -> CVReturn {
75        extern "C-unwind" {
76            fn CVPixelBufferPoolCreate(
77                allocator: Option<&CFAllocator>,
78                pool_attributes: Option<&CFDictionary>,
79                pixel_buffer_attributes: Option<&CFDictionary>,
80                pool_out: NonNull<*mut CVPixelBufferPool>,
81            ) -> CVReturn;
82        }
83        unsafe {
84            CVPixelBufferPoolCreate(
85                allocator,
86                pool_attributes,
87                pixel_buffer_attributes,
88                pool_out,
89            )
90        }
91    }
92
93    /// Returns the pool attributes dictionary for a CVPixelBufferPool
94    ///
95    /// Parameter `pool`: The CVPixelBufferPoolRef to retrieve the attributes from
96    ///
97    /// Returns: Returns the pool attributes dictionary, or NULL on failure.
98    #[doc(alias = "CVPixelBufferPoolGetAttributes")]
99    #[inline]
100    pub fn attributes(&self) -> Option<CFRetained<CFDictionary>> {
101        extern "C-unwind" {
102            fn CVPixelBufferPoolGetAttributes(
103                pool: &CVPixelBufferPool,
104            ) -> Option<NonNull<CFDictionary>>;
105        }
106        let ret = unsafe { CVPixelBufferPoolGetAttributes(self) };
107        ret.map(|ret| unsafe { CFRetained::retain(ret) })
108    }
109
110    /// Returns the attributes of pixel buffers that will be created from this pool.
111    ///
112    /// This function is provided for those cases where you may need to know some information about the buffers that
113    /// will be created up front.
114    ///
115    /// Parameter `pool`: The CVPixelBufferPoolRef to retrieve the attributes from
116    ///
117    /// Returns: Returns the pixel buffer attributes dictionary, or NULL on failure.
118    #[doc(alias = "CVPixelBufferPoolGetPixelBufferAttributes")]
119    #[inline]
120    pub fn pixel_buffer_attributes(&self) -> Option<CFRetained<CFDictionary>> {
121        extern "C-unwind" {
122            fn CVPixelBufferPoolGetPixelBufferAttributes(
123                pool: &CVPixelBufferPool,
124            ) -> Option<NonNull<CFDictionary>>;
125        }
126        let ret = unsafe { CVPixelBufferPoolGetPixelBufferAttributes(self) };
127        ret.map(|ret| unsafe { CFRetained::retain(ret) })
128    }
129
130    /// Creates a new PixelBuffer object from the pool.
131    ///
132    /// The function creates a new (attachment-free) CVPixelBuffer using the pixel buffer attributes specifed during pool creation.
133    ///
134    /// Parameter `allocator`: The CFAllocatorRef to use for creating the pixel buffer.  May be NULL.
135    ///
136    /// Parameter `pool`: The CVPixelBufferPool that should create the new CVPixelBuffer.
137    ///
138    /// Parameter `pixelBufferOut`: The newly created pixel buffer will be placed here
139    ///
140    /// Returns: Returns kCVReturnSuccess on success
141    ///
142    /// # Safety
143    ///
144    /// `pixel_buffer_out` must be a valid pointer.
145    #[doc(alias = "CVPixelBufferPoolCreatePixelBuffer")]
146    #[cfg(all(
147        feature = "CVBuffer",
148        feature = "CVImageBuffer",
149        feature = "CVPixelBuffer",
150        feature = "CVReturn"
151    ))]
152    #[inline]
153    pub unsafe fn create_pixel_buffer(
154        allocator: Option<&CFAllocator>,
155        pixel_buffer_pool: &CVPixelBufferPool,
156        pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
157    ) -> CVReturn {
158        extern "C-unwind" {
159            fn CVPixelBufferPoolCreatePixelBuffer(
160                allocator: Option<&CFAllocator>,
161                pixel_buffer_pool: &CVPixelBufferPool,
162                pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
163            ) -> CVReturn;
164        }
165        unsafe {
166            CVPixelBufferPoolCreatePixelBuffer(allocator, pixel_buffer_pool, pixel_buffer_out)
167        }
168    }
169
170    /// # Safety
171    ///
172    /// - `aux_attributes` generics must be of the correct type.
173    /// - `pixel_buffer_out` must be a valid pointer.
174    #[doc(alias = "CVPixelBufferPoolCreatePixelBufferWithAuxAttributes")]
175    #[cfg(all(
176        feature = "CVBuffer",
177        feature = "CVImageBuffer",
178        feature = "CVPixelBuffer",
179        feature = "CVReturn"
180    ))]
181    #[inline]
182    pub unsafe fn create_pixel_buffer_with_aux_attributes(
183        allocator: Option<&CFAllocator>,
184        pixel_buffer_pool: &CVPixelBufferPool,
185        aux_attributes: Option<&CFDictionary>,
186        pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
187    ) -> CVReturn {
188        extern "C-unwind" {
189            fn CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(
190                allocator: Option<&CFAllocator>,
191                pixel_buffer_pool: &CVPixelBufferPool,
192                aux_attributes: Option<&CFDictionary>,
193                pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
194            ) -> CVReturn;
195        }
196        unsafe {
197            CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(
198                allocator,
199                pixel_buffer_pool,
200                aux_attributes,
201                pixel_buffer_out,
202            )
203        }
204    }
205}
206
207extern "C" {
208    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvpixelbufferpoolallocationthresholdkey?language=objc)
209    pub static kCVPixelBufferPoolAllocationThresholdKey: &'static CFString;
210}
211
212extern "C" {
213    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvpixelbufferpoolfreebuffernotification?language=objc)
214    pub static kCVPixelBufferPoolFreeBufferNotification: &'static CFString;
215}
216
217/// Flags to pass to CVPixelBufferPoolFlush()
218///
219/// This flag will cause CVPixelBufferPoolFlush to flush all unused buffers regardless of age.
220///
221/// See also [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvpixelbufferpoolflushflags?language=objc)
222// NS_OPTIONS
223#[cfg(feature = "CVBase")]
224#[repr(transparent)]
225#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
226pub struct CVPixelBufferPoolFlushFlags(pub CVOptionFlags);
227#[cfg(feature = "CVBase")]
228bitflags::bitflags! {
229    impl CVPixelBufferPoolFlushFlags: CVOptionFlags {
230        #[doc(alias = "kCVPixelBufferPoolFlushExcessBuffers")]
231        const ExcessBuffers = 1;
232    }
233}
234
235#[cfg(all(feature = "CVBase", feature = "objc2"))]
236unsafe impl Encode for CVPixelBufferPoolFlushFlags {
237    const ENCODING: Encoding = CVOptionFlags::ENCODING;
238}
239
240#[cfg(all(feature = "CVBase", feature = "objc2"))]
241unsafe impl RefEncode for CVPixelBufferPoolFlushFlags {
242    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
243}
244
245impl CVPixelBufferPool {
246    /// Frees as many buffers from the pool as possible.
247    ///
248    /// By default, this function will free all aged out buffers.  Setting the
249    /// kCVPixelBufferPoolFlushExcessBuffers flag will cause this call to free all unused
250    /// buffers regardless of age.
251    ///
252    /// Parameter `pool`: The CVPixelBufferPool to be flushed.
253    ///
254    /// Parameter `options`: Set to kCVPixelBufferPoolFlushExcessBuffers to free all unused buffers
255    /// regardless of their age.
256    #[doc(alias = "CVPixelBufferPoolFlush")]
257    #[cfg(feature = "CVBase")]
258    #[inline]
259    pub fn flush(&self, options: CVPixelBufferPoolFlushFlags) {
260        extern "C-unwind" {
261            fn CVPixelBufferPoolFlush(
262                pool: &CVPixelBufferPool,
263                options: CVPixelBufferPoolFlushFlags,
264            );
265        }
266        unsafe { CVPixelBufferPoolFlush(self, options) }
267    }
268}
269
270extern "C-unwind" {
271    #[cfg(feature = "CVReturn")]
272    #[deprecated = "renamed to `CVPixelBufferPool::create`"]
273    pub fn CVPixelBufferPoolCreate(
274        allocator: Option<&CFAllocator>,
275        pool_attributes: Option<&CFDictionary>,
276        pixel_buffer_attributes: Option<&CFDictionary>,
277        pool_out: NonNull<*mut CVPixelBufferPool>,
278    ) -> CVReturn;
279}
280
281#[deprecated = "renamed to `CVPixelBufferPool::attributes`"]
282#[inline]
283pub extern "C-unwind" fn CVPixelBufferPoolGetAttributes(
284    pool: &CVPixelBufferPool,
285) -> Option<CFRetained<CFDictionary>> {
286    extern "C-unwind" {
287        fn CVPixelBufferPoolGetAttributes(
288            pool: &CVPixelBufferPool,
289        ) -> Option<NonNull<CFDictionary>>;
290    }
291    let ret = unsafe { CVPixelBufferPoolGetAttributes(pool) };
292    ret.map(|ret| unsafe { CFRetained::retain(ret) })
293}
294
295#[deprecated = "renamed to `CVPixelBufferPool::pixel_buffer_attributes`"]
296#[inline]
297pub extern "C-unwind" fn CVPixelBufferPoolGetPixelBufferAttributes(
298    pool: &CVPixelBufferPool,
299) -> Option<CFRetained<CFDictionary>> {
300    extern "C-unwind" {
301        fn CVPixelBufferPoolGetPixelBufferAttributes(
302            pool: &CVPixelBufferPool,
303        ) -> Option<NonNull<CFDictionary>>;
304    }
305    let ret = unsafe { CVPixelBufferPoolGetPixelBufferAttributes(pool) };
306    ret.map(|ret| unsafe { CFRetained::retain(ret) })
307}
308
309extern "C-unwind" {
310    #[cfg(all(
311        feature = "CVBuffer",
312        feature = "CVImageBuffer",
313        feature = "CVPixelBuffer",
314        feature = "CVReturn"
315    ))]
316    #[deprecated = "renamed to `CVPixelBufferPool::create_pixel_buffer`"]
317    pub fn CVPixelBufferPoolCreatePixelBuffer(
318        allocator: Option<&CFAllocator>,
319        pixel_buffer_pool: &CVPixelBufferPool,
320        pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
321    ) -> CVReturn;
322}
323
324extern "C-unwind" {
325    #[cfg(all(
326        feature = "CVBuffer",
327        feature = "CVImageBuffer",
328        feature = "CVPixelBuffer",
329        feature = "CVReturn"
330    ))]
331    #[deprecated = "renamed to `CVPixelBufferPool::create_pixel_buffer_with_aux_attributes`"]
332    pub fn CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(
333        allocator: Option<&CFAllocator>,
334        pixel_buffer_pool: &CVPixelBufferPool,
335        aux_attributes: Option<&CFDictionary>,
336        pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
337    ) -> CVReturn;
338}
339
340#[cfg(feature = "CVBase")]
341#[deprecated = "renamed to `CVPixelBufferPool::flush`"]
342#[inline]
343pub extern "C-unwind" fn CVPixelBufferPoolFlush(
344    pool: &CVPixelBufferPool,
345    options: CVPixelBufferPoolFlushFlags,
346) {
347    extern "C-unwind" {
348        fn CVPixelBufferPoolFlush(pool: &CVPixelBufferPool, options: CVPixelBufferPoolFlushFlags);
349    }
350    unsafe { CVPixelBufferPoolFlush(pool, options) }
351}