objc2-core-video 0.3.2

Bindings to the CoreVideo framework
Documentation
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;

use crate::*;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbufferpropagatedattachmentskey?language=objc)
    pub static kCVBufferPropagatedAttachmentsKey: &'static CFString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffernonpropagatedattachmentskey?language=objc)
    pub static kCVBufferNonPropagatedAttachmentsKey: &'static CFString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffermovietimekey?language=objc)
    pub static kCVBufferMovieTimeKey: &'static CFString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffertimevaluekey?language=objc)
    pub static kCVBufferTimeValueKey: &'static CFString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/corevideo/kcvbuffertimescalekey?language=objc)
    pub static kCVBufferTimeScaleKey: &'static CFString;
}

/// [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvattachmentmode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CVAttachmentMode(pub u32);
impl CVAttachmentMode {
    #[doc(alias = "kCVAttachmentMode_ShouldNotPropagate")]
    pub const ShouldNotPropagate: Self = Self(0);
    #[doc(alias = "kCVAttachmentMode_ShouldPropagate")]
    pub const ShouldPropagate: Self = Self(1);
}

#[cfg(feature = "objc2")]
unsafe impl Encode for CVAttachmentMode {
    const ENCODING: Encoding = u32::ENCODING;
}

#[cfg(feature = "objc2")]
unsafe impl RefEncode for CVAttachmentMode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Base type for all CoreVideo buffers
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/corevideo/cvbuffer?language=objc)
#[doc(alias = "CVBufferRef")]
#[repr(C)]
pub struct CVBuffer {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl CVBuffer {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"__CVBuffer"> for CVBuffer {}
);

impl CVBuffer {
    /// Sets or adds a attachment of a CVBuffer object
    ///
    /// 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.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
    ///
    /// Parameter `value`: Attachment in form af a CF object.
    ///
    /// Parameter `attachmentMode`: Specifies which attachment mode is desired for this attachment.   A particular attachment key may only exist in
    /// a single mode at a time.
    ///
    /// # Safety
    ///
    /// `value` should be of the correct type.
    #[doc(alias = "CVBufferSetAttachment")]
    #[inline]
    pub unsafe fn set_attachment(
        &self,
        key: &CFString,
        value: &CFType,
        attachment_mode: CVAttachmentMode,
    ) {
        extern "C-unwind" {
            fn CVBufferSetAttachment(
                buffer: &CVBuffer,
                key: &CFString,
                value: &CFType,
                attachment_mode: CVAttachmentMode,
            );
        }
        unsafe { CVBufferSetAttachment(self, key, value, attachment_mode) }
    }

