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