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 *****************************************************************************/
31 #include <stdlib.h> /* free() */
32 #include <sys/types.h> /* opendir() */
33 #include <dirent.h> /* opendir() */
35 #include <vlc_interface.h>
36 #include <vlc_block.h>
37 #include <vlc_playlist.h>
40 #include <vlc_image.h>
42 #include <vlc_charset.h>
44 #include <vlc_strings.h>
45 #include <vlc_charset.h>
46 #include "../libvlc.h"
48 /*****************************************************************************
50 *****************************************************************************/
51 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
53 /* Object variables callbacks */
54 static int ZoomCallback( vlc_object_t *, char const *,
55 vlc_value_t, vlc_value_t, void * );
56 static int CropCallback( vlc_object_t *, char const *,
57 vlc_value_t, vlc_value_t, void * );
58 static int AspectCallback( vlc_object_t *, char const *,
59 vlc_value_t, vlc_value_t, void * );
60 static int OnTopCallback( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
62 static int FullscreenCallback( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
64 static int SnapshotCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
66 static int TitleCallback( vlc_object_t *, char const *,
67 vlc_value_t, vlc_value_t, void * );
69 /*****************************************************************************
70 * vout_RequestWindow: Create/Get a video window if possible.
71 *****************************************************************************
72 * This function looks for the main interface and tries to request
73 * a new video window. If it fails then the vout will still need to create the
75 *****************************************************************************/
76 void *vout_RequestWindow( vout_thread_t *p_vout,
77 int *pi_x_hint, int *pi_y_hint,
78 unsigned int *pi_width_hint,
79 unsigned int *pi_height_hint )
81 intf_thread_t *p_intf = NULL;
88 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
90 /* Get requested coordinates */
91 var_Get( p_vout, "video-x", &val );
92 *pi_x_hint = val.i_int ;
93 var_Get( p_vout, "video-y", &val );
94 *pi_y_hint = val.i_int;
96 *pi_width_hint = p_vout->i_window_width;
97 *pi_height_hint = p_vout->i_window_height;
99 /* Check whether someone provided us with a window ID */
100 var_Get( p_vout->p_libvlc, "drawable", &val );
101 if( val.i_int ) return (void *)(intptr_t)val.i_int;
103 /* Find if the main interface supports embedding */
104 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
105 if( !p_list ) return NULL;
107 for( i = 0; i < p_list->i_count; i++ )
109 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
110 if( p_intf->pf_request_window ) break;
116 vlc_list_release( p_list );
120 vlc_object_yield( p_intf );
121 vlc_list_release( p_list );
123 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
124 pi_width_hint, pi_height_hint );
126 if( !p_window ) vlc_object_release( p_intf );
127 else p_vout->p_parent_intf = p_intf;
132 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
134 intf_thread_t *p_intf = p_vout->p_parent_intf;
136 if( !p_intf ) return;
138 vlc_mutex_lock( &p_intf->object_lock );
141 vlc_mutex_unlock( &p_intf->object_lock );
145 if( !p_intf->pf_release_window )
147 msg_Err( p_vout, "no pf_release_window");
148 vlc_mutex_unlock( &p_intf->object_lock );
149 vlc_object_release( p_intf );
153 p_intf->pf_release_window( p_intf, p_window );
155 p_vout->p_parent_intf = NULL;
156 vlc_mutex_unlock( &p_intf->object_lock );
157 vlc_object_release( p_intf );
160 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
161 int i_query, va_list args )
163 intf_thread_t *p_intf = p_vout->p_parent_intf;
166 if( !p_intf ) return VLC_EGENERIC;
168 vlc_mutex_lock( &p_intf->object_lock );
171 vlc_mutex_unlock( &p_intf->object_lock );
175 if( !p_intf->pf_control_window )
177 msg_Err( p_vout, "no pf_control_window");
178 vlc_mutex_unlock( &p_intf->object_lock );
182 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
183 vlc_mutex_unlock( &p_intf->object_lock );
187 /*****************************************************************************
188 * vout_IntfInit: called during the vout creation to initialise misc things.
189 *****************************************************************************/
193 const char *psz_label;
194 } p_zoom_values[] = {
195 { 0.25, N_("1:4 Quarter") },
196 { 0.5, N_("1:2 Half") },
197 { 1, N_("1:1 Original") },
198 { 2, N_("2:1 Double") },
203 const char *psz_value;
204 const char *psz_label;
205 } p_crop_values[] = {
206 { "", N_("Default") },
210 { "16:10", "16:10" },
213 { "1.85:1", "1.85:1" },
214 { "221:100", "2.21:1" },
215 { "235:100", "2.35:1" },
216 { "239:100", "2.39:1" },
221 const char *psz_value;
222 const char *psz_label;
223 } p_aspect_ratio_values[] = {
224 { "", N_("Default") },
228 { "16:10", "16:10" },
229 { "221:100", "2.21:1" },
233 static void AddCustomRatios( vout_thread_t *p_vout, const char *psz_var,
236 if( psz_list && *psz_list )
238 char *psz_cur = psz_list;
240 while( psz_cur && *psz_cur )
242 vlc_value_t val, text;
243 psz_next = strchr( psz_cur, ',' );
249 val.psz_string = psz_cur;
250 text.psz_string = psz_cur;
251 var_Change( p_vout, psz_var, VLC_VAR_ADDCHOICE, &val, &text);
257 void vout_IntfInit( vout_thread_t *p_vout )
259 vlc_value_t val, text, old_val;
260 vlc_bool_t b_force_par = VLC_FALSE;
264 /* Create a few object variables we'll need later on */
265 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
266 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
267 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
268 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
269 var_Create( p_vout, "snapshot-sequential",
270 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
271 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
272 var_SetInteger( p_vout, "snapshot-num", 1 );
273 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
274 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
276 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
277 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
278 p_vout->i_alignment = var_CreateGetInteger( p_vout, "align" );
280 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
281 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
283 p_vout->b_title_show = var_CreateGetBool( p_vout, "video-title-show" );
284 p_vout->i_title_timeout =
285 (mtime_t)var_CreateGetInteger( p_vout, "video-title-timeout" );
286 p_vout->i_title_position =
287 var_CreateGetInteger( p_vout, "video-title-position" );
289 var_AddCallback( p_vout, "video-title-show", TitleCallback, NULL );
290 var_AddCallback( p_vout, "video-title-timeout", TitleCallback, NULL );
291 var_AddCallback( p_vout, "video-title-position", TitleCallback, NULL );
293 /* Zoom object var */
294 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
295 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
297 text.psz_string = _("Zoom");
298 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
300 var_Get( p_vout, "zoom", &old_val );
302 for( i = 0; p_zoom_values[i].f_value; i++ )
304 if( old_val.f_float == p_zoom_values[i].f_value )
305 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
306 val.f_float = p_zoom_values[i].f_value;
307 text.psz_string = _( p_zoom_values[i].psz_label );
308 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
311 var_Set( p_vout, "zoom", old_val ); /* Is this really needed? */
313 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
315 /* Crop offset vars */
316 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
317 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
318 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
319 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
321 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
322 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
323 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
324 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
326 /* Crop object var */
327 var_Create( p_vout, "crop", VLC_VAR_STRING |
328 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
330 text.psz_string = _("Crop");
331 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
333 val.psz_string = (char*)"";
334 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
336 for( i = 0; p_crop_values[i].psz_value; i++ )
338 val.psz_string = (char*)p_crop_values[i].psz_value;
339 text.psz_string = _( p_crop_values[i].psz_label );
340 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
343 /* Add custom crop ratios */
344 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
345 AddCustomRatios( p_vout, "crop", psz_buf );
348 var_AddCallback( p_vout, "crop", CropCallback, NULL );
349 var_Get( p_vout, "crop", &old_val );
350 if( old_val.psz_string && *old_val.psz_string )
351 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
352 if( old_val.psz_string ) free( old_val.psz_string );
354 /* Monitor pixel aspect-ratio */
355 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
356 var_Get( p_vout, "monitor-par", &val );
357 if( val.psz_string && *val.psz_string )
359 char *psz_parser = strchr( val.psz_string, ':' );
360 unsigned int i_aspect_num = 0, i_aspect_den = 0;
364 i_aspect_num = strtol( val.psz_string, 0, 10 );
365 i_aspect_den = strtol( ++psz_parser, 0, 10 );
369 i_aspect = atof( val.psz_string );
370 vlc_ureduce( &i_aspect_num, &i_aspect_den,
371 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
373 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
375 p_vout->i_par_num = i_aspect_num;
376 p_vout->i_par_den = i_aspect_den;
378 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
379 p_vout->i_par_num, p_vout->i_par_den, 0 );
381 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
382 p_vout->i_par_num, p_vout->i_par_den );
383 b_force_par = VLC_TRUE;
385 if( val.psz_string ) free( val.psz_string );
387 /* Aspect-ratio object var */
388 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
389 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
391 text.psz_string = _("Aspect-ratio");
392 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
394 val.psz_string = (char*)"";
395 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
397 for( i = 0; p_aspect_ratio_values[i].psz_value; i++ )
399 val.psz_string = (char*)p_aspect_ratio_values[i].psz_value;
400 text.psz_string = _( p_aspect_ratio_values[i].psz_label );
401 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
404 /* Add custom aspect ratios */
405 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
406 AddCustomRatios( p_vout, "aspect-ratio", psz_buf );
409 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
410 var_Get( p_vout, "aspect-ratio", &old_val );
411 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
412 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
413 if( old_val.psz_string ) free( old_val.psz_string );
415 /* Initialize the dimensions of the video window */
416 InitWindowSize( p_vout, &p_vout->i_window_width,
417 &p_vout->i_window_height );
419 /* Add a variable to indicate if the window should be on top of others */
420 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
421 text.psz_string = _("Always on top");
422 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
423 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
425 /* Add a variable to indicate whether we want window decoration or not */
426 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
428 /* Add a fullscreen variable */
429 if( var_CreateGetBool( p_vout, "fullscreen" ) )
431 /* user requested fullscreen */
432 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
434 text.psz_string = _("Fullscreen");
435 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
436 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
438 /* Add a snapshot variable */
439 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
440 text.psz_string = _("Snapshot");
441 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
442 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
444 /* Mouse coordinates */
445 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
446 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
447 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
448 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
449 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
451 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
452 var_SetBool( p_vout, "intf-change", VLC_TRUE );
455 /*****************************************************************************
456 * vout_Snapshot: generates a snapshot.
457 *****************************************************************************/
458 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
460 image_handler_t *p_image = image_HandlerCreate( p_vout );
461 video_format_t fmt_in, fmt_out;
462 char *psz_filename = NULL;
463 subpicture_t *p_subpic;
465 vlc_value_t val, format;
469 memset( &fmt_in, 0, sizeof(video_format_t));
470 memset( &fmt_out, 0, sizeof(video_format_t));
472 var_Get( p_vout, "snapshot-path", &val );
473 if( val.psz_string && !*val.psz_string )
475 free( val.psz_string );
479 /* Embedded snapshot : if snapshot-path == object:object-id, then
480 create a snapshot_t* and store it in
481 object(object-id)->p_private, then unlock and signal the
484 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
487 vlc_object_t* p_dest;
489 snapshot_t *p_snapshot;
492 /* Destination object-id is following object: */
493 i_id = atoi( &val.psz_string[7] );
494 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
497 msg_Err( p_vout, "Cannot find calling object" );
498 image_HandlerDelete( p_image );
501 /* Object must be locked. We will unlock it once we get the
502 snapshot and written it to p_private */
503 p_dest->p_private = NULL;
505 /* Save the snapshot to a memory zone */
506 fmt_in = p_vout->fmt_in;
507 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
508 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
509 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
510 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
512 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
515 msg_Err( p_vout, "Could not get snapshot" );
516 image_HandlerDelete( p_image );
517 vlc_cond_signal( &p_dest->object_wait );
518 vlc_object_release( p_dest );
522 /* Copy the p_block data to a snapshot structure */
523 /* FIXME: get the timestamp */
524 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
527 block_Release( p_block );
528 image_HandlerDelete( p_image );
529 vlc_cond_signal( &p_dest->object_wait );
530 vlc_object_release( p_dest );
534 i_size = p_block->i_buffer;
536 p_snapshot->i_width = fmt_out.i_width;
537 p_snapshot->i_height = fmt_out.i_height;
538 p_snapshot->i_datasize = i_size;
539 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
540 p_snapshot->p_data = ( char* ) malloc( i_size );
541 if( !p_snapshot->p_data )
543 block_Release( p_block );
545 image_HandlerDelete( p_image );
546 vlc_cond_signal( &p_dest->object_wait );
547 vlc_object_release( p_dest );
550 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
552 p_dest->p_private = p_snapshot;
554 block_Release( p_block );
556 /* Unlock the object */
557 vlc_cond_signal( &p_dest->object_wait );
558 vlc_object_release( p_dest );
560 image_HandlerDelete( p_image );
564 #if defined(__APPLE__) || defined(SYS_BEOS)
565 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
567 if( asprintf( &val.psz_string, "%s/Desktop",
568 p_vout->p_libvlc->psz_homedir ) == -1 )
569 val.psz_string = NULL;
572 #elif defined(WIN32) && !defined(UNDER_CE)
573 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
575 /* Get the My Pictures folder path */
577 char *p_mypicturesdir = NULL;
578 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
580 #ifndef CSIDL_FLAG_CREATE
581 # define CSIDL_FLAG_CREATE 0x8000
583 #ifndef CSIDL_MYPICTURES
584 # define CSIDL_MYPICTURES 0x27
586 #ifndef SHGFP_TYPE_CURRENT
587 # define SHGFP_TYPE_CURRENT 0
590 HINSTANCE shfolder_dll;
591 SHGETFOLDERPATH SHGetFolderPath ;
593 /* load the shfolder dll to retrieve SHGetFolderPath */
594 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
596 wchar_t wdir[PATH_MAX];
597 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
598 _T("SHGetFolderPathW") );
599 if ((SHGetFolderPath != NULL )
600 && SUCCEEDED (SHGetFolderPath (NULL,
601 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
602 NULL, SHGFP_TYPE_CURRENT,
604 p_mypicturesdir = FromWide (wdir);
606 FreeLibrary( shfolder_dll );
609 if( p_mypicturesdir == NULL )
611 if( asprintf( &val.psz_string, "%s",
612 p_vout->p_libvlc->psz_homedir ) == -1 )
613 val.psz_string = NULL;
617 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
618 val.psz_string = NULL;
619 free( p_mypicturesdir );
624 /* XXX: This saves in the data directory. Shouldn't we try saving
625 * to psz_homedir/Desktop or something nicer ? */
626 if( !val.psz_string && p_vout->p_libvlc->psz_datadir )
628 if( asprintf( &val.psz_string, "%s",
629 p_vout->p_libvlc->psz_datadir ) == -1 )
630 val.psz_string = NULL;
634 if( !val.psz_string )
636 msg_Err( p_vout, "no path specified for snapshots" );
639 var_Get( p_vout, "snapshot-format", &format );
640 if( !format.psz_string || !*format.psz_string )
642 if( format.psz_string ) free( format.psz_string );
643 format.psz_string = strdup( "png" );
647 * Did the user specify a directory? If not, path = NULL.
649 path = utf8_opendir ( (const char *)val.psz_string );
652 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
653 if( psz_prefix == NULL )
654 psz_prefix = strdup( "vlcsnap-" );
657 char *psz_tmp = str_format( p_vout, psz_prefix );
658 filename_sanitize( psz_tmp );
660 psz_prefix = psz_tmp;
664 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
666 int i_num = var_GetInteger( p_vout, "snapshot-num" );
670 asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s", val.psz_string,
671 psz_prefix, i_num++, format.psz_string );
673 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
674 var_SetInteger( p_vout, "snapshot-num", i_num );
678 asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s", val.psz_string,
680 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
686 else // The user specified a full path name (including file name)
688 psz_filename = str_format( p_vout, val.psz_string );
689 path_sanitize( psz_filename );
692 free( val.psz_string );
693 free( format.psz_string );
695 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
696 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
698 if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
700 float f = (float)p_vout->fmt_in.i_height / fmt_out.i_height;
701 fmt_out.i_width = p_vout->fmt_in.i_width / f;
703 else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
705 float f = (float)p_vout->fmt_in.i_width / fmt_out.i_width;
706 fmt_out.i_height = p_vout->fmt_in.i_height / f;
709 /* Save the snapshot */
710 fmt_in = p_vout->fmt_in;
711 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
712 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
713 if( i_ret != VLC_SUCCESS )
715 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
716 free( psz_filename );
717 image_HandlerDelete( p_image );
721 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
722 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
723 "%s", psz_filename );
724 free( psz_filename );
726 if( var_GetBool( p_vout, "snapshot-preview" ) )
728 /* Inject a subpicture with the snapshot */
729 memset( &fmt_out, 0, sizeof(fmt_out) );
730 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
731 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
732 image_HandlerDelete( p_image );
733 if( !p_pif ) return VLC_EGENERIC;
735 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
736 if( p_subpic == NULL )
738 p_pif->pf_release( p_pif );
742 p_subpic->i_channel = 0;
743 p_subpic->i_start = mdate();
744 p_subpic->i_stop = mdate() + 4000000;
745 p_subpic->b_ephemer = VLC_TRUE;
746 p_subpic->b_fade = VLC_TRUE;
747 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
748 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
750 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
751 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
753 p_pif->pf_release( p_pif );
755 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
759 image_HandlerDelete( p_image );
765 /*****************************************************************************
767 *****************************************************************************/
769 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
770 vlc_bool_t b_add, vlc_bool_t b_setconfig )
773 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
775 /* Todo : Use some generic chain manipulation functions */
776 if( !psz_string ) psz_string = strdup("");
778 psz_parser = strstr( psz_string, psz_name );
783 psz_parser = psz_string;
784 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
785 psz_string, psz_name );
795 memmove( psz_parser, psz_parser + strlen(psz_name) +
796 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
797 strlen(psz_parser + strlen(psz_name)) + 1 );
799 /* Remove trailing : : */
800 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
802 *(psz_string+strlen(psz_string ) -1 ) = '\0';
812 config_PutPsz( p_vout, "vout-filter", psz_string );
814 var_SetString( p_vout, "vout-filter", psz_string );
818 /*****************************************************************************
819 * vout_ControlDefault: default methods for video output control.
820 *****************************************************************************/
821 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
828 if( p_vout->p_parent_intf )
830 vlc_object_release( p_vout->p_parent_intf );
831 p_vout->p_parent_intf = NULL;
837 p_vout->b_snapshot = VLC_TRUE;
842 msg_Dbg( p_vout, "control query not supported" );
847 /*****************************************************************************
848 * InitWindowSize: find the initial dimensions the video window should have.
849 *****************************************************************************
850 * This function will check the "width", "height" and "zoom" config options and
851 * will calculate the size that the video window should have.
852 *****************************************************************************/
853 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
854 unsigned *pi_height )
857 int i_width, i_height;
860 #define FP_FACTOR 1000 /* our fixed point factor */
862 var_Get( p_vout, "width", &val );
864 var_Get( p_vout, "height", &val );
865 i_height = val.i_int;
866 var_Get( p_vout, "zoom", &val );
867 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
869 if( i_width > 0 && i_height > 0)
871 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
872 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
875 else if( i_width > 0 )
877 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
878 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
879 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
880 FP_FACTOR / p_vout->fmt_in.i_visible_width );
883 else if( i_height > 0 )
885 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
886 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
887 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
888 FP_FACTOR / p_vout->fmt_in.i_visible_height );
892 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
893 msg_Warn( p_vout, "fucked up aspect" );
894 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
895 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
897 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
899 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
900 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
901 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
906 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
908 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
909 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
913 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
914 p_vout->i_window_height );
919 /*****************************************************************************
920 * Object variables callbacks
921 *****************************************************************************/
922 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
923 vlc_value_t oldval, vlc_value_t newval, void *p_data )
925 vout_thread_t *p_vout = (vout_thread_t *)p_this;
926 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
927 InitWindowSize( p_vout, &p_vout->i_window_width,
928 &p_vout->i_window_height );
929 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
930 p_vout->i_window_height );
934 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
935 vlc_value_t oldval, vlc_value_t newval, void *p_data )
937 vout_thread_t *p_vout = (vout_thread_t *)p_this;
938 int64_t i_aspect_num, i_aspect_den;
939 unsigned int i_width, i_height;
941 (void)oldval; (void)p_data;
943 /* Restore defaults */
944 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
945 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
946 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
947 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
949 if( !strcmp( psz_cmd, "crop" ) )
951 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
954 /* We're using the 3:4 syntax */
955 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
956 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
958 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
959 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
961 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
962 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
963 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
964 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
966 if( i_width < p_vout->fmt_render.i_visible_width )
968 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
969 (p_vout->fmt_render.i_visible_width - i_width) / 2;
970 p_vout->fmt_in.i_visible_width = i_width;
974 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
975 (p_vout->fmt_render.i_visible_height - i_height) / 2;
976 p_vout->fmt_in.i_visible_height = i_height;
981 psz_parser = strchr( newval.psz_string, 'x' );
984 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
985 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
987 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
988 if( psz_end != psz_parser ) goto crop_end;
990 psz_parser = strchr( ++psz_end, '+' );
991 i_crop_height = strtol( psz_end, &psz_end, 10 );
992 if( psz_end != psz_parser ) goto crop_end;
994 psz_parser = strchr( ++psz_end, '+' );
995 i_crop_left = strtol( psz_end, &psz_end, 10 );
996 if( psz_end != psz_parser ) goto crop_end;
999 i_crop_top = strtol( psz_end, &psz_end, 10 );
1000 if( *psz_end != '\0' ) goto crop_end;
1002 i_width = i_crop_width;
1003 p_vout->fmt_in.i_visible_width = i_width;
1005 i_height = i_crop_height;
1006 p_vout->fmt_in.i_visible_height = i_height;
1008 p_vout->fmt_in.i_x_offset = i_crop_left;
1009 p_vout->fmt_in.i_y_offset = i_crop_top;
1013 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1014 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1016 psz_parser = strchr( newval.psz_string, '+' );
1017 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1018 if( psz_end != psz_parser ) goto crop_end;
1020 psz_parser = strchr( ++psz_end, '+' );
1021 i_crop_top = strtol( psz_end, &psz_end, 10 );
1022 if( psz_end != psz_parser ) goto crop_end;
1024 psz_parser = strchr( ++psz_end, '+' );
1025 i_crop_right = strtol( psz_end, &psz_end, 10 );
1026 if( psz_end != psz_parser ) goto crop_end;
1029 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1030 if( *psz_end != '\0' ) goto crop_end;
1032 i_width = p_vout->fmt_render.i_visible_width
1033 - i_crop_left - i_crop_right;
1034 p_vout->fmt_in.i_visible_width = i_width;
1036 i_height = p_vout->fmt_render.i_visible_height
1037 - i_crop_top - i_crop_bottom;
1038 p_vout->fmt_in.i_visible_height = i_height;
1040 p_vout->fmt_in.i_x_offset = i_crop_left;
1041 p_vout->fmt_in.i_y_offset = i_crop_top;
1045 else if( !strcmp( psz_cmd, "crop-top" )
1046 || !strcmp( psz_cmd, "crop-left" )
1047 || !strcmp( psz_cmd, "crop-bottom" )
1048 || !strcmp( psz_cmd, "crop-right" ) )
1050 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1052 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1053 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1054 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1055 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1057 i_width = p_vout->fmt_render.i_visible_width
1058 - i_crop_left - i_crop_right;
1059 p_vout->fmt_in.i_visible_width = i_width;
1061 i_height = p_vout->fmt_render.i_visible_height
1062 - i_crop_top - i_crop_bottom;
1063 p_vout->fmt_in.i_visible_height = i_height;
1065 p_vout->fmt_in.i_x_offset = i_crop_left;
1066 p_vout->fmt_in.i_y_offset = i_crop_top;
1070 InitWindowSize( p_vout, &p_vout->i_window_width,
1071 &p_vout->i_window_height );
1073 p_vout->i_changes |= VOUT_CROP_CHANGE;
1075 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1076 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1077 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1078 p_vout->fmt_in.i_visible_width,
1079 p_vout->fmt_in.i_visible_height );
1084 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1085 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1087 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1088 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1091 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1092 (void)psz_cmd; (void)oldval; (void)p_data;
1094 /* Restore defaults */
1095 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1096 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1097 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1098 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1100 if( !psz_parser ) goto aspect_end;
1102 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1103 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1105 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1106 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1108 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1109 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1110 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1111 p_vout->fmt_in.i_sar_num = i_sar_num;
1112 p_vout->fmt_in.i_sar_den = i_sar_den;
1113 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1114 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1117 if( p_vout->i_par_num && p_vout->i_par_den )
1119 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1120 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1121 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1122 p_vout->i_par_den / p_vout->i_par_num;
1123 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1126 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1128 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1129 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1130 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1131 i_aspect_num, i_aspect_den,
1132 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1134 var_Get( p_vout, "crop", &val );
1135 return CropCallback( p_this, "crop", val, val, 0 );
1138 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1139 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1141 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1142 playlist_t *p_playlist = pl_Yield( p_this );
1143 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1144 (void)psz_cmd; (void)oldval; (void)p_data;
1146 /* Modify playlist as well because the vout might have to be restarted */
1147 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1148 var_Set( p_playlist, "video-on-top", newval );
1150 pl_Release( p_this );
1154 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1155 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1157 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1159 playlist_t *p_playlist = pl_Yield( p_this );
1160 (void)psz_cmd; (void)oldval; (void)p_data;
1162 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1164 /* Modify playlist as well because the vout might have to be restarted */
1165 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1166 var_Set( p_playlist, "fullscreen", newval );
1167 pl_Release( p_playlist );
1169 val.b_bool = VLC_TRUE;
1170 var_Set( p_vout, "intf-change", val );
1174 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1175 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1177 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1178 vout_Control( p_vout, VOUT_SNAPSHOT );
1179 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
1183 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
1184 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1186 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1188 if( !strncmp( psz_cmd, "video-title-show", 16 ) )
1189 p_vout->b_title_show = newval.b_bool;
1190 else if( !strncmp( psz_cmd, "video-title-timeout", 19 ) )
1191 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1192 else if( !strncmp( psz_cmd, "video-title-position", 20 ) )
1193 p_vout->i_title_position = newval.i_int;