From 8ec8ec48e2b27ba7aa751bc478508f3fc0fe4c43 Mon Sep 17 00:00:00 2001 From: "T. Okubo" Date: Tue, 8 Dec 2015 21:53:16 +0900 Subject: [PATCH] Add some video control functions as the MediaPlayerVideoEx trait --- src/enums.rs | 11 +++++++ src/ffi.rs | 12 +------- src/lib.rs | 3 +- src/video.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 src/video.rs diff --git a/src/enums.rs b/src/enums.rs index 80c6b5f..c957b60 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -76,6 +76,17 @@ pub enum Position { BottomRight, } +#[repr(C)] +#[derive(Clone, Copy, Debug)] +pub enum VideoAdjustOption { + Enable = 0, + Contrast, + Brightness, + Hue, + Saturation, + Gamma +} + // #[repr(C)] // #[derive(Clone, Copy, PartialEq, Eq, Debug)] // pub enum ParseFlag { diff --git a/src/ffi.rs b/src/ffi.rs index 3780167..a14bc8f 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -305,6 +305,7 @@ pub enum libvlc_navigate_mode_t { } pub use Position as libvlc_position_t; +pub use VideoAdjustOption as libvlc_video_adjust_option; #[repr(C)] #[derive(Clone, Copy, Debug)] @@ -319,17 +320,6 @@ pub enum libvlc_video_logo_option_t { libvlc_logo_position } -#[repr(C)] -#[derive(Clone, Copy, Debug)] -pub enum libvlc_video_adjust_option_t { - libvlc_adjust_Enable = 0, - libvlc_adjust_Contrast, - libvlc_adjust_Brightness, - libvlc_adjust_Hue, - libvlc_adjust_Saturation, - libvlc_adjust_Gamma -} - #[repr(C)] #[derive(Clone, Copy, Debug)] pub enum libvlc_audio_output_device_types_t { diff --git a/src/lib.rs b/src/lib.rs index 3a055a0..e286569 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ mod media_player; mod media_list; mod media_library; mod enums; +mod video; pub use enums::*; pub use core::*; @@ -20,4 +21,4 @@ pub use media::*; pub use media_player::*; pub use media_list::*; pub use media_library::*; - +pub use video::*; diff --git a/src/video.rs b/src/video.rs new file mode 100644 index 0000000..95244fe --- /dev/null +++ b/src/video.rs @@ -0,0 +1,86 @@ +// Copyright (c) 2015 T. Okubo +// This file is part of vlc-rs. +// Licensed under the MIT license, see the LICENSE file. + +use ffi; +use ::MediaPlayer; +use ::enums::VideoAdjustOption; + +pub trait MediaPlayerVideoEx { + fn toggle_fullscreen(&self); + fn set_fullscreen(&self, fullscreen: bool); + fn get_fullscreen(&self) -> bool; + fn set_key_input(&self, on: bool); + fn set_mouse_input(&self, on: bool); + fn get_size(&self, num: u32) -> Option<(u32, u32)>; + fn get_video_track(&self) -> Option; + fn set_video_track(&self, track: i32); + fn get_cursor(&self, num: u32) -> Option<(i32, i32)>; + fn get_scale(&self) -> f32; + fn set_scale(&self, factor: f32); + 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; + fn set_adjust_float(&self, option: VideoAdjustOption, value: f32); +} + +impl MediaPlayerVideoEx for MediaPlayer { + fn toggle_fullscreen(&self) { + unsafe{ ffi::libvlc_toggle_fullscreen(self.ptr); } + } + fn set_fullscreen(&self, fullscreen: bool) { + unsafe{ ffi::libvlc_set_fullscreen(self.ptr, if fullscreen { 1 }else{ 0 }); } + } + fn get_fullscreen(&self) -> bool { + unsafe{ if ffi::libvlc_get_fullscreen(self.ptr) == 0 { false }else{ true } } + } + fn set_key_input(&self, on: bool) { + unsafe{ ffi::libvlc_video_set_key_input(self.ptr, if on { 1 }else{ 0 }); } + } + fn set_mouse_input(&self, on: bool) { + unsafe{ ffi::libvlc_video_set_mouse_input(self.ptr, if on { 1 }else{ 0 }); } + } + fn get_size(&self, num: u32) -> Option<(u32, u32)> { + unsafe{ + let mut x = 0; + let mut y = 0; + let res = ffi::libvlc_video_get_size(self.ptr, num, &mut x, &mut y); + if res == -1 { None }else{ Some((x, y)) } + } + } + fn get_cursor(&self, num: u32) -> Option<(i32, i32)> { + unsafe{ + let mut x = 0; + let mut y = 0; + let res = ffi::libvlc_video_get_cursor(self.ptr, num, &mut x, &mut y); + if res == -1 { None }else{ Some((x, y)) } + } + } + fn get_scale(&self) -> f32 { + unsafe{ ffi::libvlc_video_get_scale(self.ptr) } + } + fn set_scale(&self, factor: f32) { + unsafe{ ffi::libvlc_video_set_scale(self.ptr, factor); } + } + fn get_video_track(&self) -> Option { + unsafe{ + let track = ffi::libvlc_video_get_track(self.ptr); + if track == -1 { None }else{ Some(track) } + } + } + fn set_video_track(&self, track: i32) { + unsafe{ ffi::libvlc_video_set_track(self.ptr, track); } + } + fn get_adjust_int(&self, option: VideoAdjustOption) -> i32 { + unsafe{ ffi::libvlc_video_get_adjust_int(self.ptr, option as u32) } + } + fn set_adjust_int(&self, option: VideoAdjustOption, value: i32) { + unsafe{ ffi::libvlc_video_set_adjust_int(self.ptr, option as u32, value); } + } + fn get_adjust_float(&self, option: VideoAdjustOption) -> f32 { + unsafe{ ffi::libvlc_video_get_adjust_float(self.ptr, option as u32) } + } + fn set_adjust_float(&self, option: VideoAdjustOption, value: f32) { + unsafe{ ffi::libvlc_video_set_adjust_float(self.ptr, option as u32, value); } + } +}