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->b_block && 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 *****************************************************************************/
190 void vout_IntfInit( vout_thread_t *p_vout )
192 vlc_value_t val, text, old_val;
193 vlc_bool_t b_force_par = VLC_FALSE;
196 /* Create a few object variables we'll need later on */
197 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
198 var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
199 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
200 var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
201 var_Create( p_vout, "snapshot-sequential",
202 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
203 var_Create( p_vout, "snapshot-num", VLC_VAR_INTEGER );
204 var_SetInteger( p_vout, "snapshot-num", 1 );
206 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
207 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
208 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
209 var_Get( p_vout, "align", &val );
210 p_vout->i_alignment = val.i_int;
212 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
213 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
215 var_Create( p_vout, "video-title-show", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
216 var_Create( p_vout, "video-title-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
217 var_Create( p_vout, "video-title-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
219 p_vout->b_title_show = var_GetBool( p_vout, "video-title-show" );
220 p_vout->i_title_timeout = (mtime_t) var_GetInteger( p_vout, "video-title-timeout" );
221 p_vout->i_title_position = var_GetInteger( p_vout, "video-title-position" );
223 var_AddCallback( p_vout, "video-title-show", TitleCallback, NULL );
224 var_AddCallback( p_vout, "video-title-timeout", TitleCallback, NULL );
225 var_AddCallback( p_vout, "video-title-position", TitleCallback, NULL );
227 /* Zoom object var */
228 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
229 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
231 text.psz_string = _("Zoom");
232 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
234 var_Get( p_vout, "zoom", &old_val );
235 if( old_val.f_float == 0.25 ||
236 old_val.f_float == 0.5 ||
237 old_val.f_float == 1 ||
238 old_val.f_float == 2 )
240 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
243 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
244 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
245 val.f_float = 0.5; text.psz_string = _("1:2 Half");
246 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
247 val.f_float = 1; text.psz_string = _("1:1 Original");
248 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
249 val.f_float = 2; text.psz_string = _("2:1 Double");
250 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
252 var_Set( p_vout, "zoom", old_val );
254 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
256 /* Crop offset vars */
257 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
258 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
259 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
260 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
262 var_SetInteger( p_vout, "crop-left", 0 );
263 var_SetInteger( p_vout, "crop-top", 0 );
264 var_SetInteger( p_vout, "crop-right", 0 );
265 var_SetInteger( p_vout, "crop-bottom", 0 );
267 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
268 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
269 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
270 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
272 /* Crop object var */
273 var_Create( p_vout, "crop", VLC_VAR_STRING |
274 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
276 text.psz_string = _("Crop");
277 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
280 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
281 val.psz_string = ""; text.psz_string = _("Default");
282 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
283 val.psz_string = "1:1"; text.psz_string = "1:1";
284 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
285 val.psz_string = "4:3"; text.psz_string = "4:3";
286 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
287 val.psz_string = "16:9"; text.psz_string = "16:9";
288 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
289 val.psz_string = "16:10"; text.psz_string = "16:10";
290 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
291 val.psz_string = "5:4"; text.psz_string = "5:4";
292 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
293 val.psz_string = "5:3"; text.psz_string = "5:3";
294 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
295 val.psz_string = "1.85:1"; text.psz_string = "1.85:1";
296 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
297 val.psz_string = "221:100"; text.psz_string = "2.21:1";
298 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
299 val.psz_string = "235:100"; text.psz_string = "2.35:1";
300 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
301 val.psz_string = "239:100"; text.psz_string = "2.39:1";
302 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
304 /* Add custom crop ratios */
305 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
306 if( psz_buf && *psz_buf )
308 char *psz_cur = psz_buf;
310 while( psz_cur && *psz_cur )
312 psz_next = strchr( psz_cur, ',' );
318 val.psz_string = strdup( psz_cur );
319 text.psz_string = strdup( psz_cur );
320 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text);
321 free( val.psz_string );
322 free( text.psz_string );
326 if( psz_buf ) free( psz_buf );
328 var_AddCallback( p_vout, "crop", CropCallback, NULL );
329 var_Get( p_vout, "crop", &old_val );
330 if( old_val.psz_string && *old_val.psz_string )
331 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
332 if( old_val.psz_string ) free( old_val.psz_string );
334 /* Monitor pixel aspect-ratio */
335 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
336 var_Get( p_vout, "monitor-par", &val );
337 if( val.psz_string && *val.psz_string )
339 char *psz_parser = strchr( val.psz_string, ':' );
340 unsigned int i_aspect_num = 0, i_aspect_den = 0;
344 i_aspect_num = strtol( val.psz_string, 0, 10 );
345 i_aspect_den = strtol( ++psz_parser, 0, 10 );
349 i_aspect = atof( val.psz_string );
350 vlc_ureduce( &i_aspect_num, &i_aspect_den,
351 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
353 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
355 p_vout->i_par_num = i_aspect_num;
356 p_vout->i_par_den = i_aspect_den;
358 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
359 p_vout->i_par_num, p_vout->i_par_den, 0 );
361 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
362 p_vout->i_par_num, p_vout->i_par_den );
363 b_force_par = VLC_TRUE;
365 if( val.psz_string ) free( val.psz_string );
367 /* Aspect-ratio object var */
368 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
369 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
371 text.psz_string = _("Aspect-ratio");
372 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
375 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
376 val.psz_string = ""; text.psz_string = _("Default");
377 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
378 val.psz_string = "1:1"; text.psz_string = "1:1";
379 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
380 val.psz_string = "4:3"; text.psz_string = "4:3";
381 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
382 val.psz_string = "16:9"; text.psz_string = "16:9";
383 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
384 val.psz_string = "16:10"; text.psz_string = "16:10";
385 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
386 val.psz_string = "221:100"; text.psz_string = "2.21:1";
387 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
388 val.psz_string = "5:4"; text.psz_string = "5:4";
389 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
391 /* Add custom aspect ratios */
392 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
393 if( psz_buf && *psz_buf )
395 char *psz_cur = psz_buf;
397 while( psz_cur && *psz_cur )
399 psz_next = strchr( psz_cur, ',' );
405 val.psz_string = strdup( psz_cur );
406 text.psz_string = strdup( psz_cur );
407 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text);
408 free( val.psz_string );
409 free( text.psz_string );
413 if( psz_buf ) free( psz_buf );
415 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
416 var_Get( p_vout, "aspect-ratio", &old_val );
417 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
418 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
419 if( old_val.psz_string ) free( old_val.psz_string );
421 /* Initialize the dimensions of the video window */
422 InitWindowSize( p_vout, &p_vout->i_window_width,
423 &p_vout->i_window_height );
425 /* Add a variable to indicate if the window should be on top of others */
426 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
427 text.psz_string = _("Always on top");
428 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
429 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
431 /* Add a variable to indicate whether we want window decoration or not */
432 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
434 /* Add a fullscreen variable */
435 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
436 text.psz_string = _("Fullscreen");
437 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
438 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
441 /* user requested fullscreen */
442 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
444 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
446 /* Add a snapshot variable */
447 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
448 text.psz_string = _("Snapshot");
449 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
450 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
452 /* Mouse coordinates */
453 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
454 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
455 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
456 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
457 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
459 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
460 val.b_bool = VLC_TRUE;
461 var_Set( p_vout, "intf-change", val );
464 /*****************************************************************************
465 * vout_Snapshot: generates a snapshot.
466 *****************************************************************************/
467 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
469 image_handler_t *p_image = image_HandlerCreate( p_vout );
470 video_format_t fmt_in, fmt_out;
471 char *psz_filename = NULL;
472 subpicture_t *p_subpic;
474 vlc_value_t val, format;
478 memset( &fmt_in, 0, sizeof(video_format_t));
479 memset( &fmt_out, 0, sizeof(video_format_t));
481 var_Get( p_vout, "snapshot-path", &val );
482 if( val.psz_string && !*val.psz_string )
484 free( val.psz_string );
488 /* Embedded snapshot : if snapshot-path == object:object-id, then
489 create a snapshot_t* and store it in
490 object(object-id)->p_private, then unlock and signal the
493 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
496 vlc_object_t* p_dest;
498 snapshot_t *p_snapshot;
501 /* Destination object-id is following object: */
502 i_id = atoi( &val.psz_string[7] );
503 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
506 msg_Err( p_vout, "Cannot find calling object" );
507 image_HandlerDelete( p_image );
510 /* Object must be locked. We will unlock it once we get the
511 snapshot and written it to p_private */
512 p_dest->p_private = NULL;
514 /* Save the snapshot to a memory zone */
515 fmt_in = p_vout->fmt_in;
516 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
517 /* FIXME: should not be hardcoded. We should be able to
518 specify the snapshot size (snapshot-width and snapshot-height). */
519 fmt_out.i_width = 320;
520 fmt_out.i_height = 200;
521 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
522 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
525 msg_Err( p_vout, "Could not get snapshot" );
526 image_HandlerDelete( p_image );
527 vlc_cond_signal( &p_dest->object_wait );
528 vlc_object_release( p_dest );
532 /* Copy the p_block data to a snapshot structure */
533 /* FIXME: get the timestamp */
534 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
537 block_Release( p_block );
538 image_HandlerDelete( p_image );
539 vlc_cond_signal( &p_dest->object_wait );
540 vlc_object_release( p_dest );
544 i_size = p_block->i_buffer;
546 p_snapshot->i_width = fmt_out.i_width;
547 p_snapshot->i_height = fmt_out.i_height;
548 p_snapshot->i_datasize = i_size;
549 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
550 p_snapshot->p_data = ( char* ) malloc( i_size );
551 if( !p_snapshot->p_data )
553 block_Release( p_block );
555 image_HandlerDelete( p_image );
556 vlc_cond_signal( &p_dest->object_wait );
557 vlc_object_release( p_dest );
560 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
562 p_dest->p_private = p_snapshot;
564 block_Release( p_block );
566 /* Unlock the object */
567 vlc_cond_signal( &p_dest->object_wait );
568 vlc_object_release( p_dest );
570 image_HandlerDelete( p_image );
575 #if defined(__APPLE__) || defined(SYS_BEOS)
576 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
578 if( asprintf( &val.psz_string, "%s/Desktop",
579 p_vout->p_libvlc->psz_homedir ) == -1 )
580 val.psz_string = NULL;
583 #elif defined(WIN32) && !defined(UNDER_CE)
584 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
586 /* Get the My Pictures folder path */
588 char *p_mypicturesdir = NULL;
589 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
591 #ifndef CSIDL_FLAG_CREATE
592 # define CSIDL_FLAG_CREATE 0x8000
594 #ifndef CSIDL_MYPICTURES
595 # define CSIDL_MYPICTURES 0x27
597 #ifndef SHGFP_TYPE_CURRENT
598 # define SHGFP_TYPE_CURRENT 0
601 HINSTANCE shfolder_dll;
602 SHGETFOLDERPATH SHGetFolderPath ;
604 /* load the shfolder dll to retrieve SHGetFolderPath */
605 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
607 wchar_t wdir[PATH_MAX];
608 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
609 _T("SHGetFolderPathW") );
610 if ((SHGetFolderPath != NULL )
611 && SUCCEEDED (SHGetFolderPath (NULL,
612 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
613 NULL, SHGFP_TYPE_CURRENT,
615 p_mypicturesdir = FromWide (wdir);
617 FreeLibrary( shfolder_dll );
620 if( p_mypicturesdir == NULL )
622 if( asprintf( &val.psz_string, "%s",
623 p_vout->p_libvlc->psz_homedir ) == -1 )
624 val.psz_string = NULL;
628 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
629 val.psz_string = NULL;
630 free( p_mypicturesdir );
635 /* XXX: This saves in the data directory. Shouldn't we try saving
636 * to psz_homedir/Desktop or something nicer ? */
637 if( !val.psz_string && p_vout->p_libvlc->psz_datadir )
639 if( asprintf( &val.psz_string, "%s",
640 p_vout->p_libvlc->psz_datadir ) == -1 )
641 val.psz_string = NULL;
645 if( !val.psz_string )
647 msg_Err( p_vout, "no path specified for snapshots" );
650 var_Get( p_vout, "snapshot-format", &format );
651 if( !format.psz_string || !*format.psz_string )
653 if( format.psz_string ) free( format.psz_string );
654 format.psz_string = strdup( "png" );
658 * Did the user specify a directory? If not, path = NULL.
660 path = utf8_opendir ( (const char *)val.psz_string );
664 char *psz_prefix = var_GetString( p_vout, "snapshot-prefix" );
665 if( !psz_prefix ) psz_prefix = strdup( "vlcsnap-" );
668 char *psz_tmp = str_format( p_vout, psz_prefix );
669 filename_sanitize( psz_tmp );
671 psz_prefix = psz_tmp;
675 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
677 int i_num = var_GetInteger( p_vout, "snapshot-num" );
681 asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s", val.psz_string,
682 psz_prefix, i_num++, format.psz_string );
684 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
685 var_SetInteger( p_vout, "snapshot-num", i_num );
689 asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s", val.psz_string,
691 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
697 else // The user specified a full path name (including file name)
699 psz_filename = str_format( p_vout, val.psz_string );
700 path_sanitize( psz_filename );
703 free( val.psz_string );
704 free( format.psz_string );
706 /* Save the snapshot */
707 fmt_in = p_vout->fmt_in;
708 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
709 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
710 if( i_ret != VLC_SUCCESS )
712 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
713 free( psz_filename );
714 image_HandlerDelete( p_image );
718 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
719 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
720 "%s", psz_filename );
721 free( psz_filename );
723 if( var_GetBool( p_vout, "snapshot-preview" ) )
725 /* Inject a subpicture with the snapshot */
726 memset( &fmt_out, 0, sizeof(fmt_out) );
727 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
728 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
729 image_HandlerDelete( p_image );
730 if( !p_pif ) return VLC_EGENERIC;
732 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
733 if( p_subpic == NULL )
735 p_pif->pf_release( p_pif );
739 p_subpic->i_channel = 0;
740 p_subpic->i_start = mdate();
741 p_subpic->i_stop = mdate() + 4000000;
742 p_subpic->b_ephemer = VLC_TRUE;
743 p_subpic->b_fade = VLC_TRUE;
744 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
745 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
747 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
748 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
750 p_pif->pf_release( p_pif );
752 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
756 image_HandlerDelete( p_image );
762 /*****************************************************************************
764 *****************************************************************************/
766 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
767 vlc_bool_t b_add, vlc_bool_t b_setconfig )
770 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
772 /* Todo : Use some generic chain manipulation functions */
773 if( !psz_string ) psz_string = strdup("");
775 psz_parser = strstr( psz_string, psz_name );
780 psz_parser = psz_string;
781 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
782 psz_string, psz_name );
792 memmove( psz_parser, psz_parser + strlen(psz_name) +
793 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
794 strlen(psz_parser + strlen(psz_name)) + 1 );
796 /* Remove trailing : : */
797 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
799 *(psz_string+strlen(psz_string ) -1 ) = '\0';
809 config_PutPsz( p_vout, "vout-filter", psz_string );
811 var_SetString( p_vout, "vout-filter", psz_string );
815 /*****************************************************************************
816 * vout_ControlDefault: default methods for video output control.
817 *****************************************************************************/
818 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
825 if( p_vout->p_parent_intf )
827 vlc_object_release( p_vout->p_parent_intf );
828 p_vout->p_parent_intf = NULL;
834 p_vout->b_snapshot = VLC_TRUE;
839 msg_Dbg( p_vout, "control query not supported" );
844 /*****************************************************************************
845 * InitWindowSize: find the initial dimensions the video window should have.
846 *****************************************************************************
847 * This function will check the "width", "height" and "zoom" config options and
848 * will calculate the size that the video window should have.
849 *****************************************************************************/
850 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
851 unsigned *pi_height )
854 int i_width, i_height;
857 #define FP_FACTOR 1000 /* our fixed point factor */
859 var_Get( p_vout, "width", &val );
861 var_Get( p_vout, "height", &val );
862 i_height = val.i_int;
863 var_Get( p_vout, "zoom", &val );
864 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
866 if( i_width > 0 && i_height > 0)
868 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
869 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
872 else if( i_width > 0 )
874 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
875 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
876 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
877 FP_FACTOR / p_vout->fmt_in.i_visible_width );
880 else if( i_height > 0 )
882 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
883 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
884 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
885 FP_FACTOR / p_vout->fmt_in.i_visible_height );
889 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
890 msg_Warn( p_vout, "fucked up aspect" );
891 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
892 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
894 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
896 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
897 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
898 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
903 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
905 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
906 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
910 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
911 p_vout->i_window_height );
916 /*****************************************************************************
917 * Object variables callbacks
918 *****************************************************************************/
919 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
920 vlc_value_t oldval, vlc_value_t newval, void *p_data )
922 vout_thread_t *p_vout = (vout_thread_t *)p_this;
923 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
924 InitWindowSize( p_vout, &p_vout->i_window_width,
925 &p_vout->i_window_height );
926 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
927 p_vout->i_window_height );
931 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
932 vlc_value_t oldval, vlc_value_t newval, void *p_data )
934 vout_thread_t *p_vout = (vout_thread_t *)p_this;
935 int64_t i_aspect_num, i_aspect_den;
936 unsigned int i_width, i_height;
938 (void)oldval; (void)p_data;
940 /* Restore defaults */
941 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
942 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
943 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
944 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
946 if( !strcmp( psz_cmd, "crop" ) )
948 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
951 /* We're using the 3:4 syntax */
952 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
953 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
955 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
956 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
958 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
959 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
960 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
961 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
963 if( i_width < p_vout->fmt_render.i_visible_width )
965 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
966 (p_vout->fmt_render.i_visible_width - i_width) / 2;
967 p_vout->fmt_in.i_visible_width = i_width;
971 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
972 (p_vout->fmt_render.i_visible_height - i_height) / 2;
973 p_vout->fmt_in.i_visible_height = i_height;
978 psz_parser = strchr( newval.psz_string, 'x' );
981 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
982 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
984 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
985 if( psz_end != psz_parser ) goto crop_end;
987 psz_parser = strchr( ++psz_end, '+' );
988 i_crop_height = strtol( psz_end, &psz_end, 10 );
989 if( psz_end != psz_parser ) goto crop_end;
991 psz_parser = strchr( ++psz_end, '+' );
992 i_crop_left = strtol( psz_end, &psz_end, 10 );
993 if( psz_end != psz_parser ) goto crop_end;
996 i_crop_top = strtol( psz_end, &psz_end, 10 );
997 if( *psz_end != '\0' ) goto crop_end;
999 i_width = i_crop_width;
1000 p_vout->fmt_in.i_visible_width = i_width;
1002 i_height = i_crop_height;
1003 p_vout->fmt_in.i_visible_height = i_height;
1005 p_vout->fmt_in.i_x_offset = i_crop_left;
1006 p_vout->fmt_in.i_y_offset = i_crop_top;
1010 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1011 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1013 psz_parser = strchr( newval.psz_string, '+' );
1014 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1015 if( psz_end != psz_parser ) goto crop_end;
1017 psz_parser = strchr( ++psz_end, '+' );
1018 i_crop_top = strtol( psz_end, &psz_end, 10 );
1019 if( psz_end != psz_parser ) goto crop_end;
1021 psz_parser = strchr( ++psz_end, '+' );
1022 i_crop_right = strtol( psz_end, &psz_end, 10 );
1023 if( psz_end != psz_parser ) goto crop_end;
1026 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1027 if( *psz_end != '\0' ) goto crop_end;
1029 i_width = p_vout->fmt_render.i_visible_width
1030 - i_crop_left - i_crop_right;
1031 p_vout->fmt_in.i_visible_width = i_width;
1033 i_height = p_vout->fmt_render.i_visible_height
1034 - i_crop_top - i_crop_bottom;
1035 p_vout->fmt_in.i_visible_height = i_height;
1037 p_vout->fmt_in.i_x_offset = i_crop_left;
1038 p_vout->fmt_in.i_y_offset = i_crop_top;
1042 else if( !strcmp( psz_cmd, "crop-top" )
1043 || !strcmp( psz_cmd, "crop-left" )
1044 || !strcmp( psz_cmd, "crop-bottom" )
1045 || !strcmp( psz_cmd, "crop-right" ) )
1047 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1049 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1050 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1051 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1052 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1054 i_width = p_vout->fmt_render.i_visible_width
1055 - i_crop_left - i_crop_right;
1056 p_vout->fmt_in.i_visible_width = i_width;
1058 i_height = p_vout->fmt_render.i_visible_height
1059 - i_crop_top - i_crop_bottom;
1060 p_vout->fmt_in.i_visible_height = i_height;
1062 p_vout->fmt_in.i_x_offset = i_crop_left;
1063 p_vout->fmt_in.i_y_offset = i_crop_top;
1067 InitWindowSize( p_vout, &p_vout->i_window_width,
1068 &p_vout->i_window_height );
1070 p_vout->i_changes |= VOUT_CROP_CHANGE;
1072 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1073 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1074 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1075 p_vout->fmt_in.i_visible_width,
1076 p_vout->fmt_in.i_visible_height );
1081 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1082 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1084 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1085 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1088 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1089 (void)psz_cmd; (void)oldval; (void)p_data;
1091 /* Restore defaults */
1092 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1093 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1094 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1095 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1097 if( !psz_parser ) goto aspect_end;
1099 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1100 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1102 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1103 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1105 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1106 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1107 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1108 p_vout->fmt_in.i_sar_num = i_sar_num;
1109 p_vout->fmt_in.i_sar_den = i_sar_den;
1110 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1111 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1114 if( p_vout->i_par_num && p_vout->i_par_den )
1116 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1117 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1118 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1119 p_vout->i_par_den / p_vout->i_par_num;
1120 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1123 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1125 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1126 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1127 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1128 i_aspect_num, i_aspect_den,
1129 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1131 var_Get( p_vout, "crop", &val );
1132 return CropCallback( p_this, "crop", val, val, 0 );
1137 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
1138 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1140 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1141 playlist_t *p_playlist = pl_Yield( p_this );
1142 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1143 (void)psz_cmd; (void)oldval; (void)p_data;
1145 /* Modify playlist as well because the vout might have to be restarted */
1146 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1147 var_Set( p_playlist, "video-on-top", newval );
1149 pl_Release( p_this );
1153 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1154 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1156 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1158 playlist_t *p_playlist = pl_Yield( p_this );
1159 (void)psz_cmd; (void)oldval; (void)p_data;
1161 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1163 /* Modify playlist as well because the vout might have to be restarted */
1164 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1165 var_Set( p_playlist, "fullscreen", newval );
1166 pl_Release( p_playlist );
1168 val.b_bool = VLC_TRUE;
1169 var_Set( p_vout, "intf-change", val );
1173 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1174 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1176 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1177 vout_Control( p_vout, VOUT_SNAPSHOT );
1178 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
1182 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
1183 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1185 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1187 if( !strncmp( psz_cmd, "video-title-show", 16 ) )
1188 p_vout->b_title_show = newval.b_bool;
1189 else if( !strncmp( psz_cmd, "video-title-timeout", 19 ) )
1190 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1191 else if( !strncmp( psz_cmd, "video-title-position", 20 ) )
1192 p_vout->i_title_position = newval.i_int;