]> git.sesse.net Git - vlc/blob - src/video_output/vout_intf.c
Fix warning.
[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     (void)dummy;
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     { "16:10", "16:10" },
181     { "16:9", "16:9" },
182     { "185:100", "1.85:1" },
183     { "221:100", "2.21:1" },
184     { "235:100", "2.35:1" },
185     { "239:100", "2.39:1" },
186     { "5:3", "5:3" },
187     { "4:3", "4:3" },
188     { "5:4", "5:4" },
189     { "1:1", "1: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_chroma = VLC_FOURCC( 'p','n','g',' ' );
489
490         fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
491         fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
492         /* If snapshot-width and/or snapshot height were not specified,
493            use a default snapshot width of 320 */
494         if( fmt_out.i_width == 0 && fmt_out.i_height == 0 )
495         {
496             fmt_out.i_width = 320;
497         }
498
499         if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
500         {
501             fmt_out.i_width = (fmt_in.i_width * fmt_out.i_height) / fmt_in.i_height;
502         }
503         else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
504         {
505             fmt_out.i_height = (fmt_in.i_height * fmt_out.i_width) / fmt_in.i_width;
506         }
507         else
508         {
509             fmt_out.i_width = fmt_in.i_width;
510             fmt_out.i_height = fmt_in.i_height;
511         }
512
513         p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
514         if( !p_block )
515         {
516             msg_Err( p_vout, "Could not get snapshot" );
517             image_HandlerDelete( p_image );
518             vlc_object_signal( p_dest );
519             vlc_object_release( p_dest );
520             return VLC_EGENERIC;
521         }
522
523         /* Copy the p_block data to a snapshot structure */
524         /* FIXME: get the timestamp */
525         p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
526         if( !p_snapshot )
527         {
528             block_Release( p_block );
529             image_HandlerDelete( p_image );
530             vlc_object_signal( p_dest );
531             vlc_object_release( p_dest );
532             return VLC_ENOMEM;
533         }
534
535         i_size = p_block->i_buffer;
536
537         p_snapshot->i_width = fmt_out.i_width;
538         p_snapshot->i_height = fmt_out.i_height;
539         p_snapshot->i_datasize = i_size;
540         p_snapshot->date = p_block->i_pts; /* FIXME ?? */
541         p_snapshot->p_data = ( char* ) malloc( i_size );
542         if( !p_snapshot->p_data )
543         {
544             block_Release( p_block );
545             free( p_snapshot );
546             image_HandlerDelete( p_image );
547             vlc_object_signal( p_dest );
548             vlc_object_release( p_dest );
549             return VLC_ENOMEM;
550         }
551         memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
552
553         p_dest->p_private = p_snapshot;
554
555         block_Release( p_block );
556
557         /* Unlock the object */
558         vlc_object_signal( p_dest );
559         vlc_object_release( p_dest );
560
561         image_HandlerDelete( p_image );
562         return VLC_SUCCESS;
563     }
564
565 #if defined(__APPLE__) || defined(SYS_BEOS)
566     if( !val.psz_string )
567     {
568         if( asprintf( &val.psz_string, "%s/Desktop",
569                       config_GetHomeDir() ) == -1 )
570             val.psz_string = NULL;
571     }
572
573 #elif defined(WIN32) && !defined(UNDER_CE)
574     if( !val.psz_string )
575     {
576         /* Get the My Pictures folder path */
577
578         char *p_mypicturesdir = NULL;
579         typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
580                                                    LPWSTR );
581         #ifndef CSIDL_FLAG_CREATE
582         #   define CSIDL_FLAG_CREATE 0x8000
583         #endif
584         #ifndef CSIDL_MYPICTURES
585         #   define CSIDL_MYPICTURES 0x27
586         #endif
587         #ifndef SHGFP_TYPE_CURRENT
588         #   define SHGFP_TYPE_CURRENT 0
589         #endif
590
591         HINSTANCE shfolder_dll;
592         SHGETFOLDERPATH SHGetFolderPath ;
593
594         /* load the shfolder dll to retrieve SHGetFolderPath */
595         if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
596         {
597            wchar_t wdir[PATH_MAX];
598            SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
599                                                       _T("SHGetFolderPathW") );
600             if ((SHGetFolderPath != NULL )
601              && SUCCEEDED (SHGetFolderPath (NULL,
602                                            CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
603                                            NULL, SHGFP_TYPE_CURRENT,
604                                            wdir)))
605                 p_mypicturesdir = FromWide (wdir);
606
607             FreeLibrary( shfolder_dll );
608         }
609
610         if( p_mypicturesdir == NULL )
611             val.psz_string = strdup( config_GetHomeDir() );
612         else
613             val.psz_string = p_mypicturesdir;
614     }
615
616 #else
617     /* XXX: This saves in the data directory. Shouldn't we try saving
618      *      to psz_homedir/Desktop or something nicer ? */
619     char *psz_datadir = config_GetUserDataDir();
620     if( !val.psz_string && psz_datadir )
621     {
622         if( asprintf( &val.psz_string, "%s", psz_datadir ) == -1 )
623             val.psz_string = NULL;
624     }
625     free( psz_datadir );
626 #endif
627
628     if( !val.psz_string )
629     {
630         msg_Err( p_vout, "no path specified for snapshots" );
631         image_HandlerDelete( p_image );
632         return VLC_EGENERIC;
633     }
634     var_Get( p_vout, "snapshot-format", &format );
635     if( !format.psz_string || !*format.psz_string )
636     {
637         free( format.psz_string );
638         format.psz_string = strdup( "png" );
639     }
640
641     /*
642      * Did the user specify a directory? If not, path = NULL.
643      */
644     path = utf8_opendir ( (const char *)val.psz_string  );
645     if( path != NULL )
646     {
647         char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
648         if( psz_prefix == NULL )
649             psz_prefix = strdup( "vlcsnap-" );
650         else
651         {
652             char *psz_tmp = str_format( p_vout, psz_prefix );
653             filename_sanitize( psz_tmp );
654             free( psz_prefix );
655             psz_prefix = psz_tmp;
656         }
657
658         closedir( path );
659         if( var_GetBool( p_vout, "snapshot-sequential" ) == true )
660         {
661             int i_num = var_GetInteger( p_vout, "snapshot-num" );
662             FILE *p_file;
663             do
664             {
665                 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
666                               val.psz_string, psz_prefix, i_num++,
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             while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
675             var_SetInteger( p_vout, "snapshot-num", i_num );
676         }
677         else
678         {
679             if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
680                           val.psz_string, psz_prefix,
681                           (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
682                           format.psz_string ) == -1 )
683             {
684                 msg_Err( p_vout, "could not create snapshot" );
685                 image_HandlerDelete( p_image );
686                 return VLC_EGENERIC;
687             }
688         }
689
690         free( psz_prefix );
691     }
692     else // The user specified a full path name (including file name)
693     {
694         psz_filename = str_format( p_vout, val.psz_string );
695         path_sanitize( psz_filename );
696     }
697
698     free( val.psz_string );
699     free( format.psz_string );
700
701     fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
702     fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
703
704     fmt_in = p_vout->fmt_in;
705
706     if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
707     {
708         fmt_out.i_width = (fmt_in.i_width * fmt_out.i_height) / fmt_in.i_height;
709     }
710     else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
711     {
712         fmt_out.i_height = (fmt_in.i_height * fmt_out.i_width) / fmt_in.i_width;
713     }
714     else
715     {
716         fmt_out.i_width = fmt_in.i_width;
717         fmt_out.i_height = fmt_in.i_height;
718     }
719
720     /* Save the snapshot */
721     fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
722     i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
723     if( i_ret != VLC_SUCCESS )
724     {
725         msg_Err( p_vout, "could not create snapshot %s", psz_filename );
726         free( psz_filename );
727         image_HandlerDelete( p_image );
728         return VLC_EGENERIC;
729     }
730
731     msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
732     vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
733                      "%s", psz_filename );
734     free( psz_filename );
735
736     if( var_GetBool( p_vout, "snapshot-preview" ) )
737     {
738         /* Inject a subpicture with the snapshot */
739         memset( &fmt_out, 0, sizeof(fmt_out) );
740         fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
741         p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
742         image_HandlerDelete( p_image );
743         if( !p_pif ) return VLC_EGENERIC;
744
745         p_subpic = spu_CreateSubpicture( p_vout->p_spu );
746         if( p_subpic == NULL )
747         {
748              p_pif->pf_release( p_pif );
749              return VLC_EGENERIC;
750         }
751
752         p_subpic->i_channel = 0;
753         p_subpic->i_start = mdate();
754         p_subpic->i_stop = mdate() + 4000000;
755         p_subpic->b_ephemer = true;
756         p_subpic->b_fade = true;
757         p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
758         p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
759
760         p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
761         vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
762                           p_pif );
763         p_pif->pf_release( p_pif );
764
765         spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
766     }
767     else
768     {
769         image_HandlerDelete( p_image );
770     }
771
772     return VLC_SUCCESS;
773 }
774
775 /*****************************************************************************
776  * Handle filters
777  *****************************************************************************/
778
779 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
780                         bool b_add, bool b_setconfig )
781 {
782     char *psz_parser;
783     char *psz_string = config_GetPsz( p_vout, "vout-filter" );
784
785     /* Todo : Use some generic chain manipulation functions */
786     if( !psz_string ) psz_string = strdup("");
787
788     psz_parser = strstr( psz_string, psz_name );
789     if( b_add )
790     {
791         if( !psz_parser )
792         {
793             psz_parser = psz_string;
794             if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
795                           psz_string, psz_name ) == -1 )
796             {
797                 free( psz_parser );
798                 return;
799             }
800             free( psz_parser );
801         }
802         else
803             return;
804     }
805     else
806     {
807         if( psz_parser )
808         {
809             memmove( psz_parser, psz_parser + strlen(psz_name) +
810                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
811                             strlen(psz_parser + strlen(psz_name)) + 1 );
812
813             /* Remove trailing : : */
814             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
815             {
816                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
817             }
818          }
819          else
820          {
821              free( psz_string );
822              return;
823          }
824     }
825     if( b_setconfig )
826         config_PutPsz( p_vout, "vout-filter", psz_string );
827
828     var_SetString( p_vout, "vout-filter", psz_string );
829     free( psz_string );
830 }
831
832 /*****************************************************************************
833  * vout_ControlDefault: default methods for video output control.
834  *****************************************************************************/
835 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
836 {
837     (void)args;
838     switch( i_query )
839     {
840     case VOUT_REPARENT:
841     case VOUT_CLOSE:
842         vout_ReleaseWindow( p_vout, NULL );
843         return VLC_SUCCESS;
844
845     case VOUT_SNAPSHOT:
846         p_vout->b_snapshot = true;
847         return VLC_SUCCESS;
848
849     default:
850         msg_Dbg( p_vout, "control query not supported" );
851     }
852     return VLC_EGENERIC;
853 }
854
855 /*****************************************************************************
856  * InitWindowSize: find the initial dimensions the video window should have.
857  *****************************************************************************
858  * This function will check the "width", "height" and "zoom" config options and
859  * will calculate the size that the video window should have.
860  *****************************************************************************/
861 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
862                             unsigned *pi_height )
863 {
864     vlc_value_t val;
865     int i_width, i_height;
866     uint64_t ll_zoom;
867
868 #define FP_FACTOR 1000                             /* our fixed point factor */
869
870     var_Get( p_vout, "width", &val );
871     i_width = val.i_int;
872     var_Get( p_vout, "height", &val );
873     i_height = val.i_int;
874     var_Get( p_vout, "zoom", &val );
875     ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
876
877     if( i_width > 0 && i_height > 0)
878     {
879         *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
880         *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
881         goto initwsize_end;
882     }
883     else if( i_width > 0 )
884     {
885         *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
886         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
887             p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
888             FP_FACTOR / p_vout->fmt_in.i_visible_width );
889         goto initwsize_end;
890     }
891     else if( i_height > 0 )
892     {
893         *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
894         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
895             p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
896             FP_FACTOR / p_vout->fmt_in.i_visible_height );
897         goto initwsize_end;
898     }
899
900     if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
901         msg_Warn( p_vout, "fucked up aspect" );
902         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
903         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
904     }
905     else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
906     {
907         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
908             p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
909         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
910             / FP_FACTOR );
911     }
912     else
913     {
914         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
915             / FP_FACTOR );
916         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
917             p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
918     }
919
920 initwsize_end:
921     msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
922              p_vout->i_window_height );
923
924 #undef FP_FACTOR
925 }
926
927 /*****************************************************************************
928  * Object variables callbacks
929  *****************************************************************************/
930 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
931                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
932 {
933     vout_thread_t *p_vout = (vout_thread_t *)p_this;
934     (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
935     InitWindowSize( p_vout, &p_vout->i_window_width,
936                     &p_vout->i_window_height );
937     vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
938                   p_vout->i_window_height );
939     return VLC_SUCCESS;
940 }
941
942 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
943                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
944 {
945     vout_thread_t *p_vout = (vout_thread_t *)p_this;
946     int64_t i_aspect_num, i_aspect_den;
947     unsigned int i_width, i_height;
948
949     (void)oldval; (void)p_data;
950
951     /* Restore defaults */
952     p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
953     p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
954     p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
955     p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
956
957     if( !strcmp( psz_cmd, "crop" ) )
958     {
959         char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
960         if( psz_parser )
961         {
962             /* We're using the 3:4 syntax */
963             i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
964             if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
965
966             i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
967             if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
968
969             i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
970                 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
971             i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
972                 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
973
974             if( i_width < p_vout->fmt_render.i_visible_width )
975             {
976                 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
977                     (p_vout->fmt_render.i_visible_width - i_width) / 2;
978                 p_vout->fmt_in.i_visible_width = i_width;
979             }
980             else
981             {
982                 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
983                     (p_vout->fmt_render.i_visible_height - i_height) / 2;
984                 p_vout->fmt_in.i_visible_height = i_height;
985             }
986         }
987         else
988         {
989             psz_parser = strchr( newval.psz_string, 'x' );
990             if( psz_parser )
991             {
992                 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
993                 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
994
995                 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
996                 if( psz_end != psz_parser ) goto crop_end;
997
998                 psz_parser = strchr( ++psz_end, '+' );
999                 i_crop_height = strtol( psz_end, &psz_end, 10 );
1000                 if( psz_end != psz_parser ) goto crop_end;
1001
1002                 psz_parser = strchr( ++psz_end, '+' );
1003                 i_crop_left = strtol( psz_end, &psz_end, 10 );
1004                 if( psz_end != psz_parser ) goto crop_end;
1005
1006                 psz_end++;
1007                 i_crop_top = strtol( psz_end, &psz_end, 10 );
1008                 if( *psz_end != '\0' ) goto crop_end;
1009
1010                 i_width = i_crop_width;
1011                 p_vout->fmt_in.i_visible_width = i_width;
1012
1013                 i_height = i_crop_height;
1014                 p_vout->fmt_in.i_visible_height = i_height;
1015
1016                 p_vout->fmt_in.i_x_offset = i_crop_left;
1017                 p_vout->fmt_in.i_y_offset = i_crop_top;
1018             }
1019             else
1020             {
1021                 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1022                 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1023
1024                 psz_parser = strchr( newval.psz_string, '+' );
1025                 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1026                 if( psz_end != psz_parser ) goto crop_end;
1027
1028                 psz_parser = strchr( ++psz_end, '+' );
1029                 i_crop_top = strtol( psz_end, &psz_end, 10 );
1030                 if( psz_end != psz_parser ) goto crop_end;
1031
1032                 psz_parser = strchr( ++psz_end, '+' );
1033                 i_crop_right = strtol( psz_end, &psz_end, 10 );
1034                 if( psz_end != psz_parser ) goto crop_end;
1035
1036                 psz_end++;
1037                 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1038                 if( *psz_end != '\0' ) goto crop_end;
1039
1040                 i_width = p_vout->fmt_render.i_visible_width
1041                           - i_crop_left - i_crop_right;
1042                 p_vout->fmt_in.i_visible_width = i_width;
1043
1044                 i_height = p_vout->fmt_render.i_visible_height
1045                            - i_crop_top - i_crop_bottom;
1046                 p_vout->fmt_in.i_visible_height = i_height;
1047
1048                 p_vout->fmt_in.i_x_offset = i_crop_left;
1049                 p_vout->fmt_in.i_y_offset = i_crop_top;
1050             }
1051         }
1052     }
1053     else if( !strcmp( psz_cmd, "crop-top" )
1054           || !strcmp( psz_cmd, "crop-left" )
1055           || !strcmp( psz_cmd, "crop-bottom" )
1056           || !strcmp( psz_cmd, "crop-right" ) )
1057     {
1058         unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1059
1060         i_crop_top = var_GetInteger( p_vout, "crop-top" );
1061         i_crop_left = var_GetInteger( p_vout, "crop-left" );
1062         i_crop_right = var_GetInteger( p_vout, "crop-right" );
1063         i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1064
1065         i_width = p_vout->fmt_render.i_visible_width
1066                   - i_crop_left - i_crop_right;
1067         p_vout->fmt_in.i_visible_width = i_width;
1068
1069         i_height = p_vout->fmt_render.i_visible_height
1070                    - i_crop_top - i_crop_bottom;
1071         p_vout->fmt_in.i_visible_height = i_height;
1072
1073         p_vout->fmt_in.i_x_offset = i_crop_left;
1074         p_vout->fmt_in.i_y_offset = i_crop_top;
1075     }
1076
1077  crop_end:
1078     InitWindowSize( p_vout, &p_vout->i_window_width,
1079                     &p_vout->i_window_height );
1080
1081     p_vout->i_changes |= VOUT_CROP_CHANGE;
1082
1083     msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1084              p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1085              p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1086              p_vout->fmt_in.i_visible_width,
1087              p_vout->fmt_in.i_visible_height );
1088
1089     var_SetVoid( p_vout, "crop-update" );
1090
1091     return VLC_SUCCESS;
1092 }
1093
1094 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1095                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1096 {
1097     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1098     unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1099     vlc_value_t val;
1100
1101     char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1102     (void)psz_cmd; (void)oldval; (void)p_data;
1103
1104     /* Restore defaults */
1105     p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1106     p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1107     p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1108     p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1109
1110     if( !psz_parser ) goto aspect_end;
1111
1112     i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1113     if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1114
1115     i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1116     if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1117
1118     i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1119     i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1120     vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1121     p_vout->fmt_in.i_sar_num = i_sar_num;
1122     p_vout->fmt_in.i_sar_den = i_sar_den;
1123     p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1124     p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1125
1126  aspect_end:
1127     if( p_vout->i_par_num && p_vout->i_par_den )
1128     {
1129         p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1130         p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1131         p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1132             p_vout->i_par_den / p_vout->i_par_num;
1133         p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1134     }
1135
1136     p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1137
1138     vlc_ureduce( &i_aspect_num, &i_aspect_den,
1139                  p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1140     msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1141              i_aspect_num, i_aspect_den,
1142              p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1143
1144     if( var_Get( p_vout, "crop", &val ) )
1145         return VLC_EGENERIC;
1146
1147     int i_ret = CropCallback( p_this, "crop", val, val, 0 );
1148     free( val.psz_string );
1149     return i_ret;
1150 }
1151
1152 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1153                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1154 {
1155     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1156     vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1157     (void)psz_cmd; (void)oldval; (void)p_data;
1158
1159     /* Modify libvlc as well because the vout might have to be restarted */
1160     var_Create( p_vout->p_libvlc, "video-on-top", VLC_VAR_BOOL );
1161     var_Set( p_vout->p_libvlc, "video-on-top", newval );
1162
1163     return VLC_SUCCESS;
1164 }
1165
1166 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1167                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1168 {
1169     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1170     vlc_value_t val;
1171     (void)psz_cmd; (void)oldval; (void)p_data;
1172
1173     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1174
1175     /* Modify libvlc as well because the vout might have to be restarted */
1176     var_Create( p_vout->p_libvlc, "fullscreen", VLC_VAR_BOOL );
1177     var_Set( p_vout->p_libvlc, "fullscreen", newval );
1178
1179     val.b_bool = true;
1180     var_Set( p_vout, "intf-change", val );
1181     return VLC_SUCCESS;
1182 }
1183
1184 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1185                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1186 {
1187     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1188     VLC_UNUSED(newval); VLC_UNUSED(p_data);
1189     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1190     vout_Control( p_vout, VOUT_SNAPSHOT );
1191     return VLC_SUCCESS;
1192 }
1193
1194 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1195                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1196 {
1197     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1198     VLC_UNUSED(p_data);
1199     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1200     p_vout->b_title_show = newval.b_bool;
1201     return VLC_SUCCESS;
1202 }
1203
1204 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
1205                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1206 {
1207     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1208     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1209     p_vout->i_title_timeout = (mtime_t) newval.i_int;
1210     return VLC_SUCCESS;
1211 }
1212
1213 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1214                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1215 {
1216     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1217     VLC_UNUSED(p_data);
1218     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1219     p_vout->i_title_position = newval.i_int;
1220     return VLC_SUCCESS;
1221 }