Skip to content

Commit

Permalink
More AVSampleBufferVideoRenderer api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 19, 2024
1 parent 88d14d1 commit 171fbea
Showing 1 changed file with 92 additions and 3 deletions.
95 changes: 92 additions & 3 deletions cidre/src/av/sample_buffer/video_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{api, arc, av, cm, cv, define_obj_type, ns, objc};
use crate::{api, arc, av, blocks, cm, cv, define_obj_type, ns, objc};

define_obj_type!(
#[doc(alias = "AVSampleBufferVideoRenderer")]
Expand All @@ -14,10 +14,33 @@ impl VideoRenderer {
pub fn status(&self) -> av::QueuedSampleBufRenderingStatus;

#[objc::msg_send(error)]
pub fn error(&self) -> Option<&ns::Error>;
pub fn error(&self) -> Option<arc::R<ns::Error>>;

#[objc::msg_send(requiresFlushToResumeDecoding)]
pub fn requires_flush_to_resume_decoding(&self) -> bool;

/// Instructs the video renderer to discard pending enqueued sample buffers and call the provided block when complete.
#[objc::msg_send(removeDisplayedImage:completionHandler:)]
pub fn flush_ch_block(
&mut self,
remove_displayed_image: bool,
ch: Option<&mut blocks::CompletionBlock>,
);

/// Instructs the video renderer to discard pending enqueued sample buffers and call the provided closure when complete.
#[doc(alias = "removeDisplayedImage:completionHandler:")]
pub fn flush_ch(&mut self, remove_displayed_image: bool, ch: impl FnMut() + 'static) {
let mut block = blocks::CompletionBlock::new0(ch);
self.flush_ch_block(remove_displayed_image, Some(&mut block));
}

#[doc(alias = "removeDisplayedImage:completionHandler:")]
#[cfg(feature = "async")]
pub async fn flush(&mut self, remove_displayed_image: bool) {
let (f, mut block) = blocks::comp0();
self.flush_ch_block(remove_displayed_image, Some(&mut block));
f.await
}
}

/// AVSampleBufferVideoRendererPixelBufferOutput
Expand All @@ -30,7 +53,7 @@ impl VideoRenderer {
tvos = 17.4,
visionos = 1.1
)]
pub fn copy_displayed_pixel_buf(&self) -> Option<arc::Retained<cv::PixelBuf>>;
pub fn displayed_pixel_buf(&self) -> Option<arc::Retained<cv::PixelBuf>>;
}

/// AVSampleBufferVideoRendererPowerOptimization
Expand Down Expand Up @@ -69,9 +92,75 @@ impl VideoRenderer {
visionos = 1.1
)]
pub fn reset_upcoming_sample_buf_pts_expectations(&mut self);

#[api::available(
macos = 14.0,
maccatalyst = 17.0,
ios = 17.0,
tvos = 17.0,
visionos = 1.0
)]
pub fn did_fail_to_decode_notification() -> &'static ns::NotificationName {
unsafe { AVSampleBufferVideoRendererDidFailToDecodeNotification }
}

#[api::available(
macos = 14.0,
maccatalyst = 17.0,
ios = 17.0,
tvos = 17.0,
visionos = 1.0
)]
pub fn did_fail_to_decode_notification_err_key() -> &'static ns::String {
unsafe { AVSampleBufferVideoRendererDidFailToDecodeNotificationErrorKey }
}

#[api::available(
macos = 14.0,
maccatalyst = 17.0,
ios = 17.0,
tvos = 17.0,
visionos = 1.0
)]
pub fn requires_flush_to_resume_decoding_did_change_notification(
) -> &'static ns::NotificationName {
unsafe { AVSampleBufferVideoRendererRequiresFlushToResumeDecodingDidChangeNotification }
}
}

#[link(name = "ca", kind = "static")]
extern "C" {
static AV_SAMPLE_BUFFER_VIDEO_RENDERER: &'static objc::Class<VideoRenderer>;
}

#[link(name = "AVFoundation", kind = "framework")]
#[api::weak]
extern "C" {
#[api::available(
macos = 14.0,
maccatalyst = 17.0,
ios = 17.0,
tvos = 17.0,
visionos = 1.0
)]
static AVSampleBufferVideoRendererDidFailToDecodeNotification: &'static ns::NotificationName;

#[api::available(
macos = 14.0,
maccatalyst = 17.0,
ios = 17.0,
tvos = 17.0,
visionos = 1.0
)]
static AVSampleBufferVideoRendererDidFailToDecodeNotificationErrorKey: &'static ns::String;

#[api::available(
macos = 14.0,
maccatalyst = 17.0,
ios = 17.0,
tvos = 17.0,
visionos = 1.0
)]
static AVSampleBufferVideoRendererRequiresFlushToResumeDecodingDidChangeNotification:
&'static ns::NotificationName;
}

0 comments on commit 171fbea

Please # to comment.