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