]> git.sesse.net Git - vlc/blob - src/control/video.c
libvlc compile warnings resolved
[vlc] / src / control / video.c
1 /*****************************************************************************
2  * video.c: ibvlc new API video functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <libvlc_internal.h>
25 #include <vlc/libvlc.h>
26
27 #include <vlc/vout.h>
28 #include <vlc/intf.h>
29
30 static vout_thread_t *GetVout( libvlc_input_t *p_input,
31                                libvlc_exception_t *p_exception )
32 {
33     input_thread_t *p_input_thread;
34     vout_thread_t *p_vout;
35
36     if( !p_input )
37     {
38         libvlc_exception_raise( p_exception, "Input is NULL" );
39         return NULL;
40     }
41
42     p_input_thread = (input_thread_t*)vlc_object_get(
43                                  p_input->p_instance->p_vlc,
44                                  p_input->i_input_id );
45     if( !p_input_thread )
46     {
47         libvlc_exception_raise( p_exception, "Input does not exist" );
48         return NULL;
49     }
50
51     p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
52     if( !p_vout )
53     {
54         vlc_object_release( p_input_thread );
55         libvlc_exception_raise( p_exception, "No active video output" );
56         return NULL;
57     }
58     vlc_object_release( p_input_thread );
59     
60     return p_vout;
61 }
62 /**********************************************************************
63  * Exported functions
64  **********************************************************************/
65
66 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
67                             libvlc_exception_t *p_e )
68 {
69     /* We only work on the first vout */
70     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
71     vlc_value_t val; int i_ret;
72
73     /* GetVout will raise the exception for us */
74     if( !p_vout1 )
75     {
76         return;
77     }
78
79     if( b_fullscreen ) val.b_bool = VLC_TRUE;
80     else               val.b_bool = VLC_FALSE;
81
82     i_ret = var_Set( p_vout1, "fullscreen", val );
83     if( i_ret )
84         libvlc_exception_raise( p_e,
85                         "Unexpected error while setting fullscreen value" );
86
87     vlc_object_release( p_vout1 );
88
89 }
90
91 int libvlc_get_fullscreen( libvlc_input_t *p_input,
92                             libvlc_exception_t *p_e )
93 {
94     /* We only work on the first vout */
95     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
96     vlc_value_t val; int i_ret;
97
98     /* GetVout will raise the exception for us */
99     if( !p_vout1 )
100         return 0;
101
102     i_ret = var_Get( p_vout1, "fullscreen", &val );
103     if( i_ret )
104         libvlc_exception_raise( p_e,
105                         "Unexpected error while looking up fullscreen value" );
106
107     return val.b_bool == VLC_TRUE ? 1 : 0;
108 }
109
110 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
111                                libvlc_exception_t *p_e )
112 {
113     /* We only work on the first vout */
114     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
115     vlc_value_t val; int i_ret;
116
117     /* GetVout will raise the exception for us */
118     if( !p_vout1 )
119         return;
120
121     i_ret = var_Get( p_vout1, "fullscreen", &val );
122     if( i_ret )
123         libvlc_exception_raise( p_e,
124                         "Unexpected error while looking up fullscreen value" );
125
126     val.b_bool = !val.b_bool;
127     i_ret = var_Set( p_vout1, "fullscreen", val );
128     if( i_ret )
129         libvlc_exception_raise( p_e,
130                         "Unexpected error while setting fullscreen value" );
131
132     vlc_object_release( p_vout1 );
133
134 }
135
136 void
137 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
138                        libvlc_exception_t *p_e )
139 {
140     vout_thread_t *p_vout = GetVout( p_input, p_e );
141     input_thread_t *p_input_thread;
142     
143     char path[256];
144
145     /* GetVout will raise the exception for us */
146     if( !p_vout )
147     {
148         return;
149     }
150
151     p_input_thread = (input_thread_t*)vlc_object_get(
152                                  p_input->p_instance->p_vlc,
153                                  p_input->i_input_id );
154     if( !p_input_thread )
155     {
156         libvlc_exception_raise( p_e, "Input does not exist" );
157         return;
158     }
159    
160     snprintf( path, 255, "%s", psz_filepath );
161     var_SetString( p_vout, "snapshot-path", path );
162     var_SetString( p_vout, "snapshot-format", "png" );
163
164     vout_Control( p_vout, VOUT_SNAPSHOT );
165     vlc_object_release( p_vout );
166
167     return;
168     
169 }
170
171 int libvlc_video_get_height( libvlc_input_t *p_input,
172                              libvlc_exception_t *p_e ) 
173 {
174     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
175     if( !p_vout1 )
176         return 0;
177
178     vlc_object_release( p_vout1 );
179
180     return p_vout1->i_window_height;
181 }
182
183 int libvlc_video_get_width( libvlc_input_t *p_input,
184                             libvlc_exception_t *p_e ) 
185 {
186     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
187     if( !p_vout1 )
188         return 0;
189
190     vlc_object_release( p_vout1 );
191
192     return p_vout1->i_window_width;
193 }
194
195 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
196                                   libvlc_exception_t *p_e )
197 {
198     vout_thread_t *p_vout = GetVout( p_input, p_e );
199
200     /* GetVout will raise the exception for us */
201     if( !p_vout )
202     {
203         return VLC_FALSE;
204     }
205
206     vlc_object_release( p_vout );
207     
208     return VLC_TRUE;
209 }