Retrieve IOSurface in Rust callback as opposed to doing so in delegate
This commit is contained in:
parent
c4110edb78
commit
d30e360664
1 changed files with 21 additions and 25 deletions
|
@ -63,7 +63,24 @@ fn main() {
|
||||||
let output: id = msg_send![capture_output_class, alloc];
|
let output: id = msg_send![capture_output_class, alloc];
|
||||||
let output: id = msg_send![output, init];
|
let output: id = msg_send![output, init];
|
||||||
let callback = Box::new(|buffer: CMSampleBufferRef| {
|
let callback = Box::new(|buffer: CMSampleBufferRef| {
|
||||||
dbg!("HEY!");
|
let buffer = CMSampleBuffer::wrap_under_get_rule(buffer);
|
||||||
|
let attachments = buffer.attachments();
|
||||||
|
let attachments = attachments.first().expect("no attachments for sample");
|
||||||
|
let string = bindings::SCStreamFrameInfoStatus.0 as CFStringRef;
|
||||||
|
let status = core_foundation::number::CFNumber::wrap_under_get_rule(
|
||||||
|
*attachments.get(string) as CFNumberRef,
|
||||||
|
)
|
||||||
|
.to_i64()
|
||||||
|
.expect("invalid frame info status");
|
||||||
|
|
||||||
|
if status != bindings::SCFrameStatus_SCFrameStatusComplete {
|
||||||
|
println!("received incomplete frame");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let image_buffer = buffer.image_buffer();
|
||||||
|
dbg!(image_buffer.width(), image_buffer.height());
|
||||||
|
let io_surface = image_buffer.io_surface();
|
||||||
}) as Box<dyn FnMut(CMSampleBufferRef)>;
|
}) as Box<dyn FnMut(CMSampleBufferRef)>;
|
||||||
let callback = Box::into_raw(Box::new(callback));
|
let callback = Box::into_raw(Box::new(callback));
|
||||||
(*output).set_ivar("callback", callback as *mut c_void);
|
(*output).set_ivar("callback", callback as *mut c_void);
|
||||||
|
@ -159,34 +176,13 @@ extern "C" fn sample_output(
|
||||||
buffer: id,
|
buffer: id,
|
||||||
_kind: SCStreamOutputType,
|
_kind: SCStreamOutputType,
|
||||||
) {
|
) {
|
||||||
let buffer = unsafe { CMSampleBuffer::wrap_under_get_rule(buffer as CMSampleBufferRef) };
|
|
||||||
let callback = unsafe { *this.get_ivar::<*mut c_void>("callback") };
|
|
||||||
let callback = callback as *mut Box<dyn FnMut(CMSampleBufferRef)>;
|
|
||||||
let x = unsafe { callback.as_mut().unwrap() };
|
|
||||||
(*x)(buffer.as_concrete_TypeRef());
|
|
||||||
|
|
||||||
let attachments = buffer.attachments();
|
|
||||||
let attachments = attachments.first().expect("no attachments for sample");
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let string = bindings::SCStreamFrameInfoStatus.0 as CFStringRef;
|
let callback = *this.get_ivar::<*mut c_void>("callback");
|
||||||
let status = core_foundation::number::CFNumber::wrap_under_get_rule(
|
let callback = &mut *(callback as *mut Box<dyn FnMut(CMSampleBufferRef)>);
|
||||||
*attachments.get(string) as CFNumberRef,
|
(*callback)(buffer as CMSampleBufferRef);
|
||||||
)
|
|
||||||
.to_i64()
|
|
||||||
.expect("invalid frame info status");
|
|
||||||
|
|
||||||
if status != bindings::SCFrameStatus_SCFrameStatusComplete {
|
|
||||||
println!("received incomplete frame");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let image_buffer = buffer.image_buffer();
|
|
||||||
dbg!(image_buffer.width(), image_buffer.height());
|
|
||||||
let io_surface = image_buffer.io_surface();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
|
fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
|
||||||
cx.platform().quit();
|
cx.platform().quit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue