1 /*****************************************************************************
2 * vout_intf.c : video output interface
3 *****************************************************************************
4 * Copyright (C) 2000-2006 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() */
36 #include <vlc_block.h>
38 #include "vlc_video.h"
39 #include "video_output.h"
40 #include "vlc_image.h"
45 /*****************************************************************************
47 *****************************************************************************/
48 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
50 /* Object variables callbacks */
51 static int ZoomCallback( vlc_object_t *, char const *,
52 vlc_value_t, vlc_value_t, void * );
53 static int CropCallback( vlc_object_t *, char const *,
54 vlc_value_t, vlc_value_t, void * );
55 static int AspectCallback( vlc_object_t *, char const *,
56 vlc_value_t, vlc_value_t, void * );
57 static int OnTopCallback( vlc_object_t *, char const *,
58 vlc_value_t, vlc_value_t, void * );
59 static int FullscreenCallback( vlc_object_t *, char const *,
60 vlc_value_t, vlc_value_t, void * );
61 static int SnapshotCallback( vlc_object_t *, char const *,
62 vlc_value_t, vlc_value_t, void * );
64 /*****************************************************************************
65 * vout_RequestWindow: Create/Get a video window if possible.
66 *****************************************************************************
67 * This function looks for the main interface and tries to request
68 * a new video window. If it fails then the vout will still need to create the
70 *****************************************************************************/
71 void *vout_RequestWindow( vout_thread_t *p_vout,
72 int *pi_x_hint, int *pi_y_hint,
73 unsigned int *pi_width_hint,
74 unsigned int *pi_height_hint )
76 intf_thread_t *p_intf = NULL;
83 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
85 /* Get requested coordinates */
86 var_Get( p_vout, "video-x", &val );
87 *pi_x_hint = val.i_int ;
88 var_Get( p_vout, "video-y", &val );
89 *pi_y_hint = val.i_int;
91 *pi_width_hint = p_vout->i_window_width;
92 *pi_height_hint = p_vout->i_window_height;
94 /* Check whether someone provided us with a window ID */
95 var_Get( p_vout->p_libvlc, "drawable", &val );
96 if( val.i_int ) return (void *)val.i_int;
98 /* Find if the main interface supports embedding */
99 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
100 if( !p_list ) return NULL;
102 for( i = 0; i < p_list->i_count; i++ )
104 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
105 if( p_intf->b_block && p_intf->pf_request_window ) break;
111 vlc_list_release( p_list );
115 vlc_object_yield( p_intf );
116 vlc_list_release( p_list );
118 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
119 pi_width_hint, pi_height_hint );
121 if( !p_window ) vlc_object_release( p_intf );
122 else p_vout->p_parent_intf = p_intf;
127 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
129 intf_thread_t *p_intf = p_vout->p_parent_intf;
131 if( !p_intf ) return;
133 vlc_mutex_lock( &p_intf->object_lock );
136 vlc_mutex_unlock( &p_intf->object_lock );
140 if( !p_intf->pf_release_window )
142 msg_Err( p_vout, "no pf_release_window");
143 vlc_mutex_unlock( &p_intf->object_lock );
144 vlc_object_release( p_intf );
148 p_intf->pf_release_window( p_intf, p_window );
150 p_vout->p_parent_intf = NULL;
151 vlc_mutex_unlock( &p_intf->object_lock );
152 vlc_object_release( p_intf );
155 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
156 int i_query, va_list args )
158 intf_thread_t *p_intf = p_vout->p_parent_intf;
161 if( !p_intf ) return VLC_EGENERIC;
163 vlc_mutex_lock( &p_intf->object_lock );
166 vlc_mutex_unlock( &p_intf->object_lock );
170 if( !p_intf->pf_control_window )
172 msg_Err( p_vout, "no pf_control_window");
173 vlc_mutex_unlock( &p_intf->object_lock );
177 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
178 vlc_mutex_unlock( &p_intf->object_lock );
182 /*****************************************************************************
183 * vout_IntfInit: called during the vout creation to initialise misc things.
184 *****************************************************************************/
185 void vout_IntfInit( vout_thread_t *p_vout )
187 vlc_value_t val, text, old_val;
188 vlc_bool_t b_force_par = VLC_FALSE;
191 /* Create a few object variables we'll need later on */
192 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
193 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
194 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
195 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
196 var_Create( p_vout, "snapshot-sequential",
197 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
198 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
199 var_SetInteger( p_vout, "snapshot-num", 1 );
201 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
202 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
203 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
204 var_Get( p_vout, "align", &val );
205 p_vout->i_alignment = val.i_int;
207 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
208 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
210 /* Zoom object var */
211 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
212 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
214 text.psz_string = _("Zoom");
215 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
217 var_Get( p_vout, "zoom", &old_val );
218 if( old_val.f_float == 0.25 ||
219 old_val.f_float == 0.5 ||
220 old_val.f_float == 1 ||
221 old_val.f_float == 2 )
223 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
226 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
227 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
228 val.f_float = 0.5; text.psz_string = _("1:2 Half");
229 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
230 val.f_float = 1; text.psz_string = _("1:1 Original");
231 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
232 val.f_float = 2; text.psz_string = _("2:1 Double");
233 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
235 var_Set( p_vout, "zoom", old_val );
237 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
239 /* Crop offset vars */
240 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
241 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
242 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
243 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
245 var_SetInteger( p_vout, "crop-left", 0 );
246 var_SetInteger( p_vout, "crop-top", 0 );
247 var_SetInteger( p_vout, "crop-right", 0 );
248 var_SetInteger( p_vout, "crop-bottom", 0 );
250 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
251 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
252 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
253 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
255 /* Crop object var */
256 var_Create( p_vout, "crop", VLC_VAR_STRING |
257 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
259 text.psz_string = _("Crop");
260 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
263 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
264 val.psz_string = ""; text.psz_string = _("Default");
265 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
266 val.psz_string = "1:1"; text.psz_string = "1:1";
267 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
268 val.psz_string = "4:3"; text.psz_string = "4:3";
269 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
270 val.psz_string = "16:9"; text.psz_string = "16:9";
271 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
272 val.psz_string = "16:10"; text.psz_string = "16:10";
273 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
274 val.psz_string = "221:100"; text.psz_string = "221:100";
275 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
276 val.psz_string = "5:4"; text.psz_string = "5:4";
277 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
279 /* Add custom crop ratios */
280 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
281 if( psz_buf && *psz_buf )
283 char *psz_cur = psz_buf;
285 while( psz_cur && *psz_cur )
287 psz_next = strchr( psz_cur, ',' );
293 val.psz_string = strdup( psz_cur );
294 text.psz_string = strdup( psz_cur );
295 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text);
296 free( val.psz_string );
297 free( text.psz_string );
301 if( psz_buf ) free( psz_buf );
303 var_AddCallback( p_vout, "crop", CropCallback, NULL );
304 var_Get( p_vout, "crop", &old_val );
305 if( old_val.psz_string && *old_val.psz_string )
306 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
307 if( old_val.psz_string ) free( old_val.psz_string );
309 /* Monitor pixel aspect-ratio */
310 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
311 var_Get( p_vout, "monitor-par", &val );
312 if( val.psz_string && *val.psz_string )
314 char *psz_parser = strchr( val.psz_string, ':' );
315 unsigned int i_aspect_num = 0, i_aspect_den = 0;
319 i_aspect_num = strtol( val.psz_string, 0, 10 );
320 i_aspect_den = strtol( ++psz_parser, 0, 10 );
324 i_aspect = atof( val.psz_string );
325 vlc_ureduce( &i_aspect_num, &i_aspect_den,
326 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
328 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
330 p_vout->i_par_num = i_aspect_num;
331 p_vout->i_par_den = i_aspect_den;
333 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
334 p_vout->i_par_num, p_vout->i_par_den, 0 );
336 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
337 p_vout->i_par_num, p_vout->i_par_den );
338 b_force_par = VLC_TRUE;
340 if( val.psz_string ) free( val.psz_string );
342 /* Aspect-ratio object var */
343 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
344 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
346 text.psz_string = _("Aspect-ratio");
347 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
350 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
351 val.psz_string = ""; text.psz_string = _("Default");
352 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
353 val.psz_string = "1:1"; text.psz_string = "1:1";
354 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
355 val.psz_string = "4:3"; text.psz_string = "4:3";
356 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
357 val.psz_string = "16:9"; text.psz_string = "16:9";
358 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
359 val.psz_string = "16:10"; text.psz_string = "16:10";
360 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
361 val.psz_string = "221:100"; text.psz_string = "221:100";
362 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
363 val.psz_string = "5:4"; text.psz_string = "5:4";
364 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
366 /* Add custom aspect ratios */
367 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
368 if( psz_buf && *psz_buf )
370 char *psz_cur = psz_buf;
372 while( psz_cur && *psz_cur )
374 psz_next = strchr( psz_cur, ',' );
380 val.psz_string = strdup( psz_cur );
381 text.psz_string = strdup( psz_cur );
382 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text);
383 free( val.psz_string );
384 free( text.psz_string );
388 if( psz_buf ) free( psz_buf );
390 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
391 var_Get( p_vout, "aspect-ratio", &old_val );
392 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
393 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
394 if( old_val.psz_string ) free( old_val.psz_string );
396 /* Initialize the dimensions of the video window */
397 InitWindowSize( p_vout, &p_vout->i_window_width,
398 &p_vout->i_window_height );
400 /* Add a variable to indicate if the window should be on top of others */
401 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
402 text.psz_string = _("Always on top");
403 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
404 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
406 /* Add a variable to indicate whether we want window decoration or not */
407 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
409 /* Add a fullscreen variable */
410 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
411 text.psz_string = _("Fullscreen");
412 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
413 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
416 /* user requested fullscreen */
417 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
419 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
421 /* Add a snapshot variable */
422 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
423 text.psz_string = _("Snapshot");
424 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
425 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
427 /* Mouse coordinates */
428 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
429 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
430 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
431 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
432 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
434 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
435 val.b_bool = VLC_TRUE;
436 var_Set( p_vout, "intf-change", val );
439 /*****************************************************************************
440 * vout_Snapshot: generates a snapshot.
441 *****************************************************************************/
442 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
444 image_handler_t *p_image = image_HandlerCreate( p_vout );
445 video_format_t fmt_in = {0}, fmt_out = {0};
446 char *psz_filename = NULL;
447 subpicture_t *p_subpic;
449 vlc_value_t val, format;
454 var_Get( p_vout, "snapshot-path", &val );
455 if( val.psz_string && !*val.psz_string )
457 free( val.psz_string );
461 /* Embedded snapshot : if snapshot-path == object:object-id, then
462 create a snapshot_t* and store it in
463 object(object-id)->p_private, then unlock and signal the
466 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
469 vlc_object_t* p_dest;
471 snapshot_t *p_snapshot;
474 /* Destination object-id is following object: */
475 i_id = atoi( &val.psz_string[7] );
476 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
479 msg_Err( p_vout, "Cannot find calling object" );
480 image_HandlerDelete( p_image );
483 /* Object must be locked. We will unlock it once we get the
484 snapshot and written it to p_private */
485 p_dest->p_private = NULL;
487 /* Save the snapshot to a memory zone */
488 fmt_in = p_vout->fmt_in;
489 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
490 /* FIXME: should not be hardcoded. We should be able to
491 specify the snapshot size (snapshot-width and snapshot-height). */
492 fmt_out.i_width = 320;
493 fmt_out.i_height = 200;
494 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
495 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
498 msg_Err( p_vout, "Could not get snapshot" );
499 image_HandlerDelete( p_image );
500 vlc_cond_signal( &p_dest->object_wait );
501 vlc_mutex_unlock( &p_dest->object_lock );
502 vlc_object_release( p_dest );
506 /* Copy the p_block data to a snapshot structure */
507 /* FIXME: get the timestamp */
508 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
511 block_Release( p_block );
512 image_HandlerDelete( p_image );
513 vlc_cond_signal( &p_dest->object_wait );
514 vlc_mutex_unlock( &p_dest->object_lock );
515 vlc_object_release( p_dest );
519 i_size = p_block->i_buffer;
521 p_snapshot->i_width = fmt_out.i_width;
522 p_snapshot->i_height = fmt_out.i_height;
523 p_snapshot->i_datasize = i_size;
524 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
525 p_snapshot->p_data = ( char* ) malloc( i_size );
526 if( !p_snapshot->p_data )
528 block_Release( p_block );
530 image_HandlerDelete( p_image );
531 vlc_cond_signal( &p_dest->object_wait );
532 vlc_mutex_unlock( &p_dest->object_lock );
533 vlc_object_release( p_dest );
536 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
538 p_dest->p_private = p_snapshot;
540 block_Release( p_block );
542 /* Unlock the object */
543 vlc_cond_signal( &p_dest->object_wait );
544 vlc_mutex_unlock( &p_dest->object_lock );
545 vlc_object_release( p_dest );
547 image_HandlerDelete( p_image );
552 #if defined(__APPLE__) || defined(SYS_BEOS)
553 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
555 asprintf( &val.psz_string, "%s/Desktop",
556 p_vout->p_libvlc->psz_homedir );
559 #elif defined(WIN32) && !defined(UNDER_CE)
560 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
562 /* Get the My Pictures folder path */
564 char *p_mypicturesdir = NULL;
565 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
567 #ifndef CSIDL_FLAG_CREATE
568 # define CSIDL_FLAG_CREATE 0x8000
570 #ifndef CSIDL_MYPICTURES
571 # define CSIDL_MYPICTURES 0x27
573 #ifndef SHGFP_TYPE_CURRENT
574 # define SHGFP_TYPE_CURRENT 0
577 HINSTANCE shfolder_dll;
578 SHGETFOLDERPATH SHGetFolderPath ;
580 /* load the shfolder dll to retrieve SHGetFolderPath */
581 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
583 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
584 _T("SHGetFolderPathA") );
585 if( SHGetFolderPath != NULL )
587 p_mypicturesdir = (char *)malloc( MAX_PATH );
588 if( p_mypicturesdir )
591 if( S_OK != SHGetFolderPath( NULL,
592 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
593 NULL, SHGFP_TYPE_CURRENT,
596 free( p_mypicturesdir );
597 p_mypicturesdir = NULL;
601 FreeLibrary( shfolder_dll );
604 if( p_mypicturesdir == NULL )
606 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
607 p_vout->p_libvlc->psz_homedir );
611 asprintf( &val.psz_string, p_mypicturesdir );
612 free( p_mypicturesdir );
617 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
619 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
620 p_vout->p_libvlc->psz_homedir );
624 if( !val.psz_string )
626 msg_Err( p_vout, "no path specified for snapshots" );
629 var_Get( p_vout, "snapshot-format", &format );
630 if( !format.psz_string || !*format.psz_string )
632 if( format.psz_string ) free( format.psz_string );
633 format.psz_string = strdup( "png" );
637 * Did the user specify a directory? If not, path = NULL.
639 path = opendir ( (const char *)val.psz_string );
643 char *psz_prefix = var_GetString( p_vout, "snapshot-prefix" );
644 if( !psz_prefix ) psz_prefix = strdup( "vlcsnap-" );
647 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
649 int i_num = var_GetInteger( p_vout, "snapshot-num" );
653 asprintf( &psz_filename, "%s/%s%05d.%s", val.psz_string,
654 psz_prefix, i_num++, format.psz_string );
656 while( ( p_file = fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
657 var_SetInteger( p_vout, "snapshot-num", i_num );
661 asprintf( &psz_filename, "%s/%s%u.%s", val.psz_string,
663 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
669 else // The user specified a full path name (including file name)
671 asprintf ( &psz_filename, "%s", val.psz_string );
674 free( val.psz_string );
675 free( format.psz_string );
677 /* Save the snapshot */
678 fmt_in = p_vout->fmt_in;
679 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
680 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
681 if( i_ret != VLC_SUCCESS )
683 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
684 free( psz_filename );
685 image_HandlerDelete( p_image );
689 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
690 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
691 "%s", psz_filename );
692 free( psz_filename );
694 if( var_GetBool( p_vout, "snapshot-preview" ) )
696 /* Inject a subpicture with the snapshot */
697 memset( &fmt_out, 0, sizeof(fmt_out) );
698 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
699 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
700 image_HandlerDelete( p_image );
701 if( !p_pif ) return VLC_EGENERIC;
703 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
704 if( p_subpic == NULL )
706 p_pif->pf_release( p_pif );
710 p_subpic->i_channel = 0;
711 p_subpic->i_start = mdate();
712 p_subpic->i_stop = mdate() + 4000000;
713 p_subpic->b_ephemer = VLC_TRUE;
714 p_subpic->b_fade = VLC_TRUE;
715 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
716 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
718 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
719 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
721 p_pif->pf_release( p_pif );
723 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
727 image_HandlerDelete( p_image );
733 /*****************************************************************************
735 *****************************************************************************/
737 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
738 vlc_bool_t b_add, vlc_bool_t b_setconfig )
741 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
743 /* Todo : Use some generic chain manipulation functions */
744 if( !psz_string ) psz_string = strdup("");
746 psz_parser = strstr( psz_string, psz_name );
751 psz_parser = psz_string;
752 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
753 psz_string, psz_name );
763 memmove( psz_parser, psz_parser + strlen(psz_name) +
764 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
765 strlen(psz_parser + strlen(psz_name)) + 1 );
767 /* Remove trailing : : */
768 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
770 *(psz_string+strlen(psz_string ) -1 ) = '\0';
780 config_PutPsz( p_vout, "vout-filter", psz_string );
782 var_SetString( p_vout, "vout-filter", psz_string );
786 /*****************************************************************************
787 * vout_ControlDefault: default methods for video output control.
788 *****************************************************************************/
789 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
795 if( p_vout->p_parent_intf )
797 vlc_object_release( p_vout->p_parent_intf );
798 p_vout->p_parent_intf = NULL;
804 p_vout->b_snapshot = VLC_TRUE;
809 msg_Dbg( p_vout, "control query not supported" );
814 /*****************************************************************************
815 * InitWindowSize: find the initial dimensions the video window should have.
816 *****************************************************************************
817 * This function will check the "width", "height" and "zoom" config options and
818 * will calculate the size that the video window should have.
819 *****************************************************************************/
820 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
821 unsigned *pi_height )
824 int i_width, i_height;
827 #define FP_FACTOR 1000 /* our fixed point factor */
829 var_Get( p_vout, "width", &val );
831 var_Get( p_vout, "height", &val );
832 i_height = val.i_int;
833 var_Get( p_vout, "zoom", &val );
834 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
836 if( i_width > 0 && i_height > 0)
838 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
839 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
842 else if( i_width > 0 )
844 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
845 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
846 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
847 FP_FACTOR / p_vout->fmt_in.i_visible_width );
850 else if( i_height > 0 )
852 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
853 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
854 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
855 FP_FACTOR / p_vout->fmt_in.i_visible_height );
859 if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
861 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
862 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
863 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
868 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
870 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
871 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
875 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
876 p_vout->i_window_height );
881 /*****************************************************************************
882 * Object variables callbacks
883 *****************************************************************************/
884 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
885 vlc_value_t oldval, vlc_value_t newval, void *p_data )
887 vout_thread_t *p_vout = (vout_thread_t *)p_this;
888 InitWindowSize( p_vout, &p_vout->i_window_width,
889 &p_vout->i_window_height );
890 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
891 p_vout->i_window_height );
895 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
896 vlc_value_t oldval, vlc_value_t newval, void *p_data )
898 vout_thread_t *p_vout = (vout_thread_t *)p_this;
899 int64_t i_aspect_num, i_aspect_den;
900 unsigned int i_width, i_height;
902 /* Restore defaults */
903 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
904 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
905 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
906 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
908 if( !strcmp( psz_cmd, "crop" ) )
910 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
913 /* We're using the 3:4 syntax */
914 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
915 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
917 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
918 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
920 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
921 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
922 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
923 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
925 if( i_width < p_vout->fmt_render.i_visible_width )
927 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
928 (p_vout->fmt_render.i_visible_width - i_width) / 2;
929 p_vout->fmt_in.i_visible_width = i_width;
933 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
934 (p_vout->fmt_render.i_visible_height - i_height) / 2;
935 p_vout->fmt_in.i_visible_height = i_height;
940 psz_parser = strchr( newval.psz_string, 'x' );
943 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
944 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
946 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
947 if( psz_end != psz_parser ) goto crop_end;
949 psz_parser = strchr( ++psz_end, '+' );
950 i_crop_height = strtol( psz_end, &psz_end, 10 );
951 if( psz_end != psz_parser ) goto crop_end;
953 psz_parser = strchr( ++psz_end, '+' );
954 i_crop_left = strtol( psz_end, &psz_end, 10 );
955 if( psz_end != psz_parser ) goto crop_end;
958 i_crop_top = strtol( psz_end, &psz_end, 10 );
959 if( *psz_end != '\0' ) goto crop_end;
961 i_width = i_crop_width;
962 p_vout->fmt_in.i_visible_width = i_width;
964 i_height = i_crop_height;
965 p_vout->fmt_in.i_visible_height = i_height;
967 p_vout->fmt_in.i_x_offset = i_crop_left;
968 p_vout->fmt_in.i_y_offset = i_crop_top;
972 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
973 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
975 psz_parser = strchr( newval.psz_string, '+' );
976 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
977 if( psz_end != psz_parser ) goto crop_end;
979 psz_parser = strchr( ++psz_end, '+' );
980 i_crop_top = strtol( psz_end, &psz_end, 10 );
981 if( psz_end != psz_parser ) goto crop_end;
983 psz_parser = strchr( ++psz_end, '+' );
984 i_crop_right = strtol( psz_end, &psz_end, 10 );
985 if( psz_end != psz_parser ) goto crop_end;
988 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
989 if( *psz_end != '\0' ) goto crop_end;
991 i_width = p_vout->fmt_render.i_visible_width
992 - i_crop_left - i_crop_right;
993 p_vout->fmt_in.i_visible_width = i_width;
995 i_height = p_vout->fmt_render.i_visible_height
996 - i_crop_top - i_crop_bottom;
997 p_vout->fmt_in.i_visible_height = i_height;
999 p_vout->fmt_in.i_x_offset = i_crop_left;
1000 p_vout->fmt_in.i_y_offset = i_crop_top;
1004 else if( !strcmp( psz_cmd, "crop-top" )
1005 || !strcmp( psz_cmd, "crop-left" )
1006 || !strcmp( psz_cmd, "crop-bottom" )
1007 || !strcmp( psz_cmd, "crop-right" ) )
1009 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1011 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1012 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1013 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1014 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1016 i_width = p_vout->fmt_render.i_visible_width
1017 - i_crop_left - i_crop_right;
1018 p_vout->fmt_in.i_visible_width = i_width;
1020 i_height = p_vout->fmt_render.i_visible_height
1021 - i_crop_top - i_crop_bottom;
1022 p_vout->fmt_in.i_visible_height = i_height;
1024 p_vout->fmt_in.i_x_offset = i_crop_left;
1025 p_vout->fmt_in.i_y_offset = i_crop_top;
1029 InitWindowSize( p_vout, &p_vout->i_window_width,
1030 &p_vout->i_window_height );
1032 p_vout->i_changes |= VOUT_CROP_CHANGE;
1034 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1035 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1036 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1037 p_vout->fmt_in.i_visible_width,
1038 p_vout->fmt_in.i_visible_height );
1043 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1044 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1046 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1047 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1050 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1052 /* Restore defaults */
1053 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1054 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1055 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1056 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1058 if( !psz_parser ) goto aspect_end;
1060 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1061 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1063 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1064 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1066 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1067 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1068 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1069 p_vout->fmt_in.i_sar_num = i_sar_num;
1070 p_vout->fmt_in.i_sar_den = i_sar_den;
1071 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1072 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1075 if( p_vout->i_par_num && p_vout->i_par_den )
1077 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1078 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1079 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1080 p_vout->i_par_den / p_vout->i_par_num;
1081 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1084 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1086 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1087 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1088 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1089 i_aspect_num, i_aspect_den,
1090 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1092 var_Get( p_vout, "crop", &val );
1093 return CropCallback( p_this, "crop", val, val, 0 );
1098 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1099 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1101 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1102 playlist_t *p_playlist;
1103 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1105 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1109 /* Modify playlist as well because the vout might have to be restarted */
1110 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1111 var_Set( p_playlist, "video-on-top", newval );
1113 vlc_object_release( p_playlist );
1118 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1119 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1121 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1122 playlist_t *p_playlist;
1125 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1127 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1131 /* Modify playlist as well because the vout might have to be restarted */
1132 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1133 var_Set( p_playlist, "fullscreen", newval );
1135 vlc_object_release( p_playlist );
1138 /* Disable "always on top" in fullscreen mode */
1139 var_Get( p_vout, "video-on-top", &val );
1140 if( newval.b_bool && val.b_bool )
1142 val.b_bool = VLC_FALSE;
1143 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
1145 else if( !newval.b_bool && val.b_bool )
1147 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
1150 val.b_bool = VLC_TRUE;
1151 var_Set( p_vout, "intf-change", val );
1155 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1156 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1158 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1159 vout_Control( p_vout, VOUT_SNAPSHOT );