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_charset.h>
49 #include <vlc_strings.h>
50 #include <vlc_charset.h>
51 #include "../libvlc.h"
52 #include "vout_internal.h"
54 /*****************************************************************************
56 *****************************************************************************/
57 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
59 /* Object variables callbacks */
60 static int ZoomCallback( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
62 static int CropCallback( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
64 static int AspectCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
66 static int ScalingCallback( vlc_object_t *, char const *,
67 vlc_value_t, vlc_value_t, void * );
68 static int OnTopCallback( vlc_object_t *, char const *,
69 vlc_value_t, vlc_value_t, void * );
70 static int FullscreenCallback( vlc_object_t *, char const *,
71 vlc_value_t, vlc_value_t, void * );
72 static int SnapshotCallback( vlc_object_t *, char const *,
73 vlc_value_t, vlc_value_t, void * );
75 static int TitleShowCallback( vlc_object_t *, char const *,
76 vlc_value_t, vlc_value_t, void * );
77 static int TitleTimeoutCallback( vlc_object_t *, char const *,
78 vlc_value_t, vlc_value_t, void * );
79 static int TitlePositionCallback( vlc_object_t *, char const *,
80 vlc_value_t, vlc_value_t, void * );
82 /*****************************************************************************
83 * vout_IntfInit: called during the vout creation to initialise misc things.
84 *****************************************************************************/
88 const char *psz_label;
90 { 0.25, N_("1:4 Quarter") },
91 { 0.5, N_("1:2 Half") },
92 { 1, N_("1:1 Original") },
93 { 2, N_("2:1 Double") },
98 const char *psz_value;
99 const char *psz_label;
100 } p_crop_values[] = {
101 { "", N_("Default") },
102 { "16:10", "16:10" },
104 { "185:100", "1.85:1" },
105 { "221:100", "2.21:1" },
106 { "235:100", "2.35:1" },
107 { "239:100", "2.39:1" },
116 const char *psz_value;
117 const char *psz_label;
118 } p_aspect_ratio_values[] = {
119 { "", N_("Default") },
123 { "16:10", "16:10" },
124 { "221:100", "2.21:1" },
128 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
133 char *psz_cur = psz_list;
135 while( psz_cur && *psz_cur )
137 vlc_value_t val, text;
138 psz_next = strchr( psz_cur, ',' );
144 val.psz_string = psz_cur;
145 text.psz_string = psz_cur;
146 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
151 void vout_IntfInit( vout_thread_t *p_vout )
153 vlc_value_t val, text, old_val;
154 bool b_force_par = false;
158 /* Create a few object variables we'll need later on */
159 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
160 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
161 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
162 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
163 var_Create( p_vout, "snapshot-sequential",
164 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
165 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
166 var_SetInteger( p_vout, "snapshot-num", 1 );
167 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
168 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
170 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
171 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
172 p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" );
174 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
175 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
177 var_Create( p_vout, "mouse-hide-timeout",
178 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
180 p_vout->p->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
181 p_vout->p->i_title_timeout =
182 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
183 p_vout->p->i_title_position =
184 var_CreateGetInteger( p_vout, "video-title-position" );
185 p_vout->p->psz_title = NULL;
187 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
188 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
189 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
191 /* Zoom object var */
192 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
193 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
195 text.psz_string = _("Zoom");
196 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
198 var_Get( p_vout, "zoom", &old_val );
200 for( i = 0; p_zoom_values[i].f_value; i++ )
202 if( old_val.f_float == p_zoom_values[i].f_value )
203 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
204 val.f_float = p_zoom_values[i].f_value;
205 text.psz_string = _( p_zoom_values[i].psz_label );
206 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
209 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
211 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
213 /* Crop offset vars */
214 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
215 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
216 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
217 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
219 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
220 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
221 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
222 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
224 /* Crop object var */
225 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
226 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
228 text.psz_string = _("Crop");
229 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
231 val.psz_string = (char*)"";
232 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
234 for( i = 0; p_crop_values[i].psz_value; i++ )
236 val.psz_string = (char*)p_crop_values[i].psz_value;
237 text.psz_string = _( p_crop_values[i].psz_label );
238 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
241 /* update triggered every time the vout's crop parameters are changed */
242 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
244 /* Add custom crop ratios */
245 psz_buf = var_CreateGetNonEmptyString( p_vout, "custom-crop-ratios" );
248 AddCustomRatios( p_vout, "crop", psz_buf );
252 var_AddCallback( p_vout, "crop", CropCallback, NULL );
253 var_Get( p_vout, "crop", &old_val );
254 if( old_val.psz_string && *old_val.psz_string )
255 var_TriggerCallback( p_vout, "crop" );
256 free( old_val.psz_string );
258 /* Monitor pixel aspect-ratio */
259 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
260 var_Get( p_vout, "monitor-par", &val );
261 if( val.psz_string && *val.psz_string )
263 char *psz_parser = strchr( val.psz_string, ':' );
264 unsigned int i_aspect_num = 0, i_aspect_den = 0;
268 i_aspect_num = strtol( val.psz_string, 0, 10 );
269 i_aspect_den = strtol( ++psz_parser, 0, 10 );
273 i_aspect = us_atof( val.psz_string );
274 vlc_ureduce( &i_aspect_num, &i_aspect_den,
275 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
277 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
279 p_vout->p->i_par_num = i_aspect_num;
280 p_vout->p->i_par_den = i_aspect_den;
282 vlc_ureduce( &p_vout->p->i_par_num, &p_vout->p->i_par_den,
283 p_vout->p->i_par_num, p_vout->p->i_par_den, 0 );
285 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
286 p_vout->p->i_par_num, p_vout->p->i_par_den );
289 free( val.psz_string );
291 /* Aspect-ratio object var */
292 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
293 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
295 text.psz_string = _("Aspect-ratio");
296 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
298 val.psz_string = (char*)"";
299 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
301 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
303 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
304 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
305 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
308 /* Add custom aspect ratios */
309 psz_buf = var_CreateGetNonEmptyString( p_vout, "custom-aspect-ratios" );
312 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
316 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
317 var_Get( p_vout, "aspect-ratio", &old_val );
318 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
319 var_TriggerCallback( p_vout, "aspect-ratio" );
320 free( old_val.psz_string );
322 /* Add variables to manage scaling video */
323 var_Create( p_vout, "autoscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
324 | VLC_VAR_ISCOMMAND );
325 text.psz_string = _("Autoscale video");
326 var_Change( p_vout, "autoscale", VLC_VAR_SETTEXT, &text, NULL );
327 var_AddCallback( p_vout, "autoscale", ScalingCallback, NULL );
328 p_vout->b_autoscale = var_GetBool( p_vout, "autoscale" );
330 var_Create( p_vout, "scale", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT
331 | VLC_VAR_ISCOMMAND );
332 text.psz_string = _("Scale factor");
333 var_Change( p_vout, "scale", VLC_VAR_SETTEXT, &text, NULL );
334 var_AddCallback( p_vout, "scale", ScalingCallback, NULL );
335 p_vout->i_zoom = (int)( ZOOM_FP_FACTOR * var_GetFloat( p_vout, "scale" ) );
337 /* Initialize the dimensions of the video window */
338 InitWindowSize( p_vout, &p_vout->i_window_width,
339 &p_vout->i_window_height );
341 /* Add a variable to indicate if the window should be on top of others */
342 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
343 | VLC_VAR_ISCOMMAND );
344 text.psz_string = _("Always on top");
345 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
346 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
348 /* Add a variable to indicate whether we want window decoration or not */
349 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
351 /* Add a fullscreen variable */
352 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
354 /* user requested fullscreen */
355 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
357 text.psz_string = _("Fullscreen");
358 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
359 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
361 /* Add a snapshot variable */
362 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
363 text.psz_string = _("Snapshot");
364 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
365 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
367 /* Mouse coordinates */
368 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
369 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
370 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
371 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
372 var_Create( p_vout, "mouse-clicked", VLC_VAR_BOOL );
374 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
375 var_SetBool( p_vout, "intf-change", true );
378 /*****************************************************************************
379 * vout_Snapshot: generates a snapshot.
380 *****************************************************************************/
382 * This function will inject a subpicture into the vout with the provided
385 static int VoutSnapshotPip( vout_thread_t *p_vout, picture_t *p_pic )
387 subpicture_t *p_subpic = subpicture_NewFromPicture( VLC_OBJECT(p_vout),
388 p_pic, VLC_CODEC_YUVA );
392 /* FIXME DEFAULT_CHAN is not good (used by the text) but
393 * hardcoded 0 doesn't seem right */
394 p_subpic->i_channel = 0;
395 p_subpic->i_start = mdate();
396 p_subpic->i_stop = p_subpic->i_start + 4000000;
397 p_subpic->b_ephemer = true;
398 p_subpic->b_fade = true;
400 /* Reduce the picture to 1/4^2 of the screen */
401 p_subpic->i_original_picture_width *= 4;
402 p_subpic->i_original_picture_height *= 4;
404 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
409 * This function will display the name and a PIP of the provided snapshot
411 static void VoutOsdSnapshot( vout_thread_t *p_vout, picture_t *p_pic, const char *psz_filename )
413 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
414 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN, "%s", psz_filename );
416 if( var_GetBool( p_vout, "snapshot-preview" ) )
418 if( VoutSnapshotPip( p_vout, p_pic ) )
419 msg_Warn( p_vout, "Failed to display snapshot" );
424 int vout_GetSnapshot( vout_thread_t *p_vout,
425 block_t **pp_image, picture_t **pp_picture,
426 video_format_t *p_fmt,
427 const char *psz_format, mtime_t i_timeout )
429 picture_t *p_picture = vout_snapshot_Get( &p_vout->p->snapshot, i_timeout );
432 msg_Err( p_vout, "Failed to grab a snapshot" );
438 vlc_fourcc_t i_format = VLC_CODEC_PNG;
439 if( psz_format && image_Type2Fourcc( psz_format ) )
440 i_format = image_Type2Fourcc( psz_format );
442 const int i_override_width = var_GetInteger( p_vout, "snapshot-width" );
443 const int i_override_height = var_GetInteger( p_vout, "snapshot-height" );
445 if( picture_Export( VLC_OBJECT(p_vout), pp_image, p_fmt,
446 p_picture, i_format, i_override_width, i_override_height ) )
448 msg_Err( p_vout, "Failed to convert image for snapshot" );
449 picture_Release( p_picture );
454 *pp_picture = p_picture;
456 picture_Release( p_picture );
461 * This function will handle a snapshot request
463 static void VoutSaveSnapshot( vout_thread_t *p_vout )
465 char *psz_path = var_GetNonEmptyString( p_vout, "snapshot-path" );
466 char *psz_format = var_GetNonEmptyString( p_vout, "snapshot-format" );
467 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
470 picture_t *p_picture;
475 * XXX it will cause trouble with low fps video (< 2fps) */
476 if( vout_GetSnapshot( p_vout, &p_image, &p_picture, &fmt, psz_format, 500*1000 ) )
485 psz_path = vout_snapshot_GetDirectory();
488 msg_Err( p_vout, "no path specified for snapshots" );
493 vout_snapshot_save_cfg_t cfg;
494 memset( &cfg, 0, sizeof(cfg) );
495 cfg.is_sequential = var_GetBool( p_vout, "snapshot-sequential" );
496 cfg.sequence = var_GetInteger( p_vout, "snapshot-num" );
498 cfg.format = psz_format;
499 cfg.prefix_fmt = psz_prefix;
503 if (vout_snapshot_SaveImage( &psz_filename, &i_sequence,
504 p_image, VLC_OBJECT(p_vout), &cfg ) )
506 if( cfg.is_sequential )
507 var_SetInteger( p_vout, "snapshot-num", i_sequence + 1 );
509 VoutOsdSnapshot( p_vout, p_picture, psz_filename );
511 /* signal creation of a new snapshot file */
512 var_SetString( p_vout->p_libvlc, "snapshot-file", psz_filename );
514 free( psz_filename );
518 block_Release( p_image );
520 picture_Release( p_picture );
526 /*****************************************************************************
528 *****************************************************************************/
530 void vout_EnableFilter( vout_thread_t *p_vout, const char *psz_name,
531 bool b_add, bool b_setconfig )
535 const char *psz_filter_type;
537 /* FIXME temporary hack */
538 const char *psz_module_name = psz_name;
539 if( !strcmp( psz_name, "magnify" ) ||
540 !strcmp( psz_name, "puzzle" ) ||
541 !strcmp( psz_name, "logo" ) ||
542 !strcmp( psz_name, "wall" ) ||
543 !strcmp( psz_name, "clone" ) )
544 psz_module_name = "video_filter_wrapper";
546 module_t *p_obj = module_find( psz_module_name );
549 msg_Err( p_vout, "Unable to find filter module \"%s\".", psz_name );
553 if( module_provides( p_obj, "video filter" ) )
555 psz_filter_type = "vout-filter";
557 else if( module_provides( p_obj, "video filter2" ) )
559 psz_filter_type = "video-filter";
561 else if( module_provides( p_obj, "sub filter" ) )
563 psz_filter_type = "sub-filter";
567 module_release( p_obj );
568 msg_Err( p_vout, "Unknown video filter type." );
571 module_release( p_obj );
573 if( !strcmp( psz_filter_type, "sub-filter") )
574 psz_string = var_GetString( vout_GetSpu( p_vout ), psz_filter_type );
576 psz_string = var_GetString( p_vout, psz_filter_type );
578 /* Todo : Use some generic chain manipulation functions */
579 if( !psz_string ) psz_string = strdup("");
581 psz_parser = strstr( psz_string, psz_name );
586 psz_parser = psz_string;
587 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
588 psz_string, psz_name ) == -1 )
602 memmove( psz_parser, psz_parser + strlen(psz_name) +
603 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
604 strlen(psz_parser + strlen(psz_name)) + 1 );
606 /* Remove trailing : : */
607 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
609 *(psz_string+strlen(psz_string ) -1 ) = '\0';
621 if( !strcmp( psz_filter_type, "sub-filter") )
622 config_PutPsz( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
624 config_PutPsz( p_vout, psz_filter_type, psz_string );
627 if( !strcmp( psz_filter_type, "sub-filter") )
628 var_SetString( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
630 var_SetString( p_vout, psz_filter_type, psz_string );
635 /*****************************************************************************
636 * InitWindowSize: find the initial dimensions the video window should have.
637 *****************************************************************************
638 * This function will check the "width", "height" and "zoom" config options and
639 * will calculate the size that the video window should have.
640 *****************************************************************************/
641 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
642 unsigned *pi_height )
644 #define FP_FACTOR 1000 /* our fixed point factor */
646 int i_width = var_GetInteger( p_vout, "width" );
647 int i_height = var_GetInteger( p_vout, "height" );
648 float f_zoom = var_GetFloat( p_vout, "zoom" );
649 uint64_t ll_zoom = (uint64_t)( FP_FACTOR * f_zoom );
651 if( i_width > 0 && i_height > 0)
653 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
654 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
656 else if( i_width > 0 )
658 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
659 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
660 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
661 FP_FACTOR / p_vout->fmt_in.i_visible_width );
663 else if( i_height > 0 )
665 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
666 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
667 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
668 FP_FACTOR / p_vout->fmt_in.i_visible_height );
670 else if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 )
672 msg_Warn( p_vout, "aspect ratio screwed up" );
673 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
674 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
676 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
678 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
679 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
680 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
685 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
687 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
688 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
691 msg_Dbg( p_vout, "window size: %ux%u", *pi_width, *pi_height );
696 /*****************************************************************************
697 * Object variables callbacks
698 *****************************************************************************/
699 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
700 vlc_value_t oldval, vlc_value_t newval, void *p_data )
702 return var_SetFloat( p_this, "scale", newval.f_float );
705 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
706 vlc_value_t oldval, vlc_value_t newval, void *p_data )
708 vout_thread_t *p_vout = (vout_thread_t *)p_this;
709 int64_t i_aspect_num, i_aspect_den;
710 unsigned int i_width, i_height;
712 (void)oldval; (void)p_data;
714 /* Restore defaults */
715 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
716 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
717 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
718 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
720 if( !strcmp( psz_cmd, "crop" ) )
722 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
725 /* We're using the 3:4 syntax */
726 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
727 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
729 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
730 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
732 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
733 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
734 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
735 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
737 if( i_width < p_vout->fmt_render.i_visible_width )
739 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
740 (p_vout->fmt_render.i_visible_width - i_width) / 2;
741 p_vout->fmt_in.i_visible_width = i_width;
745 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
746 (p_vout->fmt_render.i_visible_height - i_height) / 2;
747 p_vout->fmt_in.i_visible_height = i_height;
752 psz_parser = strchr( newval.psz_string, 'x' );
755 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
756 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
758 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
759 if( psz_end != psz_parser ) goto crop_end;
761 psz_parser = strchr( ++psz_end, '+' );
762 i_crop_height = strtol( psz_end, &psz_end, 10 );
763 if( psz_end != psz_parser ) goto crop_end;
765 psz_parser = strchr( ++psz_end, '+' );
766 i_crop_left = strtol( psz_end, &psz_end, 10 );
767 if( psz_end != psz_parser ) goto crop_end;
770 i_crop_top = strtol( psz_end, &psz_end, 10 );
771 if( *psz_end != '\0' ) goto crop_end;
773 if( i_crop_top + i_crop_height >= p_vout->fmt_render.i_visible_height ||
774 i_crop_left + i_crop_width >= p_vout->fmt_render.i_visible_width )
776 msg_Err( p_vout, "Unable to crop over picture boundaries");
780 i_width = i_crop_width;
781 p_vout->fmt_in.i_visible_width = i_width;
783 i_height = i_crop_height;
784 p_vout->fmt_in.i_visible_height = i_height;
786 p_vout->fmt_in.i_x_offset = i_crop_left;
787 p_vout->fmt_in.i_y_offset = i_crop_top;
791 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
792 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
794 psz_parser = strchr( newval.psz_string, '+' );
795 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
796 if( psz_end != psz_parser ) goto crop_end;
798 psz_parser = strchr( ++psz_end, '+' );
799 i_crop_top = strtol( psz_end, &psz_end, 10 );
800 if( psz_end != psz_parser ) goto crop_end;
802 psz_parser = strchr( ++psz_end, '+' );
803 i_crop_right = strtol( psz_end, &psz_end, 10 );
804 if( psz_end != psz_parser ) goto crop_end;
807 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
808 if( *psz_end != '\0' ) goto crop_end;
810 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
811 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
813 msg_Err( p_vout, "Unable to crop over picture boundaries" );
817 i_width = p_vout->fmt_render.i_visible_width
818 - i_crop_left - i_crop_right;
819 p_vout->fmt_in.i_visible_width = i_width;
821 i_height = p_vout->fmt_render.i_visible_height
822 - i_crop_top - i_crop_bottom;
823 p_vout->fmt_in.i_visible_height = i_height;
825 p_vout->fmt_in.i_x_offset = i_crop_left;
826 p_vout->fmt_in.i_y_offset = i_crop_top;
830 else if( !strcmp( psz_cmd, "crop-top" )
831 || !strcmp( psz_cmd, "crop-left" )
832 || !strcmp( psz_cmd, "crop-bottom" )
833 || !strcmp( psz_cmd, "crop-right" ) )
835 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
837 i_crop_top = var_GetInteger( p_vout, "crop-top" );
838 i_crop_left = var_GetInteger( p_vout, "crop-left" );
839 i_crop_right = var_GetInteger( p_vout, "crop-right" );
840 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
842 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
843 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
845 msg_Err( p_vout, "Unable to crop over picture boundaries" );
849 i_width = p_vout->fmt_render.i_visible_width
850 - i_crop_left - i_crop_right;
851 p_vout->fmt_in.i_visible_width = i_width;
853 i_height = p_vout->fmt_render.i_visible_height
854 - i_crop_top - i_crop_bottom;
855 p_vout->fmt_in.i_visible_height = i_height;
857 p_vout->fmt_in.i_x_offset = i_crop_left;
858 p_vout->fmt_in.i_y_offset = i_crop_top;
862 InitWindowSize( p_vout, &p_vout->i_window_width,
863 &p_vout->i_window_height );
865 p_vout->i_changes |= VOUT_CROP_CHANGE;
867 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
868 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
869 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
870 p_vout->fmt_in.i_visible_width,
871 p_vout->fmt_in.i_visible_height );
873 var_TriggerCallback( p_vout, "crop-update" );
878 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
879 vlc_value_t oldval, vlc_value_t newval, void *p_data )
881 vout_thread_t *p_vout = (vout_thread_t *)p_this;
882 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
885 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
886 (void)psz_cmd; (void)oldval; (void)p_data;
888 /* Restore defaults */
889 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
890 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
891 p_vout->render.i_aspect = (int64_t)p_vout->fmt_render.i_sar_num *
892 p_vout->fmt_render.i_width *
894 p_vout->fmt_render.i_sar_den / p_vout->fmt_render.i_height;
896 if( !psz_parser ) goto aspect_end;
898 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
899 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
901 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
902 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
904 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
905 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
906 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
907 p_vout->fmt_in.i_sar_num = i_sar_num;
908 p_vout->fmt_in.i_sar_den = i_sar_den;
909 p_vout->render.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
912 if( p_vout->p->i_par_num && p_vout->p->i_par_den )
914 p_vout->fmt_in.i_sar_num *= p_vout->p->i_par_den;
915 p_vout->fmt_in.i_sar_den *= p_vout->p->i_par_num;
916 p_vout->render.i_aspect = (int64_t)p_vout->fmt_in.i_sar_num *
917 p_vout->fmt_in.i_width *
919 p_vout->fmt_in.i_sar_den /
920 p_vout->fmt_in.i_height;
923 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
925 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
926 p_vout->fmt_in.i_sar_num * p_vout->fmt_in.i_width,
927 p_vout->fmt_in.i_sar_den * p_vout->fmt_in.i_height,
928 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
930 if( var_Get( p_vout, "crop", &val ) )
933 int i_ret = CropCallback( p_this, "crop", val, val, 0 );
934 free( val.psz_string );
938 static int ScalingCallback( vlc_object_t *p_this, char const *psz_cmd,
939 vlc_value_t oldval, vlc_value_t newval, void *p_data )
941 vout_thread_t *p_vout = (vout_thread_t *)p_this;
942 (void)oldval; (void)newval; (void)p_data;
944 vlc_mutex_lock( &p_vout->change_lock );
946 if( !strcmp( psz_cmd, "autoscale" ) )
948 p_vout->i_changes |= VOUT_SCALE_CHANGE;
950 else if( !strcmp( psz_cmd, "scale" ) )
952 p_vout->i_changes |= VOUT_ZOOM_CHANGE;
955 vlc_mutex_unlock( &p_vout->change_lock );
960 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
961 vlc_value_t oldval, vlc_value_t newval, void *p_data )
963 vout_thread_t *p_vout = (vout_thread_t *)p_this;
965 vlc_mutex_lock( &p_vout->change_lock );
966 p_vout->i_changes |= VOUT_ON_TOP_CHANGE;
967 p_vout->b_on_top = newval.b_bool;
968 vlc_mutex_unlock( &p_vout->change_lock );
970 /* Modify libvlc as well because the vout might have to be restarted */
971 var_Create( p_vout->p_libvlc, "video-on-top", VLC_VAR_BOOL );
972 var_Set( p_vout->p_libvlc, "video-on-top", newval );
974 (void)psz_cmd; (void)oldval; (void)p_data;
978 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
979 vlc_value_t oldval, vlc_value_t newval, void *p_data )
981 vout_thread_t *p_vout = (vout_thread_t *)p_this;
983 (void)psz_cmd; (void)oldval; (void)p_data;
985 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
987 /* Modify libvlc as well because the vout might have to be restarted */
988 var_Create( p_vout->p_libvlc, "fullscreen", VLC_VAR_BOOL );
989 var_Set( p_vout->p_libvlc, "fullscreen", newval );
992 var_Set( p_vout, "intf-change", val );
996 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
997 vlc_value_t oldval, vlc_value_t newval, void *p_data )
999 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1000 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1001 VLC_UNUSED(newval); VLC_UNUSED(p_data);
1003 VoutSaveSnapshot( p_vout );
1007 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1008 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1010 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1012 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1013 p_vout->p->b_title_show = newval.b_bool;
1017 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
1018 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1020 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1021 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1022 p_vout->p->i_title_timeout = (mtime_t) newval.i_int;
1026 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1027 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1029 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1031 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1032 p_vout->p->i_title_position = newval.i_int;