Merge branch 'master' into vlm-broadcast

merge-requests/7/merge
Raniz 2019-11-25 11:40:28 +01:00
commit ab7c27e8cb
11 changed files with 86 additions and 85 deletions

View File

@ -8,6 +8,7 @@ keywords = ["libVLC", "bindings"]
repository = "https://github.com/garkimasera/vlc-rs"
license = "MIT"
readme = "README.md"
edition = "2018"
[lib]
name = "vlc"

View File

@ -2,14 +2,14 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use sys;
use ::MediaPlayer;
use ::TrackDescription;
use ::tools::from_cstr;
use crate::sys;
use crate::MediaPlayer;
use crate::TrackDescription;
use crate::tools::from_cstr;
pub trait MediaPlayerAudioEx {
fn get_mute(&self) -> Option<bool>;
fn set_mute(&self, bool);
fn set_mute(&self, muted: bool);
fn get_volume(&self) -> i32;
fn set_volume(&self, volume: i32) -> Result<(), ()>;
fn get_audio_track_description(&self) -> Option<Vec<TrackDescription>>;

View File

@ -7,12 +7,12 @@ use std::borrow::Cow;
use std::marker::PhantomData;
use std::ffi::{CString, CStr};
use std::i32;
use sys;
use ::tools::{to_cstr, from_cstr, from_cstr_ref};
use ::libc::{c_void, c_char, c_int};
use ::enums::*;
use libc::{c_void, c_char, c_int};
use crate::sys;
use crate::tools::{to_cstr, from_cstr, from_cstr_ref};
use crate::enums::*;
/// Retrieve libvlc version.
/// Retrieve libvlc version.
pub fn version() -> String {
unsafe{
from_cstr_ref(sys::libvlc_get_version()).unwrap().into_owned()
@ -47,7 +47,7 @@ impl Instance {
} else {
args_c_ptr = Vec::new();
}
unsafe{
let p = if args_c_ptr.is_empty() {
@ -59,12 +59,12 @@ impl Instance {
if p.is_null() {
return None;
}
Some(Instance{ptr: p})
}
}
/// Create and initialize a libvlc instance.
/// Create and initialize a libvlc instance.
pub fn new() -> Option<Instance> {
Instance::with_args(None)
}
@ -132,8 +132,8 @@ impl Instance {
/// Set logging callback
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<dyn Fn(LogLevel, Log, Cow<str>) + Send + 'static>> = Box::new(Box::new(f));
unsafe{
sys::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _);
}
@ -160,7 +160,7 @@ 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 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 f: &Box<dyn Fn(LogLevel, Log, Cow<str>) + Send + 'static> = ::std::mem::transmute(data);
let mut buf: [c_char; BUF_SIZE] = [0; BUF_SIZE];
vsnprintf(buf.as_mut_ptr(), BUF_SIZE, fmt, args);
@ -210,7 +210,7 @@ pub struct ModuleDescription {
pub help: Option<String>,
}
/// Description of a module.
/// Description of a module.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct ModuleDescriptionRef<'a> {
pub name: Option<Cow<'a, str>>,
@ -268,7 +268,7 @@ pub enum Event {
MediaFreed,
MediaStateChanged(State),
MediaSubItemTreeAdded,
MediaPlayerMediaChanged,
MediaPlayerNothingSpecial,
MediaPlayerOpening,
@ -330,9 +330,9 @@ impl<'a> EventManager<'a> {
where F: Fn(Event, VLCObject) + Send + 'static
{
// Explicit type annotation is needed
let callback: Box<Box<Fn(Event, VLCObject) + Send + 'static>> =
let callback: Box<Box<dyn Fn(Event, VLCObject) + Send + 'static>> =
Box::new(Box::new(callback));
let result = unsafe{
sys::libvlc_event_attach(
self.ptr, event_type as i32, event_manager_callback,
@ -353,7 +353,7 @@ impl<'a> EventManager<'a> {
}
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);
let f: &Box<dyn Fn(Event, VLCObject) + Send + 'static> = ::std::mem::transmute(data);
f(conv_event(pe), VLCObject{ ptr: (*pe).p_obj });
}
@ -361,7 +361,7 @@ unsafe extern "C" fn event_manager_callback(pe: *const sys::libvlc_event_t, data
// Convert c-style libvlc_event_t to 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{

View File

@ -17,12 +17,12 @@ mod video;
mod audio;
mod vlm;
pub use enums::*;
pub use core::*;
pub use media::*;
pub use media_player::*;
pub use media_list::*;
pub use media_library::*;
pub use video::*;
pub use audio::*;
pub use vlm::*;
pub use crate::enums::*;
pub use crate::core::*;
pub use crate::media::*;
pub use crate::media_player::*;
pub use crate::media_list::*;
pub use crate::media_library::*;
pub use crate::video::*;
pub use crate::audio::*;
pub use crate::vlm::*;

View File

@ -2,10 +2,10 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use sys;
use ::{Instance, EventManager};
use ::enums::{State, Meta, TrackType};
use ::tools::{to_cstr, from_cstr, path_to_cstr};
use crate::sys;
use crate::{Instance, EventManager};
use crate::enums::{State, Meta, TrackType};
use crate::tools::{to_cstr, from_cstr, path_to_cstr};
use std::path::Path;
pub struct Media {
@ -15,44 +15,44 @@ pub struct Media {
unsafe impl Send for Media {}
impl Media {
/// Create a media with a certain given media resource location, for instance a valid URL.
/// Create a media with a certain given media resource location, for instance a valid URL.
pub fn new_location(instance: &Instance, mrl: &str) -> Option<Media> {
let cstr = to_cstr(mrl);
unsafe{
let p = sys::libvlc_media_new_location(instance.ptr, cstr.as_ptr());
if p.is_null() {
return None;
}
Some(Media{ptr: p})
}
}
/// Create a media for a certain file path.
/// Create a media for a certain file path.
pub fn new_path<T: AsRef<Path>>(instance: &Instance, path: T) -> Option<Media> {
let cstr = match path_to_cstr(path.as_ref()) {
Ok(s) => s,
Err(_) => { return None; },
};
unsafe{
let p = sys::libvlc_media_new_path(instance.ptr, cstr.as_ptr());
if p.is_null() {
return None;
}
Some(Media{ptr: p})
}
}
pub fn new_fd(instance: &Instance, fd: i32) -> Option<Media> {
unsafe{
let p = sys::libvlc_media_new_fd(instance.ptr, fd);
if p.is_null() {
return None;
}
Some(Media{ptr: p})
}
}
@ -86,7 +86,7 @@ impl Media {
}
/// Set the meta of the media.
/// (This function will not save the meta, call save_meta in order to save the meta)
/// (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{
sys::libvlc_media_set_meta(self.ptr, meta, to_cstr(value).as_ptr());
@ -111,7 +111,7 @@ impl Media {
if time != -1 { Some(time) }else{ None }
}
/// Parse a media.
/// Parse a media.
pub fn parse(&self) {
unsafe{ sys::libvlc_media_parse(self.ptr) };
}
@ -235,4 +235,4 @@ pub struct VideoTrack {
pub struct SubtitleTrack {
pub encoding: Option<String>,
}

View File

@ -2,8 +2,8 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use sys;
use ::{Instance, MediaList};
use crate::sys;
use crate::{Instance, MediaList};
pub struct MediaLibrary {
pub(crate) ptr: *mut sys::libvlc_media_library_t,

View File

@ -2,8 +2,8 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use sys;
use ::{Instance, Media, EventManager};
use crate::sys;
use crate::{Instance, Media, EventManager};
pub struct MediaList {
pub(crate) ptr: *mut sys::libvlc_media_list_t,

View File

@ -2,12 +2,12 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use sys;
use ::Instance;
use ::Media;
use ::EventManager;
use ::libc::{c_void, c_uint};
use ::enums::{State, Position};
use crate::sys;
use crate::Instance;
use crate::Media;
use crate::EventManager;
use libc::{c_void, c_uint};
use crate::enums::{State, Position};
use std::mem::transmute;
/// A LibVLC media player plays one media (usually in a custom drawable).
@ -90,17 +90,17 @@ impl MediaPlayer {
pub fn set_callbacks<F>(
&self,
play: F,
pause: Option<Box<Fn(i64) + Send + 'static>>,
resume: Option<Box<Fn(i64) + Send + 'static>>,
flush: Option<Box<Fn(i64) + Send + 'static>>,
drain: Option<Box<Fn() + Send + 'static>>)
pause: Option<Box<dyn Fn(i64) + Send + 'static>>,
resume: Option<Box<dyn Fn(i64) + Send + 'static>>,
flush: Option<Box<dyn Fn(i64) + Send + 'static>>,
drain: Option<Box<dyn Fn() + Send + 'static>>)
where F: Fn(*const c_void, u32, i64) + Send + 'static,
{
let flag_pause = pause.is_some();
let flag_resume = resume.is_some();
let flag_flush = flush.is_some();
let flag_drain = drain.is_some();
let data = AudioCallbacksData {
play: Box::new(play), pause: pause, resume: resume,
flush: flush, drain: drain,
@ -119,12 +119,12 @@ impl MediaPlayer {
}
}
/// Set the NSView handler where the media player should render its video output.
/// Set the NSView handler where the media player should render its video output.
pub fn set_nsobject(&self, drawable: *mut c_void) {
unsafe{ sys::libvlc_media_player_set_nsobject(self.ptr, drawable) };
}
/// Get the NSView handler previously set with set_nsobject().
/// Get the NSView handler previously set with set_nsobject().
pub fn get_nsobject(&self) -> Option<*mut c_void> {
let nso = unsafe{ sys::libvlc_media_player_get_nsobject(self.ptr) };
if nso.is_null() { None }else{ Some(nso) }
@ -135,7 +135,7 @@ impl MediaPlayer {
unsafe{ sys::libvlc_media_player_set_xwindow(self.ptr, drawable) };
}
/// Get the X Window System window identifier previously set with set_xwindow().
/// Get the X Window System window identifier previously set with set_xwindow().
pub fn get_xwindow(&self) -> Option<u32> {
let id = unsafe{ sys::libvlc_media_player_get_xwindow(self.ptr) };
if id == 0 { None }else{ Some(id) }
@ -328,18 +328,18 @@ impl Drop for MediaPlayer {
// For audio_set_callbacks
struct AudioCallbacksData {
play: Box<Fn(*const c_void, u32, i64) + Send + 'static>,
pause: Option<Box<Fn(i64) + Send + 'static>>,
resume: Option<Box<Fn(i64) + Send + 'static>>,
flush: Option<Box<Fn(i64) + Send + 'static>>,
drain: Option<Box<Fn() + Send + 'static>>,
play: Box<dyn Fn(*const c_void, u32, i64) + Send + 'static>,
pause: Option<Box<dyn Fn(i64) + Send + 'static>>,
resume: Option<Box<dyn Fn(i64) + Send + 'static>>,
flush: Option<Box<dyn Fn(i64) + Send + 'static>>,
drain: Option<Box<dyn Fn() + Send + 'static>>,
}
unsafe extern "C" fn audio_cb_play(
data: *mut c_void, samples: *const c_void, count: c_uint, pts: i64) {
let data: &AudioCallbacksData = transmute(data as *mut AudioCallbacksData);
(data.play)(samples, count, pts);
}
unsafe extern "C" fn audio_cb_pause(data: *mut c_void, pts: i64) {

View File

@ -38,7 +38,7 @@ pub type libvlc_callback_t = unsafe extern "C" fn(*const libvlc_event_t, *mut c_
pub type va_list = *mut c_void;
pub type libvlc_log_cb = unsafe extern "C" fn(*mut c_void, c_int, *const libvlc_log_t, *const c_char, va_list);
pub use LogLevel as libvlc_log_level;
pub use crate::enums::LogLevel as libvlc_log_level;
#[repr(C)]
#[derive(Clone, Copy)]
@ -99,13 +99,13 @@ pub unsafe fn libvlc_delay(pts: i64) -> i64 {
// From libvlc_media.h
pub enum libvlc_media_t {}
pub use Meta as libvlc_meta_t;
pub use State as libvlc_state_t;
pub use crate::enums::Meta as libvlc_meta_t;
pub use crate::enums::State as libvlc_state_t;
pub const libvlc_media_option_trusted: u32 = 0x2;
pub const libvlc_media_option_unique: u32 = 0x100;
pub use TrackType as libvlc_track_type_t;
pub use crate::enums::TrackType as libvlc_track_type_t;
#[repr(C)]
#[derive(Clone, Copy)]
@ -335,8 +335,8 @@ pub enum libvlc_navigate_mode_t {
libvlc_navigate_right,
}
pub use Position as libvlc_position_t;
pub use VideoAdjustOption as libvlc_video_adjust_option;
pub use crate::enums::Position as libvlc_position_t;
pub use crate::enums::VideoAdjustOption as libvlc_video_adjust_option;
#[repr(C)]
#[derive(Clone, Copy, Debug)]
@ -575,7 +575,7 @@ extern "C" {
}
// From libvlc_events.h
pub use EventType as libvlc_event_e;
pub use crate::enums::EventType as libvlc_event_e;
#[repr(C)]
#[derive(Clone, Copy)]

View File

@ -37,7 +37,7 @@ pub unsafe fn from_cstr_ref<'a>(p: *const c_char) -> Option<Cow<'a, str>> {
// Create CString from &Path
pub fn path_to_cstr(path: &Path) -> Result<CString, NulError> {
let path = try!(CString::new(path.to_string_lossy().into_owned()));
let path = CString::new(path.to_string_lossy().into_owned())?;
Ok(path)
}

View File

@ -2,12 +2,12 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use sys;
use ::MediaPlayer;
use ::TrackDescription;
use ::enums::VideoAdjustOption;
use ::tools::{to_cstr, from_cstr};
use ::libc::c_void;
use crate::sys;
use crate::MediaPlayer;
use crate::TrackDescription;
use crate::enums::VideoAdjustOption;
use crate::tools::{to_cstr, from_cstr};
use libc::c_void;
pub trait MediaPlayerVideoEx {
fn toggle_fullscreen(&self);