Integrate VLC 4.x

merge-requests/10/head
Romain Roffé 2022-06-07 15:16:56 +02:00
parent 12a22eb8a4
commit a4eea10a8d
10 changed files with 5311 additions and 1874 deletions

File diff suppressed because it is too large Load Diff

View File

@ -91,11 +91,6 @@ impl Instance {
}
}
/// Waits until an interface causes the instance to exit.
pub fn wait(&self) {
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{
@ -122,15 +117,6 @@ impl Instance {
}
}
/// Returns the VLM event manager
pub fn vlm_event_manager<'a>(&'a self) -> EventManager<'a> {
unsafe{
let p = sys::libvlc_vlm_get_event_manager(self.ptr);
assert!(!p.is_null());
EventManager{ptr: p, _phantomdata: ::std::marker::PhantomData}
}
}
/// Set logging callback
pub fn set_log<F: Fn(LogLevel, Log, Cow<str>) + Send + 'static>(&self, f: F) {
let cb: Box<Box<dyn Fn(LogLevel, Log, Cow<str>) + Send + 'static>> = Box::new(Box::new(f));
@ -385,15 +371,6 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
Event::MediaParsedChanged((*pe).u.media_parsed_changed.new_status)
}
},
EventType::MediaFreed => {
Event::MediaFreed
},
EventType::MediaStateChanged => {
unsafe{
let new_state: sys::libvlc_state_t = (*pe).u.media_state_changed.new_state.try_into().unwrap();
Event::MediaStateChanged(new_state.into())
}
},
EventType::MediaSubItemTreeAdded => {
Event::MediaSubItemTreeAdded
},
@ -426,9 +403,6 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
EventType::MediaPlayerBackward => {
Event::MediaPlayerBackward
},
EventType::MediaPlayerEndReached => {
Event::MediaPlayerEndReached
},
EventType::MediaPlayerEncounteredError => {
Event::MediaPlayerEncounteredError
},
@ -446,9 +420,6 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
EventType::MediaPlayerPausableChanged => {
Event::MediaPlayerPausableChanged
},
EventType::MediaPlayerTitleChanged => {
Event::MediaPlayerTitleChanged
},
EventType::MediaPlayerSnapshotTaken => {
Event::MediaPlayerSnapshotTaken
},
@ -458,9 +429,6 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
EventType::MediaPlayerVout => {
Event::MediaPlayerVout
},
EventType::MediaPlayerScrambledChanged => {
Event::MediaPlayerScrambledChanged
},
EventType::MediaListItemAdded => {
Event::MediaListItemAdded
},
@ -494,67 +462,6 @@ fn conv_event(pe: *const sys::libvlc_event_t) -> Event {
EventType::MediaListPlayerStopped => {
Event::MediaListPlayerStopped
},
EventType::MediaDiscovererStarted => {
Event::MediaDiscovererStarted
},
EventType::MediaDiscovererEnded => {
Event::MediaDiscovererEnded
},
EventType::VlmMediaAdded => {
unsafe {
Event::VlmMediaAdded(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaRemoved => {
unsafe {
Event::VlmMediaRemoved(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaChanged => {
unsafe {
Event::VlmMediaChanged(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStarted => {
unsafe {
Event::VlmMediaInstanceStarted(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStopped => {
unsafe {
Event::VlmMediaInstanceStopped(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStatusInit => {
unsafe {
Event::VlmMediaInstanceStatusInit(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStatusOpening => {
unsafe {
Event::VlmMediaInstanceStatusOpening(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStatusPlaying => {
unsafe {
Event::VlmMediaInstanceStatusPlaying(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStatusPause => {
unsafe {
Event::VlmMediaInstanceStatusPause(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStatusEnd => {
unsafe {
Event::VlmMediaInstanceStatusEnd(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
EventType::VlmMediaInstanceStatusError => {
unsafe {
Event::VlmMediaInstanceStatusError(from_cstr((*pe).u.vlm_media_event.psz_instance_name), from_cstr((*pe).u.vlm_media_event.psz_media_name))
}
},
}
}

View File

@ -70,7 +70,6 @@ define_enum!(
Playing = libvlc_state_t_libvlc_Playing,
Paused = libvlc_state_t_libvlc_Paused,
Stopped = libvlc_state_t_libvlc_Stopped,
Ended = libvlc_state_t_libvlc_Ended,
Error = libvlc_state_t_libvlc_Error,
);
@ -122,8 +121,6 @@ define_enum!(
MediaSubItemAdded = libvlc_event_e_libvlc_MediaSubItemAdded,
MediaDurationChanged = libvlc_event_e_libvlc_MediaDurationChanged,
MediaParsedChanged = libvlc_event_e_libvlc_MediaParsedChanged,
MediaFreed = libvlc_event_e_libvlc_MediaFreed,
MediaStateChanged = libvlc_event_e_libvlc_MediaStateChanged,
MediaSubItemTreeAdded = libvlc_event_e_libvlc_MediaSubItemTreeAdded,
MediaPlayerMediaChanged = libvlc_event_e_libvlc_MediaPlayerMediaChanged,
MediaPlayerNothingSpecial = libvlc_event_e_libvlc_MediaPlayerNothingSpecial,
@ -134,17 +131,14 @@ define_enum!(
MediaPlayerStopped = libvlc_event_e_libvlc_MediaPlayerStopped,
MediaPlayerForward = libvlc_event_e_libvlc_MediaPlayerForward,
MediaPlayerBackward = libvlc_event_e_libvlc_MediaPlayerBackward,
MediaPlayerEndReached = libvlc_event_e_libvlc_MediaPlayerEndReached,
MediaPlayerEncounteredError = libvlc_event_e_libvlc_MediaPlayerEncounteredError,
MediaPlayerTimeChanged = libvlc_event_e_libvlc_MediaPlayerTimeChanged,
MediaPlayerPositionChanged = libvlc_event_e_libvlc_MediaPlayerPositionChanged,
MediaPlayerSeekableChanged = libvlc_event_e_libvlc_MediaPlayerSeekableChanged,
MediaPlayerPausableChanged = libvlc_event_e_libvlc_MediaPlayerPausableChanged,
MediaPlayerTitleChanged = libvlc_event_e_libvlc_MediaPlayerTitleChanged,
MediaPlayerSnapshotTaken = libvlc_event_e_libvlc_MediaPlayerSnapshotTaken,
MediaPlayerLengthChanged = libvlc_event_e_libvlc_MediaPlayerLengthChanged,
MediaPlayerVout = libvlc_event_e_libvlc_MediaPlayerVout,
MediaPlayerScrambledChanged = libvlc_event_e_libvlc_MediaPlayerScrambledChanged,
MediaListItemAdded = libvlc_event_e_libvlc_MediaListItemAdded,
MediaListWillAddItem = libvlc_event_e_libvlc_MediaListWillAddItem,
MediaListItemDeleted = libvlc_event_e_libvlc_MediaListItemDeleted,
@ -156,17 +150,4 @@ define_enum!(
MediaListPlayerPlayed = libvlc_event_e_libvlc_MediaListPlayerPlayed,
MediaListPlayerNextItemSet = libvlc_event_e_libvlc_MediaListPlayerNextItemSet,
MediaListPlayerStopped = libvlc_event_e_libvlc_MediaListPlayerStopped,
MediaDiscovererStarted = libvlc_event_e_libvlc_MediaDiscovererStarted,
MediaDiscovererEnded = libvlc_event_e_libvlc_MediaDiscovererEnded,
VlmMediaAdded = libvlc_event_e_libvlc_VlmMediaAdded,
VlmMediaRemoved = libvlc_event_e_libvlc_VlmMediaRemoved,
VlmMediaChanged = libvlc_event_e_libvlc_VlmMediaChanged,
VlmMediaInstanceStarted = libvlc_event_e_libvlc_VlmMediaInstanceStarted,
VlmMediaInstanceStopped = libvlc_event_e_libvlc_VlmMediaInstanceStopped,
VlmMediaInstanceStatusInit = libvlc_event_e_libvlc_VlmMediaInstanceStatusInit,
VlmMediaInstanceStatusOpening = libvlc_event_e_libvlc_VlmMediaInstanceStatusOpening,
VlmMediaInstanceStatusPlaying = libvlc_event_e_libvlc_VlmMediaInstanceStatusPlaying,
VlmMediaInstanceStatusPause = libvlc_event_e_libvlc_VlmMediaInstanceStatusPause,
VlmMediaInstanceStatusEnd = libvlc_event_e_libvlc_VlmMediaInstanceStatusEnd,
VlmMediaInstanceStatusError = libvlc_event_e_libvlc_VlmMediaInstanceStatusError,
);

View File

@ -9,18 +9,14 @@ mod core;
mod media;
mod media_player;
mod media_list;
mod media_library;
mod enums;
mod video;
mod audio;
mod 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

@ -4,7 +4,7 @@
use vlc_sys as sys;
use crate::{Instance, EventManager};
use crate::enums::{State, Meta, TrackType};
use crate::enums::{Meta, TrackType};
use crate::tools::{to_cstr, from_cstr, path_to_cstr};
use std::path::Path;
@ -98,11 +98,6 @@ impl Media {
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{ sys::libvlc_media_get_state(self.ptr).into() }
}
/// Get duration (in ms) of media descriptor object item.
pub fn duration(&self) -> Option<i64> {
let time = unsafe{
@ -123,7 +118,7 @@ impl Media {
/// Get Parsed status for media descriptor object.
pub fn is_parsed(&self) -> bool {
if unsafe{ sys::libvlc_media_is_parsed(self.ptr) } == 0 { false }else{ true }
unsafe{ sys::libvlc_media_is_parsed(self.ptr) }
}
pub fn tracks(&self) -> Option<Vec<MediaTrack>> {

View File

@ -1,46 +0,0 @@
// Copyright (c) 2015 T. Okubo
// This file is part of vlc-rs.
// Licensed under the MIT license, see the LICENSE file.
use vlc_sys as sys;
use crate::{Instance, MediaList};
pub struct MediaLibrary {
pub(crate) 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 = sys::libvlc_media_library_new(instance.ptr);
if p.is_null() { None }else{ Some(MediaLibrary{ptr: p}) }
}
}
/// Load media library.
pub fn load(&self) -> Result<(), ()> {
unsafe{
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 = sys::libvlc_media_library_media_list(self.ptr);
if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
}
}
/// Returns raw pointer
pub fn raw(&self) -> *mut sys::libvlc_media_library_t {
self.ptr
}
}
impl Drop for MediaLibrary {
fn drop(&mut self) {
unsafe{ sys::libvlc_media_library_release(self.ptr) };
}
}

View File

@ -3,7 +3,7 @@
// Licensed under the MIT license, see the LICENSE file.
use vlc_sys as sys;
use crate::{Instance, Media, EventManager};
use crate::{Media, EventManager};
pub struct MediaList {
pub(crate) ptr: *mut sys::libvlc_media_list_t,
@ -11,9 +11,9 @@ pub struct MediaList {
impl MediaList {
/// Create an empty media list.
pub fn new(instance: &Instance) -> Option<MediaList> {
pub fn new() -> Option<MediaList> {
unsafe{
let p = sys::libvlc_media_list_new(instance.ptr);
let p = sys::libvlc_media_list_new();
if p.is_null() { None }else{ Some(MediaList{ptr: p}) }
}
}
@ -82,7 +82,7 @@ impl MediaList {
/// This indicates if this media list is read-only from a user point of view.
pub fn is_readonly(&self) -> bool {
unsafe{ if sys::libvlc_media_list_is_readonly(self.ptr) == 0 { false }else{ true } }
unsafe{ sys::libvlc_media_list_is_readonly(self.ptr) }
}
/// Get lock on media list items

View File

@ -56,11 +56,7 @@ impl MediaPlayer {
/// is_playing
pub fn is_playing(&self) -> bool {
if unsafe{ sys::libvlc_media_player_is_playing(self.ptr) } == 0 {
false
}else{
true
}
unsafe{ sys::libvlc_media_player_is_playing(self.ptr) }
}
/// Play
@ -84,7 +80,7 @@ impl MediaPlayer {
/// Stop (no effect if there is no media)
pub fn stop(&self) {
unsafe{ sys::libvlc_media_player_stop(self.ptr) };
unsafe{ sys::libvlc_media_player_stop_async(self.ptr) };
}
pub fn set_callbacks<F>(
@ -163,8 +159,8 @@ 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{ sys::libvlc_media_player_set_time(self.ptr, time); }
pub fn set_time(&self, time: i64, fast: bool) {
unsafe{ sys::libvlc_media_player_set_time(self.ptr, time, fast); }
}
/// Get movie position as percentage between 0.0 and 1.0.
@ -177,8 +173,8 @@ 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{ sys::libvlc_media_player_set_position(self.ptr, pos); }
pub fn set_position(&self, pos: f32, fast: bool) {
unsafe{ sys::libvlc_media_player_set_position(self.ptr, pos, fast); }
}
/// Set movie chapter (if applicable).
@ -204,10 +200,7 @@ impl MediaPlayer {
/// Is the player able to play.
pub fn will_play(&self) -> bool {
unsafe{
let b = sys::libvlc_media_player_will_play(self.ptr);
if b == 0 { false }else{ true }
}
false
}
/// Get title chapter count.
@ -277,26 +270,17 @@ impl MediaPlayer {
/// Is this media player seekable?
pub fn is_seekable(&self) -> bool {
unsafe{
let b = sys::libvlc_media_player_is_seekable(self.ptr);
if b == 0 { false }else{ true }
}
unsafe{ sys::libvlc_media_player_is_seekable(self.ptr) }
}
/// Can this media player be paused?
pub fn can_pause(&self) -> bool {
unsafe{
let b = sys::libvlc_media_player_can_pause(self.ptr);
if b == 0 { false }else{ true }
}
unsafe{ sys::libvlc_media_player_can_pause(self.ptr) }
}
/// Check if the current program is scrambled.
pub fn program_scrambled(&self) -> bool {
unsafe{
let b = sys::libvlc_media_player_program_scrambled(self.ptr);
if b == 0 { false }else{ true }
}
unsafe{ sys::libvlc_media_player_program_scrambled(self.ptr) }
}
/// Display the next frame (if supported)

View File

@ -35,10 +35,10 @@ impl MediaPlayerVideoEx for MediaPlayer {
unsafe{ sys::libvlc_toggle_fullscreen(self.ptr); }
}
fn set_fullscreen(&self, fullscreen: bool) {
unsafe{ sys::libvlc_set_fullscreen(self.ptr, if fullscreen { 1 }else{ 0 }); }
unsafe{ sys::libvlc_set_fullscreen(self.ptr, fullscreen); }
}
fn get_fullscreen(&self) -> bool {
unsafe{ if sys::libvlc_get_fullscreen(self.ptr) == 0 { false }else{ true } }
unsafe{ sys::libvlc_get_fullscreen(self.ptr) }
}
fn set_key_input(&self, on: bool) {
unsafe{ sys::libvlc_video_set_key_input(self.ptr, if on { 1 }else{ 0 }); }

View File

@ -1,148 +0,0 @@
use std::ffi::CString;
use std::os::raw::c_char;
use std::ptr;
use vlc_sys as sys;
use crate::Instance;
use crate::tools::{from_cstr, to_cstr};
pub trait Vlm {
fn add_broadcast(&self, name: &str, input: &str, output: &str, options: Option<Vec<String>>, enabled: bool, loop_broadcast: bool, ) -> Result<(), ()>;
fn add_vod(&self, name: &str, input: &str, mux: &str, options: Option<Vec<String>>, enabled: bool) -> Result<(), ()>;
fn play_media(&self, name: &str) -> Result<(), ()>;
fn pause_media(&self, name: &str) -> Result<(), ()>;
fn stop_media(&self, name: &str) -> Result<(), ()>;
fn get_media_instance_position(&self, name: &str, instance: i32) -> Result<f32, ()>;
fn get_media_instance_length(&self, name: &str, instance: i32) -> Result<i32, ()>;
fn get_media_instance_time(&self, name: &str, instance: i32) -> Result<i32, ()>;
fn get_media_instance_rate(&self, name: &str, instance: i32) -> Result<i32, ()>;
fn show_media(&self, name: &str) -> Result<String, ()>;
}
impl Vlm for Instance {
fn add_broadcast(&self, name: &str, input: &str, output: &str, options: Option<Vec<String>>, enabled: bool, loop_broadcast: bool, ) -> Result<(), ()> {
let name = to_cstr(name);
let input = to_cstr(input);
let output = to_cstr(output);
let opts_c_ptr: Vec<*const c_char>;
let opts_c: Vec<CString>;
let enabled = if enabled { 1 } else { 0 };
let loop_broadcast = if loop_broadcast { 1 } else { 0 };
if let Some(vec) = options {
opts_c = vec.into_iter()
.map(|x| CString::new(x).expect("Error: Unexpected null byte")).collect();
opts_c_ptr = opts_c.iter().map(|x| x.as_ptr()).collect();
} else {
opts_c_ptr = Vec::new();
}
let result = unsafe {
if opts_c_ptr.is_empty() {
sys::libvlc_vlm_add_broadcast(self.ptr, name.as_ptr(), input.as_ptr(), output.as_ptr(), 0, ptr::null(), enabled, loop_broadcast)
} else {
sys::libvlc_vlm_add_broadcast(self.ptr, name.as_ptr(), input.as_ptr(), output.as_ptr(), opts_c_ptr.len() as i32, opts_c_ptr.as_ptr(), enabled, loop_broadcast)
}
};
if result == 0 { Ok(()) } else { Err(()) }
}
fn add_vod(&self, name: &str, input: &str, mux: &str, options: Option<Vec<String>>, enabled: bool) -> Result<(), ()> {
let name = to_cstr(name);
let input = to_cstr(input);
let mux = to_cstr(mux);
let opts_c_ptr: Vec<*const c_char>;
let opts_c: Vec<CString>;
let enabled = if enabled { 1 } else { 0 };
if let Some(vec) = options {
opts_c = vec.into_iter()
.map(|x| CString::new(x).expect("Error: Unexpected null byte")).collect();
opts_c_ptr = opts_c.iter().map(|x| x.as_ptr()).collect();
} else {
opts_c_ptr = Vec::new();
}
let result = unsafe {
if opts_c_ptr.is_empty() {
sys::libvlc_vlm_add_vod(self.ptr, name.as_ptr(), input.as_ptr(), 0, ptr::null(), enabled, mux.as_ptr())
} else {
sys::libvlc_vlm_add_vod(self.ptr, name.as_ptr(), input.as_ptr(), opts_c_ptr.len() as i32, opts_c_ptr.as_ptr(), enabled, mux.as_ptr())
}
};
if result == 0 { Ok(()) } else { Err(()) }
}
fn play_media(&self, name: &str) -> Result<(), ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_play_media(self.ptr, name.as_ptr())
};
if result == 0 { Ok(()) } else { Err(()) }
}
fn pause_media(&self, name: &str) -> Result<(), ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_pause_media(self.ptr, name.as_ptr())
};
if result == 0 { Ok(()) } else { Err(()) }
}
fn stop_media(&self, name: &str) -> Result<(), ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_stop_media(self.ptr, name.as_ptr())
};
if result == 0 { Ok(()) } else { Err(()) }
}
fn get_media_instance_position(&self, name: &str, instance: i32) -> Result<f32, ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_get_media_instance_position(self.ptr, name.as_ptr(), instance)
};
if result != -1f32 { Ok(result) } else { Err(()) }
}
fn get_media_instance_length(&self, name: &str, instance: i32) -> Result<i32, ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_get_media_instance_length(self.ptr, name.as_ptr(), instance)
};
if result != -1 { Ok(result) } else { Err(()) }
}
fn get_media_instance_time(&self, name: &str, instance: i32) -> Result<i32, ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_get_media_instance_time(self.ptr, name.as_ptr(), instance)
};
if result != -1 { Ok(result) } else { Err(()) }
}
fn get_media_instance_rate(&self, name: &str, instance: i32) -> Result<i32, ()> {
let name = to_cstr(name);
let result = unsafe {
sys::libvlc_vlm_get_media_instance_rate(self.ptr, name.as_ptr(), instance)
};
if result != -1 { Ok(result) } else { Err(()) }
}
fn show_media(&self, name: &str) -> Result<String, ()> {
let name = to_cstr(name);
let result = unsafe {
from_cstr(sys::libvlc_vlm_show_media(self.ptr, name.as_ptr()))
};
if let Some(data) = result {
Ok(data.to_string())
} else {
Err(())
}
}
}