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 var_Create( p_vout, "mouse-hide-timeout",
291 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
293 p_vout->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
294 p_vout->i_title_timeout =
295 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
296 p_vout->i_title_position =
297 var_CreateGetInteger( p_vout, "video-title-position" );
299 var_AddCallback( p_vout, "video-title-show", TitleShowCallback, NULL );
300 var_AddCallback( p_vout, "video-title-timeout", TitleTimeoutCallback, NULL );
301 var_AddCallback( p_vout, "video-title-position", TitlePositionCallback, NULL );
303 /* Zoom object var */
304 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
305 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
307 text.psz_string = _("Zoom");
308 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
310 var_Get( p_vout, "zoom", &old_val );
312 for( i = 0; p_zoom_values[i].f_value; i++ )
314 if( old_val.f_float == p_zoom_values[i].f_value )
315 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
316 val.f_float = p_zoom_values[i].f_value;
317 text.psz_string = _( p_zoom_values[i].psz_label );
318 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
321 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
323 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
325 /* Crop offset vars */
326 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
327 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
328 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
329 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
331 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
332 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
333 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
334 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
336 /* Crop object var */
337 var_Create( p_vout, "crop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
338 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
340 text.psz_string = _("Crop");
341 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
343 val.psz_string = (char*)"";
344 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
346 for( i = 0; p_crop_values[i].psz_value; i++ )
348 val.psz_string = (char*)p_crop_values[i].psz_value;
349 text.psz_string = _( p_crop_values[i].psz_label );
350 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
353 /* update triggered every time the vout's crop parameters are changed */
354 var_Create( p_vout, "crop-update", VLC_VAR_VOID );
356 /* Add custom crop ratios */
357 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
358 AddCustomRatios( p_vout, "crop", psz_buf );
361 var_AddCallback( p_vout, "crop", CropCallback, NULL );
362 var_Get( p_vout, "crop", &old_val );
363 if( old_val.psz_string && *old_val.psz_string )
364 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
365 free( old_val.psz_string );
367 /* Monitor pixel aspect-ratio */
368 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
369 var_Get( p_vout, "monitor-par", &val );
370 if( val.psz_string && *val.psz_string )
372 char *psz_parser = strchr( val.psz_string, ':' );
373 unsigned int i_aspect_num = 0, i_aspect_den = 0;
377 i_aspect_num = strtol( val.psz_string, 0, 10 );
378 i_aspect_den = strtol( ++psz_parser, 0, 10 );
382 i_aspect = atof( val.psz_string );
383 vlc_ureduce( &i_aspect_num, &i_aspect_den,
384 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
386 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
388 p_vout->i_par_num = i_aspect_num;
389 p_vout->i_par_den = i_aspect_den;
391 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
392 p_vout->i_par_num, p_vout->i_par_den, 0 );
394 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
395 p_vout->i_par_num, p_vout->i_par_den );
396 b_force_par = VLC_TRUE;
398 free( val.psz_string );
400 /* Aspect-ratio object var */
401 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND |
402 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
404 text.psz_string = _("Aspect-ratio");
405 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
407 val.psz_string = (char*)"";
408 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
410 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
412 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
413 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
414 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
417 /* Add custom aspect ratios */
418 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
419 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
422 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
423 var_Get( p_vout, "aspect-ratio", &old_val );
424 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
425 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
426 free( old_val.psz_string );
428 /* Initialize the dimensions of the video window */
429 InitWindowSize( p_vout, &p_vout->i_window_width,
430 &p_vout->i_window_height );
432 /* Add a variable to indicate if the window should be on top of others */
433 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT
434 | VLC_VAR_ISCOMMAND );
435 text.psz_string = _("Always on top");
436 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
437 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
439 /* Add a variable to indicate whether we want window decoration or not */
440 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
442 /* Add a fullscreen variable */
443 if( var_CreateGetBoolCommand( p_vout, "fullscreen" ) )
445 /* user requested fullscreen */
446 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
448 text.psz_string = _("Fullscreen");
449 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
450 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
452 /* Add a snapshot variable */
453 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
454 text.psz_string = _("Snapshot");
455 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
456 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
458 /* Mouse coordinates */
459 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
460 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
461 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
462 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
463 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
465 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
466 var_SetBool( p_vout, "intf-change", VLC_TRUE );
469 /*****************************************************************************
470 * vout_Snapshot: generates a snapshot.
471 *****************************************************************************/
472 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
474 image_handler_t *p_image = image_HandlerCreate( p_vout );
475 video_format_t fmt_in, fmt_out;
476 char *psz_filename = NULL;
477 subpicture_t *p_subpic;
479 vlc_value_t val, format;
483 memset( &fmt_in, 0, sizeof(video_format_t) );
484 memset( &fmt_out, 0, sizeof(video_format_t) );
486 var_Get( p_vout, "snapshot-path", &val );
487 if( val.psz_string && !*val.psz_string )
489 free( val.psz_string );
493 /* Embedded snapshot : if snapshot-path == object:object-id, then
494 create a snapshot_t* and store it in
495 object(object-id)->p_private, then unlock and signal the
498 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
501 vlc_object_t* p_dest;
503 snapshot_t *p_snapshot;
506 /* Destination object-id is following object: */
507 i_id = atoi( &val.psz_string[7] );
508 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
511 msg_Err( p_vout, "Cannot find calling object" );
512 image_HandlerDelete( p_image );
515 /* Object must be locked. We will unlock it once we get the
516 snapshot and written it to p_private */
517 p_dest->p_private = NULL;
519 /* Save the snapshot to a memory zone */
520 fmt_in = p_vout->fmt_in;
521 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
522 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
523 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
524 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
526 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
529 msg_Err( p_vout, "Could not get snapshot" );
530 image_HandlerDelete( p_image );
531 vlc_cond_signal( &p_dest->object_wait );
532 vlc_object_release( p_dest );
536 /* Copy the p_block data to a snapshot structure */
537 /* FIXME: get the timestamp */
538 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
541 block_Release( p_block );
542 image_HandlerDelete( p_image );
543 vlc_cond_signal( &p_dest->object_wait );
544 vlc_object_release( p_dest );
548 i_size = p_block->i_buffer;
550 p_snapshot->i_width = fmt_out.i_width;
551 p_snapshot->i_height = fmt_out.i_height;
552 p_snapshot->i_datasize = i_size;
553 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
554 p_snapshot->p_data = ( char* ) malloc( i_size );
555 if( !p_snapshot->p_data )
557 block_Release( p_block );
559 image_HandlerDelete( p_image );
560 vlc_cond_signal( &p_dest->object_wait );
561 vlc_object_release( p_dest );
564 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
566 p_dest->p_private = p_snapshot;
568 block_Release( p_block );
570 /* Unlock the object */
571 vlc_cond_signal( &p_dest->object_wait );
572 vlc_object_release( p_dest );
574 image_HandlerDelete( p_image );
578 #if defined(__APPLE__) || defined(SYS_BEOS)
579 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
581 if( asprintf( &val.psz_string, "%s/Desktop",
582 p_vout->p_libvlc->psz_homedir ) == -1 )
583 val.psz_string = NULL;
586 #elif defined(WIN32) && !defined(UNDER_CE)
587 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
589 /* Get the My Pictures folder path */
591 char *p_mypicturesdir = NULL;
592 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
594 #ifndef CSIDL_FLAG_CREATE
595 # define CSIDL_FLAG_CREATE 0x8000
597 #ifndef CSIDL_MYPICTURES
598 # define CSIDL_MYPICTURES 0x27
600 #ifndef SHGFP_TYPE_CURRENT
601 # define SHGFP_TYPE_CURRENT 0
604 HINSTANCE shfolder_dll;
605 SHGETFOLDERPATH SHGetFolderPath ;
607 /* load the shfolder dll to retrieve SHGetFolderPath */
608 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
610 wchar_t wdir[PATH_MAX];
611 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
612 _T("SHGetFolderPathW") );
613 if ((SHGetFolderPath != NULL )
614 && SUCCEEDED (SHGetFolderPath (NULL,
615 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
616 NULL, SHGFP_TYPE_CURRENT,
618 p_mypicturesdir = FromWide (wdir);
620 FreeLibrary( shfolder_dll );
623 if( p_mypicturesdir == NULL )
625 if( asprintf( &val.psz_string, "%s",
626 p_vout->p_libvlc->psz_homedir ) == -1 )
627 val.psz_string = NULL;
631 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
632 val.psz_string = NULL;
633 free( p_mypicturesdir );
638 /* XXX: This saves in the data directory. Shouldn't we try saving
639 * to psz_homedir/Desktop or something nicer ? */
640 if( !val.psz_string && p_vout->p_libvlc->psz_datadir )
642 if( asprintf( &val.psz_string, "%s",
643 p_vout->p_libvlc->psz_datadir ) == -1 )
644 val.psz_string = NULL;
648 if( !val.psz_string )
650 msg_Err( p_vout, "no path specified for snapshots" );
653 var_Get( p_vout, "snapshot-format", &format );
654 if( !format.psz_string || !*format.psz_string )
656 free( format.psz_string );
657 format.psz_string = strdup( "png" );
661 * Did the user specify a directory? If not, path = NULL.
663 path = utf8_opendir ( (const char *)val.psz_string );
666 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
667 if( psz_prefix == NULL )
668 psz_prefix = strdup( "vlcsnap-" );
671 char *psz_tmp = str_format( p_vout, psz_prefix );
672 filename_sanitize( psz_tmp );
674 psz_prefix = psz_tmp;
678 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
680 int i_num = var_GetInteger( p_vout, "snapshot-num" );
684 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
685 val.psz_string, psz_prefix, i_num++,
686 format.psz_string ) == -1 )
688 msg_Err( p_vout, "could not create snapshot" );
689 image_HandlerDelete( p_image );
693 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
694 var_SetInteger( p_vout, "snapshot-num", i_num );
698 if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
699 val.psz_string, psz_prefix,
700 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
701 format.psz_string ) == -1 )
703 msg_Err( p_vout, "could not create snapshot" );
704 image_HandlerDelete( p_image );
711 else // The user specified a full path name (including file name)
713 psz_filename = str_format( p_vout, val.psz_string );
714 path_sanitize( psz_filename );
717 free( val.psz_string );
718 free( format.psz_string );
720 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
721 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
723 fmt_in = p_vout->fmt_in;
725 if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
727 float f = (float)fmt_in.i_height / fmt_out.i_height;
728 fmt_out.i_width = fmt_in.i_width / f;
730 else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
732 float f = (float)fmt_in.i_width / fmt_out.i_width;
733 fmt_out.i_height = fmt_in.i_height / f;
737 fmt_out.i_width = fmt_in.i_width;
738 fmt_out.i_height = fmt_in.i_height;
741 /* Save the snapshot */
742 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
743 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
744 if( i_ret != VLC_SUCCESS )
746 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
747 free( psz_filename );
748 image_HandlerDelete( p_image );
752 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
753 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
754 "%s", psz_filename );
755 free( psz_filename );
757 if( var_GetBool( p_vout, "snapshot-preview" ) )
759 /* Inject a subpicture with the snapshot */
760 memset( &fmt_out, 0, sizeof(fmt_out) );
761 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
762 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
763 image_HandlerDelete( p_image );
764 if( !p_pif ) return VLC_EGENERIC;
766 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
767 if( p_subpic == NULL )
769 p_pif->pf_release( p_pif );
773 p_subpic->i_channel = 0;
774 p_subpic->i_start = mdate();
775 p_subpic->i_stop = mdate() + 4000000;
776 p_subpic->b_ephemer = VLC_TRUE;
777 p_subpic->b_fade = VLC_TRUE;
778 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
779 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
781 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
782 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
784 p_pif->pf_release( p_pif );
786 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
790 image_HandlerDelete( p_image );
796 /*****************************************************************************
798 *****************************************************************************/
800 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
801 vlc_bool_t b_add, vlc_bool_t b_setconfig )
804 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
806 /* Todo : Use some generic chain manipulation functions */
807 if( !psz_string ) psz_string = strdup("");
809 psz_parser = strstr( psz_string, psz_name );
814 psz_parser = psz_string;
815 if( asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
816 psz_string, psz_name ) == -1 )
830 memmove( psz_parser, psz_parser + strlen(psz_name) +
831 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
832 strlen(psz_parser + strlen(psz_name)) + 1 );
834 /* Remove trailing : : */
835 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
837 *(psz_string+strlen(psz_string ) -1 ) = '\0';
847 config_PutPsz( p_vout, "vout-filter", psz_string );
849 var_SetString( p_vout, "vout-filter", psz_string );
853 /*****************************************************************************
854 * vout_ControlDefault: default methods for video output control.
855 *****************************************************************************/
856 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
863 if( p_vout->p_parent_intf )
865 vlc_object_release( p_vout->p_parent_intf );
866 p_vout->p_parent_intf = NULL;
872 p_vout->b_snapshot = VLC_TRUE;
877 msg_Dbg( p_vout, "control query not supported" );
882 /*****************************************************************************
883 * InitWindowSize: find the initial dimensions the video window should have.
884 *****************************************************************************
885 * This function will check the "width", "height" and "zoom" config options and
886 * will calculate the size that the video window should have.
887 *****************************************************************************/
888 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
889 unsigned *pi_height )
892 int i_width, i_height;
895 #define FP_FACTOR 1000 /* our fixed point factor */
897 var_Get( p_vout, "width", &val );
899 var_Get( p_vout, "height", &val );
900 i_height = val.i_int;
901 var_Get( p_vout, "zoom", &val );
902 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
904 if( i_width > 0 && i_height > 0)
906 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
907 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
910 else if( i_width > 0 )
912 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
913 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
914 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
915 FP_FACTOR / p_vout->fmt_in.i_visible_width );
918 else if( i_height > 0 )
920 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
921 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
922 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
923 FP_FACTOR / p_vout->fmt_in.i_visible_height );
927 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
928 msg_Warn( p_vout, "fucked up aspect" );
929 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
930 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
932 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
934 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
935 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
936 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
941 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
943 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
944 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
948 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
949 p_vout->i_window_height );
954 /*****************************************************************************
955 * Object variables callbacks
956 *****************************************************************************/
957 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
958 vlc_value_t oldval, vlc_value_t newval, void *p_data )
960 vout_thread_t *p_vout = (vout_thread_t *)p_this;
961 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
962 InitWindowSize( p_vout, &p_vout->i_window_width,
963 &p_vout->i_window_height );
964 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
965 p_vout->i_window_height );
969 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
970 vlc_value_t oldval, vlc_value_t newval, void *p_data )
972 vout_thread_t *p_vout = (vout_thread_t *)p_this;
973 int64_t i_aspect_num, i_aspect_den;
974 unsigned int i_width, i_height;
976 (void)oldval; (void)p_data;
978 /* Restore defaults */
979 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
980 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
981 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
982 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
984 if( !strcmp( psz_cmd, "crop" ) )
986 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
989 /* We're using the 3:4 syntax */
990 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
991 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
993 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
994 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
996 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
997 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
998 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
999 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
1001 if( i_width < p_vout->fmt_render.i_visible_width )
1003 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
1004 (p_vout->fmt_render.i_visible_width - i_width) / 2;
1005 p_vout->fmt_in.i_visible_width = i_width;
1009 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
1010 (p_vout->fmt_render.i_visible_height - i_height) / 2;
1011 p_vout->fmt_in.i_visible_height = i_height;
1016 psz_parser = strchr( newval.psz_string, 'x' );
1019 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
1020 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
1022 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
1023 if( psz_end != psz_parser ) goto crop_end;
1025 psz_parser = strchr( ++psz_end, '+' );
1026 i_crop_height = strtol( psz_end, &psz_end, 10 );
1027 if( psz_end != psz_parser ) goto crop_end;
1029 psz_parser = strchr( ++psz_end, '+' );
1030 i_crop_left = strtol( psz_end, &psz_end, 10 );
1031 if( psz_end != psz_parser ) goto crop_end;
1034 i_crop_top = strtol( psz_end, &psz_end, 10 );
1035 if( *psz_end != '\0' ) goto crop_end;
1037 i_width = i_crop_width;
1038 p_vout->fmt_in.i_visible_width = i_width;
1040 i_height = i_crop_height;
1041 p_vout->fmt_in.i_visible_height = i_height;
1043 p_vout->fmt_in.i_x_offset = i_crop_left;
1044 p_vout->fmt_in.i_y_offset = i_crop_top;
1048 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1049 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1051 psz_parser = strchr( newval.psz_string, '+' );
1052 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1053 if( psz_end != psz_parser ) goto crop_end;
1055 psz_parser = strchr( ++psz_end, '+' );
1056 i_crop_top = strtol( psz_end, &psz_end, 10 );
1057 if( psz_end != psz_parser ) goto crop_end;
1059 psz_parser = strchr( ++psz_end, '+' );
1060 i_crop_right = strtol( psz_end, &psz_end, 10 );
1061 if( psz_end != psz_parser ) goto crop_end;
1064 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1065 if( *psz_end != '\0' ) goto crop_end;
1067 i_width = p_vout->fmt_render.i_visible_width
1068 - i_crop_left - i_crop_right;
1069 p_vout->fmt_in.i_visible_width = i_width;
1071 i_height = p_vout->fmt_render.i_visible_height
1072 - i_crop_top - i_crop_bottom;
1073 p_vout->fmt_in.i_visible_height = i_height;
1075 p_vout->fmt_in.i_x_offset = i_crop_left;
1076 p_vout->fmt_in.i_y_offset = i_crop_top;
1080 else if( !strcmp( psz_cmd, "crop-top" )
1081 || !strcmp( psz_cmd, "crop-left" )
1082 || !strcmp( psz_cmd, "crop-bottom" )
1083 || !strcmp( psz_cmd, "crop-right" ) )
1085 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1087 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1088 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1089 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1090 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1092 i_width = p_vout->fmt_render.i_visible_width
1093 - i_crop_left - i_crop_right;
1094 p_vout->fmt_in.i_visible_width = i_width;
1096 i_height = p_vout->fmt_render.i_visible_height
1097 - i_crop_top - i_crop_bottom;
1098 p_vout->fmt_in.i_visible_height = i_height;
1100 p_vout->fmt_in.i_x_offset = i_crop_left;
1101 p_vout->fmt_in.i_y_offset = i_crop_top;
1105 InitWindowSize( p_vout, &p_vout->i_window_width,
1106 &p_vout->i_window_height );
1108 p_vout->i_changes |= VOUT_CROP_CHANGE;
1110 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1111 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1112 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1113 p_vout->fmt_in.i_visible_width,
1114 p_vout->fmt_in.i_visible_height );
1116 var_SetVoid( p_vout, "crop-update" );
1121 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1122 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1124 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1125 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1128 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1129 (void)psz_cmd; (void)oldval; (void)p_data;
1131 /* Restore defaults */
1132 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1133 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1134 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1135 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1137 if( !psz_parser ) goto aspect_end;
1139 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1140 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1142 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1143 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1145 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1146 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1147 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1148 p_vout->fmt_in.i_sar_num = i_sar_num;
1149 p_vout->fmt_in.i_sar_den = i_sar_den;
1150 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1151 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1154 if( p_vout->i_par_num && p_vout->i_par_den )
1156 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1157 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1158 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1159 p_vout->i_par_den / p_vout->i_par_num;
1160 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1163 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1165 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1166 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1167 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1168 i_aspect_num, i_aspect_den,
1169 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1171 var_Get( p_vout, "crop", &val );
1172 return CropCallback( p_this, "crop", val, val, 0 );
1175 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1176 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1178 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1179 playlist_t *p_playlist = pl_Yield( p_this );
1180 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1181 (void)psz_cmd; (void)oldval; (void)p_data;
1183 /* Modify playlist as well because the vout might have to be restarted */
1184 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1185 var_Set( p_playlist, "video-on-top", newval );
1187 pl_Release( p_this );
1191 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1192 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1194 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1196 playlist_t *p_playlist = pl_Yield( p_this );
1197 (void)psz_cmd; (void)oldval; (void)p_data;
1199 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1201 /* Modify playlist as well because the vout might have to be restarted */
1202 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1203 var_Set( p_playlist, "fullscreen", newval );
1204 pl_Release( p_playlist );
1206 val.b_bool = VLC_TRUE;
1207 var_Set( p_vout, "intf-change", val );
1211 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1212 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1214 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1215 VLC_UNUSED(newval); VLC_UNUSED(p_data);
1216 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1217 vout_Control( p_vout, VOUT_SNAPSHOT );
1221 static int TitleShowCallback( vlc_object_t *p_this, char const *psz_cmd,
1222 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1224 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1226 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1227 p_vout->b_title_show = newval.b_bool;
1231 static int TitleTimeoutCallback( 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); VLC_UNUSED(p_data);
1235 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1236 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1240 static int TitlePositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1241 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1243 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
1245 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1246 p_vout->i_title_position = newval.i_int;