objc2-video-toolbox 0.3.2

Bindings to the VideoToolbox framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::cell::UnsafeCell;
use core::ffi::*;
use core::marker::{PhantomData, PhantomPinned};
use core::ptr::NonNull;
#[cfg(feature = "objc2")]
use objc2::__framework_prelude::*;
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-video")]
use objc2_core_video::*;

use crate::*;

/// A reference to a Video Toolbox Pixel Rotation Session.
///
/// A pixel rotation session supports the rotating of images from source CVPixelBuffers to
/// destination CVPixelBuffers.  The session reference is a reference-counted CF object.
/// To create an image rotation session, call VTPixelRotationSessionCreate;
/// then you can optionally configure the session using VTSessionSetProperty;
/// then to transfer pixels, call VTPixelRotationSessionRotateImage.
/// When you are done with the session, you should call CFRelease to tear it down
/// and release your object reference.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/videotoolbox/vtpixelrotationsession?language=objc)
#[doc(alias = "VTPixelRotationSessionRef")]
#[repr(C)]
pub struct VTPixelRotationSession {
    inner: [u8; 0],
    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
}

cf_type!(
    unsafe impl VTPixelRotationSession {}
);
#[cfg(feature = "objc2")]
cf_objc2_type!(
    unsafe impl RefEncode<"OpaqueVTPixelRotationSession"> for VTPixelRotationSession {}
);

impl VTPixelRotationSession {
    /// Creates a session for rotating images between CVPixelBuffers.
    ///
    /// Parameter `allocator`: An allocator for the session.  Pass NULL to use the default allocator.
    ///
    /// Parameter `pixelRotationSessionOut`: Points to a variable to receive the new pixel rotation session.
    ///
    /// # Safety
    ///
    /// `pixel_rotation_session_out` must be a valid pointer.
    #[doc(alias = "VTPixelRotationSessionCreate")]
    #[inline]
    pub unsafe fn create(
        allocator: Option<&CFAllocator>,
        pixel_rotation_session_out: NonNull<*mut VTPixelRotationSession>,
    ) -> OSStatus {
        extern "C-unwind" {
            fn VTPixelRotationSessionCreate(
                allocator: Option<&CFAllocator>,
                pixel_rotation_session_out: NonNull<*mut VTPixelRotationSession>,
            ) -> OSStatus;
        }
        unsafe { VTPixelRotationSessionCreate(allocator, pixel_rotation_session_out) }
    }

    /// Tears down a pixel rotation session.
    ///
    /// When you are done with an image rotation session you created, call VTPixelRotationSessionInvalidate
    /// to tear it down and then CFRelease to release your object reference.
    /// When an pixel rotation 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 VTPixelRotationSessionInvalidate ensures a deterministic, orderly teardown.
    #[doc(alias = "VTPixelRotationSessionInvalidate")]
    #[inline]
    pub unsafe fn invalidate(&self) {
        extern "C-unwind" {
            fn VTPixelRotationSessionInvalidate(session: &VTPixelRotationSession);
        }
        unsafe { VTPixelRotationSessionInvalidate(self) }
    }
}

unsafe impl ConcreteType for VTPixelRotationSession {
    /// Returns the CFTypeID for pixel rotation sessions.
    #[doc(alias = "VTPixelRotationSessionGetTypeID")]
    #[inline]
    fn type_id() -> CFTypeID {
        extern "C-unwind" {
            fn VTPixelRotationSessionGetTypeID() -> CFTypeID;
        }
        unsafe { VTPixelRotationSessionGetTypeID() }
    }
}

impl VTPixelRotationSession {
    /// Rotates a pixel buffer.
    ///
    /// Rotates sourceBuffer and places the output in destinationBuffer.
    /// For 90 and 270 degree rotations, the width and height of destinationBuffer must be the inverse
    /// of sourceBuffer.
    /// For 180 degree rotations, the width and height of destinationBuffer and sourceBuffer must match.
    /// By default, all existing attachments on destinationBuffer are removed and new attachments
    /// are set describing the transferred image.  Unrecognised attachments on sourceBuffer will
    /// be propagated to destinationBuffer.
    /// Some properties may modify this behaviour; see VTPixelRotationProperties.h for more details.
    ///
    /// Parameter `session`: The pixel rotation session.
    ///
    /// Parameter `sourceBuffer`: The source buffer.
    ///
    /// Parameter `destinationBuffer`: The destination buffer.
    ///
    /// Returns: If the transfer was successful, noErr; otherwise an error code, such as kVTPixelRotationNotSupportedErr.
    #[doc(alias = "VTPixelRotationSessionRotateImage")]
    #[cfg(feature = "objc2-core-video")]
    #[inline]
    pub unsafe fn rotate_image(
        &self,
        source_buffer: &CVPixelBuffer,
        destination_buffer: &CVPixelBuffer,
    ) -> OSStatus {
        extern "C-unwind" {
            fn VTPixelRotationSessionRotateImage(
                session: &VTPixelRotationSession,
                source_buffer: &CVPixelBuffer,
                destination_buffer: &CVPixelBuffer,
            ) -> OSStatus;
        }
        unsafe { VTPixelRotationSessionRotateImage(self, source_buffer, destination_buffer) }
    }
}

extern "C-unwind" {
    #[deprecated = "renamed to `VTPixelRotationSession::create`"]
    pub fn VTPixelRotationSessionCreate(
        allocator: Option<&CFAllocator>,
        pixel_rotation_session_out: NonNull<*mut VTPixelRotationSession>,
    ) -> OSStatus;
}

extern "C-unwind" {
    #[deprecated = "renamed to `VTPixelRotationSession::invalidate`"]
    pub fn VTPixelRotationSessionInvalidate(session: &VTPixelRotationSession);
}

extern "C-unwind" {
    #[cfg(feature = "objc2-core-video")]
    #[deprecated = "renamed to `VTPixelRotationSession::rotate_image`"]
    pub fn VTPixelRotationSessionRotateImage(
        session: &VTPixelRotationSession,
        source_buffer: &CVPixelBuffer,
        destination_buffer: &CVPixelBuffer,
    ) -> OSStatus;
}