2015-12-08 12:53:16 +00:00
|
|
|
// Copyright (c) 2015 T. Okubo
|
|
|
|
// This file is part of vlc-rs.
|
|
|
|
// Licensed under the MIT license, see the LICENSE file.
|
|
|
|
|
2019-11-15 12:31:53 +00:00
|
|
|
use crate::sys;
|
|
|
|
use crate::MediaPlayer;
|
|
|
|
use crate::TrackDescription;
|
|
|
|
use crate::enums::VideoAdjustOption;
|
|
|
|
use crate::tools::{to_cstr, from_cstr};
|
|
|
|
use libc::c_void;
|
2015-12-08 12:53:16 +00:00
|
|
|
|
|
|
|
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<i32>;
|
|
|
|
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);
|
2015-12-17 12:49:28 +00:00
|
|
|
fn get_aspect_ratio(&self) -> Option<String>;
|
|
|
|
fn set_aspect_ratio(&self, aspect: Option<&str>);
|
2015-12-19 02:23:20 +00:00
|
|
|
fn get_video_track_description(&self) -> Option<Vec<TrackDescription>>;
|
2015-12-08 12:53:16 +00:00
|
|
|
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) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_toggle_fullscreen(self.ptr); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn set_fullscreen(&self, fullscreen: bool) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_set_fullscreen(self.ptr, if fullscreen { 1 }else{ 0 }); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn get_fullscreen(&self) -> bool {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ if sys::libvlc_get_fullscreen(self.ptr) == 0 { false }else{ true } }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn set_key_input(&self, on: bool) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_set_key_input(self.ptr, if on { 1 }else{ 0 }); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn set_mouse_input(&self, on: bool) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_set_mouse_input(self.ptr, if on { 1 }else{ 0 }); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn get_size(&self, num: u32) -> Option<(u32, u32)> {
|
|
|
|
unsafe{
|
|
|
|
let mut x = 0;
|
|
|
|
let mut y = 0;
|
2018-02-27 13:52:21 +00:00
|
|
|
let res = sys::libvlc_video_get_size(self.ptr, num, &mut x, &mut y);
|
2015-12-08 12:53:16 +00:00
|
|
|
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;
|
2018-02-27 13:52:21 +00:00
|
|
|
let res = sys::libvlc_video_get_cursor(self.ptr, num, &mut x, &mut y);
|
2015-12-08 12:53:16 +00:00
|
|
|
if res == -1 { None }else{ Some((x, y)) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn get_scale(&self) -> f32 {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_get_scale(self.ptr) }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn set_scale(&self, factor: f32) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_set_scale(self.ptr, factor); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn get_video_track(&self) -> Option<i32> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let track = sys::libvlc_video_get_track(self.ptr);
|
2015-12-08 12:53:16 +00:00
|
|
|
if track == -1 { None }else{ Some(track) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn set_video_track(&self, track: i32) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_set_track(self.ptr, track); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
2015-12-17 12:49:28 +00:00
|
|
|
fn get_aspect_ratio(&self) -> Option<String> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let p = sys::libvlc_video_get_aspect_ratio(self.ptr);
|
2015-12-17 12:49:28 +00:00
|
|
|
let s = from_cstr(p);
|
2018-02-27 13:52:21 +00:00
|
|
|
if !p.is_null() { sys::libvlc_free(p as *mut c_void); }
|
2015-12-17 12:49:28 +00:00
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn set_aspect_ratio(&self, aspect: Option<&str>) {
|
|
|
|
unsafe{
|
|
|
|
if let Some(a) = aspect {
|
2018-02-27 13:52:21 +00:00
|
|
|
sys::libvlc_video_set_aspect_ratio(self.ptr, to_cstr(a).as_ptr());
|
2015-12-17 12:49:28 +00:00
|
|
|
}else{
|
2018-02-27 13:52:21 +00:00
|
|
|
sys::libvlc_video_set_aspect_ratio(self.ptr, ::std::ptr::null());
|
2015-12-17 12:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-19 02:23:20 +00:00
|
|
|
fn get_video_track_description(&self) -> Option<Vec<TrackDescription>> {
|
|
|
|
unsafe{
|
2018-02-27 13:52:21 +00:00
|
|
|
let p0 = sys::libvlc_video_get_track_description(self.ptr);
|
2015-12-19 02:23:20 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-02-27 13:52:21 +00:00
|
|
|
sys::libvlc_track_description_list_release(p0);
|
2015-12-19 02:23:20 +00:00
|
|
|
Some(td)
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 12:53:16 +00:00
|
|
|
fn get_adjust_int(&self, option: VideoAdjustOption) -> i32 {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_get_adjust_int(self.ptr, option as u32) }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn set_adjust_int(&self, option: VideoAdjustOption, value: i32) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_set_adjust_int(self.ptr, option as u32, value); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn get_adjust_float(&self, option: VideoAdjustOption) -> f32 {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_get_adjust_float(self.ptr, option as u32) }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
fn set_adjust_float(&self, option: VideoAdjustOption, value: f32) {
|
2018-02-27 13:52:21 +00:00
|
|
|
unsafe{ sys::libvlc_video_set_adjust_float(self.ptr, option as u32, value); }
|
2015-12-08 12:53:16 +00:00
|
|
|
}
|
|
|
|
}
|