1 /*****************************************************************************
2 * vout_intf.c : video output interface
3 *****************************************************************************
4 * Copyright (C) 2000-2007 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
35 #include <stdlib.h> /* free() */
36 #include <sys/types.h> /* opendir() */
37 #include <dirent.h> /* opendir() */
39 #include <vlc_interface.h>
40 #include <vlc_block.h>
41 #include <vlc_playlist.h>
44 #include <vlc_image.h>
46 #include <vlc_charset.h>
48 #include <vlc_strings.h>
49 #include <vlc_charset.h>
50 #include "../libvlc.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 OnTopCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
66 static int FullscreenCallback( vlc_object_t *, char const *,
67 vlc_value_t, vlc_value_t, void * );
68 static int SnapshotCallback( vlc_object_t *, char const *,
69 vlc_value_t, vlc_value_t, void * );
71 static int TitleShowCallback( vlc_object_t *, char const *,
72 vlc_value_t, vlc_value_t, void * );
73 static int TitleTimeoutCallback( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
75 static int TitlePositionCallback( vlc_object_t *, char const *,
76 vlc_value_t, vlc_value_t, void * );
78 /*****************************************************************************
79 * vout_RequestWindow: Create/Get a video window if possible.
80 *****************************************************************************
81 * This function looks for the main interface and tries to request
82 * a new video window. If it fails then the vout will still need to create the
84 *****************************************************************************/
85 void *vout_RequestWindow( vout_thread_t *p_vout,
86 int *pi_x_hint, int *pi_y_hint,
87 unsigned int *pi_width_hint,
88 unsigned int *pi_height_hint )
90 intf_thread_t *p_intf = NULL;
97 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
99 /* Get requested coordinates */
100 *pi_x_hint = var_GetInteger( p_vout, "video-x" );
101 *pi_y_hint = var_GetInteger( p_vout, "video-y" );
103 *pi_width_hint = p_vout->i_window_width;
104 *pi_height_hint = p_vout->i_window_height;
106 /* Check whether someone provided us with a window ID */
107 int drawable = var_CreateGetInteger( p_vout, "drawable" );
108 if( drawable ) return (void *)(intptr_t)drawable;
112 * This code is utter crap w.r.t. threading. And it has always been.
113 * First, one cannot invoke callbacks from another thread's object.
114 * Not without a well-defined locking convention.
116 * Second, this would need to "wait" for the interface to be ready.
117 * Otherwise, the availability of the embded window would become
120 * In the past, this kind of things worked by accident. This time is over.
121 * -- Courmisch, 12 Jun 2008
123 /* Find if the main interface supports embedding */
124 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
125 if( !p_list ) return NULL;
127 for( i = 0; i < p_list->i_count; i++ )
129 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
130 if( p_intf->pf_request_window ) break;
136 vlc_list_release( p_list );
140 vlc_object_yield( p_intf );
141 vlc_list_release( p_list );
143 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
144 pi_width_hint, pi_height_hint );
146 if( !p_window ) vlc_object_release( p_intf );
147 else p_vout->p_parent_intf = p_intf;
155 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
157 intf_thread_t *p_intf = p_vout->p_parent_intf;
159 if( !p_intf ) return;
161 vlc_mutex_lock( &p_intf->object_lock );
164 vlc_mutex_unlock( &p_intf->object_lock );
168 if( !p_intf->pf_release_window )
170 msg_Err( p_vout, "no pf_release_window");
171 vlc_mutex_unlock( &p_intf->object_lock );
172 vlc_object_release( p_intf );
176 p_intf->pf_release_window( p_intf, p_window );
178 p_vout->p_parent_intf = NULL;
179 vlc_mutex_unlock( &p_intf->object_lock );
180 vlc_object_release( p_intf );
183 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
184 int i_query, va_list args )
186 intf_thread_t *p_intf = p_vout->p_parent_intf;
189 if( !p_intf ) return VLC_EGENERIC;
191 vlc_mutex_lock( &p_intf->object_lock );
194 vlc_mutex_unlock( &p_intf->object_lock );
198 if( !p_intf->pf_control_window )
200 msg_Err( p_vout, "no pf_control_window");
201 vlc_mutex_unlock( &p_intf->object_lock );
205 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
206 vlc_mutex_unlock( &p_intf->object_lock );
210 /*****************************************************************************
211 * vout_IntfInit: called during the vout creation to initialise misc things.
212 *****************************************************************************/
216 const char *psz_label;
217 } p_zoom_values[] = {
218 { 0.25, N_("1:4 Quarter") },
219 { 0.5, N_("1:2 Half") },
220 { 1, N_("1:1 Original") },
221 { 2, N_("2:1 Double") },
226 const char *psz_value;
227 const char *psz_label;
228 } p_crop_values[] = {
229 { "", N_("Default") },
233 { "16:10", "16:10" },
236 { "1.85:1", "1.85:1" },
237 { "221:100", "2.21:1" },
238 { "235:100", "2.35:1" },
239 { "239:100", "2.39:1" },
244 const char *psz_value;
245 const char *psz_label;
246 } p_aspect_ratio_values[] = {
247 { "", N_("Default") },
251 { "16:10", "16:10" },
252 { "221:100", "2.21:1" },
256 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
259 if( psz_list && *psz_list )
261 char *psz_cur = psz_list;
263 while( psz_cur && *psz_cur )
265 vlc_value_t val, text;
266 psz_next = strchr( psz_cur, ',' );
272 val.psz_string = psz_cur;
273 text.psz_string = psz_cur;
274 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
280 void vout_IntfInit( vout_thread_t *p_vout )
282 vlc_value_t val, text, old_val;
283 bool b_force_par = false;
287 /* Create a few object variables we'll need later on */
288 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
289 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
290 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
291 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
292 var_Create( p_vout, "snapshot-sequential",
293 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
294 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
295 var_SetInteger( p_vout, "snapshot-num", 1 );
296 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
297 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
299 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
300 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
301 p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" );
303 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
304 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
306 var_Create( p_vout, "mouse-hide-timeout",
307 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
309 p_vout->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
310 p_vout->i_title_timeout =
311 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
312 p_vout->i_title_position =
313 var_CreateGetInteger( p_vout, "video-title-position" );
315 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
316 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
317 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
319 /* Zoom object var */
320 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
321 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
323 text.psz_string = _("Zoom");
324 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
326 var_Get( p_vout, "zoom", &old_val );
328 for( i = 0; p_zoom_values[i].f_value; i++ )
330 if( old_val.f_float == p_zoom_values[i].f_value )
331 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
332 val.f_float = p_zoom_values[i].f_value;
333 text.psz_string = _( p_zoom_values[i].psz_label );
334 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
337 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
339 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
341 /* Crop offset vars */
342 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
343 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
344 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
345 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
347 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
348 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
349 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
350 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
352 /* Crop object var */
353 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
354 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
356 text.psz_string = _("Crop");
357 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
359 val.psz_string = (char*)"";
360 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
362 for( i = 0; p_crop_values[i].psz_value; i++ )
364 val.psz_string = (char*)p_crop_values[i].psz_value;
365 text.psz_string = _( p_crop_values[i].psz_label );
366 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
369 /* update triggered every time the vout's crop parameters are changed */
370 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
372 /* Add custom crop ratios */
373 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
374 AddCustomRatios( p_vout, "crop", psz_buf );
377 var_AddCallback( p_vout, "crop", CropCallback, NULL );
378 var_Get( p_vout, "crop", &old_val );
379 if( old_val.psz_string && *old_val.psz_string )
380 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
381 free( old_val.psz_string );
383 /* Monitor pixel aspect-ratio */
384 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
385 var_Get( p_vout, "monitor-par", &val );
386 if( val.psz_string && *val.psz_string )
388 char *psz_parser = strchr( val.psz_string, ':' );
389 unsigned int i_aspect_num = 0, i_aspect_den = 0;
393 i_aspect_num = strtol( val.psz_string, 0, 10 );
394 i_aspect_den = strtol( ++psz_parser, 0, 10 );
398 i_aspect = atof( val.psz_string );
399 vlc_ureduce( &i_aspect_num, &i_aspect_den,
400 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
402 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
404 p_vout->i_par_num = i_aspect_num;
405 p_vout->i_par_den = i_aspect_den;
407 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
408 p_vout->i_par_num, p_vout->i_par_den, 0 );
410 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
411 p_vout->i_par_num, p_vout->i_par_den );
414 free( val.psz_string );
416 /* Aspect-ratio object var */
417 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
418 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
420 text.psz_string = _("Aspect-ratio");
421 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
423 val.psz_string = (char*)"";
424 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
426 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
428 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
429 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
430 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
433 /* Add custom aspect ratios */
434 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
435 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
438 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
439 var_Get( p_vout, "aspect-ratio", &old_val );
440 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
441 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
442 free( old_val.psz_string );
444 /* Initialize the dimensions of the video window */
445 InitWindowSize( p_vout, &p_vout->i_window_width,
446 &p_vout->i_window_height );
448 /* Add a variable to indicate if the window should be on top of others */
449 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
450 | VLC_VAR_ISCOMMAND );
451 text.psz_string = _("Always on top");
452 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
453 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
455 /* Add a variable to indicate whether we want window decoration or not */
456 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
458 /* Add a fullscreen variable */
459 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
461 /* user requested fullscreen */
462 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
464 text.psz_string = _("Fullscreen");
465 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
466 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
468 /* Add a snapshot variable */
469 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
470 text.psz_string = _("Snapshot");
471 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
472 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
474 /* Mouse coordinates */
475 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
476 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
477 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
478 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
479 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
481 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
482 var_SetBool( p_vout, "intf-change", true );
485 /*****************************************************************************
486 * vout_Snapshot: generates a snapshot.
487 *****************************************************************************/
488 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
490 image_handler_t *p_image = image_HandlerCreate( p_vout );
491 video_format_t fmt_in, fmt_out;
492 char *psz_filename = NULL;
493 subpicture_t *p_subpic;
495 vlc_value_t val, format;
499 memset( &fmt_in, 0, sizeof(video_format_t) );
500 memset( &fmt_out, 0, sizeof(video_format_t) );
502 var_Get( p_vout, "snapshot-path", &val );
503 if( val.psz_string && !*val.psz_string )
505 free( val.psz_string );
509 /* Embedded snapshot : if snapshot-path == object:object-id, then
510 create a snapshot_t* and store it in
511 object(object-id)->p_private, then unlock and signal the
514 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
517 vlc_object_t* p_dest;
519 snapshot_t *p_snapshot;
522 /* Destination object-id is following object: */
523 i_id = atoi( &val.psz_string[7] );
524 p_dest = ( vlc_object_t* )vlc_object_get( i_id );
527 msg_Err( p_vout, "Cannot find calling object" );
528 image_HandlerDelete( p_image );
531 /* Object must be locked. We will unlock it once we get the
532 snapshot and written it to p_private */
533 p_dest->p_private = NULL;
535 /* Save the snapshot to a memory zone */
536 fmt_in = p_vout->fmt_in;
537 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
538 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
539 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
540 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
542 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
545 msg_Err( p_vout, "Could not get snapshot" );
546 image_HandlerDelete( p_image );
547 vlc_cond_signal( &p_dest->object_wait );
548 vlc_object_release( p_dest );
552 /* Copy the p_block data to a snapshot structure */
553 /* FIXME: get the timestamp */
554 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
557 block_Release( p_block );
558 image_HandlerDelete( p_image );
559 vlc_cond_signal( &p_dest->object_wait );
560 vlc_object_release( p_dest );
564 i_size = p_block->i_buffer;
566 p_snapshot->i_width = fmt_out.i_width;
567 p_snapshot->i_height = fmt_out.i_height;
568 p_snapshot->i_datasize = i_size;
569 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
570 p_snapshot->p_data = ( char* ) malloc( i_size );
571 if( !p_snapshot->p_data )
573 block_Release( p_block );
575 image_HandlerDelete( p_image );
576 vlc_cond_signal( &p_dest->object_wait );
577 vlc_object_release( p_dest );
580 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
582 p_dest->p_private = p_snapshot;
584 block_Release( p_block );
586 /* Unlock the object */
587 vlc_cond_signal( &p_dest->object_wait );
588 vlc_object_release( p_dest );
590 image_HandlerDelete( p_image );
594 #if defined(__APPLE__) || defined(SYS_BEOS)
595 if( !val.psz_string )
597 if( asprintf( &val.psz_string, "%s/Desktop",
598 config_GetHomeDir() ) == -1 )
599 val.psz_string = NULL;
602 #elif defined(WIN32) && !defined(UNDER_CE)
603 if( !val.psz_string )
605 /* Get the My Pictures folder path */
607 char *p_mypicturesdir = NULL;
608 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
610 #ifndef CSIDL_FLAG_CREATE
611 # define CSIDL_FLAG_CREATE 0x8000
613 #ifndef CSIDL_MYPICTURES
614 # define CSIDL_MYPICTURES 0x27
616 #ifndef SHGFP_TYPE_CURRENT
617 # define SHGFP_TYPE_CURRENT 0
620 HINSTANCE shfolder_dll;
621 SHGETFOLDERPATH SHGetFolderPath ;
623 /* load the shfolder dll to retrieve SHGetFolderPath */
624 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
626 wchar_t wdir[PATH_MAX];
627 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
628 _T("SHGetFolderPathW") );
629 if ((SHGetFolderPath != NULL )
630 && SUCCEEDED (SHGetFolderPath (NULL,
631 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
632 NULL, SHGFP_TYPE_CURRENT,
634 p_mypicturesdir = FromWide (wdir);
636 FreeLibrary( shfolder_dll );
639 if( p_mypicturesdir == NULL )
641 if( asprintf( &val.psz_string, "%s", config_GetHomeDir() ) == -1 )
642 val.psz_string = NULL;
646 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
647 val.psz_string = NULL;
648 free( p_mypicturesdir );
653 /* XXX: This saves in the data directory. Shouldn't we try saving
654 * to psz_homedir/Desktop or something nicer ? */
655 char *psz_datadir = config_GetUserDataDir();
656 if( !val.psz_string && psz_datadir )
658 if( asprintf( &val.psz_string, "%s", psz_datadir ) == -1 )
659 val.psz_string = NULL;
664 if( !val.psz_string )
666 msg_Err( p_vout, "no path specified for snapshots" );
667 image_HandlerDelete( p_image );
670 var_Get( p_vout, "snapshot-format", &format );
671 if( !format.psz_string || !*format.psz_string )
673 free( format.psz_string );
674 format.psz_string = strdup( "png" );
678 * Did the user specify a directory? If not, path = NULL.
680 path = utf8_opendir ( (const char *)val.psz_string );
683 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
684 if( psz_prefix == NULL )
685 psz_prefix = strdup( "vlcsnap-" );
688 char *psz_tmp = str_format( p_vout, psz_prefix );
689 filename_sanitize( psz_tmp );
691 psz_prefix = psz_tmp;
695 if( var_GetBool( p_vout, "snapshot-sequential" ) == true )
697 int i_num = var_GetInteger( p_vout, "snapshot-num" );
701 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
702 val.psz_string, psz_prefix, i_num++,
703 format.psz_string ) == -1 )
705 msg_Err( p_vout, "could not create snapshot" );
706 image_HandlerDelete( p_image );
710 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
711 var_SetInteger( p_vout, "snapshot-num", i_num );
715 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
716 val.psz_string, psz_prefix,
717 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
718 format.psz_string ) == -1 )
720 msg_Err( p_vout, "could not create snapshot" );
721 image_HandlerDelete( p_image );
728 else // The user specified a full path name (including file name)
730 psz_filename = str_format( p_vout, val.psz_string );
731 path_sanitize( psz_filename );
734 free( val.psz_string );
735 free( format.psz_string );
737 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
738 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
740 fmt_in = p_vout->fmt_in;
742 if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
744 fmt_out.i_width = (fmt_in.i_width * fmt_out.i_height) / fmt_in.i_height;
746 else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
748 fmt_out.i_height = (fmt_in.i_height * fmt_out.i_width) / fmt_in.i_width;
752 fmt_out.i_width = fmt_in.i_width;
753 fmt_out.i_height = fmt_in.i_height;
756 /* Save the snapshot */
757 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
758 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
759 if( i_ret != VLC_SUCCESS )
761 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
762 free( psz_filename );
763 image_HandlerDelete( p_image );
767 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
768 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
769 "%s", psz_filename );
770 free( psz_filename );
772 if( var_GetBool( p_vout, "snapshot-preview" ) )
774 /* Inject a subpicture with the snapshot */
775 memset( &fmt_out, 0, sizeof(fmt_out) );
776 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
777 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
778 image_HandlerDelete( p_image );
779 if( !p_pif ) return VLC_EGENERIC;
781 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
782 if( p_subpic == NULL )
784 p_pif->pf_release( p_pif );
788 p_subpic->i_channel = 0;
789 p_subpic->i_start = mdate();
790 p_subpic->i_stop = mdate() + 4000000;
791 p_subpic->b_ephemer = true;
792 p_subpic->b_fade = true;
793 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
794 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
796 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
797 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
799 p_pif->pf_release( p_pif );
801 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
805 image_HandlerDelete( p_image );
811 /*****************************************************************************
813 *****************************************************************************/
815 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
816 bool b_add, bool b_setconfig )
819 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
821 /* Todo : Use some generic chain manipulation functions */
822 if( !psz_string ) psz_string = strdup("");
824 psz_parser = strstr( psz_string, psz_name );
829 psz_parser = psz_string;
830 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
831 psz_string, psz_name ) == -1 )
845 memmove( psz_parser, psz_parser + strlen(psz_name) +
846 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
847 strlen(psz_parser + strlen(psz_name)) + 1 );
849 /* Remove trailing : : */
850 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
852 *(psz_string+strlen(psz_string ) -1 ) = '\0';
862 config_PutPsz( p_vout, "vout-filter", psz_string );
864 var_SetString( p_vout, "vout-filter", psz_string );
868 /*****************************************************************************
869 * vout_ControlDefault: default methods for video output control.
870 *****************************************************************************/
871 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
878 if( p_vout->p_parent_intf )
880 vlc_object_release( p_vout->p_parent_intf );
881 p_vout->p_parent_intf = NULL;
887 p_vout->b_snapshot = true;
892 msg_Dbg( p_vout, "control query not supported" );
897 /*****************************************************************************
898 * InitWindowSize: find the initial dimensions the video window should have.
899 *****************************************************************************
900 * This function will check the "width", "height" and "zoom" config options and
901 * will calculate the size that the video window should have.
902 *****************************************************************************/
903 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
904 unsigned *pi_height )
907 int i_width, i_height;
910 #define FP_FACTOR 1000 /* our fixed point factor */
912 var_Get( p_vout, "width", &val );
914 var_Get( p_vout, "height", &val );
915 i_height = val.i_int;
916 var_Get( p_vout, "zoom", &val );
917 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
919 if( i_width > 0 && i_height > 0)
921 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
922 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
925 else if( i_width > 0 )
927 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
928 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
929 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
930 FP_FACTOR / p_vout->fmt_in.i_visible_width );
933 else if( i_height > 0 )
935 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
936 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
937 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
938 FP_FACTOR / p_vout->fmt_in.i_visible_height );
942 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
943 msg_Warn( p_vout, "fucked up aspect" );
944 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
945 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
947 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
949 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
950 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
951 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
956 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
958 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
959 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
963 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
964 p_vout->i_window_height );
969 /*****************************************************************************
970 * Object variables callbacks
971 *****************************************************************************/
972 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
973 vlc_value_t oldval, vlc_value_t newval, void *p_data )
975 vout_thread_t *p_vout = (vout_thread_t *)p_this;
976 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
977 InitWindowSize( p_vout, &p_vout->i_window_width,
978 &p_vout->i_window_height );
979 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
980 p_vout->i_window_height );
984 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
985 vlc_value_t oldval, vlc_value_t newval, void *p_data )
987 vout_thread_t *p_vout = (vout_thread_t *)p_this;
988 int64_t i_aspect_num, i_aspect_den;
989 unsigned int i_width, i_height;
991 (void)oldval; (void)p_data;
993 /* Restore defaults */
994 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
995 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
996 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
997 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
999 if( !strcmp( psz_cmd, "crop" ) )
1001 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
1004 /* We're using the 3:4 syntax */
1005 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1006 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
1008 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1009 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
1011 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
1012 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
1013 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
1014 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
1016 if( i_width < p_vout->fmt_render.i_visible_width )
1018 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
1019 (p_vout->fmt_render.i_visible_width - i_width) / 2;
1020 p_vout->fmt_in.i_visible_width = i_width;
1024 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
1025 (p_vout->fmt_render.i_visible_height - i_height) / 2;
1026 p_vout->fmt_in.i_visible_height = i_height;
1031 psz_parser = strchr( newval.psz_string, 'x' );
1034 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
1035 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
1037 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
1038 if( psz_end != psz_parser ) goto crop_end;
1040 psz_parser = strchr( ++psz_end, '+' );
1041 i_crop_height = strtol( psz_end, &psz_end, 10 );
1042 if( psz_end != psz_parser ) goto crop_end;
1044 psz_parser = strchr( ++psz_end, '+' );
1045 i_crop_left = strtol( psz_end, &psz_end, 10 );
1046 if( psz_end != psz_parser ) goto crop_end;
1049 i_crop_top = strtol( psz_end, &psz_end, 10 );
1050 if( *psz_end != '\0' ) goto crop_end;
1052 i_width = i_crop_width;
1053 p_vout->fmt_in.i_visible_width = i_width;
1055 i_height = i_crop_height;
1056 p_vout->fmt_in.i_visible_height = i_height;
1058 p_vout->fmt_in.i_x_offset = i_crop_left;
1059 p_vout->fmt_in.i_y_offset = i_crop_top;
1063 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1064 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1066 psz_parser = strchr( newval.psz_string, '+' );
1067 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1068 if( psz_end != psz_parser ) goto crop_end;
1070 psz_parser = strchr( ++psz_end, '+' );
1071 i_crop_top = strtol( psz_end, &psz_end, 10 );
1072 if( psz_end != psz_parser ) goto crop_end;
1074 psz_parser = strchr( ++psz_end, '+' );
1075 i_crop_right = strtol( psz_end, &psz_end, 10 );
1076 if( psz_end != psz_parser ) goto crop_end;
1079 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1080 if( *psz_end != '\0' ) goto crop_end;
1082 i_width = p_vout->fmt_render.i_visible_width
1083 - i_crop_left - i_crop_right;
1084 p_vout->fmt_in.i_visible_width = i_width;
1086 i_height = p_vout->fmt_render.i_visible_height
1087 - i_crop_top - i_crop_bottom;
1088 p_vout->fmt_in.i_visible_height = i_height;
1090 p_vout->fmt_in.i_x_offset = i_crop_left;
1091 p_vout->fmt_in.i_y_offset = i_crop_top;
1095 else if( !strcmp( psz_cmd, "crop-top" )
1096 || !strcmp( psz_cmd, "crop-left" )
1097 || !strcmp( psz_cmd, "crop-bottom" )
1098 || !strcmp( psz_cmd, "crop-right" ) )
1100 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1102 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1103 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1104 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1105 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1107 i_width = p_vout->fmt_render.i_visible_width
1108 - i_crop_left - i_crop_right;
1109 p_vout->fmt_in.i_visible_width = i_width;
1111 i_height = p_vout->fmt_render.i_visible_height
1112 - i_crop_top - i_crop_bottom;
1113 p_vout->fmt_in.i_visible_height = i_height;
1115 p_vout->fmt_in.i_x_offset = i_crop_left;
1116 p_vout->fmt_in.i_y_offset = i_crop_top;
1120 InitWindowSize( p_vout, &p_vout->i_window_width,
1121 &p_vout->i_window_height );
1123 p_vout->i_changes |= VOUT_CROP_CHANGE;
1125 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1126 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1127 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1128 p_vout->fmt_in.i_visible_width,
1129 p_vout->fmt_in.i_visible_height );
1131 var_SetVoid( p_vout, "crop-update" );
1136 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1137 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1139 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1140 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1143 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1144 (void)psz_cmd; (void)oldval; (void)p_data;
1146 /* Restore defaults */
1147 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1148 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1149 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1150 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1152 if( !psz_parser ) goto aspect_end;
1154 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1155 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1157 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1158 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1160 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1161 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1162 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1163 p_vout->fmt_in.i_sar_num = i_sar_num;
1164 p_vout->fmt_in.i_sar_den = i_sar_den;
1165 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1166 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1169 if( p_vout->i_par_num && p_vout->i_par_den )
1171 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1172 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1173 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1174 p_vout->i_par_den / p_vout->i_par_num;
1175 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1178 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1180 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1181 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1182 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1183 i_aspect_num, i_aspect_den,
1184 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1186 var_Get( p_vout, "crop", &val );
1187 return CropCallback( p_this, "crop", val, val, 0 );
1190 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1191 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1193 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1194 playlist_t *p_playlist = pl_Yield( p_this );
1195 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1196 (void)psz_cmd; (void)oldval; (void)p_data;
1198 /* Modify playlist as well because the vout might have to be restarted */
1199 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1200 var_Set( p_playlist, "video-on-top", newval );
1202 pl_Release( p_this );
1206 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1207 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1209 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1211 playlist_t *p_playlist = pl_Yield( p_this );
1212 (void)psz_cmd; (void)oldval; (void)p_data;
1214 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1216 /* Modify playlist as well because the vout might have to be restarted */
1217 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1218 var_Set( p_playlist, "fullscreen", newval );
1219 pl_Release( p_playlist );
1222 var_Set( p_vout, "intf-change", val );
1226 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1227 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1229 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1230 VLC_UNUSED(newval); VLC_UNUSED(p_data);
1231 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1232 vout_Control( p_vout, VOUT_SNAPSHOT );
1236 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1237 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1239 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1241 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1242 p_vout->b_title_show = newval.b_bool;
1246 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
1247 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1249 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1250 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1251 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1255 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1256 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1258 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1260 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1261 p_vout->i_title_position = newval.i_int;