From 171fbeab53c72f19b28f54dc8509946d650ee752 Mon Sep 17 00:00:00 2001 From: Yury Date: Tue, 19 Nov 2024 09:40:53 +0300 Subject: [PATCH] More AVSampleBufferVideoRenderer api --- cidre/src/av/sample_buffer/video_renderer.rs | 95 +++++++++++++++++++- 1 file changed, 92 insertions(+), 3 deletions(-) diff --git a/cidre/src/av/sample_buffer/video_renderer.rs b/cidre/src/av/sample_buffer/video_renderer.rs index e4fe0612..464ec9af 100644 --- a/cidre/src/av/sample_buffer/video_renderer.rs +++ b/cidre/src/av/sample_buffer/video_renderer.rs @@ -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")] @@ -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>; #[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 @@ -30,7 +53,7 @@ impl VideoRenderer { tvos = 17.4, visionos = 1.1 )] - pub fn copy_displayed_pixel_buf(&self) -> Option>; + pub fn displayed_pixel_buf(&self) -> Option>; } /// AVSampleBufferVideoRendererPowerOptimization @@ -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; } + +#[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; +}