Fix to use libvlc-sys
							parent
							
								
									1cc3be26dd
								
							
						
					
					
						commit
						2ce884fc5c
					
				| 
						 | 
					@ -6,7 +6,7 @@ edition = "2018"
 | 
				
			||||||
build = "build.rs"
 | 
					build = "build.rs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[lib]
 | 
					[lib]
 | 
				
			||||||
name = "libvlc_sys"
 | 
					name = "vlc_sys"
 | 
				
			||||||
crate-type = ["rlib"]
 | 
					crate-type = ["rlib"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::MediaPlayer;
 | 
					use crate::MediaPlayer;
 | 
				
			||||||
use crate::TrackDescription;
 | 
					use crate::TrackDescription;
 | 
				
			||||||
use crate::tools::from_cstr;
 | 
					use crate::tools::from_cstr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										21
									
								
								src/core.rs
								
								
								
								
							
							
						
						
									
										21
									
								
								src/core.rs
								
								
								
								
							| 
						 | 
					@ -7,8 +7,9 @@ use std::borrow::Cow;
 | 
				
			||||||
use std::marker::PhantomData;
 | 
					use std::marker::PhantomData;
 | 
				
			||||||
use std::ffi::CString;
 | 
					use std::ffi::CString;
 | 
				
			||||||
use std::i32;
 | 
					use std::i32;
 | 
				
			||||||
 | 
					use std::convert::TryInto;
 | 
				
			||||||
use libc::{c_void, c_char, c_int};
 | 
					use libc::{c_void, c_char, c_int};
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::tools::{to_cstr, from_cstr, from_cstr_ref};
 | 
					use crate::tools::{to_cstr, from_cstr, from_cstr_ref};
 | 
				
			||||||
use crate::enums::*;
 | 
					use crate::enums::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -124,7 +125,7 @@ impl Instance {
 | 
				
			||||||
        let cb: Box<Box<dyn 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{
 | 
					        unsafe{
 | 
				
			||||||
            sys::libvlc_log_set(self.ptr, logging_cb, Box::into_raw(cb) as *mut _);
 | 
					            sys::libvlc_log_set(self.ptr, Some(logging_cb), Box::into_raw(cb) as *mut _);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -142,17 +143,14 @@ impl Drop for Instance {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern "C" {
 | 
					 | 
				
			||||||
    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.
 | 
					const BUF_SIZE: usize = 1024; // Write log message to the buffer by vsnprintf.
 | 
				
			||||||
unsafe extern "C" fn logging_cb(
 | 
					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) {
 | 
					    data: *mut c_void, level: c_int, ctx: *const sys::libvlc_log_t, fmt: *const c_char, args: *mut sys::__va_list_tag) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let f: &Box<dyn 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];
 | 
					    let mut buf: [c_char; BUF_SIZE] = [0; BUF_SIZE];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vsnprintf(buf.as_mut_ptr(), BUF_SIZE, fmt, args);
 | 
					    sys::vsnprintf(buf.as_mut_ptr(), BUF_SIZE.try_into().unwrap(), fmt, args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    f((level as u32).into(), Log{ptr: ctx}, from_cstr_ref(buf.as_ptr()).unwrap());
 | 
					    f((level as u32).into(), Log{ptr: ctx}, from_cstr_ref(buf.as_ptr()).unwrap());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -324,7 +322,7 @@ impl<'a> EventManager<'a> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let result = unsafe{
 | 
					        let result = unsafe{
 | 
				
			||||||
            sys::libvlc_event_attach(
 | 
					            sys::libvlc_event_attach(
 | 
				
			||||||
                self.ptr, event_type as i32, event_manager_callback,
 | 
					                self.ptr, event_type as i32, Some(event_manager_callback),
 | 
				
			||||||
                Box::into_raw(callback) as *mut c_void)
 | 
					                Box::into_raw(callback) as *mut c_void)
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -349,12 +347,12 @@ unsafe extern "C" fn event_manager_callback(pe: *const sys::libvlc_event_t, data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Convert c-style libvlc_event_t to Event
 | 
					// Convert c-style libvlc_event_t to Event
 | 
				
			||||||
fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
 | 
					fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
 | 
				
			||||||
    let event_type: EventType = (unsafe{ (*pe)._type } as u32).into();
 | 
					    let event_type: EventType = (unsafe{ (*pe).type_ } as u32).into();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    match event_type {
 | 
					    match event_type {
 | 
				
			||||||
        EventType::MediaMetaChanged => {
 | 
					        EventType::MediaMetaChanged => {
 | 
				
			||||||
            unsafe{
 | 
					            unsafe{
 | 
				
			||||||
                Event::MediaMetaChanged((*pe).u.media_meta_changed.meta_type)
 | 
					                Event::MediaMetaChanged((*pe).u.media_meta_changed.meta_type.into())
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        EventType::MediaSubItemAdded => {
 | 
					        EventType::MediaSubItemAdded => {
 | 
				
			||||||
| 
						 | 
					@ -375,7 +373,8 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        EventType::MediaStateChanged => {
 | 
					        EventType::MediaStateChanged => {
 | 
				
			||||||
            unsafe{
 | 
					            unsafe{
 | 
				
			||||||
                Event::MediaStateChanged((*pe).u.media_state_changed.new_state)
 | 
					                let new_state: sys::libvlc_state_t = (*pe).u.media_state_changed.new_state.try_into().unwrap();
 | 
				
			||||||
 | 
					                Event::MediaStateChanged(new_state.into())
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        EventType::MediaSubItemTreeAdded => {
 | 
					        EventType::MediaSubItemTreeAdded => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use libvlc_sys as sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
macro_rules! define_enum {
 | 
					macro_rules! define_enum {
 | 
				
			||||||
    ($enum_name:ident, $original_type:ident; $($value:ident = $c_value:ident,)*) => {
 | 
					    ($enum_name:ident, $original_type:ident; $($value:ident = $c_value:ident,)*) => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/media.rs
								
								
								
								
							
							
						
						
									
										19
									
								
								src/media.rs
								
								
								
								
							| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::{Instance, EventManager};
 | 
					use crate::{Instance, EventManager};
 | 
				
			||||||
use crate::enums::{State, Meta, TrackType};
 | 
					use crate::enums::{State, Meta, TrackType};
 | 
				
			||||||
use crate::tools::{to_cstr, from_cstr, path_to_cstr};
 | 
					use crate::tools::{to_cstr, from_cstr, path_to_cstr};
 | 
				
			||||||
| 
						 | 
					@ -76,7 +76,7 @@ impl Media {
 | 
				
			||||||
    /// If the media has not yet been parsed this will return None.
 | 
					    /// If the media has not yet been parsed this will return None.
 | 
				
			||||||
    pub fn get_meta(&self, meta: Meta) -> Option<String> {
 | 
					    pub fn get_meta(&self, meta: Meta) -> Option<String> {
 | 
				
			||||||
        unsafe{
 | 
					        unsafe{
 | 
				
			||||||
            let p_str = sys::libvlc_media_get_meta(self.ptr, meta);
 | 
					            let p_str = sys::libvlc_media_get_meta(self.ptr, meta as u32);
 | 
				
			||||||
            let s = from_cstr(p_str);
 | 
					            let s = from_cstr(p_str);
 | 
				
			||||||
            sys::libvlc_free(p_str as *mut ::libc::c_void);
 | 
					            sys::libvlc_free(p_str as *mut ::libc::c_void);
 | 
				
			||||||
            s
 | 
					            s
 | 
				
			||||||
| 
						 | 
					@ -87,7 +87,7 @@ impl 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) {
 | 
					    pub fn set_meta(&self, meta: Meta, value: &str) {
 | 
				
			||||||
        unsafe{
 | 
					        unsafe{
 | 
				
			||||||
            sys::libvlc_media_set_meta(self.ptr, meta, to_cstr(value).as_ptr());
 | 
					            sys::libvlc_media_set_meta(self.ptr, meta as u32, to_cstr(value).as_ptr());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -98,7 +98,7 @@ impl Media {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Get current state of media descriptor object.
 | 
					    /// Get current state of media descriptor object.
 | 
				
			||||||
    pub fn state(&self) -> State {
 | 
					    pub fn state(&self) -> State {
 | 
				
			||||||
        unsafe{ sys::libvlc_media_get_state(self.ptr) }
 | 
					        unsafe{ sys::libvlc_media_get_state(self.ptr).into() }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Get duration (in ms) of media descriptor object item.
 | 
					    /// Get duration (in ms) of media descriptor object item.
 | 
				
			||||||
| 
						 | 
					@ -136,16 +136,17 @@ impl Media {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for i in 0..n {
 | 
					            for i in 0..n {
 | 
				
			||||||
                let p = p_track.offset(i as isize);
 | 
					                let p = p_track.offset(i as isize);
 | 
				
			||||||
                let type_specific_data = match (**p).i_type {
 | 
					                let i_type: TrackType = (**p).i_type.into();
 | 
				
			||||||
 | 
					                let type_specific_data = match i_type {
 | 
				
			||||||
                    TrackType::Audio => {
 | 
					                    TrackType::Audio => {
 | 
				
			||||||
                        let audio = (**p).audio();
 | 
					                        let audio = (**p).__bindgen_anon_1.audio;
 | 
				
			||||||
                        MediaTrackUnion::Audio(AudioTrack{
 | 
					                        MediaTrackUnion::Audio(AudioTrack{
 | 
				
			||||||
                            channels: (*audio).i_channels,
 | 
					                            channels: (*audio).i_channels,
 | 
				
			||||||
                            rate:     (*audio).i_rate,
 | 
					                            rate:     (*audio).i_rate,
 | 
				
			||||||
                        })
 | 
					                        })
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                    TrackType::Video => {
 | 
					                    TrackType::Video => {
 | 
				
			||||||
                        let video = (**p).video();
 | 
					                        let video = (**p).__bindgen_anon_1.video;
 | 
				
			||||||
                        MediaTrackUnion::Video(VideoTrack{
 | 
					                        MediaTrackUnion::Video(VideoTrack{
 | 
				
			||||||
                            height:         (*video).i_height,
 | 
					                            height:         (*video).i_height,
 | 
				
			||||||
                            width:          (*video).i_width,
 | 
					                            width:          (*video).i_width,
 | 
				
			||||||
| 
						 | 
					@ -156,7 +157,7 @@ impl Media {
 | 
				
			||||||
                        })
 | 
					                        })
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                    TrackType::Text => {
 | 
					                    TrackType::Text => {
 | 
				
			||||||
                        let subtitle = (**p).subtitle();
 | 
					                        let subtitle = (**p).__bindgen_anon_1.subtitle;
 | 
				
			||||||
                        MediaTrackUnion::Subtitle(SubtitleTrack{
 | 
					                        MediaTrackUnion::Subtitle(SubtitleTrack{
 | 
				
			||||||
                            encoding: from_cstr((*subtitle).psz_encoding)
 | 
					                            encoding: from_cstr((*subtitle).psz_encoding)
 | 
				
			||||||
                        })
 | 
					                        })
 | 
				
			||||||
| 
						 | 
					@ -167,7 +168,7 @@ impl Media {
 | 
				
			||||||
                    codec:              (**p).i_codec,
 | 
					                    codec:              (**p).i_codec,
 | 
				
			||||||
                    original_fourcc:    (**p).i_original_fourcc,
 | 
					                    original_fourcc:    (**p).i_original_fourcc,
 | 
				
			||||||
                    id:                 (**p).i_id,
 | 
					                    id:                 (**p).i_id,
 | 
				
			||||||
                    track_type:         (**p).i_type,
 | 
					                    track_type:         (**p).i_type.into(),
 | 
				
			||||||
                    profile:            (**p).i_profile,
 | 
					                    profile:            (**p).i_profile,
 | 
				
			||||||
                    level:              (**p).i_level,
 | 
					                    level:              (**p).i_level,
 | 
				
			||||||
                    bitrate:            (**p).i_bitrate,
 | 
					                    bitrate:            (**p).i_bitrate,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::{Instance, MediaList};
 | 
					use crate::{Instance, MediaList};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct MediaLibrary {
 | 
					pub struct MediaLibrary {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::{Instance, Media, EventManager};
 | 
					use crate::{Instance, Media, EventManager};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct MediaList {
 | 
					pub struct MediaList {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::Instance;
 | 
					use crate::Instance;
 | 
				
			||||||
use crate::Media;
 | 
					use crate::Media;
 | 
				
			||||||
use crate::EventManager;
 | 
					use crate::EventManager;
 | 
				
			||||||
| 
						 | 
					@ -265,7 +265,7 @@ impl MediaPlayer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Get current movie state.
 | 
					    /// Get current movie state.
 | 
				
			||||||
    pub fn state(&self) -> State {
 | 
					    pub fn state(&self) -> State {
 | 
				
			||||||
        unsafe{ sys::libvlc_media_player_get_state(self.ptr) }
 | 
					        unsafe{ sys::libvlc_media_player_get_state(self.ptr) }.into()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// How many video outputs does this media player have?
 | 
					    /// How many video outputs does this media player have?
 | 
				
			||||||
| 
						 | 
					@ -309,7 +309,7 @@ impl MediaPlayer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Set if, and how, the video title will be shown when media is played.
 | 
					    /// 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) {
 | 
					    pub fn set_video_title_display(&self, position: Position, timeout: u32) {
 | 
				
			||||||
        unsafe{ sys::libvlc_media_player_set_video_title_display(self.ptr, position, timeout); }
 | 
					        unsafe{ sys::libvlc_media_player_set_video_title_display(self.ptr, position as i32, timeout); }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Returns raw pointer
 | 
					    /// Returns raw pointer
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@
 | 
				
			||||||
// This file is part of vlc-rs.
 | 
					// This file is part of vlc-rs.
 | 
				
			||||||
// Licensed under the MIT license, see the LICENSE file.
 | 
					// Licensed under the MIT license, see the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::sys;
 | 
					use vlc_sys as sys;
 | 
				
			||||||
use crate::MediaPlayer;
 | 
					use crate::MediaPlayer;
 | 
				
			||||||
use crate::TrackDescription;
 | 
					use crate::TrackDescription;
 | 
				
			||||||
use crate::enums::VideoAdjustOption;
 | 
					use crate::enums::VideoAdjustOption;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue