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