objc2_video_toolbox/generated/
VTPixelTransferSession.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/// A reference to a Video Toolbox Pixel Transfer Session.
16///
17/// A pixel transfer session supports the copying and/or conversion of
18/// images from source CVPixelBuffers to destination CVPixelBuffers.
19/// The session reference is a reference-counted CF object.
20/// To create a pixel transfer session, call VTPixelTransferSessionCreate;
21/// then you can optionally configure the session using VTSessionSetProperty;
22/// then to transfer pixels, call VTPixelTransferSessionTransferImage.
23/// When you are done with the session, you should call VTPixelTransferSessionInvalidate
24/// to tear it down and CFRelease to release your object reference.
25///
26/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtpixeltransfersession?language=objc)
27#[repr(C)]
28pub struct VTPixelTransferSession {
29    inner: [u8; 0],
30    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
31}
32
33cf_type!(
34    unsafe impl VTPixelTransferSession {}
35);
36#[cfg(feature = "objc2")]
37cf_objc2_type!(
38    unsafe impl RefEncode<"OpaqueVTPixelTransferSession"> for VTPixelTransferSession {}
39);
40
41impl VTPixelTransferSession {
42    /// Creates a session for transferring images between CVPixelBuffers.
43    ///
44    /// The function creates a session for transferring images between CVPixelBuffers.
45    ///
46    /// Parameter `allocator`: An allocator for the session.  Pass NULL to use the default allocator.
47    ///
48    /// Parameter `pixelTransferSessionOut`: Points to a variable to receive the new pixel transfer session.
49    #[doc(alias = "VTPixelTransferSessionCreate")]
50    #[inline]
51    pub unsafe fn create(
52        allocator: Option<&CFAllocator>,
53        pixel_transfer_session_out: NonNull<*mut VTPixelTransferSession>,
54    ) -> OSStatus {
55        extern "C-unwind" {
56            fn VTPixelTransferSessionCreate(
57                allocator: Option<&CFAllocator>,
58                pixel_transfer_session_out: NonNull<*mut VTPixelTransferSession>,
59            ) -> OSStatus;
60        }
61        unsafe { VTPixelTransferSessionCreate(allocator, pixel_transfer_session_out) }
62    }
63
64    /// Tears down a pixel transfer session.
65    ///
66    /// When you are done with a pixel transfer session you created, call VTPixelTransferSessionInvalidate
67    /// to tear it down and then CFRelease to release your object reference.
68    /// When a pixel transfer session's retain count reaches zero, it is automatically invalidated, but
69    /// since sessions may be retained by multiple parties, it can be hard to predict when this will happen.
70    /// Calling VTPixelTransferSessionInvalidate ensures a deterministic, orderly teardown.
71    #[doc(alias = "VTPixelTransferSessionInvalidate")]
72    #[inline]
73    pub unsafe fn invalidate(self: &VTPixelTransferSession) {
74        extern "C-unwind" {
75            fn VTPixelTransferSessionInvalidate(session: &VTPixelTransferSession);
76        }
77        unsafe { VTPixelTransferSessionInvalidate(self) }
78    }
79}
80
81unsafe impl ConcreteType for VTPixelTransferSession {
82    /// Returns the CFTypeID for pixel transfer sessions.
83    #[doc(alias = "VTPixelTransferSessionGetTypeID")]
84    #[inline]
85    fn type_id() -> CFTypeID {
86        extern "C-unwind" {
87            fn VTPixelTransferSessionGetTypeID() -> CFTypeID;
88        }
89        unsafe { VTPixelTransferSessionGetTypeID() }
90    }
91}
92
93impl VTPixelTransferSession {
94    /// Copies and/or converts an image from one pixel buffer to another.
95    ///
96    /// By default, the full width and height of sourceBuffer are scaled to the full
97    /// width and height of destinationBuffer.
98    /// By default, all existing attachments on destinationBuffer are removed and new attachments
99    /// are set describing the transferred image.  Unrecognised attachments on sourceBuffer will
100    /// be propagated to destinationBuffer.
101    /// Some properties will modify this behaviour; see VTPixelTransferProperties.h for more details.
102    ///
103    /// Parameter `session`: The pixel transfer session.
104    ///
105    /// Parameter `sourceBuffer`: The source buffer.
106    ///
107    /// Parameter `destinationBuffer`: The destination buffer.
108    ///
109    /// Returns: If the transfer was successful, noErr; otherwise an error code, such as kVTPixelTransferNotSupportedErr.
110    #[doc(alias = "VTPixelTransferSessionTransferImage")]
111    #[cfg(feature = "objc2-core-video")]
112    #[inline]
113    pub unsafe fn transfer_image(
114        self: &VTPixelTransferSession,
115        source_buffer: &CVPixelBuffer,
116        destination_buffer: &CVPixelBuffer,
117    ) -> OSStatus {
118        extern "C-unwind" {
119            fn VTPixelTransferSessionTransferImage(
120                session: &VTPixelTransferSession,
121                source_buffer: &CVPixelBuffer,
122                destination_buffer: &CVPixelBuffer,
123            ) -> OSStatus;
124        }
125        unsafe { VTPixelTransferSessionTransferImage(self, source_buffer, destination_buffer) }
126    }
127}
128
129extern "C-unwind" {
130    #[deprecated = "renamed to `VTPixelTransferSession::create`"]
131    pub fn VTPixelTransferSessionCreate(
132        allocator: Option<&CFAllocator>,
133        pixel_transfer_session_out: NonNull<*mut VTPixelTransferSession>,
134    ) -> OSStatus;
135}
136
137extern "C-unwind" {
138    #[deprecated = "renamed to `VTPixelTransferSession::invalidate`"]
139    pub fn VTPixelTransferSessionInvalidate(session: &VTPixelTransferSession);
140}
141
142extern "C-unwind" {
143    #[cfg(feature = "objc2-core-video")]
144    #[deprecated = "renamed to `VTPixelTransferSession::transfer_image`"]
145    pub fn VTPixelTransferSessionTransferImage(
146        session: &VTPixelTransferSession,
147        source_buffer: &CVPixelBuffer,
148        destination_buffer: &CVPixelBuffer,
149    ) -> OSStatus;
150}