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() */
37 #include <dirent.h> /* opendir() */
39 #include <time.h> /* strftime */
41 #include <vlc_interface.h>
42 #include <vlc_block.h>
43 #include <vlc_playlist.h>
46 #include <vlc_image.h>
48 #include <vlc_charset.h>
50 #include <vlc_strings.h>
51 #include <vlc_charset.h>
52 #include "../libvlc.h"
53 #include "vout_internal.h"
55 /*****************************************************************************
57 *****************************************************************************/
58 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
60 /* Object variables callbacks */
61 static int ZoomCallback( vlc_object_t *, char const *,
62 vlc_value_t, vlc_value_t, void * );
63 static int CropCallback( vlc_object_t *, char const *,
64 vlc_value_t, vlc_value_t, void * );
65 static int AspectCallback( vlc_object_t *, char const *,
66 vlc_value_t, vlc_value_t, void * );
67 static int ScalingCallback( vlc_object_t *, char const *,
68 vlc_value_t, vlc_value_t, void * );
69 static int OnTopCallback( vlc_object_t *, char const *,
70 vlc_value_t, vlc_value_t, void * );
71 static int FullscreenCallback( vlc_object_t *, char const *,
72 vlc_value_t, vlc_value_t, void * );
73 static int SnapshotCallback( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
76 static int TitleShowCallback( vlc_object_t *, char const *,
77 vlc_value_t, vlc_value_t, void * );
78 static int TitleTimeoutCallback( vlc_object_t *, char const *,
79 vlc_value_t, vlc_value_t, void * );
80 static int TitlePositionCallback( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
83 /*****************************************************************************
84 * vout_IntfInit: called during the vout creation to initialise misc things.
85 *****************************************************************************/
89 const char *psz_label;
91 { 0.25, N_("1:4 Quarter") },
92 { 0.5, N_("1:2 Half") },
93 { 1, N_("1:1 Original") },
94 { 2, N_("2:1 Double") },
99 const char *psz_value;
100 const char *psz_label;
101 } p_crop_values[] = {
102 { "", N_("Default") },
103 { "16:10", "16:10" },
105 { "185:100", "1.85:1" },
106 { "221:100", "2.21:1" },
107 { "235:100", "2.35:1" },
108 { "239:100", "2.39:1" },
117 const char *psz_value;
118 const char *psz_label;
119 } p_aspect_ratio_values[] = {
120 { "", N_("Default") },
124 { "16:10", "16:10" },
125 { "221:100", "2.21:1" },
129 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
134 char *psz_cur = psz_list;
136 while( psz_cur && *psz_cur )
138 vlc_value_t val, text;
139 psz_next = strchr( psz_cur, ',' );
145 val.psz_string = psz_cur;
146 text.psz_string = psz_cur;
147 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
152 void vout_IntfInit( vout_thread_t *p_vout )
154 vlc_value_t val, text, old_val;
155 bool b_force_par = false;
159 /* Create a few object variables we'll need later on */
160 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
161 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
162 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
163 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
164 var_Create( p_vout, "snapshot-sequential",
165 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
166 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
167 var_SetInteger( p_vout, "snapshot-num", 1 );
168 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
169 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
171 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
172 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
173 p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" );
175 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
176 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
178 var_Create( p_vout, "mouse-hide-timeout",
179 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
181 p_vout->p->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
182 p_vout->p->i_title_timeout =
183 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
184 p_vout->p->i_title_position =
185 var_CreateGetInteger( p_vout, "video-title-position" );
186 p_vout->p->psz_title = NULL;
188 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
189 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
190 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
192 /* Zoom object var */
193 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
194 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
196 text.psz_string = _("Zoom");
197 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
199 var_Get( p_vout, "zoom", &old_val );
201 for( i = 0; p_zoom_values[i].f_value; i++ )
203 if( old_val.f_float == p_zoom_values[i].f_value )
204 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
205 val.f_float = p_zoom_values[i].f_value;
206 text.psz_string = _( p_zoom_values[i].psz_label );
207 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
210 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
212 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
214 /* Crop offset vars */
215 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
216 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
217 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
218 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
220 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
221 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
222 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
223 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
225 /* Crop object var */
226 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
227 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
229 text.psz_string = _("Crop");
230 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
232 val.psz_string = (char*)"";
233 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
235 for( i = 0; p_crop_values[i].psz_value; i++ )
237 val.psz_string = (char*)p_crop_values[i].psz_value;
238 text.psz_string = _( p_crop_values[i].psz_label );
239 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
242 /* update triggered every time the vout's crop parameters are changed */
243 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
245 /* Add custom crop ratios */
246 psz_buf = var_CreateGetNonEmptyString( p_vout, "custom-crop-ratios" );
249 AddCustomRatios( p_vout, "crop", psz_buf );
253 var_AddCallback( p_vout, "crop", CropCallback, NULL );
254 var_Get( p_vout, "crop", &old_val );
255 if( old_val.psz_string && *old_val.psz_string )
256 var_TriggerCallback( p_vout, "crop" );
257 free( old_val.psz_string );
259 /* Monitor pixel aspect-ratio */
260 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
261 var_Get( p_vout, "monitor-par", &val );
262 if( val.psz_string && *val.psz_string )
264 char *psz_parser = strchr( val.psz_string, ':' );
265 unsigned int i_aspect_num = 0, i_aspect_den = 0;
269 i_aspect_num = strtol( val.psz_string, 0, 10 );
270 i_aspect_den = strtol( ++psz_parser, 0, 10 );
274 i_aspect = us_atof( val.psz_string );
275 vlc_ureduce( &i_aspect_num, &i_aspect_den,
276 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
278 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
280 p_vout->p->i_par_num = i_aspect_num;
281 p_vout->p->i_par_den = i_aspect_den;
283 vlc_ureduce( &p_vout->p->i_par_num, &p_vout->p->i_par_den,
284 p_vout->p->i_par_num, p_vout->p->i_par_den, 0 );
286 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
287 p_vout->p->i_par_num, p_vout->p->i_par_den );
290 free( val.psz_string );
292 /* Aspect-ratio object var */
293 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
294 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
296 text.psz_string = _("Aspect-ratio");
297 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
299 val.psz_string = (char*)"";
300 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
302 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
304 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
305 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
306 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
309 /* Add custom aspect ratios */
310 psz_buf = var_CreateGetNonEmptyString( p_vout, "custom-aspect-ratios" );
313 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
317 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
318 var_Get( p_vout, "aspect-ratio", &old_val );
319 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
320 var_TriggerCallback( p_vout, "aspect-ratio" );
321 free( old_val.psz_string );
323 /* Add variables to manage scaling video */
324 var_Create( p_vout, "autoscale", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
325 | VLC_VAR_ISCOMMAND );
326 text.psz_string = _("Autoscale video");
327 var_Change( p_vout, "autoscale", VLC_VAR_SETTEXT, &text, NULL );
328 var_AddCallback( p_vout, "autoscale", ScalingCallback, NULL );
329 p_vout->b_autoscale = var_GetBool( p_vout, "autoscale" );
331 var_Create( p_vout, "scale", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT
332 | VLC_VAR_ISCOMMAND );
333 text.psz_string = _("Scale factor");
334 var_Change( p_vout, "scale", VLC_VAR_SETTEXT, &text, NULL );
335 var_AddCallback( p_vout, "scale", ScalingCallback, NULL );
336 p_vout->i_zoom = (int)( ZOOM_FP_FACTOR * var_GetFloat( p_vout, "scale" ) );
338 /* Initialize the dimensions of the video window */
339 InitWindowSize( p_vout, &p_vout->i_window_width,
340 &p_vout->i_window_height );
342 /* Add a variable to indicate if the window should be on top of others */
343 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
344 | VLC_VAR_ISCOMMAND );
345 text.psz_string = _("Always on top");
346 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
347 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
349 /* Add a variable to indicate whether we want window decoration or not */
350 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
352 /* Add a fullscreen variable */
353 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
355 /* user requested fullscreen */
356 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
358 text.psz_string = _("Fullscreen");
359 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
360 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
362 /* Add a snapshot variable */
363 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
364 text.psz_string = _("Snapshot");
365 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
366 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
368 /* Mouse coordinates */
369 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
370 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
371 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
372 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
373 var_Create( p_vout, "mouse-clicked", VLC_VAR_BOOL );
375 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
376 var_SetBool( p_vout, "intf-change", true );
379 /*****************************************************************************
380 * vout_Snapshot: generates a snapshot.
381 *****************************************************************************/
383 * This function will inject a subpicture into the vout with the provided
386 static int VoutSnapshotPip( vout_thread_t *p_vout, picture_t *p_pic )
388 subpicture_t *p_subpic = subpicture_NewFromPicture( VLC_OBJECT(p_vout),
389 p_pic, VLC_CODEC_YUVA );
393 /* FIXME DEFAULT_CHAN is not good (used by the text) but
394 * hardcoded 0 doesn't seem right */
395 p_subpic->i_channel = 0;
396 p_subpic->i_start = mdate();
397 p_subpic->i_stop = p_subpic->i_start + 4000000;
398 p_subpic->b_ephemer = true;
399 p_subpic->b_fade = true;
401 /* Reduce the picture to 1/4^2 of the screen */
402 p_subpic->i_original_picture_width *= 4;
403 p_subpic->i_original_picture_height *= 4;
405 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
410 * This function will display the name and a PIP of the provided snapshot
412 static void VoutOsdSnapshot( vout_thread_t *p_vout, picture_t *p_pic, const char *psz_filename )
414 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
415 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN, "%s", psz_filename );
417 if( var_GetBool( p_vout, "snapshot-preview" ) )
419 if( VoutSnapshotPip( p_vout, p_pic ) )
420 msg_Warn( p_vout, "Failed to display snapshot" );
425 int vout_GetSnapshot( vout_thread_t *p_vout,
426 block_t **pp_image, picture_t **pp_picture,
427 video_format_t *p_fmt,
428 const char *psz_format, mtime_t i_timeout )
430 picture_t *p_picture = vout_snapshot_Get( &p_vout->p->snapshot, i_timeout );
433 msg_Err( p_vout, "Failed to grab a snapshot" );
439 vlc_fourcc_t i_format = VLC_CODEC_PNG;
440 if( psz_format && image_Type2Fourcc( psz_format ) )
441 i_format = image_Type2Fourcc( psz_format );
443 const int i_override_width = var_GetInteger( p_vout, "snapshot-width" );
444 const int i_override_height = var_GetInteger( p_vout, "snapshot-height" );
446 if( picture_Export( VLC_OBJECT(p_vout), pp_image, p_fmt,
447 p_picture, i_format, i_override_width, i_override_height ) )
449 msg_Err( p_vout, "Failed to convert image for snapshot" );
450 picture_Release( p_picture );
455 *pp_picture = p_picture;
457 picture_Release( p_picture );
462 * This function will handle a snapshot request
464 static void VoutSaveSnapshot( vout_thread_t *p_vout )
466 char *psz_path = var_GetNonEmptyString( p_vout, "snapshot-path" );
467 char *psz_format = var_GetNonEmptyString( p_vout, "snapshot-format" );
468 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
471 picture_t *p_picture;
476 * XXX it will cause trouble with low fps video (< 2fps) */
477 if( vout_GetSnapshot( p_vout, &p_image, &p_picture, &fmt, psz_format, 500*1000 ) )
486 psz_path = vout_snapshot_GetDirectory();
489 msg_Err( p_vout, "no path specified for snapshots" );
494 vout_snapshot_save_cfg_t cfg;
495 memset( &cfg, 0, sizeof(cfg) );
496 cfg.is_sequential = var_GetBool( p_vout, "snapshot-sequential" );
497 cfg.sequence = var_GetInteger( p_vout, "snapshot-num" );
499 cfg.format = psz_format;
500 cfg.prefix_fmt = psz_prefix;
504 if (vout_snapshot_SaveImage( &psz_filename, &i_sequence,
505 p_image, VLC_OBJECT(p_vout), &cfg ) )
507 if( cfg.is_sequential )
508 var_SetInteger( p_vout, "snapshot-num", i_sequence + 1 );
510 VoutOsdSnapshot( p_vout, p_picture, psz_filename );
512 /* signal creation of a new snapshot file */
513 var_SetString( p_vout->p_libvlc, "snapshot-file", psz_filename );
515 free( psz_filename );
519 block_Release( p_image );
521 picture_Release( p_picture );
527 /*****************************************************************************
529 *****************************************************************************/
531 void vout_EnableFilter( vout_thread_t *p_vout, const char *psz_name,
532 bool b_add, bool b_setconfig )
536 const char *psz_filter_type;
538 /* FIXME temporary hack */
539 const char *psz_module_name = psz_name;
540 if( !strcmp( psz_name, "magnify" ) ||
541 !strcmp( psz_name, "puzzle" ) ||
542 !strcmp( psz_name, "logo" ) ||
543 !strcmp( psz_name, "wall" ) ||
544 !strcmp( psz_name, "clone" ) )
545 psz_module_name = "video_filter_wrapper";
547 module_t *p_obj = module_find( psz_module_name );
550 msg_Err( p_vout, "Unable to find filter module \"%s\".", psz_name );
554 if( module_provides( p_obj, "video filter" ) )
556 psz_filter_type = "vout-filter";
558 else if( module_provides( p_obj, "video filter2" ) )
560 psz_filter_type = "video-filter";
562 else if( module_provides( p_obj, "sub filter" ) )
564 psz_filter_type = "sub-filter";
568 module_release( p_obj );
569 msg_Err( p_vout, "Unknown video filter type." );
572 module_release( p_obj );
574 if( !strcmp( psz_filter_type, "sub-filter") )
575 psz_string = var_GetString( vout_GetSpu( p_vout ), psz_filter_type );
577 psz_string = var_GetString( p_vout, psz_filter_type );
579 /* Todo : Use some generic chain manipulation functions */
580 if( !psz_string ) psz_string = strdup("");
582 psz_parser = strstr( psz_string, psz_name );
587 psz_parser = psz_string;
588 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
589 psz_string, psz_name ) == -1 )
603 memmove( psz_parser, psz_parser + strlen(psz_name) +
604 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
605 strlen(psz_parser + strlen(psz_name)) + 1 );
607 /* Remove trailing : : */
608 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
610 *(psz_string+strlen(psz_string ) -1 ) = '\0';
622 if( !strcmp( psz_filter_type, "sub-filter") )
623 config_PutPsz( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
625 config_PutPsz( p_vout, psz_filter_type, psz_string );
628 if( !strcmp( psz_filter_type, "sub-filter") )
629 var_SetString( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
631 var_SetString( p_vout, psz_filter_type, psz_string );
636 /*****************************************************************************
637 * InitWindowSize: find the initial dimensions the video window should have.
638 *****************************************************************************
639 * This function will check the "width", "height" and "zoom" config options and
640 * will calculate the size that the video window should have.
641 *****************************************************************************/
642 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
643 unsigned *pi_height )
645 #define FP_FACTOR 1000 /* our fixed point factor */
647 int i_width = var_GetInteger( p_vout, "width" );
648 int i_height = var_GetInteger( p_vout, "height" );
649 float f_zoom = var_GetFloat( p_vout, "zoom" );
650 uint64_t ll_zoom = (uint64_t)( FP_FACTOR * f_zoom );
652 if( i_width > 0 && i_height > 0)
654 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
655 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
657 else if( i_width > 0 )
659 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
660 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
661 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
662 FP_FACTOR / p_vout->fmt_in.i_visible_width );
664 else if( i_height > 0 )
666 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
667 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
668 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
669 FP_FACTOR / p_vout->fmt_in.i_visible_height );
671 else if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 )
673 msg_Warn( p_vout, "aspect ratio screwed up" );
674 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
675 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
677 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
679 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
680 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
681 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
686 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
688 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
689 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
692 msg_Dbg( p_vout, "window size: %ux%u", *pi_width, *pi_height );
697 /*****************************************************************************
698 * Object variables callbacks
699 *****************************************************************************/
700 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
701 vlc_value_t oldval, vlc_value_t newval, void *p_data )
703 vout_thread_t *p_vout = (vout_thread_t *)p_this;
704 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
705 InitWindowSize( p_vout, &p_vout->i_window_width,
706 &p_vout->i_window_height );
707 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
708 p_vout->i_window_height );
712 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
713 vlc_value_t oldval, vlc_value_t newval, void *p_data )
715 vout_thread_t *p_vout = (vout_thread_t *)p_this;
716 int64_t i_aspect_num, i_aspect_den;
717 unsigned int i_width, i_height;
719 (void)oldval; (void)p_data;
721 /* Restore defaults */
722 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
723 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
724 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
725 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
727 if( !strcmp( psz_cmd, "crop" ) )
729 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
732 /* We're using the 3:4 syntax */
733 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
734 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
736 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
737 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
739 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
740 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
741 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
742 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
744 if( i_width < p_vout->fmt_render.i_visible_width )
746 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
747 (p_vout->fmt_render.i_visible_width - i_width) / 2;
748 p_vout->fmt_in.i_visible_width = i_width;
752 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
753 (p_vout->fmt_render.i_visible_height - i_height) / 2;
754 p_vout->fmt_in.i_visible_height = i_height;
759 psz_parser = strchr( newval.psz_string, 'x' );
762 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
763 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
765 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
766 if( psz_end != psz_parser ) goto crop_end;
768 psz_parser = strchr( ++psz_end, '+' );
769 i_crop_height = strtol( psz_end, &psz_end, 10 );
770 if( psz_end != psz_parser ) goto crop_end;
772 psz_parser = strchr( ++psz_end, '+' );
773 i_crop_left = strtol( psz_end, &psz_end, 10 );
774 if( psz_end != psz_parser ) goto crop_end;
777 i_crop_top = strtol( psz_end, &psz_end, 10 );
778 if( *psz_end != '\0' ) goto crop_end;
780 if( i_crop_top + i_crop_height >= p_vout->fmt_render.i_visible_height ||
781 i_crop_left + i_crop_width >= p_vout->fmt_render.i_visible_width )
783 msg_Err( p_vout, "Unable to crop over picture boundaries");
787 i_width = i_crop_width;
788 p_vout->fmt_in.i_visible_width = i_width;
790 i_height = i_crop_height;
791 p_vout->fmt_in.i_visible_height = i_height;
793 p_vout->fmt_in.i_x_offset = i_crop_left;
794 p_vout->fmt_in.i_y_offset = i_crop_top;
798 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
799 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
801 psz_parser = strchr( newval.psz_string, '+' );
802 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
803 if( psz_end != psz_parser ) goto crop_end;
805 psz_parser = strchr( ++psz_end, '+' );
806 i_crop_top = strtol( psz_end, &psz_end, 10 );
807 if( psz_end != psz_parser ) goto crop_end;
809 psz_parser = strchr( ++psz_end, '+' );
810 i_crop_right = strtol( psz_end, &psz_end, 10 );
811 if( psz_end != psz_parser ) goto crop_end;
814 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
815 if( *psz_end != '\0' ) goto crop_end;
817 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
818 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
820 msg_Err( p_vout, "Unable to crop over picture boundaries" );
824 i_width = p_vout->fmt_render.i_visible_width
825 - i_crop_left - i_crop_right;
826 p_vout->fmt_in.i_visible_width = i_width;
828 i_height = p_vout->fmt_render.i_visible_height
829 - i_crop_top - i_crop_bottom;
830 p_vout->fmt_in.i_visible_height = i_height;
832 p_vout->fmt_in.i_x_offset = i_crop_left;
833 p_vout->fmt_in.i_y_offset = i_crop_top;
837 else if( !strcmp( psz_cmd, "crop-top" )
838 || !strcmp( psz_cmd, "crop-left" )
839 || !strcmp( psz_cmd, "crop-bottom" )
840 || !strcmp( psz_cmd, "crop-right" ) )
842 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
844 i_crop_top = var_GetInteger( p_vout, "crop-top" );
845 i_crop_left = var_GetInteger( p_vout, "crop-left" );
846 i_crop_right = var_GetInteger( p_vout, "crop-right" );
847 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
849 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
850 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
852 msg_Err( p_vout, "Unable to crop over picture boundaries" );
856 i_width = p_vout->fmt_render.i_visible_width
857 - i_crop_left - i_crop_right;
858 p_vout->fmt_in.i_visible_width = i_width;
860 i_height = p_vout->fmt_render.i_visible_height
861 - i_crop_top - i_crop_bottom;
862 p_vout->fmt_in.i_visible_height = i_height;
864 p_vout->fmt_in.i_x_offset = i_crop_left;
865 p_vout->fmt_in.i_y_offset = i_crop_top;
869 InitWindowSize( p_vout, &p_vout->i_window_width,
870 &p_vout->i_window_height );
872 p_vout->i_changes |= VOUT_CROP_CHANGE;
874 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
875 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
876 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
877 p_vout->fmt_in.i_visible_width,
878 p_vout->fmt_in.i_visible_height );
880 var_TriggerCallback( p_vout, "crop-update" );
885 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
886 vlc_value_t oldval, vlc_value_t newval, void *p_data )
888 vout_thread_t *p_vout = (vout_thread_t *)p_this;
889 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
892 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
893 (void)psz_cmd; (void)oldval; (void)p_data;
895 /* Restore defaults */
896 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
897 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
898 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
899 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
901 if( !psz_parser ) goto aspect_end;
903 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
904 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
906 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
907 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
909 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
910 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
911 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
912 p_vout->fmt_in.i_sar_num = i_sar_num;
913 p_vout->fmt_in.i_sar_den = i_sar_den;
914 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
915 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
918 if( p_vout->p->i_par_num && p_vout->p->i_par_den )
920 p_vout->fmt_in.i_sar_num *= p_vout->p->i_par_den;
921 p_vout->fmt_in.i_sar_den *= p_vout->p->i_par_num;
922 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
923 p_vout->p->i_par_den / p_vout->p->i_par_num;
924 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
927 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
929 vlc_ureduce( &i_aspect_num, &i_aspect_den,
930 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
931 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
932 i_aspect_num, i_aspect_den,
933 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
935 if( var_Get( p_vout, "crop", &val ) )
938 int i_ret = CropCallback( p_this, "crop", val, val, 0 );
939 free( val.psz_string );
943 static int ScalingCallback( vlc_object_t *p_this, char const *psz_cmd,
944 vlc_value_t oldval, vlc_value_t newval, void *p_data )
946 vout_thread_t *p_vout = (vout_thread_t *)p_this;
947 (void)oldval; (void)newval; (void)p_data;
949 vlc_mutex_lock( &p_vout->change_lock );
951 if( !strcmp( psz_cmd, "autoscale" ) )
953 p_vout->i_changes |= VOUT_SCALE_CHANGE;
955 else if( !strcmp( psz_cmd, "scale" ) )
957 p_vout->i_changes |= VOUT_ZOOM_CHANGE;
960 vlc_mutex_unlock( &p_vout->change_lock );
965 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
966 vlc_value_t oldval, vlc_value_t newval, void *p_data )
968 vout_thread_t *p_vout = (vout_thread_t *)p_this;
970 vlc_mutex_lock( &p_vout->change_lock );
971 p_vout->i_changes |= VOUT_ON_TOP_CHANGE;
972 p_vout->b_on_top = newval.b_bool;
973 vlc_mutex_unlock( &p_vout->change_lock );
975 /* Modify libvlc as well because the vout might have to be restarted */
976 var_Create( p_vout->p_libvlc, "video-on-top", VLC_VAR_BOOL );
977 var_Set( p_vout->p_libvlc, "video-on-top", newval );
979 (void)psz_cmd; (void)oldval; (void)p_data;
983 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
984 vlc_value_t oldval, vlc_value_t newval, void *p_data )
986 vout_thread_t *p_vout = (vout_thread_t *)p_this;
988 (void)psz_cmd; (void)oldval; (void)p_data;
990 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
992 /* Modify libvlc as well because the vout might have to be restarted */
993 var_Create( p_vout->p_libvlc, "fullscreen", VLC_VAR_BOOL );
994 var_Set( p_vout->p_libvlc, "fullscreen", newval );
997 var_Set( p_vout, "intf-change", val );
1001 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1002 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1004 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1005 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1006 VLC_UNUSED(newval); VLC_UNUSED(p_data);
1008 VoutSaveSnapshot( p_vout );
1012 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1013 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1015 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1017 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1018 p_vout->p->b_title_show = newval.b_bool;
1022 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
1023 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1025 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1026 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1027 p_vout->p->i_title_timeout = (mtime_t) newval.i_int;
1031 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1032 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1034 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1036 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1037 p_vout->p->i_title_position = newval.i_int;