Skip to content

Commit

Permalink
more api cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 19, 2024
1 parent 1e811ee commit f2af426
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
27 changes: 12 additions & 15 deletions cidre/src/av/asset/writer_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl WriterInput {
Self::alloc().init_media_type_output_settings_throws(media_type, output_settings)
}

pub fn with_media_type_and_output_settings<'ar>(
pub fn with_media_type_and_output_settings<'ear>(
media_type: &MediaType,
output_settings: Option<&ns::Dictionary<ns::String, ns::Id>>,
) -> Result<arc::R<WriterInput>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, arc::R<WriterInput>> {
ns::try_catch(|| unsafe {
Self::alloc().init_media_type_output_settings_throws(media_type, output_settings)
})
Expand All @@ -50,11 +50,11 @@ impl WriterInput {
)
}

pub fn with_media_type_output_settings_source_format_hint<'ar>(
pub fn with_media_type_output_settings_source_format_hint<'ear>(
media_type: &MediaType,
output_settings: Option<&ns::Dictionary<ns::String, ns::Id>>,
source_format_hint: Option<&cm::FormatDesc>,
) -> Result<arc::R<WriterInput>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, arc::R<WriterInput>> {
ns::try_catch(|| unsafe {
Self::with_media_type_output_settings_source_format_hint_throws(
media_type,
Expand All @@ -79,17 +79,17 @@ impl WriterInput {
Self::with_media_type_output_settings_throws(media_type, None)
}

pub fn with_media_type<'ar>(
pub fn with_media_type<'ear>(
media_type: &MediaType,
) -> Result<arc::R<WriterInput>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, arc::R<WriterInput>> {
ns::try_catch(|| unsafe { Self::with_media_type_throws(media_type) })
}

#[objc::msg_send(mediaType)]
pub fn media_type(&self) -> &MediaType;
pub fn media_type(&self) -> arc::R<MediaType>;

#[objc::msg_send(outputSettings)]
pub fn output_settings(&self) -> Option<&ns::Dictionary<ns::String, ns::Id>>;
pub fn output_settings(&self) -> Option<arc::R<ns::Dictionary<ns::String, ns::Id>>>;

#[objc::msg_send(isReadyForMoreMediaData)]
pub fn is_ready_for_more_media_data(&self) -> bool;
Expand Down Expand Up @@ -120,10 +120,7 @@ impl WriterInput {
#[objc::msg_send(appendSampleBuffer:)]
pub unsafe fn append_sample_buf_throws(&mut self, buffer: &cm::SampleBuf) -> bool;

pub fn append_sample_buf<'ar>(
&mut self,
buffer: &cm::SampleBuf,
) -> Result<bool, &'ar ns::Exception> {
pub fn append_sample_buf<'ear>(&mut self, buffer: &cm::SampleBuf) -> ns::ExResult<'ear, bool> {
ns::try_catch(|| unsafe { self.append_sample_buf_throws(buffer) })
}

Expand Down Expand Up @@ -165,7 +162,7 @@ impl WriterInputPixelBufAdaptor {
pub fn with_input_writer<'ear>(
input: &WriterInput,
src_pixel_buf_attrs: Option<ns::Dictionary<ns::String, ns::Id>>,
) -> Result<arc::R<Self>, &'ear ns::Exception> {
) -> ns::ExResult<'ear, arc::R<Self>> {
ns::try_catch(|| unsafe {
Self::alloc().init_with_asset_writer_input_throws(input, src_pixel_buf_attrs)
})
Expand Down Expand Up @@ -195,7 +192,7 @@ impl WriterInputPixelBufAdaptor {
&mut self,
buf: &cv::PixelBuf,
pts: cm::Time,
) -> Result<bool, &'ear ns::Exception> {
) -> ns::ExResult<'ear, bool> {
ns::try_catch(|| unsafe { self.append_pixel_buf_with_pts_throws(buf, pts) })
}
}
Expand All @@ -215,7 +212,7 @@ mod tests {
fn basics() {
let input = av::asset::WriterInput::with_media_type(av::MediaType::video())
.expect("failed to create writer");
assert_eq!(input.media_type(), av::MediaType::video());
assert_eq!(input.media_type().as_ref(), av::MediaType::video());
av::asset::WriterInput::with_media_type(av::MediaType::muxed()).unwrap();
av::asset::WriterInput::with_media_type(av::MediaType::audio()).unwrap();
av::asset::WriterInput::with_media_type(av::MediaType::text()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion cidre/src/mc/nearby_service_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl NearbyServiceBrowser {
pub fn with_peer<'ear>(
peer: &mc::PeerId,
service_type: &ns::String,
) -> Result<arc::R<Self>, &'ear ns::Exception> {
) -> ns::ExResult<'ear, arc::R<Self>> {
ns::try_catch(|| unsafe {
Self::alloc().init_with_peer_and_service_type_throws(peer, service_type)
})
Expand Down
8 changes: 4 additions & 4 deletions cidre/src/mtl/indirect_command_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ impl IndirectCmdBuf {
) -> arc::R<mtl::IndirectRenderCmd>;

#[inline]
pub fn indirect_render_cmd_at<'ar>(
pub fn indirect_render_cmd_at<'ear>(
&self,
index: usize,
) -> Result<arc::R<mtl::IndirectRenderCmd>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, arc::R<mtl::IndirectRenderCmd>> {
ns::try_catch(|| unsafe { self.indirect_render_cmd_at_throws(index) })
}

Expand All @@ -142,10 +142,10 @@ impl IndirectCmdBuf {
) -> arc::R<mtl::IndirectComputeCmd>;

#[inline]
pub fn indirect_compute_cmd_at<'ar>(
pub fn indirect_compute_cmd_at<'ear>(
&self,
index: usize,
) -> Result<arc::R<mtl::IndirectComputeCmd>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, arc::R<mtl::IndirectComputeCmd>> {
ns::try_catch(|| unsafe { self.indirect_compute_cmd_at_throws(index) })
}
}
Expand Down
16 changes: 8 additions & 8 deletions cidre/src/ns/key_value_coding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ impl ns::Id {
#[objc::msg_send(valueForKey:)]
pub unsafe fn value_for_key_throws(&self, key: &ns::String) -> Option<arc::R<Self>>;

pub fn value_for_key<'ar>(
pub fn value_for_key<'ear>(
&self,
key: &ns::String,
) -> Result<Option<arc::R<Self>>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, Option<arc::R<Self>>> {
ns::try_catch(|| unsafe { self.value_for_key_throws(key) })
}

