]> git.sesse.net Git - vlc/blob - src/video_output/vout_intf.c
Remove obsolete comment.
[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 #include <vlc/vlc.h>
29
30 #include <stdio.h>
31 #include <stdlib.h>                                                /* free() */
32 #include <sys/types.h>                                          /* opendir() */
33 #include <dirent.h>                                             /* opendir() */
34
35 #include <vlc_interface.h>
36 #include <vlc_block.h>
37 #include <vlc_playlist.h>
38
39 #include <vlc_vout.h>
40 #include <vlc_image.h>
41 #include <vlc_osd.h>
42 #include <vlc_charset.h>
43
44 #include <vlc_strings.h>
45 #include <vlc_charset.h>
46 #include "../libvlc.h"
47
48 /*****************************************************************************
49  * Local prototypes
50  *****************************************************************************/
51 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
52
53 /* Object variables callbacks */
54 static int ZoomCallback( vlc_object_t *, char const *,
55                          vlc_value_t, vlc_value_t, void * );
56 static int CropCallback( vlc_object_t *, char const *,
57                          vlc_value_t, vlc_value_t, void * );
58 static int AspectCallback( vlc_object_t *, char const *,
59                            vlc_value_t, vlc_value_t, void * );
60 static int OnTopCallback( vlc_object_t *, char const *,
61                           vlc_value_t, vlc_value_t, void * );
62 static int FullscreenCallback( vlc_object_t *, char const *,
63                                vlc_value_t, vlc_value_t, void * );
64 static int SnapshotCallback( vlc_object_t *, char const *,
65                              vlc_value_t, vlc_value_t, void * );
66 static int TitleCallback( vlc_object_t *, char const *,
67                        vlc_value_t, vlc_value_t, void * );
68
69 /*****************************************************************************
70  * vout_RequestWindow: Create/Get a video window if possible.
71  *****************************************************************************
72  * This function looks for the main interface and tries to request
73  * a new video window. If it fails then the vout will still need to create the
74  * window by itself.
75  *****************************************************************************/
76 void *vout_RequestWindow( vout_thread_t *p_vout,
77                           int *pi_x_hint, int *pi_y_hint,
78                           unsigned int *pi_width_hint,
79                           unsigned int *pi_height_hint )
80 {
81     intf_thread_t *p_intf = NULL;
82     vlc_list_t *p_list;
83     void *p_window;
84     vlc_value_t val;
85     int i;
86
87     /* Small kludge */
88     if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
89
90     /* Get requested coordinates */
91     var_Get( p_vout, "video-x", &val );
92     *pi_x_hint = val.i_int ;
93     var_Get( p_vout, "video-y", &val );
94     *pi_y_hint = val.i_int;
95
96     *pi_width_hint = p_vout->i_window_width;
97     *pi_height_hint = p_vout->i_window_height;
98
99     /* Check whether someone provided us with a window ID */
100     var_Get( p_vout->p_libvlc, "drawable", &val );
101     if( val.i_int ) return (void *)(intptr_t)val.i_int;
102
103     /* Find if the main interface supports embedding */
104     p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
105     if( !p_list ) return NULL;
106
107     for( i = 0; i < p_list->i_count; i++ )
108     {
109         p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
110         if( p_intf->pf_request_window ) break;
111         p_intf = NULL;
112     }
113
114     if( !p_intf )
115     {
116         vlc_list_release( p_list );
117         return NULL;
118     }
119
120     vlc_object_yield( p_intf );
121     vlc_list_release( p_list );
122
123     p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
124                                           pi_width_hint, pi_height_hint );
125
126     if( !p_window ) vlc_object_release( p_intf );
127     else p_vout->p_parent_intf = p_intf;
128
129     return p_window;
130 }
131
132 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
133 {
134     intf_thread_t *p_intf = p_vout->p_parent_intf;
135
136     if( !p_intf ) return;
137
138     vlc_mutex_lock( &p_intf->object_lock );
139     if( p_intf->b_dead )
140     {
141         vlc_mutex_unlock( &p_intf->object_lock );
142         return;
143     }
144
145     if( !p_intf->pf_release_window )
146     {
147         msg_Err( p_vout, "no pf_release_window");
148         vlc_mutex_unlock( &p_intf->object_lock );
149         vlc_object_release( p_intf );
150         return;
151     }
152
153     p_intf->pf_release_window( p_intf, p_window );
154
155     p_vout->p_parent_intf = NULL;
156     vlc_mutex_unlock( &p_intf->object_lock );
157     vlc_object_release( p_intf );
158 }
159
160 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
161                         int i_query, va_list args )
162 {
163     intf_thread_t *p_intf = p_vout->p_parent_intf;
164     int i_ret;
165
166     if( !p_intf ) return VLC_EGENERIC;
167
168     vlc_mutex_lock( &p_intf->object_lock );
169     if( p_intf->b_dead )
170     {
171         vlc_mutex_unlock( &p_intf->object_lock );
172         return VLC_EGENERIC;
173     }
174
175     if( !p_intf->pf_control_window )
176     {
177         msg_Err( p_vout, "no pf_control_window");
178         vlc_mutex_unlock( &p_intf->object_lock );
179         return VLC_EGENERIC;
180     }
181
182     i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
183     vlc_mutex_unlock( &p_intf->object_lock );
184     return i_ret;
185 }
186
187 /*****************************************************************************
188  * vout_IntfInit: called during the vout creation to initialise misc things.
189  *****************************************************************************/
190 void vout_IntfInit( vout_thread_t *p_vout )
191 {
192     vlc_value_t val, text, old_val;
193     vlc_bool_t b_force_par = VLC_FALSE;
194     char *psz_buf;
195
196     /* Create a few object variables we'll need later on */
197     var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
198     var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
199     var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
200     var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
201     var_Create( p_vout, "snapshot-sequential",
202                 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
203     var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
204     var_SetInteger( p_vout, "snapshot-num", 1 );
205     var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
206     var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
207
208     var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
209     var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
210     var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
211     var_Get( p_vout, "align", &val );
212     p_vout->i_alignment = val.i_int;
213
214     var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
215     var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
216
217     var_Create( p_vout, "video-title-show", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
218     var_Create( p_vout, "video-title-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
219     var_Create( p_vout, "video-title-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
220
221     p_vout->b_title_show = var_GetBool( p_vout, "video-title-show" );
222     p_vout->i_title_timeout = (mtime_t) var_GetInteger( p_vout, "video-title-timeout" );
223     p_vout->i_title_position = var_GetInteger( p_vout, "video-title-position" );
224
225     var_AddCallback( p_vout, "video-title-show", TitleCallback, NULL );
226     var_AddCallback( p_vout, "video-title-timeout", TitleCallback, NULL );
227     var_AddCallback( p_vout, "video-title-position", TitleCallback, NULL );
228
229     /* Zoom object var */
230     var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
231                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
232
233     text.psz_string = _("Zoom");
234     var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
235
236     var_Get( p_vout, "zoom", &old_val );
237     if( old_val.f_float == 0.25 ||
238         old_val.f_float == 0.5 ||
239         old_val.f_float == 1 ||
240         old_val.f_float == 2 )
241     {
242         var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
243     }
244
245     val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
246     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
247     val.f_float = 0.5; text.psz_string = _("1:2 Half");
248     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
249     val.f_float = 1; text.psz_string = _("1:1 Original");
250     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
251     val.f_float = 2; text.psz_string = _("2:1 Double");
252     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
253
254     var_Set( p_vout, "zoom", old_val );
255
256     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
257
258     /* Crop offset vars */
259     var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
260     var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
261     var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
262     var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
263
264     var_SetInteger( p_vout, "crop-left", 0 );
265     var_SetInteger( p_vout, "crop-top", 0 );
266     var_SetInteger( p_vout, "crop-right", 0 );
267     var_SetInteger( p_vout, "crop-bottom", 0 );
268
269     var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
270     var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
271     var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
272     var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
273
274     /* Crop object var */
275     var_Create( p_vout, "crop", VLC_VAR_STRING |
276                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
277
278     text.psz_string = _("Crop");
279     var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
280
281     val.psz_string = "";
282     var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
283     val.psz_string = ""; text.psz_string = _("Default");
284     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
285     val.psz_string = "1:1"; text.psz_string = "1:1";
286     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
287     val.psz_string = "4:3"; text.psz_string = "4:3";
288     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
289     val.psz_string = "16:9"; text.psz_string = "16:9";
290     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
291     val.psz_string = "16:10"; text.psz_string = "16:10";
292     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
293     val.psz_string = "5:4"; text.psz_string = "5:4";
294     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
295     val.psz_string = "5:3"; text.psz_string = "5:3";
296     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
297     val.psz_string = "1.85:1"; text.psz_string = "1.85:1";
298     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
299     val.psz_string = "221:100"; text.psz_string = "2.21:1";
300     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
301     val.psz_string = "235:100"; text.psz_string = "2.35:1";
302     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
303     val.psz_string = "239:100"; text.psz_string = "2.39:1";
304     var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
305
306     /* Add custom crop ratios */
307     psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
308     if( psz_buf && *psz_buf )
309     {
310         char *psz_cur = psz_buf;
311         char *psz_next;
312         while( psz_cur && *psz_cur )
313         {
314             psz_next = strchr( psz_cur, ',' );
315             if( psz_next )
316             {
317                 *psz_next = '\0';
318                 psz_next++;
319             }
320             val.psz_string = strdup( psz_cur );
321             text.psz_string = strdup( psz_cur );
322             var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text);
323             free( val.psz_string );
324             free( text.psz_string );
325             psz_cur = psz_next;
326         }
327     }
328     if( psz_buf ) free( psz_buf );
329
330     var_AddCallback( p_vout, "crop", CropCallback, NULL );
331     var_Get( p_vout, "crop", &old_val );
332     if( old_val.psz_string && *old_val.psz_string )
333         var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
334     if( old_val.psz_string ) free( old_val.psz_string );
335
336     /* Monitor pixel aspect-ratio */
337     var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
338     var_Get( p_vout, "monitor-par", &val );
339     if( val.psz_string && *val.psz_string )
340     {
341         char *psz_parser = strchr( val.psz_string, ':' );
342         unsigned int i_aspect_num = 0, i_aspect_den = 0;
343         float i_aspect = 0;
344         if( psz_parser )
345         {
346             i_aspect_num = strtol( val.psz_string, 0, 10 );
347             i_aspect_den = strtol( ++psz_parser, 0, 10 );
348         }
349         else
350         {
351             i_aspect = atof( val.psz_string );
352             vlc_ureduce( &i_aspect_num, &i_aspect_den,
353                          i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
354         }
355         if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
356
357         p_vout->i_par_num = i_aspect_num;
358         p_vout->i_par_den = i_aspect_den;
359
360         vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
361                      p_vout->i_par_num, p_vout->i_par_den, 0 );
362
363         msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
364                  p_vout->i_par_num, p_vout->i_par_den );
365         b_force_par = VLC_TRUE;
366     }
367     if( val.psz_string ) free( val.psz_string );
368
369     /* Aspect-ratio object var */
370     var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
371                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
372
373     text.psz_string = _("Aspect-ratio");
374     var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
375
376     val.psz_string = "";
377     var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
378     val.psz_string = ""; text.psz_string = _("Default");
379     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
380     val.psz_string = "1:1"; text.psz_string = "1:1";
381     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
382     val.psz_string = "4:3"; text.psz_string = "4:3";
383     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
384     val.psz_string = "16:9"; text.psz_string = "16:9";
385     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
386     val.psz_string = "16:10"; text.psz_string = "16:10";
387     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
388     val.psz_string = "221:100"; text.psz_string = "2.21:1";
389     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
390     val.psz_string = "5:4"; text.psz_string = "5:4";
391     var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
392
393     /* Add custom aspect ratios */
394     psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
395     if( psz_buf && *psz_buf )
396     {
397         char *psz_cur = psz_buf;
398         char *psz_next;
399         while( psz_cur && *psz_cur )
400         {
401             psz_next = strchr( psz_cur, ',' );
402             if( psz_next )
403             {
404                 *psz_next = '\0';
405                 psz_next++;
406             }
407             val.psz_string = strdup( psz_cur );
408             text.psz_string = strdup( psz_cur );
409             var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text);
410             free( val.psz_string );
411             free( text.psz_string );
412             psz_cur = psz_next;
413         }
414     }
415     if( psz_buf ) free( psz_buf );
416
417     var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
418     var_Get( p_vout, "aspect-ratio", &old_val );
419     if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
420         var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
421     if( old_val.psz_string ) free( old_val.psz_string );
422
423     /* Initialize the dimensions of the video window */
424     InitWindowSize( p_vout, &p_vout->i_window_width,
425                     &p_vout->i_window_height );
426
427     /* Add a variable to indicate if the window should be on top of others */
428     var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
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     var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
438     text.psz_string = _("Fullscreen");
439     var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
440     var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
441     if( val.b_bool )
442     {
443         /* user requested fullscreen */
444         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
445     }
446     var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
447
448     /* Add a snapshot variable */
449     var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
450     text.psz_string = _("Snapshot");
451     var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
452     var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
453
454     /* Mouse coordinates */
455     var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
456     var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
457     var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
458     var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
459     var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
460
461     var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
462     val.b_bool = VLC_TRUE;
463     var_Set( p_vout, "intf-change", val );
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         if( format.psz_string ) 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                 asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s", val.psz_string,
682                           psz_prefix, i_num++, format.psz_string );
683             }
684             while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
685             var_SetInteger( p_vout, "snapshot-num", i_num );
686         }
687         else
688         {
689             asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s", val.psz_string,
690                       psz_prefix,
691                       (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
692                       format.psz_string );
693         }
694
695         free( psz_prefix );
696     }
697     else // The user specified a full path name (including file name)
698     {
699         psz_filename = str_format( p_vout, val.psz_string );
700         path_sanitize( psz_filename );
701     }
702
703     free( val.psz_string );
704     free( format.psz_string );
705
706     fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
707     fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
708
709     if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
710     {
711         float f = (float)p_vout->fmt_in.i_height / fmt_out.i_height;
712         fmt_out.i_width = p_vout->fmt_in.i_width / f;
713     }
714     else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
715     {
716         float f = (float)p_vout->fmt_in.i_width / fmt_out.i_width;
717         fmt_out.i_height = p_vout->fmt_in.i_height / f;
718     }
719
720     /* Save the snapshot */
721     fmt_in = p_vout->fmt_in;
722     fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
723     i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
724     if( i_ret != VLC_SUCCESS )
725     {
726         msg_Err( p_vout, "could not create snapshot %s", psz_filename );
727         free( psz_filename );
728         image_HandlerDelete( p_image );
729         return VLC_EGENERIC;
730     }
731
732     msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
733     vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
734                      "%s", psz_filename );
735     free( psz_filename );
736
737     if( var_GetBool( p_vout, "snapshot-preview" ) )
738     {
739         /* Inject a subpicture with the snapshot */
740         memset( &fmt_out, 0, sizeof(fmt_out) );
741         fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
742         p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
743         image_HandlerDelete( p_image );
744         if( !p_pif ) return VLC_EGENERIC;
745
746         p_subpic = spu_CreateSubpicture( p_vout->p_spu );
747         if( p_subpic == NULL )
748         {
749              p_pif->pf_release( p_pif );
750              return VLC_EGENERIC;
751         }
752
753         p_subpic->i_channel = 0;
754         p_subpic->i_start = mdate();
755         p_subpic->i_stop = mdate() + 4000000;
756         p_subpic->b_ephemer = VLC_TRUE;
757         p_subpic->b_fade = VLC_TRUE;
758         p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
759         p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
760
761         p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
762         vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
763                           p_pif );
764         p_pif->pf_release( p_pif );
765
766         spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
767     }
768     else
769     {
770         image_HandlerDelete( p_image );
771     }
772
773     return VLC_SUCCESS;
774 }
775
776 /*****************************************************************************
777  * Handle filters
778  *****************************************************************************/
779
780 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
781                         vlc_bool_t b_add, vlc_bool_t b_setconfig )
782 {
783     char *psz_parser;
784     char *psz_string = config_GetPsz( p_vout, "vout-filter" );
785
786     /* Todo : Use some generic chain manipulation functions */
787     if( !psz_string ) psz_string = strdup("");
788
789     psz_parser = strstr( psz_string, psz_name );
790     if( b_add )
791     {
792         if( !psz_parser )
793         {
794             psz_parser = psz_string;
795             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
796                             psz_string, psz_name );
797             free( psz_parser );
798         }
799         else
800             return;
801     }
802     else
803     {
804         if( psz_parser )
805         {
806             memmove( psz_parser, psz_parser + strlen(psz_name) +
807                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
808                             strlen(psz_parser + strlen(psz_name)) + 1 );
809
810             /* Remove trailing : : */
811             if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
812             {
813                 *(psz_string+strlen(psz_string ) -1 ) = '\0';
814             }
815          }
816          else
817          {
818              free( psz_string );
819              return;
820          }
821     }
822     if( b_setconfig )
823         config_PutPsz( p_vout, "vout-filter", psz_string );
824
825     var_SetString( p_vout, "vout-filter", psz_string );
826     free( psz_string );
827 }
828
829 /*****************************************************************************
830  * vout_ControlDefault: default methods for video output control.
831  *****************************************************************************/
832 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
833 {
834     (void)args;
835     switch( i_query )
836     {
837     case VOUT_REPARENT:
838     case VOUT_CLOSE:
839         if( p_vout->p_parent_intf )
840         {
841             vlc_object_release( p_vout->p_parent_intf );
842             p_vout->p_parent_intf = NULL;
843         }
844         return VLC_SUCCESS;
845         break;
846
847     case VOUT_SNAPSHOT:
848         p_vout->b_snapshot = VLC_TRUE;
849         return VLC_SUCCESS;
850         break;
851
852     default:
853         msg_Dbg( p_vout, "control query not supported" );
854         return VLC_EGENERIC;
855     }
856 }
857
858 /*****************************************************************************
859  * InitWindowSize: find the initial dimensions the video window should have.
860  *****************************************************************************
861  * This function will check the "width", "height" and "zoom" config options and
862  * will calculate the size that the video window should have.
863  *****************************************************************************/
864 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
865                             unsigned *pi_height )
866 {
867     vlc_value_t val;
868     int i_width, i_height;
869     uint64_t ll_zoom;
870
871 #define FP_FACTOR 1000                             /* our fixed point factor */
872
873     var_Get( p_vout, "width", &val );
874     i_width = val.i_int;
875     var_Get( p_vout, "height", &val );
876     i_height = val.i_int;
877     var_Get( p_vout, "zoom", &val );
878     ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
879
880     if( i_width > 0 && i_height > 0)
881     {
882         *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
883         *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
884         goto initwsize_end;
885     }
886     else if( i_width > 0 )
887     {
888         *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
889         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
890             p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
891             FP_FACTOR / p_vout->fmt_in.i_visible_width );
892         goto initwsize_end;
893     }
894     else if( i_height > 0 )
895     {
896         *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
897         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
898             p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
899             FP_FACTOR / p_vout->fmt_in.i_visible_height );
900         goto initwsize_end;
901     }
902
903     if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
904         msg_Warn( p_vout, "fucked up aspect" );
905         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
906         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
907     }
908     else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
909     {
910         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
911             p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
912         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
913             / FP_FACTOR );
914     }
915     else
916     {
917         *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
918             / FP_FACTOR );
919         *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
920             p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
921     }
922
923 initwsize_end:
924     msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
925              p_vout->i_window_height );
926
927 #undef FP_FACTOR
928 }
929
930 /*****************************************************************************
931  * Object variables callbacks
932  *****************************************************************************/
933 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
934                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
935 {
936     vout_thread_t *p_vout = (vout_thread_t *)p_this;
937     (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
938     InitWindowSize( p_vout, &p_vout->i_window_width,
939                     &p_vout->i_window_height );
940     vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
941                   p_vout->i_window_height );
942     return VLC_SUCCESS;
943 }
944
945 static int CropCallback( 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     int64_t i_aspect_num, i_aspect_den;
950     unsigned int i_width, i_height;
951
952     (void)oldval; (void)p_data;
953
954     /* Restore defaults */
955     p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
956     p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
957     p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
958     p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
959
960     if( !strcmp( psz_cmd, "crop" ) )
961     {
962         char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
963         if( psz_parser )
964         {
965             /* We're using the 3:4 syntax */
966             i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
967             if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
968
969             i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
970             if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
971
972             i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
973                 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
974             i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
975                 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
976
977             if( i_width < p_vout->fmt_render.i_visible_width )
978             {
979                 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
980                     (p_vout->fmt_render.i_visible_width - i_width) / 2;
981                 p_vout->fmt_in.i_visible_width = i_width;
982             }
983             else
984             {
985                 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
986                     (p_vout->fmt_render.i_visible_height - i_height) / 2;
987                 p_vout->fmt_in.i_visible_height = i_height;
988             }
989         }
990         else
991         {
992             psz_parser = strchr( newval.psz_string, 'x' );
993             if( psz_parser )
994             {
995                 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
996                 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
997
998                 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
999                 if( psz_end != psz_parser ) goto crop_end;
1000
1001                 psz_parser = strchr( ++psz_end, '+' );
1002                 i_crop_height = strtol( psz_end, &psz_end, 10 );
1003                 if( psz_end != psz_parser ) goto crop_end;
1004
1005                 psz_parser = strchr( ++psz_end, '+' );
1006                 i_crop_left = strtol( psz_end, &psz_end, 10 );
1007                 if( psz_end != psz_parser ) goto crop_end;
1008
1009                 psz_end++;
1010                 i_crop_top = strtol( psz_end, &psz_end, 10 );
1011                 if( *psz_end != '\0' ) goto crop_end;
1012
1013                 i_width = i_crop_width;
1014                 p_vout->fmt_in.i_visible_width = i_width;
1015
1016                 i_height = i_crop_height;
1017                 p_vout->fmt_in.i_visible_height = i_height;
1018
1019                 p_vout->fmt_in.i_x_offset = i_crop_left;
1020                 p_vout->fmt_in.i_y_offset = i_crop_top;
1021             }
1022             else
1023             {
1024                 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1025                 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1026
1027                 psz_parser = strchr( newval.psz_string, '+' );
1028                 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1029                 if( psz_end != psz_parser ) goto crop_end;
1030
1031                 psz_parser = strchr( ++psz_end, '+' );
1032                 i_crop_top = strtol( psz_end, &psz_end, 10 );
1033                 if( psz_end != psz_parser ) goto crop_end;
1034
1035                 psz_parser = strchr( ++psz_end, '+' );
1036                 i_crop_right = strtol( psz_end, &psz_end, 10 );
1037                 if( psz_end != psz_parser ) goto crop_end;
1038
1039                 psz_end++;
1040                 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1041                 if( *psz_end != '\0' ) goto crop_end;
1042
1043                 i_width = p_vout->fmt_render.i_visible_width
1044                           - i_crop_left - i_crop_right;
1045                 p_vout->fmt_in.i_visible_width = i_width;
1046
1047                 i_height = p_vout->fmt_render.i_visible_height
1048                            - i_crop_top - i_crop_bottom;
1049                 p_vout->fmt_in.i_visible_height = i_height;
1050
1051                 p_vout->fmt_in.i_x_offset = i_crop_left;
1052                 p_vout->fmt_in.i_y_offset = i_crop_top;
1053             }
1054         }
1055     }
1056     else if( !strcmp( psz_cmd, "crop-top" )
1057           || !strcmp( psz_cmd, "crop-left" )
1058           || !strcmp( psz_cmd, "crop-bottom" )
1059           || !strcmp( psz_cmd, "crop-right" ) )
1060     {
1061         unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1062
1063         i_crop_top = var_GetInteger( p_vout, "crop-top" );
1064         i_crop_left = var_GetInteger( p_vout, "crop-left" );
1065         i_crop_right = var_GetInteger( p_vout, "crop-right" );
1066         i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1067
1068         i_width = p_vout->fmt_render.i_visible_width
1069                   - i_crop_left - i_crop_right;
1070         p_vout->fmt_in.i_visible_width = i_width;
1071
1072         i_height = p_vout->fmt_render.i_visible_height
1073                    - i_crop_top - i_crop_bottom;
1074         p_vout->fmt_in.i_visible_height = i_height;
1075
1076         p_vout->fmt_in.i_x_offset = i_crop_left;
1077         p_vout->fmt_in.i_y_offset = i_crop_top;
1078     }
1079
1080  crop_end:
1081     InitWindowSize( p_vout, &p_vout->i_window_width,
1082                     &p_vout->i_window_height );
1083
1084     p_vout->i_changes |= VOUT_CROP_CHANGE;
1085
1086     msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1087              p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1088              p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1089              p_vout->fmt_in.i_visible_width,
1090              p_vout->fmt_in.i_visible_height );
1091
1092     return VLC_SUCCESS;
1093 }
1094
1095 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1096                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1097 {
1098     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1099     unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1100     vlc_value_t val;
1101
1102     char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1103     (void)psz_cmd; (void)oldval; (void)p_data;
1104
1105     /* Restore defaults */
1106     p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1107     p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1108     p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1109     p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1110
1111     if( !psz_parser ) goto aspect_end;
1112
1113     i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1114     if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1115
1116     i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1117     if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1118
1119     i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1120     i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1121     vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1122     p_vout->fmt_in.i_sar_num = i_sar_num;
1123     p_vout->fmt_in.i_sar_den = i_sar_den;
1124     p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1125     p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1126
1127  aspect_end:
1128     if( p_vout->i_par_num && p_vout->i_par_den )
1129     {
1130         p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1131         p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1132         p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1133             p_vout->i_par_den / p_vout->i_par_num;
1134         p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1135     }
1136
1137     p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1138
1139     vlc_ureduce( &i_aspect_num, &i_aspect_den,
1140                  p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1141     msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1142              i_aspect_num, i_aspect_den,
1143              p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1144
1145     var_Get( p_vout, "crop", &val );
1146     return CropCallback( p_this, "crop", val, val, 0 );
1147
1148     return VLC_SUCCESS;
1149 }
1150
1151 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1152                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1153 {
1154     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1155     playlist_t *p_playlist = pl_Yield( p_this );
1156     vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1157     (void)psz_cmd; (void)oldval; (void)p_data;
1158
1159     /* Modify playlist as well because the vout might have to be restarted */
1160     var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1161     var_Set( p_playlist, "video-on-top", newval );
1162
1163     pl_Release( p_this );
1164     return VLC_SUCCESS;
1165 }
1166
1167 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1168                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1169 {
1170     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1171     vlc_value_t val;
1172     playlist_t *p_playlist = pl_Yield( p_this );
1173     (void)psz_cmd; (void)oldval; (void)p_data;
1174
1175     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1176
1177     /* Modify playlist as well because the vout might have to be restarted */
1178     var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1179     var_Set( p_playlist, "fullscreen", newval );
1180     pl_Release( p_playlist );
1181
1182     val.b_bool = VLC_TRUE;
1183     var_Set( p_vout, "intf-change", val );
1184     return VLC_SUCCESS;
1185 }
1186
1187 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1188                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1189 {
1190     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1191     vout_Control( p_vout, VOUT_SNAPSHOT );
1192     (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
1193     return VLC_SUCCESS;
1194 }
1195
1196 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
1197                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1198 {
1199     vout_thread_t *p_vout = (vout_thread_t *)p_this;
1200
1201     if( !strncmp( psz_cmd, "video-title-show", 16 ) )
1202         p_vout->b_title_show = newval.b_bool;
1203     else if( !strncmp( psz_cmd, "video-title-timeout", 19 ) )
1204         p_vout->i_title_timeout = (mtime_t) newval.i_int;
1205     else if( !strncmp( psz_cmd, "video-title-position", 20 ) )
1206         p_vout->i_title_position = newval.i_int;
1207     return VLC_SUCCESS;
1208 }