Created
March 2, 2018 00:26
-
-
Save djg/c88ac72b549660ccbaa83e226f96dfdf to your computer and use it in GitHub Desktop.
Pulse Audio Callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ServerInfoCB = FnMut(&ContextRef, Option<&ServerInfoRef>) + Send + Sync + 'static; | |
pub fn get_server_info<CB>(&self, cb: CB) -> Result<Operation> | |
where | |
CB: FnMut(&ContextRef, Option<&SourceInfo>) + Send + Sync + 'static, | |
{ | |
let userdata = Box::into_raw(Box::new(cb)) as *mut c_void; | |
let cb: ffi::pa_server_info_cb_t = Some(c_get_server_info_cb); | |
op_or_err!( | |
self, | |
ffi::pa_context_get_server_info(self.as_ptr(), cb, userdata) | |
) | |
} | |
unsafe extern "C" fn c_get_server_info_cb( | |
c: *mut ffi::pa_context, | |
i: *const ffi::pa_server_info, | |
userdata: *mut c_void, | |
) { | |
if panic::catch_unwind(|| { | |
let ctx = ContextRef::from_ptr(c); | |
let info = if i.is_null() { | |
None | |
} else { | |
Some(ServerInfoRef::from_ptr(i as *mut _)) | |
}; | |
let cb = Box::from_raw(userdata as *mut ServerInfoCB); | |
cb(ctx, info); | |
}).is_err() | |
{ | |
process::abort() | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment