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