enable mpv verbose logging

This commit is contained in:
Erica Z 2024-11-02 18:25:26 +01:00
parent b966bc18df
commit 8ab1e1e1fa

View file

@ -86,6 +86,9 @@ impl Handle {
); );
} }
// set up verbose logging for now
Error::from_return_code(unsafe { ffi::mpv_request_log_messages(inner.as_ptr(), c"v".as_ptr()) }).unwrap();
// TODO: maybe we need to set something before initialization, but idk // TODO: maybe we need to set something before initialization, but idk
// also wed need a builder, since "Note that you should avoid doing concurrent accesses on the uninitialized client handle." // also wed need a builder, since "Note that you should avoid doing concurrent accesses on the uninitialized client handle."
Error::from_return_code(unsafe { ffi::mpv_initialize(inner.as_ptr()) }) Error::from_return_code(unsafe { ffi::mpv_initialize(inner.as_ptr()) })
@ -116,6 +119,15 @@ impl Handle {
match event.event_id { match event.event_id {
ffi::mpv_event_id_MPV_EVENT_NONE => break, ffi::mpv_event_id_MPV_EVENT_NONE => break,
ffi::mpv_event_id_MPV_EVENT_LOG_MESSAGE => {
let data = unsafe { &*(event.data as *mut ffi::mpv_event_log_message) };
// TODO: actual logging?
let prefix = unsafe { CStr::from_ptr(data.prefix) }.to_str().unwrap();
let level = unsafe { CStr::from_ptr(data.level) }.to_str().unwrap();
let text = unsafe { CStr::from_ptr(data.text) }.to_str().unwrap();
print!("[{prefix}] {level}: {text}");
},
11 => { /* deprecated, ignore */ } 11 => { /* deprecated, ignore */ }
_ => todo!("event {}", event.event_id), _ => todo!("event {}", event.event_id),
@ -134,8 +146,9 @@ impl Handle {
impl Drop for Handle { impl Drop for Handle {
fn drop(&mut self) { fn drop(&mut self) {
// destroy? terminate_destroy?? unsafe {
todo!() ffi::mpv_destroy(self.inner.as_ptr());
}
} }
} }