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