├── src ├── image_buffer.rs ├── display_link.rs ├── open_gl_es_texture.rs ├── metal_texture.rs ├── opengl_texture.rs ├── host_time.rs ├── pixel_buffer_io_surface.rs ├── open_gl_es_texture_cache.rs ├── metal_texture_cache.rs ├── opengl_buffer_pool.rs ├── return_.rs ├── opengl_buffer.rs ├── buffer.rs ├── opengl_texture_cache.rs ├── lib.rs ├── pixel_buffer_pool.rs ├── base.rs ├── pixel_format_description.rs └── pixel_buffer.rs ├── .gitignore ├── .travis.yml ├── Cargo.toml └── LICENSE /src/image_buffer.rs: -------------------------------------------------------------------------------- 1 | use crate::buffer::CVBufferRef; 2 | 3 | pub type CVImageBufferRef = CVBufferRef; 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | -------------------------------------------------------------------------------- /src/display_link.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | core_foundation_sys::base::CFTypeID, 3 | core_graphics::display::CGDirectDisplayID, 4 | CVReturn, CVTime, 5 | }; 6 | 7 | #[derive(Debug, Copy, Clone)] 8 | pub enum __CVDisplayLink { } 9 | pub type CVDisplayLinkRef = *mut __CVDisplayLink; 10 | 11 | extern "C" { 12 | pub fn CVDisplayLinkGetTypeID() -> CFTypeID; 13 | pub fn CVDisplayLinkCreateWithCGDisplay(displayID: CGDirectDisplayID, displayLinkOut: *mut CVDisplayLinkRef) -> CVReturn; 14 | pub fn CVDisplayLinkGetNominalOutputVideoRefreshPeriod(displayLink: CVDisplayLinkRef) -> CVTime; 15 | pub fn CVDisplayLinkRelease(displayLink: CVDisplayLinkRef); 16 | } 17 | -------------------------------------------------------------------------------- /src/open_gl_es_texture.rs: -------------------------------------------------------------------------------- 1 | use crate::core_foundation_sys::base::{ Boolean, CFTypeID }; 2 | 3 | use crate::{ 4 | GLenum, GLuint, 5 | image_buffer::CVImageBufferRef, 6 | }; 7 | 8 | 9 | pub type CVOpenGLESTextureRef = CVImageBufferRef; 10 | 11 | extern "C" { 12 | pub fn CVOpenGLESTextureGetTypeID() -> CFTypeID; 13 | 14 | pub fn CVOpenGLESTextureGetTarget(image: CVOpenGLESTextureRef) -> GLenum; 15 | 16 | pub fn CVOpenGLESTextureGetName(image: CVOpenGLESTextureRef) -> GLuint; 17 | 18 | pub fn CVOpenGLESTextureIsFlipped(image: CVOpenGLESTextureRef) -> Boolean; 19 | 20 | //pub fn CVOpenGLESTextureGetCleanTexCoords( image:CVOpenGLESTextureRef , 21 | // GLfloat lowerLeft[ 2], 22 | // GLfloat lowerRight[ 2], 23 | // GLfloat upperRight[ 2], 24 | // GLfloat upperLeft[ 2] ); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: rust 3 | cache: cargo 4 | 5 | matrix: 6 | fast_finish: false 7 | allow_failures: 8 | - rust: nightly 9 | os: osx 10 | os: 11 | - osx: 12 | osx_image: xcode10.1 13 | include: 14 | - name: "macOS Rust Stable" 15 | os: osx 16 | rust: stable 17 | script: 18 | - cargo build --release --all 19 | - cargo test --release --all 20 | - cargo test --release --all-features 21 | - cargo test --release --no-default-features 22 | - cargo doc --release --no-deps --all 23 | - name: "macOS Rust Nightly" 24 | os: osx 25 | rust: nightly 26 | script: 27 | - cargo build --release --all 28 | - cargo test --release --all 29 | - cargo test --release --all-features 30 | - cargo test --release --no-default-features 31 | - cargo doc --release --no-deps --all 32 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "core-video-sys" 3 | version = "0.1.4" 4 | authors = ["luozijun ", "michael.laifx "] 5 | description = "Bindings to CoreVideo.framework for macOS and iOS" 6 | license = "MIT" 7 | homepage = "https://github.com/luozijun/rust-core-video-sys" 8 | repository = "https://github.com/luozijun/rust-core-video-sys" 9 | documentation = "https://docs.rs/core-video-sys/*/x86_64-apple-darwin/core-video-sys" 10 | edition = "2018" 11 | 12 | [dependencies] 13 | cfg-if = "1.0" 14 | libc = "0.2" 15 | objc = "0.2" 16 | core-foundation-sys = "0.8" 17 | 18 | [dependencies.metal] 19 | version = "0.20" 20 | features = ["private"] 21 | optional = true 22 | 23 | [dependencies.core-graphics] 24 | version = "0.22" 25 | optional = true 26 | 27 | [features] 28 | default = [ "display_link", "metal" ] 29 | all = [ "display_link", "direct3d", "io_suface", "opengl" ] 30 | 31 | display_link = [ "opengl", "core-graphics" ] 32 | direct3d = [ ] 33 | io_suface = [ ] 34 | opengl = [ ] 35 | 36 | -------------------------------------------------------------------------------- /src/metal_texture.rs: -------------------------------------------------------------------------------- 1 | use crate::metal::Texture; 2 | use crate::core_foundation_sys::{ 3 | base::{ Boolean, CFTypeID, }, 4 | string::CFStringRef, 5 | }; 6 | 7 | use crate::{ 8 | image_buffer::CVImageBufferRef, 9 | }; 10 | 11 | 12 | pub type CVMetalTextureRef = CVImageBufferRef; 13 | 14 | extern "C" { 15 | pub static kCVMetalTextureUsage: CFStringRef; 16 | 17 | 18 | pub fn CVMetalTextureGetTypeID() -> CFTypeID; 19 | pub fn CVMetalTextureGetTexture(image: CVMetalTextureRef) -> Texture; 20 | pub fn CVMetalTextureIsFlipped(image: CVMetalTextureRef) -> Boolean; 21 | // CV_EXPORT void CVMetalTextureGetCleanTexCoords( CVMetalTextureRef CV_NONNULL image, 22 | // float lowerLeft[2], 23 | // float lowerRight[2], 24 | // float upperRight[2], 25 | // float upperLeft[2] ) API_AVAILABLE(macosx(10.11), ios(8.0), tvos(9.0)) __WATCHOS_PROHIBITED; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/opengl_texture.rs: -------------------------------------------------------------------------------- 1 | use crate::core_foundation_sys::{ 2 | base::{ Boolean, CFTypeID, }, 3 | }; 4 | 5 | use crate::{ 6 | GLenum, GLuint, 7 | image_buffer::CVImageBufferRef, 8 | }; 9 | 10 | 11 | pub type CVOpenGLTextureRef = CVImageBufferRef; 12 | 13 | 14 | extern "C" { 15 | pub fn CVOpenGLTextureGetTypeID() -> CFTypeID; 16 | pub fn CVOpenGLTextureRetain(texture: CVOpenGLTextureRef) -> CVOpenGLTextureRef; 17 | pub fn CVOpenGLTextureRelease(texture: CVOpenGLTextureRef); 18 | pub fn CVOpenGLTextureGetTarget(image: CVOpenGLTextureRef) -> GLenum; 19 | pub fn CVOpenGLTextureGetName(image: CVOpenGLTextureRef) -> GLuint; 20 | pub fn CVOpenGLTextureIsFlipped(image: CVOpenGLTextureRef) -> Boolean; 21 | // CV_EXPORT void CVOpenGLTextureGetCleanTexCoords( CVOpenGLTextureRef CV_NONNULL image, 22 | // GLfloat lowerLeft[2], 23 | // GLfloat lowerRight[2], 24 | // GLfloat upperRight[2], 25 | // GLfloat upperLeft[2] ) AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 26 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 寧靜 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/host_time.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::c_double; 2 | 3 | extern "C" { 4 | /// @function CVGetCurrentHostTime 5 | /// @abstract Retrieve the current value of the host time base. 6 | /// @discussion On Mac OS X, the host time base for CoreVideo and CoreAudio are identical, and the values returned from either API 7 | /// may be used interchangeably. 8 | /// @result The current host time. 9 | pub fn CVGetCurrentHostTime() -> u64; 10 | /// @function CVGetHostClockFrequency 11 | /// @abstract Retrieve the frequency of the host time base. 12 | /// @discussion On Mac OS X, the host time base for CoreVideo and CoreAudio are identical, and the values returned from either API 13 | /// may be used interchangeably. 14 | /// @result The current host frequency. 15 | pub fn CVGetHostClockFrequency() -> c_double; 16 | /// @function CVGetHostClockMinimumTimeDelta 17 | /// @abstract Retrieve the smallest possible increment in the host time base. 18 | /// @result The smallest valid increment in the host time base. 19 | pub fn CVGetHostClockMinimumTimeDelta() -> u32; 20 | } 21 | 22 | 23 | #[test] 24 | fn test_get_curr_time() { 25 | unsafe { 26 | assert!(CVGetCurrentHostTime() > 0); 27 | } 28 | } -------------------------------------------------------------------------------- /src/pixel_buffer_io_surface.rs: -------------------------------------------------------------------------------- 1 | use crate::core_foundation_sys::{ 2 | base::{ CFAllocatorRef, }, 3 | dictionary::CFDictionaryRef, 4 | string::CFStringRef, 5 | }; 6 | 7 | use crate::{ 8 | pixel_buffer::CVPixelBufferRef, 9 | return_::CVReturn, 10 | }; 11 | 12 | 13 | // https://developer.apple.com/documentation/iosurface/iosurfaceref?language=objc 14 | #[derive(Debug, Copy, Clone)] 15 | pub enum _IOSurface { } 16 | pub type IOSurfaceRef = *mut _IOSurface; 17 | 18 | 19 | extern "C" { 20 | pub static kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey: CFStringRef; 21 | pub static kCVPixelBufferIOSurfaceOpenGLFBOCompatibilityKey: CFStringRef; 22 | pub static kCVPixelBufferIOSurfaceCoreAnimationCompatibilityKey: CFStringRef; 23 | 24 | pub static kCVPixelBufferIOSurfaceOpenGLESTextureCompatibilityKey: CFStringRef; 25 | pub static kCVPixelBufferIOSurfaceOpenGLESFBOCompatibilityKey: CFStringRef; 26 | 27 | 28 | pub fn CVPixelBufferGetIOSurface(pixelBuffer: CVPixelBufferRef) -> IOSurfaceRef; 29 | pub fn CVPixelBufferCreateWithIOSurface(allocator: CFAllocatorRef, 30 | surface: IOSurfaceRef, 31 | pixelBufferAttributes: CFDictionaryRef, 32 | pixelBufferOut: *mut CVPixelBufferRef) -> CVReturn; 33 | } -------------------------------------------------------------------------------- /src/open_gl_es_texture_cache.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::size_t; 2 | use crate::objc::runtime::Object; 3 | use crate::core_foundation_sys::{ 4 | base::{ CFAllocatorRef, CFTypeRef }, 5 | dictionary::CFDictionaryRef, 6 | }; 7 | 8 | use crate::{ 9 | GLenum, GLint, GLsizei, 10 | return_::CVReturn, 11 | image_buffer::CVImageBufferRef, 12 | open_gl_es_texture::CVOpenGLESTextureRef, 13 | }; 14 | 15 | 16 | pub type CVOpenGLESTextureCacheRef = CFTypeRef; 17 | pub type CVEAGLContext = *mut Object; 18 | 19 | extern "C" { 20 | pub fn CVOpenGLESTextureCacheCreate( 21 | allocator: CFAllocatorRef, 22 | cacheAttributes: CFDictionaryRef, 23 | eaglContext: CVEAGLContext, 24 | textureAttributes: CFDictionaryRef, 25 | cacheOut: *mut CVOpenGLESTextureCacheRef, 26 | ) -> CVReturn; 27 | 28 | pub fn CVOpenGLESTextureCacheCreateTextureFromImage( 29 | allocator: CFAllocatorRef, 30 | textureCache: CVOpenGLESTextureCacheRef, 31 | sourceImage: CVImageBufferRef, 32 | textureAttributes: CFDictionaryRef, 33 | target: GLenum, 34 | internalFormat: GLint, 35 | width: GLsizei, 36 | height: GLsizei, 37 | format: GLenum, 38 | type_: GLenum, 39 | planeIndex: size_t, 40 | textureOut: *mut CVOpenGLESTextureRef, 41 | ) -> CVReturn; 42 | } 43 | -------------------------------------------------------------------------------- /src/metal_texture_cache.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::size_t; 2 | use crate::core_foundation_sys::{ 3 | base::{CFAllocatorRef, CFTypeID, CFTypeRef}, 4 | dictionary::CFDictionaryRef, 5 | string::CFStringRef, 6 | }; 7 | use crate::{ 8 | base::CVOptionFlags, 9 | image_buffer::CVImageBufferRef, 10 | metal_texture::CVMetalTextureRef, 11 | return_::CVReturn, 12 | }; 13 | 14 | 15 | pub type CVMetalTextureCacheRef = CFTypeRef; 16 | 17 | extern "C" { 18 | pub static kCVMetalTextureCacheMaximumTextureAgeKey: CFStringRef; 19 | 20 | 21 | pub fn CVMetalTextureCacheGetTypeID() -> CFTypeID; 22 | pub fn CVMetalTextureCacheCreate( 23 | allocator: CFAllocatorRef, 24 | cacheAttributes: CFDictionaryRef, 25 | metalDevice: metal::Device, 26 | textureAttributes: CFDictionaryRef, 27 | cacheOut: *mut CVMetalTextureCacheRef, 28 | ) -> CVReturn; 29 | pub fn CVMetalTextureCacheCreateTextureFromImage( 30 | allocator: CFAllocatorRef, 31 | textureCache: CVMetalTextureCacheRef, 32 | sourceImage: CVImageBufferRef, 33 | textureAttributes: CFDictionaryRef, 34 | pixelFormat: metal::MTLPixelFormat, 35 | width: size_t, 36 | height: size_t, 37 | planeIndex: size_t, 38 | textureOut: *mut CVMetalTextureRef, 39 | ) -> CVReturn; 40 | pub fn CVMetalTextureCacheFlush(textureCache: CVMetalTextureCacheRef, 41 | options: CVOptionFlags); 42 | } 43 | -------------------------------------------------------------------------------- /src/opengl_buffer_pool.rs: -------------------------------------------------------------------------------- 1 | use crate::core_foundation_sys::{ 2 | base::{ CFAllocatorRef, CFTypeID, }, 3 | dictionary::CFDictionaryRef, 4 | string::CFStringRef, 5 | }; 6 | 7 | use crate::{ 8 | return_::CVReturn, 9 | image_buffer::CVImageBufferRef, 10 | opengl_buffer::{ CVOpenGLBufferRef, }, 11 | }; 12 | 13 | 14 | pub type CVOpenGLBufferPoolRef = CVImageBufferRef; 15 | 16 | 17 | extern "C" { 18 | pub static kCVOpenGLBufferPoolMinimumBufferCountKey: CFStringRef; 19 | pub static kCVOpenGLBufferPoolMaximumBufferAgeKey: CFStringRef; 20 | 21 | pub fn CVOpenGLBufferPoolGetTypeID() -> CFTypeID; 22 | pub fn CVOpenGLBufferPoolRetain(openGLBufferPool: CVOpenGLBufferPoolRef) -> CVOpenGLBufferPoolRef; 23 | pub fn CVOpenGLBufferPoolRelease(openGLBufferPool: CVOpenGLBufferPoolRef); 24 | pub fn CVOpenGLBufferPoolCreate(allocator: CFAllocatorRef, 25 | poolAttributes: CFDictionaryRef, 26 | openGLBufferAttributes: CFDictionaryRef, 27 | poolOut: *mut CVOpenGLBufferPoolRef) -> CVReturn; 28 | pub fn CVOpenGLBufferPoolGetAttributes(pool: CVOpenGLBufferPoolRef) -> CFDictionaryRef; 29 | pub fn CVOpenGLBufferPoolCreateOpenGLBuffer(allocator: CFAllocatorRef, 30 | openGLBufferPool: CVOpenGLBufferPoolRef, 31 | openGLBufferOut: *mut CVOpenGLBufferRef) -> CVReturn; 32 | } -------------------------------------------------------------------------------- /src/return_.rs: -------------------------------------------------------------------------------- 1 | 2 | pub type CVReturn = i32; 3 | 4 | 5 | pub const kCVReturnSuccess: CVReturn = 0; 6 | pub const kCVReturnFirst: CVReturn = -6660; 7 | pub const kCVReturnError: CVReturn = kCVReturnFirst; 8 | pub const kCVReturnInvalidArgument: CVReturn = -6661; 9 | pub const kCVReturnAllocationFailed: CVReturn = -6662; 10 | pub const kCVReturnUnsupported: CVReturn = -6663; 11 | 12 | // DisplayLink related errors 13 | pub const kCVReturnInvalidDisplay: CVReturn = -6670; 14 | pub const kCVReturnDisplayLinkAlreadyRunning: CVReturn = -6671; 15 | pub const kCVReturnDisplayLinkNotRunning: CVReturn = -6672; 16 | pub const kCVReturnDisplayLinkCallbacksNotSet: CVReturn = -6673; 17 | 18 | // Buffer related errors 19 | pub const kCVReturnInvalidPixelFormat: CVReturn = -6680; 20 | pub const kCVReturnInvalidSize: CVReturn = -6681; 21 | pub const kCVReturnInvalidPixelBufferAttributes: CVReturn = -6682; 22 | pub const kCVReturnPixelBufferNotOpenGLCompatible: CVReturn = -6683; 23 | pub const kCVReturnPixelBufferNotMetalCompatible: CVReturn = -6684; 24 | 25 | // Buffer Pool related errors 26 | pub const kCVReturnWouldExceedAllocationThreshold: CVReturn = -6689; 27 | pub const kCVReturnPoolAllocationFailed: CVReturn = -6690; 28 | pub const kCVReturnInvalidPoolAttributes: CVReturn = -6691; 29 | pub const kCVReturnRetry: CVReturn = -6692; 30 | 31 | pub const kCVReturnLast: CVReturn = -669; 32 | -------------------------------------------------------------------------------- /src/opengl_buffer.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::size_t; 2 | use crate::core_foundation_sys::{ 3 | base::{ CFAllocatorRef, CFTypeID, }, 4 | dictionary::CFDictionaryRef, 5 | string::CFStringRef, 6 | }; 7 | use crate::{ 8 | GLenum, GLint, 9 | return_::CVReturn, 10 | image_buffer::CVImageBufferRef, 11 | }; 12 | 13 | 14 | pub type CVOpenGLBufferRef = CVImageBufferRef; 15 | // https://developer.apple.com/documentation/appkit/nsopenglcontext/1436158-cglcontextobj?language=objc 16 | pub type CGLContextObj = CVImageBufferRef; 17 | // https://developer.apple.com/documentation/appkit/nsopenglpixelformat/1436148-cglpixelformatobj 18 | pub type CGLPixelFormatObj = CVImageBufferRef; 19 | 20 | extern "C" { 21 | pub static kCVOpenGLBufferWidth: CFStringRef; 22 | pub static kCVOpenGLBufferHeight: CFStringRef; 23 | pub static kCVOpenGLBufferTarget: CFStringRef; 24 | pub static kCVOpenGLBufferInternalFormat: CFStringRef; 25 | pub static kCVOpenGLBufferMaximumMipmapLevel: CFStringRef; 26 | 27 | 28 | pub fn CVOpenGLBufferGetTypeID() -> CFTypeID; 29 | pub fn CVOpenGLBufferRetain(buffer: CVOpenGLBufferRef) -> CVOpenGLBufferRef; 30 | pub fn CVOpenGLBufferRelease(buffer: CVOpenGLBufferRef); 31 | pub fn CVOpenGLBufferCreate(allocator: CFAllocatorRef, 32 | width: size_t, 33 | height: size_t, 34 | attributes: CFDictionaryRef, 35 | bufferOut: *mut CVOpenGLBufferRef) -> CVReturn; 36 | pub fn CVOpenGLBufferGetAttributes(openGLBuffer: CVOpenGLBufferRef) -> CFDictionaryRef; 37 | pub fn CVOpenGLBufferAttach(openGLBuffer: CVOpenGLBufferRef, 38 | cglContext: CGLContextObj, 39 | face: GLenum, 40 | level: GLint, 41 | screen: GLint) -> CVReturn; 42 | } -------------------------------------------------------------------------------- /src/buffer.rs: -------------------------------------------------------------------------------- 1 | use crate::core_foundation_sys::{ 2 | base::{ CFTypeRef, }, 3 | string::CFStringRef, 4 | dictionary::CFDictionaryRef, 5 | }; 6 | 7 | 8 | 9 | #[derive(Debug, Copy, Clone)] 10 | pub enum __CVBuffer { } 11 | pub type CVBufferRef = *mut __CVBuffer; 12 | 13 | 14 | pub type CVAttachmentMode = u32; 15 | pub const kCVAttachmentMode_ShouldNotPropagate: CVAttachmentMode = 0; 16 | pub const kCVAttachmentMode_ShouldPropagate: CVAttachmentMode = 1; 17 | 18 | 19 | extern "C" { 20 | pub static kCVBufferPropagatedAttachmentsKey: CFStringRef; 21 | pub static kCVBufferNonPropagatedAttachmentsKey: CFStringRef; 22 | 23 | pub static kCVBufferMovieTimeKey: CFStringRef; 24 | pub static kCVBufferTimeValueKey: CFStringRef; 25 | pub static kCVBufferTimeScaleKey: CFStringRef; 26 | 27 | pub fn CVBufferRetain(buffer: CVBufferRef) -> CVBufferRef; 28 | pub fn CVBufferRelease(buffer: CVBufferRef); 29 | pub fn CVBufferSetAttachment(buffer: CVBufferRef, 30 | key: CFStringRef, 31 | value: CFTypeRef, 32 | attachmentMode: CVAttachmentMode); 33 | pub fn CVBufferGetAttachment(buffer: CVBufferRef, 34 | key: CFStringRef, 35 | attachmentMode: *mut CVAttachmentMode) -> CFTypeRef; 36 | pub fn CVBufferRemoveAttachment(buffer: CVBufferRef, 37 | key: CFStringRef); 38 | pub fn CVBufferRemoveAllAttachments(buffer: CVBufferRef); 39 | pub fn CVBufferGetAttachments(buffer: CVBufferRef, 40 | attachmentMode: CVAttachmentMode) -> CFDictionaryRef; 41 | pub fn CVBufferSetAttachments(buffer: CVBufferRef, 42 | theAttachments: CFDictionaryRef, 43 | attachmentMode: CVAttachmentMode); 44 | pub fn CVBufferPropagateAttachments(sourceBuffer: CVBufferRef, 45 | destinationBuffer: CVBufferRef); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/opengl_texture_cache.rs: -------------------------------------------------------------------------------- 1 | use crate::core_foundation_sys::{ 2 | base::{ CFAllocatorRef, CFTypeID, }, 3 | dictionary::CFDictionaryRef, 4 | string::CFStringRef, 5 | }; 6 | 7 | use crate::{ 8 | base::CVOptionFlags, 9 | return_::CVReturn, 10 | image_buffer::CVImageBufferRef, 11 | opengl_buffer::{ CGLContextObj, CGLPixelFormatObj, }, 12 | opengl_texture::CVOpenGLTextureRef, 13 | 14 | }; 15 | 16 | 17 | pub type CVOpenGLTextureCacheRef = CVImageBufferRef; 18 | 19 | 20 | extern "C" { 21 | pub static kCVOpenGLTextureCacheChromaSamplingModeKey: CFStringRef; 22 | pub static kCVOpenGLTextureCacheChromaSamplingModeAutomatic: CFStringRef; 23 | pub static kCVOpenGLTextureCacheChromaSamplingModeHighestQuality: CFStringRef; 24 | pub static kCVOpenGLTextureCacheChromaSamplingModeBestPerformance: CFStringRef; 25 | 26 | pub fn CVOpenGLTextureCacheGetTypeID() -> CFTypeID; 27 | pub fn CVOpenGLTextureCacheRetain(textureCache: CVOpenGLTextureCacheRef) -> CVOpenGLTextureCacheRef; 28 | pub fn CVOpenGLTextureCacheRelease(textureCache: CVOpenGLTextureCacheRef); 29 | pub fn CVOpenGLTextureCacheCreate(allocator: CFAllocatorRef, 30 | cacheAttributes: CFDictionaryRef, 31 | cglContext: CGLContextObj, 32 | cglPixelFormat: CGLPixelFormatObj, 33 | textureAttributes: CFDictionaryRef, 34 | cacheOut: *mut CVOpenGLTextureCacheRef) -> CVReturn; 35 | pub fn CVOpenGLTextureCacheCreateTextureFromImage(allocator: CFAllocatorRef, 36 | textureCache: CVOpenGLTextureCacheRef, 37 | sourceImage: CVImageBufferRef, 38 | attributes: CFDictionaryRef, 39 | textureOut: *mut CVOpenGLTextureRef) -> CVReturn; 40 | pub fn CVOpenGLTextureCacheFlush(textureCache: CVOpenGLTextureCacheRef, 41 | options: CVOptionFlags); 42 | } -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow( 2 | non_snake_case, 3 | non_camel_case_types, 4 | non_upper_case_globals, 5 | improper_ctypes 6 | )] 7 | 8 | #[macro_use] 9 | extern crate cfg_if; 10 | extern crate libc; 11 | extern crate objc; 12 | extern crate core_foundation_sys; 13 | 14 | 15 | #[cfg(any(target_os = "macos", target_os = "ios"))] 16 | #[link(name = "CoreVideo", kind = "framework")] 17 | extern "C" { } 18 | 19 | 20 | pub(crate) type OSType = u32; 21 | pub(crate) type GLenum = libc::c_uint; 22 | pub(crate) type GLsizei = libc::c_int; 23 | pub(crate) type GLint = libc::c_int; 24 | pub(crate) type GLuint = libc::c_uint; 25 | 26 | 27 | pub mod base; 28 | pub mod buffer; 29 | pub mod return_; 30 | pub mod image_buffer; 31 | pub mod pixel_buffer; 32 | pub mod pixel_buffer_pool; 33 | pub mod pixel_format_description; 34 | 35 | pub use self::base::*; 36 | pub use self::buffer::*; 37 | pub use self::return_::*; 38 | pub use self::image_buffer::*; 39 | pub use self::pixel_buffer::*; 40 | pub use self::pixel_buffer_pool::*; 41 | pub use self::pixel_format_description::*; 42 | 43 | cfg_if! { 44 | if #[cfg(feature = "metal")] { 45 | extern crate metal; 46 | 47 | pub mod metal_texture; 48 | pub mod metal_texture_cache; 49 | 50 | pub use self::metal_texture::*; 51 | pub use self::metal_texture_cache::*; 52 | } 53 | } 54 | 55 | cfg_if! { 56 | if #[cfg(feature = "display_link")] { 57 | extern crate core_graphics; 58 | 59 | pub mod host_time; 60 | pub mod display_link; 61 | 62 | pub use self::host_time::*; 63 | pub use self::display_link::*; 64 | } 65 | } 66 | 67 | cfg_if! { 68 | if #[cfg(feature = "opengl")] { 69 | pub mod opengl_buffer; 70 | pub mod opengl_buffer_pool; 71 | pub mod opengl_texture; 72 | pub mod opengl_texture_cache; 73 | 74 | pub use self::opengl_buffer::*; 75 | pub use self::opengl_buffer_pool::*; 76 | pub use self::opengl_texture::*; 77 | pub use self::opengl_texture_cache::*; 78 | } 79 | } 80 | 81 | cfg_if! { 82 | if #[cfg(feature = "io_suface")] { 83 | pub mod pixel_buffer_io_surface; 84 | 85 | pub use self::pixel_buffer_io_surface::*; 86 | } 87 | } 88 | 89 | 90 | pub mod open_gl_es_texture; 91 | pub mod open_gl_es_texture_cache; 92 | 93 | pub use self::open_gl_es_texture::*; 94 | pub use self::open_gl_es_texture_cache::*; 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/pixel_buffer_pool.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::{ c_void, }; 2 | use crate::core_foundation_sys::{ 3 | base::{ CFAllocatorRef, CFTypeID, CFTypeRef }, 4 | dictionary::CFDictionaryRef, 5 | string::CFStringRef, 6 | }; 7 | 8 | use crate::{ 9 | base::CVOptionFlags, 10 | pixel_buffer::CVPixelBufferRef, 11 | return_::CVReturn, 12 | 13 | }; 14 | 15 | 16 | pub type CVPixelBufferPoolRef = CFTypeRef; 17 | pub type CVPixelBufferPoolFlushFlags = CVOptionFlags; 18 | 19 | pub const kCVPixelBufferPoolFlushExcessBuffers: CVPixelBufferPoolFlushFlags = 1; 20 | 21 | extern "C" { 22 | pub static kCVPixelBufferPoolMinimumBufferCountKey: CFStringRef; 23 | pub static kCVPixelBufferPoolMaximumBufferAgeKey: CFStringRef; 24 | 25 | pub static kCVPixelBufferPoolAllocationThresholdKey: CFStringRef; 26 | pub static kCVPixelBufferPoolFreeBufferNotification: CFStringRef; 27 | 28 | pub fn CVPixelBufferPoolGetTypeID() -> CFTypeID; 29 | pub fn CVPixelBufferPoolRetain(pixelBufferPool: CVPixelBufferPoolRef) -> CVPixelBufferPoolRef; 30 | pub fn CVPixelBufferPoolRelease(pixelBufferPool: CVPixelBufferPoolRef) -> c_void; 31 | pub fn CVPixelBufferPoolCreate(allocator: CFAllocatorRef, 32 | poolAttributes: CFDictionaryRef, 33 | pixelBufferAttributes: CFDictionaryRef, 34 | poolOut: *mut CVPixelBufferPoolRef) -> CVReturn; 35 | pub fn CVPixelBufferPoolGetAttributes(pool: CVPixelBufferPoolRef) -> CFDictionaryRef; 36 | pub fn CVPixelBufferPoolGetPixelBufferAttributes(pool: CVPixelBufferPoolRef) -> CFDictionaryRef; 37 | pub fn CVPixelBufferPoolCreatePixelBuffer(allocator: CFAllocatorRef, 38 | pixelBufferPool: CVPixelBufferPoolRef, 39 | pixelBufferOut: *mut CVPixelBufferRef) -> CVReturn; 40 | pub fn CVPixelBufferPoolCreatePixelBufferWithAuxAttributes(allocator: CFAllocatorRef, 41 | pixelBufferPool: CVPixelBufferPoolRef, 42 | auxAttributes: CFDictionaryRef, 43 | pixelBufferOut: *mut CVPixelBufferRef) -> CVReturn; 44 | pub fn CVPixelBufferPoolFlush(pool: CVPixelBufferPoolRef, 45 | options: CVPixelBufferPoolFlushFlags); 46 | } -------------------------------------------------------------------------------- /src/base.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::c_double; 2 | 3 | 4 | // https://developer.apple.com/documentation/corevideo/cvoptionflags?language=objc 5 | pub type CVOptionFlags = u64; 6 | pub type CVSMPTETimeType = u32; 7 | pub type CVSMPTETimeFlags = u32; 8 | pub type CVTimeFlags = i32; 9 | pub type CVTimeStampFlags = u64; 10 | 11 | 12 | pub const kCVSMPTETimeType24: CVSMPTETimeType = 0; 13 | pub const kCVSMPTETimeType25: CVSMPTETimeType = 1; 14 | pub const kCVSMPTETimeType30Drop: CVSMPTETimeType = 2; 15 | pub const kCVSMPTETimeType30: CVSMPTETimeType = 3; 16 | pub const kCVSMPTETimeType2997: CVSMPTETimeType = 4; 17 | pub const kCVSMPTETimeType2997Drop: CVSMPTETimeType = 5; 18 | pub const kCVSMPTETimeType60: CVSMPTETimeType = 6; 19 | pub const kCVSMPTETimeType5994: CVSMPTETimeType = 7; 20 | 21 | pub const kCVSMPTETimeValid: CVSMPTETimeFlags = 1 << 0; 22 | pub const kCVSMPTETimeRunning: CVSMPTETimeFlags = 1 << 1; 23 | 24 | pub const kCVTimeIsIndefinite: CVTimeFlags = 1 << 0; 25 | 26 | 27 | #[repr(C)] 28 | #[derive(Debug, Clone)] 29 | pub struct CVSMPTETime { 30 | pub subframes: i16, 31 | pub subframeDivisor: i16, 32 | pub counter: u32, 33 | pub type_: u32, 34 | pub flags: u32, 35 | pub hours: i16, 36 | pub minutes: i16, 37 | pub seconds: i16, 38 | pub frames: i16, 39 | } 40 | 41 | 42 | #[repr(C)] 43 | #[derive(Debug, Clone)] 44 | pub struct CVTime { 45 | pub timeValue: i64, 46 | pub timeScale: i32, 47 | pub flags: i32 48 | } 49 | 50 | #[repr(C)] 51 | #[derive(Debug, Clone)] 52 | pub struct CVTimeStamp { 53 | pub version: u32, 54 | pub videoTimeScale: i32, 55 | pub videoTime: i64, 56 | pub hostTime: u64, 57 | pub rateScalar: c_double, 58 | pub videoRefreshPeriod: i64, 59 | pub smpteTime: CVSMPTETime, 60 | pub flags: u64, 61 | pub reserved: u64, 62 | } 63 | 64 | 65 | pub const kCVTimeStampVideoTimeValid: CVTimeStampFlags = 1 << 0; 66 | pub const kCVTimeStampHostTimeValid: CVTimeStampFlags = 1 << 1; 67 | pub const kCVTimeStampSMPTETimeValid: CVTimeStampFlags = 1 << 2; 68 | pub const kCVTimeStampVideoRefreshPeriodValid: CVTimeStampFlags = 1 << 3; 69 | pub const kCVTimeStampRateScalarValid: CVTimeStampFlags = 1 << 4; 70 | 71 | // There are flags for each field to make it easier to detect interlaced vs progressive output 72 | pub const kCVTimeStampTopField: CVTimeStampFlags = 1 << 16; 73 | pub const kCVTimeStampBottomField: CVTimeStampFlags = 1 << 17; 74 | 75 | // Some commonly used combinations of timestamp flags 76 | pub const kCVTimeStampVideoHostTimeValid: CVTimeStampFlags = kCVTimeStampVideoTimeValid | kCVTimeStampHostTimeValid; 77 | pub const kCVTimeStampIsInterlaced: CVTimeStampFlags = kCVTimeStampTopField | kCVTimeStampBottomField; 78 | 79 | 80 | extern "C" { 81 | pub static kCVZeroTime: CVTime; 82 | pub static kCVIndefiniteTime: CVTime; 83 | } 84 | -------------------------------------------------------------------------------- /src/pixel_format_description.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::{ c_void, }; 2 | use crate::core_foundation_sys::{ 3 | base::{ Boolean, CFAllocatorRef, CFIndex, }, 4 | dictionary::CFDictionaryRef, 5 | array::CFArrayRef, 6 | string::CFStringRef, 7 | }; 8 | 9 | use crate::{ 10 | OSType, 11 | pixel_buffer::CVPixelBufferRef, 12 | }; 13 | 14 | 15 | pub type CVFillExtendedPixelsCallBack = extern "C" fn (pixelBuffer: CVPixelBufferRef, 16 | refCon: *mut c_void) -> Boolean; 17 | 18 | 19 | #[repr(C)] 20 | #[derive(Debug, Clone, Copy)] 21 | pub struct CVFillExtendedPixelsCallBackData { 22 | pub version: CFIndex, 23 | pub fillCallBack: CVFillExtendedPixelsCallBack, 24 | pub refCon: *mut c_void, 25 | 26 | } 27 | 28 | 29 | extern "C" { 30 | pub static kCVPixelFormatName: CFStringRef; 31 | 32 | /// QuickTime/QuickDraw Pixel Format Type constant (OSType) 33 | pub static kCVPixelFormatConstant: CFStringRef; 34 | 35 | /// This is the codec type constant, i.e. '2vuy' or k422YpCbCr8CodecType 36 | pub static kCVPixelFormatCodecType: CFStringRef; 37 | 38 | /// This is the equivalent Microsoft FourCC code for this pixel format 39 | pub static kCVPixelFormatFourCC: CFStringRef; 40 | 41 | /// kCFBooleanTrue indicates that the format contains alpha and some images may be considered transparent 42 | /// kCFBooleanFalse indicates that there is no alpha and images are always opaque. 43 | pub static kCVPixelFormatContainsAlpha: CFStringRef; 44 | 45 | /// kCFBooleanTrue indicates that the format contains YCbCr data 46 | pub static kCVPixelFormatContainsYCbCr: CFStringRef; 47 | 48 | /// kCFBooleanTrue indicates that the format contains RGB data 49 | pub static kCVPixelFormatContainsRGB: CFStringRef; 50 | 51 | pub static kCVPixelFormatComponentRange: CFStringRef; 52 | 53 | pub static kCVPixelFormatComponentRange_VideoRange: CFStringRef; 54 | 55 | pub static kCVPixelFormatComponentRange_FullRange: CFStringRef; 56 | 57 | pub static kCVPixelFormatComponentRange_WideRange: CFStringRef; 58 | 59 | /// All buffers have one or more image planes. 60 | /// Each plane may contain a single or an interleaved set of components 61 | /// For simplicity sake, 62 | /// pixel formats that are not planar may place the required format keys at the top level dictionary. 63 | pub static kCVPixelFormatPlanes: CFStringRef; 64 | 65 | 66 | pub static kCVPixelFormatBlockWidth: CFStringRef; 67 | pub static kCVPixelFormatBlockHeight: CFStringRef; 68 | 69 | /// This value must be present. 70 | /// For simple pixel formats this will be equivalent to the traditional bitsPerPixel value. 71 | pub static kCVPixelFormatBitsPerBlock: CFStringRef; 72 | 73 | /// Used to state requirements on block multiples. v210 would be '8' here for the horizontal case, 74 | /// to match the standard v210 row alignment value of 48. 75 | /// These may be assumed as 1 if not present. 76 | pub static kCVPixelFormatBlockHorizontalAlignment: CFStringRef; 77 | pub static kCVPixelFormatBlockVerticalAlignment: CFStringRef; 78 | 79 | /// CFData containing the bit pattern for a block of black pixels. If absent, black is assumed to be all zeros. 80 | /// If present, this should be bitsPerPixel bits long -- if bitsPerPixel is less than a byte, repeat the bit pattern 81 | /// for the full byte. 82 | pub static kCVPixelFormatBlackBlock: CFStringRef; 83 | 84 | /// Subsampling information for this plane. Assumed to be '1' if not present. 85 | pub static kCVPixelFormatHorizontalSubsampling: CFStringRef; 86 | pub static kCVPixelFormatVerticalSubsampling: CFStringRef; 87 | 88 | /// If present, these two keys describe the OpenGL format and type enums you would use to describe this 89 | /// image plane to OpenGL 90 | pub static kCVPixelFormatOpenGLFormat: CFStringRef; 91 | pub static kCVPixelFormatOpenGLType: CFStringRef; 92 | pub static kCVPixelFormatOpenGLInternalFormat: CFStringRef; 93 | 94 | /// CGBitmapInfo value, if required 95 | pub static kCVPixelFormatCGBitmapInfo: CFStringRef; 96 | 97 | /// Pixel format compatibility flags 98 | pub static kCVPixelFormatQDCompatibility: CFStringRef; 99 | pub static kCVPixelFormatCGBitmapContextCompatibility: CFStringRef; 100 | pub static kCVPixelFormatCGImageCompatibility: CFStringRef; 101 | pub static kCVPixelFormatOpenGLCompatibility: CFStringRef; 102 | pub static kCVPixelFormatOpenGLESCompatibility: CFStringRef; 103 | 104 | pub static kCVPixelFormatFillExtendedPixelsCallback: CFStringRef; 105 | 106 | 107 | pub fn CVPixelFormatDescriptionCreateWithPixelFormatType(allocator: CFAllocatorRef, 108 | pixelFormat: OSType) -> CFDictionaryRef; 109 | pub fn CVPixelFormatDescriptionArrayCreateWithAllPixelFormatTypes(allocator: CFAllocatorRef) -> CFArrayRef; 110 | pub fn CVPixelFormatDescriptionRegisterDescriptionWithPixelFormatType(description: CFDictionaryRef, 111 | pixelFormat: OSType); 112 | } 113 | 114 | 115 | #[cfg(feature = "direct3d")] 116 | extern "C" { 117 | pub static kCVPixelFormatDirect3DFormat: CFStringRef; 118 | pub static kCVPixelFormatDirect3DType: CFStringRef; 119 | pub static kCVPixelFormatDirect3DInternalFormat: CFStringRef; 120 | pub static kCVPixelFormatDirect3DCompatibility: CFStringRef; 121 | } 122 | -------------------------------------------------------------------------------- /src/pixel_buffer.rs: -------------------------------------------------------------------------------- 1 | use crate::libc::{ c_void, size_t, }; 2 | use crate::core_foundation_sys::{ 3 | base::{ Boolean, CFAllocatorRef, CFTypeID }, 4 | dictionary::CFDictionaryRef, 5 | array::CFArrayRef, 6 | string::CFStringRef, 7 | }; 8 | 9 | use crate::{ 10 | OSType, 11 | base::CVOptionFlags, 12 | image_buffer::CVImageBufferRef, 13 | return_::CVReturn, 14 | }; 15 | 16 | 17 | const fn as_u32_be(array: &[u8; 4]) -> u32 { 18 | ((array[0] as u32) << 24) + 19 | ((array[1] as u32) << 16) + 20 | ((array[2] as u32) << 8) + 21 | ((array[3] as u32) << 0) 22 | } 23 | 24 | 25 | pub type CVPixelBufferLockFlags = u64; 26 | pub type CVPixelBufferRef = CVImageBufferRef; 27 | 28 | 29 | pub const kCVPixelFormatType_1Monochrome: OSType = 0x00000001; /* 1 bit indexed */ 30 | pub const kCVPixelFormatType_2Indexed: OSType = 0x00000002; /* 2 bit indexed */ 31 | pub const kCVPixelFormatType_4Indexed: OSType = 0x00000004; /* 4 bit indexed */ 32 | pub const kCVPixelFormatType_8Indexed: OSType = 0x00000008; /* 8 bit indexed */ 33 | pub const kCVPixelFormatType_1IndexedGray_WhiteIsZero: OSType = 0x00000021; /* 1 bit indexed gray, white is zero */ 34 | pub const kCVPixelFormatType_2IndexedGray_WhiteIsZero: OSType = 0x00000022; /* 2 bit indexed gray, white is zero */ 35 | pub const kCVPixelFormatType_4IndexedGray_WhiteIsZero: OSType = 0x00000024; /* 4 bit indexed gray, white is zero */ 36 | pub const kCVPixelFormatType_8IndexedGray_WhiteIsZero: OSType = 0x00000028; /* 8 bit indexed gray, white is zero */ 37 | pub const kCVPixelFormatType_16BE555: OSType = 0x00000010; /* 16 bit BE RGB 555 */ 38 | pub const kCVPixelFormatType_16LE555: OSType = as_u32_be(b"L555"); /* 16 bit LE RGB 555 */ 39 | pub const kCVPixelFormatType_16LE5551: OSType = as_u32_be(b"5551"); /* 16 bit LE RGB 5551 */ 40 | pub const kCVPixelFormatType_16BE565: OSType = as_u32_be(b"B565"); /* 16 bit BE RGB 565 */ 41 | pub const kCVPixelFormatType_16LE565: OSType = as_u32_be(b"L565"); /* 16 bit LE RGB 565 */ 42 | pub const kCVPixelFormatType_24RGB: OSType = 0x00000018; /* 24 bit RGB */ 43 | pub const kCVPixelFormatType_24BGR: OSType = as_u32_be(b"24BG"); /* 24 bit BGR */ 44 | pub const kCVPixelFormatType_32ARGB: OSType = 0x00000020; /* 32 bit ARGB */ 45 | pub const kCVPixelFormatType_32BGRA: OSType = as_u32_be(b"BGRA"); /* 32 bit BGRA */ 46 | pub const kCVPixelFormatType_32ABGR: OSType = as_u32_be(b"ABGR"); /* 32 bit ABGR */ 47 | pub const kCVPixelFormatType_32RGBA: OSType = as_u32_be(b"RGBA"); /* 32 bit RGBA */ 48 | pub const kCVPixelFormatType_64ARGB: OSType = as_u32_be(b"b64a"); /* 64 bit ARGB, 16-bit big-endian samples */ 49 | pub const kCVPixelFormatType_48RGB: OSType = as_u32_be(b"b48r"); /* 48 bit RGB, 16-bit big-endian samples */ 50 | pub const kCVPixelFormatType_32AlphaGray: OSType = as_u32_be(b"b32a"); /* 32 bit AlphaGray, 16-bit big-endian samples, black is zero */ 51 | pub const kCVPixelFormatType_16Gray: OSType = as_u32_be(b"b16g"); /* 16 bit Grayscale, 16-bit big-endian samples, black is zero */ 52 | pub const kCVPixelFormatType_30RGB: OSType = as_u32_be(b"R10k"); /* 30 bit RGB, 10-bit big-endian samples, 2 unused padding bits (at least significant end). */ 53 | pub const kCVPixelFormatType_422YpCbCr8: OSType = as_u32_be(b"2vuy"); /* Component Y'CbCr 8-bit 4:2:2, ordered Cb Y'0 Cr Y'1 */ 54 | pub const kCVPixelFormatType_4444YpCbCrA8: OSType = as_u32_be(b"v408"); /* Component Y'CbCrA 8-bit 4:4:4:4, ordered Cb Y' Cr A */ 55 | pub const kCVPixelFormatType_4444YpCbCrA8R: OSType = as_u32_be(b"r408"); /* Component Y'CbCrA 8-bit 4:4:4:4, rendering format. full range alpha, zero biased YUV, ordered A Y' Cb Cr */ 56 | pub const kCVPixelFormatType_4444AYpCbCr8: OSType = as_u32_be(b"y408"); /* Component Y'CbCrA 8-bit 4:4:4:4, ordered A Y' Cb Cr, full range alpha, video range Y'CbCr. */ 57 | pub const kCVPixelFormatType_4444AYpCbCr16: OSType = as_u32_be(b"y416"); /* Component Y'CbCrA 16-bit 4:4:4:4, ordered A Y' Cb Cr, full range alpha, video range Y'CbCr, 16-bit little-endian samples. */ 58 | pub const kCVPixelFormatType_444YpCbCr8: OSType = as_u32_be(b"v308"); /* Component Y'CbCr 8-bit 4:4:4 */ 59 | pub const kCVPixelFormatType_422YpCbCr16: OSType = as_u32_be(b"v216"); /* Component Y'CbCr 10,12,14,16-bit 4:2:2 */ 60 | pub const kCVPixelFormatType_422YpCbCr10: OSType = as_u32_be(b"v210"); /* Component Y'CbCr 10-bit 4:2:2 */ 61 | pub const kCVPixelFormatType_444YpCbCr10: OSType = as_u32_be(b"v410"); /* Component Y'CbCr 10-bit 4:4:4 */ 62 | pub const kCVPixelFormatType_420YpCbCr8Planar: OSType = as_u32_be(b"y420"); /* Planar Component Y'CbCr 8-bit 4:2:0. baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct */ 63 | pub const kCVPixelFormatType_420YpCbCr8PlanarFullRange: OSType = as_u32_be(b"f420"); /* Planar Component Y'CbCr 8-bit 4:2:0, full range. baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrPlanar struct */ 64 | pub const kCVPixelFormatType_422YpCbCr_4A_8BiPlanar: OSType = as_u32_be(b"a2vy"); /* First plane: Video-range Component Y'CbCr 8-bit 4:2:2, ordered Cb Y'0 Cr Y'1; second plane: alpha 8-bit 0-255 */ 65 | pub const kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange: OSType = as_u32_be(b"420v"); /* Bi-Planar Component Y'CbCr 8-bit 4:2:0, video-range (luma=[16,235] chroma=[16,240]). baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct */ 66 | pub const kCVPixelFormatType_420YpCbCr8BiPlanarFullRange: OSType = as_u32_be(b"420f"); /* Bi-Planar Component Y'CbCr 8-bit 4:2:0, full-range (luma=[0,255] chroma=[1,255]). baseAddr points to a big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar struct */ 67 | pub const kCVPixelFormatType_422YpCbCr8_yuvs: OSType = as_u32_be(b"yuvs"); /* Component Y'CbCr 8-bit 4:2:2, ordered Y'0 Cb Y'1 Cr */ 68 | pub const kCVPixelFormatType_422YpCbCr8FullRange: OSType = as_u32_be(b"yuvf"); /* Component Y'CbCr 8-bit 4:2:2, full range, ordered Y'0 Cb Y'1 Cr */ 69 | pub const kCVPixelFormatType_OneComponent8: OSType = as_u32_be(b"L008"); /* 8 bit one component, black is zero */ 70 | pub const kCVPixelFormatType_TwoComponent8: OSType = as_u32_be(b"2C08"); /* 8 bit two component, black is zero */ 71 | pub const kCVPixelFormatType_30RGBLEPackedWideGamut: OSType = as_u32_be(b"w30r"); /* little-endian RGB101010, 2 MSB are zero, wide-gamut (384-895) */ 72 | pub const kCVPixelFormatType_ARGB2101010LEPacked: OSType = as_u32_be(b"l10r"); /* little-endian ARGB2101010 full-range ARGB */ 73 | pub const kCVPixelFormatType_OneComponent16Half: OSType = as_u32_be(b"L00h"); /* 16 bit one component IEEE half-precision float, 16-bit little-endian samples */ 74 | pub const kCVPixelFormatType_OneComponent32Float: OSType = as_u32_be(b"L00f"); /* 32 bit one component IEEE float, 32-bit little-endian samples */ 75 | pub const kCVPixelFormatType_TwoComponent16Half: OSType = as_u32_be(b"2C0h"); /* 16 bit two component IEEE half-precision float, 16-bit little-endian samples */ 76 | pub const kCVPixelFormatType_TwoComponent32Float: OSType = as_u32_be(b"2C0f"); /* 32 bit two component IEEE float, 32-bit little-endian samples */ 77 | pub const kCVPixelFormatType_64RGBAHalf: OSType = as_u32_be(b"RGhA"); /* 64 bit RGBA IEEE half-precision float, 16-bit little-endian samples */ 78 | pub const kCVPixelFormatType_128RGBAFloat: OSType = as_u32_be(b"RGfA"); /* 128 bit RGBA IEEE float, 32-bit little-endian samples */ 79 | pub const kCVPixelFormatType_14Bayer_GRBG: OSType = as_u32_be(b"grb4"); /* Bayer 14-bit Little-Endian, packed in 16-bits, ordered G R G R... alternating with B G B G... */ 80 | pub const kCVPixelFormatType_14Bayer_RGGB: OSType = as_u32_be(b"rgg4"); /* Bayer 14-bit Little-Endian, packed in 16-bits, ordered R G R G... alternating with G B G B... */ 81 | pub const kCVPixelFormatType_14Bayer_BGGR: OSType = as_u32_be(b"bgg4"); /* Bayer 14-bit Little-Endian, packed in 16-bits, ordered B G B G... alternating with G R G R... */ 82 | pub const kCVPixelFormatType_14Bayer_GBRG: OSType = as_u32_be(b"gbr4"); /* Bayer 14-bit Little-Endian, packed in 16-bits, ordered G B G B... alternating with R G R G... */ 83 | pub const kCVPixelFormatType_DisparityFloat16: OSType = as_u32_be(b"hdis"); /* IEEE754-2008 binary16 (half float), describing the normalized shift when comparing two images. Units are 1/meters: ( pixelShift / (pixelFocalLength * baselineInMeters) ) */ 84 | pub const kCVPixelFormatType_DisparityFloat32: OSType = as_u32_be(b"fdis"); /* IEEE754-2008 binary32 float, describing the normalized shift when comparing two images. Units are 1/meters: ( pixelShift / (pixelFocalLength * baselineInMeters) ) */ 85 | pub const kCVPixelFormatType_DepthFloat16: OSType = as_u32_be(b"hdep"); /* IEEE754-2008 binary16 (half float), describing the depth (distance to an object) in meters */ 86 | pub const kCVPixelFormatType_DepthFloat32: OSType = as_u32_be(b"fdep"); /* IEEE754-2008 binary32 float, describing the depth (distance to an object) in meters */ 87 | pub const kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange: OSType = as_u32_be(b"x420"); /* 2 plane YCbCr10 4:2:0, each 10 bits in the MSBs of 16bits, video-range (luma=[64,940] chroma=[64,960]) */ 88 | pub const kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange: OSType = as_u32_be(b"x422"); /* 2 plane YCbCr10 4:2:2, each 10 bits in the MSBs of 16bits, video-range (luma=[64,940] chroma=[64,960]) */ 89 | pub const kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange: OSType = as_u32_be(b"x444"); /* 2 plane YCbCr10 4:4:4, each 10 bits in the MSBs of 16bits, video-range (luma=[64,940] chroma=[64,960]) */ 90 | pub const kCVPixelFormatType_420YpCbCr10BiPlanarFullRange: OSType = as_u32_be(b"xf20"); /* 2 plane YCbCr10 4:2:0, each 10 bits in the MSBs of 16bits, full-range (Y range 0-1023) */ 91 | pub const kCVPixelFormatType_422YpCbCr10BiPlanarFullRange: OSType = as_u32_be(b"xf22"); /* 2 plane YCbCr10 4:2:2, each 10 bits in the MSBs of 16bits, full-range (Y range 0-1023) */ 92 | pub const kCVPixelFormatType_444YpCbCr10BiPlanarFullRange: OSType = as_u32_be(b"xf44"); /* 2 plane YCbCr10 4:4:4, each 10 bits in the MSBs of 16bits, full-range (Y range 0-1023) */ 93 | 94 | 95 | pub const kCVPixelBufferLock_ReadOnly: CVPixelBufferLockFlags = 1; 96 | 97 | #[repr(C)] 98 | #[derive(Debug, Clone, Copy)] 99 | pub struct CVPlanarComponentInfo { 100 | /// offset from main base address to base address of this plane, big-endian 101 | pub offset: i32, 102 | /// bytes per row of this plane, big-endian 103 | pub rowBytes: u32, 104 | } 105 | 106 | #[repr(C)] 107 | #[derive(Debug, Clone, Copy)] 108 | pub struct CVPlanarPixelBufferInfo { 109 | pub componentInfo: [CVPlanarComponentInfo; 1], 110 | } 111 | 112 | #[repr(C)] 113 | #[derive(Debug, Clone, Copy)] 114 | pub struct CVPlanarPixelBufferInfo_YCbCrPlanar { 115 | pub componentInfoY: CVPlanarComponentInfo, 116 | pub componentInfoCb: CVPlanarComponentInfo, 117 | pub componentInfoCr: CVPlanarComponentInfo, 118 | } 119 | 120 | #[repr(C)] 121 | #[derive(Debug, Clone, Copy)] 122 | pub struct CVPlanarPixelBufferInfo_YCbCrBiPlanar { 123 | pub componentInfoY: CVPlanarComponentInfo, 124 | pub componentInfoCbCr: CVPlanarComponentInfo, 125 | } 126 | 127 | 128 | 129 | pub type CVPixelBufferReleaseBytesCallback = extern "C" fn (releaseRefCon: *mut c_void, 130 | baseAddress: *const *const c_void); 131 | pub type CVPixelBufferReleasePlanarBytesCallback = extern "C" fn (releaseRefCon: *mut c_void, 132 | dataPtr: *const *const c_void, 133 | dataSize: size_t, 134 | numberOfPlanes: size_t, 135 | planeAddresses: *const *const c_void); 136 | 137 | extern "C" { 138 | pub static kCVPixelBufferPixelFormatTypeKey: CFStringRef; 139 | pub static kCVPixelBufferMemoryAllocatorKey: CFStringRef; 140 | pub static kCVPixelBufferWidthKey: CFStringRef; 141 | pub static kCVPixelBufferHeightKey: CFStringRef; 142 | pub static kCVPixelBufferExtendedPixelsLeftKey: CFStringRef; 143 | pub static kCVPixelBufferExtendedPixelsTopKey: CFStringRef; 144 | pub static kCVPixelBufferExtendedPixelsRightKey: CFStringRef; 145 | pub static kCVPixelBufferExtendedPixelsBottomKey: CFStringRef; 146 | pub static kCVPixelBufferBytesPerRowAlignmentKey: CFStringRef; 147 | pub static kCVPixelBufferCGBitmapContextCompatibilityKey: CFStringRef; 148 | pub static kCVPixelBufferCGImageCompatibilityKey: CFStringRef; 149 | pub static kCVPixelBufferOpenGLCompatibilityKey: CFStringRef; 150 | pub static kCVPixelBufferPlaneAlignmentKey: CFStringRef; 151 | pub static kCVPixelBufferIOSurfacePropertiesKey: CFStringRef; 152 | pub static kCVPixelBufferOpenGLESCompatibilityKey: CFStringRef; 153 | pub static kCVPixelBufferMetalCompatibilityKey: CFStringRef; 154 | pub static kCVPixelBufferOpenGLTextureCacheCompatibilityKey: CFStringRef; 155 | pub static kCVPixelBufferOpenGLESTextureCacheCompatibilityKey: CFStringRef; 156 | 157 | 158 | pub fn CVBufferGetTypeID() -> CFTypeID; 159 | pub fn CVPixelBufferRetain(texture: CVPixelBufferRef) -> CVPixelBufferRef; 160 | pub fn CVPixelBufferRelease(texture: CVPixelBufferRef); 161 | pub fn CVPixelBufferCreateResolvedAttributesDictionary(allocator: CFAllocatorRef, 162 | attributes: CFArrayRef, 163 | resolvedDictionaryOut: *mut CFDictionaryRef) -> CVReturn; 164 | pub fn CVPixelBufferCreate( 165 | allocator: CFAllocatorRef, 166 | width: size_t, 167 | height: size_t, 168 | pixelFormatType: OSType, 169 | pixelBufferAttributes: CFDictionaryRef, 170 | pixelBufferOut: *mut CVPixelBufferRef, 171 | ) -> CVReturn; 172 | // pub fn CVPixelBufferCreateWithBytes(allocator: CFAllocatorRef, 173 | // width: size_t, 174 | // height: size_t, 175 | // pixelFormatType: OSType, 176 | // baseAddress: *const c_void, 177 | // bytesPerRow: size_t, 178 | // releaseCallback: CVPixelBufferReleaseBytesCallback, 179 | // releaseRefCon: *const c_void, 180 | // pixelBufferAttributes: CFDictionaryRef, 181 | // pixelBufferOut: *mut CVPixelBufferRef) -> CVReturn; 182 | // pub fn CVPixelBufferCreateWithPlanarBytes(allocator: CFAllocatorRef, 183 | // width: size_t, 184 | // height: size_t, 185 | // pixelFormatType: OSType, 186 | // dataPtr: *const c_void, 187 | // dataSize: size_t, 188 | // numberOfPlanes: size_t, 189 | // planeBaseAddress: *const *const c_void, 190 | // ) -> CVReturn; 191 | 192 | pub fn CVPixelBufferLockBaseAddress(pixelBuffer: CVPixelBufferRef, 193 | lockFlags: CVOptionFlags) -> CVReturn; 194 | pub fn CVPixelBufferUnlockBaseAddress(pixelBuffer: CVPixelBufferRef, 195 | unlockFlags: CVOptionFlags) -> CVReturn; 196 | pub fn CVPixelBufferGetWidth(pixelBuffer: CVPixelBufferRef) -> size_t; 197 | pub fn CVPixelBufferGetHeight(pixelBuffer: CVPixelBufferRef) -> size_t; 198 | pub fn CVPixelBufferGetPixelFormatType(pixelBuffer: CVPixelBufferRef) -> OSType; 199 | 200 | pub fn CVPixelBufferGetBaseAddress(pixelBuffer: CVPixelBufferRef) -> *mut c_void; 201 | pub fn CVPixelBufferGetBytesPerRow(pixelBuffer: CVPixelBufferRef) -> size_t; 202 | pub fn CVPixelBufferIsPlanar(pixelBuffer: CVPixelBufferRef) -> Boolean; 203 | pub fn CVPixelBufferGetPlaneCount(pixelBuffer: CVPixelBufferRef) -> size_t; 204 | pub fn CVPixelBufferGetWidthOfPlane(pixelBuffer: CVPixelBufferRef, 205 | planeIndex: size_t) -> size_t; 206 | pub fn CVPixelBufferGetHeightOfPlane(pixelBuffer: CVPixelBufferRef, 207 | planeIndex: size_t) -> size_t; 208 | pub fn CVPixelBufferGetBaseAddressOfPlane(pixelBuffer: CVPixelBufferRef, 209 | planeIndex: size_t) -> *mut c_void; 210 | pub fn CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer: CVPixelBufferRef, 211 | planeIndex: size_t) -> size_t; 212 | 213 | pub fn CVPixelBufferGetExtendedPixels(pixelBuffer: CVPixelBufferRef, 214 | extraColumnsOnLeft: *const size_t, 215 | extraColumnsOnRight: *const size_t, 216 | extraRowsOnTop: *const size_t, 217 | extraRowsOnBottom: *const size_t); 218 | pub fn CVPixelBufferFillExtendedPixels(pixelBuffer: CVPixelBufferRef) -> CVReturn; 219 | } 220 | --------------------------------------------------------------------------------