Skip to content

Commit

Permalink
continue on cm and vt api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Feb 26, 2025
1 parent 972042f commit 4f42799
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 61 deletions.
2 changes: 2 additions & 0 deletions cidre/src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub use format_description::FormatDesc;
pub use format_description::FormatDescExtKey;
pub use format_description::LogTransferFn;
pub use format_description::MediaType;
pub use format_description::MuxedFormatDesc;
pub use format_description::PixelFormat;
pub use format_description::TaggedBufGroupFormatDesc;
pub use format_description::VideoCodec;
pub use format_description::VideoDimensions;
pub use format_description::VideoFormatDesc;
Expand Down
59 changes: 50 additions & 9 deletions cidre/src/cm/format_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{ffi::c_void, mem::transmute};
use crate::{
FourCharCode, api, arc,
cf::{self, Allocator},
define_cf_type, os,
cm, define_cf_type, os,
};

#[cfg(feature = "cv")]
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct VideoDimensions {
}

#[doc(alias = "CMMediaType")]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
#[derive(Eq, PartialEq, Copy, Clone, Hash)]
#[repr(transparent)]
pub struct MediaType(pub FourCharCode);

Expand Down Expand Up @@ -106,8 +106,14 @@ impl MediaType {
}
}

impl std::fmt::Debug for MediaType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::four_cc_fmt_debug(self.0, "MediaType", f)
}
}

#[doc(alias = "CMVideoCodecType")]
#[derive(Debug, Eq, PartialEq, Clone, Copy)]
#[derive(Eq, PartialEq, Clone, Copy, Hash)]
#[repr(transparent)]
pub struct VideoCodec(FourCharCode);

Expand Down Expand Up @@ -171,6 +177,12 @@ impl VideoCodec {
}
}

impl std::fmt::Debug for VideoCodec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::four_cc_fmt_debug(self.0, "VideoCodec", f)
}
}