#[objc::msg_send(setValue:forKey:)]
pub unsafe fn set_value_for_key_throws(&mut self, val: Option<&Self>, key: &ns::String);

pub fn set_value_for_key<'ar>(
pub fn set_value_for_key<'ear>(
&mut self,
val: Option<&Self>,
key: &ns::String,
) -> Result<(), &'ar ns::Exception> {
) -> ns::ExResult<'ear> {
ns::try_catch(|| unsafe { self.set_value_for_key_throws(val, key) })
}

#[objc::msg_send(valueForKeyPath:)]
pub unsafe fn value_for_key_path_throws(&self, key_path: &ns::String) -> Option<arc::R<Self>>;

pub fn value_for_key_path<'ar>(
pub fn value_for_key_path<'ear>(
&self,
key_path: &ns::String,
) -> Result<Option<arc::R<Self>>, &'ar ns::Exception> {
) -> ns::ExResult<'ear, Option<arc::R<Self>>> {
ns::try_catch(|| unsafe { self.value_for_key_path_throws(key_path) })
}

Expand All @@ -39,11 +39,11 @@ impl ns::Id {
key_path: &ns::String,
);

pub fn set_value_for_key_path<'ar>(
pub fn set_value_for_key_path<'ear>(
&mut self,
val: Option<&Self>,
key_path: &ns::String,
) -> Result<(), &'ar ns::Exception> {
) -> ns::ExResult<'ear> {
ns::try_catch(|| unsafe { self.set_value_for_key_path_throws(val, key_path) })
}
}
Expand Down

0 comments on commit f2af426

Please sign in to comment.