1 /*****************************************************************************
2 * vout_intf.c : video output interface
3 *****************************************************************************
4 * Copyright (C) 2000-2007 the VideoLAN team
6 * Authors: Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
31 #include <vlc_common.h>
34 #include <stdlib.h> /* free() */
35 #include <sys/types.h> /* opendir() */
36 #include <dirent.h> /* opendir() */
38 #include <time.h> /* strftime */
40 #include <vlc_interface.h>
41 #include <vlc_block.h>
42 #include <vlc_playlist.h>
45 #include <vlc_image.h>
47 #include <vlc_strings.h>
48 #include <vlc_charset.h>
49 #include "../libvlc.h"
50 #include "vout_internal.h"
52 /*****************************************************************************
54 *****************************************************************************/
55 /* Object variables callbacks */
56 static int ZoomCallback( vlc_object_t *, char const *,
57 vlc_value_t, vlc_value_t, void * );
58 static int CropCallback( vlc_object_t *, char const *,
59 vlc_value_t, vlc_value_t, void * );
60 static int AspectCallback( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
62 static int ScalingCallback( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
64 static int OnTopCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
66 static int FullscreenCallback( vlc_object_t *, char const *,
67 vlc_value_t, vlc_value_t, void * );
68 static int SnapshotCallback( vlc_object_t *, char const *,
69 vlc_value_t, vlc_value_t, void * );
71 static int TitleShowCallback( vlc_object_t *, char const *,
72 vlc_value_t, vlc_value_t, void * );
73 static int TitleTimeoutCallback( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
75 static int TitlePositionCallback( vlc_object_t *, char const *,
76 vlc_value_t, vlc_value_t, void * );
78 /*****************************************************************************
79 * vout_IntfInit: called during the vout creation to initialise misc things.
80 *****************************************************************************/
84 const char *psz_label;
86 { 0.25, N_("1:4 Quarter") },
87 { 0.5, N_("1:2 Half") },
88 { 1, N_("1:1 Original") },
89 { 2, N_("2:1 Double") },
94 const char *psz_value;
95 const char *psz_label;
97 { "", N_("Default") },
100 { "185:100", "1.85:1" },
101 { "221:100", "2.21:1" },
102 { "235:100", "2.35:1" },
103 { "239:100", "2.39:1" },
112 const char *psz_value;
113 const char *psz_label;
114 } p_aspect_ratio_values[] = {
115 { "", N_("Default") },
119 { "16:10", "16:10" },
120 { "221:100", "2.21:1" },
121 { "235:100", "2.35:1" },
122 { "239:100", "2.39:1" },
126 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
131 char *psz_cur = psz_list;
133 while( psz_cur && *psz_cur )
135 vlc_value_t val, text;
136 psz_next = strchr( psz_cur, ',' );
142 val.psz_string = psz_cur;
143 text.psz_string = psz_cur;
144 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
149 void vout_IntfInit( vout_thread_t *p_vout )
151 vlc_value_t val, text, old_val;
152 bool b_force_par = false;
156 /* Create a few object variables we'll need later on */
157 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
158 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
159 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
160 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
161 var_Create( p_vout, "snapshot-sequential",
162 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
163 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
164 var_SetInteger( p_vout, "snapshot-num", 1 );
165 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
166 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
168 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
169 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
170 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
172 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
173 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
175 var_Create( p_vout, "mouse-hide-timeout",
176 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
178 p_vout->p->title.show = var_CreateGetBool( p_vout, "video-title-show" );
179 p_vout->p->title.timeout = var_CreateGetInteger( p_vout,
180 "video-title-timeout" );
181 p_vout->p->title.position = var_CreateGetInteger( p_vout,
182 "video-title-position" );
183 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
184 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
185 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
187 /* Zoom object var */
188 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
189 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
191 text.psz_string = _("Zoom");
192 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
194 var_Get( p_vout, "zoom", &old_val );
196 for( i = 0; p_zoom_values[i].f_value; i++ )
198 if( old_val.f_float == p_zoom_values[i].f_value )
199 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
200 val.f_float = p_zoom_values[i].f_value;
201 text.psz_string = _( p_zoom_values[i].psz_label );
202 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
205 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
207 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
209 /* Crop offset vars */
210 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
211 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
212 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
213 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
215 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
216 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
217 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
218 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
220 /* Crop object var */
221 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
222 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
224 text.psz_string = _("Crop");
225 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
227 val.psz_string = (char*)"";
228 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
230 for( i = 0; p_crop_values[i].psz_value; i++ )
232 val.psz_string = (char*)p_crop_values[i].psz_value;
233 text.psz_string = _( p_crop_values[i].psz_label );
234 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
237 /* update triggered every time the vout's crop parameters are changed */
238 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
240 /* Add custom crop ratios */
241 psz_buf = var_CreateGetNonEmptyString( p_vout, "custom-crop-ratios" );
244 AddCustomRatios( p_vout, "crop", psz_buf );
248 var_AddCallback( p_vout, "crop", CropCallback, NULL );
249 var_Get( p_vout, "crop", &old_val );
250 if( old_val.psz_string && *old_val.psz_string )
251 var_TriggerCallback( p_vout, "crop" );
252 free( old_val.psz_string );
254 /* Monitor pixel aspect-ratio */
255 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
256 var_Get( p_vout, "monitor-par", &val );
257 if( val.psz_string && *val.psz_string )
259 char *psz_parser = strchr( val.psz_string, ':' );
260 unsigned int i_aspect_num = 0, i_aspect_den = 0;
264 i_aspect_num = strtol( val.psz_string, 0, 10 );
265 i_aspect_den = strtol( ++psz_parser, 0, 10 );
269 i_aspect = us_atof( val.psz_string );
270 vlc_ureduce( &i_aspect_num, &i_aspect_den,
271 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
273 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
275 p_vout->p->i_par_num = i_aspect_num;
276 p_vout->p->i_par_den = i_aspect_den;
278 vlc_ureduce( &p_vout->p->i_par_num, &p_vout->p->i_par_den,
279 p_vout->p->i_par_num, p_vout->p->i_par_den, 0 );
281 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
282 p_vout->p->i_par_num, p_vout->p->i_par_den );
285 free( val.psz_string );
287 /* Aspect-ratio object var */
288 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
289 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
291 text.psz_string = _("Aspect-ratio");
292 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
294 val.psz_string = (char*)"";
295 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
297 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
299 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
300 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
301 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
304 /* Add custom aspect ratios */
305 psz_buf = var_CreateGetNonEmptyString( p_vout, "custom-aspect-ratios" );
308 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
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 );
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 );
325 var_Create( p_vout, "scale", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT
326 | VLC_VAR_ISCOMMAND );
327 text.psz_string = _("Scale factor");
328 var_Change( p_vout, "scale", VLC_VAR_SETTEXT, &text, NULL );
329 var_AddCallback( p_vout, "scale", ScalingCallback, NULL );
331 /* Add a variable to indicate if the window should be on top of others */
332 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
333 | VLC_VAR_ISCOMMAND );
334 text.psz_string = _("Always on top");
335 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
336 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
338 /* Add a variable to indicate whether we want window decoration or not */
339 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
341 /* Add a fullscreen variable */
342 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
344 /* user requested fullscreen */
345 p_vout->p->i_changes |= VOUT_FULLSCREEN_CHANGE;
347 text.psz_string = _("Fullscreen");
348 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
349 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
351 /* Add a snapshot variable */
352 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
353 text.psz_string = _("Snapshot");
354 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
355 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
357 /* Mouse coordinates */
358 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
359 var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
360 var_Create( p_vout, "mouse-clicked", VLC_VAR_COORDS );
361 var_Create( p_vout, "mouse-object", VLC_VAR_BOOL );
363 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
364 var_SetBool( p_vout, "intf-change", true );
367 /*****************************************************************************
368 * vout_Snapshot: generates a snapshot.
369 *****************************************************************************/
371 * This function will inject a subpicture into the vout with the provided
374 static int VoutSnapshotPip( vout_thread_t *p_vout, picture_t *p_pic )
376 subpicture_t *p_subpic = subpicture_NewFromPicture( VLC_OBJECT(p_vout),
377 p_pic, VLC_CODEC_YUVA );
381 /* FIXME DEFAULT_CHAN is not good (used by the text) but
382 * hardcoded 0 doesn't seem right */
383 p_subpic->i_channel = 0;
384 p_subpic->i_start = mdate();
385 p_subpic->i_stop = p_subpic->i_start + 4000000;
386 p_subpic->b_ephemer = true;
387 p_subpic->b_fade = true;
389 /* Reduce the picture to 1/4^2 of the screen */
390 p_subpic->i_original_picture_width *= 4;
391 p_subpic->i_original_picture_height *= 4;
393 spu_DisplaySubpicture( vout_GetSpu( p_vout ), p_subpic );
398 * This function will display the name and a PIP of the provided snapshot
400 static void VoutOsdSnapshot( vout_thread_t *p_vout, picture_t *p_pic, const char *psz_filename )
402 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
403 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN, "%s", psz_filename );
405 if( var_GetBool( p_vout, "snapshot-preview" ) )
407 if( VoutSnapshotPip( p_vout, p_pic ) )
408 msg_Warn( p_vout, "Failed to display snapshot" );
413 int vout_GetSnapshot( vout_thread_t *p_vout,
414 block_t **pp_image, picture_t **pp_picture,
415 video_format_t *p_fmt,
416 const char *psz_format, mtime_t i_timeout )
418 picture_t *p_picture = vout_snapshot_Get( &p_vout->p->snapshot, i_timeout );
421 msg_Err( p_vout, "Failed to grab a snapshot" );
427 vlc_fourcc_t i_format = VLC_CODEC_PNG;
428 if( psz_format && image_Type2Fourcc( psz_format ) )
429 i_format = image_Type2Fourcc( psz_format );
431 const int i_override_width = var_GetInteger( p_vout, "snapshot-width" );
432 const int i_override_height = var_GetInteger( p_vout, "snapshot-height" );
434 if( picture_Export( VLC_OBJECT(p_vout), pp_image, p_fmt,
435 p_picture, i_format, i_override_width, i_override_height ) )
437 msg_Err( p_vout, "Failed to convert image for snapshot" );
438 picture_Release( p_picture );
443 *pp_picture = p_picture;
445 picture_Release( p_picture );
450 * This function will handle a snapshot request
452 static void VoutSaveSnapshot( vout_thread_t *p_vout )
454 char *psz_path = var_GetNonEmptyString( p_vout, "snapshot-path" );
455 char *psz_format = var_GetNonEmptyString( p_vout, "snapshot-format" );
456 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
459 picture_t *p_picture;
464 * XXX it will cause trouble with low fps video (< 2fps) */
465 if( vout_GetSnapshot( p_vout, &p_image, &p_picture, &fmt, psz_format, 500*1000 ) )
474 psz_path = vout_snapshot_GetDirectory();
477 msg_Err( p_vout, "no path specified for snapshots" );
482 vout_snapshot_save_cfg_t cfg;
483 memset( &cfg, 0, sizeof(cfg) );
484 cfg.is_sequential = var_GetBool( p_vout, "snapshot-sequential" );
485 cfg.sequence = var_GetInteger( p_vout, "snapshot-num" );
487 cfg.format = psz_format;
488 cfg.prefix_fmt = psz_prefix;
492 if (vout_snapshot_SaveImage( &psz_filename, &i_sequence,
493 p_image, VLC_OBJECT(p_vout), &cfg ) )
495 if( cfg.is_sequential )
496 var_SetInteger( p_vout, "snapshot-num", i_sequence + 1 );
498 VoutOsdSnapshot( p_vout, p_picture, psz_filename );
500 /* signal creation of a new snapshot file */
501 var_SetString( p_vout->p_libvlc, "snapshot-file", psz_filename );
503 free( psz_filename );
507 block_Release( p_image );
509 picture_Release( p_picture );
515 /*****************************************************************************
517 *****************************************************************************/
519 void vout_EnableFilter( vout_thread_t *p_vout, const char *psz_name,
520 bool b_add, bool b_setconfig )
524 const char *psz_filter_type;
526 /* FIXME temporary hack */
527 const char *psz_module_name = psz_name;
528 if( !strcmp( psz_name, "magnify" ) ||
529 !strcmp( psz_name, "puzzle" ) ||
530 !strcmp( psz_name, "logo" ) ||
531 !strcmp( psz_name, "wall" ) ||
532 !strcmp( psz_name, "clone" ) )
533 psz_module_name = "video_filter_wrapper";
535 module_t *p_obj = module_find( psz_module_name );
538 msg_Err( p_vout, "Unable to find filter module \"%s\".", psz_name );
542 if( module_provides( p_obj, "video filter" ) )
544 psz_filter_type = "vout-filter";
546 else if( module_provides( p_obj, "video filter2" ) )
548 psz_filter_type = "video-filter";
550 else if( module_provides( p_obj, "sub filter" ) )
552 psz_filter_type = "sub-filter";
556 module_release( p_obj );
557 msg_Err( p_vout, "Unknown video filter type." );
560 module_release( p_obj );
562 if( !strcmp( psz_filter_type, "sub-filter") )
563 psz_string = var_GetString( vout_GetSpu( p_vout ), psz_filter_type );
565 psz_string = var_GetString( p_vout, psz_filter_type );
567 /* Todo : Use some generic chain manipulation functions */
568 if( !psz_string ) psz_string = strdup("");
570 psz_parser = strstr( psz_string, psz_name );
575 psz_parser = psz_string;
576 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
577 psz_string, psz_name ) == -1 )
591 memmove( psz_parser, psz_parser + strlen(psz_name) +
592 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
593 strlen(psz_parser + strlen(psz_name)) + 1 );
595 /* Remove trailing : : */
596 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
598 *(psz_string+strlen(psz_string ) -1 ) = '\0';
610 if( !strcmp( psz_filter_type, "sub-filter") )
611 config_PutPsz( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
613 config_PutPsz( p_vout, psz_filter_type, psz_string );
616 if( !strcmp( psz_filter_type, "sub-filter") )
617 var_SetString( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
619 var_SetString( p_vout, psz_filter_type, psz_string );
624 /*****************************************************************************
625 * Object variables callbacks
626 *****************************************************************************/
627 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
628 vlc_value_t oldval, vlc_value_t newval, void *p_data )
630 (void)psz_cmd; (void)oldval; (void)p_data;
632 return var_SetFloat( p_this, "scale", newval.f_float );
635 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
636 vlc_value_t oldval, vlc_value_t newval, void *p_data )
638 vout_thread_t *p_vout = (vout_thread_t *)p_this;
639 int64_t i_aspect_num, i_aspect_den;
640 unsigned int i_width, i_height;
642 (void)oldval; (void)p_data;
644 /* Restore defaults */
645 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
646 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
647 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
648 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
650 if( !strcmp( psz_cmd, "crop" ) )
652 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
655 /* We're using the 3:4 syntax */
656 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
657 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
659 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
660 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
662 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
663 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
664 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
665 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
667 if( i_width < p_vout->fmt_render.i_visible_width )
669 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
670 (p_vout->fmt_render.i_visible_width - i_width) / 2;
671 p_vout->fmt_in.i_visible_width = i_width;
675 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
676 (p_vout->fmt_render.i_visible_height - i_height) / 2;
677 p_vout->fmt_in.i_visible_height = i_height;
682 psz_parser = strchr( newval.psz_string, 'x' );
685 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
686 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
688 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
689 if( psz_end != psz_parser ) goto crop_end;
691 psz_parser = strchr( ++psz_end, '+' );
692 i_crop_height = strtol( psz_end, &psz_end, 10 );
693 if( psz_end != psz_parser ) goto crop_end;
695 psz_parser = strchr( ++psz_end, '+' );
696 i_crop_left = strtol( psz_end, &psz_end, 10 );
697 if( psz_end != psz_parser ) goto crop_end;
700 i_crop_top = strtol( psz_end, &psz_end, 10 );
701 if( *psz_end != '\0' ) goto crop_end;
703 if( i_crop_top + i_crop_height >= p_vout->fmt_render.i_visible_height ||
704 i_crop_left + i_crop_width >= p_vout->fmt_render.i_visible_width )
706 msg_Err( p_vout, "Unable to crop over picture boundaries");
710 i_width = i_crop_width;
711 p_vout->fmt_in.i_visible_width = i_width;
713 i_height = i_crop_height;
714 p_vout->fmt_in.i_visible_height = i_height;
716 p_vout->fmt_in.i_x_offset = i_crop_left;
717 p_vout->fmt_in.i_y_offset = i_crop_top;
721 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
722 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
724 psz_parser = strchr( newval.psz_string, '+' );
725 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
726 if( psz_end != psz_parser ) goto crop_end;
728 psz_parser = strchr( ++psz_end, '+' );
729 i_crop_top = strtol( psz_end, &psz_end, 10 );
730 if( psz_end != psz_parser ) goto crop_end;
732 psz_parser = strchr( ++psz_end, '+' );
733 i_crop_right = strtol( psz_end, &psz_end, 10 );
734 if( psz_end != psz_parser ) goto crop_end;
737 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
738 if( *psz_end != '\0' ) goto crop_end;
740 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
741 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
743 msg_Err( p_vout, "Unable to crop over picture boundaries" );
747 i_width = p_vout->fmt_render.i_visible_width
748 - i_crop_left - i_crop_right;
749 p_vout->fmt_in.i_visible_width = i_width;
751 i_height = p_vout->fmt_render.i_visible_height
752 - i_crop_top - i_crop_bottom;
753 p_vout->fmt_in.i_visible_height = i_height;
755 p_vout->fmt_in.i_x_offset = i_crop_left;
756 p_vout->fmt_in.i_y_offset = i_crop_top;
760 else if( !strcmp( psz_cmd, "crop-top" )
761 || !strcmp( psz_cmd, "crop-left" )
762 || !strcmp( psz_cmd, "crop-bottom" )
763 || !strcmp( psz_cmd, "crop-right" ) )
765 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
767 i_crop_top = var_GetInteger( p_vout, "crop-top" );
768 i_crop_left = var_GetInteger( p_vout, "crop-left" );
769 i_crop_right = var_GetInteger( p_vout, "crop-right" );
770 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
772 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
773 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
775 msg_Err( p_vout, "Unable to crop over picture boundaries" );
779 i_width = p_vout->fmt_render.i_visible_width
780 - i_crop_left - i_crop_right;
781 p_vout->fmt_in.i_visible_width = i_width;
783 i_height = p_vout->fmt_render.i_visible_height
784 - i_crop_top - i_crop_bottom;
785 p_vout->fmt_in.i_visible_height = i_height;
787 p_vout->fmt_in.i_x_offset = i_crop_left;
788 p_vout->fmt_in.i_y_offset = i_crop_top;
792 p_vout->p->i_changes |= VOUT_CROP_CHANGE;
794 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
795 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
796 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
797 p_vout->fmt_in.i_visible_width,
798 p_vout->fmt_in.i_visible_height );
800 var_TriggerCallback( p_vout, "crop-update" );
805 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
806 vlc_value_t oldval, vlc_value_t newval, void *p_data )
808 vout_thread_t *p_vout = (vout_thread_t *)p_this;
809 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
812 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
813 (void)psz_cmd; (void)oldval; (void)p_data;
815 /* Restore defaults */
816 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
817 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
819 if( !psz_parser ) goto aspect_end;
821 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
822 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
824 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
825 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
827 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
828 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
829 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
830 p_vout->fmt_in.i_sar_num = i_sar_num;
831 p_vout->fmt_in.i_sar_den = i_sar_den;
834 if( p_vout->p->i_par_num && p_vout->p->i_par_den )
836 p_vout->fmt_in.i_sar_num *= p_vout->p->i_par_den;
837 p_vout->fmt_in.i_sar_den *= p_vout->p->i_par_num;
840 p_vout->p->i_changes |= VOUT_ASPECT_CHANGE;
842 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
843 p_vout->fmt_in.i_sar_num * p_vout->fmt_in.i_width,
844 p_vout->fmt_in.i_sar_den * p_vout->fmt_in.i_height,
845 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
847 if( var_Get( p_vout, "crop", &val ) )
850 int i_ret = CropCallback( p_this, "crop", val, val, 0 );
851 free( val.psz_string );
855 static int ScalingCallback( vlc_object_t *p_this, char const *psz_cmd,
856 vlc_value_t oldval, vlc_value_t newval, void *p_data )
858 vout_thread_t *p_vout = (vout_thread_t *)p_this;
859 (void)oldval; (void)newval; (void)p_data;
861 vlc_mutex_lock( &p_vout->p->change_lock );
863 if( !strcmp( psz_cmd, "autoscale" ) )
865 p_vout->p->i_changes |= VOUT_SCALE_CHANGE;
867 else if( !strcmp( psz_cmd, "scale" ) )
869 p_vout->p->i_changes |= VOUT_ZOOM_CHANGE;
872 vlc_mutex_unlock( &p_vout->p->change_lock );
877 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
878 vlc_value_t oldval, vlc_value_t newval, void *p_data )
880 vout_thread_t *p_vout = (vout_thread_t *)p_this;
882 vlc_mutex_lock( &p_vout->p->change_lock );
883 p_vout->p->i_changes |= VOUT_ON_TOP_CHANGE;
884 p_vout->p->b_on_top = newval.b_bool;
885 vlc_mutex_unlock( &p_vout->p->change_lock );
887 (void)psz_cmd; (void)oldval; (void)p_data;
891 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
892 vlc_value_t oldval, vlc_value_t newval, void *p_data )
894 vout_thread_t *p_vout = (vout_thread_t *)p_this;
896 (void)psz_cmd; (void)p_data;
898 if( oldval.b_bool == newval.b_bool )
899 return VLC_SUCCESS; /* no-op */
900 p_vout->p->i_changes |= VOUT_FULLSCREEN_CHANGE;
903 var_Set( p_vout, "intf-change", val );
907 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
908 vlc_value_t oldval, vlc_value_t newval, void *p_data )
910 vout_thread_t *p_vout = (vout_thread_t *)p_this;
911 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
912 VLC_UNUSED(newval); VLC_UNUSED(p_data);
914 VoutSaveSnapshot( p_vout );
918 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
919 vlc_value_t oldval, vlc_value_t newval, void *p_data )
921 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
923 vout_thread_t *p_vout = (vout_thread_t *)p_this;
924 p_vout->p->title.show = newval.b_bool;
928 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
929 vlc_value_t oldval, vlc_value_t newval, void *p_data )
931 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
932 vout_thread_t *p_vout = (vout_thread_t *)p_this;
933 p_vout->p->title.timeout = (mtime_t) newval.i_int;
937 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
938 vlc_value_t oldval, vlc_value_t newval, void *p_data )
940 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
942 vout_thread_t *p_vout = (vout_thread_t *)p_this;
943 p_vout->p->title.position = newval.i_int;