objc2_video_toolbox/generated/
VTDecompressionSession.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#[cfg(feature = "objc2-core-media")]
11use objc2_core_media::*;
12#[cfg(feature = "objc2-core-video")]
13use objc2_core_video::*;
14
15use crate::*;
16
17/// A reference to a Video Toolbox Decompression Session.
18///
19/// A decompression session supports the decompression of a sequence of video frames.
20/// The session reference is a reference-counted CF object.
21/// To create a decompression session, call VTDecompressionSessionCreate;
22/// then you can optionally configure the session using VTSessionSetProperty;
23/// then to decode frames, call VTDecompressionSessionDecodeFrame.
24/// When you are done with the session, you should call VTDecompressionSessionInvalidate
25/// to tear it down and CFRelease to release your object reference.
26///
27/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtdecompressionsession?language=objc)
28#[doc(alias = "VTDecompressionSessionRef")]
29#[repr(C)]
30pub struct VTDecompressionSession {
31    inner: [u8; 0],
32    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
33}
34
35cf_type!(
36    unsafe impl VTDecompressionSession {}
37);
38#[cfg(feature = "objc2")]
39cf_objc2_type!(
40    unsafe impl RefEncode<"OpaqueVTDecompressionSession"> for VTDecompressionSession {}
41);
42
43/// Prototype for callback invoked when frame decompression is complete.
44///
45/// When you create a decompression session, you pass in a callback function to be called
46/// for decompressed frames.  This function will not necessarily be called in display order.
47///
48/// Parameter `decompressionOutputRefCon`: The callback's reference value, copied from the decompressionOutputRefCon field of the
49/// VTDecompressionOutputCallbackRecord structure.
50///
51/// Parameter `sourceFrameRefCon`: The frame's reference value, copied from the sourceFrameRefCon argument to
52/// VTDecompressionSessionDecodeFrame.
53///
54/// Parameter `status`: noErr if decompression was successful; an error code if decompression was not successful.
55///
56/// Parameter `infoFlags`: Contains information about the decode operation.
57/// The kVTDecodeInfo_Asynchronous bit may be set if the decode ran asynchronously.
58/// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped.
59/// If the kVTDecodeInfo_ImageBufferModifiable bit is set, it is safe for the client to modify the imageBuffer.
60///
61/// Parameter `imageBuffer`: Contains the decompressed frame, if decompression was successful; otherwise, NULL.
62/// IMPORTANT: The video decompressor may still be referencing the imageBuffer returned in this
63/// callback if the kVTDecodeInfo_ImageBufferModifiable flag is not set.  Unless this flag
64/// is set, it is not safe to modify the returned imageBuffer.
65///
66/// Parameter `presentationTimeStamp`: The frame's presentation timestamp, which will be determined by calling
67/// CMSampleBufferGetOutputPresentationTimeStamp; kCMTimeInvalid if not available.
68///
69/// Parameter `presentationDuration`: The frame's presentation duration, which will be determined by calling
70/// CMSampleBufferGetOutputDuration; kCMTimeInvalid if not available.
71///
72/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtdecompressionoutputcallback?language=objc)
73#[cfg(all(
74    feature = "VTErrors",
75    feature = "objc2-core-media",
76    feature = "objc2-core-video"
77))]
78pub type VTDecompressionOutputCallback = Option<
79    unsafe extern "C-unwind" fn(
80        *mut c_void,
81        *mut c_void,
82        OSStatus,
83        VTDecodeInfoFlags,
84        *mut CVImageBuffer,
85        CMTime,
86        CMTime,
87    ),
88>;
89
90/// [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtdecompressionoutputcallbackrecord?language=objc)
91#[cfg(all(
92    feature = "VTErrors",
93    feature = "objc2-core-media",
94    feature = "objc2-core-video"
95))]
96#[repr(C, packed(4))]
97#[allow(unpredictable_function_pointer_comparisons)]
98#[derive(Clone, Copy, Debug, PartialEq)]
99pub struct VTDecompressionOutputCallbackRecord {
100    pub decompressionOutputCallback: VTDecompressionOutputCallback,
101    pub decompressionOutputRefCon: *mut c_void,
102}
103
104#[cfg(all(
105    feature = "VTErrors",
106    feature = "objc2",
107    feature = "objc2-core-media",
108    feature = "objc2-core-video"
109))]
110unsafe impl Encode for VTDecompressionOutputCallbackRecord {
111    const ENCODING: Encoding = Encoding::Struct(
112        "VTDecompressionOutputCallbackRecord",
113        &[
114            <VTDecompressionOutputCallback>::ENCODING,
115            <*mut c_void>::ENCODING,
116        ],
117    );
118}
119
120#[cfg(all(
121    feature = "VTErrors",
122    feature = "objc2",
123    feature = "objc2-core-media",
124    feature = "objc2-core-video"
125))]
126unsafe impl RefEncode for VTDecompressionOutputCallbackRecord {
127    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
128}
129
130impl VTDecompressionSession {
131    /// Creates a session for decompressing video frames.
132    ///
133    /// Decompressed frames will be emitted through calls to outputCallback.
134    ///
135    /// Parameter `allocator`: An allocator for the session.  Pass NULL to use the default allocator.
136    ///
137    /// Parameter `videoFormatDescription`: Describes the source video frames.
138    ///
139    /// Parameter `videoDecoderSpecification`: Specifies a particular video decoder that must be used.
140    /// Pass NULL to let the video toolbox choose a decoder.
141    ///
142    /// Parameter `destinationImageBufferAttributes`: Describes requirements for emitted pixel buffers.
143    /// Pass NULL to set no requirements.
144    ///
145    /// Parameter `outputCallback`: The callback to be called with decompressed frames.
146    /// Pass NULL if and only if you will be calling VTDecompressionSessionDecodeFrameWithOutputHandler for decoding frames.
147    ///
148    /// Parameter `decompressionSessionOut`: Points to a variable to receive the new decompression session.
149    ///
150    /// # Safety
151    ///
152    /// - `video_decoder_specification` generics must be of the correct type.
153    /// - `destination_image_buffer_attributes` generics must be of the correct type.
154    /// - `output_callback` must be a valid pointer or null.
155    /// - `decompression_session_out` must be a valid pointer.
156    #[doc(alias = "VTDecompressionSessionCreate")]
157    #[cfg(all(
158        feature = "VTErrors",
159        feature = "objc2-core-media",
160        feature = "objc2-core-video"
161    ))]
162    #[inline]
163    pub unsafe fn create(
164        allocator: Option<&CFAllocator>,
165        video_format_description: &CMVideoFormatDescription,
166        video_decoder_specification: Option<&CFDictionary>,
167        destination_image_buffer_attributes: Option<&CFDictionary>,
168        output_callback: *const VTDecompressionOutputCallbackRecord,
169        decompression_session_out: NonNull<*mut VTDecompressionSession>,
170    ) -> OSStatus {
171        extern "C-unwind" {
172            fn VTDecompressionSessionCreate(
173                allocator: Option<&CFAllocator>,
174                video_format_description: &CMVideoFormatDescription,
175                video_decoder_specification: Option<&CFDictionary>,
176                destination_image_buffer_attributes: Option<&CFDictionary>,
177                output_callback: *const VTDecompressionOutputCallbackRecord,
178                decompression_session_out: NonNull<*mut VTDecompressionSession>,
179            ) -> OSStatus;
180        }
181        unsafe {
182            VTDecompressionSessionCreate(
183                allocator,
184                video_format_description,
185                video_decoder_specification,
186                destination_image_buffer_attributes,
187                output_callback,
188                decompression_session_out,
189            )
190        }
191    }
192
193    /// Tears down a decompression session.
194    ///
195    /// When you are done with a decompression session you created, call VTDecompressionSessionInvalidate
196    /// to tear it down and then CFRelease to release your object reference.
197    /// When a decompression session's retain count reaches zero, it is automatically invalidated, but
198    /// since sessions may be retained by multiple parties, it can be hard to predict when this will happen.
199    /// Calling VTDecompressionSessionInvalidate ensures a deterministic, orderly teardown.
200    #[doc(alias = "VTDecompressionSessionInvalidate")]
201    #[inline]
202    pub unsafe fn invalidate(&self) {
203        extern "C-unwind" {
204            fn VTDecompressionSessionInvalidate(session: &VTDecompressionSession);
205        }
206        unsafe { VTDecompressionSessionInvalidate(self) }
207    }
208}
209
210unsafe impl ConcreteType for VTDecompressionSession {
211    /// Returns the CFTypeID for decompression sessions.
212    #[doc(alias = "VTDecompressionSessionGetTypeID")]
213    #[inline]
214    fn type_id() -> CFTypeID {
215        extern "C-unwind" {
216            fn VTDecompressionSessionGetTypeID() -> CFTypeID;
217        }
218        unsafe { VTDecompressionSessionGetTypeID() }
219    }
220}
221
222impl VTDecompressionSession {
223    /// Decompresses a video frame.
224    ///
225    /// If an error is returned from this function, there will be no callback.  Otherwise
226    /// the callback provided during VTDecompressionSessionCreate will be called.
227    ///
228    /// Parameter `session`: The decompression session.
229    ///
230    /// Parameter `sampleBuffer`: A CMSampleBuffer containing one or more video frames.
231    ///
232    /// Parameter `decodeFlags`: A bitfield of directives to the decompression session and decoder.
233    /// The kVTDecodeFrame_EnableAsynchronousDecompression bit indicates whether the video decoder
234    /// may decompress the frame asynchronously.
235    /// The kVTDecodeFrame_EnableTemporalProcessing bit indicates whether the decoder may delay calls to the output callback
236    /// so as to enable processing in temporal (display) order.
237    /// If both flags are clear, the decompression shall complete and your output callback function will be called
238    /// before VTDecompressionSessionDecodeFrame returns.
239    /// If either flag is set, VTDecompressionSessionDecodeFrame may return before the output callback function is called.
240    ///
241    /// Parameter `sourceFrameRefCon`: Your reference value for the frame.
242    /// Note that if sampleBuffer contains multiple frames, the output callback function will be called
243    /// multiple times with this sourceFrameRefCon.
244    ///
245    /// Parameter `infoFlagsOut`: Points to a VTDecodeInfoFlags to receive information about the decode operation.
246    /// The kVTDecodeInfo_Asynchronous bit may be set if the decode is (or was) running
247    /// asynchronously.
248    /// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
249    /// Pass NULL if you do not want to receive this information.
250    ///
251    /// # Safety
252    ///
253    /// - `source_frame_ref_con` must be a valid pointer or null.
254    /// - `info_flags_out` must be a valid pointer or null.
255    #[doc(alias = "VTDecompressionSessionDecodeFrame")]
256    #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
257    #[inline]
258    pub unsafe fn decode_frame(
259        &self,
260        sample_buffer: &CMSampleBuffer,
261        decode_flags: VTDecodeFrameFlags,
262        source_frame_ref_con: *mut c_void,
263        info_flags_out: *mut VTDecodeInfoFlags,
264    ) -> OSStatus {
265        extern "C-unwind" {
266            fn VTDecompressionSessionDecodeFrame(
267                session: &VTDecompressionSession,
268                sample_buffer: &CMSampleBuffer,
269                decode_flags: VTDecodeFrameFlags,
270                source_frame_ref_con: *mut c_void,
271                info_flags_out: *mut VTDecodeInfoFlags,
272            ) -> OSStatus;
273        }
274        unsafe {
275            VTDecompressionSessionDecodeFrame(
276                self,
277                sample_buffer,
278                decode_flags,
279                source_frame_ref_con,
280                info_flags_out,
281            )
282        }
283    }
284}
285
286/// Prototype for block invoked when frame decompression is complete.
287///
288/// When you decode a frame, you pass in a callback block to be called
289/// for that decompressed frame.  This block will not necessarily be called in display order.
290/// If the VTDecompressionSessionDecodeFrameWithOutputHandler call returns an error, the block
291/// will not be called.
292///
293/// Parameter `status`: noErr if decompression was successful; an error code if decompression was not successful.
294///
295/// Parameter `infoFlags`: Contains information about the decode operation.
296/// The kVTDecodeInfo_Asynchronous bit may be set if the decode ran asynchronously.
297/// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped.
298/// If the kVTDecodeInfo_ImageBufferModifiable bit is set, it is safe for the client to modify the imageBuffer.
299///
300/// Parameter `imageBuffer`: Contains the decompressed frame, if decompression was successful; otherwise, NULL.
301/// IMPORTANT: The video decompressor may still be referencing the imageBuffer returned in this
302/// callback if the kVTDecodeInfo_ImageBufferModifiable flag is not set.  Unless this flag
303/// is set, it is not safe to modify the returned imageBuffer.
304///
305/// Parameter `presentationTimeStamp`: The frame's presentation timestamp; kCMTimeInvalid if not available.
306///
307/// Parameter `presentationDuration`: The frame's presentation duration; kCMTimeInvalid if not available.
308///
309/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtdecompressionoutputhandler?language=objc)
310#[cfg(all(
311    feature = "VTErrors",
312    feature = "block2",
313    feature = "objc2-core-media",
314    feature = "objc2-core-video"
315))]
316pub type VTDecompressionOutputHandler =
317    *mut block2::DynBlock<dyn Fn(OSStatus, VTDecodeInfoFlags, *mut CVImageBuffer, CMTime, CMTime)>;
318
319impl VTDecompressionSession {
320    /// Decompresses a video frame.
321    ///
322    /// Cannot be called with a session created with a VTDecompressionOutputCallbackRecord.
323    /// If the VTDecompressionSessionDecodeFrameWithOutputHandler call returns an error, the block
324    /// will not be called.
325    ///
326    /// Parameter `session`: The decompression session.
327    ///
328    /// Parameter `sampleBuffer`: A CMSampleBuffer containing one or more video frames.
329    ///
330    /// Parameter `decodeFlags`: A bitfield of directives to the decompression session and decoder.
331    /// The kVTDecodeFrame_EnableAsynchronousDecompression bit indicates whether the video decoder
332    /// may decompress the frame asynchronously.
333    /// The kVTDecodeFrame_EnableTemporalProcessing bit indicates whether the decoder may delay calls to the output callback
334    /// so as to enable processing in temporal (display) order.
335    /// If both flags are clear, the decompression shall complete and your output callback function will be called
336    /// before VTDecompressionSessionDecodeFrame returns.
337    /// If either flag is set, VTDecompressionSessionDecodeFrame may return before the output callback function is called.
338    ///
339    /// Parameter `infoFlagsOut`: Points to a VTDecodeInfoFlags to receive information about the decode operation.
340    /// The kVTDecodeInfo_Asynchronous bit may be set if the decode is (or was) running
341    /// asynchronously.
342    /// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
343    /// Pass NULL if you do not want to receive this information.
344    ///
345    /// Parameter `outputHandler`: The block to be called when decoding the frame is completed.  If the VTDecompressionSessionDecodeFrameWithOutputHandler
346    /// call returns an error, the block will not be called.
347    ///
348    /// # Safety
349    ///
350    /// - `info_flags_out` must be a valid pointer or null.
351    /// - `output_handler` must be a valid pointer.
352    #[doc(alias = "VTDecompressionSessionDecodeFrameWithOutputHandler")]
353    #[cfg(all(
354        feature = "VTErrors",
355        feature = "block2",
356        feature = "objc2-core-media",
357        feature = "objc2-core-video"
358    ))]
359    #[inline]
360    pub unsafe fn decode_frame_with_output_handler(
361        &self,
362        sample_buffer: &CMSampleBuffer,
363        decode_flags: VTDecodeFrameFlags,
364        info_flags_out: *mut VTDecodeInfoFlags,
365        output_handler: VTDecompressionOutputHandler,
366    ) -> OSStatus {
367        extern "C-unwind" {
368            fn VTDecompressionSessionDecodeFrameWithOutputHandler(
369                session: &VTDecompressionSession,
370                sample_buffer: &CMSampleBuffer,
371                decode_flags: VTDecodeFrameFlags,
372                info_flags_out: *mut VTDecodeInfoFlags,
373                output_handler: VTDecompressionOutputHandler,
374            ) -> OSStatus;
375        }
376        unsafe {
377            VTDecompressionSessionDecodeFrameWithOutputHandler(
378                self,
379                sample_buffer,
380                decode_flags,
381                info_flags_out,
382                output_handler,
383            )
384        }
385    }
386
387    /// Directs the decompression session to emit all delayed frames.
388    ///
389    /// By default, the decompression session may not delay frames indefinitely;
390    /// frames may only be indefinitely delayed if the client opts in via
391    /// kVTDecodeFrame_EnableTemporalProcessing.
392    /// IMPORTANT NOTE: This function may return before all delayed frames are emitted.
393    /// To wait for them, call VTDecompressionSessionWaitForAsynchronousFrames instead.
394    #[doc(alias = "VTDecompressionSessionFinishDelayedFrames")]
395    #[inline]
396    pub unsafe fn finish_delayed_frames(&self) -> OSStatus {
397        extern "C-unwind" {
398            fn VTDecompressionSessionFinishDelayedFrames(
399                session: &VTDecompressionSession,
400            ) -> OSStatus;
401        }
402        unsafe { VTDecompressionSessionFinishDelayedFrames(self) }
403    }
404
405    /// Indicates whether the session can decode frames with the given format description.
406    ///
407    /// Some video decoders are able to accommodate minor changes in format without needing to be
408    /// completely reset in a new session.  This function can be used to test whether a format change
409    /// is sufficiently minor.
410    #[doc(alias = "VTDecompressionSessionCanAcceptFormatDescription")]
411    #[cfg(feature = "objc2-core-media")]
412    #[inline]
413    pub unsafe fn can_accept_format_description(
414        &self,
415        new_format_desc: &CMFormatDescription,
416    ) -> bool {
417        extern "C-unwind" {
418            fn VTDecompressionSessionCanAcceptFormatDescription(
419                session: &VTDecompressionSession,
420                new_format_desc: &CMFormatDescription,
421            ) -> Boolean;
422        }
423        let ret =
424            unsafe { VTDecompressionSessionCanAcceptFormatDescription(self, new_format_desc) };
425        ret != 0
426    }
427
428    /// Waits for any and all outstanding asynchronous and delayed frames to complete, then returns.
429    ///
430    /// This function automatically calls VTDecompressionSessionFinishDelayedFrames,
431    /// so clients don't have to call both.
432    #[doc(alias = "VTDecompressionSessionWaitForAsynchronousFrames")]
433    #[inline]
434    pub unsafe fn wait_for_asynchronous_frames(&self) -> OSStatus {
435        extern "C-unwind" {
436            fn VTDecompressionSessionWaitForAsynchronousFrames(
437                session: &VTDecompressionSession,
438            ) -> OSStatus;
439        }
440        unsafe { VTDecompressionSessionWaitForAsynchronousFrames(self) }
441    }
442
443    /// Copies a black pixel buffer from the decompression session.
444    ///
445    /// The pixel buffer is in the same format that the session is decompressing to.
446    ///
447    /// Parameter `session`: The decompression session.
448    ///
449    /// Parameter `pixelBufferOut`: Points to a variable to receive the copied pixel buffer.
450    ///
451    /// # Safety
452    ///
453    /// `pixel_buffer_out` must be a valid pointer.
454    #[doc(alias = "VTDecompressionSessionCopyBlackPixelBuffer")]
455    #[cfg(feature = "objc2-core-video")]
456    #[inline]
457    pub unsafe fn copy_black_pixel_buffer(
458        &self,
459        pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
460    ) -> OSStatus {
461        extern "C-unwind" {
462            fn VTDecompressionSessionCopyBlackPixelBuffer(
463                session: &VTDecompressionSession,
464                pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
465            ) -> OSStatus;
466        }
467        unsafe { VTDecompressionSessionCopyBlackPixelBuffer(self, pixel_buffer_out) }
468    }
469}
470
471/// Indicates whether the current system supports hardware decode for a given codec
472///
473/// This routine reports whether the current system supports hardware decode.  Using
474/// this information, clients can make informed decisions regarding remote assets to load,
475/// favoring alternate encodings when hardware decode is not supported.
476/// This call returning true does not guarantee that hardware decode resources will be
477/// available at all times.
478#[cfg(feature = "objc2-core-media")]
479#[inline]
480pub unsafe extern "C-unwind" fn VTIsHardwareDecodeSupported(codec_type: CMVideoCodecType) -> bool {
481    extern "C-unwind" {
482        fn VTIsHardwareDecodeSupported(codec_type: CMVideoCodecType) -> Boolean;
483    }
484    let ret = unsafe { VTIsHardwareDecodeSupported(codec_type) };
485    ret != 0
486}
487
488/// Indicates whether the current system supports stereo MV-HEVC decode.
489///
490/// This call returning true does not guarantee that decode resources will be available at all times.
491#[inline]
492pub unsafe extern "C-unwind" fn VTIsStereoMVHEVCDecodeSupported() -> bool {
493    extern "C-unwind" {
494        fn VTIsStereoMVHEVCDecodeSupported() -> Boolean;
495    }
496    let ret = unsafe { VTIsStereoMVHEVCDecodeSupported() };
497    ret != 0
498}
499
500/// Prototype for callback invoked when multi-image frame decompression is complete.
501///
502/// When you create a decompression session, you pass in a callback function to be called
503/// for decompressed frames.  This function will not necessarily be called in display order.
504///
505/// Parameter `decompressionOutputMultiImageRefCon`: The callback's reference value, copied from the outputMultiImageRefcon passed to
506/// VTDecompressionSessionSetMultiImageCallback.
507///
508/// Parameter `sourceFrameRefCon`: The frame's reference value, copied from the sourceFrameRefCon argument to
509/// VTDecompressionSessionDecodeFrame.
510///
511/// Parameter `status`: noErr if decompression was successful; an error code if decompression was not successful.
512///
513/// Parameter `infoFlags`: Contains information about the decode operation.
514/// The kVTDecodeInfo_Asynchronous bit may be set if the decode ran asynchronously.
515/// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped.
516/// If the kVTDecodeInfo_ImageBufferModifiable bit is set, it is safe for the client to modify the imageBuffer.
517///
518/// Parameter `taggedBufferGroup`: Contains the decompressed frame's multiple images, if decompression was successful; otherwise, NULL.
519/// IMPORTANT: The video decompressor may still be referencing the pixelBuffers returned in this
520/// callback if the kVTDecodeInfo_ImageBufferModifiable flag is not set.  Unless this flag
521/// is set, it is not safe to modify the returned pixelBuffers.
522///
523/// Parameter `presentationTimeStamp`: The frame's presentation timestamp, which will be determined by calling
524/// CMSampleBufferGetOutputPresentationTimeStamp; kCMTimeInvalid if not available.
525///
526/// Parameter `presentationDuration`: The frame's presentation duration, which will be determined by calling
527/// CMSampleBufferGetOutputDuration; kCMTimeInvalid if not available.
528///
529/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtdecompressionoutputmultiimagecallback?language=objc)
530#[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
531pub type VTDecompressionOutputMultiImageCallback = Option<
532    unsafe extern "C-unwind" fn(
533        *mut c_void,
534        *mut c_void,
535        OSStatus,
536        VTDecodeInfoFlags,
537        *mut CMTaggedBufferGroup,
538        CMTime,
539        CMTime,
540    ),
541>;
542
543impl VTDecompressionSession {
544    /// Provides a callback capable of receiving multiple images for individual DecodeFrame requests.
545    ///
546    /// The outputMultiImageCallback will be used when the video decoder outputs CMTaggedBufferGroups.
547    /// When installed, outputMultiImageCallback will also be used when DecodeFrame operations fail and return a nonzero status.
548    /// The original single-image callback will only be used in the case where the video decoder outputs a CVImageBuffer instead of a CMTaggedBufferGroup.
549    /// Terminology note: in multi-image decompression, a single video sample (from one CMSampleBuffer) contains a single frame (with one PTS) that is decoded to produce multiple images.
550    ///
551    /// # Safety
552    ///
553    /// - `output_multi_image_callback` must be implemented correctly.
554    /// - `output_multi_image_refcon` must be a valid pointer or null.
555    #[doc(alias = "VTDecompressionSessionSetMultiImageCallback")]
556    #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
557    #[inline]
558    pub unsafe fn set_multi_image_callback(
559        &self,
560        output_multi_image_callback: VTDecompressionOutputMultiImageCallback,
561        output_multi_image_refcon: *mut c_void,
562    ) -> OSStatus {
563        extern "C-unwind" {
564            fn VTDecompressionSessionSetMultiImageCallback(
565                decompression_session: &VTDecompressionSession,
566                output_multi_image_callback: VTDecompressionOutputMultiImageCallback,
567                output_multi_image_refcon: *mut c_void,
568            ) -> OSStatus;
569        }
570        unsafe {
571            VTDecompressionSessionSetMultiImageCallback(
572                self,
573                output_multi_image_callback,
574                output_multi_image_refcon,
575            )
576        }
577    }
578}
579
580/// Prototype for block invoked when frame decompression is complete.
581///
582/// When you decode a frame, you pass in a callback block to be called
583/// for that decompressed frame.  This block will not necessarily be called in display order.
584/// If the VTDecompressionSessionDecodeFrameWithOutputHandler call returns an error, the block
585/// will not be called.
586///
587/// Parameter `status`: noErr if decompression was successful; an error code if decompression was not successful.
588///
589/// Parameter `infoFlags`: Contains information about the decode operation.
590/// The kVTDecodeInfo_Asynchronous bit may be set if the decode ran asynchronously.
591/// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped.
592/// If the kVTDecodeInfo_ImageBufferModifiable bit is set, it is safe for the client to modify the imageBuffer.
593///
594/// Parameter `imageBuffer`: Contains the decompressed frame, if decompression was successful and the CMSampleBuffer contained
595/// a single image frame; otherwise, NULL.
596/// IMPORTANT: The video decompressor may still be referencing the imageBuffer returned in this
597/// callback if the kVTDecodeInfo_ImageBufferModifiable flag is not set.  Unless this flag
598/// is set, it is not safe to modify the returned imageBuffer.
599///
600/// Parameter `taggedBufferGroup`: Contains the decompressed frame's multiple images, if decompression was successful and the CMSampleBuffer
601/// contained a multi-image frame; otherwise, NULL.
602/// IMPORTANT: The video decompressor may still be referencing the pixelBuffers returned in this
603/// callback if the kVTDecodeInfo_ImageBufferModifiable flag is not set.  Unless this flag
604/// is set, it is not safe to modify the returned pixelBuffers.
605///
606/// Parameter `presentationTimeStamp`: The frame's presentation timestamp; kCMTimeInvalid if not available.
607///
608/// Parameter `presentationDuration`: The frame's presentation duration; kCMTimeInvalid if not available.
609///
610/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtdecompressionmultiimagecapableoutputhandler?language=objc)
611#[cfg(all(
612    feature = "VTErrors",
613    feature = "block2",
614    feature = "objc2-core-media",
615    feature = "objc2-core-video"
616))]
617pub type VTDecompressionMultiImageCapableOutputHandler = *mut block2::DynBlock<
618    dyn Fn(
619        OSStatus,
620        VTDecodeInfoFlags,
621        *mut CVImageBuffer,
622        *mut CMTaggedBufferGroup,
623        CMTime,
624        CMTime,
625    ),
626>;
627
628impl VTDecompressionSession {
629    /// Decompresses a video frame.
630    ///
631    /// Cannot be called with a session created with a VTDecompressionOutputCallbackRecord.
632    /// If the VTDecompressionSessionDecodeFrameWithOutputHandler call returns an error, the block
633    /// will not be called.
634    ///
635    /// Parameter `session`: The decompression session.
636    ///
637    /// Parameter `sampleBuffer`: A CMSampleBuffer containing one or more video frames.
638    ///
639    /// Parameter `decodeFlags`: A bitfield of directives to the decompression session and decoder.
640    /// The kVTDecodeFrame_EnableAsynchronousDecompression bit indicates whether the video decoder
641    /// may decompress the frame asynchronously.
642    /// The kVTDecodeFrame_EnableTemporalProcessing bit indicates whether the decoder may delay calls to the output callback
643    /// so as to enable processing in temporal (display) order.
644    /// If both flags are clear, the decompression shall complete and your output callback function will be called
645    /// before VTDecompressionSessionDecodeFrame returns.
646    /// If either flag is set, VTDecompressionSessionDecodeFrame may return before the output callback function is called.
647    ///
648    /// Parameter `infoFlagsOut`: Points to a VTDecodeInfoFlags to receive information about the decode operation.
649    /// The kVTDecodeInfo_Asynchronous bit may be set if the decode is (or was) running
650    /// asynchronously.
651    /// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
652    /// Pass NULL if you do not want to receive this information.
653    ///
654    /// Parameter `multiImageCapableOutputHandler`: The block to be called when decoding the frame is completed.  If the
655    /// VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler call returns an error,
656    /// the block will not be called.
657    ///
658    /// # Safety
659    ///
660    /// - `info_flags_out` must be a valid pointer or null.
661    /// - `multi_image_capable_output_handler` must be a valid pointer.
662    #[doc(alias = "VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler")]
663    #[cfg(all(
664        feature = "VTErrors",
665        feature = "block2",
666        feature = "objc2-core-media",
667        feature = "objc2-core-video"
668    ))]
669    #[inline]
670    pub unsafe fn decode_frame_with_multi_image_capable_output_handler(
671        &self,
672        sample_buffer: &CMSampleBuffer,
673        decode_flags: VTDecodeFrameFlags,
674        info_flags_out: *mut VTDecodeInfoFlags,
675        multi_image_capable_output_handler: VTDecompressionMultiImageCapableOutputHandler,
676    ) -> OSStatus {
677        extern "C-unwind" {
678            fn VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler(
679                session: &VTDecompressionSession,
680                sample_buffer: &CMSampleBuffer,
681                decode_flags: VTDecodeFrameFlags,
682                info_flags_out: *mut VTDecodeInfoFlags,
683                multi_image_capable_output_handler: VTDecompressionMultiImageCapableOutputHandler,
684            ) -> OSStatus;
685        }
686        unsafe {
687            VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler(
688                self,
689                sample_buffer,
690                decode_flags,
691                info_flags_out,
692                multi_image_capable_output_handler,
693            )
694        }
695    }
696
697    /// Decompresses a video frame.
698    ///
699    /// If an error is returned from this function, there will be no callback.  Otherwise
700    /// the callback provided during VTDecompressionSessionCreate will be called.
701    ///
702    /// Parameter `session`: The decompression session.
703    ///
704    /// Parameter `sampleBuffer`: A CMSampleBuffer containing one or more video frames.
705    ///
706    /// Parameter `decodeFlags`: A bitfield of directives to the decompression session and decoder.
707    /// The kVTDecodeFrame_EnableAsynchronousDecompression bit indicates whether the video decoder
708    /// may decompress the frame asynchronously.
709    /// The kVTDecodeFrame_EnableTemporalProcessing bit indicates whether the decoder may delay calls to the output callback
710    /// so as to enable processing in temporal (display) order.
711    /// If both flags are clear, the decompression shall complete and your output callback function will be called
712    /// before VTDecompressionSessionDecodeFrameWithOptions returns.
713    /// If either flag is set, VTDecompressionSessionDecodeFrameWithOptions may return before the output callback function is called.
714    ///
715    /// Parameter `frameOptions`: Contains key/value pairs specifying additional options for decoding this frame.
716    /// Only keys with `kVTDecodeFrameOptionKey_` prefix should be used in this dictionary.
717    ///
718    /// Parameter `sourceFrameRefCon`: Your reference value for the frame.
719    /// Note that if sampleBuffer contains multiple frames, the output callback function will be called
720    /// multiple times with this sourceFrameRefCon.
721    ///
722    /// Parameter `infoFlagsOut`: Points to a VTDecodeInfoFlags to receive information about the decode operation.
723    /// The kVTDecodeInfo_Asynchronous bit may be set if the decode is (or was) running
724    /// asynchronously.
725    /// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
726    /// Pass NULL if you do not want to receive this information.
727    ///
728    /// # Safety
729    ///
730    /// - `frame_options` generics must be of the correct type.
731    /// - `source_frame_ref_con` must be a valid pointer or null.
732    /// - `info_flags_out` must be a valid pointer or null.
733    #[doc(alias = "VTDecompressionSessionDecodeFrameWithOptions")]
734    #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
735    #[inline]
736    pub unsafe fn decode_frame_with_options(
737        &self,
738        sample_buffer: &CMSampleBuffer,
739        decode_flags: VTDecodeFrameFlags,
740        frame_options: Option<&CFDictionary>,
741        source_frame_ref_con: *mut c_void,
742        info_flags_out: *mut VTDecodeInfoFlags,
743    ) -> OSStatus {
744        extern "C-unwind" {
745            fn VTDecompressionSessionDecodeFrameWithOptions(
746                session: &VTDecompressionSession,
747                sample_buffer: &CMSampleBuffer,
748                decode_flags: VTDecodeFrameFlags,
749                frame_options: Option<&CFDictionary>,
750                source_frame_ref_con: *mut c_void,
751                info_flags_out: *mut VTDecodeInfoFlags,
752            ) -> OSStatus;
753        }
754        unsafe {
755            VTDecompressionSessionDecodeFrameWithOptions(
756                self,
757                sample_buffer,
758                decode_flags,
759                frame_options,
760                source_frame_ref_con,
761                info_flags_out,
762            )
763        }
764    }
765
766    /// Decompresses a video frame.
767    ///
768    /// Cannot be called with a session created with a VTDecompressionOutputCallbackRecord.
769    /// If the VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler call returns an error,
770    /// the block will not be called.
771    ///
772    /// Parameter `session`: The decompression session.
773    ///
774    /// Parameter `sampleBuffer`: A CMSampleBuffer containing one or more video frames.
775    ///
776    /// Parameter `decodeFlags`: A bitfield of directives to the decompression session and decoder.
777    /// The kVTDecodeFrame_EnableAsynchronousDecompression bit indicates whether the video decoder
778    /// may decompress the frame asynchronously.
779    /// The kVTDecodeFrame_EnableTemporalProcessing bit indicates whether the decoder may delay calls to the output callback
780    /// so as to enable processing in temporal (display) order.
781    /// If both flags are clear, the decompression shall complete and your output callback function will be called
782    /// before VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler returns.
783    /// If either flag is set, VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler may return before the output
784    /// callback function is called.
785    ///
786    /// Parameter `frameOptions`: Contains key/value pairs specifying additional options for decoding this frame.
787    /// Only keys with `kVTDecodeFrameOptionKey_` prefix should be used in this dictionary.
788    ///
789    /// Parameter `infoFlagsOut`: Points to a VTDecodeInfoFlags to receive information about the decode operation.
790    /// The kVTDecodeInfo_Asynchronous bit may be set if the decode is (or was) running
791    /// asynchronously.
792    /// The kVTDecodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
793    /// Pass NULL if you do not want to receive this information.
794    ///
795    /// Parameter `outputHandler`: The block to be called when decoding the frame is completed.  If the VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler
796    /// call returns an error, the block will not be called.
797    ///
798    /// # Safety
799    ///
800    /// - `frame_options` generics must be of the correct type.
801    /// - `info_flags_out` must be a valid pointer or null.
802    /// - `output_handler` must be a valid pointer.
803    #[doc(alias = "VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler")]
804    #[cfg(all(
805        feature = "VTErrors",
806        feature = "block2",
807        feature = "objc2-core-media",
808        feature = "objc2-core-video"
809    ))]
810    #[inline]
811    pub unsafe fn decode_frame_with_options_and_output_handler(
812        &self,
813        sample_buffer: &CMSampleBuffer,
814        decode_flags: VTDecodeFrameFlags,
815        frame_options: Option<&CFDictionary>,
816        info_flags_out: *mut VTDecodeInfoFlags,
817        output_handler: VTDecompressionOutputHandler,
818    ) -> OSStatus {
819        extern "C-unwind" {
820            fn VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler(
821                session: &VTDecompressionSession,
822                sample_buffer: &CMSampleBuffer,
823                decode_flags: VTDecodeFrameFlags,
824                frame_options: Option<&CFDictionary>,
825                info_flags_out: *mut VTDecodeInfoFlags,
826                output_handler: VTDecompressionOutputHandler,
827            ) -> OSStatus;
828        }
829        unsafe {
830            VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler(
831                self,
832                sample_buffer,
833                decode_flags,
834                frame_options,
835                info_flags_out,
836                output_handler,
837            )
838        }
839    }
840}
841
842extern "C-unwind" {
843    #[cfg(all(
844        feature = "VTErrors",
845        feature = "objc2-core-media",
846        feature = "objc2-core-video"
847    ))]
848    #[deprecated = "renamed to `VTDecompressionSession::create`"]
849    pub fn VTDecompressionSessionCreate(
850        allocator: Option<&CFAllocator>,
851        video_format_description: &CMVideoFormatDescription,
852        video_decoder_specification: Option<&CFDictionary>,
853        destination_image_buffer_attributes: Option<&CFDictionary>,
854        output_callback: *const VTDecompressionOutputCallbackRecord,
855        decompression_session_out: NonNull<*mut VTDecompressionSession>,
856    ) -> OSStatus;
857}
858
859extern "C-unwind" {
860    #[deprecated = "renamed to `VTDecompressionSession::invalidate`"]
861    pub fn VTDecompressionSessionInvalidate(session: &VTDecompressionSession);
862}
863
864extern "C-unwind" {
865    #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
866    #[deprecated = "renamed to `VTDecompressionSession::decode_frame`"]
867    pub fn VTDecompressionSessionDecodeFrame(
868        session: &VTDecompressionSession,
869        sample_buffer: &CMSampleBuffer,
870        decode_flags: VTDecodeFrameFlags,
871        source_frame_ref_con: *mut c_void,
872        info_flags_out: *mut VTDecodeInfoFlags,
873    ) -> OSStatus;
874}
875
876extern "C-unwind" {
877    #[cfg(all(
878        feature = "VTErrors",
879        feature = "block2",
880        feature = "objc2-core-media",
881        feature = "objc2-core-video"
882    ))]
883    #[deprecated = "renamed to `VTDecompressionSession::decode_frame_with_output_handler`"]
884    pub fn VTDecompressionSessionDecodeFrameWithOutputHandler(
885        session: &VTDecompressionSession,
886        sample_buffer: &CMSampleBuffer,
887        decode_flags: VTDecodeFrameFlags,
888        info_flags_out: *mut VTDecodeInfoFlags,
889        output_handler: VTDecompressionOutputHandler,
890    ) -> OSStatus;
891}
892
893extern "C-unwind" {
894    #[deprecated = "renamed to `VTDecompressionSession::finish_delayed_frames`"]
895    pub fn VTDecompressionSessionFinishDelayedFrames(session: &VTDecompressionSession) -> OSStatus;
896}
897
898#[cfg(feature = "objc2-core-media")]
899#[deprecated = "renamed to `VTDecompressionSession::can_accept_format_description`"]
900#[inline]
901pub unsafe extern "C-unwind" fn VTDecompressionSessionCanAcceptFormatDescription(
902    session: &VTDecompressionSession,
903    new_format_desc: &CMFormatDescription,
904) -> bool {
905    extern "C-unwind" {
906        fn VTDecompressionSessionCanAcceptFormatDescription(
907            session: &VTDecompressionSession,
908            new_format_desc: &CMFormatDescription,
909        ) -> Boolean;
910    }
911    let ret = unsafe { VTDecompressionSessionCanAcceptFormatDescription(session, new_format_desc) };
912    ret != 0
913}
914
915extern "C-unwind" {
916    #[deprecated = "renamed to `VTDecompressionSession::wait_for_asynchronous_frames`"]
917    pub fn VTDecompressionSessionWaitForAsynchronousFrames(
918        session: &VTDecompressionSession,
919    ) -> OSStatus;
920}
921
922extern "C-unwind" {
923    #[cfg(feature = "objc2-core-video")]
924    #[deprecated = "renamed to `VTDecompressionSession::copy_black_pixel_buffer`"]
925    pub fn VTDecompressionSessionCopyBlackPixelBuffer(
926        session: &VTDecompressionSession,
927        pixel_buffer_out: NonNull<*mut CVPixelBuffer>,
928    ) -> OSStatus;
929}
930
931extern "C-unwind" {
932    #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
933    #[deprecated = "renamed to `VTDecompressionSession::set_multi_image_callback`"]
934    pub fn VTDecompressionSessionSetMultiImageCallback(
935        decompression_session: &VTDecompressionSession,
936        output_multi_image_callback: VTDecompressionOutputMultiImageCallback,
937        output_multi_image_refcon: *mut c_void,
938    ) -> OSStatus;
939}
940
941extern "C-unwind" {
942    #[cfg(all(
943        feature = "VTErrors",
944        feature = "block2",
945        feature = "objc2-core-media",
946        feature = "objc2-core-video"
947    ))]
948    #[deprecated = "renamed to `VTDecompressionSession::decode_frame_with_multi_image_capable_output_handler`"]
949    pub fn VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler(
950        session: &VTDecompressionSession,
951        sample_buffer: &CMSampleBuffer,
952        decode_flags: VTDecodeFrameFlags,
953        info_flags_out: *mut VTDecodeInfoFlags,
954        multi_image_capable_output_handler: VTDecompressionMultiImageCapableOutputHandler,
955    ) -> OSStatus;
956}
957
958extern "C-unwind" {
959    #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
960    #[deprecated = "renamed to `VTDecompressionSession::decode_frame_with_options`"]
961    pub fn VTDecompressionSessionDecodeFrameWithOptions(
962        session: &VTDecompressionSession,
963        sample_buffer: &CMSampleBuffer,
964        decode_flags: VTDecodeFrameFlags,
965        frame_options: Option<&CFDictionary>,
966        source_frame_ref_con: *mut c_void,
967        info_flags_out: *mut VTDecodeInfoFlags,
968    ) -> OSStatus;
969}
970
971extern "C-unwind" {
972    #[cfg(all(
973        feature = "VTErrors",
974        feature = "block2",
975        feature = "objc2-core-media",
976        feature = "objc2-core-video"
977    ))]
978    #[deprecated = "renamed to `VTDecompressionSession::decode_frame_with_options_and_output_handler`"]
979    pub fn VTDecompressionSessionDecodeFrameWithOptionsAndOutputHandler(
980        session: &VTDecompressionSession,
981        sample_buffer: &CMSampleBuffer,
982        decode_flags: VTDecodeFrameFlags,
983        frame_options: Option<&CFDictionary>,
984        info_flags_out: *mut VTDecodeInfoFlags,
985        output_handler: VTDecompressionOutputHandler,
986    ) -> OSStatus;
987}