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