Skip to content

Commit

Permalink
tune api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 1, 2024
1 parent 67bc451 commit 9aa1f1a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cidre/src/cat/audio/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions cidre/src/cf/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<arc::R<Url>> {
Self::with_path(path.into(), false)
}

/// ```
/// use cidre::cf;
///
Expand Down
6 changes: 6 additions & 0 deletions cidre/src/cg/image/destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<arc::R<Self>> {
Expand Down
4 changes: 3 additions & 1 deletion cidre/src/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion cidre/src/cm/block_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cidre/src/cm/format_description_bridge.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
40 changes: 35 additions & 5 deletions cidre/src/cm/sample_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -946,7 +946,7 @@ pub mod buffer_attachment_keys {
}
}

pub mod errors {
pub mod err {
use crate::os::Error;

/// An allocation failed.
Expand Down Expand Up @@ -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());
}
}
4 changes: 4 additions & 0 deletions cidre/src/mtk/texture_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ impl TextureLoader {
Self::alloc().init_with_device(device)
}

pub fn with_sys_default_device() -> Option<arc::R<Self>> {
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(
Expand Down
2 changes: 2 additions & 0 deletions cidre/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl std::error::Error for Error {}

pub type Result<Ok = ()> = std::result::Result<Ok, Error>;

#[inline]
pub(crate) unsafe fn result_unchecked<T, R>(op: impl FnOnce(&mut Option<T>) -> R) -> Result<T>
where
R: Into<Result>,
Expand All @@ -85,6 +86,7 @@ where
Ok(unsafe { option.unwrap_unchecked() })
}

#[inline]
pub(crate) fn result_init<T, R>(op: impl FnOnce(*mut T) -> R) -> Result<T>
where
R: Into<Result>,
Expand Down
1 change: 1 addition & 0 deletions cidre/src/vn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9aa1f1a

Please sign in to comment.