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 #[encoding_name = "OpaqueVTCompressionSession"]
37 unsafe impl VTCompressionSession {}
38);
39
40/// Prototype for callback invoked when frame compression is complete.
41///
42/// When you create a compression session, you pass in a callback function to be called
43/// for compressed frames. This function will be called in decode order (which is not
44/// necessarily the same as display order).
45///
46/// Parameter `outputCallbackRefCon`: The callback's reference value.
47///
48/// Parameter `sourceFrameRefCon`: The frame's reference value, copied from the sourceFrameRefCon argument to
49/// VTCompressionSessionEncodeFrame.
50///
51/// Parameter `status`: noErr if compression was successful; an error code if compression was not successful.
52///
53/// Parameter `infoFlags`: Contains information about the encode operation.
54/// The kVTEncodeInfo_Asynchronous bit may be set if the encode ran asynchronously.
55/// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped.
56///
57/// Parameter `sampleBuffer`: Contains the compressed frame, if compression was successful and the frame was not dropped;
58/// otherwise, NULL.
59///
60/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionoutputcallback?language=objc)
61#[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
62pub type VTCompressionOutputCallback = Option<
63 unsafe extern "C-unwind" fn(
64 *mut c_void,
65 *mut c_void,
66 OSStatus,
67 VTEncodeInfoFlags,
68 *mut CMSampleBuffer,
69 ),
70>;
71
72extern "C" {
73 /// Specifies a particular video encoder by its ID string.
74 ///
75 /// To specify a particular video encoder when creating a compression session, pass an
76 /// encoderSpecification CFDictionary containing this key and the EncoderID as its value.
77 /// The EncoderID CFString may be obtained from the kVTVideoEncoderList_EncoderID entry in
78 /// the array returned by VTCopyVideoEncoderList.
79 ///
80 /// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/kvtvideoencoderspecification_encoderid?language=objc)
81 pub static kVTVideoEncoderSpecification_EncoderID: &'static CFString;
82}
83
84extern "C-unwind" {
85 /// Creates a session for compressing video frames.
86 ///
87 /// Compressed frames will be emitted through calls to outputCallback.
88 ///
89 /// Parameter `allocator`: An allocator for the session. Pass NULL to use the default allocator.
90 ///
91 /// Parameter `width`: The width of frames, in pixels.
92 /// If the video encoder cannot support the provided width and height it may change them.
93 ///
94 /// Parameter `height`: The height of frames in pixels.
95 ///
96 /// Parameter `codecType`: The codec type.
97 ///
98 /// Parameter `encoderSpecification`: Specifies a particular video encoder that must be used.
99 /// Pass NULL to let the video toolbox choose a encoder.
100 ///
101 /// Parameter `sourceImageBufferAttributes`: Required attributes for source pixel buffers, used when creating a pixel buffer pool
102 /// for source frames. If you do not want the Video Toolbox to create one for you, pass NULL.
103 /// (Using pixel buffers not allocated by the Video Toolbox may increase the chance that
104 /// it will be necessary to copy image data.)
105 ///
106 /// Parameter `compressedDataAllocator`: An allocator for the compressed data. Pass NULL to use the default allocator.
107 /// Note: on MacOS 10.12 and later, using a compressedDataAllocator may trigger an extra buffer copy.
108 ///
109 /// Parameter `outputCallback`: The callback to be called with compressed frames.
110 /// This function may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrame.
111 /// Pass NULL if and only if you will be calling VTCompressionSessionEncodeFrameWithOutputHandler for encoding frames.
112 ///
113 /// Parameter `outputCallbackRefCon`: Client-defined reference value for the output callback.
114 ///
115 /// Parameter `compressionSessionOut`: Points to a variable to receive the new compression session.
116 #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
117 pub fn VTCompressionSessionCreate(
118 allocator: Option<&CFAllocator>,
119 width: i32,
120 height: i32,
121 codec_type: CMVideoCodecType,
122 encoder_specification: Option<&CFDictionary>,
123 source_image_buffer_attributes: Option<&CFDictionary>,
124 compressed_data_allocator: Option<&CFAllocator>,
125 output_callback: VTCompressionOutputCallback,
126 output_callback_ref_con: *mut c_void,
127 compression_session_out: NonNull<*mut VTCompressionSession>,
128 ) -> OSStatus;
129}
130
131extern "C-unwind" {
132 /// Tears down a compression session.
133 ///
134 /// When you are done with a compression session you created, call VTCompressionSessionInvalidate
135 /// to tear it down and then CFRelease to release your object reference.
136 /// When a compression session's retain count reaches zero, it is automatically invalidated, but
137 /// since sessions may be retained by multiple parties, it can be hard to predict when this will happen.
138 /// Calling VTCompressionSessionInvalidate ensures a deterministic, orderly teardown.
139 pub fn VTCompressionSessionInvalidate(session: &VTCompressionSession);
140}
141
142unsafe impl ConcreteType for VTCompressionSession {
143 /// Returns the CFTypeID for compression sessions.
144 #[doc(alias = "VTCompressionSessionGetTypeID")]
145 #[inline]
146 fn type_id() -> CFTypeID {
147 extern "C-unwind" {
148 fn VTCompressionSessionGetTypeID() -> CFTypeID;
149 }
150 unsafe { VTCompressionSessionGetTypeID() }
151 }
152}
153
154/// Returns a pool that can provide ideal source pixel buffers for a compression session.
155///
156/// The compression session creates this pixel buffer pool based on
157/// the compressor's pixel buffer attributes and any pixel buffer
158/// attributes passed in to VTCompressionSessionCreate. If the
159/// source pixel buffer attributes and the compressor pixel buffer
160/// attributes cannot be reconciled, the pool is based on the source
161/// pixel buffer attributes and the Video Toolbox converts each CVImageBuffer
162/// internally.
163/// <BR
164/// >
165/// While clients can call VTCompressionSessionGetPixelBufferPool once
166/// and retain the resulting pool, the call is cheap enough that it's OK
167/// to call it once per frame. If a change of session properties causes
168/// the compressor's pixel buffer attributes to change, it's possible that
169/// VTCompressionSessionGetPixelBufferPool might return a different pool.
170#[cfg(feature = "objc2-core-video")]
171#[inline]
172pub unsafe extern "C-unwind" fn VTCompressionSessionGetPixelBufferPool(
173 session: &VTCompressionSession,
174) -> Option<CFRetained<CVPixelBufferPool>> {
175 extern "C-unwind" {
176 fn VTCompressionSessionGetPixelBufferPool(
177 session: &VTCompressionSession,
178 ) -> Option<NonNull<CVPixelBufferPool>>;
179 }
180 let ret = unsafe { VTCompressionSessionGetPixelBufferPool(session) };
181 ret.map(|ret| unsafe { CFRetained::retain(ret) })
182}
183
184extern "C-unwind" {
185 /// You can optionally call this function to provide the encoder with an opportunity to perform
186 /// any necessary resource allocation before it begins encoding frames.
187 ///
188 /// This optional call can be used to provide the encoder an opportunity to allocate
189 /// any resources necessary before it begins encoding frames. If this isn't called, any
190 /// necessary resources will be allocated on the first VTCompressionSessionEncodeFrame call.
191 /// Extra calls to this function will have no effect.
192 ///
193 /// Parameter `session`: The compression session.
194 pub fn VTCompressionSessionPrepareToEncodeFrames(session: &VTCompressionSession) -> OSStatus;
195}
196
197extern "C-unwind" {
198 /// Call this function to present frames to the compression session.
199 /// Encoded frames may or may not be output before the function returns.
200 ///
201 /// The client should not modify the pixel data after making this call.
202 /// The session and/or encoder will retain the image buffer as long as necessary.
203 ///
204 /// Parameter `session`: The compression session.
205 ///
206 /// Parameter `imageBuffer`: A CVImageBuffer containing a video frame to be compressed.
207 /// Must have a nonzero reference count.
208 ///
209 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
210 /// Each presentation timestamp passed to a session must be greater than the previous one.
211 ///
212 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
213 /// If you do not have duration information, pass kCMTimeInvalid.
214 ///
215 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
216 /// Note that some session properties may also be changed between frames.
217 /// Such changes have effect on subsequently encoded frames.
218 ///
219 /// Parameter `sourceFrameRefcon`: Your reference value for the frame, which will be passed to the output callback function.
220 ///
221 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
222 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
223 /// asynchronously.
224 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
225 /// Pass NULL if you do not want to receive this information.
226 #[cfg(all(
227 feature = "VTErrors",
228 feature = "objc2-core-media",
229 feature = "objc2-core-video"
230 ))]
231 pub fn VTCompressionSessionEncodeFrame(
232 session: &VTCompressionSession,
233 image_buffer: &CVImageBuffer,
234 presentation_time_stamp: CMTime,
235 duration: CMTime,
236 frame_properties: Option<&CFDictionary>,
237 source_frame_refcon: *mut c_void,
238 info_flags_out: *mut VTEncodeInfoFlags,
239 ) -> OSStatus;
240}
241
242/// Prototype for block invoked when frame compression is complete.
243///
244/// When you encode a frame, you pass in a callback block to be called
245/// for that compressed frame. This block will be called in decode order (which is not
246/// necessarily the same as display order).
247///
248/// Parameter `status`: noErr if compression was successful; an error code if compression was not successful.
249///
250/// Parameter `infoFlags`: Contains information about the encode operation.
251/// The kVTEncodeInfo_Asynchronous bit may be set if the encode ran asynchronously.
252/// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped.
253///
254/// Parameter `sampleBuffer`: Contains the compressed frame, if compression was successful and the frame was not dropped;
255/// otherwise, NULL.
256///
257/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionoutputhandler?language=objc)
258#[cfg(all(feature = "VTErrors", feature = "block2", feature = "objc2-core-media"))]
259pub type VTCompressionOutputHandler =
260 *mut block2::Block<dyn Fn(OSStatus, VTEncodeInfoFlags, *mut CMSampleBuffer)>;
261
262extern "C-unwind" {
263 /// Call this function to present frames to the compression session.
264 /// Encoded frames may or may not be output before the function returns.
265 ///
266 /// The client should not modify the pixel data after making this call.
267 /// The session and/or encoder will retain the image buffer as long as necessary.
268 /// Cannot be called with a session created with a VTCompressionOutputCallback.
269 ///
270 /// Parameter `session`: The compression session.
271 ///
272 /// Parameter `imageBuffer`: A CVImageBuffer containing a video frame to be compressed.
273 /// Must have a nonzero reference count.
274 ///
275 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
276 /// Each presentation timestamp passed to a session must be greater than the previous one.
277 ///
278 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
279 /// If you do not have duration information, pass kCMTimeInvalid.
280 ///
281 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
282 /// Note that some session properties may also be changed between frames.
283 /// Such changes have effect on subsequently encoded frames.
284 ///
285 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
286 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
287 /// asynchronously.
288 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
289 /// Pass NULL if you do not want to receive this information.
290 ///
291 /// Parameter `outputHandler`: The block to be called when encoding the frame is completed.
292 /// This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrameWithOutputHandler.
293 #[cfg(all(
294 feature = "VTErrors",
295 feature = "block2",
296 feature = "objc2-core-media",
297 feature = "objc2-core-video"
298 ))]
299 pub fn VTCompressionSessionEncodeFrameWithOutputHandler(
300 session: &VTCompressionSession,
301 image_buffer: &CVImageBuffer,
302 presentation_time_stamp: CMTime,
303 duration: CMTime,
304 frame_properties: Option<&CFDictionary>,
305 info_flags_out: *mut VTEncodeInfoFlags,
306 output_handler: VTCompressionOutputHandler,
307 ) -> OSStatus;
308}
309
310extern "C-unwind" {
311 /// Forces the compression session to complete encoding frames.
312 ///
313 /// If completeUntilPresentationTimeStamp is numeric, frames with presentation timestamps
314 /// up to and including this timestamp will be emitted before the function returns.
315 /// If completeUntilPresentationTimeStamp is non-numeric, all pending frames
316 /// will be emitted before the function returns.
317 #[cfg(feature = "objc2-core-media")]
318 pub fn VTCompressionSessionCompleteFrames(
319 session: &VTCompressionSession,
320 complete_until_presentation_time_stamp: CMTime,
321 ) -> OSStatus;
322}
323
324/// Indicates whether the current system supports stereo MV-HEVC encode.
325///
326/// This call returning true does not guarantee that encode resources will be available at all times.
327#[inline]
328pub unsafe extern "C-unwind" fn VTIsStereoMVHEVCEncodeSupported() -> bool {
329 extern "C-unwind" {
330 fn VTIsStereoMVHEVCEncodeSupported() -> Boolean;
331 }
332 let ret = unsafe { VTIsStereoMVHEVCEncodeSupported() };
333 ret != 0
334}
335
336extern "C-unwind" {
337 /// Call this function to present a multi-image frame to the compression session.
338 /// Encoded frames may or may not be output before the function returns.
339 ///
340 /// The client should not modify the pixel data after making this call.
341 /// The session and/or encoder will retain the image buffer as long as necessary.
342 ///
343 /// Parameter `session`: The compression session.
344 ///
345 /// Parameter `taggedBufferGroup`: A CMTaggedBufferGroup containing the multiple images for a video frame to be compressed.
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 `sourceFrameRefcon`: Your reference value for the frame, which will be passed to the output callback function.
358 ///
359 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
360 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
361 /// asynchronously.
362 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
363 /// Pass NULL if you do not want to receive this information.
364 #[cfg(all(feature = "VTErrors", feature = "objc2-core-media"))]
365 pub fn VTCompressionSessionEncodeMultiImageFrame(
366 session: &VTCompressionSession,
367 tagged_buffer_group: &CMTaggedBufferGroup,
368 presentation_time_stamp: CMTime,
369 duration: CMTime,
370 frame_properties: Option<&CFDictionary>,
371 source_frame_refcon: *mut c_void,
372 info_flags_out: *mut VTEncodeInfoFlags,
373 ) -> OSStatus;
374}
375
376extern "C-unwind" {
377 /// Call this function to present a multi-image frame to the compression session.
378 /// Encoded frames may or may not be output before the function returns.
379 ///
380 /// The client should not modify the pixel data after making this call.
381 /// The session and/or encoder will retain the image buffer as long as necessary.
382 /// Cannot be called with a session created with a VTCompressionOutputCallback.
383 ///
384 /// Parameter `session`: The compression session.
385 ///
386 /// Parameter `taggedBufferGroup`: A CMTaggedBufferGroup containing the multiple images for a video frame to be compressed.
387 ///
388 /// Parameter `presentationTimeStamp`: The presentation timestamp for this frame, to be attached to the sample buffer.
389 /// Each presentation timestamp passed to a session must be greater than the previous one.
390 ///
391 /// Parameter `duration`: The presentation duration for this frame, to be attached to the sample buffer.
392 /// If you do not have duration information, pass kCMTimeInvalid.
393 ///
394 /// Parameter `frameProperties`: Contains key/value pairs specifying additional properties for encoding this frame.
395 /// Note that some session properties may also be changed between frames.
396 /// Such changes have effect on subsequently encoded frames.
397 ///
398 /// Parameter `infoFlagsOut`: Points to a VTEncodeInfoFlags to receive information about the encode operation.
399 /// The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
400 /// asynchronously.
401 /// The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
402 /// Pass NULL if you do not want to receive this information.
403 ///
404 /// Parameter `outputHandler`: The block to be called when encoding the frame is completed.
405 /// This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeMultiImageFrameWithOutputHandler.
406 #[cfg(all(feature = "VTErrors", feature = "block2", feature = "objc2-core-media"))]
407 pub fn VTCompressionSessionEncodeMultiImageFrameWithOutputHandler(
408 session: &VTCompressionSession,
409 tagged_buffer_group: &CMTaggedBufferGroup,
410 presentation_time_stamp: CMTime,
411 duration: CMTime,
412 frame_properties: Option<&CFDictionary>,
413 info_flags_out: *mut VTEncodeInfoFlags,
414 output_handler: VTCompressionOutputHandler,
415 ) -> OSStatus;
416}
417
418/// [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtcompressionsessionoptionflags?language=objc)
419// NS_OPTIONS
420#[repr(transparent)]
421#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
422pub struct VTCompressionSessionOptionFlags(pub u32);
423bitflags::bitflags! {
424 impl VTCompressionSessionOptionFlags: u32 {
425 #[doc(alias = "kVTCompressionSessionBeginFinalPass")]
426 const BeginFinalPass = 1<<0;
427 }
428}
429
430#[cfg(feature = "objc2")]
431unsafe impl Encode for VTCompressionSessionOptionFlags {
432 const ENCODING: Encoding = u32::ENCODING;
433}
434
435#[cfg(feature = "objc2")]
436unsafe impl RefEncode for VTCompressionSessionOptionFlags {
437 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
438}
439
440extern "C-unwind" {
441 /// Call to announce the start of a specific compression pass.
442 ///
443 /// During multi-pass encoding, this function must be called before VTCompressionSessionEncodeFrame.
444 /// It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage.
445 ///
446 /// Parameter `beginPassFlags`: Pass kVTCompressionSessionBeginFinalPass to inform the encoder that the pass must be the final pass.
447 pub fn VTCompressionSessionBeginPass(
448 session: &VTCompressionSession,
449 begin_pass_flags: VTCompressionSessionOptionFlags,
450 reserved: *mut u32,
451 ) -> OSStatus;
452}
453
454extern "C-unwind" {
455 /// Call to announce the end of a pass.
456 ///
457 /// VTCompressionSessionEndPass can take a long time, since the video encoder may perform significant processing between passes.
458 /// 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.
459 /// It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage.
460 ///
461 /// Parameter `furtherPassesRequestedOut`: Points to a Boolean that will be set to true if the video encoder would like to perform another pass, false otherwise.
462 /// 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.
463 pub fn VTCompressionSessionEndPass(
464 session: &VTCompressionSession,
465 further_passes_requested_out: *mut Boolean,
466 reserved: *mut u32,
467 ) -> OSStatus;
468}
469
470extern "C-unwind" {
471 /// Retrieves the time ranges for the next pass.
472 ///
473 /// 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.
474 /// Each time range is considered to include any frame at its start time and not to include any frame at its end time.
475 /// 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.
476 ///
477 /// Parameter `timeRangeCountOut`: Points to a CMItemCount to receive the number of CMTimeRanges.
478 ///
479 /// Parameter `timeRangeArrayOut`: Points to a const CMTimeRange * to receive a pointer to a C array of CMTimeRanges.
480 /// The storage for this array belongs to the VTCompressionSession and should not be modified.
481 /// The pointer will be valid until the next call to VTCompressionSessionEndPass, or until the VTCompressionSession is invalidated or finalized.
482 #[cfg(feature = "objc2-core-media")]
483 pub fn VTCompressionSessionGetTimeRangesForNextPass(
484 session: &VTCompressionSession,
485 time_range_count_out: NonNull<CMItemCount>,
486 time_range_array_out: NonNull<*const CMTimeRange>,
487 ) -> OSStatus;
488}