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