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