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 *****************************************************************************/
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 var_Get( p_vout->p_libvlc, "drawable", &val );
108 if( val.i_int ) return (void *)(intptr_t)val.i_int;
110 /* Find if the main interface supports embedding */
111 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
112 if( !p_list ) return NULL;
114 for( i = 0; i < p_list->i_count; i++ )
116 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
117 if( p_intf->pf_request_window ) break;
123 vlc_list_release( p_list );
127 vlc_object_yield( p_intf );
128 vlc_list_release( p_list );
130 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
131 pi_width_hint, pi_height_hint );
133 if( !p_window ) vlc_object_release( p_intf );
134 else p_vout->p_parent_intf = p_intf;
139 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
141 intf_thread_t *p_intf = p_vout->p_parent_intf;
143 if( !p_intf ) return;
145 vlc_mutex_lock( &p_intf->object_lock );
148 vlc_mutex_unlock( &p_intf->object_lock );
152 if( !p_intf->pf_release_window )
154 msg_Err( p_vout, "no pf_release_window");
155 vlc_mutex_unlock( &p_intf->object_lock );
156 vlc_object_release( p_intf );
160 p_intf->pf_release_window( p_intf, p_window );
162 p_vout->p_parent_intf = NULL;
163 vlc_mutex_unlock( &p_intf->object_lock );
164 vlc_object_release( p_intf );
167 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
168 int i_query, va_list args )
170 intf_thread_t *p_intf = p_vout->p_parent_intf;
173 if( !p_intf ) return VLC_EGENERIC;
175 vlc_mutex_lock( &p_intf->object_lock );
178 vlc_mutex_unlock( &p_intf->object_lock );
182 if( !p_intf->pf_control_window )
184 msg_Err( p_vout, "no pf_control_window");
185 vlc_mutex_unlock( &p_intf->object_lock );
189 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
190 vlc_mutex_unlock( &p_intf->object_lock );
194 /*****************************************************************************
195 * vout_IntfInit: called during the vout creation to initialise misc things.
196 *****************************************************************************/
200 const char *psz_label;
201 } p_zoom_values[] = {
202 { 0.25, N_("1:4 Quarter") },
203 { 0.5, N_("1:2 Half") },
204 { 1, N_("1:1 Original") },
205 { 2, N_("2:1 Double") },
210 const char *psz_value;
211 const char *psz_label;
212 } p_crop_values[] = {
213 { "", N_("Default") },
217 { "16:10", "16:10" },
220 { "1.85:1", "1.85:1" },
221 { "221:100", "2.21:1" },
222 { "235:100", "2.35:1" },
223 { "239:100", "2.39:1" },
228 const char *psz_value;
229 const char *psz_label;
230 } p_aspect_ratio_values[] = {
231 { "", N_("Default") },
235 { "16:10", "16:10" },
236 { "221:100", "2.21:1" },
240 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
243 if( psz_list && *psz_list )
245 char *psz_cur = psz_list;
247 while( psz_cur && *psz_cur )
249 vlc_value_t val, text;
250 psz_next = strchr( psz_cur, ',' );
256 val.psz_string = psz_cur;
257 text.psz_string = psz_cur;
258 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
264 void vout_IntfInit( vout_thread_t *p_vout )
266 vlc_value_t val, text, old_val;
267 vlc_bool_t b_force_par = VLC_FALSE;
271 /* Create a few object variables we'll need later on */
272 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
273 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
274 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
275 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
276 var_Create( p_vout, "snapshot-sequential",
277 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
278 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
279 var_SetInteger( p_vout, "snapshot-num", 1 );
280 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
281 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
283 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
284 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
285 p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" );
287 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
288 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
290 p_vout->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
291 p_vout->i_title_timeout =
292 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
293 p_vout->i_title_position =
294 var_CreateGetInteger( p_vout, "video-title-position" );
296 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
297 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
298 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
300 /* Zoom object var */
301 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
302 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
304 text.psz_string = _("Zoom");
305 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
307 var_Get( p_vout, "zoom", &old_val );
309 for( i = 0; p_zoom_values[i].f_value; i++ )
311 if( old_val.f_float == p_zoom_values[i].f_value )
312 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
313 val.f_float = p_zoom_values[i].f_value;
314 text.psz_string = _( p_zoom_values[i].psz_label );
315 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
318 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
320 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
322 /* Crop offset vars */
323 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
324 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
325 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
326 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
328 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
329 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
330 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
331 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
333 /* Crop object var */
334 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
335 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
337 text.psz_string = _("Crop");
338 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
340 val.psz_string = (char*)"";
341 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
343 for( i = 0; p_crop_values[i].psz_value; i++ )
345 val.psz_string = (char*)p_crop_values[i].psz_value;
346 text.psz_string = _( p_crop_values[i].psz_label );
347 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
350 /* update triggered every time the vout's crop parameters are changed */
351 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
353 /* Add custom crop ratios */
354 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
355 AddCustomRatios( p_vout, "crop", psz_buf );
358 var_AddCallback( p_vout, "crop", CropCallback, NULL );
359 var_Get( p_vout, "crop", &old_val );
360 if( old_val.psz_string && *old_val.psz_string )
361 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
362 if( old_val.psz_string ) free( old_val.psz_string );
364 /* Monitor pixel aspect-ratio */
365 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
366 var_Get( p_vout, "monitor-par", &val );
367 if( val.psz_string && *val.psz_string )
369 char *psz_parser = strchr( val.psz_string, ':' );
370 unsigned int i_aspect_num = 0, i_aspect_den = 0;
374 i_aspect_num = strtol( val.psz_string, 0, 10 );
375 i_aspect_den = strtol( ++psz_parser, 0, 10 );
379 i_aspect = atof( val.psz_string );
380 vlc_ureduce( &i_aspect_num, &i_aspect_den,
381 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
383 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
385 p_vout->i_par_num = i_aspect_num;
386 p_vout->i_par_den = i_aspect_den;
388 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
389 p_vout->i_par_num, p_vout->i_par_den, 0 );
391 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
392 p_vout->i_par_num, p_vout->i_par_den );
393 b_force_par = VLC_TRUE;
395 if( val.psz_string ) free( val.psz_string );
397 /* Aspect-ratio object var */
398 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
399 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
401 text.psz_string = _("Aspect-ratio");
402 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
404 val.psz_string = (char*)"";
405 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
407 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
409 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
410 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
411 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
414 /* Add custom aspect ratios */
415 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
416 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
419 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
420 var_Get( p_vout, "aspect-ratio", &old_val );
421 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
422 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
423 if( old_val.psz_string ) free( old_val.psz_string );
425 /* Initialize the dimensions of the video window */
426 InitWindowSize( p_vout, &p_vout->i_window_width,
427 &p_vout->i_window_height );
429 /* Add a variable to indicate if the window should be on top of others */
430 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
431 | VLC_VAR_ISCOMMAND );
432 text.psz_string = _("Always on top");
433 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
434 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
436 /* Add a variable to indicate whether we want window decoration or not */
437 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
439 /* Add a fullscreen variable */
440 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
442 /* user requested fullscreen */
443 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
445 text.psz_string = _("Fullscreen");
446 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
447 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
449 /* Add a snapshot variable */
450 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
451 text.psz_string = _("Snapshot");
452 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
453 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
455 /* Mouse coordinates */
456 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
457 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
458 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
459 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
460 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
462 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
463 var_SetBool( p_vout, "intf-change", VLC_TRUE );
466 /*****************************************************************************
467 * vout_Snapshot: generates a snapshot.
468 *****************************************************************************/
469 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
471 image_handler_t *p_image = image_HandlerCreate( p_vout );
472 video_format_t fmt_in, fmt_out;
473 char *psz_filename = NULL;
474 subpicture_t *p_subpic;
476 vlc_value_t val, format;
480 memset( &fmt_in, 0, sizeof(video_format_t) );
481 memset( &fmt_out, 0, sizeof(video_format_t) );
483 var_Get( p_vout, "snapshot-path", &val );
484 if( val.psz_string && !*val.psz_string )
486 free( val.psz_string );
490 /* Embedded snapshot : if snapshot-path == object:object-id, then
491 create a snapshot_t* and store it in
492 object(object-id)->p_private, then unlock and signal the
495 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
498 vlc_object_t* p_dest;
500 snapshot_t *p_snapshot;
503 /* Destination object-id is following object: */
504 i_id = atoi( &val.psz_string[7] );
505 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
508 msg_Err( p_vout, "Cannot find calling object" );
509 image_HandlerDelete( p_image );
512 /* Object must be locked. We will unlock it once we get the
513 snapshot and written it to p_private */
514 p_dest->p_private = NULL;
516 /* Save the snapshot to a memory zone */
517 fmt_in = p_vout->fmt_in;
518 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
519 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
520 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
521 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
523 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
526 msg_Err( p_vout, "Could not get snapshot" );
527 image_HandlerDelete( p_image );
528 vlc_cond_signal( &p_dest->object_wait );
529 vlc_object_release( p_dest );
533 /* Copy the p_block data to a snapshot structure */
534 /* FIXME: get the timestamp */
535 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
538 block_Release( p_block );
539 image_HandlerDelete( p_image );
540 vlc_cond_signal( &p_dest->object_wait );
541 vlc_object_release( p_dest );
545 i_size = p_block->i_buffer;
547 p_snapshot->i_width = fmt_out.i_width;
548 p_snapshot->i_height = fmt_out.i_height;
549 p_snapshot->i_datasize = i_size;
550 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
551 p_snapshot->p_data = ( char* ) malloc( i_size );
552 if( !p_snapshot->p_data )
554 block_Release( p_block );
556 image_HandlerDelete( p_image );
557 vlc_cond_signal( &p_dest->object_wait );
558 vlc_object_release( p_dest );
561 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
563 p_dest->p_private = p_snapshot;
565 block_Release( p_block );
567 /* Unlock the object */
568 vlc_cond_signal( &p_dest->object_wait );
569 vlc_object_release( p_dest );
571 image_HandlerDelete( p_image );
575 #if defined(__APPLE__) || defined(SYS_BEOS)
576 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
578 if( asprintf( &val.psz_string, "%s/Desktop",
579 p_vout->p_libvlc->psz_homedir ) == -1 )
580 val.psz_string = NULL;
583 #elif defined(WIN32) && !defined(UNDER_CE)
584 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
586 /* Get the My Pictures folder path */
588 char *p_mypicturesdir = NULL;
589 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
591 #ifndef CSIDL_FLAG_CREATE
592 # define CSIDL_FLAG_CREATE 0x8000
594 #ifndef CSIDL_MYPICTURES
595 # define CSIDL_MYPICTURES 0x27
597 #ifndef SHGFP_TYPE_CURRENT
598 # define SHGFP_TYPE_CURRENT 0
601 HINSTANCE shfolder_dll;
602 SHGETFOLDERPATH SHGetFolderPath ;
604 /* load the shfolder dll to retrieve SHGetFolderPath */
605 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
607 wchar_t wdir[PATH_MAX];
608 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
609 _T("SHGetFolderPathW") );
610 if ((SHGetFolderPath != NULL )
611 && SUCCEEDED (SHGetFolderPath (NULL,
612 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
613 NULL, SHGFP_TYPE_CURRENT,
615 p_mypicturesdir = FromWide (wdir);
617 FreeLibrary( shfolder_dll );
620 if( p_mypicturesdir == NULL )
622 if( asprintf( &val.psz_string, "%s",
623 p_vout->p_libvlc->psz_homedir ) == -1 )
624 val.psz_string = NULL;
628 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
629 val.psz_string = NULL;
630 free( p_mypicturesdir );
635 /* XXX: This saves in the data directory. Shouldn't we try saving
636 * to psz_homedir/Desktop or something nicer ? */
637 if( !val.psz_string && p_vout->p_libvlc->psz_datadir )
639 if( asprintf( &val.psz_string, "%s",
640 p_vout->p_libvlc->psz_datadir ) == -1 )
641 val.psz_string = NULL;
645 if( !val.psz_string )
647 msg_Err( p_vout, "no path specified for snapshots" );
650 var_Get( p_vout, "snapshot-format", &format );
651 if( !format.psz_string || !*format.psz_string )
653 if( format.psz_string ) free( format.psz_string );
654 format.psz_string = strdup( "png" );
658 * Did the user specify a directory? If not, path = NULL.
660 path = utf8_opendir ( (const char *)val.psz_string );
663 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
664 if( psz_prefix == NULL )
665 psz_prefix = strdup( "vlcsnap-" );
668 char *psz_tmp = str_format( p_vout, psz_prefix );
669 filename_sanitize( psz_tmp );
671 psz_prefix = psz_tmp;
675 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
677 int i_num = var_GetInteger( p_vout, "snapshot-num" );
681 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
682 val.psz_string, psz_prefix, i_num++,
683 format.psz_string ) == -1 )
685 msg_Err( p_vout, "could not create snapshot" );
686 image_HandlerDelete( p_image );
690 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
691 var_SetInteger( p_vout, "snapshot-num", i_num );
695 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
696 val.psz_string, psz_prefix,
697 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
698 format.psz_string ) == -1 )
700 msg_Err( p_vout, "could not create snapshot" );
701 image_HandlerDelete( p_image );
708 else // The user specified a full path name (including file name)
710 psz_filename = str_format( p_vout, val.psz_string );
711 path_sanitize( psz_filename );
714 free( val.psz_string );
715 free( format.psz_string );
717 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
718 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
720 if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
722 float f = (float)p_vout->fmt_in.i_height / fmt_out.i_height;
723 fmt_out.i_width = p_vout->fmt_in.i_width / f;
725 else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
727 float f = (float)p_vout->fmt_in.i_width / fmt_out.i_width;
728 fmt_out.i_height = p_vout->fmt_in.i_height / f;
731 /* Save the snapshot */
732 fmt_in = p_vout->fmt_in;
733 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
734 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
735 if( i_ret != VLC_SUCCESS )
737 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
738 free( psz_filename );
739 image_HandlerDelete( p_image );
743 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
744 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
745 "%s", psz_filename );
746 free( psz_filename );
748 if( var_GetBool( p_vout, "snapshot-preview" ) )
750 /* Inject a subpicture with the snapshot */
751 memset( &fmt_out, 0, sizeof(fmt_out) );
752 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
753 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
754 image_HandlerDelete( p_image );
755 if( !p_pif ) return VLC_EGENERIC;
757 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
758 if( p_subpic == NULL )
760 p_pif->pf_release( p_pif );
764 p_subpic->i_channel = 0;
765 p_subpic->i_start = mdate();
766 p_subpic->i_stop = mdate() + 4000000;
767 p_subpic->b_ephemer = VLC_TRUE;
768 p_subpic->b_fade = VLC_TRUE;
769 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
770 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
772 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
773 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
775 p_pif->pf_release( p_pif );
777 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
781 image_HandlerDelete( p_image );
787 /*****************************************************************************
789 *****************************************************************************/
791 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
792 vlc_bool_t b_add, vlc_bool_t b_setconfig )
795 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
797 /* Todo : Use some generic chain manipulation functions */
798 if( !psz_string ) psz_string = strdup("");
800 psz_parser = strstr( psz_string, psz_name );
805 psz_parser = psz_string;
806 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
807 psz_string, psz_name ) == -1 )
821 memmove( psz_parser, psz_parser + strlen(psz_name) +
822 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
823 strlen(psz_parser + strlen(psz_name)) + 1 );
825 /* Remove trailing : : */
826 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
828 *(psz_string+strlen(psz_string ) -1 ) = '\0';
838 config_PutPsz( p_vout, "vout-filter", psz_string );
840 var_SetString( p_vout, "vout-filter", psz_string );
844 /*****************************************************************************
845 * vout_ControlDefault: default methods for video output control.
846 *****************************************************************************/
847 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
854 if( p_vout->p_parent_intf )
856 vlc_object_release( p_vout->p_parent_intf );
857 p_vout->p_parent_intf = NULL;
863 p_vout->b_snapshot = VLC_TRUE;
868 msg_Dbg( p_vout, "control query not supported" );
873 /*****************************************************************************
874 * InitWindowSize: find the initial dimensions the video window should have.
875 *****************************************************************************
876 * This function will check the "width", "height" and "zoom" config options and
877 * will calculate the size that the video window should have.
878 *****************************************************************************/
879 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
880 unsigned *pi_height )
883 int i_width, i_height;
886 #define FP_FACTOR 1000 /* our fixed point factor */
888 var_Get( p_vout, "width", &val );
890 var_Get( p_vout, "height", &val );
891 i_height = val.i_int;
892 var_Get( p_vout, "zoom", &val );
893 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
895 if( i_width > 0 && i_height > 0)
897 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
898 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
901 else if( i_width > 0 )
903 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
904 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
905 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
906 FP_FACTOR / p_vout->fmt_in.i_visible_width );
909 else if( i_height > 0 )
911 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
912 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
913 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
914 FP_FACTOR / p_vout->fmt_in.i_visible_height );
918 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
919 msg_Warn( p_vout, "fucked up aspect" );
920 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
921 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
923 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
925 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
926 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
927 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
932 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
934 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
935 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
939 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
940 p_vout->i_window_height );
945 /*****************************************************************************
946 * Object variables callbacks
947 *****************************************************************************/
948 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
949 vlc_value_t oldval, vlc_value_t newval, void *p_data )
951 vout_thread_t *p_vout = (vout_thread_t *)p_this;
952 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
953 InitWindowSize( p_vout, &p_vout->i_window_width,
954 &p_vout->i_window_height );
955 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
956 p_vout->i_window_height );
960 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
961 vlc_value_t oldval, vlc_value_t newval, void *p_data )
963 vout_thread_t *p_vout = (vout_thread_t *)p_this;
964 int64_t i_aspect_num, i_aspect_den;
965 unsigned int i_width, i_height;
967 (void)oldval; (void)p_data;
969 /* Restore defaults */
970 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
971 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
972 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
973 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
975 if( !strcmp( psz_cmd, "crop" ) )
977 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
980 /* We're using the 3:4 syntax */
981 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
982 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
984 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
985 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
987 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
988 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
989 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
990 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
992 if( i_width < p_vout->fmt_render.i_visible_width )
994 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
995 (p_vout->fmt_render.i_visible_width - i_width) / 2;
996 p_vout->fmt_in.i_visible_width = i_width;
1000 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
1001 (p_vout->fmt_render.i_visible_height - i_height) / 2;
1002 p_vout->fmt_in.i_visible_height = i_height;
1007 psz_parser = strchr( newval.psz_string, 'x' );
1010 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
1011 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
1013 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
1014 if( psz_end != psz_parser ) goto crop_end;
1016 psz_parser = strchr( ++psz_end, '+' );
1017 i_crop_height = strtol( psz_end, &psz_end, 10 );
1018 if( psz_end != psz_parser ) goto crop_end;
1020 psz_parser = strchr( ++psz_end, '+' );
1021 i_crop_left = strtol( psz_end, &psz_end, 10 );
1022 if( psz_end != psz_parser ) goto crop_end;
1025 i_crop_top = strtol( psz_end, &psz_end, 10 );
1026 if( *psz_end != '\0' ) goto crop_end;
1028 i_width = i_crop_width;
1029 p_vout->fmt_in.i_visible_width = i_width;
1031 i_height = i_crop_height;
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 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1040 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1042 psz_parser = strchr( newval.psz_string, '+' );
1043 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1044 if( psz_end != psz_parser ) goto crop_end;
1046 psz_parser = strchr( ++psz_end, '+' );
1047 i_crop_top = strtol( psz_end, &psz_end, 10 );
1048 if( psz_end != psz_parser ) goto crop_end;
1050 psz_parser = strchr( ++psz_end, '+' );
1051 i_crop_right = strtol( psz_end, &psz_end, 10 );
1052 if( psz_end != psz_parser ) goto crop_end;
1055 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1056 if( *psz_end != '\0' ) goto crop_end;
1058 i_width = p_vout->fmt_render.i_visible_width
1059 - i_crop_left - i_crop_right;
1060 p_vout->fmt_in.i_visible_width = i_width;
1062 i_height = p_vout->fmt_render.i_visible_height
1063 - i_crop_top - i_crop_bottom;
1064 p_vout->fmt_in.i_visible_height = i_height;
1066 p_vout->fmt_in.i_x_offset = i_crop_left;
1067 p_vout->fmt_in.i_y_offset = i_crop_top;
1071 else if( !strcmp( psz_cmd, "crop-top" )
1072 || !strcmp( psz_cmd, "crop-left" )
1073 || !strcmp( psz_cmd, "crop-bottom" )
1074 || !strcmp( psz_cmd, "crop-right" ) )
1076 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1078 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1079 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1080 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1081 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1083 i_width = p_vout->fmt_render.i_visible_width
1084 - i_crop_left - i_crop_right;
1085 p_vout->fmt_in.i_visible_width = i_width;
1087 i_height = p_vout->fmt_render.i_visible_height
1088 - i_crop_top - i_crop_bottom;
1089 p_vout->fmt_in.i_visible_height = i_height;
1091 p_vout->fmt_in.i_x_offset = i_crop_left;
1092 p_vout->fmt_in.i_y_offset = i_crop_top;
1096 InitWindowSize( p_vout, &p_vout->i_window_width,
1097 &p_vout->i_window_height );
1099 p_vout->i_changes |= VOUT_CROP_CHANGE;
1101 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1102 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1103 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1104 p_vout->fmt_in.i_visible_width,
1105 p_vout->fmt_in.i_visible_height );
1107 var_SetVoid( p_vout, "crop-update" );
1112 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1113 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1115 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1116 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1119 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1120 (void)psz_cmd; (void)oldval; (void)p_data;
1122 /* Restore defaults */
1123 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1124 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1125 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1126 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1128 if( !psz_parser ) goto aspect_end;
1130 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1131 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1133 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1134 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1136 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1137 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1138 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1139 p_vout->fmt_in.i_sar_num = i_sar_num;
1140 p_vout->fmt_in.i_sar_den = i_sar_den;
1141 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1142 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1145 if( p_vout->i_par_num && p_vout->i_par_den )
1147 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1148 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1149 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1150 p_vout->i_par_den / p_vout->i_par_num;
1151 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1154 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1156 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1157 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1158 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1159 i_aspect_num, i_aspect_den,
1160 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1162 var_Get( p_vout, "crop", &val );
1163 return CropCallback( p_this, "crop", val, val, 0 );
1166 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1167 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1169 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1170 playlist_t *p_playlist = pl_Yield( p_this );
1171 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1172 (void)psz_cmd; (void)oldval; (void)p_data;
1174 /* Modify playlist as well because the vout might have to be restarted */
1175 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1176 var_Set( p_playlist, "video-on-top", newval );
1178 pl_Release( p_this );
1182 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1183 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1185 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1187 playlist_t *p_playlist = pl_Yield( p_this );
1188 (void)psz_cmd; (void)oldval; (void)p_data;
1190 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1192 /* Modify playlist as well because the vout might have to be restarted */
1193 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1194 var_Set( p_playlist, "fullscreen", newval );
1195 pl_Release( p_playlist );
1197 val.b_bool = VLC_TRUE;
1198 var_Set( p_vout, "intf-change", val );
1202 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1203 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1205 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1206 VLC_UNUSED(newval); VLC_UNUSED(p_data);
1207 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1208 vout_Control( p_vout, VOUT_SNAPSHOT );
1212 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1213 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1215 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1217 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1218 p_vout->b_title_show = newval.b_bool;
1222 static int TitleTimeoutCallback( vlc_object_t *p_this, char const *psz_cmd,
1223 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1225 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1226 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1227 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1231 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1232 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1234 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1236 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1237 p_vout->i_title_position = newval.i_int;