diff --git a/cidre/src/cat/audio/base_types.rs b/cidre/src/cat/audio/base_types.rs index d0b4a667..f4a46431 100644 --- a/cidre/src/cat/audio/base_types.rs +++ b/cidre/src/cat/audio/base_types.rs @@ -9,7 +9,7 @@ use crate::{define_opts, four_cc_to_str, os}; use crate::ns; /// These are the error codes returned from the APIs found through Core Audio related frameworks. -pub mod errors { +pub mod err { use crate::os::Error; /// Unimplemented core routine. diff --git a/cidre/src/cf/url.rs b/cidre/src/cf/url.rs index 059824f7..715a6295 100644 --- a/cidre/src/cf/url.rs +++ b/cidre/src/cf/url.rs @@ -75,6 +75,11 @@ impl Url { cf::Url::with_fs_path_in(&path, PathStyle::Posix, is_dir, None) } + #[inline] + pub fn with_file_path(path: &Path) -> Option> { + Self::with_path(path.into(), false) + } + /// ``` /// use cidre::cf; /// diff --git a/cidre/src/cg/image/destination.rs b/cidre/src/cg/image/destination.rs index a61dc5ad..e26a46e3 100644 --- a/cidre/src/cg/image/destination.rs +++ b/cidre/src/cg/image/destination.rs @@ -130,6 +130,12 @@ impl Dst { unsafe { CGImageDestinationCreateWithData(data, ty, count, None) } } + /// Creates an image destination that writes image data to the specified URL. + /// + /// # Arguments: + /// * `url` - The URL at which to write the image data. This object overwrites any data at the specified URL. + /// * `ty` - The uniform type identifier of the resulting image file. + /// * `count` - The number of images (not including thumbnail images) you want to include in the image file. #[doc(alias = "CGImageDestinationCreateWithURL")] #[inline] pub fn with_url(url: &cf::Url, ty: &cf::String, count: usize) -> Option> { diff --git a/cidre/src/cm.rs b/cidre/src/cm.rs index c8298a3e..38480006 100644 --- a/cidre/src/cm.rs +++ b/cidre/src/cm.rs @@ -15,7 +15,7 @@ pub use format_description::VideoDimensions; pub use format_description::VideoFormatDesc; mod format_description_bridge; -pub use format_description_bridge::errors as format_description_bridge_errors; +pub use format_description_bridge::err as format_desc_bridge_err; pub use format_description_bridge::swap_be_image_desc_to_host; pub use format_description_bridge::swap_be_sound_desc_to_host; pub use format_description_bridge::swap_host_image_desc_to_be; @@ -35,6 +35,7 @@ pub use time::TimeValue; pub mod sample_buffer; +pub use sample_buffer::err as sample_buf_err; #[cfg(feature = "cat")] pub use sample_buffer::BlockBufAudioBufList; pub use sample_buffer::Flags as SampleBufFlags; @@ -46,6 +47,7 @@ pub use attachment::Bearer as AttachBearer; pub use attachment::Mode as AttachMode; pub mod block_buffer; +pub use block_buffer::err as block_buf_err; pub use block_buffer::BlockBuf; pub use block_buffer::Flags as BlockBufFlags; diff --git a/cidre/src/cm/block_buffer.rs b/cidre/src/cm/block_buffer.rs index 2b15f8fd..4047f4a0 100644 --- a/cidre/src/cm/block_buffer.rs +++ b/cidre/src/cm/block_buffer.rs @@ -357,7 +357,7 @@ extern "C-unwind" { } -pub mod errors { +pub mod err { use crate::os::Error; /// Returned when a cm::BlockBuffer-creating API gets a failure diff --git a/cidre/src/cm/format_description_bridge.rs b/cidre/src/cm/format_description_bridge.rs index da645b44..2968340e 100644 --- a/cidre/src/cm/format_description_bridge.rs +++ b/cidre/src/cm/format_description_bridge.rs @@ -1,6 +1,6 @@ use crate::{arc, cf, cm, define_cf_type, os}; -pub mod errors { +pub mod err { use crate::os::Error; /// Invalid parameter. diff --git a/cidre/src/cm/sample_buffer.rs b/cidre/src/cm/sample_buffer.rs index e5fb812a..3b5223ec 100644 --- a/cidre/src/cm/sample_buffer.rs +++ b/cidre/src/cm/sample_buffer.rs @@ -377,7 +377,7 @@ impl SampleBuf { true } else { let dict = &arr[0]; - match dict.get(attachment_keys::not_sync()) { + match dict.get(attach_keys::not_sync()) { None => true, Some(not_sync) => unsafe { // in theory we don't need check actual value here. @@ -395,7 +395,7 @@ impl SampleBuf { #[inline] pub unsafe fn contains_not_sync(&self) -> bool { let arr = self.attaches(true).unwrap_unchecked(); - arr[0].contains_key(attachment_keys::not_sync()) + arr[0].contains_key(attach_keys::not_sync()) } /// Returns a value that indicates whether a sample buffer is valid. @@ -649,7 +649,7 @@ extern "C-unwind" { } /// Use attachements() -pub mod attachment_keys { +pub mod attach_keys { use crate::cf; /// cf::Boolean (absence of this key implies Sync) @@ -743,7 +743,7 @@ pub mod attachment_keys { } /// use get_attachment or dictionary_of_attachments -pub mod buffer_attachment_keys { +pub mod buf_attach_keys { use crate::cf; /// cf::Boolean @@ -946,7 +946,7 @@ pub mod buffer_attachment_keys { } } -pub mod errors { +pub mod err { use crate::os::Error; /// An allocation failed. @@ -1022,3 +1022,33 @@ pub mod errors { #[doc(alias = "kCMSampleBufferError_DataCanceled")] pub const DATA_CANCELED: Error = Error::new_unchecked(-16751); } + +#[cfg(test)] +mod tests { + use crate::{cf, cm, cv}; + + #[test] + fn basics() { + let image_buf = cv::ImageBuf::new(1920, 1080, cv::PixelFormat::_32_BGRA, None).unwrap(); + let format_desc = cm::FormatDesc::with_image_buf(&image_buf).unwrap(); + let timing_info = cm::SampleTimingInfo::invalid(); + let mut sample_buf = cm::SampleBuf::with_image_buf( + &image_buf, + true, + None, + std::ptr::null(), + &format_desc, + &timing_info, + ) + .unwrap(); + assert!(sample_buf.data_is_ready()); + + let attaches = sample_buf.attaches_mut(true).unwrap(); + attaches[0].insert( + cm::sample_buffer::attach_keys::do_not_display(), + cf::Number::tagged_i8(1).into(), + ); + + assert!(sample_buf.is_key_frame()); + } +} diff --git a/cidre/src/mtk/texture_loader.rs b/cidre/src/mtk/texture_loader.rs index 4791b995..34eb731c 100644 --- a/cidre/src/mtk/texture_loader.rs +++ b/cidre/src/mtk/texture_loader.rs @@ -161,6 +161,10 @@ impl TextureLoader { Self::alloc().init_with_device(device) } + pub fn with_sys_default_device() -> Option> { + Some(Self::alloc().init_with_device(mtl::Device::sys_default().as_ref()?)) + } + #[cfg(feature = "blocks")] #[objc::msg_send(newTextureWithContentsOfURL:options:completionHandler:)] pub fn new_texture_with_url_ch( diff --git a/cidre/src/os.rs b/cidre/src/os.rs index fd3650a3..2e87ae67 100644 --- a/cidre/src/os.rs +++ b/cidre/src/os.rs @@ -76,6 +76,7 @@ impl std::error::Error for Error {} pub type Result = std::result::Result; +#[inline] pub(crate) unsafe fn result_unchecked(op: impl FnOnce(&mut Option) -> R) -> Result where R: Into, @@ -85,6 +86,7 @@ where Ok(unsafe { option.unwrap_unchecked() }) } +#[inline] pub(crate) fn result_init(op: impl FnOnce(*mut T) -> R) -> Result where R: Into, diff --git a/cidre/src/vn.rs b/cidre/src/vn.rs index cae4e610..323f6806 100644 --- a/cidre/src/vn.rs +++ b/cidre/src/vn.rs @@ -64,6 +64,7 @@ pub use face_landmarks::Region as FaceLandmarkRegion; pub use face_landmarks::Region2d as FaceLandmarkRegion2d; mod generate_foreground_instance_mask_request; +pub use generate_foreground_instance_mask_request::GenForegroundInstanceMaskRequest; mod generate_person_segmentation_request; pub use generate_person_segmentation_request::GenPersonSegmentationRequest;