Rename ffi module to sys

merge-requests/7/merge
T. Okubo 2018-02-27 22:52:21 +09:00
parent c4f08bb2cb
commit 3d029b0c37
9 changed files with 149 additions and 149 deletions

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use ffi;
use sys;
use ::MediaPlayer;
use ::TrackDescription;
use ::tools::from_cstr;
@ -17,7 +17,7 @@ pub trait MediaPlayerAudioEx {
impl MediaPlayerAudioEx for MediaPlayer {
fn get_mute(&self) -> Option<bool> {
let r = unsafe{ ffi::libvlc_audio_get_mute(self.ptr) };
let r = unsafe{ sys::libvlc_audio_get_mute(self.ptr) };
if r == 0 {
Some(false)
@ -29,20 +29,20 @@ impl MediaPlayerAudioEx for MediaPlayer {
}
fn set_mute(&self, status: bool) {
unsafe{ ffi::libvlc_audio_set_mute(self.ptr, if status { 1 }else{ 0 }) };
unsafe{ sys::libvlc_audio_set_mute(self.ptr, if status { 1 }else{ 0 }) };
}
fn get_volume(&self) -> i32 {
unsafe{ ffi::libvlc_audio_get_volume(self.ptr) }
unsafe{ sys::libvlc_audio_get_volume(self.ptr) }
}
fn set_volume(&self, volume: i32) -> Result<(), ()> {
unsafe{
if ffi::libvlc_audio_set_volume(self.ptr, volume) == 0 { Ok(()) }else{ Err(()) }
if sys::libvlc_audio_set_volume(self.ptr, volume) == 0 { Ok(()) }else{ Err(()) }
}
}
fn get_audio_track_description(&self) -> Option<Vec<TrackDescription>> {
unsafe{
let p0 = ffi::libvlc_audio_get_track_description(self.ptr);
let p0 = sys::libvlc_audio_get_track_description(self.ptr);
if p0.is_null() { return None; }
let mut td = Vec::new();
let mut p = p0;
@ -51,7 +51,7 @@ impl MediaPlayerAudioEx for MediaPlayer {
td.push(TrackDescription{ id: (*p).i_id, name: from_cstr((*p).psz_name) });
p = (*p).p_next;
}
ffi::libvlc_track_description_list_release(p0);
sys::libvlc_track_description_list_release(p0);
Some(td)
}
}

View File

@ -5,7 +5,7 @@
use std::ptr::null;
use std::borrow::Cow;
use std::marker::PhantomData;
use ffi;
use sys;
use ::tools::{to_cstr, from_cstr, from_cstr_ref};
use ::libc::{c_void, c_char, c_int};
use ::enums::*;
@ -13,26 +13,26 @@ use ::enums::*;
/// Retrieve libvlc version.
pub fn version() -> Cow<'static, str> {
unsafe{
from_cstr_ref(ffi::libvlc_get_version()).unwrap()
from_cstr_ref(sys::libvlc_get_version()).unwrap()
}
}
/// Retrieve libvlc compiler version.
pub fn compiler() -> Cow<'static, str> {
unsafe{
from_cstr_ref(ffi::libvlc_get_compiler()).unwrap()
from_cstr_ref(sys::libvlc_get_compiler()).unwrap()
}
}
pub struct Instance {
pub ptr: *mut ffi::libvlc_instance_t,
pub ptr: *mut sys::libvlc_instance_t,
}
impl Instance {
/// Create and initialize a libvlc instance.
pub fn new() -> Option<Instance> {
unsafe{
let p = ffi::libvlc_new(0, null());
let p = sys::libvlc_new(0, null());
if p.is_null() {
return None;
@ -47,7 +47,7 @@ impl Instance {
let cstr = to_cstr(name);
let result = unsafe{
ffi::libvlc_add_intf(self.ptr, cstr.as_ptr())
sys::libvlc_add_intf(self.ptr, cstr.as_ptr())
};
if result == 0 { Ok(()) }
@ -58,20 +58,20 @@ impl Instance {
/// LibVLC passes this as the user agent string when a protocol requires it.
pub fn set_user_agent(&self, name: &str, http: &str) {
unsafe{
ffi::libvlc_set_user_agent(
sys::libvlc_set_user_agent(
self.ptr, to_cstr(name).as_ptr(), to_cstr(http).as_ptr());
}
}
/// Waits until an interface causes the instance to exit.
pub fn wait(&self) {
unsafe{ ffi::libvlc_wait(self.ptr) };
unsafe{ sys::libvlc_wait(self.ptr) };
}
/// Sets some meta-information about the application.
pub fn set_app_id(&self, id: &str, version: &str, icon: &str) {
unsafe{
ffi::libvlc_set_app_id(
sys::libvlc_set_app_id(
self.ptr, to_cstr(id).as_ptr(), to_cstr(version).as_ptr(), to_cstr(icon).as_ptr());
}
}
@ -79,7 +79,7 @@ impl Instance {
/// Returns a list of audio filters that are available.
pub fn audio_filter_list_get(&self) -> Option<ModuleDescriptionList> {
unsafe{
let p = ffi::libvlc_audio_filter_list_get(self.ptr);
let p = sys::libvlc_audio_filter_list_get(self.ptr);
if p.is_null() { None }
else { Some(ModuleDescriptionList{ptr: p}) }
}
@ -88,7 +88,7 @@ impl Instance {
/// Returns a list of video filters that are available.
pub fn video_filter_list_get(&self) -> Option<ModuleDescriptionList> {
unsafe{
let p = ffi::libvlc_video_filter_list_get(self.ptr);
let p = sys::libvlc_video_filter_list_get(self.ptr);
if p.is_null() { None }
else { Some(ModuleDescriptionList{ptr: p}) }
}
@ -99,7 +99,7 @@ impl Instance {
let cb: Box<Box<Fn(LogLevel, Log, Cow<str>) + Send + 'static>> = Box::new(Box::new(f));
unsafe{
ffi::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _);
sys::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _);
}
}
}
@ -107,17 +107,17 @@ impl Instance {
impl Drop for Instance {
fn drop(&mut self) {
unsafe{
ffi::libvlc_release(self.ptr);
sys::libvlc_release(self.ptr);
}
}
}
extern "C" {
fn vsnprintf(s: *mut c_char, n: usize, fmt: *const c_char, arg: ffi::va_list);
fn vsnprintf(s: *mut c_char, n: usize, fmt: *const c_char, arg: sys::va_list);
}
const BUF_SIZE: usize = 1024; // Write log message to the buffer by vsnprintf.
unsafe extern "C" fn logging_cb(
data: *mut c_void, level: c_int, ctx: *const ffi::libvlc_log_t, fmt: *const c_char, args: ffi::va_list) {
data: *mut c_void, level: c_int, ctx: *const sys::libvlc_log_t, fmt: *const c_char, args: sys::va_list) {
let f: &Box<Fn(LogLevel, Log, Cow<str>) + Send + 'static> = ::std::mem::transmute(data);
let mut buf: [c_char; BUF_SIZE] = [0; BUF_SIZE];
@ -129,12 +129,12 @@ unsafe extern "C" fn logging_cb(
/// List of module description.
pub struct ModuleDescriptionList {
ptr: *mut ffi::libvlc_module_description_t,
ptr: *mut sys::libvlc_module_description_t,
}
impl Drop for ModuleDescriptionList {
fn drop(&mut self) {
unsafe{ ffi::libvlc_module_description_list_release(self.ptr) };
unsafe{ sys::libvlc_module_description_list_release(self.ptr) };
}
}
@ -148,8 +148,8 @@ impl<'a> IntoIterator for &'a ModuleDescriptionList {
}
pub struct ModuleDescriptionListIter<'a> {
ptr: *mut ffi::libvlc_module_description_t,
_phantomdata: PhantomData<&'a ffi::libvlc_module_description_t>,
ptr: *mut sys::libvlc_module_description_t,
_phantomdata: PhantomData<&'a sys::libvlc_module_description_t>,
}
/// Description of a module.
@ -204,11 +204,11 @@ impl<'a> ModuleDescriptionRef<'a> {
}
pub fn errmsg() -> Option<String> {
unsafe{ from_cstr(ffi::libvlc_errmsg()) }
unsafe{ from_cstr(sys::libvlc_errmsg()) }
}
pub fn clearerr() {
unsafe{ ffi::libvlc_clearerr() };
unsafe{ sys::libvlc_clearerr() };
}
#[derive(Clone, Debug)]
@ -273,8 +273,8 @@ pub enum Event {
}
pub struct EventManager<'a> {
pub ptr: *mut ffi::libvlc_event_manager_t,
pub _phantomdata: ::std::marker::PhantomData<&'a ffi::libvlc_event_manager_t>,
pub ptr: *mut sys::libvlc_event_manager_t,
pub _phantomdata: ::std::marker::PhantomData<&'a sys::libvlc_event_manager_t>,
}
impl<'a> EventManager<'a> {
@ -286,7 +286,7 @@ impl<'a> EventManager<'a> {
Box::new(Box::new(callback));
let result = unsafe{
ffi::libvlc_event_attach(
sys::libvlc_event_attach(
self.ptr, event_type as i32, event_manager_callback,
Box::into_raw(callback) as *mut c_void)
};
@ -299,20 +299,20 @@ impl<'a> EventManager<'a> {
}
}
unsafe extern "C" fn event_manager_callback(pe: *const ffi::libvlc_event_t, data: *mut c_void) {
unsafe extern "C" fn event_manager_callback(pe: *const sys::libvlc_event_t, data: *mut c_void) {
let f: &Box<Fn(Event, VLCObject) + Send + 'static> = ::std::mem::transmute(data);
f(conv_event(pe), VLCObject{_ptr: (*pe).p_obj});
}
// Convert c-style libvlc_event_t to Event
fn conv_event(pe: *const ffi::libvlc_event_t) -> Event {
fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
let event_type: EventType = unsafe{ ::std::mem::transmute((*pe)._type) };
match event_type {
EventType::MediaMetaChanged => {
unsafe{
let p = ffi::libvlc_event_t_union::get_media_meta_changed(pe);
let p = sys::libvlc_event_t_union::get_media_meta_changed(pe);
Event::MediaMetaChanged((*p).meta_type)
}
},
@ -321,13 +321,13 @@ fn conv_event(pe: *const ffi::libvlc_event_t) -> Event {
},
EventType::MediaDurationChanged => {
unsafe{
let p = ffi::libvlc_event_t_union::get_media_duration_changed(pe);
let p = sys::libvlc_event_t_union::get_media_duration_changed(pe);
Event::MediaDurationChanged((*p).new_duration)
}
},
EventType::MediaParsedChanged => {
unsafe{
let p = ffi::libvlc_event_t_union::get_media_parsed_changed(pe);
let p = sys::libvlc_event_t_union::get_media_parsed_changed(pe);
Event::MediaParsedChanged((*p).new_status)
}
},
@ -336,7 +336,7 @@ fn conv_event(pe: *const ffi::libvlc_event_t) -> Event {
},
EventType::MediaStateChanged => {
unsafe{
let p = ffi::libvlc_event_t_union::get_media_state_changed(pe);
let p = sys::libvlc_event_t_union::get_media_state_changed(pe);
Event::MediaStateChanged((*p).new_state)
}
},
@ -354,7 +354,7 @@ fn conv_event(pe: *const ffi::libvlc_event_t) -> Event {
},
EventType::MediaPlayerBuffering => {
unsafe{
let p = ffi::libvlc_event_t_union::get_media_player_buffering(pe);
let p = sys::libvlc_event_t_union::get_media_player_buffering(pe);
Event::MediaPlayerBuffering((*p).new_cache)
}
},
@ -384,7 +384,7 @@ fn conv_event(pe: *const ffi::libvlc_event_t) -> Event {
},
EventType::MediaPlayerPositionChanged => {
unsafe{
let p = ffi::libvlc_event_t_union::get_media_player_position_changed(pe);
let p = sys::libvlc_event_t_union::get_media_player_position_changed(pe);
Event::MediaPlayerPositionChanged((*p).new_position)
}
},
@ -489,6 +489,6 @@ pub struct VLCObject {
}
pub struct Log {
pub ptr: *const ffi::libvlc_log_t
pub ptr: *const sys::libvlc_log_t
}

View File

@ -4,7 +4,7 @@
extern crate libc;
pub mod ffi;
pub mod sys;
mod tools;
mod core;

View File

@ -2,14 +2,14 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use ffi;
use sys;
use ::{Instance, EventManager};
use ::enums::{State, Meta, TrackType};
use ::tools::{to_cstr, from_cstr, path_to_cstr};
use std::path::Path;
pub struct Media {
pub ptr: *mut ffi::libvlc_media_t,
pub ptr: *mut sys::libvlc_media_t,
}
impl Media {
@ -18,7 +18,7 @@ impl Media {
let cstr = to_cstr(mrl);
unsafe{
let p = ffi::libvlc_media_new_location(instance.ptr, cstr.as_ptr());
let p = sys::libvlc_media_new_location(instance.ptr, cstr.as_ptr());
if p.is_null() {
return None;
}
@ -35,7 +35,7 @@ impl Media {
};
unsafe{
let p = ffi::libvlc_media_new_path(instance.ptr, cstr.as_ptr());
let p = sys::libvlc_media_new_path(instance.ptr, cstr.as_ptr());
if p.is_null() {
return None;
}
@ -46,7 +46,7 @@ impl Media {
pub fn new_fd(instance: &Instance, fd: i32) -> Option<Media> {
unsafe{
let p = ffi::libvlc_media_new_fd(instance.ptr, fd);
let p = sys::libvlc_media_new_fd(instance.ptr, fd);
if p.is_null() {
return None;
}
@ -57,16 +57,16 @@ impl Media {
pub fn mrl(&self) -> Option<String> {
unsafe{
let p_str = ffi::libvlc_media_get_mrl(self.ptr);
let p_str = sys::libvlc_media_get_mrl(self.ptr);
let s = from_cstr(p_str);
ffi::libvlc_free(p_str as *mut ::libc::c_void);
sys::libvlc_free(p_str as *mut ::libc::c_void);
s
}
}
pub fn event_manager<'a>(&'a self) -> EventManager<'a> {
unsafe{
let p = ffi::libvlc_media_event_manager(self.ptr);
let p = sys::libvlc_media_event_manager(self.ptr);
assert!(!p.is_null());
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
}
@ -76,9 +76,9 @@ impl Media {
/// If the media has not yet been parsed this will return None.
pub fn get_meta(&self, meta: Meta) -> Option<String> {
unsafe{
let p_str = ffi::libvlc_media_get_meta(self.ptr, meta);
let p_str = sys::libvlc_media_get_meta(self.ptr, meta);
let s = from_cstr(p_str);
ffi::libvlc_free(p_str as *mut ::libc::c_void);
sys::libvlc_free(p_str as *mut ::libc::c_void);
s
}
}
@ -87,47 +87,47 @@ impl Media {
/// (This function will not save the meta, call save_meta in order to save the meta)
pub fn set_meta(&self, meta: Meta, value: &str) {
unsafe{
ffi::libvlc_media_set_meta(self.ptr, meta, to_cstr(value).as_ptr());
sys::libvlc_media_set_meta(self.ptr, meta, to_cstr(value).as_ptr());
}
}
/// Save the meta previously set.
pub fn save_meta(&self) -> bool {
if unsafe{ ffi::libvlc_media_save_meta(self.ptr) } == 0 { false }else{ true }
if unsafe{ sys::libvlc_media_save_meta(self.ptr) } == 0 { false }else{ true }
}
/// Get current state of media descriptor object.
pub fn state(&self) -> State {
unsafe{ ffi::libvlc_media_get_state(self.ptr) }
unsafe{ sys::libvlc_media_get_state(self.ptr) }
}
/// Get duration (in ms) of media descriptor object item.
pub fn duration(&self) -> Option<i64> {
let time = unsafe{
ffi::libvlc_media_get_duration(self.ptr)
sys::libvlc_media_get_duration(self.ptr)
};
if time != -1 { Some(time) }else{ None }
}
/// Parse a media.
pub fn parse(&self) {
unsafe{ ffi::libvlc_media_parse(self.ptr) };
unsafe{ sys::libvlc_media_parse(self.ptr) };
}
/// Parse a media.
pub fn parse_async(&self) {
unsafe{ ffi::libvlc_media_parse_async(self.ptr) };
unsafe{ sys::libvlc_media_parse_async(self.ptr) };
}
/// Get Parsed status for media descriptor object.
pub fn is_parsed(&self) -> bool {
if unsafe{ ffi::libvlc_media_is_parsed(self.ptr) } == 0 { false }else{ true }
if unsafe{ sys::libvlc_media_is_parsed(self.ptr) } == 0 { false }else{ true }
}
pub fn tracks(&self) -> Option<Vec<MediaTrack>> {
unsafe{
let mut p_track: *mut *mut ffi::libvlc_media_track_t = ::std::ptr::null_mut();
let n = ffi::libvlc_media_tracks_get(self.ptr, &mut p_track);
let mut p_track: *mut *mut sys::libvlc_media_track_t = ::std::ptr::null_mut();
let n = sys::libvlc_media_tracks_get(self.ptr, &mut p_track);
if n == 0 {
return None;
}
@ -177,7 +177,7 @@ impl Media {
});
}
ffi::libvlc_media_tracks_release(p_track, n);
sys::libvlc_media_tracks_release(p_track, n);
Some(track)
}
}
@ -185,7 +185,7 @@ impl Media {
impl Drop for Media {
fn drop(&mut self) {
unsafe{ ffi::libvlc_media_release(self.ptr) };
unsafe{ sys::libvlc_media_release(self.ptr) };
}
}

View File

@ -2,18 +2,18 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use ffi;
use sys;
use ::{Instance, MediaList};
pub struct MediaLibrary {
pub ptr: *mut ffi::libvlc_media_library_t,
pub ptr: *mut sys::libvlc_media_library_t,
}
impl MediaLibrary {
/// Create an new Media Library object.
pub fn new(instance: &Instance) -> Option<MediaLibrary> {
unsafe{
let p = ffi::libvlc_media_library_new(instance.ptr);
let p = sys::libvlc_media_library_new(instance.ptr);
if p.is_null() { None }else{ Some(MediaLibrary{ptr: p}) }
}
}
@ -21,14 +21,14 @@ impl MediaLibrary {
/// Load media library.
pub fn load(&self) -> Result<(), ()> {
unsafe{
if ffi::libvlc_media_library_load(self.ptr) == 0 { Ok(()) }else{ Err(()) }
if sys::libvlc_media_library_load(self.ptr) == 0 { Ok(()) }else{ Err(()) }
}
}
/// Get media library subitems.
pub fn media_list(&self) -> Option<MediaList> {
unsafe{
let p = ffi::libvlc_media_library_media_list(self.ptr);
let p = sys::libvlc_media_library_media_list(self.ptr);
if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
}
}
@ -36,6 +36,6 @@ impl MediaLibrary {
impl Drop for MediaLibrary {
fn drop(&mut self) {
unsafe{ ffi::libvlc_media_library_release(self.ptr) };
unsafe{ sys::libvlc_media_library_release(self.ptr) };
}
}

View File

@ -2,18 +2,18 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use ffi;
use sys;
use ::{Instance, Media, EventManager};
pub struct MediaList {
pub ptr: *mut ffi::libvlc_media_list_t,
pub ptr: *mut sys::libvlc_media_list_t,
}
impl MediaList {
/// Create an empty media list.
pub fn new(instance: &Instance) -> Option<MediaList> {
unsafe{
let p = ffi::libvlc_media_list_new(instance.ptr);
let p = sys::libvlc_media_list_new(instance.ptr);
if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
}
}
@ -21,14 +21,14 @@ impl MediaList {
/// Associate media instance with this media list instance.
/// If another media instance was present it will be released. The libvlc_media_list_lock should NOT be held upon entering this function.
pub fn set_media(&self, md: &Media) {
unsafe{ ffi::libvlc_media_list_set_media(self.ptr, md.ptr); }
unsafe{ sys::libvlc_media_list_set_media(self.ptr, md.ptr); }
}
/// Get media instance from this media list instance.
/// The MediaList::lock should NOT be held upon entering this function.
pub fn media(&self) -> Option<Media> {
unsafe{
let p = ffi::libvlc_media_list_media(self.ptr);
let p = sys::libvlc_media_list_media(self.ptr);
if p.is_null() { None }else{ Some(Media{ptr: p}) }
}
}
@ -37,7 +37,7 @@ impl MediaList {
/// The MediaList::lock should be held upon entering this function.
pub fn add_media(&self, md: &Media) -> Result<(), ()> {
unsafe{
if ffi::libvlc_media_list_add_media(self.ptr, md.ptr) == 0 { Ok(()) }else{ Err(()) }
if sys::libvlc_media_list_add_media(self.ptr, md.ptr) == 0 { Ok(()) }else{ Err(()) }
}
}
@ -45,7 +45,7 @@ impl MediaList {
/// The MediaList::lock should be held upon entering this function.
pub fn insert_media(&self, md: &Media, pos: i32) -> Result<(), ()> {
unsafe{
if ffi::libvlc_media_list_insert_media(self.ptr, md.ptr, pos) == 0 { Ok(()) }else{ Err(()) }
if sys::libvlc_media_list_insert_media(self.ptr, md.ptr, pos) == 0 { Ok(()) }else{ Err(()) }
}
}
@ -53,21 +53,21 @@ impl MediaList {
/// The MediaList::lock should be held upon entering this function.
pub fn remove_index(&self, pos: i32) -> Result<(), ()> {
unsafe{
if ffi::libvlc_media_list_remove_index(self.ptr, pos) == 0 { Ok(()) }else{ Err(()) }
if sys::libvlc_media_list_remove_index(self.ptr, pos) == 0 { Ok(()) }else{ Err(()) }
}
}
/// Get count on media list items.
/// The MediaList::lock should be held upon entering this function.
pub fn count(&self) -> i32 {
unsafe{ ffi::libvlc_media_list_count(self.ptr) }
unsafe{ sys::libvlc_media_list_count(self.ptr) }
}
/// List media instance in media list at a position.
/// The MediaList::lock should be held upon entering this function.
pub fn item_at_index(&self, pos: i32) -> Option<Media> {
unsafe{
let p = ffi::libvlc_media_list_item_at_index(self.ptr, pos);
let p = sys::libvlc_media_list_item_at_index(self.ptr, pos);
if p.is_null() { None }else{ Some(Media{ptr: p}) }
}
}
@ -75,31 +75,31 @@ impl MediaList {
/// Find index position of List media instance in media list.
pub fn index_of_item(&self, md: &Media) -> Option<i32> {
unsafe{
let i = ffi::libvlc_media_list_index_of_item(self.ptr, md.ptr);
let i = sys::libvlc_media_list_index_of_item(self.ptr, md.ptr);
if i == -1 { None }else{ Some(i) }
}
}
/// This indicates if this media list is read-only from a user point of view.
pub fn is_readonly(&self) -> bool {
unsafe{ if ffi::libvlc_media_list_is_readonly(self.ptr) == 0 { false }else{ true } }
unsafe{ if sys::libvlc_media_list_is_readonly(self.ptr) == 0 { false }else{ true } }
}
/// Get lock on media list items
pub fn lock(&self) {
unsafe{ ffi::libvlc_media_list_lock(self.ptr); }
unsafe{ sys::libvlc_media_list_lock(self.ptr); }
}
/// Release lock on media list items
/// The libvlc_media_list_lock should be held upon entering this function.
pub fn unlock(&self) {
unsafe{ ffi::libvlc_media_list_unlock(self.ptr); }
unsafe{ sys::libvlc_media_list_unlock(self.ptr); }
}
/// Get EventManager from this media list instance.
pub fn event_manager<'a>(&'a self) -> EventManager<'a> {
unsafe{
let p = ffi::libvlc_media_list_event_manager(self.ptr);
let p = sys::libvlc_media_list_event_manager(self.ptr);
assert!(!p.is_null());
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
}
@ -108,6 +108,6 @@ impl MediaList {
impl Drop for MediaList {
fn drop(&mut self) {
unsafe{ ffi::libvlc_media_list_release(self.ptr) };
unsafe{ sys::libvlc_media_list_release(self.ptr) };
}
}

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use ffi;
use sys;
use ::Instance;
use ::Media;
use ::EventManager;
@ -12,14 +12,14 @@ use std::mem::transmute;
/// A LibVLC media player plays one media (usually in a custom drawable).
pub struct MediaPlayer {
pub ptr: *mut ffi::libvlc_media_player_t,
pub ptr: *mut sys::libvlc_media_player_t,
}
impl MediaPlayer {
/// Create an empty Media Player object
pub fn new(instance: &Instance) -> Option<MediaPlayer> {
unsafe{
let p = ffi::libvlc_media_player_new(instance.ptr);
let p = sys::libvlc_media_player_new(instance.ptr);
if p.is_null() {
return None;
@ -30,12 +30,12 @@ impl MediaPlayer {
/// Set the media that will be used by the media_player. If any, previous md will be released.
pub fn set_media(&self, md: &Media) {
unsafe{ ffi::libvlc_media_player_set_media(self.ptr, md.ptr) };
unsafe{ sys::libvlc_media_player_set_media(self.ptr, md.ptr) };
}
/// Get the media used by the media_player.
pub fn get_media(&self) -> Option<Media> {
let p = unsafe{ ffi::libvlc_media_player_get_media(self.ptr) };
let p = unsafe{ sys::libvlc_media_player_get_media(self.ptr) };
if p.is_null() {
None
}else{
@ -46,7 +46,7 @@ impl MediaPlayer {
/// Get the Event Manager from which the media player send event.
pub fn event_manager<'a>(&'a self) -> EventManager<'a> {
unsafe{
let p = ffi::libvlc_media_player_event_manager(self.ptr);
let p = sys::libvlc_media_player_event_manager(self.ptr);
assert!(!p.is_null());
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
}
@ -54,7 +54,7 @@ impl MediaPlayer {
/// is_playing
pub fn is_playing(&self) -> bool {
if unsafe{ ffi::libvlc_media_player_is_playing(self.ptr) } == 0 {
if unsafe{ sys::libvlc_media_player_is_playing(self.ptr) } == 0 {
false
}else{
true
@ -63,7 +63,7 @@ impl MediaPlayer {
/// Play
pub fn play(&self) -> Result<(), ()> {
if unsafe{ ffi::libvlc_media_player_play(self.ptr) } == 0 {
if unsafe{ sys::libvlc_media_player_play(self.ptr) } == 0 {
Ok(())
}else{
Err(())
@ -72,17 +72,17 @@ impl MediaPlayer {
/// Pause or resume (no effect if there is no media)
pub fn set_pause(&self, do_pause: bool) {
unsafe{ ffi::libvlc_media_player_set_pause(self.ptr, if do_pause {1} else {0}) };
unsafe{ sys::libvlc_media_player_set_pause(self.ptr, if do_pause {1} else {0}) };
}
/// Toggle pause (no effect if there is no media)
pub fn pause(&self) {
unsafe{ ffi::libvlc_media_player_pause(self.ptr) };
unsafe{ sys::libvlc_media_player_pause(self.ptr) };
}
/// Stop (no effect if there is no media)
pub fn stop(&self) {
unsafe{ ffi::libvlc_media_player_stop(self.ptr) };
unsafe{ sys::libvlc_media_player_stop(self.ptr) };
}
pub fn set_callbacks<F>(
@ -106,7 +106,7 @@ impl MediaPlayer {
let data = Box::into_raw(Box::new(data));
unsafe{
ffi::libvlc_audio_set_callbacks(
sys::libvlc_audio_set_callbacks(
self.ptr,
Some(audio_cb_play),
if flag_pause {Some(audio_cb_pause)} else {None},
@ -119,42 +119,42 @@ impl MediaPlayer {
/// Set the NSView handler where the media player should render its video output.
pub fn set_nsobject(&self, drawable: *mut c_void) {
unsafe{ ffi::libvlc_media_player_set_nsobject(self.ptr, drawable) };
unsafe{ sys::libvlc_media_player_set_nsobject(self.ptr, drawable) };
}
/// Get the NSView handler previously set with set_nsobject().
pub fn get_nsobject(&self) -> Option<*mut c_void> {
let nso = unsafe{ ffi::libvlc_media_player_get_nsobject(self.ptr) };
let nso = unsafe{ sys::libvlc_media_player_get_nsobject(self.ptr) };
if nso.is_null() { None }else{ Some(nso) }
}
/// Set an X Window System drawable where the media player should render its video output.
pub fn set_xwindow(&self, drawable: u32) {
unsafe{ ffi::libvlc_media_player_set_xwindow(self.ptr, drawable) };
unsafe{ sys::libvlc_media_player_set_xwindow(self.ptr, drawable) };
}
/// Get the X Window System window identifier previously set with set_xwindow().
pub fn get_xwindow(&self) -> Option<u32> {
let id = unsafe{ ffi::libvlc_media_player_get_xwindow(self.ptr) };
let id = unsafe{ sys::libvlc_media_player_get_xwindow(self.ptr) };
if id == 0 { None }else{ Some(id) }
}
/// Set a Win32/Win64 API window handle (HWND) where the media player should render its video output.
/// If LibVLC was built without Win32/Win64 API output support, then this has no effects.
pub fn set_hwnd(&self, drawable: *mut c_void) {
unsafe{ ffi::libvlc_media_player_set_hwnd(self.ptr, drawable) };
unsafe{ sys::libvlc_media_player_set_hwnd(self.ptr, drawable) };
}
/// Get the Windows API window handle (HWND) previously set with set_hwnd().
pub fn get_hwnd(&self) -> Option<*mut c_void> {
let hwnd = unsafe{ ffi::libvlc_media_player_get_hwnd(self.ptr) };
let hwnd = unsafe{ sys::libvlc_media_player_get_hwnd(self.ptr) };
if hwnd.is_null() { None }else{ Some(hwnd) }
}
/// Get the current movie time (in ms).
pub fn get_time(&self) -> Option<i64> {
unsafe{
let t = ffi::libvlc_media_player_get_time(self.ptr);
let t = sys::libvlc_media_player_get_time(self.ptr);
if t == -1 { None }else{ Some(t) }
}
}
@ -162,13 +162,13 @@ impl MediaPlayer {
/// Set the movie time (in ms).
/// This has no effect if no media is being played. Not all formats and protocols support this.
pub fn set_time(&self, time: i64) {
unsafe{ ffi::libvlc_media_player_set_time(self.ptr, time); }
unsafe{ sys::libvlc_media_player_set_time(self.ptr, time); }
}
/// Get movie position as percentage between 0.0 and 1.0.
pub fn get_position(&self) -> Option<f32> {
unsafe{
let pos = ffi::libvlc_media_player_get_position(self.ptr);
let pos = sys::libvlc_media_player_get_position(self.ptr);
if pos == -1f32 { None }else{ Some(pos) }
}
}
@ -176,18 +176,18 @@ impl MediaPlayer {
/// Set movie position as percentage between 0.0 and 1.0.
/// This has no effect if playback is not enabled. This might not work depending on the underlying input format and protocol.
pub fn set_position(&self, pos: f32) {
unsafe{ ffi::libvlc_media_player_set_position(self.ptr, pos); }
unsafe{ sys::libvlc_media_player_set_position(self.ptr, pos); }
}
/// Set movie chapter (if applicable).
pub fn set_chapter(&self, chapter: i32) {
unsafe{ ffi::libvlc_media_player_set_chapter(self.ptr, chapter); }
unsafe{ sys::libvlc_media_player_set_chapter(self.ptr, chapter); }
}
/// Get movie chapter.
pub fn get_chapter(&self) -> Option<i32> {
unsafe{
let c = ffi::libvlc_media_player_get_chapter(self.ptr);
let c = sys::libvlc_media_player_get_chapter(self.ptr);
if c == -1 { None }else{ Some(c) }
}
}
@ -195,7 +195,7 @@ impl MediaPlayer {
/// Get movie chapter count.
pub fn chapter_count(&self) -> Option<i32> {
unsafe{
let c = ffi::libvlc_media_player_get_chapter_count(self.ptr);
let c = sys::libvlc_media_player_get_chapter_count(self.ptr);
if c == -1 { None }else{ Some(c) }
}
}
@ -203,7 +203,7 @@ impl MediaPlayer {
/// Is the player able to play.
pub fn will_play(&self) -> bool {
unsafe{
let b = ffi::libvlc_media_player_will_play(self.ptr);
let b = sys::libvlc_media_player_will_play(self.ptr);
if b == 0 { false }else{ true }
}
}
@ -211,20 +211,20 @@ impl MediaPlayer {
/// Get title chapter count.
pub fn chapter_count_for_title(&self, title: i32) -> Option<i32> {
unsafe{
let c = ffi::libvlc_media_player_get_chapter_count_for_title(self.ptr, title);
let c = sys::libvlc_media_player_get_chapter_count_for_title(self.ptr, title);
if c == -1 { None }else{ Some(c) }
}
}
/// Set movie title.
pub fn set_title(&self, title: i32) {
unsafe{ ffi::libvlc_media_player_set_title(self.ptr, title); }
unsafe{ sys::libvlc_media_player_set_title(self.ptr, title); }
}
/// Get movie title.
pub fn get_title(&self) -> Option<i32> {
unsafe{
let t = ffi::libvlc_media_player_get_title(self.ptr);
let t = sys::libvlc_media_player_get_title(self.ptr);
if t == -1 { None }else{ Some(t) }
}
}
@ -232,30 +232,30 @@ impl MediaPlayer {
/// Get movie title count.
pub fn title_count(&self) -> Option<i32> {
unsafe{
let t = ffi::libvlc_media_player_get_title_count(self.ptr);
let t = sys::libvlc_media_player_get_title_count(self.ptr);
if t == -1 { Some(t) } else { None }
}
}
/// Set previous chapter (if applicable)
pub fn previous_chapter(&self) {
unsafe{ ffi::libvlc_media_player_previous_chapter(self.ptr); }
unsafe{ sys::libvlc_media_player_previous_chapter(self.ptr); }
}
/// Set next chapter (if applicable)
pub fn next_chapter(&self) {
unsafe{ ffi::libvlc_media_player_next_chapter(self.ptr); }
unsafe{ sys::libvlc_media_player_next_chapter(self.ptr); }
}
/// Get the requested movie play rate.
pub fn get_rate(&self) -> f32 {
unsafe{ ffi::libvlc_media_player_get_rate(self.ptr) }
unsafe{ sys::libvlc_media_player_get_rate(self.ptr) }
}
/// Set movie play rate.
pub fn set_rate(&self, rate: f32) -> Result<(),()> {
unsafe{
if ffi::libvlc_media_player_set_rate(self.ptr, rate) == -1 {
if sys::libvlc_media_player_set_rate(self.ptr, rate) == -1 {
Err(())
}else{
Ok(())
@ -265,18 +265,18 @@ impl MediaPlayer {
/// Get current movie state.
pub fn state(&self) -> State {
unsafe{ ffi::libvlc_media_player_get_state(self.ptr) }
unsafe{ sys::libvlc_media_player_get_state(self.ptr) }
}
/// How many video outputs does this media player have?
pub fn has_vout(&self) -> u32 {
unsafe{ ffi::libvlc_media_player_has_vout(self.ptr) }
unsafe{ sys::libvlc_media_player_has_vout(self.ptr) }
}
/// Is this media player seekable?
pub fn is_seekable(&self) -> bool {
unsafe{
let b = ffi::libvlc_media_player_is_seekable(self.ptr);
let b = sys::libvlc_media_player_is_seekable(self.ptr);
if b == 0 { false }else{ true }
}
}
@ -284,7 +284,7 @@ impl MediaPlayer {
/// Can this media player be paused?
pub fn can_pause(&self) -> bool {
unsafe{
let b = ffi::libvlc_media_player_can_pause(self.ptr);
let b = sys::libvlc_media_player_can_pause(self.ptr);
if b == 0 { false }else{ true }
}
}
@ -292,30 +292,30 @@ impl MediaPlayer {
/// Check if the current program is scrambled.
pub fn program_scrambled(&self) -> bool {
unsafe{
let b = ffi::libvlc_media_player_program_scrambled(self.ptr);
let b = sys::libvlc_media_player_program_scrambled(self.ptr);
if b == 0 { false }else{ true }
}
}
/// Display the next frame (if supported)
pub fn next_frame(&self) {
unsafe{ ffi::libvlc_media_player_next_frame(self.ptr); }
unsafe{ sys::libvlc_media_player_next_frame(self.ptr); }
}
/// Navigate through DVD Menu.
pub fn navigate(&self, navigate: u32) {
unsafe{ ffi::libvlc_media_player_navigate(self.ptr, navigate); }
unsafe{ sys::libvlc_media_player_navigate(self.ptr, navigate); }
}
/// Set if, and how, the video title will be shown when media is played.
pub fn set_video_title_display(&self, position: Position, timeout: u32) {
unsafe{ ffi::libvlc_media_player_set_video_title_display(self.ptr, position, timeout); }
unsafe{ sys::libvlc_media_player_set_video_title_display(self.ptr, position, timeout); }
}
}
impl Drop for MediaPlayer {
fn drop(&mut self) {
unsafe{ ffi::libvlc_media_player_release(self.ptr) };
unsafe{ sys::libvlc_media_player_release(self.ptr) };
}
}

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use ffi;
use sys;
use ::MediaPlayer;
use ::TrackDescription;
use ::enums::VideoAdjustOption;
@ -32,25 +32,25 @@ pub trait MediaPlayerVideoEx {
impl MediaPlayerVideoEx for MediaPlayer {
fn toggle_fullscreen(&self) {
unsafe{ ffi::libvlc_toggle_fullscreen(self.ptr); }
unsafe{ sys::libvlc_toggle_fullscreen(self.ptr); }
}
fn set_fullscreen(&self, fullscreen: bool) {
unsafe{ ffi::libvlc_set_fullscreen(self.ptr, if fullscreen { 1 }else{ 0 }); }
unsafe{ sys::libvlc_set_fullscreen(self.ptr, if fullscreen { 1 }else{ 0 }); }
}
fn get_fullscreen(&self) -> bool {
unsafe{ if ffi::libvlc_get_fullscreen(self.ptr) == 0 { false }else{ true } }
unsafe{ if sys::libvlc_get_fullscreen(self.ptr) == 0 { false }else{ true } }
}
fn set_key_input(&self, on: bool) {
unsafe{ ffi::libvlc_video_set_key_input(self.ptr, if on { 1 }else{ 0 }); }
unsafe{ sys::libvlc_video_set_key_input(self.ptr, if on { 1 }else{ 0 }); }
}
fn set_mouse_input(&self, on: bool) {
unsafe{ ffi::libvlc_video_set_mouse_input(self.ptr, if on { 1 }else{ 0 }); }
unsafe{ sys::libvlc_video_set_mouse_input(self.ptr, if on { 1 }else{ 0 }); }
}
fn get_size(&self, num: u32) -> Option<(u32, u32)> {
unsafe{
let mut x = 0;
let mut y = 0;
let res = ffi::libvlc_video_get_size(self.ptr, num, &mut x, &mut y);
let res = sys::libvlc_video_get_size(self.ptr, num, &mut x, &mut y);
if res == -1 { None }else{ Some((x, y)) }
}
}
@ -58,45 +58,45 @@ impl MediaPlayerVideoEx for MediaPlayer {
unsafe{
let mut x = 0;
let mut y = 0;
let res = ffi::libvlc_video_get_cursor(self.ptr, num, &mut x, &mut y);
let res = sys::libvlc_video_get_cursor(self.ptr, num, &mut x, &mut y);
if res == -1 { None }else{ Some((x, y)) }
}
}
fn get_scale(&self) -> f32 {
unsafe{ ffi::libvlc_video_get_scale(self.ptr) }
unsafe{ sys::libvlc_video_get_scale(self.ptr) }
}
fn set_scale(&self, factor: f32) {
unsafe{ ffi::libvlc_video_set_scale(self.ptr, factor); }
unsafe{ sys::libvlc_video_set_scale(self.ptr, factor); }
}
fn get_video_track(&self) -> Option<i32> {
unsafe{
let track = ffi::libvlc_video_get_track(self.ptr);
let track = sys::libvlc_video_get_track(self.ptr);
if track == -1 { None }else{ Some(track) }
}
}
fn set_video_track(&self, track: i32) {
unsafe{ ffi::libvlc_video_set_track(self.ptr, track); }
unsafe{ sys::libvlc_video_set_track(self.ptr, track); }
}
fn get_aspect_ratio(&self) -> Option<String> {
unsafe{
let p = ffi::libvlc_video_get_aspect_ratio(self.ptr);
let p = sys::libvlc_video_get_aspect_ratio(self.ptr);
let s = from_cstr(p);
if !p.is_null() { ffi::libvlc_free(p as *mut c_void); }
if !p.is_null() { sys::libvlc_free(p as *mut c_void); }
s
}
}
fn set_aspect_ratio(&self, aspect: Option<&str>) {
unsafe{
if let Some(a) = aspect {
ffi::libvlc_video_set_aspect_ratio(self.ptr, to_cstr(a).as_ptr());
sys::libvlc_video_set_aspect_ratio(self.ptr, to_cstr(a).as_ptr());
}else{
ffi::libvlc_video_set_aspect_ratio(self.ptr, ::std::ptr::null());
sys::libvlc_video_set_aspect_ratio(self.ptr, ::std::ptr::null());
}
}
}
fn get_video_track_description(&self) -> Option<Vec<TrackDescription>> {
unsafe{
let p0 = ffi::libvlc_video_get_track_description(self.ptr);
let p0 = sys::libvlc_video_get_track_description(self.ptr);
if p0.is_null() { return None; }
let mut td = Vec::new();
let mut p = p0;
@ -105,20 +105,20 @@ impl MediaPlayerVideoEx for MediaPlayer {
td.push(TrackDescription{ id: (*p).i_id, name: from_cstr((*p).psz_name) });
p = (*p).p_next;
}
ffi::libvlc_track_description_list_release(p0);
sys::libvlc_track_description_list_release(p0);
Some(td)
}
}
fn get_adjust_int(&self, option: VideoAdjustOption) -> i32 {
unsafe{ ffi::libvlc_video_get_adjust_int(self.ptr, option as u32) }
unsafe{ sys::libvlc_video_get_adjust_int(self.ptr, option as u32) }
}
fn set_adjust_int(&self, option: VideoAdjustOption, value: i32) {
unsafe{ ffi::libvlc_video_set_adjust_int(self.ptr, option as u32, value); }
unsafe{ sys::libvlc_video_set_adjust_int(self.ptr, option as u32, value); }
}
fn get_adjust_float(&self, option: VideoAdjustOption) -> f32 {
unsafe{ ffi::libvlc_video_get_adjust_float(self.ptr, option as u32) }
unsafe{ sys::libvlc_video_get_adjust_float(self.ptr, option as u32) }
}
fn set_adjust_float(&self, option: VideoAdjustOption, value: f32) {
unsafe{ ffi::libvlc_video_set_adjust_float(self.ptr, option as u32, value); }
unsafe{ sys::libvlc_video_set_adjust_float(self.ptr, option as u32, value); }
}
}