playa_ffmpeg/util/
interrupt.rs1use std::{panic, process};
2
3use crate::ffi::*;
4use libc::{c_int, c_void};
5
6pub struct Interrupt {
7 pub interrupt: AVIOInterruptCB,
8}
9
10extern "C" fn callback<F>(opaque: *mut c_void) -> c_int
11where
12 F: FnMut() -> bool,
13{
14 #[allow(clippy::needless_borrow)]
16 match panic::catch_unwind(|| (unsafe { &mut *(opaque as *mut F) })()) {
17 Ok(ret) => ret as c_int,
18 Err(_) => process::abort(),
19 }
20}
21
22pub fn new<F>(opaque: Box<F>) -> Interrupt
23where
24 F: FnMut() -> bool,
25{
26 let interrupt_cb = AVIOInterruptCB { callback: Some(callback::<F>), opaque: Box::into_raw(opaque) as *mut c_void };
27 Interrupt { interrupt: interrupt_cb }
28}