]> git.sesse.net Git - vlc/blob - src/control/video.c
Remove libvlc_set_video_drawable, libvlc_video_set_parent offers the same functionality
[vlc] / src / control / video.c
1 /*****************************************************************************
2  * video.c: libvlc new API video functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * $Id: core.c 14187 2006-02-07 16:37:40Z courmisch $
7  *
8  * Authors: Cl�ent Stenac <zorglub@videolan.org>
9  *          Filippo Carone <littlejohn@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #include <libvlc_internal.h>
27 #include <vlc/libvlc.h>
28
29 #include <vlc/vout.h>
30 #include <vlc/intf.h>
31
32 /*
33  * Remember to release the returned vout_thread_t since it is locked at
34  * the end of this function.
35  */
36 static vout_thread_t *GetVout( libvlc_input_t *p_input,
37                                libvlc_exception_t *p_exception )
38 {
39     input_thread_t *p_input_thread;
40     vout_thread_t *p_vout;
41
42     if( !p_input )
43     {
44         libvlc_exception_raise( p_exception, "Input is NULL" );
45         return NULL;
46     }
47
48     p_input_thread = (input_thread_t*)vlc_object_get(
49                                  p_input->p_instance->p_libvlc_int,
50                                  p_input->i_input_id );
51     if( !p_input_thread )
52     {
53         libvlc_exception_raise( p_exception, "Input does not exist" );
54         return NULL;
55     }
56
57     p_vout = vlc_object_find( p_input_thread, VLC_OBJECT_VOUT, FIND_CHILD );
58     if( !p_vout )
59     {
60         vlc_object_release( p_input_thread );
61         libvlc_exception_raise( p_exception, "No active video output" );
62         return NULL;
63     }
64     vlc_object_release( p_input_thread );
65
66     return p_vout;
67 }
68 /**********************************************************************
69  * Exported functions
70  **********************************************************************/
71
72 void libvlc_set_fullscreen( libvlc_input_t *p_input, int b_fullscreen,
73                             libvlc_exception_t *p_e )
74 {
75     /* We only work on the first vout */
76     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
77     vlc_value_t val; int i_ret;
78
79     /* GetVout will raise the exception for us */
80     if( !p_vout1 )
81     {
82         return;
83     }
84
85     if( b_fullscreen ) val.b_bool = VLC_TRUE;
86     else               val.b_bool = VLC_FALSE;
87
88     i_ret = var_Set( p_vout1, "fullscreen", val );
89     if( i_ret )
90         libvlc_exception_raise( p_e,
91                         "Unexpected error while setting fullscreen value" );
92
93     vlc_object_release( p_vout1 );
94 }
95
96 int libvlc_get_fullscreen( libvlc_input_t *p_input,
97                             libvlc_exception_t *p_e )
98 {
99     /* We only work on the first vout */
100     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
101     vlc_value_t val; int i_ret;
102
103     /* GetVout will raise the exception for us */
104     if( !p_vout1 )
105         return 0;
106
107     i_ret = var_Get( p_vout1, "fullscreen", &val );
108     if( i_ret )
109         libvlc_exception_raise( p_e,
110                         "Unexpected error while looking up fullscreen value" );
111
112     return val.b_bool == VLC_TRUE ? 1 : 0;
113 }
114
115 void libvlc_toggle_fullscreen( libvlc_input_t *p_input,
116                                libvlc_exception_t *p_e )
117 {
118     /* We only work on the first vout */
119     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
120     vlc_value_t val; int i_ret;
121
122     /* GetVout will raise the exception for us */
123     if( !p_vout1 )
124         return;
125
126     i_ret = var_Get( p_vout1, "fullscreen", &val );
127     if( i_ret )
128         libvlc_exception_raise( p_e,
129                         "Unexpected error while looking up fullscreen value" );
130
131     val.b_bool = !val.b_bool;
132     i_ret = var_Set( p_vout1, "fullscreen", val );
133     if( i_ret )
134         libvlc_exception_raise( p_e,
135                         "Unexpected error while setting fullscreen value" );
136
137     vlc_object_release( p_vout1 );
138 }
139
140 void
141 libvlc_video_take_snapshot( libvlc_input_t *p_input, char *psz_filepath,
142                        libvlc_exception_t *p_e )
143 {
144     vout_thread_t *p_vout = GetVout( p_input, p_e );
145     input_thread_t *p_input_thread;
146
147     char path[256];
148
149     /* GetVout will raise the exception for us */
150     if( !p_vout )
151     {
152         return;
153     }
154
155     p_input_thread = (input_thread_t*)vlc_object_get(
156                                  p_input->p_instance->p_libvlc_int,
157                                  p_input->i_input_id );
158     if( !p_input_thread )
159     {
160         libvlc_exception_raise( p_e, "Input does not exist" );
161         return;
162     }
163
164     snprintf( path, 255, "%s", psz_filepath );
165     var_SetString( p_vout, "snapshot-path", path );
166     var_SetString( p_vout, "snapshot-format", "png" );
167
168     vout_Control( p_vout, VOUT_SNAPSHOT );
169     vlc_object_release( p_vout );
170     vlc_object_release( p_input_thread );
171 }
172
173 int libvlc_video_get_height( libvlc_input_t *p_input,
174                              libvlc_exception_t *p_e ) 
175 {
176     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
177     if( !p_vout1 )
178         return 0;
179
180     vlc_object_release( p_vout1 );
181
182     return p_vout1->i_window_height;
183 }
184
185 int libvlc_video_get_width( libvlc_input_t *p_input,
186                             libvlc_exception_t *p_e ) 
187 {
188     vout_thread_t *p_vout1 = GetVout( p_input, p_e );
189     if( !p_vout1 )
190         return 0;
191
192     vlc_object_release( p_vout1 );
193
194     return p_vout1->i_window_width;
195 }
196
197 vlc_bool_t libvlc_input_has_vout( libvlc_input_t *p_input,
198                                   libvlc_exception_t *p_e )
199 {
200     vout_thread_t *p_vout = GetVout( p_input, p_e );
201
202     /* GetVout will raise the exception for us */
203     if( !p_vout )
204     {
205         return VLC_FALSE;
206     }
207
208     vlc_object_release( p_vout );
209
210     return VLC_TRUE;
211 }
212
213 int libvlc_video_reparent( libvlc_input_t *p_input, libvlc_drawable_t d,
214                            libvlc_exception_t *p_e )
215 {
216     vout_thread_t *p_vout = GetVout( p_input, p_e );
217
218     if ( p_vout == NULL)
219     {
220         /// \todo: set exception
221         return 0;
222     }
223     
224     vout_Control( p_vout , VOUT_REPARENT, d);
225     vlc_object_release( p_vout );
226
227     return 0;
228 }
229
230 void libvlc_video_resize( libvlc_input_t *p_input, int width, int height, libvlc_exception_t *p_e )
231 {
232     vout_thread_t *p_vout = GetVout( p_input, p_e );
233     vout_Control( p_vout, VOUT_SET_SIZE, width, height );
234     vlc_object_release( p_vout );
235 }
236
237 /* global video settings */
238
239 void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d,
240                               libvlc_exception_t *p_e )
241 {
242     /* set as default for future vout instances */
243     var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
244
245     if( libvlc_playlist_isplaying(p_instance, p_e) )
246     {
247         libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
248         if( p_input )
249         {
250             vout_thread_t *p_vout = GetVout( p_input, p_e );
251             if( p_vout )
252             {
253                 /* tell running vout to re-parent */
254                 vout_Control( p_vout , VOUT_REPARENT, d);
255                 vlc_object_release( p_vout );
256             }
257             libvlc_input_free(p_input);
258         }
259     }
260 }
261
262 void libvlc_video_set_size( libvlc_instance_t *p_instance, int width, int height,
263                            libvlc_exception_t *p_e )
264 {
265     /* set as default for future vout instances */
266     config_PutInt(p_instance->p_libvlc_int, "width", width);
267     config_PutInt(p_instance->p_libvlc_int, "height", height);
268
269     if( libvlc_playlist_isplaying(p_instance, p_e) )
270     {
271         libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
272         if( p_input )
273         {
274             vout_thread_t *p_vout = GetVout( p_input, p_e );
275             if( p_vout )
276             {
277                 /* tell running vout to re-size */
278                 vout_Control( p_vout , VOUT_SET_SIZE, width, height);
279                 vlc_object_release( p_vout );
280             }
281             libvlc_input_free(p_input);
282         }
283     }
284 }
285
286 void libvlc_video_set_viewport( libvlc_instance_t *p_instance,
287                             const libvlc_rectangle_t *view, const libvlc_rectangle_t *clip,
288                            libvlc_exception_t *p_e )
289 {
290     if( NULL == view )
291     {
292         libvlc_exception_raise( p_e, "viewport is NULL" );
293     }
294
295     /* if clip is NULL, then use view rectangle as clip */
296     if( NULL == clip )
297         clip = view;
298
299     /* set as default for future vout instances */
300     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-top", view->top );
301     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-left", view->left );
302     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-bottom", view->bottom );
303     var_SetInteger( p_instance->p_libvlc_int, "drawable-view-right", view->right );
304     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-top", clip->top );
305     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-left", clip->left );
306     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-bottom", clip->bottom );
307     var_SetInteger( p_instance->p_libvlc_int, "drawable-clip-right", clip->right );
308
309     if( libvlc_playlist_isplaying(p_instance, p_e) )
310     {
311         libvlc_input_t *p_input = libvlc_playlist_get_input(p_instance, p_e);
312         if( p_input )
313         {
314             vout_thread_t *p_vout = GetVout( p_input, p_e );
315             if( p_vout )
316             {
317                 /* change viewport for running vout */
318                 vout_Control( p_vout , VOUT_SET_VIEWPORT,
319                                    view->top, view->left, view->bottom, view->right,
320                                    clip->top, clip->left, clip->bottom, clip->right );
321                 vlc_object_release( p_vout );
322             }
323             libvlc_input_free(p_input);
324         }
325     }
326 }
327
328 char *libvlc_video_get_aspect_ratio( libvlc_input_t *p_input,
329                                    libvlc_exception_t *p_e )
330 {
331     char *psz_aspect = 0;
332     vout_thread_t *p_vout = GetVout( p_input, p_e );
333
334     if( !p_vout )
335         return 0;
336
337     psz_aspect = var_GetString( p_vout, "aspect-ratio" );
338     vlc_object_release( p_vout );
339     return psz_aspect;
340 }
341
342 void libvlc_video_set_aspect_ratio( libvlc_input_t *p_input,
343                                     char *psz_aspect, libvlc_exception_t *p_e )
344 {
345     vout_thread_t *p_vout = GetVout( p_input, p_e );
346     int i_ret = -1;
347
348     if( !p_vout )
349         return;
350
351     i_ret = var_SetString( p_vout, "aspect-ratio", psz_aspect );
352     if( i_ret )
353         libvlc_exception_raise( p_e,
354                         "Unexpected error while setting aspect-ratio value" );
355
356     vlc_object_release( p_vout );
357 }
358
359 int libvlc_video_destroy( libvlc_input_t *p_input,
360                           libvlc_exception_t *p_e )
361 {
362     vout_thread_t *p_vout = GetVout( p_input, p_e );
363     vlc_object_detach( p_vout ); 
364     vlc_object_release( p_vout );
365     vout_Destroy( p_vout );
366
367     return 0;
368 }