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