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