Add support for VLM events

merge-requests/7/merge
Raniz 2019-11-19 15:20:05 +01:00
parent 31a5840407
commit cd3b94f83b
1 changed files with 54 additions and 23 deletions

View File

@ -5,7 +5,7 @@
use std::ptr; use std::ptr;
use std::borrow::Cow; use std::borrow::Cow;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ffi::CString; use std::ffi::{CString, CStr};
use std::i32; use std::i32;
use sys; use sys;
use ::tools::{to_cstr, from_cstr, from_cstr_ref}; use ::tools::{to_cstr, from_cstr, from_cstr_ref};
@ -190,6 +190,15 @@ impl Instance {
} }
} }
/// Returns the VLM event manager
pub fn vlm_event_manager<'a>(&'a self) -> EventManager<'a> {
unsafe{
let p = sys::libvlc_vlm_get_event_manager(self.ptr);
assert!(!p.is_null());
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
}
}
/// Set logging callback /// Set logging callback
pub fn set_log<F: Fn(LogLevel, Log, Cow<str>) + Send + 'static>(&self, f: F) { pub fn set_log<F: Fn(LogLevel, Log, Cow<str>) + Send + 'static>(&self, f: F) {
let cb: Box<Box<Fn(LogLevel, Log, Cow<str>) + Send + 'static>> = Box::new(Box::new(f)); let cb: Box<Box<Fn(LogLevel, Log, Cow<str>) + Send + 'static>> = Box::new(Box::new(f));
@ -367,17 +376,17 @@ pub enum Event {
MediaDiscovererStarted, MediaDiscovererStarted,
MediaDiscovererEnded, MediaDiscovererEnded,
VlmMediaAdded, VlmMediaAdded(Option<String>, Option<String>),
VlmMediaRemoved, VlmMediaRemoved(Option<String>, Option<String>),
VlmMediaChanged, VlmMediaChanged(Option<String>, Option<String>),
VlmMediaInstanceStarted, VlmMediaInstanceStarted(Option<String>, Option<String>),
VlmMediaInstanceStopped, VlmMediaInstanceStopped(Option<String>, Option<String>),
VlmMediaInstanceStatusInit, VlmMediaInstanceStatusInit(Option<String>, Option<String>),
VlmMediaInstanceStatusOpening, VlmMediaInstanceStatusOpening(Option<String>, Option<String>),
VlmMediaInstanceStatusPlaying, VlmMediaInstanceStatusPlaying(Option<String>, Option<String>),
VlmMediaInstanceStatusPause, VlmMediaInstanceStatusPause(Option<String>, Option<String>),
VlmMediaInstanceStatusEnd, VlmMediaInstanceStatusEnd(Option<String>, Option<String>),
VlmMediaInstanceStatusError VlmMediaInstanceStatusError(Option<String>, Option<String>)
} }
pub struct EventManager<'a> { pub struct EventManager<'a> {
@ -556,37 +565,59 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
Event::MediaDiscovererEnded Event::MediaDiscovererEnded
}, },
EventType::VlmMediaAdded => { EventType::VlmMediaAdded => {
Event::VlmMediaAdded unsafe {
Event::VlmMediaAdded(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaRemoved => { EventType::VlmMediaRemoved => {
Event::VlmMediaRemoved unsafe {
Event::VlmMediaRemoved(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaChanged => { EventType::VlmMediaChanged => {
Event::VlmMediaChanged unsafe {
Event::VlmMediaChanged(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStarted => { EventType::VlmMediaInstanceStarted => {
Event::VlmMediaInstanceStarted unsafe {
Event::VlmMediaInstanceStarted(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStopped => { EventType::VlmMediaInstanceStopped => {
Event::VlmMediaInstanceStopped unsafe {
Event::VlmMediaInstanceStopped(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStatusInit => { EventType::VlmMediaInstanceStatusInit => {
Event::VlmMediaInstanceStatusInit unsafe {
Event::VlmMediaInstanceStatusInit(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStatusOpening => { EventType::VlmMediaInstanceStatusOpening => {
Event::VlmMediaInstanceStatusOpening unsafe {
Event::VlmMediaInstanceStatusOpening(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStatusPlaying => { EventType::VlmMediaInstanceStatusPlaying => {
Event::VlmMediaInstanceStatusPlaying unsafe {
Event::VlmMediaInstanceStatusPlaying(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStatusPause => { EventType::VlmMediaInstanceStatusPause => {
Event::VlmMediaInstanceStatusPause unsafe {
Event::VlmMediaInstanceStatusPause(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStatusEnd => { EventType::VlmMediaInstanceStatusEnd => {
Event::VlmMediaInstanceStatusEnd unsafe {
Event::VlmMediaInstanceStatusEnd(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
EventType::VlmMediaInstanceStatusError => { EventType::VlmMediaInstanceStatusError => {
Event::VlmMediaInstanceStatusError unsafe {
Event::VlmMediaInstanceStatusError(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
}, },
} }
} }