diff --git a/cidre/src/cm.rs b/cidre/src/cm.rs index 5428d7fe..8f480e6c 100644 --- a/cidre/src/cm.rs +++ b/cidre/src/cm.rs @@ -34,6 +34,10 @@ pub use tag_collection::TagCollection; pub use tag_collection::TagCollectionMut; pub use tag_collection::err as tag_collection_err; +mod tagged_buffer_group; +pub use tagged_buffer_group::TaggedBufGroup; +pub use tagged_buffer_group::err as tagged_buf_group_err; + mod time; pub use time::Time; pub use time::TimeEpoch; diff --git a/cidre/src/cm/tag_collection.rs b/cidre/src/cm/tag_collection.rs index a2fe9726..d46a9c9d 100644 --- a/cidre/src/cm/tag_collection.rs +++ b/cidre/src/cm/tag_collection.rs @@ -108,11 +108,35 @@ impl TagCollection { } } + #[doc(alias = "CMTagCollectionContainsTag")] #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] #[inline] pub fn contains(&self, val: cm::Tag) -> bool { unsafe { CMTagCollectionContainsTag(self, val) } } + + #[doc(alias = "CMTagCollectionContainsTagsOfCollection")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn contains_collection(&self, val: &cm::TagCollection) -> bool { + unsafe { CMTagCollectionContainsTagsOfCollection(self, val) } + } + + #[doc(alias = "CMTagCollectionContainsSpecifiedTags")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn contains_tags(&self, tags: &[cm::Tag]) -> bool { + unsafe { CMTagCollectionContainsSpecifiedTags(self, tags.as_ptr(), tags.len() as _) } + } + + #[doc(alias = "CMTagCollectionContainsCategory")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn contains_catogery(&self, val: cm::TagCategory) -> bool { + unsafe { CMTagCollectionContainsCategory(self, val) } + } + + // TODO: more api } #[link(name = "CoreMedia", kind = "framework")] @@ -135,6 +159,25 @@ unsafe extern "C-unwind" { #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] fn CMTagCollectionContainsTag(tag_collection: &TagCollection, val: cm::Tag) -> bool; + + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + fn CMTagCollectionContainsTagsOfCollection( + tag_collection: &TagCollection, + contained_tag_collection: &TagCollection, + ) -> bool; + + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + fn CMTagCollectionContainsSpecifiedTags( + tag_collection: &TagCollection, + contained_tags: *const cm::Tag, + contained_tag_count: cm::ItemCount, + ) -> bool; + + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + fn CMTagCollectionContainsCategory( + tag_collection: &TagCollection, + category: cm::TagCategory, + ) -> bool; } #[cfg(test)] @@ -148,5 +191,11 @@ mod tests { let tag = cm::Tag::with_f64(cm::TagCategory::MediaType, 0.0); assert!(!empty.contains(tag)); + let empty2 = cm::TagCollection::with_tags(&[]).unwrap(); + + assert!(empty.contains_collection(&empty2)); + + assert!(empty.contains_tags(&[])); + assert!(!empty.contains_tags(&[tag])); } } diff --git a/cidre/src/cm/tagged_buffer_group.rs b/cidre/src/cm/tagged_buffer_group.rs new file mode 100644 index 00000000..00bd4fe2 --- /dev/null +++ b/cidre/src/cm/tagged_buffer_group.rs @@ -0,0 +1,109 @@ +use crate::{api, arc, cf, cm, define_cf_type, os}; + +/// The os::Errors returned from the CMTaggedBufferGroup routines. +#[doc(alias = "CMTaggedBufferGroupError")] +pub mod err { + use crate::os::Error; + + #[doc(alias = "kCMTaggedBufferGroupError_ParamErr")] + pub const PARAM_ERR: Error = Error::new_unchecked(-15780); + + #[doc(alias = "kCMTaggedBufferGroupError_AllocationFailed")] + pub const ALLOC_FAILED: Error = Error::new_unchecked(-15781); + + #[doc(alias = "kCMTaggedBufferGroupError_InternalError")] + pub const INTERNAL_ERR: Error = Error::new_unchecked(-15782); +} + +define_cf_type!( + #[doc(alias = "CMTaggedBufferGroupRef")] + TaggedBufGroup(cf::Type) +); + +impl TaggedBufGroup { + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn get_type_id() -> cf::Type { + unsafe { CMTaggedBufferGroupGetTypeID() } + } + + #[doc(alias = "CMTaggedBufferGroupCreate")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn create_in( + tag_collections: &cf::ArrayOf, + buffers: &cf::ArrayOf, + allocator: Option<&cf::Allocator>, + ) -> os::Result>> { + unsafe { + let mut res = None; + CMTaggedBufferGroupCreate(allocator, tag_collections, buffers, &mut res) + .to_result_option(res) + } + } + + #[doc(alias = "CMTaggedBufferGroupCreate")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn with( + tag_collections: &cf::ArrayOf, + buffers: &cf::ArrayOf, + ) -> os::Result> { + unsafe { + let res = Self::create_in(tag_collections, buffers, None)?; + Ok(res.unwrap_unchecked()) + } + } + + #[doc(alias = "CMTaggedBufferGroupGetCount")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn count(&self) -> cm::ItemCount { + unsafe { CMTaggedBufferGroupGetCount(self) } + } + + #[doc(alias = "CMTaggedBufferGroupGetCount")] + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn len(&self) -> usize { + self.count() as _ + } + + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + #[inline] + pub fn is_empty(&self) -> bool { + #[allow(unused_unsafe)] + unsafe { + self.len() == 0 + } + } +} + +#[link(name = "CoreMedia", kind = "framework")] +#[api::weak] +unsafe extern "C-unwind" { + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + fn CMTaggedBufferGroupGetTypeID() -> cf::Type; + + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + fn CMTaggedBufferGroupCreate( + allocator: Option<&cf::Allocator>, + tag_collections: &cf::ArrayOf, + buffers: &cf::ArrayOf, + group_out: *mut Option>, + ) -> os::Status; + + #[api::available(macos = 14.0, ios = 17.0, tvos = 17.0, watchos = 10.0, visionos = 1.0)] + fn CMTaggedBufferGroupGetCount(group: &TaggedBufGroup) -> cm::ItemCount; +} + +#[cfg(test)] +mod tests { + use crate::{cf, cm}; + + #[test] + fn basics() { + let group = cm::TaggedBufGroup::with(&cf::ArrayOf::new(), &cf::ArrayOf::new()).unwrap(); + assert!(group.is_empty()); + } +}