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 *****************************************************************************/
27 #include <stdlib.h> /* free() */
28 #include <sys/types.h> /* opendir() */
29 #include <dirent.h> /* opendir() */
33 #include <vlc_block.h>
35 #include "vlc_video.h"
36 #include "video_output.h"
37 #include "vlc_image.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
47 /* Object variables callbacks */
48 static int ZoomCallback( vlc_object_t *, char const *,
49 vlc_value_t, vlc_value_t, void * );
50 static int CropCallback( vlc_object_t *, char const *,
51 vlc_value_t, vlc_value_t, void * );
52 static int AspectCallback( vlc_object_t *, char const *,
53 vlc_value_t, vlc_value_t, void * );
54 static int OnTopCallback( vlc_object_t *, char const *,
55 vlc_value_t, vlc_value_t, void * );
56 static int FullscreenCallback( vlc_object_t *, char const *,
57 vlc_value_t, vlc_value_t, void * );
58 static int SnapshotCallback( vlc_object_t *, char const *,
59 vlc_value_t, vlc_value_t, void * );
61 /*****************************************************************************
62 * vout_RequestWindow: Create/Get a video window if possible.
63 *****************************************************************************
64 * This function looks for the main interface and tries to request
65 * a new video window. If it fails then the vout will still need to create the
67 *****************************************************************************/
68 void *vout_RequestWindow( vout_thread_t *p_vout,
69 int *pi_x_hint, int *pi_y_hint,
70 unsigned int *pi_width_hint,
71 unsigned int *pi_height_hint )
73 intf_thread_t *p_intf = NULL;
80 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
82 /* Get requested coordinates */
83 var_Get( p_vout, "video-x", &val );
84 *pi_x_hint = val.i_int ;
85 var_Get( p_vout, "video-y", &val );
86 *pi_y_hint = val.i_int;
88 *pi_width_hint = p_vout->i_window_width;
89 *pi_height_hint = p_vout->i_window_height;
91 /* Check whether someone provided us with a window ID */
92 var_Get( p_vout->p_vlc, "drawable", &val );
93 if( val.i_int ) return (void *)val.i_int;
95 /* Find if the main interface supports embedding */
96 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
97 if( !p_list ) return NULL;
99 for( i = 0; i < p_list->i_count; i++ )
101 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
102 if( p_intf->b_block && p_intf->pf_request_window ) break;
108 vlc_list_release( p_list );
112 vlc_object_yield( p_intf );
113 vlc_list_release( p_list );
115 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
116 pi_width_hint, pi_height_hint );
118 if( !p_window ) vlc_object_release( p_intf );
119 else p_vout->p_parent_intf = p_intf;
124 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
126 intf_thread_t *p_intf = p_vout->p_parent_intf;
128 if( !p_intf ) return;
130 vlc_mutex_lock( &p_intf->object_lock );
133 vlc_mutex_unlock( &p_intf->object_lock );
137 if( !p_intf->pf_release_window )
139 msg_Err( p_vout, "no pf_release_window");
140 vlc_mutex_unlock( &p_intf->object_lock );
141 vlc_object_release( p_intf );
145 p_intf->pf_release_window( p_intf, p_window );
147 p_vout->p_parent_intf = NULL;
148 vlc_mutex_unlock( &p_intf->object_lock );
149 vlc_object_release( p_intf );
152 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
153 int i_query, va_list args )
155 intf_thread_t *p_intf = p_vout->p_parent_intf;
158 if( !p_intf ) return VLC_EGENERIC;
160 vlc_mutex_lock( &p_intf->object_lock );
163 vlc_mutex_unlock( &p_intf->object_lock );
167 if( !p_intf->pf_control_window )
169 msg_Err( p_vout, "no pf_control_window");
170 vlc_mutex_unlock( &p_intf->object_lock );
174 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
175 vlc_mutex_unlock( &p_intf->object_lock );
179 /*****************************************************************************
180 * vout_IntfInit: called during the vout creation to initialise misc things.
181 *****************************************************************************/
182 void vout_IntfInit( vout_thread_t *p_vout )
184 vlc_value_t val, text, old_val;
185 vlc_bool_t b_force_par = VLC_FALSE;
188 /* Create a few object variables we'll need later on */
189 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
190 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
191 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
192 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
193 var_Create( p_vout, "snapshot-sequential",
194 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
195 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
196 var_SetInteger( p_vout, "snapshot-num", 1 );
198 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
199 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
200 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
201 var_Get( p_vout, "align", &val );
202 p_vout->i_alignment = val.i_int;
204 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
205 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
207 /* Zoom object var */
208 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
209 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
211 text.psz_string = _("Zoom");
212 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
214 var_Get( p_vout, "zoom", &old_val );
215 if( old_val.f_float == 0.25 ||
216 old_val.f_float == 0.5 ||
217 old_val.f_float == 1 ||
218 old_val.f_float == 2 )
220 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
223 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
224 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
225 val.f_float = 0.5; text.psz_string = _("1:2 Half");
226 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
227 val.f_float = 1; text.psz_string = _("1:1 Original");
228 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
229 val.f_float = 2; text.psz_string = _("2:1 Double");
230 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
232 var_Set( p_vout, "zoom", old_val );
234 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
236 /* Crop offset vars */
237 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
238 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
239 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
240 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
242 var_SetInteger( p_vout, "crop-left", 0 );
243 var_SetInteger( p_vout, "crop-top", 0 );
244 var_SetInteger( p_vout, "crop-right", 0 );
245 var_SetInteger( p_vout, "crop-bottom", 0 );
247 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
248 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
249 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
250 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
252 /* Crop object var */
253 var_Create( p_vout, "crop", VLC_VAR_STRING |
254 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
256 text.psz_string = _("Crop");
257 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
260 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
261 val.psz_string = ""; text.psz_string = _("Default");
262 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
263 val.psz_string = "1:1"; text.psz_string = "1:1";
264 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
265 val.psz_string = "4:3"; text.psz_string = "4:3";
266 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
267 val.psz_string = "16:9"; text.psz_string = "16:9";
268 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
269 val.psz_string = "16:10"; text.psz_string = "16:10";
270 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
271 val.psz_string = "221:100"; text.psz_string = "221:100";
272 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
273 val.psz_string = "5:4"; text.psz_string = "5:4";
274 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
276 /* Add custom crop ratios */
277 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
278 if( psz_buf && *psz_buf )
280 char *psz_cur = psz_buf;
282 while( psz_cur && *psz_cur )
284 psz_next = strchr( psz_cur, ',' );
290 val.psz_string = strdup( psz_cur );
291 text.psz_string = strdup( psz_cur );
292 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text);
293 free( val.psz_string );
294 free( text.psz_string );
298 if( psz_buf ) free( psz_buf );
300 var_AddCallback( p_vout, "crop", CropCallback, NULL );
301 var_Get( p_vout, "crop", &old_val );
302 if( old_val.psz_string && *old_val.psz_string )
303 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
304 if( old_val.psz_string ) free( old_val.psz_string );
306 /* Monitor pixel aspect-ratio */
307 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
308 var_Get( p_vout, "monitor-par", &val );
309 if( val.psz_string && *val.psz_string )
311 char *psz_parser = strchr( val.psz_string, ':' );
312 unsigned int i_aspect_num = 0, i_aspect_den = 0;
316 i_aspect_num = strtol( val.psz_string, 0, 10 );
317 i_aspect_den = strtol( ++psz_parser, 0, 10 );
321 i_aspect = atof( val.psz_string );
322 vlc_ureduce( &i_aspect_num, &i_aspect_den,
323 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
325 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
327 p_vout->i_par_num = i_aspect_num;
328 p_vout->i_par_den = i_aspect_den;
330 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
331 p_vout->i_par_num, p_vout->i_par_den, 0 );
333 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
334 p_vout->i_par_num, p_vout->i_par_den );
335 b_force_par = VLC_TRUE;
337 if( val.psz_string ) free( val.psz_string );
339 /* Aspect-ratio object var */
340 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
341 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
343 text.psz_string = _("Aspect-ratio");
344 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
347 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
348 val.psz_string = ""; text.psz_string = _("Default");
349 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
350 val.psz_string = "1:1"; text.psz_string = "1:1";
351 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
352 val.psz_string = "4:3"; text.psz_string = "4:3";
353 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
354 val.psz_string = "16:9"; text.psz_string = "16:9";
355 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
356 val.psz_string = "16:10"; text.psz_string = "16:10";
357 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
358 val.psz_string = "221:100"; text.psz_string = "221:100";
359 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
360 val.psz_string = "5:4"; text.psz_string = "5:4";
361 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
363 /* Add custom aspect ratios */
364 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
365 if( psz_buf && *psz_buf )
367 char *psz_cur = psz_buf;
369 while( psz_cur && *psz_cur )
371 psz_next = strchr( psz_cur, ',' );
377 val.psz_string = strdup( psz_cur );
378 text.psz_string = strdup( psz_cur );
379 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text);
380 free( val.psz_string );
381 free( text.psz_string );
385 if( psz_buf ) free( psz_buf );
387 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
388 var_Get( p_vout, "aspect-ratio", &old_val );
389 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
390 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
391 if( old_val.psz_string ) free( old_val.psz_string );
393 /* Initialize the dimensions of the video window */
394 InitWindowSize( p_vout, &p_vout->i_window_width,
395 &p_vout->i_window_height );
397 /* Add a variable to indicate if the window should be on top of others */
398 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
399 text.psz_string = _("Always on top");
400 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
401 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
403 /* Add a variable to indicate whether we want window decoration or not */
404 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
406 /* Add a fullscreen variable */
407 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
408 text.psz_string = _("Fullscreen");
409 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
410 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
413 /* user requested fullscreen */
414 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
416 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
418 /* Add a snapshot variable */
419 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
420 text.psz_string = _("Snapshot");
421 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
422 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
424 /* Mouse coordinates */
425 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
426 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
427 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
428 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
429 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
431 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
432 val.b_bool = VLC_TRUE;
433 var_Set( p_vout, "intf-change", val );
436 /*****************************************************************************
437 * vout_Snapshot: generates a snapshot.
438 *****************************************************************************/
439 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
441 image_handler_t *p_image = image_HandlerCreate( p_vout );
442 video_format_t fmt_in = {0}, fmt_out = {0};
443 char *psz_filename = NULL;
444 subpicture_t *p_subpic;
446 vlc_value_t val, format;
451 var_Get( p_vout, "snapshot-path", &val );
452 if( val.psz_string && !*val.psz_string )
454 free( val.psz_string );
458 /* Embedded snapshot : if snapshot-path == object:object-id, then
459 create a snapshot_t* and store it in
460 object(object-id)->p_private, then unlock and signal the
463 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
466 vlc_object_t* p_dest;
468 snapshot_t *p_snapshot;
471 /* Destination object-id is following object: */
472 i_id = atoi( &val.psz_string[7] );
473 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
476 msg_Err( p_vout, "Cannot find calling object" );
477 image_HandlerDelete( p_image );
480 /* Object must be locked. We will unlock it once we get the
481 snapshot and written it to p_private */
482 p_dest->p_private = NULL;
484 /* Save the snapshot to a memory zone */
485 fmt_in = p_vout->fmt_in;
486 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
487 /* FIXME: should not be hardcoded. We should be able to
488 specify the snapshot size (snapshot-width and snapshot-height). */
489 fmt_out.i_width = 320;
490 fmt_out.i_height = 200;
491 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
492 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
495 msg_Err( p_vout, "Could not get snapshot" );
496 image_HandlerDelete( p_image );
497 vlc_cond_signal( &p_dest->object_wait );
498 vlc_mutex_unlock( &p_dest->object_lock );
499 vlc_object_release( p_dest );
503 /* Copy the p_block data to a snapshot structure */
504 /* FIXME: get the timestamp */
505 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
508 block_Release( p_block );
509 image_HandlerDelete( p_image );
510 vlc_cond_signal( &p_dest->object_wait );
511 vlc_mutex_unlock( &p_dest->object_lock );
512 vlc_object_release( p_dest );
516 i_size = p_block->i_buffer;
518 p_snapshot->i_width = fmt_out.i_width;
519 p_snapshot->i_height = fmt_out.i_height;
520 p_snapshot->i_datasize = i_size;
521 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
522 p_snapshot->p_data = ( char* ) malloc( i_size );
523 if( !p_snapshot->p_data )
525 block_Release( p_block );
527 image_HandlerDelete( p_image );
528 vlc_cond_signal( &p_dest->object_wait );
529 vlc_mutex_unlock( &p_dest->object_lock );
530 vlc_object_release( p_dest );
533 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
535 p_dest->p_private = p_snapshot;
537 block_Release( p_block );
539 /* Unlock the object */
540 vlc_cond_signal( &p_dest->object_wait );
541 vlc_mutex_unlock( &p_dest->object_lock );
542 vlc_object_release( p_dest );
544 image_HandlerDelete( p_image );
549 #if defined(__APPLE__) || defined(SYS_BEOS)
550 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
552 asprintf( &val.psz_string, "%s/Desktop",
553 p_vout->p_vlc->psz_homedir );
556 #elif defined(WIN32) && !defined(UNDER_CE)
557 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
559 /* Get the My Pictures folder path */
561 char *p_mypicturesdir = NULL;
562 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
564 #ifndef CSIDL_FLAG_CREATE
565 # define CSIDL_FLAG_CREATE 0x8000
567 #ifndef CSIDL_MYPICTURES
568 # define CSIDL_MYPICTURES 0x27
570 #ifndef SHGFP_TYPE_CURRENT
571 # define SHGFP_TYPE_CURRENT 0
574 HINSTANCE shfolder_dll;
575 SHGETFOLDERPATH SHGetFolderPath ;
577 /* load the shfolder dll to retrieve SHGetFolderPath */
578 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
580 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
581 _T("SHGetFolderPathA") );
582 if( SHGetFolderPath != NULL )
584 p_mypicturesdir = (char *)malloc( MAX_PATH );
585 if( p_mypicturesdir )
588 if( S_OK != SHGetFolderPath( NULL,
589 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
590 NULL, SHGFP_TYPE_CURRENT,
593 free( p_mypicturesdir );
594 p_mypicturesdir = NULL;
598 FreeLibrary( shfolder_dll );
601 if( p_mypicturesdir == NULL )
603 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
604 p_vout->p_vlc->psz_homedir );
608 asprintf( &val.psz_string, p_mypicturesdir );
609 free( p_mypicturesdir );
614 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
616 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
617 p_vout->p_vlc->psz_homedir );
621 if( !val.psz_string )
623 msg_Err( p_vout, "no path specified for snapshots" );
626 var_Get( p_vout, "snapshot-format", &format );
627 if( !format.psz_string || !*format.psz_string )
629 if( format.psz_string ) free( format.psz_string );
630 format.psz_string = strdup( "png" );
634 * Did the user specify a directory? If not, path = NULL.
636 path = opendir ( (const char *)val.psz_string );
640 char *psz_prefix = var_GetString( p_vout, "snapshot-prefix" );
641 if( !psz_prefix ) psz_prefix = strdup( "vlcsnap-" );
644 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
646 int i_num = var_GetInteger( p_vout, "snapshot-num" );
650 asprintf( &psz_filename, "%s/%s%05d.%s", val.psz_string,
651 psz_prefix, i_num++, format.psz_string );
653 while( ( p_file = fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
654 var_SetInteger( p_vout, "snapshot-num", i_num );
658 asprintf( &psz_filename, "%s/%s%u.%s", val.psz_string,
660 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
666 else // The user specified a full path name (including file name)
668 asprintf ( &psz_filename, "%s", val.psz_string );
671 free( val.psz_string );
672 free( format.psz_string );
674 /* Save the snapshot */
675 fmt_in = p_vout->fmt_in;
676 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
677 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
678 if( i_ret != VLC_SUCCESS )
680 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
681 free( psz_filename );
682 image_HandlerDelete( p_image );
686 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
687 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
688 "%s", psz_filename );
689 free( psz_filename );
691 if( var_GetBool( p_vout, "snapshot-preview" ) )
693 /* Inject a subpicture with the snapshot */
694 memset( &fmt_out, 0, sizeof(fmt_out) );
695 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
696 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
697 image_HandlerDelete( p_image );
698 if( !p_pif ) return VLC_EGENERIC;
700 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
701 if( p_subpic == NULL )
703 p_pif->pf_release( p_pif );
707 p_subpic->i_channel = 0;
708 p_subpic->i_start = mdate();
709 p_subpic->i_stop = mdate() + 4000000;
710 p_subpic->b_ephemer = VLC_TRUE;
711 p_subpic->b_fade = VLC_TRUE;
712 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
713 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
715 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
716 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
718 p_pif->pf_release( p_pif );
720 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
724 image_HandlerDelete( p_image );
730 /*****************************************************************************
731 * vout_ControlDefault: default methods for video output control.
732 *****************************************************************************/
733 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
739 if( p_vout->p_parent_intf )
741 vlc_object_release( p_vout->p_parent_intf );
742 p_vout->p_parent_intf = NULL;
748 p_vout->b_snapshot = VLC_TRUE;
753 msg_Dbg( p_vout, "control query not supported" );
758 /*****************************************************************************
759 * InitWindowSize: find the initial dimensions the video window should have.
760 *****************************************************************************
761 * This function will check the "width", "height" and "zoom" config options and
762 * will calculate the size that the video window should have.
763 *****************************************************************************/
764 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
765 unsigned *pi_height )
768 int i_width, i_height;
771 #define FP_FACTOR 1000 /* our fixed point factor */
773 var_Get( p_vout, "width", &val );
775 var_Get( p_vout, "height", &val );
776 i_height = val.i_int;
777 var_Get( p_vout, "zoom", &val );
778 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
780 if( i_width > 0 && i_height > 0)
782 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
783 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
786 else if( i_width > 0 )
788 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
789 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
790 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
791 FP_FACTOR / p_vout->fmt_in.i_visible_width );
794 else if( i_height > 0 )
796 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
797 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
798 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
799 FP_FACTOR / p_vout->fmt_in.i_visible_height );
803 if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
805 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
806 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
807 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
812 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
814 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
815 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
819 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
820 p_vout->i_window_height );
825 /*****************************************************************************
826 * Object variables callbacks
827 *****************************************************************************/
828 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
829 vlc_value_t oldval, vlc_value_t newval, void *p_data )
831 vout_thread_t *p_vout = (vout_thread_t *)p_this;
832 InitWindowSize( p_vout, &p_vout->i_window_width,
833 &p_vout->i_window_height );
834 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
835 p_vout->i_window_height );
839 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
840 vlc_value_t oldval, vlc_value_t newval, void *p_data )
842 vout_thread_t *p_vout = (vout_thread_t *)p_this;
843 int64_t i_aspect_num, i_aspect_den;
844 unsigned int i_width, i_height;
846 /* Restore defaults */
847 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
848 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
849 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
850 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
852 if( !strcmp( psz_cmd, "crop" ) )
854 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
857 /* We're using the 3:4 syntax */
858 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
859 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
861 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
862 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
864 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
865 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
866 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
867 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
869 if( i_width < p_vout->fmt_render.i_visible_width )
871 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
872 (p_vout->fmt_render.i_visible_width - i_width) / 2;
873 p_vout->fmt_in.i_visible_width = i_width;
877 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
878 (p_vout->fmt_render.i_visible_height - i_height) / 2;
879 p_vout->fmt_in.i_visible_height = i_height;
884 psz_parser = strchr( newval.psz_string, 'x' );
887 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
888 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
890 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
891 if( psz_end != psz_parser ) goto crop_end;
893 psz_parser = strchr( ++psz_end, '+' );
894 i_crop_height = strtol( psz_end, &psz_end, 10 );
895 if( psz_end != psz_parser ) goto crop_end;
897 psz_parser = strchr( ++psz_end, '+' );
898 i_crop_left = strtol( psz_end, &psz_end, 10 );
899 if( psz_end != psz_parser ) goto crop_end;
902 i_crop_top = strtol( psz_end, &psz_end, 10 );
903 if( *psz_end != '\0' ) goto crop_end;
905 i_width = i_crop_width;
906 p_vout->fmt_in.i_visible_width = i_width;
908 i_height = i_crop_height;
909 p_vout->fmt_in.i_visible_height = i_height;
911 p_vout->fmt_in.i_x_offset = i_crop_left;
912 p_vout->fmt_in.i_y_offset = i_crop_top;
916 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
917 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
919 psz_parser = strchr( newval.psz_string, '+' );
920 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
921 if( psz_end != psz_parser ) goto crop_end;
923 psz_parser = strchr( ++psz_end, '+' );
924 i_crop_top = strtol( psz_end, &psz_end, 10 );
925 if( psz_end != psz_parser ) goto crop_end;
927 psz_parser = strchr( ++psz_end, '+' );
928 i_crop_right = strtol( psz_end, &psz_end, 10 );
929 if( psz_end != psz_parser ) goto crop_end;
932 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
933 if( *psz_end != '\0' ) goto crop_end;
935 i_width = p_vout->fmt_render.i_visible_width
936 - i_crop_left - i_crop_right;
937 p_vout->fmt_in.i_visible_width = i_width;
939 i_height = p_vout->fmt_render.i_visible_height
940 - i_crop_top - i_crop_bottom;
941 p_vout->fmt_in.i_visible_height = i_height;
943 p_vout->fmt_in.i_x_offset = i_crop_left;
944 p_vout->fmt_in.i_y_offset = i_crop_top;
948 else if( !strcmp( psz_cmd, "crop-top" )
949 || !strcmp( psz_cmd, "crop-left" )
950 || !strcmp( psz_cmd, "crop-bottom" )
951 || !strcmp( psz_cmd, "crop-right" ) )
953 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
955 i_crop_top = var_GetInteger( p_vout, "crop-top" );
956 i_crop_left = var_GetInteger( p_vout, "crop-left" );
957 i_crop_right = var_GetInteger( p_vout, "crop-right" );
958 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
960 i_width = p_vout->fmt_render.i_visible_width
961 - i_crop_left - i_crop_right;
962 p_vout->fmt_in.i_visible_width = i_width;
964 i_height = p_vout->fmt_render.i_visible_height
965 - i_crop_top - i_crop_bottom;
966 p_vout->fmt_in.i_visible_height = i_height;
968 p_vout->fmt_in.i_x_offset = i_crop_left;
969 p_vout->fmt_in.i_y_offset = i_crop_top;
973 InitWindowSize( p_vout, &p_vout->i_window_width,
974 &p_vout->i_window_height );
976 p_vout->i_changes |= VOUT_CROP_CHANGE;
978 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
979 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
980 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
981 p_vout->fmt_in.i_visible_width,
982 p_vout->fmt_in.i_visible_height );
987 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
988 vlc_value_t oldval, vlc_value_t newval, void *p_data )
990 vout_thread_t *p_vout = (vout_thread_t *)p_this;
991 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
994 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
996 /* Restore defaults */
997 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
998 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
999 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1000 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1002 if( !psz_parser ) goto aspect_end;
1004 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1005 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1007 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1008 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1010 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1011 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1012 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1013 p_vout->fmt_in.i_sar_num = i_sar_num;
1014 p_vout->fmt_in.i_sar_den = i_sar_den;
1015 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1016 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1019 if( p_vout->i_par_num && p_vout->i_par_den )
1021 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1022 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1023 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1024 p_vout->i_par_den / p_vout->i_par_num;
1025 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1028 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1030 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1031 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1032 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1033 i_aspect_num, i_aspect_den,
1034 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1036 var_Get( p_vout, "crop", &val );
1037 return CropCallback( p_this, "crop", val, val, 0 );
1042 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1043 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1045 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1046 playlist_t *p_playlist;
1047 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1049 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1053 /* Modify playlist as well because the vout might have to be restarted */
1054 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1055 var_Set( p_playlist, "video-on-top", newval );
1057 vlc_object_release( p_playlist );
1062 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1063 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1065 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1066 playlist_t *p_playlist;
1069 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1071 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1075 /* Modify playlist as well because the vout might have to be restarted */
1076 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1077 var_Set( p_playlist, "fullscreen", newval );
1079 vlc_object_release( p_playlist );
1082 /* Disable "always on top" in fullscreen mode */
1083 var_Get( p_vout, "video-on-top", &val );
1084 if( newval.b_bool && val.b_bool )
1086 val.b_bool = VLC_FALSE;
1087 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
1089 else if( !newval.b_bool && val.b_bool )
1091 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
1094 val.b_bool = VLC_TRUE;
1095 var_Set( p_vout, "intf-change", val );
1099 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1100 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1102 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1103 vout_Control( p_vout, VOUT_SNAPSHOT );