From 48d22b29f7d01d5654ae7c576b0c3ea39a260752 Mon Sep 17 00:00:00 2001 From: "T. Okubo" Date: Sat, 19 Dec 2015 11:23:20 +0900 Subject: [PATCH] Add get_track_description --- src/audio.rs | 19 +++++++++++++++++++ src/media_player.rs | 6 ++++++ src/video.rs | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/audio.rs b/src/audio.rs index 1422c29..950e579 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -4,12 +4,15 @@ use ffi; use ::MediaPlayer; +use ::TrackDescription; +use ::tools::from_cstr; pub trait MediaPlayerAudioEx { fn get_mute(&self) -> Option; fn set_mute(&self, bool); fn get_volume(&self) -> i32; fn set_volume(&self, volume: i32) -> Result<(), ()>; + fn get_audio_track_description(&self) -> Option>; } impl MediaPlayerAudioEx for MediaPlayer { @@ -37,4 +40,20 @@ impl MediaPlayerAudioEx for MediaPlayer { if ffi::libvlc_audio_set_volume(self.ptr, volume) == 0 { Ok(()) }else{ Err(()) } } } + fn get_audio_track_description(&self) -> Option> { + unsafe{ + let p0 = ffi::libvlc_audio_get_track_description(self.ptr); + if p0.is_null() { return None; } + let mut td = Vec::new(); + let mut p = p0; + + while !(*p).p_next.is_null() { + td.push(TrackDescription{ id: (*p).i_id, name: from_cstr((*p).psz_name) }); + p = (*p).p_next; + } + ffi::libvlc_track_description_list_release(p0); + Some(td) + } + } + } diff --git a/src/media_player.rs b/src/media_player.rs index 200581a..34e660c 100644 --- a/src/media_player.rs +++ b/src/media_player.rs @@ -355,3 +355,9 @@ unsafe extern "C" fn audio_cb_drain(data: *mut c_void) { (data.drain.as_ref().unwrap())(); } +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub struct TrackDescription { + pub id: i32, + pub name: Option, +} + diff --git a/src/video.rs b/src/video.rs index dc941f0..743163b 100644 --- a/src/video.rs +++ b/src/video.rs @@ -4,6 +4,7 @@ use ffi; use ::MediaPlayer; +use ::TrackDescription; use ::enums::VideoAdjustOption; use ::tools::{to_cstr, from_cstr}; use ::libc::c_void; @@ -22,6 +23,7 @@ pub trait MediaPlayerVideoEx { fn set_scale(&self, factor: f32); fn get_aspect_ratio(&self) -> Option; fn set_aspect_ratio(&self, aspect: Option<&str>); + fn get_video_track_description(&self) -> Option>; fn get_adjust_int(&self, option: VideoAdjustOption) -> i32; fn set_adjust_int(&self, option: VideoAdjustOption, value: i32); fn get_adjust_float(&self, option: VideoAdjustOption) -> f32; @@ -92,6 +94,21 @@ impl MediaPlayerVideoEx for MediaPlayer { } } } + fn get_video_track_description(&self) -> Option> { + unsafe{ + let p0 = ffi::libvlc_video_get_track_description(self.ptr); + if p0.is_null() { return None; } + let mut td = Vec::new(); + let mut p = p0; + + while !(*p).p_next.is_null() { + td.push(TrackDescription{ id: (*p).i_id, name: from_cstr((*p).psz_name) }); + p = (*p).p_next; + } + ffi::libvlc_track_description_list_release(p0); + Some(td) + } + } fn get_adjust_int(&self, option: VideoAdjustOption) -> i32 { unsafe{ ffi::libvlc_video_get_adjust_int(self.ptr, option as u32) } }