]> git.sesse.net Git - vlc/blob - src/video_output/vout_intf.c
For consistency, remove references to vlc from libvlc
[vlc] / src / video_output / vout_intf.c
1 /*****************************************************************************
2  * vout_intf.c : video output interface
3  *****************************************************************************
4  * Copyright (C) 2000-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #include <vlc/vlc.h>
29
30 #include <stdio.h>
31 #include <stdlib.h>                                                /* free() */
32 #include <sys/types.h>                                          /* opendir() */
33 #include <dirent.h>                                             /* opendir() */
34
35 #include <vlc/intf.h>
36 #include <vlc_block.h>
37
38 #include "vlc_video.h"
39 #include "video_output.h"
40 #include "vlc_image.h"
41 #include "vlc_spu.h"
42
43 #include <snapshot.h>
44
45 /*****************************************************************************
46  * Local prototypes
47  *****************************************************************************/
48 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
49
50 /* Object variables callbacks */
51 static int ZoomCallback( vlc_object_t *, char const *,
52                          vlc_value_t, vlc_value_t, void * );
53 static int CropCallback( vlc_object_t *, char const *,
54                          vlc_value_t, vlc_value_t, void * );
55 static int AspectCallback( vlc_object_t *, char const *,
56                            vlc_value_t, vlc_value_t, void * );
57 static int OnTopCallback( vlc_object_t *, char const *,
58                           vlc_value_t, vlc_value_t, void * );
59 static int FullscreenCallback( vlc_object_t *, char const *,
60                                vlc_value_t, vlc_value_t, void * );
61 static int SnapshotCallback( vlc_object_t *, char const *,
62                              vlc_value_t, vlc_value_t, void * );
63
64 /*****************************************************************************
65  * vout_RequestWindow: Create/Get a video window if possible.
66  *****************************************************************************
67  * This function looks for the main interface and tries to request
68  * a new video window. If it fails then the vout will still need to create the
69  * window by itself.
70  *****************************************************************************/
71 void *vout_RequestWindow( vout_thread_t *p_vout,
72                           int *pi_x_hint, int *pi_y_hint,
73                           unsigned int *pi_width_hint,
74                           unsigned int *pi_height_hint )
75 {
76     intf_thread_t *p_intf = NULL;
77     vlc_list_t *p_list;
78     void *p_window;
79     vlc_value_t val;
80     int i;
81
82     /* Small kludge */
83     if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
84
85     /* Get requested coordinates */
86     var_Get( p_vout, "video-x", &val );
87     *pi_x_hint = val.i_int ;
88     var_Get( p_vout, "video-y", &val );
89     *pi_y_hint = val.i_int;
90
91     *pi_width_hint = p_vout->i_window_width;
92     *pi_height_hint = p_vout->i_window_height;
93
94     /* Check whether someone provided us with a window ID */
95     var_Get( p_vout->p_libvlc, "drawable", &val );
96     if( val.i_int ) return (void *)val.i_int;
97
98     /* Find if the main interface supports embedding */
99     p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
100     if( !p_list ) return NULL;
101
102     for( i = 0; i < p_list->i_count; i++ )
103     {
104         p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
105         if( p_intf->b_block && p_intf->pf_request_window ) break;
106         p_intf = NULL;
107     }
108
109     if( !p_intf )
110     {
111         vlc_list_release( p_list );
112         return NULL;
113     }
114
115     vlc_object_yield( p_intf );
116     vlc_list_release( p_list );
117
118     p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
119                                           pi_width_hint, pi_height_hint );
120
121     if( !p_window ) vlc_object_release( p_intf );
122     else p_vout->p_parent_intf = p_intf;
123
124     return p_window;
125 }
126
127 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
128 {
129     intf_thread_t *p_intf = p_vout->p_parent_intf;
130
131     if( !p_intf ) return;
132
133     vlc_mutex_lock( &p_intf->object_lock );
134     if( p_intf->b_dead )
135     {
136         vlc_mutex_unlock( &p_intf->object_lock );
137         return;
138     }
139
140     if( !p_intf->pf_release_window )
141     {
142         msg_Err( p_vout, "no pf_release_window");
143         vlc_mutex_unlock( &p_intf->object_lock );
144         vlc_object_release( p_intf );
145         return;
146     }
147
148     p_intf->pf_release_window( p_intf, p_window );
149
150     p_vout->p_parent_intf = NULL;
151     vlc_mutex_unlock( &p_intf->object_lock );
152     vlc_object_release( p_intf );
153 }
154
155 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
156                         int i_query, va_list args )
157 {
158     intf_thread_t *p_intf = p_vout->p_parent_intf;
159     int i_ret;
160
161     if( !p_intf ) return VLC_EGENERIC;
162
163     vlc_mutex_lock( &p_intf->object_lock );
164     if( p_intf->b_dead )
165     {
166         vlc_mutex_unlock( &p_intf->object_lock );
167         return VLC_EGENERIC;
168     }
169
170     if( !p_intf->pf_control_window )
171     {
172         msg_Err( p_vout, "no pf_control_window");
173         vlc_mutex_unlock( &p_intf->object_lock );
174         return VLC_EGENERIC;
175     }
176
177     i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
178     vlc_mutex_unlock( &p_intf->object_lock );
179     return i_ret;
180 }
181
182 /*****************************************************************************
183  * vout_IntfInit: called during the vout creation to initialise misc things.
184  *****************************************************************************/
185 void vout_IntfInit( vout_thread_t *p_vout )
186 {
187     vlc_value_t val, text, old_val;
188     vlc_bool_t b_force_par = VLC_FALSE;
189     char *psz_buf;
190
191     /* Create a few object variables we'll need later on */
192     var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
193     var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
194     var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
195     var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
196     var_Create( p_vout, "snapshot-sequential",
197                 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
198     var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
199     var_SetInteger( p_vout, "snapshot-num", 1 );
200
201     var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
202     var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
203     var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
204     var_Get( p_vout, "align", &val );
205     p_vout->i_alignment = val.i_int;
206
207     var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
208     var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
209
210     /* Zoom object var */
211     var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
212                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
213
214     text.psz_string = _("Zoom");
215     var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
216
217     var_Get( p_vout, "zoom", &old_val );
218     if( old_val.f_float == 0.25 ||
219         old_val.f_float == 0.5 ||
220         old_val.f_float == 1 ||
221         old_val.f_float == 2 )
222     {
223         var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
224     }
225
226     val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
227     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
228     val.f_float = 0.5; text.psz_string = _("1:2 Half");
229     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
230     val.f_float = 1; text.psz_string = _("1:1 Original");
231     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
232     val.f_float = 2; text.psz_string = _("2:1 Double");
233     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
234
235     var_Set( p_vout, "zoom", old_val );
236
237     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
238
239     /* Crop offset vars */
240     var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
241     var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
242     var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
243     var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
244
245     var_SetInteger( p_vout, "crop-left", 0 );
246     var_SetInteger( p_vout, "crop-top", 0 );
247     var_SetInteger( p_vout, "crop-right", 0 );
248     var_SetInteger( p_vout, "crop-bottom", 0 );
249
250     var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
251     var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
252     var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
253     var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
254
255     /* Crop object var */
256     var_Create( p_vout, "crop", VLC_VAR_STRING |
257                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
258
259     text.psz_string = _("Crop");
260     var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
261
262     val.psz_string = "";
263     var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
264     val.psz_string = ""; text.psz_string = _("Default");
265     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
266     val.psz_string = "1:1"; text.psz_string = "1:1";
267     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
268     val.psz_string = "4:3"; text.psz_string = "4:3";
269     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
270     val.psz_string = "16:9"; text.psz_string = "16:9";
271     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
272     val.psz_string = "16:10"; text.psz_string = "16:10";
273     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
274     val.psz_string = "221:100"; text.psz_string = "221:100";
275     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
276     val.psz_string = "5:4"; text.psz_string = "5:4";
277     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
278
279     /* Add custom crop ratios */
280     psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
281     if( psz_buf && *psz_buf )
282     {
283         char *psz_cur = psz_buf;
284         char *psz_next;
285         while( psz_cur && *psz_cur )
286         {
287             psz_next = strchr( psz_cur, ',' );
288             if( psz_next )
289             {
290                 *psz_next = '\0';
291                 psz_next++;
292             }
293             val.psz_string = strdup( psz_cur );
294             text.psz_string = strdup( psz_cur );
295             var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text);
296             free( val.psz_string );
297             free( text.psz_string );
298             psz_cur = psz_next;
299         }
300     }
301     if( psz_buf ) free( psz_buf );
302
303     var_AddCallback( p_vout, "crop", CropCallback, NULL );
304     var_Get( p_vout, "crop", &old_val );
305     if( old_val.psz_string && *old_val.psz_string )
306         var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
307     if( old_val.psz_string ) free( old_val.psz_string );
308
309     /* Monitor pixel aspect-ratio */
310     var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
311     var_Get( p_vout, "monitor-par", &val );
312     if( val.psz_string && *val.psz_string )
313     {
314         char *psz_parser = strchr( val.psz_string, ':' );
315         unsigned int i_aspect_num = 0, i_aspect_den = 0;
316         float i_aspect = 0;
317         if( psz_parser )
318         {
319             i_aspect_num = strtol( val.psz_string, 0, 10 );
320             i_aspect_den = strtol( ++psz_parser, 0, 10 );
321         }
322         else
323         {
324             i_aspect = atof( val.psz_string );
325             vlc_ureduce( &i_aspect_num, &i_aspect_den,
326                          i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
327         }
328         if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
329
330         p_vout->i_par_num = i_aspect_num;
331         p_vout->i_par_den = i_aspect_den;
332
333         vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
334                      p_vout->i_par_num, p_vout->i_par_den, 0 );
335
336         msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
337                  p_vout->i_par_num, p_vout->i_par_den );
338         b_force_par = VLC_TRUE;
339     }
340     if( val.psz_string ) free( val.psz_string );
341
342     /* Aspect-ratio object var */
343     var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
344                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
345
346     text.psz_string = _("Aspect-ratio");
347     var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
348
349     val.psz_string = "";
350     var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
351     val.psz_string = ""; text.psz_string = _("Default");
352     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
353     val.psz_string = "1:1"; text.psz_string = "1:1";
354     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
355     val.psz_string = "4:3"; text.psz_string = "4:3";
356     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
357     val.psz_string = "16:9"; text.psz_string = "16:9";
358     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
359     val.psz_string = "16:10"; text.psz_string = "16:10";
360     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
361     val.psz_string = "221:100"; text.psz_string = "221:100";
362     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
363     val.psz_string = "5:4"; text.psz_string = "5:4";
364     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
365
366     /* Add custom aspect ratios */
367     psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
368     if( psz_buf && *psz_buf )
369     {
370         char *psz_cur = psz_buf;
371         char *psz_next;
372         while( psz_cur && *psz_cur )
373         {
374             psz_next = strchr( psz_cur, ',' );
375             if( psz_next )
376             {
377                 *psz_next = '\0';
378                 psz_next++;
379             }
380             val.psz_string = strdup( psz_cur );
381             text.psz_string = strdup( psz_cur );
382             var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text);
383             free( val.psz_string );
384             free( text.psz_string );
385             psz_cur = psz_next;
386         }
387     }
388     if( psz_buf ) free( psz_buf );
389
390     var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
391     var_Get( p_vout, "aspect-ratio", &old_val );
392     if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
393         var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
394     if( old_val.psz_string ) free( old_val.psz_string );
395
396     /* Initialize the dimensions of the video window */
397     InitWindowSize( p_vout, &p_vout->i_window_width,
398                     &p_vout->i_window_height );
399
400     /* Add a variable to indicate if the window should be on top of others */
401     var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
402     text.psz_string = _("Always on top");
403     var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
404     var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
405
406     /* Add a variable to indicate whether we want window decoration or not */
407     var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
408
409     /* Add a fullscreen variable */
410     var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
411     text.psz_string = _("Fullscreen");
412     var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
413     var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
414     if( val.b_bool )
415     {
416         /* user requested fullscreen */
417         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
418     }
419     var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
420
421     /* Add a snapshot variable */
422     var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
423     text.psz_string = _("Snapshot");
424     var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
425     var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
426
427     /* Mouse coordinates */
428     var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
429     var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
430     var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
431     var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
432     var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
433
434     var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
435     val.b_bool = VLC_TRUE;
436     var_Set( p_vout, "intf-change", val );
437 }
438
439 /*****************************************************************************
440  * vout_Snapshot: generates a snapshot.
441  *****************************************************************************/
442 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
443 {
444     image_handler_t *p_image = image_HandlerCreate( p_vout );
445     video_format_t fmt_in = {0}, fmt_out = {0};
446     char *psz_filename = NULL;
447     subpicture_t *p_subpic;
448     picture_t *p_pif;
449     vlc_value_t val, format;
450     DIR *path;
451
452     int i_ret;
453
454     var_Get( p_vout, "snapshot-path", &val );
455     if( val.psz_string && !*val.psz_string )
456     {
457         free( val.psz_string );
458         val.psz_string = 0;
459     }
460
461     /* Embedded snapshot : if snapshot-path == object:object-id, then
462        create a snapshot_t* and store it in
463        object(object-id)->p_private, then unlock and signal the
464        waiting object.
465      */
466     if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
467     {
468         int i_id;
469         vlc_object_t* p_dest;
470         block_t *p_block;
471         snapshot_t *p_snapshot;
472         int i_size;
473
474         /* Destination object-id is following object: */
475         i_id = atoi( &val.psz_string[7] );
476         p_dest = ( vlc_object_t* )vlc_current_object( i_id );
477         if( !p_dest )
478         {
479             msg_Err( p_vout, "Cannot find calling object" );
480             image_HandlerDelete( p_image );
481             return VLC_EGENERIC;
482         }
483         /* Object must be locked. We will unlock it once we get the
484            snapshot and written it to p_private */
485         p_dest->p_private = NULL;
486
487         /* Save the snapshot to a memory zone */
488         fmt_in = p_vout->fmt_in;
489         fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
490         /* FIXME: should not be hardcoded. We should be able to
491         specify the snapshot size (snapshot-width and snapshot-height). */
492         fmt_out.i_width = 320;
493         fmt_out.i_height = 200;
494         fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
495         p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
496         if( !p_block )
497         {
498             msg_Err( p_vout, "Could not get snapshot" );
499             image_HandlerDelete( p_image );
500             vlc_cond_signal( &p_dest->object_wait );
501             vlc_mutex_unlock( &p_dest->object_lock );
502             vlc_object_release( p_dest );
503             return VLC_EGENERIC;
504         }
505
506         /* Copy the p_block data to a snapshot structure */
507         /* FIXME: get the timestamp */
508         p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
509         if( !p_snapshot )
510         {
511             block_Release( p_block );
512             image_HandlerDelete( p_image );
513             vlc_cond_signal( &p_dest->object_wait );
514             vlc_mutex_unlock( &p_dest->object_lock );
515             vlc_object_release( p_dest );
516             return VLC_ENOMEM;
517         }
518
519         i_size = p_block->i_buffer;
520
521         p_snapshot->i_width = fmt_out.i_width;
522         p_snapshot->i_height = fmt_out.i_height;
523         p_snapshot->i_datasize = i_size;
524         p_snapshot->date = p_block->i_pts; /* FIXME ?? */
525         p_snapshot->p_data = ( char* ) malloc( i_size );
526         if( !p_snapshot->p_data )
527         {
528             block_Release( p_block );
529             free( p_snapshot );
530             image_HandlerDelete( p_image );
531             vlc_cond_signal( &p_dest->object_wait );
532             vlc_mutex_unlock( &p_dest->object_lock );
533             vlc_object_release( p_dest );
534             return VLC_ENOMEM;
535         }
536         memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
537
538         p_dest->p_private = p_snapshot;
539
540         block_Release( p_block );
541
542         /* Unlock the object */
543         vlc_cond_signal( &p_dest->object_wait );
544         vlc_mutex_unlock( &p_dest->object_lock );
545         vlc_object_release( p_dest );
546
547         image_HandlerDelete( p_image );
548         return VLC_SUCCESS;
549     }
550
551
552 #if defined(__APPLE__) || defined(SYS_BEOS)
553     if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
554     {
555         asprintf( &val.psz_string, "%s/Desktop",
556                   p_vout->p_libvlc->psz_homedir );
557     }
558
559 #elif defined(WIN32) && !defined(UNDER_CE)
560     if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
561     {
562         /* Get the My Pictures folder path */
563
564         char *p_mypicturesdir = NULL;
565         typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
566                                                    LPSTR );
567         #ifndef CSIDL_FLAG_CREATE
568         #   define CSIDL_FLAG_CREATE 0x8000
569         #endif
570         #ifndef CSIDL_MYPICTURES
571         #   define CSIDL_MYPICTURES 0x27
572         #endif
573         #ifndef SHGFP_TYPE_CURRENT
574         #   define SHGFP_TYPE_CURRENT 0
575         #endif
576
577         HINSTANCE shfolder_dll;
578         SHGETFOLDERPATH SHGetFolderPath ;
579
580         /* load the shfolder dll to retrieve SHGetFolderPath */
581         if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
582         {
583             SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
584                                                       _T("SHGetFolderPathA") );
585             if( SHGetFolderPath != NULL )
586             {
587                 p_mypicturesdir = (char *)malloc( MAX_PATH );
588                 if( p_mypicturesdir ) 
589                 {
590
591                     if( S_OK != SHGetFolderPath( NULL,
592                                         CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
593                                         NULL, SHGFP_TYPE_CURRENT,
594                                         p_mypicturesdir ) )
595                     {
596                         free( p_mypicturesdir );
597                         p_mypicturesdir = NULL;
598                     }
599                 }
600             }
601             FreeLibrary( shfolder_dll );
602         }
603
604         if( p_mypicturesdir == NULL )
605         {
606             asprintf( &val.psz_string, "%s/" CONFIG_DIR,
607                       p_vout->p_libvlc->psz_homedir );
608         }
609         else
610         {
611             asprintf( &val.psz_string, p_mypicturesdir );
612             free( p_mypicturesdir );
613         }
614     }
615
616 #else
617     if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
618     {
619         asprintf( &val.psz_string, "%s/" CONFIG_DIR,
620                   p_vout->p_libvlc->psz_homedir );
621     }
622 #endif
623
624     if( !val.psz_string )
625     {
626         msg_Err( p_vout, "no path specified for snapshots" );
627         return VLC_EGENERIC;
628     }
629     var_Get( p_vout, "snapshot-format", &format );
630     if( !format.psz_string || !*format.psz_string )
631     {
632         if( format.psz_string ) free( format.psz_string );
633         format.psz_string = strdup( "png" );
634     }
635
636     /*
637      * Did the user specify a directory? If not, path = NULL.
638      */
639     path = opendir ( (const char *)val.psz_string  );
640
641     if ( path != NULL )
642     {
643         char *psz_prefix = var_GetString( p_vout, "snapshot-prefix" );
644         if( !psz_prefix ) psz_prefix = strdup( "vlcsnap-" );
645
646         closedir( path );
647         if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
648         {
649             int i_num = var_GetInteger( p_vout, "snapshot-num" );
650             FILE *p_file;
651             do
652             {
653                 asprintf( &psz_filename, "%s/%s%05d.%s", val.psz_string,
654                           psz_prefix, i_num++, format.psz_string );
655             }
656             while( ( p_file = fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
657             var_SetInteger( p_vout, "snapshot-num", i_num );
658         }
659         else
660         {
661             asprintf( &psz_filename, "%s/%s%u.%s", val.psz_string,
662                       psz_prefix,
663                       (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
664                       format.psz_string );
665         }
666
667         free( psz_prefix );
668     }
669     else // The user specified a full path name (including file name)
670     {
671         asprintf ( &psz_filename, "%s", val.psz_string );
672     }
673
674     free( val.psz_string );
675     free( format.psz_string );
676
677     /* Save the snapshot */
678     fmt_in = p_vout->fmt_in;
679     fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
680     i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
681     if( i_ret != VLC_SUCCESS )
682     {
683         msg_Err( p_vout, "could not create snapshot %s", psz_filename );
684         free( psz_filename );
685         image_HandlerDelete( p_image );
686         return VLC_EGENERIC;
687     }
688
689     msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
690     vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
691                      "%s", psz_filename );
692     free( psz_filename );
693
694     if( var_GetBool( p_vout, "snapshot-preview" ) )
695     {
696         /* Inject a subpicture with the snapshot */
697         memset( &fmt_out, 0, sizeof(fmt_out) );
698         fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
699         p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
700         image_HandlerDelete( p_image );
701         if( !p_pif ) return VLC_EGENERIC;
702
703         p_subpic = spu_CreateSubpicture( p_vout->p_spu );
704         if( p_subpic == NULL )
705         {
706              p_pif->pf_release( p_pif );
707              return VLC_EGENERIC;
708         }
709
710         p_subpic->i_channel = 0;
711         p_subpic->i_start = mdate();
712         p_subpic->i_stop = mdate() + 4000000;
713         p_subpic->b_ephemer = VLC_TRUE;
714         p_subpic->b_fade = VLC_TRUE;
715         p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
716         p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
717
718         p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
719         vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
720                           p_pif );
721         p_pif->pf_release( p_pif );
722
723         spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
724     }
725     else
726     {
727         image_HandlerDelete( p_image );
728     }
729
730     return VLC_SUCCESS;
731 }
732
733 /*****************************************************************************
734  * Handle filters
735  *****************************************************************************/
736
737 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
738                         vlc_bool_t b_add, vlc_bool_t b_setconfig )
739 {
740     char *psz_parser;
741     char *psz_string = config_GetPsz( p_vout, "vout-filter" );
742
743     /* Todo : Use some generic chain manipulation functions */
744     if( !psz_string ) psz_string = strdup("");
745
746     psz_parser = strstr( psz_string, psz_name );
747     if( b_add )
748     {
749         if( !psz_parser )
750         {
751             psz_parser = psz_string;
752             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
753                             psz_string, psz_name );
754             free( psz_parser );
755         }
756         else
757             return;
758     }
759     else
760     {
761         if( psz_parser )
762         {
763             memmove( psz_parser, psz_parser + strlen(psz_name) +
764                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
765                             strlen(psz_parser + strlen(psz_name)) + 1 );
766
767             /* Remove trailing : : */
768             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
769             {
770                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
771             }
772          }
773          else
774          {
775              free( psz_string );
776              return;
777          }
778     }
779     if( b_setconfig )
780         config_PutPsz( p_vout, "vout-filter", psz_string );
781
782     var_SetString( p_vout, "vout-filter", psz_string );
783     free( psz_string );
784 }
785
786 /*****************************************************************************
787  * vout_ControlDefault: default methods for video output control.
788  *****************************************************************************/
789 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
790 {
791     switch( i_query )
792     {
793     case VOUT_REPARENT:
794     case VOUT_CLOSE:
795         if( p_vout->p_parent_intf )
796         {
797             vlc_object_release( p_vout->p_parent_intf );
798             p_vout->p_parent_intf = NULL;
799         }
800         return VLC_SUCCESS;
801         break;
802
803     case VOUT_SNAPSHOT:
804         p_vout->b_snapshot = VLC_TRUE;
805         return VLC_SUCCESS;
806         break;
807
808     default:
809         msg_Dbg( p_vout, "control query not supported" );
810         return VLC_EGENERIC;
811     }
812 }
813
814 /*****************************************************************************
815  * InitWindowSize: find the initial dimensions the video window should have.
816  *****************************************************************************
817  * This function will check the "width", "height" and "zoom" config options and
818  * will calculate the size that the video window should have.
819  *****************************************************************************/
820 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
821                             unsigned *pi_height )
822 {
823     vlc_value_t val;
824     int i_width, i_height;
825     uint64_t ll_zoom;
826
827 #define FP_FACTOR 1000                             /* our fixed point factor */
828
829     var_Get( p_vout, "width", &val );
830     i_width = val.i_int;
831     var_Get( p_vout, "height", &val );
832     i_height = val.i_int;
833     var_Get( p_vout, "zoom", &val );
834     ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
835
836     if( i_width > 0 && i_height > 0)
837     {
838         *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
839         *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
840         goto initwsize_end;
841     }
842     else if( i_width > 0 )
843     {
844         *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
845         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
846             p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
847             FP_FACTOR / p_vout->fmt_in.i_visible_width );
848         goto initwsize_end;
849     }
850     else if( i_height > 0 )
851     {
852         *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
853         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
854             p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
855             FP_FACTOR / p_vout->fmt_in.i_visible_height );
856         goto initwsize_end;
857     }
858
859     if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
860     {
861         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
862             p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
863         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom 
864             / FP_FACTOR );
865     }
866     else
867     {
868         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom 
869             / FP_FACTOR );
870         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
871             p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
872     }
873
874 initwsize_end:
875     msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width, 
876              p_vout->i_window_height );
877
878 #undef FP_FACTOR
879 }
880
881 /*****************************************************************************
882  * Object variables callbacks
883  *****************************************************************************/
884 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
885                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
886 {
887     vout_thread_t *p_vout = (vout_thread_t *)p_this;
888     InitWindowSize( p_vout, &p_vout->i_window_width,
889                     &p_vout->i_window_height );
890     vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
891                   p_vout->i_window_height );
892     return VLC_SUCCESS;
893 }
894
895 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
896                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
897 {
898     vout_thread_t *p_vout = (vout_thread_t *)p_this;
899     int64_t i_aspect_num, i_aspect_den;
900     unsigned int i_width, i_height;
901
902     /* Restore defaults */
903     p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
904     p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
905     p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
906     p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
907
908     if( !strcmp( psz_cmd, "crop" ) )
909     {
910         char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
911         if( psz_parser )
912         {
913             /* We're using the 3:4 syntax */
914             i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
915             if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
916
917             i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
918             if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
919
920             i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
921                 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
922             i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
923                 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
924
925             if( i_width < p_vout->fmt_render.i_visible_width )
926             {
927                 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
928                     (p_vout->fmt_render.i_visible_width - i_width) / 2;
929                 p_vout->fmt_in.i_visible_width = i_width;
930             }
931             else
932             {
933                 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
934                     (p_vout->fmt_render.i_visible_height - i_height) / 2;
935                 p_vout->fmt_in.i_visible_height = i_height;
936             }
937         }
938         else
939         {
940             psz_parser = strchr( newval.psz_string, 'x' );
941             if( psz_parser )
942             {
943                 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
944                 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
945
946                 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
947                 if( psz_end != psz_parser ) goto crop_end;
948
949                 psz_parser = strchr( ++psz_end, '+' );
950                 i_crop_height = strtol( psz_end, &psz_end, 10 );
951                 if( psz_end != psz_parser ) goto crop_end;
952
953                 psz_parser = strchr( ++psz_end, '+' );
954                 i_crop_left = strtol( psz_end, &psz_end, 10 );
955                 if( psz_end != psz_parser ) goto crop_end;
956
957                 psz_end++;
958                 i_crop_top = strtol( psz_end, &psz_end, 10 );
959                 if( *psz_end != '\0' ) goto crop_end;
960
961                 i_width = i_crop_width;
962                 p_vout->fmt_in.i_visible_width = i_width;
963
964                 i_height = i_crop_height;
965                 p_vout->fmt_in.i_visible_height = i_height;
966
967                 p_vout->fmt_in.i_x_offset = i_crop_left;
968                 p_vout->fmt_in.i_y_offset = i_crop_top;
969             }
970             else
971             {
972                 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
973                 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
974
975                 psz_parser = strchr( newval.psz_string, '+' );
976                 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
977                 if( psz_end != psz_parser ) goto crop_end;
978
979                 psz_parser = strchr( ++psz_end, '+' );
980                 i_crop_top = strtol( psz_end, &psz_end, 10 );
981                 if( psz_end != psz_parser ) goto crop_end;
982
983                 psz_parser = strchr( ++psz_end, '+' );
984                 i_crop_right = strtol( psz_end, &psz_end, 10 );
985                 if( psz_end != psz_parser ) goto crop_end;
986
987                 psz_end++;
988                 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
989                 if( *psz_end != '\0' ) goto crop_end;
990
991                 i_width = p_vout->fmt_render.i_visible_width
992                           - i_crop_left - i_crop_right;
993                 p_vout->fmt_in.i_visible_width = i_width;
994
995                 i_height = p_vout->fmt_render.i_visible_height
996                            - i_crop_top - i_crop_bottom;
997                 p_vout->fmt_in.i_visible_height = i_height;
998
999                 p_vout->fmt_in.i_x_offset = i_crop_left;
1000                 p_vout->fmt_in.i_y_offset = i_crop_top;
1001             }
1002         }
1003     }
1004     else if( !strcmp( psz_cmd, "crop-top" )
1005           || !strcmp( psz_cmd, "crop-left" )
1006           || !strcmp( psz_cmd, "crop-bottom" )
1007           || !strcmp( psz_cmd, "crop-right" ) )
1008     {
1009         unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1010
1011         i_crop_top = var_GetInteger( p_vout, "crop-top" );
1012         i_crop_left = var_GetInteger( p_vout, "crop-left" );
1013         i_crop_right = var_GetInteger( p_vout, "crop-right" );
1014         i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1015
1016         i_width = p_vout->fmt_render.i_visible_width
1017                   - i_crop_left - i_crop_right;
1018         p_vout->fmt_in.i_visible_width = i_width;
1019
1020         i_height = p_vout->fmt_render.i_visible_height
1021                    - i_crop_top - i_crop_bottom;
1022         p_vout->fmt_in.i_visible_height = i_height;
1023
1024         p_vout->fmt_in.i_x_offset = i_crop_left;
1025         p_vout->fmt_in.i_y_offset = i_crop_top;
1026     }
1027
1028  crop_end:
1029     InitWindowSize( p_vout, &p_vout->i_window_width,
1030                     &p_vout->i_window_height );
1031
1032     p_vout->i_changes |= VOUT_CROP_CHANGE;
1033
1034     msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1035              p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1036              p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1037              p_vout->fmt_in.i_visible_width,
1038              p_vout->fmt_in.i_visible_height );
1039
1040     return VLC_SUCCESS;
1041 }
1042
1043 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1044                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1045 {
1046     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1047     unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1048     vlc_value_t val;
1049
1050     char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1051
1052     /* Restore defaults */
1053     p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1054     p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1055     p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1056     p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1057
1058     if( !psz_parser ) goto aspect_end;
1059
1060     i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1061     if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1062
1063     i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1064     if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1065
1066     i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1067     i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1068     vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1069     p_vout->fmt_in.i_sar_num = i_sar_num;
1070     p_vout->fmt_in.i_sar_den = i_sar_den;
1071     p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1072     p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1073
1074  aspect_end:
1075     if( p_vout->i_par_num && p_vout->i_par_den )
1076     {
1077         p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1078         p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1079         p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1080             p_vout->i_par_den / p_vout->i_par_num;
1081         p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1082     }
1083
1084     p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1085
1086     vlc_ureduce( &i_aspect_num, &i_aspect_den,
1087                  p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1088     msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1089              i_aspect_num, i_aspect_den,
1090              p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1091
1092     var_Get( p_vout, "crop", &val );
1093     return CropCallback( p_this, "crop", val, val, 0 );
1094
1095     return VLC_SUCCESS;
1096 }
1097
1098 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1099                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1100 {
1101     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1102     playlist_t *p_playlist;
1103     vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1104
1105     p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1106                                                  FIND_PARENT );
1107     if( p_playlist )
1108     {
1109         /* Modify playlist as well because the vout might have to be restarted */
1110         var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1111         var_Set( p_playlist, "video-on-top", newval );
1112
1113         vlc_object_release( p_playlist );
1114     }
1115     return VLC_SUCCESS;
1116 }
1117
1118 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1119                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1120 {
1121     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1122     playlist_t *p_playlist;
1123     vlc_value_t val;
1124
1125     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1126
1127     p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1128                                                  FIND_PARENT );
1129     if( p_playlist )
1130     {
1131         /* Modify playlist as well because the vout might have to be restarted */
1132         var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1133         var_Set( p_playlist, "fullscreen", newval );
1134
1135         vlc_object_release( p_playlist );
1136     }
1137
1138     /* Disable "always on top" in fullscreen mode */
1139     var_Get( p_vout, "video-on-top", &val );
1140     if( newval.b_bool && val.b_bool )
1141     {
1142         val.b_bool = VLC_FALSE;
1143         vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
1144     }
1145     else if( !newval.b_bool && val.b_bool )
1146     {
1147         vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
1148     }
1149
1150     val.b_bool = VLC_TRUE;
1151     var_Set( p_vout, "intf-change", val );
1152     return VLC_SUCCESS;
1153 }
1154
1155 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1156                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1157 {
1158     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1159     vout_Control( p_vout, VOUT_SNAPSHOT );
1160     return VLC_SUCCESS;
1161 }