Pass CVImageBuffers into GPUI instead of IOSurfaces
This commit is contained in:
parent
0430bbf7d9
commit
531ffc01c9
8 changed files with 95 additions and 96 deletions
13
crates/media/Cargo.toml
Normal file
13
crates/media/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "media"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "src/media.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
block = "0.1"
|
||||
core-foundation = "0.9.3"
|
||||
objc = "0.2"
|
66
crates/media/src/media.rs
Normal file
66
crates/media/src/media.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use core_foundation::{
|
||||
base::{CFTypeID, TCFType},
|
||||
declare_TCFType, impl_CFTypeDescription, impl_TCFType,
|
||||
};
|
||||
use std::ffi::c_void;
|
||||
|
||||
pub mod io_surface {
|
||||
use super::*;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct __IOSurface(c_void);
|
||||
// The ref type must be a pointer to the underlying struct.
|
||||
pub type IOSurfaceRef = *const __IOSurface;
|
||||
|
||||
declare_TCFType!(IOSurface, IOSurfaceRef);
|
||||
impl_TCFType!(IOSurface, IOSurfaceRef, IOSurfaceGetTypeID);
|
||||
impl_CFTypeDescription!(IOSurface);
|
||||
|
||||
#[link(name = "IOSurface", kind = "framework")]
|
||||
extern "C" {
|
||||
fn IOSurfaceGetTypeID() -> CFTypeID;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod core_video {
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use super::*;
|
||||
use io_surface::{IOSurface, IOSurfaceRef};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct __CVImageBuffer(c_void);
|
||||
// The ref type must be a pointer to the underlying struct.
|
||||
pub type CVImageBufferRef = *const __CVImageBuffer;
|
||||
|
||||
declare_TCFType!(CVImageBuffer, CVImageBufferRef);
|
||||
impl_TCFType!(CVImageBuffer, CVImageBufferRef, CVImageBufferGetTypeID);
|
||||
impl_CFTypeDescription!(CVImageBuffer);
|
||||
|
||||
impl CVImageBuffer {
|
||||
pub fn io_surface(&self) -> IOSurface {
|
||||
unsafe {
|
||||
IOSurface::wrap_under_get_rule(CVPixelBufferGetIOSurface(
|
||||
self.as_concrete_TypeRef(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> usize {
|
||||
unsafe { CVPixelBufferGetWidth(self.as_concrete_TypeRef()) }
|
||||
}
|
||||
|
||||
pub fn height(&self) -> usize {
|
||||
unsafe { CVPixelBufferGetHeight(self.as_concrete_TypeRef()) }
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn CVImageBufferGetTypeID() -> CFTypeID;
|
||||
fn CVPixelBufferGetIOSurface(buffer: CVImageBufferRef) -> IOSurfaceRef;
|
||||
fn CVPixelBufferGetWidth(buffer: CVImageBufferRef) -> usize;
|
||||
fn CVPixelBufferGetHeight(buffer: CVImageBufferRef) -> usize;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue