vlc/
video.rs

1// Copyright (c) 2015 T. Okubo
2// This file is part of vlc-rs.
3// Licensed under the MIT license, see the LICENSE file.
4
5use sys;
6use ::MediaPlayer;
7use ::TrackDescription;
8use ::enums::VideoAdjustOption;
9use ::tools::{to_cstr, from_cstr};
10use ::libc::c_void;
11
12pub trait MediaPlayerVideoEx {
13    fn toggle_fullscreen(&self);
14    fn set_fullscreen(&self, fullscreen: bool);
15    fn get_fullscreen(&self) -> bool;
16    fn set_key_input(&self, on: bool);
17    fn set_mouse_input(&self, on: bool);
18    fn get_size(&self, num: u32) -> Option<(u32, u32)>;
19    fn get_video_track(&self) -> Option<i32>;
20    fn set_video_track(&self, track: i32);
21    fn get_cursor(&self, num: u32) -> Option<(i32, i32)>;
22    fn get_scale(&self) -> f32;
23    fn set_scale(&self, factor: f32);
24    fn get_aspect_ratio(&self) -> Option<String>;
25    fn set_aspect_ratio(&self, aspect: Option<&str>);
26    fn get_video_track_description(&self) -> Option<Vec<TrackDescription>>;
27    fn get_adjust_int(&self, option: VideoAdjustOption) -> i32;
28    fn set_adjust_int(&self, option: VideoAdjustOption, value: i32);
29    fn get_adjust_float(&self, option: VideoAdjustOption) -> f32;
30    fn set_adjust_float(&self, option: VideoAdjustOption, value: f32);
31}
32
33impl MediaPlayerVideoEx for MediaPlayer {
34    fn toggle_fullscreen(&self) {
35        unsafe{ sys::libvlc_toggle_fullscreen(self.ptr); }
36    }
37    fn set_fullscreen(&self, fullscreen: bool) {
38        unsafe{ sys::libvlc_set_fullscreen(self.ptr, if fullscreen { 1 }else{ 0 }); }
39    }
40    fn get_fullscreen(&self) -> bool {
41        unsafe{ if sys::libvlc_get_fullscreen(self.ptr) == 0 { false }else{ true } }
42    }
43    fn set_key_input(&self, on: bool) {
44        unsafe{ sys::libvlc_video_set_key_input(self.ptr, if on { 1 }else{ 0 }); }
45    }
46    fn set_mouse_input(&self, on: bool) {
47        unsafe{ sys::libvlc_video_set_mouse_input(self.ptr, if on { 1 }else{ 0 }); }
48    }
49    fn get_size(&self, num: u32) -> Option<(u32, u32)> {
50        unsafe{
51            let mut x = 0;
52            let mut y = 0;
53            let res = sys::libvlc_video_get_size(self.ptr, num, &mut x, &mut y);
54            if res == -1 { None }else{ Some((x, y)) }
55        }
56    }
57    fn get_cursor(&self, num: u32) -> Option<(i32, i32)> {
58        unsafe{
59            let mut x = 0;
60            let mut y = 0;
61            let res = sys::libvlc_video_get_cursor(self.ptr, num, &mut x, &mut y);
62            if res == -1 { None }else{ Some((x, y)) }
63        }
64    }
65    fn get_scale(&self) -> f32 {
66        unsafe{ sys::libvlc_video_get_scale(self.ptr) }
67    }
68    fn set_scale(&self, factor: f32) {
69        unsafe{ sys::libvlc_video_set_scale(self.ptr, factor); }
70    }
71    fn get_video_track(&self) -> Option<i32> {
72        unsafe{
73            let track = sys::libvlc_video_get_track(self.ptr);
74            if track == -1 { None }else{ Some(track) }
75        }
76    }
77    fn set_video_track(&self, track: i32) {
78        unsafe{ sys::libvlc_video_set_track(self.ptr, track); }
79    }
80    fn get_aspect_ratio(&self) -> Option<String> {
81        unsafe{
82            let p = sys::libvlc_video_get_aspect_ratio(self.ptr);
83            let s = from_cstr(p);
84            if !p.is_null() { sys::libvlc_free(p as *mut c_void); }
85            s
86        }
87    }
88    fn set_aspect_ratio(&self, aspect: Option<&str>) {
89        unsafe{
90            if let Some(a) = aspect {
91                sys::libvlc_video_set_aspect_ratio(self.ptr, to_cstr(a).as_ptr());
92            }else{
93                sys::libvlc_video_set_aspect_ratio(self.ptr, ::std::ptr::null());
94            }
95        }
96    }
97    fn get_video_track_description(&self) -> Option<Vec<TrackDescription>> {
98        unsafe{
99            let p0 = sys::libvlc_video_get_track_description(self.ptr);
100            if p0.is_null() { return None; }
101            let mut td = Vec::new();
102            let mut p = p0;
103
104            while !(*p).p_next.is_null() {
105                td.push(TrackDescription{ id: (*p).i_id, name: from_cstr((*p).psz_name) });
106                p = (*p).p_next;
107            }
108            sys::libvlc_track_description_list_release(p0);
109            Some(td)
110        }
111    }
112    fn get_adjust_int(&self, option: VideoAdjustOption) -> i32 {
113        unsafe{ sys::libvlc_video_get_adjust_int(self.ptr, option as u32) }
114    }
115    fn set_adjust_int(&self, option: VideoAdjustOption, value: i32) {
116        unsafe{ sys::libvlc_video_set_adjust_int(self.ptr, option as u32, value); }
117    }
118    fn get_adjust_float(&self, option: VideoAdjustOption) -> f32 {
119        unsafe{ sys::libvlc_video_get_adjust_float(self.ptr, option as u32) }
120    }
121    fn set_adjust_float(&self, option: VideoAdjustOption, value: f32) {
122        unsafe{ sys::libvlc_video_set_adjust_float(self.ptr, option as u32, value); }
123    }
124}