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() */
39 #include <vlc_interface.h>
40 #include <vlc_block.h>
41 #include <vlc_playlist.h>
44 #include <vlc_window.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"
53 /*****************************************************************************
55 *****************************************************************************/
56 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
58 /* Object variables callbacks */
59 static int ZoomCallback( vlc_object_t *, char const *,
60 vlc_value_t, vlc_value_t, void * );
61 static int CropCallback( vlc_object_t *, char const *,
62 vlc_value_t, vlc_value_t, void * );
63 static int AspectCallback( vlc_object_t *, char const *,
64 vlc_value_t, vlc_value_t, void * );
65 static int OnTopCallback( vlc_object_t *, char const *,
66 vlc_value_t, vlc_value_t, void * );
67 static int FullscreenCallback( vlc_object_t *, char const *,
68 vlc_value_t, vlc_value_t, void * );
69 static int SnapshotCallback( vlc_object_t *, char const *,
70 vlc_value_t, vlc_value_t, void * );
72 static int TitleShowCallback( vlc_object_t *, char const *,
73 vlc_value_t, vlc_value_t, void * );
74 static int TitleTimeoutCallback( vlc_object_t *, char const *,
75 vlc_value_t, vlc_value_t, void * );
76 static int TitlePositionCallback( vlc_object_t *, char const *,
77 vlc_value_t, vlc_value_t, void * );
79 /*****************************************************************************
80 * vout_RequestWindow: Create/Get a video window if possible.
81 *****************************************************************************
82 * This function looks for the main interface and tries to request
83 * a new video window. If it fails then the vout will still need to create the
85 *****************************************************************************/
86 void *vout_RequestWindow( vout_thread_t *p_vout,
87 int *pi_x_hint, int *pi_y_hint,
88 unsigned int *pi_width_hint,
89 unsigned int *pi_height_hint )
92 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
94 /* Get requested coordinates */
95 *pi_x_hint = var_GetInteger( p_vout, "video-x" );
96 *pi_y_hint = var_GetInteger( p_vout, "video-y" );
98 *pi_width_hint = p_vout->i_window_width;
99 *pi_height_hint = p_vout->i_window_height;
101 /* Check whether someone provided us with a window ID */
102 int drawable = var_CreateGetInteger( p_vout, "drawable" );
103 if( drawable ) return (void *)(intptr_t)drawable;
105 vout_window_t *wnd = vlc_custom_create (VLC_OBJECT(p_vout), sizeof (*wnd),
106 VLC_OBJECT_GENERIC, "window");
111 wnd->width = *pi_width_hint;
112 wnd->height = *pi_height_hint;
113 wnd->pos_x = *pi_x_hint;
114 wnd->pos_y = *pi_y_hint;
115 vlc_object_attach (wnd, p_vout);
117 wnd->module = module_Need (wnd, "vout window", 0, 0);
118 if (wnd->module == NULL)
120 msg_Dbg (wnd, "no window provider available");
121 vlc_object_release (wnd);
124 p_vout->p_window = wnd;
125 *pi_width_hint = wnd->width;
126 *pi_height_hint = wnd->height;
127 *pi_x_hint = wnd->pos_x;
128 *pi_y_hint = wnd->pos_y;
132 void vout_ReleaseWindow( vout_thread_t *p_vout, void *dummy )
134 vout_window_t *wnd = p_vout->p_window;
138 p_vout->p_window = NULL;
140 assert (wnd->module);
141 module_Unneed (wnd, wnd->module);
143 vlc_object_detach (wnd);
144 vlc_object_release (wnd);
148 int vout_ControlWindow( vout_thread_t *p_vout, void *dummy,
149 int i_query, va_list args )
151 vout_window_t *wnd = p_vout->p_window;
156 assert (wnd->control);
157 return wnd->control (wnd, i_query, args);
160 /*****************************************************************************
161 * vout_IntfInit: called during the vout creation to initialise misc things.
162 *****************************************************************************/
166 const char *psz_label;
167 } p_zoom_values[] = {
168 { 0.25, N_("1:4 Quarter") },
169 { 0.5, N_("1:2 Half") },
170 { 1, N_("1:1 Original") },
171 { 2, N_("2:1 Double") },
176 const char *psz_value;
177 const char *psz_label;
178 } p_crop_values[] = {
179 { "", N_("Default") },
183 { "16:10", "16:10" },
186 { "1.85:1", "1.85:1" },
187 { "221:100", "2.21:1" },
188 { "235:100", "2.35:1" },
189 { "239:100", "2.39:1" },
194 const char *psz_value;
195 const char *psz_label;
196 } p_aspect_ratio_values[] = {
197 { "", N_("Default") },
201 { "16:10", "16:10" },
202 { "221:100", "2.21:1" },
206 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
209 if( psz_list && *psz_list )
211 char *psz_cur = psz_list;
213 while( psz_cur && *psz_cur )
215 vlc_value_t val, text;
216 psz_next = strchr( psz_cur, ',' );
222 val.psz_string = psz_cur;
223 text.psz_string = psz_cur;
224 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
230 void vout_IntfInit( vout_thread_t *p_vout )
232 vlc_value_t val, text, old_val;
233 bool b_force_par = false;
237 /* Create a few object variables we'll need later on */
238 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
239 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
240 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
241 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
242 var_Create( p_vout, "snapshot-sequential",
243 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
244 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
245 var_SetInteger( p_vout, "snapshot-num", 1 );
246 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
247 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
249 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
250 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
251 p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" );
253 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
254 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
256 var_Create( p_vout, "mouse-hide-timeout",
257 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
259 p_vout->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
260 p_vout->i_title_timeout =
261 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
262 p_vout->i_title_position =
263 var_CreateGetInteger( p_vout, "video-title-position" );
265 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
266 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
267 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
269 /* Zoom object var */
270 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
271 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
273 text.psz_string = _("Zoom");
274 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
276 var_Get( p_vout, "zoom", &old_val );
278 for( i = 0; p_zoom_values[i].f_value; i++ )
280 if( old_val.f_float == p_zoom_values[i].f_value )
281 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
282 val.f_float = p_zoom_values[i].f_value;
283 text.psz_string = _( p_zoom_values[i].psz_label );
284 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
287 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
289 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
291 /* Crop offset vars */
292 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
293 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
294 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
295 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
297 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
298 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
299 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
300 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
302 /* Crop object var */
303 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
304 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
306 text.psz_string = _("Crop");
307 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
309 val.psz_string = (char*)"";
310 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
312 for( i = 0; p_crop_values[i].psz_value; i++ )
314 val.psz_string = (char*)p_crop_values[i].psz_value;
315 text.psz_string = _( p_crop_values[i].psz_label );
316 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
319 /* update triggered every time the vout's crop parameters are changed */
320 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
322 /* Add custom crop ratios */
323 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
324 AddCustomRatios( p_vout, "crop", psz_buf );
327 var_AddCallback( p_vout, "crop", CropCallback, NULL );
328 var_Get( p_vout, "crop", &old_val );
329 if( old_val.psz_string && *old_val.psz_string )
330 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
331 free( old_val.psz_string );
333 /* Monitor pixel aspect-ratio */
334 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
335 var_Get( p_vout, "monitor-par", &val );
336 if( val.psz_string && *val.psz_string )
338 char *psz_parser = strchr( val.psz_string, ':' );
339 unsigned int i_aspect_num = 0, i_aspect_den = 0;
343 i_aspect_num = strtol( val.psz_string, 0, 10 );
344 i_aspect_den = strtol( ++psz_parser, 0, 10 );
348 i_aspect = atof( val.psz_string );
349 vlc_ureduce( &i_aspect_num, &i_aspect_den,
350 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
352 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
354 p_vout->i_par_num = i_aspect_num;
355 p_vout->i_par_den = i_aspect_den;
357 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
358 p_vout->i_par_num, p_vout->i_par_den, 0 );
360 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
361 p_vout->i_par_num, p_vout->i_par_den );
364 free( val.psz_string );
366 /* Aspect-ratio object var */
367 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
368 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
370 text.psz_string = _("Aspect-ratio");
371 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
373 val.psz_string = (char*)"";
374 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
376 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
378 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
379 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
380 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
383 /* Add custom aspect ratios */
384 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
385 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
388 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
389 var_Get( p_vout, "aspect-ratio", &old_val );
390 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
391 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
392 free( old_val.psz_string );
394 /* Initialize the dimensions of the video window */
395 InitWindowSize( p_vout, &p_vout->i_window_width,
396 &p_vout->i_window_height );
398 /* Add a variable to indicate if the window should be on top of others */
399 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
400 | VLC_VAR_ISCOMMAND );
401 text.psz_string = _("Always on top");
402 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
403 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
405 /* Add a variable to indicate whether we want window decoration or not */
406 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
408 /* Add a fullscreen variable */
409 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
411 /* user requested fullscreen */
412 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
414 text.psz_string = _("Fullscreen");
415 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
416 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
418 /* Add a snapshot variable */
419 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
420 text.psz_string = _("Snapshot");
421 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
422 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
424 /* Mouse coordinates */
425 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
426 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
427 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
428 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
429 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
431 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
432 var_SetBool( p_vout, "intf-change", true );
435 /*****************************************************************************
436 * vout_Snapshot: generates a snapshot.
437 *****************************************************************************/
438 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
440 image_handler_t *p_image = image_HandlerCreate( p_vout );
441 video_format_t fmt_in, fmt_out;
442 char *psz_filename = NULL;
443 subpicture_t *p_subpic;
445 vlc_value_t val, format;
449 memset( &fmt_in, 0, sizeof(video_format_t) );
450 memset( &fmt_out, 0, sizeof(video_format_t) );
452 var_Get( p_vout, "snapshot-path", &val );
453 if( val.psz_string && !*val.psz_string )
455 free( val.psz_string );
459 /* Embedded snapshot : if snapshot-path == object:object-id, then
460 create a snapshot_t* and store it in
461 object(object-id)->p_private, then unlock and signal the
464 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
467 vlc_object_t* p_dest;
469 snapshot_t *p_snapshot;
472 /* Destination object-id is following object: */
473 i_id = atoi( &val.psz_string[7] );
474 p_dest = ( vlc_object_t* )vlc_object_get( i_id );
477 msg_Err( p_vout, "Cannot find calling object" );
478 image_HandlerDelete( p_image );
481 /* Object must be locked. We will unlock it once we get the
482 snapshot and written it to p_private */
483 p_dest->p_private = NULL;
485 /* Save the snapshot to a memory zone */
486 fmt_in = p_vout->fmt_in;
487 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
488 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
489 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
490 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
492 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
495 msg_Err( p_vout, "Could not get snapshot" );
496 image_HandlerDelete( p_image );
497 vlc_object_signal_maybe( VLC_OBJECT(p_dest) );
498 vlc_object_release( p_dest );
502 /* Copy the p_block data to a snapshot structure */
503 /* FIXME: get the timestamp */
504 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
507 block_Release( p_block );
508 image_HandlerDelete( p_image );
509 vlc_object_signal_maybe( VLC_OBJECT(p_dest) );
510 vlc_object_release( p_dest );
514 i_size = p_block->i_buffer;
516 p_snapshot->i_width = fmt_out.i_width;
517 p_snapshot->i_height = fmt_out.i_height;
518 p_snapshot->i_datasize = i_size;
519 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
520 p_snapshot->p_data = ( char* ) malloc( i_size );
521 if( !p_snapshot->p_data )
523 block_Release( p_block );
525 image_HandlerDelete( p_image );
526 vlc_object_signal_maybe( VLC_OBJECT(p_dest) );
527 vlc_object_release( p_dest );
530 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
532 p_dest->p_private = p_snapshot;
534 block_Release( p_block );
536 /* Unlock the object */
537 vlc_object_signal_maybe( VLC_OBJECT(p_dest) );
538 vlc_object_release( p_dest );
540 image_HandlerDelete( p_image );
544 #if defined(__APPLE__) || defined(SYS_BEOS)
545 if( !val.psz_string )
547 if( asprintf( &val.psz_string, "%s/Desktop",
548 config_GetHomeDir() ) == -1 )
549 val.psz_string = NULL;
552 #elif defined(WIN32) && !defined(UNDER_CE)
553 if( !val.psz_string )
555 /* Get the My Pictures folder path */
557 char *p_mypicturesdir = NULL;
558 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
560 #ifndef CSIDL_FLAG_CREATE
561 # define CSIDL_FLAG_CREATE 0x8000
563 #ifndef CSIDL_MYPICTURES
564 # define CSIDL_MYPICTURES 0x27
566 #ifndef SHGFP_TYPE_CURRENT
567 # define SHGFP_TYPE_CURRENT 0
570 HINSTANCE shfolder_dll;
571 SHGETFOLDERPATH SHGetFolderPath ;
573 /* load the shfolder dll to retrieve SHGetFolderPath */
574 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
576 wchar_t wdir[PATH_MAX];
577 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
578 _T("SHGetFolderPathW") );
579 if ((SHGetFolderPath != NULL )
580 && SUCCEEDED (SHGetFolderPath (NULL,
581 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
582 NULL, SHGFP_TYPE_CURRENT,
584 p_mypicturesdir = FromWide (wdir);
586 FreeLibrary( shfolder_dll );
589 if( p_mypicturesdir == NULL )
591 if( asprintf( &val.psz_string, "%s", config_GetHomeDir() ) == -1 )
592 val.psz_string = NULL;
596 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
597 val.psz_string = NULL;
598 free( p_mypicturesdir );
603 /* XXX: This saves in the data directory. Shouldn't we try saving
604 * to psz_homedir/Desktop or something nicer ? */
605 char *psz_datadir = config_GetUserDataDir();
606 if( !val.psz_string && psz_datadir )
608 if( asprintf( &val.psz_string, "%s", psz_datadir ) == -1 )
609 val.psz_string = NULL;
614 if( !val.psz_string )
616 msg_Err( p_vout, "no path specified for snapshots" );
617 image_HandlerDelete( p_image );
620 var_Get( p_vout, "snapshot-format", &format );
621 if( !format.psz_string || !*format.psz_string )
623 free( format.psz_string );
624 format.psz_string = strdup( "png" );
628 * Did the user specify a directory? If not, path = NULL.
630 path = utf8_opendir ( (const char *)val.psz_string );
633 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
634 if( psz_prefix == NULL )
635 psz_prefix = strdup( "vlcsnap-" );
638 char *psz_tmp = str_format( p_vout, psz_prefix );
639 filename_sanitize( psz_tmp );
641 psz_prefix = psz_tmp;
645 if( var_GetBool( p_vout, "snapshot-sequential" ) == true )
647 int i_num = var_GetInteger( p_vout, "snapshot-num" );
651 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
652 val.psz_string, psz_prefix, i_num++,
653 format.psz_string ) == -1 )
655 msg_Err( p_vout, "could not create snapshot" );
656 image_HandlerDelete( p_image );
660 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
661 var_SetInteger( p_vout, "snapshot-num", i_num );
665 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
666 val.psz_string, psz_prefix,
667 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
668 format.psz_string ) == -1 )
670 msg_Err( p_vout, "could not create snapshot" );
671 image_HandlerDelete( p_image );
678 else // The user specified a full path name (including file name)
680 psz_filename = str_format( p_vout, val.psz_string );
681 path_sanitize( psz_filename );
684 free( val.psz_string );
685 free( format.psz_string );
687 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
688 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
690 fmt_in = p_vout->fmt_in;
692 if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
694 fmt_out.i_width = (fmt_in.i_width * fmt_out.i_height) / fmt_in.i_height;
696 else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
698 fmt_out.i_height = (fmt_in.i_height * fmt_out.i_width) / fmt_in.i_width;
702 fmt_out.i_width = fmt_in.i_width;
703 fmt_out.i_height = fmt_in.i_height;
706 /* Save the snapshot */
707 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
708 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
709 if( i_ret != VLC_SUCCESS )
711 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
712 free( psz_filename );
713 image_HandlerDelete( p_image );
717 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
718 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
719 "%s", psz_filename );
720 free( psz_filename );
722 if( var_GetBool( p_vout, "snapshot-preview" ) )
724 /* Inject a subpicture with the snapshot */
725 memset( &fmt_out, 0, sizeof(fmt_out) );
726 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
727 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
728 image_HandlerDelete( p_image );
729 if( !p_pif ) return VLC_EGENERIC;
731 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
732 if( p_subpic == NULL )
734 p_pif->pf_release( p_pif );
738 p_subpic->i_channel = 0;
739 p_subpic->i_start = mdate();
740 p_subpic->i_stop = mdate() + 4000000;
741 p_subpic->b_ephemer = true;
742 p_subpic->b_fade = true;
743 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
744 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
746 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
747 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
749 p_pif->pf_release( p_pif );
751 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
755 image_HandlerDelete( p_image );
761 /*****************************************************************************
763 *****************************************************************************/
765 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
766 bool b_add, bool b_setconfig )
769 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
771 /* Todo : Use some generic chain manipulation functions */
772 if( !psz_string ) psz_string = strdup("");
774 psz_parser = strstr( psz_string, psz_name );
779 psz_parser = psz_string;
780 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
781 psz_string, psz_name ) == -1 )
795 memmove( psz_parser, psz_parser + strlen(psz_name) +
796 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
797 strlen(psz_parser + strlen(psz_name)) + 1 );
799 /* Remove trailing : : */
800 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
802 *(psz_string+strlen(psz_string ) -1 ) = '\0';
812 config_PutPsz( p_vout, "vout-filter", psz_string );
814 var_SetString( p_vout, "vout-filter", psz_string );
818 /*****************************************************************************
819 * vout_ControlDefault: default methods for video output control.
820 *****************************************************************************/
821 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
828 vout_ReleaseWindow( p_vout, NULL );
832 p_vout->b_snapshot = true;
836 msg_Dbg( p_vout, "control query not supported" );
841 /*****************************************************************************
842 * InitWindowSize: find the initial dimensions the video window should have.
843 *****************************************************************************
844 * This function will check the "width", "height" and "zoom" config options and
845 * will calculate the size that the video window should have.
846 *****************************************************************************/
847 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
848 unsigned *pi_height )
851 int i_width, i_height;
854 #define FP_FACTOR 1000 /* our fixed point factor */
856 var_Get( p_vout, "width", &val );
858 var_Get( p_vout, "height", &val );
859 i_height = val.i_int;
860 var_Get( p_vout, "zoom", &val );
861 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
863 if( i_width > 0 && i_height > 0)
865 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
866 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
869 else if( i_width > 0 )
871 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
872 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
873 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
874 FP_FACTOR / p_vout->fmt_in.i_visible_width );
877 else if( i_height > 0 )
879 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
880 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
881 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
882 FP_FACTOR / p_vout->fmt_in.i_visible_height );
886 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
887 msg_Warn( p_vout, "fucked up aspect" );
888 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
889 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
891 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
893 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
894 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
895 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
900 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
902 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
903 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
907 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
908 p_vout->i_window_height );
913 /*****************************************************************************
914 * Object variables callbacks
915 *****************************************************************************/
916 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
917 vlc_value_t oldval, vlc_value_t newval, void *p_data )
919 vout_thread_t *p_vout = (vout_thread_t *)p_this;
920 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
921 InitWindowSize( p_vout, &p_vout->i_window_width,
922 &p_vout->i_window_height );
923 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
924 p_vout->i_window_height );
928 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
929 vlc_value_t oldval, vlc_value_t newval, void *p_data )
931 vout_thread_t *p_vout = (vout_thread_t *)p_this;
932 int64_t i_aspect_num, i_aspect_den;
933 unsigned int i_width, i_height;
935 (void)oldval; (void)p_data;
937 /* Restore defaults */
938 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
939 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
940 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
941 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
943 if( !strcmp( psz_cmd, "crop" ) )
945 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
948 /* We're using the 3:4 syntax */
949 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
950 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
952 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
953 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
955 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
956 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
957 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
958 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
960 if( i_width < p_vout->fmt_render.i_visible_width )
962 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
963 (p_vout->fmt_render.i_visible_width - i_width) / 2;
964 p_vout->fmt_in.i_visible_width = i_width;
968 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
969 (p_vout->fmt_render.i_visible_height - i_height) / 2;
970 p_vout->fmt_in.i_visible_height = i_height;
975 psz_parser = strchr( newval.psz_string, 'x' );
978 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
979 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
981 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
982 if( psz_end != psz_parser ) goto crop_end;
984 psz_parser = strchr( ++psz_end, '+' );
985 i_crop_height = strtol( psz_end, &psz_end, 10 );
986 if( psz_end != psz_parser ) goto crop_end;
988 psz_parser = strchr( ++psz_end, '+' );
989 i_crop_left = strtol( psz_end, &psz_end, 10 );
990 if( psz_end != psz_parser ) goto crop_end;
993 i_crop_top = strtol( psz_end, &psz_end, 10 );
994 if( *psz_end != '\0' ) goto crop_end;
996 i_width = i_crop_width;
997 p_vout->fmt_in.i_visible_width = i_width;
999 i_height = i_crop_height;
1000 p_vout->fmt_in.i_visible_height = i_height;
1002 p_vout->fmt_in.i_x_offset = i_crop_left;
1003 p_vout->fmt_in.i_y_offset = i_crop_top;
1007 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1008 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1010 psz_parser = strchr( newval.psz_string, '+' );
1011 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1012 if( psz_end != psz_parser ) goto crop_end;
1014 psz_parser = strchr( ++psz_end, '+' );
1015 i_crop_top = strtol( psz_end, &psz_end, 10 );
1016 if( psz_end != psz_parser ) goto crop_end;
1018 psz_parser = strchr( ++psz_end, '+' );
1019 i_crop_right = strtol( psz_end, &psz_end, 10 );
1020 if( psz_end != psz_parser ) goto crop_end;
1023 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1024 if( *psz_end != '\0' ) goto crop_end;
1026 i_width = p_vout->fmt_render.i_visible_width
1027 - i_crop_left - i_crop_right;
1028 p_vout->fmt_in.i_visible_width = i_width;
1030 i_height = p_vout->fmt_render.i_visible_height
1031 - i_crop_top - i_crop_bottom;
1032 p_vout->fmt_in.i_visible_height = i_height;
1034 p_vout->fmt_in.i_x_offset = i_crop_left;
1035 p_vout->fmt_in.i_y_offset = i_crop_top;
1039 else if( !strcmp( psz_cmd, "crop-top" )
1040 || !strcmp( psz_cmd, "crop-left" )
1041 || !strcmp( psz_cmd, "crop-bottom" )
1042 || !strcmp( psz_cmd, "crop-right" ) )
1044 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1046 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1047 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1048 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1049 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1051 i_width = p_vout->fmt_render.i_visible_width
1052 - i_crop_left - i_crop_right;
1053 p_vout->fmt_in.i_visible_width = i_width;
1055 i_height = p_vout->fmt_render.i_visible_height
1056 - i_crop_top - i_crop_bottom;
1057 p_vout->fmt_in.i_visible_height = i_height;
1059 p_vout->fmt_in.i_x_offset = i_crop_left;
1060 p_vout->fmt_in.i_y_offset = i_crop_top;
1064 InitWindowSize( p_vout, &p_vout->i_window_width,
1065 &p_vout->i_window_height );
1067 p_vout->i_changes |= VOUT_CROP_CHANGE;
1069 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1070 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1071 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1072 p_vout->fmt_in.i_visible_width,
1073 p_vout->fmt_in.i_visible_height );
1075 var_SetVoid( p_vout, "crop-update" );
1080 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1081 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1083 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1084 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1087 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1088 (void)psz_cmd; (void)oldval; (void)p_data;
1090 /* Restore defaults */
1091 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1092 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1093 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1094 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1096 if( !psz_parser ) goto aspect_end;
1098 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1099 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1101 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1102 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1104 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1105 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1106 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1107 p_vout->fmt_in.i_sar_num = i_sar_num;
1108 p_vout->fmt_in.i_sar_den = i_sar_den;
1109 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1110 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1113 if( p_vout->i_par_num && p_vout->i_par_den )
1115 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1116 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1117 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1118 p_vout->i_par_den / p_vout->i_par_num;
1119 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1122 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1124 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1125 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1126 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1127 i_aspect_num, i_aspect_den,
1128 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1130 var_Get( p_vout, "crop", &val );
1131 return CropCallback( p_this, "crop", val, val, 0 );
1134 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1135 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1137 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1138 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1139 (void)psz_cmd; (void)oldval; (void)p_data;
1141 /* Modify libvlc as well because the vout might have to be restarted */
1142 var_Create( p_vout->p_libvlc, "video-on-top", VLC_VAR_BOOL );
1143 var_Set( p_vout->p_libvlc, "video-on-top", newval );
1148 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1149 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1151 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1153 (void)psz_cmd; (void)oldval; (void)p_data;
1155 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1157 /* Modify libvlc as well because the vout might have to be restarted */
1158 var_Create( p_vout->p_libvlc, "fullscreen", VLC_VAR_BOOL );
1159 var_Set( p_vout->p_libvlc, "fullscreen", newval );
1162 var_Set( p_vout, "intf-change", val );
1166 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1167 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1169 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1170 VLC_UNUSED(newval); VLC_UNUSED(p_data);
1171 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1172 vout_Control( p_vout, VOUT_SNAPSHOT );
1176 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1177 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1179 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1181 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1182 p_vout->b_title_show = newval.b_bool;
1186 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
1187 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1189 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1190 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1191 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1195 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1196 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1198 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1200 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1201 p_vout->i_title_position = newval.i_int;