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