av_foundation/
capture_video_data_output.rs

1use core_media::sample_buffer::CMSampleBufferRef;
2use dispatch2::Queue;
3use objc2::{extern_class, msg_send, msg_send_id, mutability::InteriorMutable, rc::Id, runtime::ProtocolObject, ClassType, ProtocolType};
4use objc2_foundation::{NSArray, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSString};
5
6use crate::{capture_output_base::AVCaptureOutput, capture_session::AVCaptureConnection};
7
8extern_class!(
9    #[derive(Debug, PartialEq, Eq, Hash)]
10    pub struct AVCaptureVideoDataOutput;
11
12    unsafe impl ClassType for AVCaptureVideoDataOutput {
13        type Super = AVCaptureOutput;
14        type Mutability = InteriorMutable;
15    }
16);
17
18unsafe impl NSObjectProtocol for AVCaptureVideoDataOutput {}
19
20impl AVCaptureVideoDataOutput {
21    pub fn new() -> Id<Self> {
22        unsafe { msg_send_id![AVCaptureVideoDataOutput::class(), new] }
23    }
24
25    pub fn get_sample_buffer_delegate(&self) -> Option<Id<ProtocolObject<dyn AVCaptureVideoDataOutputSampleBufferDelegate>>> {
26        unsafe { msg_send_id![self, sampleBufferDelegate] }
27    }
28
29    pub fn set_sample_buffer_delegate(&self, delegate: &ProtocolObject<dyn AVCaptureVideoDataOutputSampleBufferDelegate>, queue: &Queue) {
30        unsafe { msg_send![self, setSampleBufferDelegate: delegate queue: queue.as_raw() as *const NSObject] }
31    }
32
33    pub fn get_video_settings(&self) -> Option<Id<NSDictionary<NSString, NSObject>>> {
34        unsafe { msg_send_id![self, videoSettings] }
35    }
36
37    pub fn set_video_settings(&self, video_settings: &NSDictionary<NSString, NSObject>) {
38        unsafe { msg_send![self, setVideoSettings: video_settings] }
39    }
40
41    pub fn get_available_video_cv_pixel_format_types(&self) -> Id<NSArray<NSNumber>> {
42        unsafe { msg_send_id![self, availableVideoCVPixelFormatTypes] }
43    }
44
45    pub fn get_available_video_data_format_types(&self) -> Id<NSArray<NSNumber>> {
46        unsafe { msg_send_id![self, availableVideoDataFormatTypes] }
47    }
48
49    pub fn get_always_discards_late_video_frames(&self) -> bool {
50        unsafe { msg_send![self, alwaysDiscardsLateVideoFrames] }
51    }
52
53    pub fn set_always_discards_late_video_frames(&self, always_discards_late_video_frames: bool) {
54        unsafe { msg_send![self, setAlwaysDiscardsLateVideoFrames: always_discards_late_video_frames] }
55    }
56}
57
58extern_protocol!(
59    pub unsafe trait AVCaptureVideoDataOutputSampleBufferDelegate: NSObjectProtocol {
60        #[method(captureOutput:didOutputSampleBuffer:fromConnection:)]
61        #[optional]
62        unsafe fn capture_output_did_output_sample_buffer(
63            &self,
64            capture_output: &AVCaptureOutput,
65            sample_buffer: CMSampleBufferRef,
66            connection: &AVCaptureConnection,
67        );
68        #[method(captureOutput:didDropSampleBuffer:fromConnection:)]
69        #[optional]
70        unsafe fn capture_output_did_drop_sample_buffer(
71            &self,
72            capture_output: &AVCaptureOutput,
73            sample_buffer: CMSampleBufferRef,
74            connection: &AVCaptureConnection,
75        );
76    }
77
78    unsafe impl ProtocolType for dyn AVCaptureVideoDataOutputSampleBufferDelegate {}
79);