objc2_core_video/generated/
CVBuffer.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
13extern "C" {
14    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbufferpropagatedattachmentskey?language=objc)
15    pub static kCVBufferPropagatedAttachmentsKey: &'static CFString;
16}
17
18extern "C" {
19    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffernonpropagatedattachmentskey?language=objc)
20    pub static kCVBufferNonPropagatedAttachmentsKey: &'static CFString;
21}
22
23extern "C" {
24    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffermovietimekey?language=objc)
25    pub static kCVBufferMovieTimeKey: &'static CFString;
26}
27
28extern "C" {
29    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffertimevaluekey?language=objc)
30    pub static kCVBufferTimeValueKey: &'static CFString;
31}
32
33extern "C" {
34    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffertimescalekey?language=objc)
35    pub static kCVBufferTimeScaleKey: &'static CFString;
36}
37
38/// [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvattachmentmode?language=objc)
39// NS_ENUM
40#[repr(transparent)]
41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
42pub struct CVAttachmentMode(pub u32);
43impl CVAttachmentMode {
44    #[doc(alias = "kCVAttachmentMode_ShouldNotPropagate")]
45    pub const ShouldNotPropagate: Self = Self(0);
46    #[doc(alias = "kCVAttachmentMode_ShouldPropagate")]
47    pub const ShouldPropagate: Self = Self(1);
48}
49
50#[cfg(feature = "objc2")]
51unsafe impl Encode for CVAttachmentMode {
52    const ENCODING: Encoding = u32::ENCODING;
53}
54
55#[cfg(feature = "objc2")]
56unsafe impl RefEncode for CVAttachmentMode {
57    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
58}
59
60/// Base type for all CoreVideo buffers
61///
62/// See also [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvbuffer?language=objc)
63#[doc(alias = "CVBufferRef")]
64#[repr(C)]
65pub struct CVBuffer {
66    inner: [u8; 0],
67    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
68}
69
70cf_type!(
71    unsafe impl CVBuffer {}
72);
73#[cfg(feature = "objc2")]
74cf_objc2_type!(
75    unsafe impl RefEncode<"__CVBuffer"> for CVBuffer {}
76);
77
78impl CVBuffer {
79    /// Sets or adds a attachment of a CVBuffer object
80    ///
81    /// You can attach any CF object to a CVBuffer object to store additional information. CVBufferGetAttachment stores an attachement identified by a key. If the key doesn't exist, the attachment will be added. If the key does exist, the existing attachment will be replaced. In bouth cases the retain count of the attachment will be incremented. The value can be any CFType but nil has no defined behavior.
82    ///
83    /// Parameter `buffer`: Target CVBuffer object.
84    ///
85    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
86    ///
87    /// Parameter `value`: Attachment in form af a CF object.
88    ///
89    /// Parameter `attachmentMode`: Specifies which attachment mode is desired for this attachment.   A particular attachment key may only exist in
90    /// a single mode at a time.
91    ///
92    /// # Safety
93    ///
94    /// `value` should be of the correct type.
95    #[doc(alias = "CVBufferSetAttachment")]
96    #[inline]
97    pub unsafe fn set_attachment(
98        &self,
99        key: &CFString,
100        value: &CFType,
101        attachment_mode: CVAttachmentMode,
102    ) {
103        extern "C-unwind" {
104            fn CVBufferSetAttachment(
105                buffer: &CVBuffer,
106                key: &CFString,
107                value: &CFType,
108                attachment_mode: CVAttachmentMode,
109            );
110        }
111        unsafe { CVBufferSetAttachment(self, key, value, attachment_mode) }
112    }
113
114    /// Returns a specific attachment of a CVBuffer object
115    ///
116    /// You can attach any CF object to a CVBuffer object to store additional information. CVBufferGetAttachment retrieves an attachement identified by a key.
117    ///
118    /// Parameter `buffer`: Target CVBuffer object.
119    ///
120    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
121    ///
122    /// Parameter `attachmentMode`: Returns the mode of the attachment, if desired.  May be NULL.
123    ///
124    /// Returns: If found the attachment object
125    ///
126    /// # Safety
127    ///
128    /// `attachment_mode` must be a valid pointer or null.
129    #[doc(alias = "CVBufferGetAttachment")]
130    #[deprecated]
131    #[inline]
132    pub unsafe fn get_attachment(
133        &self,
134        key: &CFString,
135        attachment_mode: *mut CVAttachmentMode,
136    ) -> Option<CFRetained<CFType>> {
137        extern "C-unwind" {
138            fn CVBufferGetAttachment(
139                buffer: &CVBuffer,
140                key: &CFString,
141                attachment_mode: *mut CVAttachmentMode,
142            ) -> Option<NonNull<CFType>>;
143        }
144        let ret = unsafe { CVBufferGetAttachment(self, key, attachment_mode) };
145        ret.map(|ret| unsafe { CFRetained::retain(ret) })
146    }
147
148    /// Removes a specific attachment of a CVBuffer object
149    ///
150    /// CVBufferRemoveAttachment removes an attachement identified by a key. If found the attachement is removed and the retain count decremented.
151    ///
152    /// Parameter `buffer`: Target CVBuffer object.
153    ///
154    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
155    #[doc(alias = "CVBufferRemoveAttachment")]
156    #[inline]
157    pub fn remove_attachment(&self, key: &CFString) {
158        extern "C-unwind" {
159            fn CVBufferRemoveAttachment(buffer: &CVBuffer, key: &CFString);
160        }
161        unsafe { CVBufferRemoveAttachment(self, key) }
162    }
163
164    /// Removes all attachments of a CVBuffer object
165    ///
166    /// While CVBufferRemoveAttachment removes a specific attachement identified by a key CVBufferRemoveAllAttachments removes all attachments of a buffer and decrements their retain counts.
167    ///
168    /// Parameter `buffer`: Target CVBuffer object.
169    #[doc(alias = "CVBufferRemoveAllAttachments")]
170    #[inline]
171    pub fn remove_all_attachments(&self) {
172        extern "C-unwind" {
173            fn CVBufferRemoveAllAttachments(buffer: &CVBuffer);
174        }
175        unsafe { CVBufferRemoveAllAttachments(self) }
176    }
177
178    /// Returns all attachments of a CVBuffer object
179    ///
180    /// CVBufferGetAttachments is a convenience call that returns all attachments with their corresponding keys in a CFDictionary.
181    ///
182    /// Parameter `buffer`: Target CVBuffer object.
183    ///
184    /// Returns: A CFDictionary with all buffer attachments identified by there keys. If no attachment is present, the dictionary is empty.  Returns NULL
185    /// for invalid attachment mode.
186    #[doc(alias = "CVBufferGetAttachments")]
187    #[deprecated]
188    #[inline]
189    pub fn get_attachments(
190        &self,
191        attachment_mode: CVAttachmentMode,
192    ) -> Option<CFRetained<CFDictionary>> {
193        extern "C-unwind" {
194            fn CVBufferGetAttachments(
195                buffer: &CVBuffer,
196                attachment_mode: CVAttachmentMode,
197            ) -> Option<NonNull<CFDictionary>>;
198        }
199        let ret = unsafe { CVBufferGetAttachments(self, attachment_mode) };
200        ret.map(|ret| unsafe { CFRetained::retain(ret) })
201    }
202
203    /// Sets a set of attachments for a CVBuffer
204    ///
205    /// CVBufferSetAttachments is a convenience call that in turn calls CVBufferSetAttachment for each key and value in the given dictionary. All key value pairs must be in the root level of the dictionary.
206    ///
207    /// Parameter `buffer`: Target CVBuffer object.
208    ///
209    /// # Safety
210    ///
211    /// `the_attachments` generics must be of the correct type.
212    #[doc(alias = "CVBufferSetAttachments")]
213    #[inline]
214    pub unsafe fn set_attachments(
215        &self,
216        the_attachments: &CFDictionary,
217        attachment_mode: CVAttachmentMode,
218    ) {
219        extern "C-unwind" {
220            fn CVBufferSetAttachments(
221                buffer: &CVBuffer,
222                the_attachments: &CFDictionary,
223                attachment_mode: CVAttachmentMode,
224            );
225        }
226        unsafe { CVBufferSetAttachments(self, the_attachments, attachment_mode) }
227    }
228
229    /// Copy all propagatable attachments from one buffer to another.
230    ///
231    /// CVBufferPropagateAttachments is a convenience call that copies all attachments with a mode of kCVAttachmentMode_ShouldPropagate from one
232    /// buffer to another.
233    ///
234    /// Parameter `sourceBuffer`: CVBuffer to copy attachments from.
235    ///
236    /// Parameter `destinationBuffer`: CVBuffer to copy attachments to.
237    #[doc(alias = "CVBufferPropagateAttachments")]
238    #[inline]
239    pub fn propagate_attachments(&self, destination_buffer: &CVBuffer) {
240        extern "C-unwind" {
241            fn CVBufferPropagateAttachments(
242                source_buffer: &CVBuffer,
243                destination_buffer: &CVBuffer,
244            );
245        }
246        unsafe { CVBufferPropagateAttachments(self, destination_buffer) }
247    }
248
249    /// Returns a copy of all attachments of a CVBuffer object. It is the caller’s responsibility to release the returned dictionary.
250    ///
251    /// CVBufferCopyAttachments is a convenience call that returns a copy of all attachments with their corresponding keys in a CFDictionary.
252    ///
253    /// Parameter `buffer`: Target CVBuffer object.
254    ///
255    /// Returns: A CFDictionary with all buffer attachments identified by their keys. If no attachment is present or invalid attachment mode,   returns NULL
256    #[doc(alias = "CVBufferCopyAttachments")]
257    #[inline]
258    pub fn attachments(
259        &self,
260        attachment_mode: CVAttachmentMode,
261    ) -> Option<CFRetained<CFDictionary>> {
262        extern "C-unwind" {
263            fn CVBufferCopyAttachments(
264                buffer: &CVBuffer,
265                attachment_mode: CVAttachmentMode,
266            ) -> Option<NonNull<CFDictionary>>;
267        }
268        let ret = unsafe { CVBufferCopyAttachments(self, attachment_mode) };
269        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
270    }
271
272    /// Returns a retained specific attachment of a CVBuffer object. It is the caller’s responsibility to release the returned value.
273    ///
274    /// You can attach any CF object to a CVBuffer object to store additional information. CVBufferCopyAttachment retrieves a retained attachment identified by a key.
275    ///
276    /// Parameter `buffer`: Target CVBuffer object.
277    ///
278    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
279    ///
280    /// Parameter `attachmentMode`: Returns the mode of the attachment, if desired.  May be NULL.
281    ///
282    /// Returns: If found the attachment object, return the value; otherwize, return NULL.
283    ///
284    /// # Safety
285    ///
286    /// `attachment_mode` must be a valid pointer or null.
287    #[doc(alias = "CVBufferCopyAttachment")]
288    #[inline]
289    pub unsafe fn attachment(
290        &self,
291        key: &CFString,
292        attachment_mode: *mut CVAttachmentMode,
293    ) -> Option<CFRetained<CFType>> {
294        extern "C-unwind" {
295            fn CVBufferCopyAttachment(
296                buffer: &CVBuffer,
297                key: &CFString,
298                attachment_mode: *mut CVAttachmentMode,
299            ) -> Option<NonNull<CFType>>;
300        }
301        let ret = unsafe { CVBufferCopyAttachment(self, key, attachment_mode) };
302        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
303    }
304
305    /// Returns true if an attachment with the passed key is present on a CVBuffer object.
306    ///
307    /// Parameter `buffer`: Target CVBuffer object.
308    ///
309    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
310    ///
311    /// Returns: True if an attachment with this key is present, otherwise false.
312    #[doc(alias = "CVBufferHasAttachment")]
313    #[inline]
314    pub fn has_attachment(&self, key: &CFString) -> bool {
315        extern "C-unwind" {
316            fn CVBufferHasAttachment(buffer: &CVBuffer, key: &CFString) -> Boolean;
317        }
318        let ret = unsafe { CVBufferHasAttachment(self, key) };
319        ret != 0
320    }
321}
322
323extern "C-unwind" {
324    #[deprecated = "renamed to `CVBuffer::set_attachment`"]
325    pub fn CVBufferSetAttachment(
326        buffer: &CVBuffer,
327        key: &CFString,
328        value: &CFType,
329        attachment_mode: CVAttachmentMode,
330    );
331}
332
333#[deprecated = "renamed to `CVBuffer::get_attachment`"]
334#[inline]
335pub unsafe extern "C-unwind" fn CVBufferGetAttachment(
336    buffer: &CVBuffer,
337    key: &CFString,
338    attachment_mode: *mut CVAttachmentMode,
339) -> Option<CFRetained<CFType>> {
340    extern "C-unwind" {
341        fn CVBufferGetAttachment(
342            buffer: &CVBuffer,
343            key: &CFString,
344            attachment_mode: *mut CVAttachmentMode,
345        ) -> Option<NonNull<CFType>>;
346    }
347    let ret = unsafe { CVBufferGetAttachment(buffer, key, attachment_mode) };
348    ret.map(|ret| unsafe { CFRetained::retain(ret) })
349}
350
351#[deprecated = "renamed to `CVBuffer::remove_attachment`"]
352#[inline]
353pub extern "C-unwind" fn CVBufferRemoveAttachment(buffer: &CVBuffer, key: &CFString) {
354    extern "C-unwind" {
355        fn CVBufferRemoveAttachment(buffer: &CVBuffer, key: &CFString);
356    }
357    unsafe { CVBufferRemoveAttachment(buffer, key) }
358}
359
360#[deprecated = "renamed to `CVBuffer::remove_all_attachments`"]
361#[inline]
362pub extern "C-unwind" fn CVBufferRemoveAllAttachments(buffer: &CVBuffer) {
363    extern "C-unwind" {
364        fn CVBufferRemoveAllAttachments(buffer: &CVBuffer);
365    }
366    unsafe { CVBufferRemoveAllAttachments(buffer) }
367}
368
369#[deprecated = "renamed to `CVBuffer::get_attachments`"]
370#[inline]
371pub extern "C-unwind" fn CVBufferGetAttachments(
372    buffer: &CVBuffer,
373    attachment_mode: CVAttachmentMode,
374) -> Option<CFRetained<CFDictionary>> {
375    extern "C-unwind" {
376        fn CVBufferGetAttachments(
377            buffer: &CVBuffer,
378            attachment_mode: CVAttachmentMode,
379        ) -> Option<NonNull<CFDictionary>>;
380    }
381    let ret = unsafe { CVBufferGetAttachments(buffer, attachment_mode) };
382    ret.map(|ret| unsafe { CFRetained::retain(ret) })
383}
384
385extern "C-unwind" {
386    #[deprecated = "renamed to `CVBuffer::set_attachments`"]
387    pub fn CVBufferSetAttachments(
388        buffer: &CVBuffer,
389        the_attachments: &CFDictionary,
390        attachment_mode: CVAttachmentMode,
391    );
392}
393
394#[deprecated = "renamed to `CVBuffer::propagate_attachments`"]
395#[inline]
396pub extern "C-unwind" fn CVBufferPropagateAttachments(
397    source_buffer: &CVBuffer,
398    destination_buffer: &CVBuffer,
399) {
400    extern "C-unwind" {
401        fn CVBufferPropagateAttachments(source_buffer: &CVBuffer, destination_buffer: &CVBuffer);
402    }
403    unsafe { CVBufferPropagateAttachments(source_buffer, destination_buffer) }
404}
405
406#[deprecated = "renamed to `CVBuffer::attachments`"]
407#[inline]
408pub extern "C-unwind" fn CVBufferCopyAttachments(
409    buffer: &CVBuffer,
410    attachment_mode: CVAttachmentMode,
411) -> Option<CFRetained<CFDictionary>> {
412    extern "C-unwind" {
413        fn CVBufferCopyAttachments(
414            buffer: &CVBuffer,
415            attachment_mode: CVAttachmentMode,
416        ) -> Option<NonNull<CFDictionary>>;
417    }
418    let ret = unsafe { CVBufferCopyAttachments(buffer, attachment_mode) };
419    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
420}
421
422#[deprecated = "renamed to `CVBuffer::attachment`"]
423#[inline]
424pub unsafe extern "C-unwind" fn CVBufferCopyAttachment(
425    buffer: &CVBuffer,
426    key: &CFString,
427    attachment_mode: *mut CVAttachmentMode,
428) -> Option<CFRetained<CFType>> {
429    extern "C-unwind" {
430        fn CVBufferCopyAttachment(
431            buffer: &CVBuffer,
432            key: &CFString,
433            attachment_mode: *mut CVAttachmentMode,
434        ) -> Option<NonNull<CFType>>;
435    }
436    let ret = unsafe { CVBufferCopyAttachment(buffer, key, attachment_mode) };
437    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
438}
439
440#[deprecated = "renamed to `CVBuffer::has_attachment`"]
441#[inline]
442pub extern "C-unwind" fn CVBufferHasAttachment(buffer: &CVBuffer, key: &CFString) -> bool {
443    extern "C-unwind" {
444        fn CVBufferHasAttachment(buffer: &CVBuffer, key: &CFString) -> Boolean;
445    }
446    let ret = unsafe { CVBufferHasAttachment(buffer, key) };
447    ret != 0
448}