objc2_video_toolbox/generated/VTMotionEstimationSession.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-video")]
11use objc2_core_video::*;
12
13use crate::*;
14
15/// Flags to control processing of a frame you pass to the motion-estimation session.
16///
17/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtmotionestimationframeflags?language=objc)
18// NS_OPTIONS
19#[repr(transparent)]
20#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
21pub struct VTMotionEstimationFrameFlags(pub u32);
22bitflags::bitflags! {
23 impl VTMotionEstimationFrameFlags: u32 {
24/// A hint to the motion-estimation session that you are going to reuse the `currentBuffer` as `referenceBuffer` in
25/// the next call to ``VTMotionEstimationSessionEstimateMotionVectors``. Using this flag allows the motion-estimation
26/// processor to deliver better performance.
27 #[doc(alias = "kVTMotionEstimationFrameFlags_CurrentBufferWillBeNextReferenceBuffer")]
28 const CurrentBufferWillBeNextReferenceBuffer = 1<<0;
29 }
30}
31
32#[cfg(feature = "objc2")]
33unsafe impl Encode for VTMotionEstimationFrameFlags {
34 const ENCODING: Encoding = u32::ENCODING;
35}
36
37#[cfg(feature = "objc2")]
38unsafe impl RefEncode for VTMotionEstimationFrameFlags {
39 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
40}
41
42/// Directives that provide information back to you with the results of motion-estimation.
43///
44/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtmotionestimationinfoflags?language=objc)
45// NS_OPTIONS
46#[repr(transparent)]
47#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
48pub struct VTMotionEstimationInfoFlags(pub u32);
49bitflags::bitflags! {
50 impl VTMotionEstimationInfoFlags: u32 {
51 #[doc(alias = "kVTMotionEstimationInfoFlags_Reserved0")]
52 const Reserved0 = 1<<0;
53 }
54}
55
56#[cfg(feature = "objc2")]
57unsafe impl Encode for VTMotionEstimationInfoFlags {
58 const ENCODING: Encoding = u32::ENCODING;
59}
60
61#[cfg(feature = "objc2")]
62unsafe impl RefEncode for VTMotionEstimationInfoFlags {
63 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
64}
65
66/// A reference to a Video Toolbox motion-estimation session.
67///
68/// A motion-estimation session supports two `CVPixelBuffer`s of the same size and type, and returns motion vectors in
69/// the form of a ``CVPixelBuffer``. The session is a reference-counted CF object. To create a motion-estimation session,
70/// call ``VTMotionEstimationSessionCreate``; then you can optionally configure the session using `VTSessionSetProperty`.
71/// To create motion-estimations, call ``VTMotionEstimationSessionCreateMotionEstimation``. When you are done with the
72/// session, you should call ``VTMotionEstimationSessionInvalidate`` to tear it down and ``CFRelease`` to release the
73/// session object reference.
74///
75/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtmotionestimationsession?language=objc)
76#[doc(alias = "VTMotionEstimationSessionRef")]
77#[repr(C)]
78pub struct VTMotionEstimationSession {
79 inner: [u8; 0],
80 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
81}
82
83cf_type!(
84 unsafe impl VTMotionEstimationSession {}
85);
86#[cfg(feature = "objc2")]
87cf_objc2_type!(
88 unsafe impl RefEncode<"OpaqueVTMotionEstimationSession"> for VTMotionEstimationSession {}
89);
90
91unsafe impl ConcreteType for VTMotionEstimationSession {
92 /// Get the CoreFoundation type identifier for motion-estimation session type.
93 #[doc(alias = "VTMotionEstimationSessionGetTypeID")]
94 #[inline]
95 fn type_id() -> CFTypeID {
96 extern "C-unwind" {
97 fn VTMotionEstimationSessionGetTypeID() -> CFTypeID;
98 }
99 unsafe { VTMotionEstimationSessionGetTypeID() }
100 }
101}
102
103impl VTMotionEstimationSession {
104 /// Creates a session you use to generate a pixel buffer of motion vectors from two pixel buffers.
105 ///
106 /// The function creates a session for computing motion vectors between two pixel buffers.
107 ///
108 /// - Parameters:
109 /// - allocator: An allocator for the session. Pass NULL to use the default allocator.
110 /// - motionVectorProcessorSelectionOptions: Available creation options are:
111 /// - term ``kVTMotionEstimationSessionCreationOption_MotionVectorSize``: Size of the search block.
112 /// - term ``kVTMotionEstimationSessionCreationOption_UseMultiPassSearch``: Use multiple passes to detect true motion.
113 /// - term ``kVTMotionEstimationSessionCreationOption_Label``: Label used for logging and resource tracking.
114 /// - width: The width of frames in pixels.
115 /// - height: The height of frames in pixels.
116 /// - motionEstimationSessionOut: Points to a variable to receive the new motion-estimation session.
117 ///
118 /// # Safety
119 ///
120 /// - `motion_vector_processor_selection_options` generics must be of the correct type.
121 /// - `motion_estimation_session_out` must be a valid pointer.
122 #[doc(alias = "VTMotionEstimationSessionCreate")]
123 #[inline]
124 pub unsafe fn create(
125 allocator: Option<&CFAllocator>,
126 motion_vector_processor_selection_options: Option<&CFDictionary>,
127 width: u32,
128 height: u32,
129 motion_estimation_session_out: NonNull<*mut VTMotionEstimationSession>,
130 ) -> OSStatus {
131 extern "C-unwind" {
132 fn VTMotionEstimationSessionCreate(
133 allocator: Option<&CFAllocator>,
134 motion_vector_processor_selection_options: Option<&CFDictionary>,
135 width: u32,
136 height: u32,
137 motion_estimation_session_out: NonNull<*mut VTMotionEstimationSession>,
138 ) -> OSStatus;
139 }
140 unsafe {
141 VTMotionEstimationSessionCreate(
142 allocator,
143 motion_vector_processor_selection_options,
144 width,
145 height,
146 motion_estimation_session_out,
147 )
148 }
149 }
150
151 /// Copies the attributes for source pixel buffers expected by motion-estimation session.
152 ///
153 /// This function provides a `CFDictionary` of attributes that you must release. Use this function to query
154 /// ``VTMotionEstimationSession`` for the native source attributes. If you provide an input ``CVPixelBuffer`` that is
155 /// not compatible with the attributes that this function returns, ``VTMotionEstimationSession`` automatically
156 /// converts the input pixel buffer into a compatible pixel buffer for processing.
157 ///
158 /// - Parameters:
159 /// - session: The motion-estimation session.
160 /// - attributesOut: Points to a variable to receive the attributes dictionary.
161 ///
162 /// # Safety
163 ///
164 /// `attributes_out` must be a valid pointer.
165 #[doc(alias = "VTMotionEstimationSessionCopySourcePixelBufferAttributes")]
166 #[inline]
167 pub unsafe fn copy_source_pixel_buffer_attributes(
168 &self,
169 attributes_out: NonNull<*const CFDictionary>,
170 ) -> OSStatus {
171 extern "C-unwind" {
172 fn VTMotionEstimationSessionCopySourcePixelBufferAttributes(
173 motion_estimation_session: &VTMotionEstimationSession,
174 attributes_out: NonNull<*const CFDictionary>,
175 ) -> OSStatus;
176 }
177 unsafe { VTMotionEstimationSessionCopySourcePixelBufferAttributes(self, attributes_out) }
178 }
179
180 /// Tears down a motion-estimation session.
181 ///
182 /// When you are done with a motion-estimation session you created, call this function to tear
183 /// it down and then `CFRelease` to release the session object reference. When a motion-estimation session's retain count
184 /// reaches zero, the system automatically invalidates it, but because multiple parties may retain sessions, it can be
185 /// hard to predict when this happens. Calling this function ensures a deterministic, orderly teardown.
186 #[doc(alias = "VTMotionEstimationSessionInvalidate")]
187 #[inline]
188 pub unsafe fn invalidate(&self) {
189 extern "C-unwind" {
190 fn VTMotionEstimationSessionInvalidate(session: &VTMotionEstimationSession);
191 }
192 unsafe { VTMotionEstimationSessionInvalidate(self) }
193 }
194}
195
196/// A block invoked by motion-estimation session when frame processing is complete.
197///
198/// When the client requests a motion-estimation, the client passes in a callback block that the system invokes for the
199/// result of that request. If the ``VTMotionEstimationSessionCreateMotionEstimation`` call returns an error, the system
200/// does not invoke this block.
201///
202/// - Parameters:
203/// - status: `noErr` if processing request was successful; an error code if motion-estimation was not successful.
204/// - infoFlags: A bit field that contains information about the processing operation.
205/// - additionalInfo: Additional processing information about the operation that cannot fit in `infoFlags`.
206/// Currently, the system expects this to be NULL.
207/// - motionVectorPixelBuffer: A `CVPixelBuffer` that contains the motion vector information, if processing request
208/// was successful; otherwise, NULL.
209///
210/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtmotionestimationoutputhandler?language=objc)
211#[cfg(all(feature = "block2", feature = "objc2-core-video"))]
212pub type VTMotionEstimationOutputHandler = *mut block2::DynBlock<
213 dyn Fn(OSStatus, VTMotionEstimationInfoFlags, *const CFDictionary, *mut CVPixelBuffer),
214>;
215
216impl VTMotionEstimationSession {
217 /// Creates a new pixel buffer that contains motion vectors between the input pixel buffers.
218 ///
219 /// The motion-estimation session compares the reference frame to the current frame, and generates motion vectors in
220 /// the form of a `CVPixelBuffer`.
221 ///
222 /// - Parameters:
223 /// - session: The motion-estimation session.
224 /// - referenceImage: The reference image.
225 /// - currentImage: The current image.
226 /// - motionEstimationFrameFlags: A bit field with per-frame options. See ``kVTMotionEstimationFrameFlags_CurrentBufferWillBeNextReferenceBuffer``.
227 /// - additionalFrameOptions: A way to pass additional information that doesn't fit in `motionEstimationFrameFlags`;
228 /// currently the system expects it to be `NULL`.
229 /// - outputHandler: The block invoked by the syetem when the processing request is completed. If the
230 /// `VTMotionEstimationSessionCreateMotionEstimation` call returns an error, the system does not invoke the block.
231 ///
232 /// - Returns: If the call was successful, returns `noErr`; otherwise, returns an error code, such as `kVTMotionEstimationNotSupportedErr`.
233 ///
234 /// # Safety
235 ///
236 /// - `additional_frame_options` generics must be of the correct type.
237 /// - `output_handler` must be a valid pointer.
238 #[doc(alias = "VTMotionEstimationSessionEstimateMotionVectors")]
239 #[cfg(all(feature = "block2", feature = "objc2-core-video"))]
240 #[inline]
241 pub unsafe fn estimate_motion_vectors(
242 &self,
243 reference_image: &CVPixelBuffer,
244 current_image: &CVPixelBuffer,
245 motion_estimation_frame_flags: VTMotionEstimationFrameFlags,
246 additional_frame_options: Option<&CFDictionary>,
247 output_handler: VTMotionEstimationOutputHandler,
248 ) -> OSStatus {
249 extern "C-unwind" {
250 fn VTMotionEstimationSessionEstimateMotionVectors(
251 session: &VTMotionEstimationSession,
252 reference_image: &CVPixelBuffer,
253 current_image: &CVPixelBuffer,
254 motion_estimation_frame_flags: VTMotionEstimationFrameFlags,
255 additional_frame_options: Option<&CFDictionary>,
256 output_handler: VTMotionEstimationOutputHandler,
257 ) -> OSStatus;
258 }
259 unsafe {
260 VTMotionEstimationSessionEstimateMotionVectors(
261 self,
262 reference_image,
263 current_image,
264 motion_estimation_frame_flags,
265 additional_frame_options,
266 output_handler,
267 )
268 }
269 }
270
271 /// Directs the motion-estimation session to emit all pending frames and waits for completion.
272 ///
273 /// Directs the motion-estimation session to emit all pending frames, then waits for all outstanding requests to complete, then returns.
274 #[doc(alias = "VTMotionEstimationSessionCompleteFrames")]
275 #[inline]
276 pub unsafe fn complete_frames(&self) -> OSStatus {
277 extern "C-unwind" {
278 fn VTMotionEstimationSessionCompleteFrames(
279 session: &VTMotionEstimationSession,
280 ) -> OSStatus;
281 }
282 unsafe { VTMotionEstimationSessionCompleteFrames(self) }
283 }
284}
285
286extern "C-unwind" {
287 #[deprecated = "renamed to `VTMotionEstimationSession::create`"]
288 pub fn VTMotionEstimationSessionCreate(
289 allocator: Option<&CFAllocator>,
290 motion_vector_processor_selection_options: Option<&CFDictionary>,
291 width: u32,
292 height: u32,
293 motion_estimation_session_out: NonNull<*mut VTMotionEstimationSession>,
294 ) -> OSStatus;
295}
296
297extern "C-unwind" {
298 #[deprecated = "renamed to `VTMotionEstimationSession::copy_source_pixel_buffer_attributes`"]
299 pub fn VTMotionEstimationSessionCopySourcePixelBufferAttributes(
300 motion_estimation_session: &VTMotionEstimationSession,
301 attributes_out: NonNull<*const CFDictionary>,
302 ) -> OSStatus;
303}
304
305extern "C-unwind" {
306 #[deprecated = "renamed to `VTMotionEstimationSession::invalidate`"]
307 pub fn VTMotionEstimationSessionInvalidate(session: &VTMotionEstimationSession);
308}
309
310extern "C-unwind" {
311 #[cfg(all(feature = "block2", feature = "objc2-core-video"))]
312 #[deprecated = "renamed to `VTMotionEstimationSession::estimate_motion_vectors`"]
313 pub fn VTMotionEstimationSessionEstimateMotionVectors(
314 session: &VTMotionEstimationSession,
315 reference_image: &CVPixelBuffer,
316 current_image: &CVPixelBuffer,
317 motion_estimation_frame_flags: VTMotionEstimationFrameFlags,
318 additional_frame_options: Option<&CFDictionary>,
319 output_handler: VTMotionEstimationOutputHandler,
320 ) -> OSStatus;
321}
322
323extern "C-unwind" {
324 #[deprecated = "renamed to `VTMotionEstimationSession::complete_frames`"]
325 pub fn VTMotionEstimationSessionCompleteFrames(session: &VTMotionEstimationSession)
326 -> OSStatus;
327}