    /// Returns a specific attachment of a CVBuffer object
    ///
    /// You can attach any CF object to a CVBuffer object to store additional information. CVBufferGetAttachment retrieves an attachement identified by a key.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
    ///
    /// Parameter `attachmentMode`: Returns the mode of the attachment, if desired.  May be NULL.
    ///
    /// Returns: If found the attachment object
    ///
    /// # Safety
    ///
    /// `attachment_mode` must be a valid pointer or null.
    #[doc(alias = "CVBufferGetAttachment")]
    #[deprecated]
    #[inline]
    pub unsafe fn get_attachment(
        &self,
        key: &CFString,
        attachment_mode: *mut CVAttachmentMode,
    ) -> Option<CFRetained<CFType>> {
        extern "C-unwind" {
            fn CVBufferGetAttachment(
                buffer: &CVBuffer,
                key: &CFString,
                attachment_mode: *mut CVAttachmentMode,
            ) -> Option<NonNull<CFType>>;
        }
        let ret = unsafe { CVBufferGetAttachment(self, key, attachment_mode) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// Removes a specific attachment of a CVBuffer object
    ///
    /// CVBufferRemoveAttachment removes an attachement identified by a key. If found the attachement is removed and the retain count decremented.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
    #[doc(alias = "CVBufferRemoveAttachment")]
    #[inline]
    pub fn remove_attachment(&self, key: &CFString) {
        extern "C-unwind" {
            fn CVBufferRemoveAttachment(buffer: &CVBuffer, key: &CFString);
        }
        unsafe { CVBufferRemoveAttachment(self, key) }
    }

    /// Removes all attachments of a CVBuffer object
    ///
    /// While CVBufferRemoveAttachment removes a specific attachement identified by a key CVBufferRemoveAllAttachments removes all attachments of a buffer and decrements their retain counts.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    #[doc(alias = "CVBufferRemoveAllAttachments")]
    #[inline]
    pub fn remove_all_attachments(&self) {
        extern "C-unwind" {
            fn CVBufferRemoveAllAttachments(buffer: &CVBuffer);
        }
        unsafe { CVBufferRemoveAllAttachments(self) }
    }

    /// Returns all attachments of a CVBuffer object
    ///
    /// CVBufferGetAttachments is a convenience call that returns all attachments with their corresponding keys in a CFDictionary.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Returns: A CFDictionary with all buffer attachments identified by there keys. If no attachment is present, the dictionary is empty.  Returns NULL
    /// for invalid attachment mode.
    #[doc(alias = "CVBufferGetAttachments")]
    #[deprecated]
    #[inline]
    pub fn get_attachments(
        &self,
        attachment_mode: CVAttachmentMode,
    ) -> Option<CFRetained<CFDictionary>> {
        extern "C-unwind" {
            fn CVBufferGetAttachments(
                buffer: &CVBuffer,
                attachment_mode: CVAttachmentMode,
            ) -> Option<NonNull<CFDictionary>>;
        }
        let ret = unsafe { CVBufferGetAttachments(self, attachment_mode) };
        ret.map(|ret| unsafe { CFRetained::retain(ret) })
    }

    /// Sets a set of attachments for a CVBuffer
    ///
    /// 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.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// # Safety
    ///
    /// `the_attachments` generics must be of the correct type.
    #[doc(alias = "CVBufferSetAttachments")]
    #[inline]
    pub unsafe fn set_attachments(
        &self,
        the_attachments: &CFDictionary,
        attachment_mode: CVAttachmentMode,
    ) {
        extern "C-unwind" {
            fn CVBufferSetAttachments(
                buffer: &CVBuffer,
                the_attachments: &CFDictionary,
                attachment_mode: CVAttachmentMode,
            );
        }
        unsafe { CVBufferSetAttachments(self, the_attachments, attachment_mode) }
    }

    /// Copy all propagatable attachments from one buffer to another.
    ///
    /// CVBufferPropagateAttachments is a convenience call that copies all attachments with a mode of kCVAttachmentMode_ShouldPropagate from one
    /// buffer to another.
    ///
    /// Parameter `sourceBuffer`: CVBuffer to copy attachments from.
    ///
    /// Parameter `destinationBuffer`: CVBuffer to copy attachments to.
    #[doc(alias = "CVBufferPropagateAttachments")]
    #[inline]
    pub fn propagate_attachments(&self, destination_buffer: &CVBuffer) {
        extern "C-unwind" {
            fn CVBufferPropagateAttachments(
                source_buffer: &CVBuffer,
                destination_buffer: &CVBuffer,
            );
        }
        unsafe { CVBufferPropagateAttachments(self, destination_buffer) }
    }

    /// Returns a copy of all attachments of a CVBuffer object. It is the caller’s responsibility to release the returned dictionary.
    ///
    /// CVBufferCopyAttachments is a convenience call that returns a copy of all attachments with their corresponding keys in a CFDictionary.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Returns: A CFDictionary with all buffer attachments identified by their keys. If no attachment is present or invalid attachment mode,   returns NULL
    #[doc(alias = "CVBufferCopyAttachments")]
    #[inline]
    pub fn attachments(
        &self,
        attachment_mode: CVAttachmentMode,
    ) -> Option<CFRetained<CFDictionary>> {
        extern "C-unwind" {
            fn CVBufferCopyAttachments(
                buffer: &CVBuffer,
                attachment_mode: CVAttachmentMode,
            ) -> Option<NonNull<CFDictionary>>;
        }
        let ret = unsafe { CVBufferCopyAttachments(self, attachment_mode) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Returns a retained specific attachment of a CVBuffer object. It is the caller’s responsibility to release the returned value.
    ///
    /// You can attach any CF object to a CVBuffer object to store additional information. CVBufferCopyAttachment retrieves a retained attachment identified by a key.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
    ///
    /// Parameter `attachmentMode`: Returns the mode of the attachment, if desired.  May be NULL.
    ///
    /// Returns: If found the attachment object, return the value; otherwize, return NULL.
    ///
    /// # Safety
    ///
    /// `attachment_mode` must be a valid pointer or null.
    #[doc(alias = "CVBufferCopyAttachment")]
    #[inline]
    pub unsafe fn attachment(
        &self,
        key: &CFString,
        attachment_mode: *mut CVAttachmentMode,
    ) -> Option<CFRetained<CFType>> {
        extern "C-unwind" {
            fn CVBufferCopyAttachment(
                buffer: &CVBuffer,
                key: &CFString,
                attachment_mode: *mut CVAttachmentMode,
            ) -> Option<NonNull<CFType>>;
        }
        let ret = unsafe { CVBufferCopyAttachment(self, key, attachment_mode) };
        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
    }

    /// Returns true if an attachment with the passed key is present on a CVBuffer object.
    ///
    /// Parameter `buffer`: Target CVBuffer object.
    ///
    /// Parameter `key`: Key in form of a CFString identifying the desired attachment.
    ///
    /// Returns: True if an attachment with this key is present, otherwise false.
    #[doc(alias = "CVBufferHasAttachment")]
    #[inline]
    pub fn has_attachment(&self, key: &CFString) -> bool {
        extern "C-unwind" {
            fn CVBufferHasAttachment(buffer: &CVBuffer, key: &CFString) -> Boolean;
        }
        let ret = unsafe { CVBufferHasAttachment(self, key) };
        ret != 0
    }
}

extern "C-unwind" {
    #[deprecated = "renamed to `CVBuffer::set_attachment`"]
    pub fn CVBufferSetAttachment(
        buffer: &CVBuffer,
        key: &CFString,
        value: &CFType,
        attachment_mode: CVAttachmentMode,
    );
}

#[deprecated = "renamed to `CVBuffer::get_attachment`"]
#[inline]
pub unsafe extern "C-unwind" fn CVBufferGetAttachment(
    buffer: &CVBuffer,
    key: &CFString,
    attachment_mode: *mut CVAttachmentMode,
) -> Option<CFRetained<CFType>> {
    extern "C-unwind" {
        fn CVBufferGetAttachment(
            buffer: &CVBuffer,
            key: &CFString,
            attachment_mode: *mut CVAttachmentMode,
        ) -> Option<NonNull<CFType>>;
    }
    let ret = unsafe { CVBufferGetAttachment(buffer, key, attachment_mode) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

#[deprecated = "renamed to `CVBuffer::remove_attachment`"]
#[inline]
pub extern "C-unwind" fn CVBufferRemoveAttachment(buffer: &CVBuffer, key: &CFString) {
    extern "C-unwind" {
        fn CVBufferRemoveAttachment(buffer: &CVBuffer, key: &CFString);
    }
    unsafe { CVBufferRemoveAttachment(buffer, key) }
}

#[deprecated = "renamed to `CVBuffer::remove_all_attachments`"]
#[inline]
pub extern "C-unwind" fn CVBufferRemoveAllAttachments(buffer: &CVBuffer) {
    extern "C-unwind" {
        fn CVBufferRemoveAllAttachments(buffer: &CVBuffer);
    }
    unsafe { CVBufferRemoveAllAttachments(buffer) }
}

#[deprecated = "renamed to `CVBuffer::get_attachments`"]
#[inline]
pub extern "C-unwind" fn CVBufferGetAttachments(
    buffer: &CVBuffer,
    attachment_mode: CVAttachmentMode,
) -> Option<CFRetained<CFDictionary>> {
    extern "C-unwind" {
        fn CVBufferGetAttachments(
            buffer: &CVBuffer,
            attachment_mode: CVAttachmentMode,
        ) -> Option<NonNull<CFDictionary>>;
    }
    let ret = unsafe { CVBufferGetAttachments(buffer, attachment_mode) };
    ret.map(|ret| unsafe { CFRetained::retain(ret) })
}

extern "C-unwind" {
    #[deprecated = "renamed to `CVBuffer::set_attachments`"]
    pub fn CVBufferSetAttachments(
        buffer: &CVBuffer,
        the_attachments: &CFDictionary,
        attachment_mode: CVAttachmentMode,
    );
}

#[deprecated = "renamed to `CVBuffer::propagate_attachments`"]
#[inline]
pub extern "C-unwind" fn CVBufferPropagateAttachments(
    source_buffer: &CVBuffer,
    destination_buffer: &CVBuffer,
) {
    extern "C-unwind" {
        fn CVBufferPropagateAttachments(source_buffer: &CVBuffer, destination_buffer: &CVBuffer);
    }
    unsafe { CVBufferPropagateAttachments(source_buffer, destination_buffer) }
}

#[deprecated = "renamed to `CVBuffer::attachments`"]
#[inline]
pub extern "C-unwind" fn CVBufferCopyAttachments(
    buffer: &CVBuffer,
    attachment_mode: CVAttachmentMode,
) -> Option<CFRetained<CFDictionary>> {
    extern "C-unwind" {
        fn CVBufferCopyAttachments(
            buffer: &CVBuffer,
            attachment_mode: CVAttachmentMode,
        ) -> Option<NonNull<CFDictionary>>;
    }
    let ret = unsafe { CVBufferCopyAttachments(buffer, attachment_mode) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `CVBuffer::attachment`"]
#[inline]
pub unsafe extern "C-unwind" fn CVBufferCopyAttachment(
    buffer: &CVBuffer,
    key: &CFString,
    attachment_mode: *mut CVAttachmentMode,
) -> Option<CFRetained<CFType>> {
    extern "C-unwind" {
        fn CVBufferCopyAttachment(
            buffer: &CVBuffer,
            key: &CFString,
            attachment_mode: *mut CVAttachmentMode,
        ) -> Option<NonNull<CFType>>;
    }
    let ret = unsafe { CVBufferCopyAttachment(buffer, key, attachment_mode) };
    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
}

#[deprecated = "renamed to `CVBuffer::has_attachment`"]
#[inline]
pub extern "C-unwind" fn CVBufferHasAttachment(buffer: &CVBuffer, key: &CFString) -> bool {
    extern "C-unwind" {
        fn CVBufferHasAttachment(buffer: &CVBuffer, key: &CFString) -> Boolean;
    }
    let ret = unsafe { CVBufferHasAttachment(buffer, key) };
    ret != 0
}