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