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