Fix to use libvlc-sys

2-bindgen
T. Okubo 2019-11-25 20:10:17 +09:00
parent 1cc3be26dd
commit 2ce884fc5c
9 changed files with 29 additions and 29 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
build = "build.rs"
[lib]
name = "libvlc_sys"
name = "vlc_sys"
crate-type = ["rlib"]
[dependencies]

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use crate::sys;
use vlc_sys as sys;
use crate::MediaPlayer;
use crate::TrackDescription;
use crate::tools::from_cstr;

View File

@ -7,8 +7,9 @@ use std::borrow::Cow;
use std::marker::PhantomData;
use std::ffi::CString;
use std::i32;
use std::convert::TryInto;
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::enums::*;
@ -124,7 +125,7 @@ impl Instance {
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 _);
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.
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 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());
}
@ -324,7 +322,7 @@ impl<'a> EventManager<'a> {
let result = unsafe{
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)
};
@ -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
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 {
EventType::MediaMetaChanged => {
unsafe{
Event::MediaMetaChanged((*pe).u.media_meta_changed.meta_type)
Event::MediaMetaChanged((*pe).u.media_meta_changed.meta_type.into())
}
},
EventType::MediaSubItemAdded => {
@ -375,7 +373,8 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
},
EventType::MediaStateChanged => {
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 => {

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use libvlc_sys as sys;
use vlc_sys as sys;
macro_rules! define_enum {
($enum_name:ident, $original_type:ident; $($value:ident = $c_value:ident,)*) => {

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use crate::sys;
use vlc_sys as sys;
use crate::{Instance, EventManager};
use crate::enums::{State, Meta, TrackType};
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.
pub fn get_meta(&self, meta: Meta) -> Option<String> {
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);
sys::libvlc_free(p_str as *mut ::libc::c_void);
s
@ -87,7 +87,7 @@ 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{
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.
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.
@ -136,16 +136,17 @@ impl Media {
for i in 0..n {
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 => {
let audio = (**p).audio();
let audio = (**p).__bindgen_anon_1.audio;
MediaTrackUnion::Audio(AudioTrack{
channels: (*audio).i_channels,
rate: (*audio).i_rate,
})
},
TrackType::Video => {
let video = (**p).video();
let video = (**p).__bindgen_anon_1.video;
MediaTrackUnion::Video(VideoTrack{
height: (*video).i_height,
width: (*video).i_width,
@ -156,7 +157,7 @@ impl Media {
})
},
TrackType::Text => {
let subtitle = (**p).subtitle();
let subtitle = (**p).__bindgen_anon_1.subtitle;
MediaTrackUnion::Subtitle(SubtitleTrack{
encoding: from_cstr((*subtitle).psz_encoding)
})
@ -167,7 +168,7 @@ impl Media {
codec: (**p).i_codec,
original_fourcc: (**p).i_original_fourcc,
id: (**p).i_id,
track_type: (**p).i_type,
track_type: (**p).i_type.into(),
profile: (**p).i_profile,
level: (**p).i_level,
bitrate: (**p).i_bitrate,

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use crate::sys;
use vlc_sys as sys;
use crate::{Instance, MediaList};
pub struct MediaLibrary {

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use crate::sys;
use vlc_sys as sys;
use crate::{Instance, Media, EventManager};
pub struct MediaList {

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use crate::sys;
use vlc_sys as sys;
use crate::Instance;
use crate::Media;
use crate::EventManager;
@ -265,7 +265,7 @@ impl MediaPlayer {
/// Get current movie 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?
@ -309,7 +309,7 @@ impl MediaPlayer {
/// 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{ 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

View File

@ -2,7 +2,7 @@
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use crate::sys;
use vlc_sys as sys;
use crate::MediaPlayer;
use crate::TrackDescription;
use crate::enums::VideoAdjustOption;