pub struct VTCompressionSession { /* private fields */ }VTCompressionSession only.Expand description
A reference to a Video Toolbox Compression Session.
A compression session supports the compression of a sequence of video frames. The session reference is a reference-counted CF object. To create a compression session, call VTCompressionSessionCreate; then you can optionally configure the session using VTSessionSetProperty; then to encode frames, call VTCompressionSessionEncodeFrame. To force completion of some or all pending frames, call VTCompressionSessionCompleteFrames. When you are done with the session, you should call VTCompressionSessionInvalidate to tear it down and CFRelease to release your object reference.
See also Apple’s documentation
Implementations§
Source§impl VTCompressionSession
impl VTCompressionSession
Sourcepub unsafe fn create(
allocator: Option<&CFAllocator>,
width: i32,
height: i32,
codec_type: CMVideoCodecType,
encoder_specification: Option<&CFDictionary>,
source_image_buffer_attributes: Option<&CFDictionary>,
compressed_data_allocator: Option<&CFAllocator>,
output_callback: VTCompressionOutputCallback,
output_callback_ref_con: *mut c_void,
compression_session_out: NonNull<*mut VTCompressionSession>,
) -> i32
Available on crate features VTErrors and objc2-core-media only.
pub unsafe fn create( allocator: Option<&CFAllocator>, width: i32, height: i32, codec_type: CMVideoCodecType, encoder_specification: Option<&CFDictionary>, source_image_buffer_attributes: Option<&CFDictionary>, compressed_data_allocator: Option<&CFAllocator>, output_callback: VTCompressionOutputCallback, output_callback_ref_con: *mut c_void, compression_session_out: NonNull<*mut VTCompressionSession>, ) -> i32
VTErrors and objc2-core-media only.Creates a session for compressing video frames.
Compressed frames will be emitted through calls to outputCallback.
Parameter allocator: An allocator for the session. Pass NULL to use the default allocator.
Parameter width: The width of frames, in pixels.
If the video encoder cannot support the provided width and height it may change them.
Parameter height: The height of frames in pixels.
Parameter codecType: The codec type.
Parameter encoderSpecification: Specifies a particular video encoder that must be used.
Pass NULL to let the video toolbox choose a encoder.
Parameter sourceImageBufferAttributes: Required attributes for source pixel buffers, used when creating a pixel buffer pool
for source frames. If you do not want the Video Toolbox to create one for you, pass NULL.
(Using pixel buffers not allocated by the Video Toolbox may increase the chance that
it will be necessary to copy image data.)
Parameter compressedDataAllocator: An allocator for the compressed data. Pass NULL to use the default allocator.
Note: on MacOS 10.12 and later, using a compressedDataAllocator may trigger an extra buffer copy.
Parameter outputCallback: The callback to be called with compressed frames.
This function may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrame.
Pass NULL if and only if you will be calling VTCompressionSessionEncodeFrameWithOutputHandler for encoding frames.
Parameter outputCallbackRefCon: Client-defined reference value for the output callback.
Parameter compressionSessionOut: Points to a variable to receive the new compression session.
§Safety
encoder_specificationgenerics must be of the correct type.source_image_buffer_attributesgenerics must be of the correct type.output_callbackmust be implemented correctly.output_callback_ref_conmust be a valid pointer or null.compression_session_outmust be a valid pointer.
Sourcepub unsafe fn invalidate(&self)
pub unsafe fn invalidate(&self)
Tears down a compression session.
When you are done with a compression session you created, call VTCompressionSessionInvalidate to tear it down and then CFRelease to release your object reference. When a compression session’s retain count reaches zero, it is automatically invalidated, but since sessions may be retained by multiple parties, it can be hard to predict when this will happen. Calling VTCompressionSessionInvalidate ensures a deterministic, orderly teardown.
Source§impl VTCompressionSession
impl VTCompressionSession
Sourcepub unsafe fn pixel_buffer_pool(&self) -> Option<CFRetained<CVPixelBufferPool>>
Available on crate feature objc2-core-video only.
pub unsafe fn pixel_buffer_pool(&self) -> Option<CFRetained<CVPixelBufferPool>>
objc2-core-video only.Returns a pool that can provide ideal source pixel buffers for a compression session.
The compression session creates this pixel buffer pool based on the compressor’s pixel buffer attributes and any pixel buffer attributes passed in to VTCompressionSessionCreate. If the source pixel buffer attributes and the compressor pixel buffer attributes cannot be reconciled, the pool is based on the source pixel buffer attributes and the Video Toolbox converts each CVImageBuffer internally. <BR
While clients can call VTCompressionSessionGetPixelBufferPool once and retain the resulting pool, the call is cheap enough that it’s OK to call it once per frame. If a change of session properties causes the compressor’s pixel buffer attributes to change, it’s possible that VTCompressionSessionGetPixelBufferPool might return a different pool.
Sourcepub unsafe fn prepare_to_encode_frames(&self) -> i32
pub unsafe fn prepare_to_encode_frames(&self) -> i32
You can optionally call this function to provide the encoder with an opportunity to perform any necessary resource allocation before it begins encoding frames.
This optional call can be used to provide the encoder an opportunity to allocate any resources necessary before it begins encoding frames. If this isn’t called, any necessary resources will be allocated on the first VTCompressionSessionEncodeFrame call. Extra calls to this function will have no effect.
Parameter session: The compression session.
Sourcepub unsafe fn encode_frame(
&self,
image_buffer: &CVImageBuffer,
presentation_time_stamp: CMTime,
duration: CMTime,
frame_properties: Option<&CFDictionary>,
source_frame_refcon: *mut c_void,
info_flags_out: *mut VTEncodeInfoFlags,
) -> i32
Available on crate features VTErrors and objc2-core-media and objc2-core-video only.
pub unsafe fn encode_frame( &self, image_buffer: &CVImageBuffer, presentation_time_stamp: CMTime, duration: CMTime, frame_properties: Option<&CFDictionary>, source_frame_refcon: *mut c_void, info_flags_out: *mut VTEncodeInfoFlags, ) -> i32
VTErrors and objc2-core-media and objc2-core-video only.Call this function to present frames to the compression session. Encoded frames may or may not be output before the function returns.
The client should not modify the pixel data after making this call. The session and/or encoder will retain the image buffer as long as necessary.
Parameter session: The compression session.
Parameter imageBuffer: A CVImageBuffer containing a video frame to be compressed.
Must have a nonzero reference count.
Parameter presentationTimeStamp: The presentation timestamp for this frame, to be attached to the sample buffer.
Each presentation timestamp passed to a session must be greater than the previous one.
Parameter duration: The presentation duration for this frame, to be attached to the sample buffer.
If you do not have duration information, pass kCMTimeInvalid.
Parameter frameProperties: Contains key/value pairs specifying additional properties for encoding this frame.
Note that some session properties may also be changed between frames.
Such changes have effect on subsequently encoded frames.
Parameter sourceFrameRefcon: Your reference value for the frame, which will be passed to the output callback function.
Parameter infoFlagsOut: Points to a VTEncodeInfoFlags to receive information about the encode operation.
The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
asynchronously.
The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
Pass NULL if you do not want to receive this information.
§Safety
frame_propertiesgenerics must be of the correct type.source_frame_refconmust be a valid pointer or null.info_flags_outmust be a valid pointer or null.
Source§impl VTCompressionSession
impl VTCompressionSession
Sourcepub unsafe fn encode_frame_with_output_handler(
&self,
image_buffer: &CVImageBuffer,
presentation_time_stamp: CMTime,
duration: CMTime,
frame_properties: Option<&CFDictionary>,
info_flags_out: *mut VTEncodeInfoFlags,
output_handler: VTCompressionOutputHandler,
) -> i32
Available on crate features VTErrors and block2 and objc2-core-media and objc2-core-video only.
pub unsafe fn encode_frame_with_output_handler( &self, image_buffer: &CVImageBuffer, presentation_time_stamp: CMTime, duration: CMTime, frame_properties: Option<&CFDictionary>, info_flags_out: *mut VTEncodeInfoFlags, output_handler: VTCompressionOutputHandler, ) -> i32
VTErrors and block2 and objc2-core-media and objc2-core-video only.Call this function to present frames to the compression session. Encoded frames may or may not be output before the function returns.
The client should not modify the pixel data after making this call. The session and/or encoder will retain the image buffer as long as necessary. Cannot be called with a session created with a VTCompressionOutputCallback.
Parameter session: The compression session.
Parameter imageBuffer: A CVImageBuffer containing a video frame to be compressed.
Must have a nonzero reference count.
Parameter presentationTimeStamp: The presentation timestamp for this frame, to be attached to the sample buffer.
Each presentation timestamp passed to a session must be greater than the previous one.
Parameter duration: The presentation duration for this frame, to be attached to the sample buffer.
If you do not have duration information, pass kCMTimeInvalid.
Parameter frameProperties: Contains key/value pairs specifying additional properties for encoding this frame.
Note that some session properties may also be changed between frames.
Such changes have effect on subsequently encoded frames.
Parameter infoFlagsOut: Points to a VTEncodeInfoFlags to receive information about the encode operation.
The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
asynchronously.
The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
Pass NULL if you do not want to receive this information.
Parameter outputHandler: The block to be called when encoding the frame is completed.
This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeFrameWithOutputHandler.
§Safety
frame_propertiesgenerics must be of the correct type.info_flags_outmust be a valid pointer or null.output_handlermust be a valid pointer.
Sourcepub unsafe fn complete_frames(
&self,
complete_until_presentation_time_stamp: CMTime,
) -> i32
Available on crate feature objc2-core-media only.
pub unsafe fn complete_frames( &self, complete_until_presentation_time_stamp: CMTime, ) -> i32
objc2-core-media only.Forces the compression session to complete encoding frames.
If completeUntilPresentationTimeStamp is numeric, frames with presentation timestamps up to and including this timestamp will be emitted before the function returns. If completeUntilPresentationTimeStamp is non-numeric, all pending frames will be emitted before the function returns.
Source§impl VTCompressionSession
impl VTCompressionSession
Sourcepub unsafe fn encode_multi_image_frame(
&self,
tagged_buffer_group: &CMTaggedBufferGroup,
presentation_time_stamp: CMTime,
duration: CMTime,
frame_properties: Option<&CFDictionary>,
source_frame_refcon: *mut c_void,
info_flags_out: *mut VTEncodeInfoFlags,
) -> i32
Available on crate features VTErrors and objc2-core-media only.
pub unsafe fn encode_multi_image_frame( &self, tagged_buffer_group: &CMTaggedBufferGroup, presentation_time_stamp: CMTime, duration: CMTime, frame_properties: Option<&CFDictionary>, source_frame_refcon: *mut c_void, info_flags_out: *mut VTEncodeInfoFlags, ) -> i32
VTErrors and objc2-core-media only.Call this function to present a multi-image frame to the compression session. Encoded frames may or may not be output before the function returns.
The client should not modify the pixel data after making this call. The session and/or encoder will retain the image buffer as long as necessary.
Parameter session: The compression session.
Parameter taggedBufferGroup: A CMTaggedBufferGroup containing the multiple images for a video frame to be compressed.
Parameter presentationTimeStamp: The presentation timestamp for this frame, to be attached to the sample buffer.
Each presentation timestamp passed to a session must be greater than the previous one.
Parameter duration: The presentation duration for this frame, to be attached to the sample buffer.
If you do not have duration information, pass kCMTimeInvalid.
Parameter frameProperties: Contains key/value pairs specifying additional properties for encoding this frame.
Note that some session properties may also be changed between frames.
Such changes have effect on subsequently encoded frames.
Parameter sourceFrameRefcon: Your reference value for the frame, which will be passed to the output callback function.
Parameter infoFlagsOut: Points to a VTEncodeInfoFlags to receive information about the encode operation.
The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
asynchronously.
The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
Pass NULL if you do not want to receive this information.
§Safety
frame_propertiesgenerics must be of the correct type.source_frame_refconmust be a valid pointer or null.info_flags_outmust be a valid pointer or null.
Sourcepub unsafe fn encode_multi_image_frame_with_output_handler(
&self,
tagged_buffer_group: &CMTaggedBufferGroup,
presentation_time_stamp: CMTime,
duration: CMTime,
frame_properties: Option<&CFDictionary>,
info_flags_out: *mut VTEncodeInfoFlags,
output_handler: VTCompressionOutputHandler,
) -> i32
Available on crate features VTErrors and block2 and objc2-core-media only.
pub unsafe fn encode_multi_image_frame_with_output_handler( &self, tagged_buffer_group: &CMTaggedBufferGroup, presentation_time_stamp: CMTime, duration: CMTime, frame_properties: Option<&CFDictionary>, info_flags_out: *mut VTEncodeInfoFlags, output_handler: VTCompressionOutputHandler, ) -> i32
VTErrors and block2 and objc2-core-media only.Call this function to present a multi-image frame to the compression session. Encoded frames may or may not be output before the function returns.
The client should not modify the pixel data after making this call. The session and/or encoder will retain the image buffer as long as necessary. Cannot be called with a session created with a VTCompressionOutputCallback.
Parameter session: The compression session.
Parameter taggedBufferGroup: A CMTaggedBufferGroup containing the multiple images for a video frame to be compressed.
Parameter presentationTimeStamp: The presentation timestamp for this frame, to be attached to the sample buffer.
Each presentation timestamp passed to a session must be greater than the previous one.
Parameter duration: The presentation duration for this frame, to be attached to the sample buffer.
If you do not have duration information, pass kCMTimeInvalid.
Parameter frameProperties: Contains key/value pairs specifying additional properties for encoding this frame.
Note that some session properties may also be changed between frames.
Such changes have effect on subsequently encoded frames.
Parameter infoFlagsOut: Points to a VTEncodeInfoFlags to receive information about the encode operation.
The kVTEncodeInfo_Asynchronous bit may be set if the encode is (or was) running
asynchronously.
The kVTEncodeInfo_FrameDropped bit may be set if the frame was dropped (synchronously).
Pass NULL if you do not want to receive this information.
Parameter outputHandler: The block to be called when encoding the frame is completed.
This block may be called asynchronously, on a different thread from the one that calls VTCompressionSessionEncodeMultiImageFrameWithOutputHandler.
§Safety
frame_propertiesgenerics must be of the correct type.info_flags_outmust be a valid pointer or null.output_handlermust be a valid pointer.
Source§impl VTCompressionSession
impl VTCompressionSession
Sourcepub unsafe fn begin_pass(
&self,
begin_pass_flags: VTCompressionSessionOptionFlags,
reserved: *mut u32,
) -> i32
pub unsafe fn begin_pass( &self, begin_pass_flags: VTCompressionSessionOptionFlags, reserved: *mut u32, ) -> i32
Call to announce the start of a specific compression pass.
During multi-pass encoding, this function must be called before VTCompressionSessionEncodeFrame. It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage.
Parameter beginPassFlags: Pass kVTCompressionSessionBeginFinalPass to inform the encoder that the pass must be the final pass.
§Safety
reserved must be a valid pointer or null.
Sourcepub unsafe fn end_pass(
&self,
further_passes_requested_out: *mut u8,
reserved: *mut u32,
) -> i32
pub unsafe fn end_pass( &self, further_passes_requested_out: *mut u8, reserved: *mut u32, ) -> i32
Call to announce the end of a pass.
VTCompressionSessionEndPass can take a long time, since the video encoder may perform significant processing between passes. 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. It is an error to call this function when multi-pass encoding has not been enabled by setting kVTCompressionPropertyKey_MultiPassStorage.
Parameter furtherPassesRequestedOut: Points to a Boolean that will be set to true if the video encoder would like to perform another pass, false otherwise.
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.
§Safety
further_passes_requested_outmust be a valid pointer or null.reservedmust be a valid pointer or null.
Sourcepub unsafe fn time_ranges_for_next_pass(
&self,
time_range_count_out: NonNull<CMItemCount>,
time_range_array_out: NonNull<*const CMTimeRange>,
) -> i32
Available on crate feature objc2-core-media only.
pub unsafe fn time_ranges_for_next_pass( &self, time_range_count_out: NonNull<CMItemCount>, time_range_array_out: NonNull<*const CMTimeRange>, ) -> i32
objc2-core-media only.Retrieves the time ranges for the next pass.
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. Each time range is considered to include any frame at its start time and not to include any frame at its end time. 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.
Parameter timeRangeCountOut: Points to a CMItemCount to receive the number of CMTimeRanges.
Parameter timeRangeArrayOut: Points to a const CMTimeRange * to receive a pointer to a C array of CMTimeRanges.
The storage for this array belongs to the VTCompressionSession and should not be modified.
The pointer will be valid until the next call to VTCompressionSessionEndPass, or until the VTCompressionSession is invalidated or finalized.
§Safety
time_range_count_outmust be a valid pointer.time_range_array_outmust be a valid pointer.
Methods from Deref<Target = CFType>§
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: ConcreteType,
Available on crate feature VTSession only.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: ConcreteType,
VTSession only.Attempt to downcast the type to that of type T.
This is the reference-variant. Use CFRetained::downcast if you
want to convert a retained type. See also ConcreteType for more
details on which types support being converted to.
Sourcepub fn retain_count(&self) -> usize
Available on crate feature VTSession only.
pub fn retain_count(&self) -> usize
VTSession only.Get the reference count of the object.
This function may be useful for debugging. You normally do not use this function otherwise.
Beware that some things (like CFNumbers, small CFStrings etc.) may
not have a normal retain count for optimization purposes, and can
return usize::MAX in that case.
Trait Implementations§
Source§impl AsRef<AnyObject> for VTCompressionSession
impl AsRef<AnyObject> for VTCompressionSession
Source§impl AsRef<CFType> for VTCompressionSession
impl AsRef<CFType> for VTCompressionSession
Source§impl Borrow<AnyObject> for VTCompressionSession
impl Borrow<AnyObject> for VTCompressionSession
Source§impl Borrow<CFType> for VTCompressionSession
impl Borrow<CFType> for VTCompressionSession
Source§impl ConcreteType for VTCompressionSession
impl ConcreteType for VTCompressionSession
Source§impl Debug for VTCompressionSession
impl Debug for VTCompressionSession
Source§impl Deref for VTCompressionSession
impl Deref for VTCompressionSession
Source§impl Hash for VTCompressionSession
impl Hash for VTCompressionSession
Source§impl Message for VTCompressionSession
impl Message for VTCompressionSession
Source§impl PartialEq for VTCompressionSession
impl PartialEq for VTCompressionSession
Source§impl RefEncode for VTCompressionSession
impl RefEncode for VTCompressionSession
Source§const ENCODING_REF: Encoding
const ENCODING_REF: Encoding
Source§impl Type for VTCompressionSession
impl Type for VTCompressionSession
Source§fn retain(&self) -> CFRetained<Self>where
Self: Sized,
fn retain(&self) -> CFRetained<Self>where
Self: Sized,
Source§fn as_concrete_TypeRef(&self) -> &Self
fn as_concrete_TypeRef(&self) -> &Self
core-foundation crate.Source§unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
unsafe fn wrap_under_get_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
core-foundation crate. Read moreSource§fn as_CFTypeRef(&self) -> &CFType
fn as_CFTypeRef(&self) -> &CFType
core-foundation crate.Source§unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
unsafe fn wrap_under_create_rule(ptr: *const Self) -> CFRetained<Self>where
Self: Sized,
core-foundation crate. Read more