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 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
57 /* Object variables callbacks */
58 static int ZoomCallback( vlc_object_t *, char const *,
59 vlc_value_t, vlc_value_t, void * );
60 static int CropCallback( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
62 static int AspectCallback( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
64 static int ScalingCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
66 static int OnTopCallback( vlc_object_t *, char const *,
67 vlc_value_t, vlc_value_t, void * );
68 static int FullscreenCallback( vlc_object_t *, char const *,
69 vlc_value_t, vlc_value_t, void * );
70 static int SnapshotCallback( vlc_object_t *, char const *,
71 vlc_value_t, vlc_value_t, void * );
73 static int TitleShowCallback( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
75 static int TitleTimeoutCallback( vlc_object_t *, char const *,
76 vlc_value_t, vlc_value_t, void * );
77 static int TitlePositionCallback( vlc_object_t *, char const *,
78 vlc_value_t, vlc_value_t, void * );
80 /*****************************************************************************
81 * vout_IntfInit: called during the vout creation to initialise misc things.
82 *****************************************************************************/
86 const char *psz_label;
88 { 0.25, N_("1:4 Quarter") },
89 { 0.5, N_("1:2 Half") },
90 { 1, N_("1:1 Original") },
91 { 2, N_("2:1 Double") },
96 const char *psz_value;
97 const char *psz_label;
99 { "", N_("Default") },
100 { "16:10", "16:10" },
102 { "185:100", "1.85:1" },
103 { "221:100", "2.21:1" },
104 { "235:100", "2.35:1" },
105 { "239:100", "2.39:1" },
114 const char *psz_value;
115 const char *psz_label;
116 } p_aspect_ratio_values[] = {
117 { "", N_("Default") },
121 { "16:10", "16:10" },
122 { "221:100", "2.21:1" },
123 { "235:100", "2.35:1" },
124 { "239:100", "2.39: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-button-down", VLC_VAR_INTEGER );
369 var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
370 var_Create( p_vout, "mouse-clicked", VLC_VAR_COORDS );
371 var_Create( p_vout, "mouse-object", VLC_VAR_BOOL );
373 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
374 var_SetBool( p_vout, "intf-change", true );
377 /*****************************************************************************
378 * vout_Snapshot: generates a snapshot.
379 *****************************************************************************/
381 * This function will inject a subpicture into the vout with the provided
384 static int VoutSnapshotPip( vout_thread_t *p_vout, picture_t *p_pic )
386 subpicture_t *p_subpic = subpicture_NewFromPicture( VLC_OBJECT(p_vout),
387 p_pic, VLC_CODEC_YUVA );
391 /* FIXME DEFAULT_CHAN is not good (used by the text) but
392 * hardcoded 0 doesn't seem right */
393 p_subpic->i_channel = 0;
394 p_subpic->i_start = mdate();
395 p_subpic->i_stop = p_subpic->i_start + 4000000;
396 p_subpic->b_ephemer = true;
397 p_subpic->b_fade = true;
399 /* Reduce the picture to 1/4^2 of the screen */
400 p_subpic->i_original_picture_width *= 4;
401 p_subpic->i_original_picture_height *= 4;
403 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
408 * This function will display the name and a PIP of the provided snapshot
410 static void VoutOsdSnapshot( vout_thread_t *p_vout, picture_t *p_pic, const char *psz_filename )
412 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
413 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN, "%s", psz_filename );
415 if( var_GetBool( p_vout, "snapshot-preview" ) )
417 if( VoutSnapshotPip( p_vout, p_pic ) )
418 msg_Warn( p_vout, "Failed to display snapshot" );
423 int vout_GetSnapshot( vout_thread_t *p_vout,
424 block_t **pp_image, picture_t **pp_picture,
425 video_format_t *p_fmt,
426 const char *psz_format, mtime_t i_timeout )
428 picture_t *p_picture = vout_snapshot_Get( &p_vout->p->snapshot, i_timeout );
431 msg_Err( p_vout, "Failed to grab a snapshot" );
437 vlc_fourcc_t i_format = VLC_CODEC_PNG;
438 if( psz_format && image_Type2Fourcc( psz_format ) )
439 i_format = image_Type2Fourcc( psz_format );
441 const int i_override_width = var_GetInteger( p_vout, "snapshot-width" );
442 const int i_override_height = var_GetInteger( p_vout, "snapshot-height" );
444 if( picture_Export( VLC_OBJECT(p_vout), pp_image, p_fmt,
445 p_picture, i_format, i_override_width, i_override_height ) )
447 msg_Err( p_vout, "Failed to convert image for snapshot" );
448 picture_Release( p_picture );
453 *pp_picture = p_picture;
455 picture_Release( p_picture );
460 * This function will handle a snapshot request
462 static void VoutSaveSnapshot( vout_thread_t *p_vout )
464 char *psz_path = var_GetNonEmptyString( p_vout, "snapshot-path" );
465 char *psz_format = var_GetNonEmptyString( p_vout, "snapshot-format" );
466 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
469 picture_t *p_picture;
474 * XXX it will cause trouble with low fps video (< 2fps) */
475 if( vout_GetSnapshot( p_vout, &p_image, &p_picture, &fmt, psz_format, 500*1000 ) )
484 psz_path = vout_snapshot_GetDirectory();
487 msg_Err( p_vout, "no path specified for snapshots" );
492 vout_snapshot_save_cfg_t cfg;
493 memset( &cfg, 0, sizeof(cfg) );
494 cfg.is_sequential = var_GetBool( p_vout, "snapshot-sequential" );
495 cfg.sequence = var_GetInteger( p_vout, "snapshot-num" );
497 cfg.format = psz_format;
498 cfg.prefix_fmt = psz_prefix;
502 if (vout_snapshot_SaveImage( &psz_filename, &i_sequence,
503 p_image, VLC_OBJECT(p_vout), &cfg ) )
505 if( cfg.is_sequential )
506 var_SetInteger( p_vout, "snapshot-num", i_sequence + 1 );
508 VoutOsdSnapshot( p_vout, p_picture, psz_filename );
510 /* signal creation of a new snapshot file */
511 var_SetString( p_vout->p_libvlc, "snapshot-file", psz_filename );
513 free( psz_filename );
517 block_Release( p_image );
519 picture_Release( p_picture );
525 /*****************************************************************************
527 *****************************************************************************/
529 void vout_EnableFilter( vout_thread_t *p_vout, const char *psz_name,
530 bool b_add, bool b_setconfig )
534 const char *psz_filter_type;
536 /* FIXME temporary hack */
537 const char *psz_module_name = psz_name;
538 if( !strcmp( psz_name, "magnify" ) ||
539 !strcmp( psz_name, "puzzle" ) ||
540 !strcmp( psz_name, "logo" ) ||
541 !strcmp( psz_name, "wall" ) ||
542 !strcmp( psz_name, "clone" ) )
543 psz_module_name = "video_filter_wrapper";
545 module_t *p_obj = module_find( psz_module_name );
548 msg_Err( p_vout, "Unable to find filter module \"%s\".", psz_name );
552 if( module_provides( p_obj, "video filter" ) )
554 psz_filter_type = "vout-filter";
556 else if( module_provides( p_obj, "video filter2" ) )
558 psz_filter_type = "video-filter";
560 else if( module_provides( p_obj, "sub filter" ) )
562 psz_filter_type = "sub-filter";
566 module_release( p_obj );
567 msg_Err( p_vout, "Unknown video filter type." );
570 module_release( p_obj );
572 if( !strcmp( psz_filter_type, "sub-filter") )
573 psz_string = var_GetString( vout_GetSpu( p_vout ), psz_filter_type );
575 psz_string = var_GetString( p_vout, psz_filter_type );
577 /* Todo : Use some generic chain manipulation functions */
578 if( !psz_string ) psz_string = strdup("");
580 psz_parser = strstr( psz_string, psz_name );
585 psz_parser = psz_string;
586 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
587 psz_string, psz_name ) == -1 )
601 memmove( psz_parser, psz_parser + strlen(psz_name) +
602 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
603 strlen(psz_parser + strlen(psz_name)) + 1 );
605 /* Remove trailing : : */
606 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
608 *(psz_string+strlen(psz_string ) -1 ) = '\0';
620 if( !strcmp( psz_filter_type, "sub-filter") )
621 config_PutPsz( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
623 config_PutPsz( p_vout, psz_filter_type, psz_string );
626 if( !strcmp( psz_filter_type, "sub-filter") )
627 var_SetString( vout_GetSpu( p_vout ), psz_filter_type, psz_string );
629 var_SetString( p_vout, psz_filter_type, psz_string );
634 /*****************************************************************************
635 * InitWindowSize: find the initial dimensions the video window should have.
636 *****************************************************************************
637 * This function will check the "width", "height" and "zoom" config options and
638 * will calculate the size that the video window should have.
639 *****************************************************************************/
640 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
641 unsigned *pi_height )
643 #define FP_FACTOR 1000 /* our fixed point factor */
645 int i_width = var_GetInteger( p_vout, "width" );
646 int i_height = var_GetInteger( p_vout, "height" );
647 float f_zoom = var_GetFloat( p_vout, "zoom" );
648 uint64_t ll_zoom = (uint64_t)( FP_FACTOR * f_zoom );
650 if( i_width > 0 && i_height > 0)
652 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
653 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
655 else if( i_width > 0 )
657 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
658 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
659 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
660 FP_FACTOR / p_vout->fmt_in.i_visible_width );
662 else if( i_height > 0 )
664 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
665 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
666 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
667 FP_FACTOR / p_vout->fmt_in.i_visible_height );
669 else if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 )
671 msg_Warn( p_vout, "aspect ratio screwed up" );
672 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
673 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
675 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
677 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
678 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
679 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
684 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
686 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
687 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
690 msg_Dbg( p_vout, "window size: %ux%u", *pi_width, *pi_height );
695 /*****************************************************************************
696 * Object variables callbacks
697 *****************************************************************************/
698 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
699 vlc_value_t oldval, vlc_value_t newval, void *p_data )
701 (void)psz_cmd; (void)oldval; (void)p_data;
703 return var_SetFloat( p_this, "scale", newval.f_float );
706 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
707 vlc_value_t oldval, vlc_value_t newval, void *p_data )
709 vout_thread_t *p_vout = (vout_thread_t *)p_this;
710 int64_t i_aspect_num, i_aspect_den;
711 unsigned int i_width, i_height;
713 (void)oldval; (void)p_data;
715 /* Restore defaults */
716 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
717 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
718 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
719 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
721 if( !strcmp( psz_cmd, "crop" ) )
723 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
726 /* We're using the 3:4 syntax */
727 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
728 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
730 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
731 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
733 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
734 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
735 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
736 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
738 if( i_width < p_vout->fmt_render.i_visible_width )
740 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
741 (p_vout->fmt_render.i_visible_width - i_width) / 2;
742 p_vout->fmt_in.i_visible_width = i_width;
746 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
747 (p_vout->fmt_render.i_visible_height - i_height) / 2;
748 p_vout->fmt_in.i_visible_height = i_height;
753 psz_parser = strchr( newval.psz_string, 'x' );
756 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
757 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
759 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
760 if( psz_end != psz_parser ) goto crop_end;
762 psz_parser = strchr( ++psz_end, '+' );
763 i_crop_height = strtol( psz_end, &psz_end, 10 );
764 if( psz_end != psz_parser ) goto crop_end;
766 psz_parser = strchr( ++psz_end, '+' );
767 i_crop_left = strtol( psz_end, &psz_end, 10 );
768 if( psz_end != psz_parser ) goto crop_end;
771 i_crop_top = strtol( psz_end, &psz_end, 10 );
772 if( *psz_end != '\0' ) goto crop_end;
774 if( i_crop_top + i_crop_height >= p_vout->fmt_render.i_visible_height ||
775 i_crop_left + i_crop_width >= p_vout->fmt_render.i_visible_width )
777 msg_Err( p_vout, "Unable to crop over picture boundaries");
781 i_width = i_crop_width;
782 p_vout->fmt_in.i_visible_width = i_width;
784 i_height = i_crop_height;
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 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
793 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
795 psz_parser = strchr( newval.psz_string, '+' );
796 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
797 if( psz_end != psz_parser ) goto crop_end;
799 psz_parser = strchr( ++psz_end, '+' );
800 i_crop_top = strtol( psz_end, &psz_end, 10 );
801 if( psz_end != psz_parser ) goto crop_end;
803 psz_parser = strchr( ++psz_end, '+' );
804 i_crop_right = strtol( psz_end, &psz_end, 10 );
805 if( psz_end != psz_parser ) goto crop_end;
808 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
809 if( *psz_end != '\0' ) goto crop_end;
811 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
812 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
814 msg_Err( p_vout, "Unable to crop over picture boundaries" );
818 i_width = p_vout->fmt_render.i_visible_width
819 - i_crop_left - i_crop_right;
820 p_vout->fmt_in.i_visible_width = i_width;
822 i_height = p_vout->fmt_render.i_visible_height
823 - i_crop_top - i_crop_bottom;
824 p_vout->fmt_in.i_visible_height = i_height;
826 p_vout->fmt_in.i_x_offset = i_crop_left;
827 p_vout->fmt_in.i_y_offset = i_crop_top;
831 else if( !strcmp( psz_cmd, "crop-top" )
832 || !strcmp( psz_cmd, "crop-left" )
833 || !strcmp( psz_cmd, "crop-bottom" )
834 || !strcmp( psz_cmd, "crop-right" ) )
836 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
838 i_crop_top = var_GetInteger( p_vout, "crop-top" );
839 i_crop_left = var_GetInteger( p_vout, "crop-left" );
840 i_crop_right = var_GetInteger( p_vout, "crop-right" );
841 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
843 if( i_crop_top + i_crop_bottom >= p_vout->fmt_render.i_visible_height ||
844 i_crop_right + i_crop_left >= p_vout->fmt_render.i_visible_width )
846 msg_Err( p_vout, "Unable to crop over picture boundaries" );
850 i_width = p_vout->fmt_render.i_visible_width
851 - i_crop_left - i_crop_right;
852 p_vout->fmt_in.i_visible_width = i_width;
854 i_height = p_vout->fmt_render.i_visible_height
855 - i_crop_top - i_crop_bottom;
856 p_vout->fmt_in.i_visible_height = i_height;
858 p_vout->fmt_in.i_x_offset = i_crop_left;
859 p_vout->fmt_in.i_y_offset = i_crop_top;
863 InitWindowSize( p_vout, &p_vout->i_window_width,
864 &p_vout->i_window_height );
866 p_vout->i_changes |= VOUT_CROP_CHANGE;
868 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
869 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
870 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
871 p_vout->fmt_in.i_visible_width,
872 p_vout->fmt_in.i_visible_height );
874 var_TriggerCallback( p_vout, "crop-update" );
879 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
880 vlc_value_t oldval, vlc_value_t newval, void *p_data )
882 vout_thread_t *p_vout = (vout_thread_t *)p_this;
883 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
886 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
887 (void)psz_cmd; (void)oldval; (void)p_data;
889 /* Restore defaults */
890 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
891 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
892 p_vout->render.i_aspect = (int64_t)p_vout->fmt_render.i_sar_num *
893 p_vout->fmt_render.i_width *
895 p_vout->fmt_render.i_sar_den / p_vout->fmt_render.i_height;
897 if( !psz_parser ) goto aspect_end;
899 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
900 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
902 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
903 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
905 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
906 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
907 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
908 p_vout->fmt_in.i_sar_num = i_sar_num;
909 p_vout->fmt_in.i_sar_den = i_sar_den;
910 p_vout->render.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
913 if( p_vout->p->i_par_num && p_vout->p->i_par_den )
915 p_vout->fmt_in.i_sar_num *= p_vout->p->i_par_den;
916 p_vout->fmt_in.i_sar_den *= p_vout->p->i_par_num;
917 p_vout->render.i_aspect = (int64_t)p_vout->fmt_in.i_sar_num *
918 p_vout->fmt_in.i_width *
920 p_vout->fmt_in.i_sar_den /
921 p_vout->fmt_in.i_height;
924 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
926 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
927 p_vout->fmt_in.i_sar_num * p_vout->fmt_in.i_width,
928 p_vout->fmt_in.i_sar_den * p_vout->fmt_in.i_height,
929 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
931 if( var_Get( p_vout, "crop", &val ) )
934 int i_ret = CropCallback( p_this, "crop", val, val, 0 );
935 free( val.psz_string );
939 static int ScalingCallback( vlc_object_t *p_this, char const *psz_cmd,
940 vlc_value_t oldval, vlc_value_t newval, void *p_data )
942 vout_thread_t *p_vout = (vout_thread_t *)p_this;
943 (void)oldval; (void)newval; (void)p_data;
945 vlc_mutex_lock( &p_vout->change_lock );
947 if( !strcmp( psz_cmd, "autoscale" ) )
949 p_vout->i_changes |= VOUT_SCALE_CHANGE;
951 else if( !strcmp( psz_cmd, "scale" ) )
953 p_vout->i_changes |= VOUT_ZOOM_CHANGE;
956 vlc_mutex_unlock( &p_vout->change_lock );
961 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
962 vlc_value_t oldval, vlc_value_t newval, void *p_data )
964 vout_thread_t *p_vout = (vout_thread_t *)p_this;
966 vlc_mutex_lock( &p_vout->change_lock );
967 p_vout->i_changes |= VOUT_ON_TOP_CHANGE;
968 p_vout->b_on_top = newval.b_bool;
969 vlc_mutex_unlock( &p_vout->change_lock );
971 (void)psz_cmd; (void)oldval; (void)p_data;
975 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
976 vlc_value_t oldval, vlc_value_t newval, void *p_data )
978 vout_thread_t *p_vout = (vout_thread_t *)p_this;
980 (void)psz_cmd; (void)p_data;
982 if( oldval.b_bool == newval.b_bool )
983 return VLC_SUCCESS; /* no-op */
984 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
987 var_Set( p_vout, "intf-change", val );
991 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
992 vlc_value_t oldval, vlc_value_t newval, void *p_data )
994 vout_thread_t *p_vout = (vout_thread_t *)p_this;
995 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
996 VLC_UNUSED(newval); VLC_UNUSED(p_data);
998 VoutSaveSnapshot( p_vout );
1002 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1003 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1005 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1007 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1008 p_vout->p->b_title_show = newval.b_bool;
1012 static int TitleTimeoutCallback( 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); VLC_UNUSED(p_data);
1016 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1017 p_vout->p->i_title_timeout = (mtime_t) newval.i_int;
1021 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1022 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1024 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1026 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1027 p_vout->p->i_title_position = newval.i_int;