define_cf_type!(
#[doc(alias = "CMFormatDescriptionRef")]
FormatDesc(cf::Type)
Expand All @@ -179,26 +191,31 @@ define_cf_type!(
unsafe impl Send for FormatDesc {}

impl FormatDesc {
#[doc(alias = "CMFormatDescriptionGetTypeID")]
#[inline]
pub fn type_id() -> cf::TypeId {
unsafe { CMFormatDescriptionGetTypeID() }
}

#[doc(alias = "CMFormatDescriptionGetMediaType")]
#[inline]
pub fn media_type(&self) -> MediaType {
unsafe { CMFormatDescriptionGetMediaType(self) }
}

#[doc(alias = "CMFormatDescriptionGetMediaSubType")]
#[inline]
pub fn media_sub_type(&self) -> FourCharCode {
unsafe { CMFormatDescriptionGetMediaSubType(self) }
}

#[doc(alias = "CMFormatDescriptionGetExtensions")]
#[inline]
pub fn exts(&self) -> Option<&cf::DictionaryOf<cf::String, cf::Plist>> {
unsafe { CMFormatDescriptionGetExtensions(self) }
}

#[doc(alias = "CMFormatDescriptionGetExtension")]
pub fn ext<'a>(&'a self, key: &FormatDescExtKey) -> Option<&'a cf::Plist> {
unsafe { CMFormatDescriptionGetExtension(self, key) }
}
Expand Down Expand Up @@ -308,21 +325,21 @@ impl VideoFormatDesc {
/// let desc = cm::VideoFormatDesc::video(cm::VideoCodec::H264, 1920, 1080, None).unwrap();
/// ```
pub fn video(
codec_type: VideoCodec,
codec: VideoCodec,
width: i32,
height: i32,
extensions: Option<&cf::DictionaryOf<FormatDescExtKey, cf::Type>>,
) -> os::Result<arc::R<Self>> {
unsafe {
os::result_unchecked(|res| {
Self::create_video_in(codec_type, width, height, extensions, res, None)
Self::create_video_in(codec, width, height, extensions, res, None)
})
}
}

#[doc(alias = "CMVideoFormatDescriptionCreate")]
pub fn create_video_in(
codec_type: VideoCodec,
codec: VideoCodec,
width: i32,
height: i32,
extensions: Option<&cf::DictionaryOf<FormatDescExtKey, cf::Type>>,
Expand All @@ -332,7 +349,7 @@ impl VideoFormatDesc {
unsafe {
CMVideoFormatDescriptionCreate(
allocator,
codec_type,
codec,
width,
height,
extensions,
Expand All @@ -357,6 +374,15 @@ impl VideoFormatDesc {
unsafe { CMVideoFormatDescriptionMatchesImageBuffer(self, image_buffer) }
}

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub fn tag_collections(&self) -> os::Result<arc::R<cf::ArrayOf<cm::TagCollection>>> {
unsafe {
let mut res = None;
CMVideoFormatDescriptionCopyTagCollectionArray(self, &mut res).result()?;
Ok(res.unwrap_unchecked())
}
}

#[doc(alias = "CMVideoFormatDescriptionCreateForImageBuffer")]
#[cfg(feature = "cv")]
#[inline]
Expand Down Expand Up @@ -887,7 +913,10 @@ impl FormatDescExtKey {
}
}

define_cf_type!(LogTransferFn(cf::String));
define_cf_type!(
#[doc(alias = "CMFormatDescriptionLogTransferFunction")]
LogTransferFn(cf::String)
);

impl LogTransferFn {
#[doc(alias = "kCMFormatDescriptionLogTransferFunction_AppleLog")]
Expand All @@ -897,6 +926,12 @@ impl LogTransferFn {
}
}

#[doc(alias = "CMTaggedBufferGroupFormatDescriptionRef")]
pub type TaggedBufGroupFormatDesc = FormatDesc;

#[doc(alias = "CMMuxedFormatDescriptionRef")]
pub type MuxedFormatDesc = FormatDesc;

#[link(name = "CoreMedia", kind = "framework")]
#[api::weak]
unsafe extern "C-unwind" {
Expand Down Expand Up @@ -947,7 +982,7 @@ unsafe extern "C-unwind" {

fn CMVideoFormatDescriptionCreate(
allocator: Option<&cf::Allocator>,
codec_type: VideoCodec,
codec: VideoCodec,
width: i32,
height: i32,
extensions: Option<&cf::DictionaryOf<FormatDescExtKey, cf::Type>>,
Expand All @@ -962,6 +997,12 @@ unsafe extern "C-unwind" {
image_buffer: &cv::ImageBuf,
) -> bool;

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMVideoFormatDescriptionCopyTagCollectionArray(
video_desc: &VideoFormatDesc,
tag_collection_out: *mut Option<arc::R<cf::ArrayOf<cm::TagCollection>>>,
) -> os::Status;

fn CMFormatDescriptionGetMediaSubType(desc: &FormatDesc) -> FourCharCode;

fn CMFormatDescriptionGetExtensions(
Expand Down
12 changes: 12 additions & 0 deletions cidre/src/cm/tagged_buffer_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ impl TaggedBufGroup {
}
}

impl cm::SampleBuf {
#[doc(alias = "CMSampleBufferGetTaggedBufferGroup")]
#[doc(alias = "taggedBuffers")]
#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
pub fn tagged_bufs(&self) -> Option<&cm::TaggedBufGroup> {
unsafe { CMSampleBufferGetTaggedBufferGroup(self) }
}
}

#[link(name = "CoreMedia", kind = "framework")]
#[api::weak]
unsafe extern "C-unwind" {
Expand All @@ -95,6 +104,9 @@ unsafe extern "C-unwind" {

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMTaggedBufferGroupGetCount(group: &TaggedBufGroup) -> cm::ItemCount;

#[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)]
fn CMSampleBufferGetTaggedBufferGroup(sbuf: &cm::SampleBuf) -> Option<&cm::TaggedBufGroup>;
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions cidre/src/vt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ pub use compression::Session as CompressionSession;
pub use compression::properties as compression_properties;

pub mod decompression;
pub use decompression::MultiImageCapableOutputHandler as DecompressionMultiImageCapableOutputHandler;
pub use decompression::OutputCb as DecompressionOutputCb;
pub use decompression::OutputCbRecord as DecompressionOutputCbRecord;
pub use decompression::OutputMultiImageCb as DecompressionOutputMultiImageCb;
pub use decompression::Session as DecompressionSession;
pub use decompression::properties as decompression_properties;
pub use decompression::session::is_hardware_decode_supported;
Expand Down
2 changes: 2 additions & 0 deletions cidre/src/vt/decompression.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod session;
pub use session::MultiImageCapableOutputHandler;
pub use session::OutputCb;
pub use session::OutputCbRecord;
pub use session::OutputMultiImageCb;
pub use session::Session;

pub mod properties;
Expand Down
Loading

0 comments on commit 4f42799

Please # to comment.