From 6c4bbf3aa33f28d9d4a851a86661db23c8b5d8ff Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:24:36 +0100 Subject: [PATCH 01/17] lib: fix crate path --- src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6825be0..0772446 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,11 +16,11 @@ mod enums; mod video; mod audio; -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 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::*; From 5b242e55a3455489857f73543e3604007cca8835 Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:30:46 +0100 Subject: [PATCH 02/17] sys: use absolute crate path for pub use --- src/sys.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sys.rs b/src/sys.rs index 9d9e632..7221369 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -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)] From bde5163367c8631226ac9eeb41cde985cc4ad24f Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:17:32 +0100 Subject: [PATCH 03/17] tools: use ? instead of try --- src/tools.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools.rs b/src/tools.rs index 71ac32c..c44598a 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -37,7 +37,7 @@ pub unsafe fn from_cstr_ref<'a>(p: *const c_char) -> Option> { // Create CString from &Path pub fn path_to_cstr(path: &Path) -> Result { - let path = try!(CString::new(path.to_string_lossy().into_owned())); - + let path = CString::new(path.to_string_lossy().into_owned())?; + Ok(path) } From b18049f9782c42b58c33dc443a12a9fc16e5ea1a Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:20:53 +0100 Subject: [PATCH 04/17] audio: fix obsolete unnamed parameter --- src/audio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio.rs b/src/audio.rs index 5609858..7aadba6 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -9,7 +9,7 @@ use ::tools::from_cstr; pub trait MediaPlayerAudioEx { fn get_mute(&self) -> Option; - 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>; From 4fc958841d79a37ed95f758cd7861cbddedc253b Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 18:42:10 +0100 Subject: [PATCH 05/17] core: fix missing dyn --- src/core.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core.rs b/src/core.rs index 955dc3d..b7f9b6a 100644 --- a/src/core.rs +++ b/src/core.rs @@ -121,7 +121,7 @@ impl Instance { /// Set logging callback pub fn set_log) + Send + 'static>(&self, f: F) { - let cb: Box) + Send + 'static>> = Box::new(Box::new(f)); + let cb: Box) + Send + 'static>> = Box::new(Box::new(f)); unsafe{ sys::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _); @@ -149,7 +149,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) + Send + 'static> = ::std::mem::transmute(data); + let f: &Box) + 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); @@ -319,7 +319,7 @@ impl<'a> EventManager<'a> { where F: Fn(Event, VLCObject) + Send + 'static { // Explicit type annotation is needed - let callback: Box> = + let callback: Box> = Box::new(Box::new(callback)); let result = unsafe{ @@ -342,7 +342,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 = ::std::mem::transmute(data); + let f: &Box = ::std::mem::transmute(data); f(conv_event(pe), VLCObject{ ptr: (*pe).p_obj }); } From 092377878cced8cac62476f3323e864afae440c7 Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 18:42:27 +0100 Subject: [PATCH 06/17] media_player: fix missing dyn --- src/media_player.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/media_player.rs b/src/media_player.rs index 15aebf0..46b9d82 100644 --- a/src/media_player.rs +++ b/src/media_player.rs @@ -88,10 +88,10 @@ impl MediaPlayer { pub fn set_callbacks( &self, play: F, - pause: Option>, - resume: Option>, - flush: Option>, - drain: Option>) + pause: Option>, + resume: Option>, + flush: Option>, + drain: Option>) where F: Fn(*const c_void, u32, i64) + Send + 'static, { let flag_pause = pause.is_some(); @@ -326,11 +326,11 @@ impl Drop for MediaPlayer { // For audio_set_callbacks struct AudioCallbacksData { - play: Box, - pause: Option>, - resume: Option>, - flush: Option>, - drain: Option>, + play: Box, + pause: Option>, + resume: Option>, + flush: Option>, + drain: Option>, } unsafe extern "C" fn audio_cb_play( From 3dd635a5e8745a896c8834c5bcf5b2ce708c9e2c Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:21:14 +0100 Subject: [PATCH 07/17] core: fix crate path --- src/core.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core.rs b/src/core.rs index b7f9b6a..464bd3c 100644 --- a/src/core.rs +++ b/src/core.rs @@ -7,10 +7,10 @@ use std::borrow::Cow; use std::marker::PhantomData; use std::ffi::CString; 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. pub fn version() -> String { From 8ccb60ef9ac0a1d70f8ee24798e0d6a676e6fbbe Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:21:26 +0100 Subject: [PATCH 08/17] core: fix whitespaces --- src/core.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core.rs b/src/core.rs index 464bd3c..003ad11 100644 --- a/src/core.rs +++ b/src/core.rs @@ -12,7 +12,7 @@ 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() @@ -45,7 +45,7 @@ impl Instance { } else { args_c_ptr = Vec::new(); } - + unsafe{ let p = if args_c_ptr.is_empty() { @@ -57,12 +57,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::with_args(None) } @@ -122,7 +122,7 @@ impl Instance { /// Set logging callback pub fn set_log) + Send + 'static>(&self, f: F) { let cb: Box) + Send + 'static>> = Box::new(Box::new(f)); - + unsafe{ sys::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _); } @@ -199,7 +199,7 @@ pub struct ModuleDescription { pub help: Option, } -/// Description of a module. +/// Description of a module. #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub struct ModuleDescriptionRef<'a> { pub name: Option>, @@ -257,7 +257,7 @@ pub enum Event { MediaFreed, MediaStateChanged(State), MediaSubItemTreeAdded, - + MediaPlayerMediaChanged, MediaPlayerNothingSpecial, MediaPlayerOpening, @@ -321,7 +321,7 @@ impl<'a> EventManager<'a> { // Explicit type annotation is needed let callback: Box> = Box::new(Box::new(callback)); - + let result = unsafe{ sys::libvlc_event_attach( self.ptr, event_type as i32, event_manager_callback, @@ -350,7 +350,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{ From b4346a257380a004e11c805c66bd9f6b4b9e4e4b Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:21:45 +0100 Subject: [PATCH 09/17] media: fix crate path --- src/media.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/media.rs b/src/media.rs index 60e4656..fff8b66 100644 --- a/src/media.rs +++ b/src/media.rs @@ -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 { From a1d51ebb7ae4a0d35c6505c526f9361d92d02a08 Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:21:55 +0100 Subject: [PATCH 10/17] media: fix whitespace --- src/media.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/media.rs b/src/media.rs index fff8b66..4c4a44f 100644 --- a/src/media.rs +++ b/src/media.rs @@ -13,44 +13,44 @@ pub struct 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 { 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>(instance: &Instance, path: T) -> Option { 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 { unsafe{ let p = sys::libvlc_media_new_fd(instance.ptr, fd); if p.is_null() { return None; } - + Some(Media{ptr: p}) } } @@ -84,7 +84,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()); @@ -109,7 +109,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) }; } @@ -233,4 +233,4 @@ pub struct VideoTrack { pub struct SubtitleTrack { pub encoding: Option, } - + From 23a16997afca8cc4c94d5033f5a332878bd4431e Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:24:52 +0100 Subject: [PATCH 11/17] media_player: fix crate path --- src/media_player.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/media_player.rs b/src/media_player.rs index 46b9d82..2bf243b 100644 --- a/src/media_player.rs +++ b/src/media_player.rs @@ -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). From 56fc69eb3eba19ffbfebb7946d9f9966c5a25efe Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:25:05 +0100 Subject: [PATCH 12/17] media_player: fix whitespace --- src/media_player.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/media_player.rs b/src/media_player.rs index 2bf243b..8bbcc6f 100644 --- a/src/media_player.rs +++ b/src/media_player.rs @@ -98,7 +98,7 @@ impl MediaPlayer { 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, @@ -117,12 +117,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) } @@ -133,7 +133,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 { let id = unsafe{ sys::libvlc_media_player_get_xwindow(self.ptr) }; if id == 0 { None }else{ Some(id) } @@ -337,7 +337,7 @@ 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) { From 7b60a129110ff34864ffabe1466b21dbf4e94bd4 Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:20:24 +0100 Subject: [PATCH 13/17] audio: fix crate path --- src/audio.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/audio.rs b/src/audio.rs index 7aadba6..697e1c6 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -2,10 +2,10 @@ // 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; From 3061aaa97727e39464de924274a437a04e44971c Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:31:53 +0100 Subject: [PATCH 14/17] video: fix crate path --- src/video.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/video.rs b/src/video.rs index ea25162..a71bd82 100644 --- a/src/video.rs +++ b/src/video.rs @@ -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); From 2f066ce170223c532a406ad528497cc641e2a51c Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:22:30 +0100 Subject: [PATCH 15/17] media_library: fix crate path --- src/media_library.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/media_library.rs b/src/media_library.rs index e79da20..e8e5551 100644 --- a/src/media_library.rs +++ b/src/media_library.rs @@ -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, From 7e09da35b622a4a98ac0de1acc9743098569f2ad Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:22:51 +0100 Subject: [PATCH 16/17] media_list: fix crate path --- src/media_list.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/media_list.rs b/src/media_list.rs index 2b84125..c6e2f5b 100644 --- a/src/media_list.rs +++ b/src/media_list.rs @@ -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, From f771e6210c63eecaeb3eed394b4bd31ec6fa4e15 Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Fri, 15 Nov 2019 13:19:55 +0100 Subject: [PATCH 17/17] cargo: update edition to 2018 --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index ce6f291..faf9be5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ keywords = ["libVLC", "bindings"] repository = "https://github.com/garkimasera/vlc-rs" license = "MIT" readme = "README.md" +edition = "2018" [lib] name = "vlc"