Skip to content

Commit

Permalink
continue with cm::TaggedBufGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Feb 26, 2025
1 parent 0486f3a commit 972042f
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cidre/src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions cidre/src/cm/tag_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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)]
Expand All @@ -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]));
}
}
109 changes: 109 additions & 0 deletions cidre/src/cm/tagged_buffer_group.rs
Original file line number Diff line number Diff line change
@@ -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<cm::TagCollection>,
buffers: &cf::ArrayOf<cf::Type>,
allocator: Option<&cf::Allocator>,
) -> os::Result<Option<arc::R<Self>>> {
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<cm::TagCollection>,
buffers: &cf::ArrayOf<cf::Type>,
) -> os::Result<arc::R<Self>> {
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<cm::TagCollection>,
buffers: &cf::ArrayOf<cf::Type>,
group_out: *mut Option<arc::R<TaggedBufGroup>>,
) -> 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());
}
}

0 comments on commit 972042f

Please # to comment.