objc2_video_toolbox/generated/VTCompressionSession.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 Compression Session.
18///
19/// A compression session supports the compression of a sequence of video frames.
20/// The session reference is a reference-counted CF object.
21/// To create a compression session, call VTCompressionSessionCreate;
22/// then you can optionally configure the session using VTSessionSetProperty;
23/// then to encode frames, call VTCompressionSessionEncodeFrame.
24/// To force completion of some or all pending frames, call VTCompressionSessionCompleteFrames.
25/// When you are done with the session, you should call VTCompressionSessionInvalidate
26/// to tear it down and CFRelease to release your object reference.
27///
28/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionsession?language=objc)
29#[repr(C)]
30pub struct VTCompressionSession {
31 inner: [u8; 0],
32 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
33}
34
35cf_type!(
36 unsafe impl VTCompressionSession {}
37);
38#[cfg(feature = "objc2")]
39cf_objc2_type!(
40 unsafe impl RefEncode<"OpaqueVTCompressionSession"> for VTCompressionSession {}
41);
42
43/// Prototype for callback invoked when frame compression is complete.
44///
45/// When you create a compression session, you pass in a callback function to be called
46/// for compressed frames. This function will be called in decode order (which is not
47/// necessarily the same as display order).
48///
49/// Parameter `outputCallbackRefCon`: The callback's reference value.
50///
51/// Parameter `sourceFrameRefCon`: The frame's reference value, copied from the sourceFrameRefCon argument to
52/// VTCompressionSessionEncodeFrame.
53///
54/// Parameter `status`: noErr if compression was successful; an error code if compression was not successful.
55///
56/// Parameter `infoFlags`: Contains information about the encode operation.
57/// The kVTEncodeInfo_Asynchronous bit may be set if the encode ran asynchronously.
58/// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped.
59///
60/// Parameter `sampleBuffer`: Contains the compressed frame, if compression was successful and the frame was not dropped;
61/// otherwise, NULL.
62///
63/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionoutputcallback?language=objc)
64#[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
65pub type VTCompressionOutputCallback = Option<
66 unsafe extern "C-unwind" fn(
67 *mut c_void,
68 *mut c_void,
69 OSStatus,
70 VTEncodeInfoFlags,
71 *mut CMSampleBuffer,
72 ),
73>;
74
75extern "C" {
76 /// Specifies a particular video encoder by its ID string.
77 ///
78 /// To specify a particular video encoder when creating a compression session, pass an
79 /// encoderSpecification CFDictionary containing this key and the EncoderID as its value.
80 /// The EncoderID CFString may be obtained from the kVTVideoEncoderList_EncoderID entry in
81 /// the array returned by VTCopyVideoEncoderList.
82 ///
83 /// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/kvtvideoencoderspecification_encoderid?language=objc)
84 pub static kVTVideoEncoderSpecification_EncoderID: &'static CFString;
85}
86
87impl VTCompressionSession {
88 /// Creates a session for compressing video frames.
89 ///
90 /// Compressed frames will be emitted through calls to outputCallback.
91 ///
92 /// Parameter `allocator`: An allocator for the session. Pass NULL to use the default allocator.
93 ///
94 /// Parameter `width`: The width of frames, in pixels.
95 /// If the video encoder cannot support the provided width and height it may change them.
96 ///
97 /// Parameter `height`: The height of frames in pixels.
98 ///
99 /// Parameter `codecType`: The codec type.
100 ///
101 /// Parameter `encoderSpecification`: Specifies a particular video encoder that must be used.
102 /// Pass NULL to let the video toolbox choose a encoder.
103 ///
104 /// Parameter `sourceImageBufferAttributes`: Required attributes for source pixel buffers, used when creating a pixel buffer pool
105 /// for source frames. If you do not want the Video Toolbox to create one for you, pass NULL.
106 /// (Using pixel buffers not allocated by the Video Toolbox may increase the chance that
107 /// it will be necessary to copy image data.)
108 ///
109 /// Parameter `compressedDataAllocator`: An allocator for the compressed data. Pass NULL to use the default allocator.
110 /// Note: on MacOS 10.12 and later, using a compressedDataAllocator may trigger an extra buffer copy.
111 ///
112 /// Parameter `outputCallback`: The callback to be called with compressed frames.
113 /// This function may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrame.
114 /// Pass NULL if and only if you will be calling VTCompressionSessionEncodeFrameWithOutputHandler for encoding frames.
115 ///
116 /// Parameter `outputCallbackRefCon`: Client-defined reference value for the output callback.
117 ///
118 /// Parameter `compressionSessionOut`: Points to a variable to receive the new compression session.
119 #[doc(alias = "VTCompressionSessionCreate")]
120 #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
121 #[inline]
122 pub unsafe fn create(
123 allocator: Option<&CFAllocator>,
124 width: i32,
125 height: i32,
126 codec_type: CMVideoCodecType,
127 encoder_specification: Option<&CFDictionary>,
128 source_image_buffer_attributes: Option<&CFDictionary>,
129 compressed_data_allocator: Option<&CFAllocator>,
130 output_callback: VTCompressionOutputCallback,
131 output_callback_ref_con: *mut c_void,
132 compression_session_out: NonNull<*mut VTCompressionSession>,
133 ) -> OSStatus {
134 extern "C-unwind" {
135 fn VTCompressionSessionCreate(
136 allocator: Option<&CFAllocator>,
137 width: i32,
138 height: i32,
139 codec_type: CMVideoCodecType,
140 encoder_specification: Option<&CFDictionary>,
141 source_image_buffer_attributes: Option<&CFDictionary>,
142 compressed_data_allocator: Option<&CFAllocator>,
143 output_callback: VTCompressionOutputCallback,
144 output_callback_ref_con: *mut c_void,
145 compression_session_out: NonNull<*mut VTCompressionSession>,
146 ) -> OSStatus;
147 }
148 unsafe {
149 VTCompressionSessionCreate(
150 allocator,
151 width,
152 height,
153 codec_type,
154 encoder_specification,
155 source_image_buffer_attributes,
156 compressed_data_allocator,
157 output_callback,
158 output_callback_ref_con,
159 compression_session_out,
160 )
161 }
162 }
163
164 /// Tears down a compression session.
165 ///
166 /// When you are done with a compression session you created, call VTCompressionSessionInvalidate
167 /// to tear it down and then CFRelease to release your object reference.
168 /// When a compression session's retain count reaches zero, it is automatically invalidated, but
169 /// since sessions may be retained by multiple parties, it can be hard to predict when this will happen.
170 /// Calling VTCompressionSessionInvalidate ensures a deterministic, orderly teardown.
171 #[doc(alias = "VTCompressionSessionInvalidate")]
172 #[inline]
173 pub unsafe fn invalidate(self: &VTCompressionSession) {
174 extern "C-unwind" {
175 fn VTCompressionSessionInvalidate(session: &VTCompressionSession);
176 }
177 unsafe { VTCompressionSessionInvalidate(self) }
178 }
179}
180
181unsafe impl ConcreteType for VTCompressionSession {
182 /// Returns the CFTypeID for compression sessions.
183 #[doc(alias = "VTCompressionSessionGetTypeID")]
184 #[inline]
185 fn type_id() -> CFTypeID {
186 extern "C-unwind" {
187 fn VTCompressionSessionGetTypeID() -> CFTypeID;
188 }
189 unsafe { VTCompressionSessionGetTypeID() }
190 }
191}
192
193impl VTCompressionSession {
194 /// Returns a pool that can provide ideal source pixel buffers for a compression session.
195 ///
196 /// The compression session creates this pixel buffer pool based on
197 /// the compressor's pixel buffer attributes and any pixel buffer
198 /// attributes passed in to VTCompressionSessionCreate. If the
199 /// source pixel buffer attributes and the compressor pixel buffer
200 /// attributes cannot be reconciled, the pool is based on the source
201 /// pixel buffer attributes and the Video Toolbox converts each CVImageBuffer
202 /// internally.
203 /// <BR
204 /// >
205 /// While clients can call VTCompressionSessionGetPixelBufferPool once
206 /// and retain the resulting pool, the call is cheap enough that it's OK
207 /// to call it once per frame. If a change of session properties causes
208 /// the compressor's pixel buffer attributes to change, it's possible that
209 /// VTCompressionSessionGetPixelBufferPool might return a different pool.
210 #[doc(alias = "VTCompressionSessionGetPixelBufferPool")]
211 #[cfg(feature = "objc2-core-video")]
212 #[inline]
213 pub unsafe fn pixel_buffer_pool(
214 self: &VTCompressionSession,
215 ) -> Option<CFRetained<CVPixelBufferPool>> {
216 extern "C-unwind" {
217 fn VTCompressionSessionGetPixelBufferPool(
218 session: &VTCompressionSession,
219 ) -> Option<NonNull<CVPixelBufferPool>>;
220 }
221 let ret = unsafe { VTCompressionSessionGetPixelBufferPool(self) };
222 ret.map(|ret| unsafe { CFRetained::retain(ret) })
223 }
224
225 /// You can optionally call this function to provide the encoder with an opportunity to perform
226 /// any necessary resource allocation before it begins encoding frames.
227 ///
228 /// This optional call can be used to provide the encoder an opportunity to allocate
229 /// any resources necessary before it begins encoding frames. If this isn't called, any
230 /// necessary resources will be allocated on the first VTCompressionSessionEncodeFrame call.
231 /// Extra calls to this function will have no effect.
232 ///
233 /// Parameter `session`: The compression session.
234 #[doc(alias = "VTCompressionSessionPrepareToEncodeFrames")]
235 #[inline]
236 pub unsafe fn prepare_to_encode_frames(self: &VTCompressionSession) -> OSStatus {
237 extern "C-unwind" {
238 fn VTCompressionSessionPrepareToEncodeFrames(
239 session: &VTCompressionSession,
240 ) -> OSStatus;
241 }
242 unsafe { VTCompressionSessionPrepareToEncodeFrames(self) }
243 }
244
245 /// Call this function to present frames to the compression session.
246 /// Encoded frames may or may not be output before the function returns.
247 ///
248 /// The client should not modify the pixel data after making this call.
249 /// The session and/or encoder will retain the image buffer as long as necessary.
250 ///
251 /// Parameter `session`: The compression session.
252 ///
253 /// Parameter `imageBuffer`: A CVImageBuffer containing a video frame to be compressed.
254 /// Must have a nonzero reference count.
255 ///
256 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
257 /// Each presentation timestamp passed to a session must be greater than the previous one.
258 ///
259 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
260 /// If you do not have duration information, pass kCMTimeInvalid.
261 ///
262 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
263 /// Note that some session properties may also be changed between frames.
264 /// Such changes have effect on subsequently encoded frames.
265 ///
266 /// Parameter `sourceFrameRefcon`: Your reference value for the frame, which will be passed to the output callback function.
267 ///
268 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
269 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
270 /// asynchronously.
271 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
272 /// Pass NULL if you do not want to receive this information.
273 #[doc(alias = "VTCompressionSessionEncodeFrame")]
274 #[cfg(all(
275 feature = "VTErrors",
276 feature = "objc2-core-media",
277 feature = "objc2-core-video"
278 ))]
279 #[inline]
280 pub unsafe fn encode_frame(
281 self: &VTCompressionSession,
282 image_buffer: &CVImageBuffer,
283 presentation_time_stamp: CMTime,
284 duration: CMTime,
285 frame_properties: Option<&CFDictionary>,
286 source_frame_refcon: *mut c_void,
287 info_flags_out: *mut VTEncodeInfoFlags,
288 ) -> OSStatus {
289 extern "C-unwind" {
290 fn VTCompressionSessionEncodeFrame(
291 session: &VTCompressionSession,
292 image_buffer: &CVImageBuffer,
293 presentation_time_stamp: CMTime,
294 duration: CMTime,
295 frame_properties: Option<&CFDictionary>,
296 source_frame_refcon: *mut c_void,
297 info_flags_out: *mut VTEncodeInfoFlags,
298 ) -> OSStatus;
299 }
300 unsafe {
301 VTCompressionSessionEncodeFrame(
302 self,
303 image_buffer,
304 presentation_time_stamp,
305 duration,
306 frame_properties,
307 source_frame_refcon,
308 info_flags_out,
309 )
310 }
311 }
312}
313
314/// Prototype for block invoked when frame compression is complete.
315///
316/// When you encode a frame, you pass in a callback block to be called
317/// for that compressed frame. This block will be called in decode order (which is not
318/// necessarily the same as display order).
319///
320/// Parameter `status`: noErr if compression was successful; an error code if compression was not successful.
321///
322/// Parameter `infoFlags`: Contains information about the encode operation.
323/// The kVTEncodeInfo_Asynchronous bit may be set if the encode ran asynchronously.
324/// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped.
325///
326/// Parameter `sampleBuffer`: Contains the compressed frame, if compression was successful and the frame was not dropped;
327/// otherwise, NULL.
328///
329/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionoutputhandler?language=objc)
330#[cfg(all(feature = "VTErrors", feature = "block2", feature = "objc2-core-media"))]
331pub type VTCompressionOutputHandler =
332 *mut block2::DynBlock<dyn Fn(OSStatus, VTEncodeInfoFlags, *mut CMSampleBuffer)>;
333
334impl VTCompressionSession {
335 /// Call this function to present frames to the compression session.
336 /// Encoded frames may or may not be output before the function returns.
337 ///
338 /// The client should not modify the pixel data after making this call.
339 /// The session and/or encoder will retain the image buffer as long as necessary.
340 /// Cannot be called with a session created with a VTCompressionOutputCallback.
341 ///
342 /// Parameter `session`: The compression session.
343 ///
344 /// Parameter `imageBuffer`: A CVImageBuffer containing a video frame to be compressed.
345 /// Must have a nonzero reference count.
346 ///
347 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
348 /// Each presentation timestamp passed to a session must be greater than the previous one.
349 ///
350 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
351 /// If you do not have duration information, pass kCMTimeInvalid.
352 ///
353 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
354 /// Note that some session properties may also be changed between frames.
355 /// Such changes have effect on subsequently encoded frames.
356 ///
357 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
358 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
359 /// asynchronously.
360 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
361 /// Pass NULL if you do not want to receive this information.
362 ///
363 /// Parameter `outputHandler`: The block to be called when encoding the frame is completed.
364 /// This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrameWithOutputHandler.
365 #[doc(alias = "VTCompressionSessionEncodeFrameWithOutputHandler")]
366 #[cfg(all(
367 feature = "VTErrors",
368 feature = "block2",
369 feature = "objc2-core-media",
370 feature = "objc2-core-video"
371 ))]
372 #[inline]
373 pub unsafe fn encode_frame_with_output_handler(
374 self: &VTCompressionSession,
375 image_buffer: &CVImageBuffer,
376 presentation_time_stamp: CMTime,
377 duration: CMTime,
378 frame_properties: Option<&CFDictionary>,
379 info_flags_out: *mut VTEncodeInfoFlags,
380 output_handler: VTCompressionOutputHandler,
381 ) -> OSStatus {
382 extern "C-unwind" {
383 fn VTCompressionSessionEncodeFrameWithOutputHandler(
384 session: &VTCompressionSession,
385 image_buffer: &CVImageBuffer,
386 presentation_time_stamp: CMTime,
387 duration: CMTime,
388 frame_properties: Option<&CFDictionary>,
389 info_flags_out: *mut VTEncodeInfoFlags,
390 output_handler: VTCompressionOutputHandler,
391 ) -> OSStatus;
392 }
393 unsafe {
394 VTCompressionSessionEncodeFrameWithOutputHandler(
395 self,
396 image_buffer,
397 presentation_time_stamp,
398 duration,
399 frame_properties,
400 info_flags_out,
401 output_handler,
402 )
403 }
404 }
405
406 /// Forces the compression session to complete encoding frames.
407 ///
408 /// If completeUntilPresentationTimeStamp is numeric, frames with presentation timestamps
409 /// up to and including this timestamp will be emitted before the function returns.
410 /// If completeUntilPresentationTimeStamp is non-numeric, all pending frames
411 /// will be emitted before the function returns.
412 #[doc(alias = "VTCompressionSessionCompleteFrames")]
413 #[cfg(feature = "objc2-core-media")]
414 #[inline]
415 pub unsafe fn complete_frames(
416 self: &VTCompressionSession,
417 complete_until_presentation_time_stamp: CMTime,
418 ) -> OSStatus {
419 extern "C-unwind" {
420 fn VTCompressionSessionCompleteFrames(
421 session: &VTCompressionSession,
422 complete_until_presentation_time_stamp: CMTime,
423 ) -> OSStatus;
424 }
425 unsafe { VTCompressionSessionCompleteFrames(self, complete_until_presentation_time_stamp) }
426 }
427}
428
429/// Indicates whether the current system supports stereo MV-HEVC encode.
430///
431/// This call returning true does not guarantee that encode resources will be available at all times.
432#[inline]
433pub unsafe extern "C-unwind" fn VTIsStereoMVHEVCEncodeSupported() -> bool {
434 extern "C-unwind" {
435 fn VTIsStereoMVHEVCEncodeSupported() -> Boolean;
436 }
437 let ret = unsafe { VTIsStereoMVHEVCEncodeSupported() };
438 ret != 0
439}
440
441impl VTCompressionSession {
442 /// Call this function to present a multi-image frame to the compression session.
443 /// Encoded frames may or may not be output before the function returns.
444 ///
445 /// The client should not modify the pixel data after making this call.
446 /// The session and/or encoder will retain the image buffer as long as necessary.
447 ///
448 /// Parameter `session`: The compression session.
449 ///
450 /// Parameter `taggedBufferGroup`: A CMTaggedBufferGroup containing the multiple images for a video frame to be compressed.
451 ///
452 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
453 /// Each presentation timestamp passed to a session must be greater than the previous one.
454 ///
455 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
456 /// If you do not have duration information, pass kCMTimeInvalid.
457 ///
458 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
459 /// Note that some session properties may also be changed between frames.
460 /// Such changes have effect on subsequently encoded frames.
461 ///
462 /// Parameter `sourceFrameRefcon`: Your reference value for the frame, which will be passed to the output callback function.
463 ///
464 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
465 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
466 /// asynchronously.
467 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
468 /// Pass NULL if you do not want to receive this information.
469 #[doc(alias = "VTCompressionSessionEncodeMultiImageFrame")]
470 #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
471 #[inline]
472 pub unsafe fn encode_multi_image_frame(
473 self: &VTCompressionSession,
474 tagged_buffer_group: &CMTaggedBufferGroup,
475 presentation_time_stamp: CMTime,
476 duration: CMTime,
477 frame_properties: Option<&CFDictionary>,
478 source_frame_refcon: *mut c_void,
479 info_flags_out: *mut VTEncodeInfoFlags,
480 ) -> OSStatus {
481 extern "C-unwind" {
482 fn VTCompressionSessionEncodeMultiImageFrame(
483 session: &VTCompressionSession,
484 tagged_buffer_group: &CMTaggedBufferGroup,
485 presentation_time_stamp: CMTime,
486 duration: CMTime,
487 frame_properties: Option<&CFDictionary>,
488 source_frame_refcon: *mut c_void,
489 info_flags_out: *mut VTEncodeInfoFlags,
490 ) -> OSStatus;
491 }
492 unsafe {
493 VTCompressionSessionEncodeMultiImageFrame(
494 self,
495 tagged_buffer_group,
496 presentation_time_stamp,
497 duration,
498 frame_properties,
499 source_frame_refcon,
500 info_flags_out,
501 )
502 }
503 }
504
505 /// Call this function to present a multi-image frame to the compression session.
506 /// Encoded frames may or may not be output before the function returns.
507 ///
508 /// The client should not modify the pixel data after making this call.
509 /// The session and/or encoder will retain the image buffer as long as necessary.
510 /// Cannot be called with a session created with a VTCompressionOutputCallback.
511 ///
512 /// Parameter `session`: The compression session.
513 ///
514 /// Parameter `taggedBufferGroup`: A CMTaggedBufferGroup containing the multiple images for a video frame to be compressed.
515 ///
516 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
517 /// Each presentation timestamp passed to a session must be greater than the previous one.
518 ///
519 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
520 /// If you do not have duration information, pass kCMTimeInvalid.
521 ///
522 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
523 /// Note that some session properties may also be changed between frames.
524 /// Such changes have effect on subsequently encoded frames.
525 ///
526 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
527 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
528 /// asynchronously.
529 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
530 /// Pass NULL if you do not want to receive this information.
531 ///
532 /// Parameter `outputHandler`: The block to be called when encoding the frame is completed.
533 /// This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeMultiImageFrameWithOutputHandler.
534 #[doc(alias = "VTCompressionSessionEncodeMultiImageFrameWithOutputHandler")]
535 #[cfg(all(feature = "VTErrors", feature = "block2", feature = "objc2-core-media"))]
536 #[inline]
537 pub unsafe fn encode_multi_image_frame_with_output_handler(
538 self: &VTCompressionSession,
539 tagged_buffer_group: &CMTaggedBufferGroup,
540 presentation_time_stamp: CMTime,
541 duration: CMTime,
542 frame_properties: Option<&CFDictionary>,
543 info_flags_out: *mut VTEncodeInfoFlags,
544 output_handler: VTCompressionOutputHandler,
545 ) -> OSStatus {
546 extern "C-unwind" {
547 fn VTCompressionSessionEncodeMultiImageFrameWithOutputHandler(
548 session: &VTCompressionSession,
549 tagged_buffer_group: &CMTaggedBufferGroup,
550 presentation_time_stamp: CMTime,
551 duration: CMTime,
552 frame_properties: Option<&CFDictionary>,
553 info_flags_out: *mut VTEncodeInfoFlags,
554 output_handler: VTCompressionOutputHandler,
555 ) -> OSStatus;
556 }
557 unsafe {
558 VTCompressionSessionEncodeMultiImageFrameWithOutputHandler(
559 self,
560 tagged_buffer_group,
561 presentation_time_stamp,
562 duration,
563 frame_properties,
564 info_flags_out,
565 output_handler,
566 )
567 }
568 }
569}
570
571/// [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionsessionoptionflags?language=objc)
572// NS_OPTIONS
573#[repr(transparent)]
574#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
575pub struct VTCompressionSessionOptionFlags(pub u32);
576bitflags::bitflags! {
577 impl VTCompressionSessionOptionFlags: u32 {
578 #[doc(alias = "kVTCompressionSessionBeginFinalPass")]
579 const BeginFinalPass = 1<<0;
580 }
581}
582
583#[cfg(feature = "objc2")]
584unsafe impl Encode for VTCompressionSessionOptionFlags {
585 const ENCODING: Encoding = u32::ENCODING;
586}
587
588#[cfg(feature = "objc2")]
589unsafe impl RefEncode for VTCompressionSessionOptionFlags {
590 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
591}
592
593impl VTCompressionSession {
594 /// Call to announce the start of a specific compression pass.
595 ///
596 /// During multi-pass encoding, this function must be called before VTCompressionSessionEncodeFrame.
597 /// It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage.
598 ///
599 /// Parameter `beginPassFlags`: Pass kVTCompressionSessionBeginFinalPass to inform the encoder that the pass must be the final pass.
600 #[doc(alias = "VTCompressionSessionBeginPass")]
601 #[inline]
602 pub unsafe fn begin_pass(
603 self: &VTCompressionSession,
604 begin_pass_flags: VTCompressionSessionOptionFlags,
605 reserved: *mut u32,
606 ) -> OSStatus {
607 extern "C-unwind" {
608 fn VTCompressionSessionBeginPass(
609 session: &VTCompressionSession,
610 begin_pass_flags: VTCompressionSessionOptionFlags,
611 reserved: *mut u32,
612 ) -> OSStatus;
613 }
614 unsafe { VTCompressionSessionBeginPass(self, begin_pass_flags, reserved) }
615 }
616
617 /// Call to announce the end of a pass.
618 ///
619 /// VTCompressionSessionEndPass can take a long time, since the video encoder may perform significant processing between passes.
620 /// VTCompressionSessionEndPass will indicate via the furtherPassesRequestedOut argument whether the video encoder would like to perform another pass. There is no particular bound on the number of passes the video encoder may request, but the client is free to disregard this request and use the last-emitted set of frames.
621 /// It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage.
622 ///
623 /// Parameter `furtherPassesRequestedOut`: Points to a Boolean that will be set to true if the video encoder would like to perform another pass, false otherwise.
624 /// You may pass NULL to indicate that the client is certain to use this as the final pass, in which case the video encoder can skip that evaluation step.
625 #[doc(alias = "VTCompressionSessionEndPass")]
626 #[inline]
627 pub unsafe fn end_pass(
628 self: &VTCompressionSession,
629 further_passes_requested_out: *mut Boolean,
630 reserved: *mut u32,
631 ) -> OSStatus {
632 extern "C-unwind" {
633 fn VTCompressionSessionEndPass(
634 session: &VTCompressionSession,
635 further_passes_requested_out: *mut Boolean,
636 reserved: *mut u32,
637 ) -> OSStatus;
638 }
639 unsafe { VTCompressionSessionEndPass(self, further_passes_requested_out, reserved) }
640 }
641
642 /// Retrieves the time ranges for the next pass.
643 ///
644 /// If VTCompressionSessionEndPass sets *furtherPassesRequestedOut to true, call VTCompressionSessionGetTimeRangesForNextPass to find out the time ranges for the next pass. Source frames outside these time ranges should be skipped.
645 /// Each time range is considered to include any frame at its start time and not to include any frame at its end time.
646 /// It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage, or when VTCompressionSessionEndPass did not set *furtherPassesRequestedOut to true.
647 ///
648 /// Parameter `timeRangeCountOut`: Points to a CMItemCount to receive the number of CMTimeRanges.
649 ///
650 /// Parameter `timeRangeArrayOut`: Points to a const CMTimeRange * to receive a pointer to a C array of CMTimeRanges.
651 /// The storage for this array belongs to the VTCompressionSession and should not be modified.
652 /// The pointer will be valid until the next call to VTCompressionSessionEndPass, or until the VTCompressionSession is invalidated or finalized.
653 #[doc(alias = "VTCompressionSessionGetTimeRangesForNextPass")]
654 #[cfg(feature = "objc2-core-media")]
655 #[inline]
656 pub unsafe fn time_ranges_for_next_pass(
657 self: &VTCompressionSession,
658 time_range_count_out: NonNull<CMItemCount>,
659 time_range_array_out: NonNull<*const CMTimeRange>,
660 ) -> OSStatus {
661 extern "C-unwind" {
662 fn VTCompressionSessionGetTimeRangesForNextPass(
663 session: &VTCompressionSession,
664 time_range_count_out: NonNull<CMItemCount>,
665 time_range_array_out: NonNull<*const CMTimeRange>,
666 ) -> OSStatus;
667 }
668 unsafe {
669 VTCompressionSessionGetTimeRangesForNextPass(
670 self,
671 time_range_count_out,
672 time_range_array_out,
673 )
674 }
675 }
676}
677
678extern "C-unwind" {
679 #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
680 #[deprecated = "renamed to `VTCompressionSession::create`"]
681 pub fn VTCompressionSessionCreate(
682 allocator: Option<&CFAllocator>,
683 width: i32,
684 height: i32,
685 codec_type: CMVideoCodecType,
686 encoder_specification: Option<&CFDictionary>,
687 source_image_buffer_attributes: Option<&CFDictionary>,
688 compressed_data_allocator: Option<&CFAllocator>,
689 output_callback: VTCompressionOutputCallback,
690 output_callback_ref_con: *mut c_void,
691 compression_session_out: NonNull<*mut VTCompressionSession>,
692 ) -> OSStatus;
693}
694
695extern "C-unwind" {
696 #[deprecated = "renamed to `VTCompressionSession::invalidate`"]
697 pub fn VTCompressionSessionInvalidate(session: &VTCompressionSession);
698}
699
700#[cfg(feature = "objc2-core-video")]
701#[deprecated = "renamed to `VTCompressionSession::pixel_buffer_pool`"]
702#[inline]
703pub unsafe extern "C-unwind" fn VTCompressionSessionGetPixelBufferPool(
704 session: &VTCompressionSession,
705) -> Option<CFRetained<CVPixelBufferPool>> {
706 extern "C-unwind" {
707 fn VTCompressionSessionGetPixelBufferPool(
708 session: &VTCompressionSession,
709 ) -> Option<NonNull<CVPixelBufferPool>>;
710 }
711 let ret = unsafe { VTCompressionSessionGetPixelBufferPool(session) };
712 ret.map(|ret| unsafe { CFRetained::retain(ret) })
713}
714
715extern "C-unwind" {
716 #[deprecated = "renamed to `VTCompressionSession::prepare_to_encode_frames`"]
717 pub fn VTCompressionSessionPrepareToEncodeFrames(session: &VTCompressionSession) -> OSStatus;
718}
719
720extern "C-unwind" {
721 #[cfg(all(
722 feature = "VTErrors",
723 feature = "objc2-core-media",
724 feature = "objc2-core-video"
725 ))]
726 #[deprecated = "renamed to `VTCompressionSession::encode_frame`"]
727 pub fn VTCompressionSessionEncodeFrame(
728 session: &VTCompressionSession,
729 image_buffer: &CVImageBuffer,
730 presentation_time_stamp: CMTime,
731 duration: CMTime,
732 frame_properties: Option<&CFDictionary>,
733 source_frame_refcon: *mut c_void,
734 info_flags_out: *mut VTEncodeInfoFlags,
735 ) -> OSStatus;
736}
737
738extern "C-unwind" {
739 #[cfg(all(
740 feature = "VTErrors",
741 feature = "block2",
742 feature = "objc2-core-media",
743 feature = "objc2-core-video"
744 ))]
745 #[deprecated = "renamed to `VTCompressionSession::encode_frame_with_output_handler`"]
746 pub fn VTCompressionSessionEncodeFrameWithOutputHandler(
747 session: &VTCompressionSession,
748 image_buffer: &CVImageBuffer,
749 presentation_time_stamp: CMTime,
750 duration: CMTime,
751 frame_properties: Option<&CFDictionary>,
752 info_flags_out: *mut VTEncodeInfoFlags,
753 output_handler: VTCompressionOutputHandler,
754 ) -> OSStatus;
755}
756
757extern "C-unwind" {
758 #[cfg(feature = "objc2-core-media")]
759 #[deprecated = "renamed to `VTCompressionSession::complete_frames`"]
760 pub fn VTCompressionSessionCompleteFrames(
761 session: &VTCompressionSession,
762 complete_until_presentation_time_stamp: CMTime,
763 ) -> OSStatus;
764}
765
766extern "C-unwind" {
767 #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
768 #[deprecated = "renamed to `VTCompressionSession::encode_multi_image_frame`"]
769 pub fn VTCompressionSessionEncodeMultiImageFrame(
770 session: &VTCompressionSession,
771 tagged_buffer_group: &CMTaggedBufferGroup,
772 presentation_time_stamp: CMTime,
773 duration: CMTime,
774 frame_properties: Option<&CFDictionary>,
775 source_frame_refcon: *mut c_void,
776 info_flags_out: *mut VTEncodeInfoFlags,
777 ) -> OSStatus;
778}
779
780extern "C-unwind" {
781 #[cfg(all(feature = "VTErrors", feature = "block2", feature = "objc2-core-media"))]
782 #[deprecated = "renamed to `VTCompressionSession::encode_multi_image_frame_with_output_handler`"]
783 pub fn VTCompressionSessionEncodeMultiImageFrameWithOutputHandler(
784 session: &VTCompressionSession,
785 tagged_buffer_group: &CMTaggedBufferGroup,
786 presentation_time_stamp: CMTime,
787 duration: CMTime,
788 frame_properties: Option<&CFDictionary>,
789 info_flags_out: *mut VTEncodeInfoFlags,
790 output_handler: VTCompressionOutputHandler,
791 ) -> OSStatus;
792}
793
794extern "C-unwind" {
795 #[deprecated = "renamed to `VTCompressionSession::begin_pass`"]
796 pub fn VTCompressionSessionBeginPass(
797 session: &VTCompressionSession,
798 begin_pass_flags: VTCompressionSessionOptionFlags,
799 reserved: *mut u32,
800 ) -> OSStatus;
801}
802
803extern "C-unwind" {
804 #[deprecated = "renamed to `VTCompressionSession::end_pass`"]
805 pub fn VTCompressionSessionEndPass(
806 session: &VTCompressionSession,
807 further_passes_requested_out: *mut Boolean,
808 reserved: *mut u32,
809 ) -> OSStatus;
810}
811
812extern "C-unwind" {
813 #[cfg(feature = "objc2-core-media")]
814 #[deprecated = "renamed to `VTCompressionSession::time_ranges_for_next_pass`"]
815 pub fn VTCompressionSessionGetTimeRangesForNextPass(
816 session: &VTCompressionSession,
817 time_range_count_out: NonNull<CMItemCount>,
818 time_range_array_out: NonNull<*const CMTimeRange>,
819 ) -> OSStatus;
820}