1 /*****************************************************************************
2 * vout_intf.c : video output interface
3 *****************************************************************************
4 * Copyright (C) 2000-2007 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <stdlib.h> /* free() */
32 #include <sys/types.h> /* opendir() */
33 #include <dirent.h> /* opendir() */
35 #include <vlc_interface.h>
36 #include <vlc_block.h>
37 #include <vlc_playlist.h>
40 #include <vlc_image.h>
42 #include <vlc_charset.h>
44 #include <vlc_strings.h>
45 #include <vlc_charset.h>
46 #include "../libvlc.h"
48 /*****************************************************************************
50 *****************************************************************************/
51 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
53 /* Object variables callbacks */
54 static int ZoomCallback( vlc_object_t *, char const *,
55 vlc_value_t, vlc_value_t, void * );
56 static int CropCallback( vlc_object_t *, char const *,
57 vlc_value_t, vlc_value_t, void * );
58 static int AspectCallback( vlc_object_t *, char const *,
59 vlc_value_t, vlc_value_t, void * );
60 static int OnTopCallback( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
62 static int FullscreenCallback( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
64 static int SnapshotCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
66 static int TitleCallback( vlc_object_t *, char const *,
67 vlc_value_t, vlc_value_t, void * );
69 /*****************************************************************************
70 * vout_RequestWindow: Create/Get a video window if possible.
71 *****************************************************************************
72 * This function looks for the main interface and tries to request
73 * a new video window. If it fails then the vout will still need to create the
75 *****************************************************************************/
76 void *vout_RequestWindow( vout_thread_t *p_vout,
77 int *pi_x_hint, int *pi_y_hint,
78 unsigned int *pi_width_hint,
79 unsigned int *pi_height_hint )
81 intf_thread_t *p_intf = NULL;
88 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
90 /* Get requested coordinates */
91 var_Get( p_vout, "video-x", &val );
92 *pi_x_hint = val.i_int ;
93 var_Get( p_vout, "video-y", &val );
94 *pi_y_hint = val.i_int;
96 *pi_width_hint = p_vout->i_window_width;
97 *pi_height_hint = p_vout->i_window_height;
99 /* Check whether someone provided us with a window ID */
100 var_Get( p_vout->p_libvlc, "drawable", &val );
101 if( val.i_int ) return (void *)(intptr_t)val.i_int;
103 /* Find if the main interface supports embedding */
104 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
105 if( !p_list ) return NULL;
107 for( i = 0; i < p_list->i_count; i++ )
109 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
110 if( p_intf->pf_request_window ) break;
116 vlc_list_release( p_list );
120 vlc_object_yield( p_intf );
121 vlc_list_release( p_list );
123 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
124 pi_width_hint, pi_height_hint );
126 if( !p_window ) vlc_object_release( p_intf );
127 else p_vout->p_parent_intf = p_intf;
132 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
134 intf_thread_t *p_intf = p_vout->p_parent_intf;
136 if( !p_intf ) return;
138 vlc_mutex_lock( &p_intf->object_lock );
141 vlc_mutex_unlock( &p_intf->object_lock );
145 if( !p_intf->pf_release_window )
147 msg_Err( p_vout, "no pf_release_window");
148 vlc_mutex_unlock( &p_intf->object_lock );
149 vlc_object_release( p_intf );
153 p_intf->pf_release_window( p_intf, p_window );
155 p_vout->p_parent_intf = NULL;
156 vlc_mutex_unlock( &p_intf->object_lock );
157 vlc_object_release( p_intf );
160 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
161 int i_query, va_list args )
163 intf_thread_t *p_intf = p_vout->p_parent_intf;
166 if( !p_intf ) return VLC_EGENERIC;
168 vlc_mutex_lock( &p_intf->object_lock );
171 vlc_mutex_unlock( &p_intf->object_lock );
175 if( !p_intf->pf_control_window )
177 msg_Err( p_vout, "no pf_control_window");
178 vlc_mutex_unlock( &p_intf->object_lock );
182 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
183 vlc_mutex_unlock( &p_intf->object_lock );
187 /*****************************************************************************
188 * vout_IntfInit: called during the vout creation to initialise misc things.
189 *****************************************************************************/
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 );
205 var_Create( p_vout, "snapshot-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
206 var_Create( p_vout, "snapshot-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
208 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
209 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
210 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
211 var_Get( p_vout, "align", &val );
212 p_vout->i_alignment = val.i_int;
214 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
215 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
217 var_Create( p_vout, "video-title-show", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
218 var_Create( p_vout, "video-title-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
219 var_Create( p_vout, "video-title-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
221 p_vout->b_title_show = var_GetBool( p_vout, "video-title-show" );
222 p_vout->i_title_timeout = (mtime_t) var_GetInteger( p_vout, "video-title-timeout" );
223 p_vout->i_title_position = var_GetInteger( p_vout, "video-title-position" );
225 var_AddCallback( p_vout, "video-title-show", TitleCallback, NULL );
226 var_AddCallback( p_vout, "video-title-timeout", TitleCallback, NULL );
227 var_AddCallback( p_vout, "video-title-position", TitleCallback, NULL );
229 /* Zoom object var */
230 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
231 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
233 text.psz_string = _("Zoom");
234 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
236 var_Get( p_vout, "zoom", &old_val );
237 if( old_val.f_float == 0.25 ||
238 old_val.f_float == 0.5 ||
239 old_val.f_float == 1 ||
240 old_val.f_float == 2 )
242 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
245 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
246 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
247 val.f_float = 0.5; text.psz_string = _("1:2 Half");
248 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
249 val.f_float = 1; text.psz_string = _("1:1 Original");
250 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
251 val.f_float = 2; text.psz_string = _("2:1 Double");
252 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
254 var_Set( p_vout, "zoom", old_val );
256 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
258 /* Crop offset vars */
259 var_Create( p_vout, "crop-left", VLC_VAR_INTEGER );
260 var_Create( p_vout, "crop-top", VLC_VAR_INTEGER );
261 var_Create( p_vout, "crop-right", VLC_VAR_INTEGER );
262 var_Create( p_vout, "crop-bottom", VLC_VAR_INTEGER );
264 var_SetInteger( p_vout, "crop-left", 0 );
265 var_SetInteger( p_vout, "crop-top", 0 );
266 var_SetInteger( p_vout, "crop-right", 0 );
267 var_SetInteger( p_vout, "crop-bottom", 0 );
269 var_AddCallback( p_vout, "crop-left", CropCallback, NULL );
270 var_AddCallback( p_vout, "crop-top", CropCallback, NULL );
271 var_AddCallback( p_vout, "crop-right", CropCallback, NULL );
272 var_AddCallback( p_vout, "crop-bottom", CropCallback, NULL );
274 /* Crop object var */
275 var_Create( p_vout, "crop", VLC_VAR_STRING |
276 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
278 text.psz_string = _("Crop");
279 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
282 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
283 val.psz_string = ""; text.psz_string = _("Default");
284 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
285 val.psz_string = "1:1"; text.psz_string = "1:1";
286 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
287 val.psz_string = "4:3"; text.psz_string = "4:3";
288 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
289 val.psz_string = "16:9"; text.psz_string = "16:9";
290 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
291 val.psz_string = "16:10"; text.psz_string = "16:10";
292 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
293 val.psz_string = "5:4"; text.psz_string = "5:4";
294 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
295 val.psz_string = "5:3"; text.psz_string = "5:3";
296 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
297 val.psz_string = "1.85:1"; text.psz_string = "1.85:1";
298 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
299 val.psz_string = "221:100"; text.psz_string = "2.21:1";
300 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
301 val.psz_string = "235:100"; text.psz_string = "2.35:1";
302 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
303 val.psz_string = "239:100"; text.psz_string = "2.39:1";
304 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
306 /* Add custom crop ratios */
307 psz_buf = config_GetPsz( p_vout, "custom-crop-ratios" );
308 if( psz_buf && *psz_buf )
310 char *psz_cur = psz_buf;
312 while( psz_cur && *psz_cur )
314 psz_next = strchr( psz_cur, ',' );
320 val.psz_string = strdup( psz_cur );
321 text.psz_string = strdup( psz_cur );
322 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text);
323 free( val.psz_string );
324 free( text.psz_string );
328 if( psz_buf ) free( psz_buf );
330 var_AddCallback( p_vout, "crop", CropCallback, NULL );
331 var_Get( p_vout, "crop", &old_val );
332 if( old_val.psz_string && *old_val.psz_string )
333 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
334 if( old_val.psz_string ) free( old_val.psz_string );
336 /* Monitor pixel aspect-ratio */
337 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
338 var_Get( p_vout, "monitor-par", &val );
339 if( val.psz_string && *val.psz_string )
341 char *psz_parser = strchr( val.psz_string, ':' );
342 unsigned int i_aspect_num = 0, i_aspect_den = 0;
346 i_aspect_num = strtol( val.psz_string, 0, 10 );
347 i_aspect_den = strtol( ++psz_parser, 0, 10 );
351 i_aspect = atof( val.psz_string );
352 vlc_ureduce( &i_aspect_num, &i_aspect_den,
353 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
355 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
357 p_vout->i_par_num = i_aspect_num;
358 p_vout->i_par_den = i_aspect_den;
360 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
361 p_vout->i_par_num, p_vout->i_par_den, 0 );
363 msg_Dbg( p_vout, "overriding monitor pixel aspect-ratio: %i:%i",
364 p_vout->i_par_num, p_vout->i_par_den );
365 b_force_par = VLC_TRUE;
367 if( val.psz_string ) free( val.psz_string );
369 /* Aspect-ratio object var */
370 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
371 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
373 text.psz_string = _("Aspect-ratio");
374 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
377 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
378 val.psz_string = ""; text.psz_string = _("Default");
379 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
380 val.psz_string = "1:1"; text.psz_string = "1:1";
381 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
382 val.psz_string = "4:3"; text.psz_string = "4:3";
383 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
384 val.psz_string = "16:9"; text.psz_string = "16:9";
385 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
386 val.psz_string = "16:10"; text.psz_string = "16:10";
387 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
388 val.psz_string = "221:100"; text.psz_string = "2.21:1";
389 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
390 val.psz_string = "5:4"; text.psz_string = "5:4";
391 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
393 /* Add custom aspect ratios */
394 psz_buf = config_GetPsz( p_vout, "custom-aspect-ratios" );
395 if( psz_buf && *psz_buf )
397 char *psz_cur = psz_buf;
399 while( psz_cur && *psz_cur )
401 psz_next = strchr( psz_cur, ',' );
407 val.psz_string = strdup( psz_cur );
408 text.psz_string = strdup( psz_cur );
409 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text);
410 free( val.psz_string );
411 free( text.psz_string );
415 if( psz_buf ) free( psz_buf );
417 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
418 var_Get( p_vout, "aspect-ratio", &old_val );
419 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
420 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
421 if( old_val.psz_string ) free( old_val.psz_string );
423 /* Initialize the dimensions of the video window */
424 InitWindowSize( p_vout, &p_vout->i_window_width,
425 &p_vout->i_window_height );
427 /* Add a variable to indicate if the window should be on top of others */
428 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
429 text.psz_string = _("Always on top");
430 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
431 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
433 /* Add a variable to indicate whether we want window decoration or not */
434 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
436 /* Add a fullscreen variable */
437 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
438 text.psz_string = _("Fullscreen");
439 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
440 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
443 /* user requested fullscreen */
444 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
446 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
448 /* Add a snapshot variable */
449 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
450 text.psz_string = _("Snapshot");
451 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
452 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
454 /* Mouse coordinates */
455 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
456 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
457 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
458 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
459 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
461 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
462 val.b_bool = VLC_TRUE;
463 var_Set( p_vout, "intf-change", val );
466 /*****************************************************************************
467 * vout_Snapshot: generates a snapshot.
468 *****************************************************************************/
469 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
471 image_handler_t *p_image = image_HandlerCreate( p_vout );
472 video_format_t fmt_in, fmt_out;
473 char *psz_filename = NULL;
474 subpicture_t *p_subpic;
476 vlc_value_t val, format;
480 memset( &fmt_in, 0, sizeof(video_format_t));
481 memset( &fmt_out, 0, sizeof(video_format_t));
483 var_Get( p_vout, "snapshot-path", &val );
484 if( val.psz_string && !*val.psz_string )
486 free( val.psz_string );
490 /* Embedded snapshot : if snapshot-path == object:object-id, then
491 create a snapshot_t* and store it in
492 object(object-id)->p_private, then unlock and signal the
495 if( val.psz_string && !strncmp( val.psz_string, "object:", 7 ) )
498 vlc_object_t* p_dest;
500 snapshot_t *p_snapshot;
503 /* Destination object-id is following object: */
504 i_id = atoi( &val.psz_string[7] );
505 p_dest = ( vlc_object_t* )vlc_current_object( i_id );
508 msg_Err( p_vout, "Cannot find calling object" );
509 image_HandlerDelete( p_image );
512 /* Object must be locked. We will unlock it once we get the
513 snapshot and written it to p_private */
514 p_dest->p_private = NULL;
516 /* Save the snapshot to a memory zone */
517 fmt_in = p_vout->fmt_in;
518 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
519 /* FIXME: should not be hardcoded. We should be able to
520 specify the snapshot size (snapshot-width and snapshot-height). */
521 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
522 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
523 fmt_out.i_chroma = VLC_FOURCC( 'p','n','g',' ' );
525 p_block = ( block_t* ) image_Write( p_image, p_pic, &fmt_in, &fmt_out );
528 msg_Err( p_vout, "Could not get snapshot" );
529 image_HandlerDelete( p_image );
530 vlc_cond_signal( &p_dest->object_wait );
531 vlc_object_release( p_dest );
535 /* Copy the p_block data to a snapshot structure */
536 /* FIXME: get the timestamp */
537 p_snapshot = ( snapshot_t* ) malloc( sizeof( snapshot_t ) );
540 block_Release( p_block );
541 image_HandlerDelete( p_image );
542 vlc_cond_signal( &p_dest->object_wait );
543 vlc_object_release( p_dest );
547 i_size = p_block->i_buffer;
549 p_snapshot->i_width = fmt_out.i_width;
550 p_snapshot->i_height = fmt_out.i_height;
551 p_snapshot->i_datasize = i_size;
552 p_snapshot->date = p_block->i_pts; /* FIXME ?? */
553 p_snapshot->p_data = ( char* ) malloc( i_size );
554 if( !p_snapshot->p_data )
556 block_Release( p_block );
558 image_HandlerDelete( p_image );
559 vlc_cond_signal( &p_dest->object_wait );
560 vlc_object_release( p_dest );
563 memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer );
565 p_dest->p_private = p_snapshot;
567 block_Release( p_block );
569 /* Unlock the object */
570 vlc_cond_signal( &p_dest->object_wait );
571 vlc_object_release( p_dest );
573 image_HandlerDelete( p_image );
577 #if defined(__APPLE__) || defined(SYS_BEOS)
578 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
580 if( asprintf( &val.psz_string, "%s/Desktop",
581 p_vout->p_libvlc->psz_homedir ) == -1 )
582 val.psz_string = NULL;
585 #elif defined(WIN32) && !defined(UNDER_CE)
586 if( !val.psz_string && p_vout->p_libvlc->psz_homedir )
588 /* Get the My Pictures folder path */
590 char *p_mypicturesdir = NULL;
591 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
593 #ifndef CSIDL_FLAG_CREATE
594 # define CSIDL_FLAG_CREATE 0x8000
596 #ifndef CSIDL_MYPICTURES
597 # define CSIDL_MYPICTURES 0x27
599 #ifndef SHGFP_TYPE_CURRENT
600 # define SHGFP_TYPE_CURRENT 0
603 HINSTANCE shfolder_dll;
604 SHGETFOLDERPATH SHGetFolderPath ;
606 /* load the shfolder dll to retrieve SHGetFolderPath */
607 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
609 wchar_t wdir[PATH_MAX];
610 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
611 _T("SHGetFolderPathW") );
612 if ((SHGetFolderPath != NULL )
613 && SUCCEEDED (SHGetFolderPath (NULL,
614 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
615 NULL, SHGFP_TYPE_CURRENT,
617 p_mypicturesdir = FromWide (wdir);
619 FreeLibrary( shfolder_dll );
622 if( p_mypicturesdir == NULL )
624 if( asprintf( &val.psz_string, "%s",
625 p_vout->p_libvlc->psz_homedir ) == -1 )
626 val.psz_string = NULL;
630 if( asprintf( &val.psz_string, p_mypicturesdir ) == -1 )
631 val.psz_string = NULL;
632 free( p_mypicturesdir );
637 /* XXX: This saves in the data directory. Shouldn't we try saving
638 * to psz_homedir/Desktop or something nicer ? */
639 if( !val.psz_string && p_vout->p_libvlc->psz_datadir )
641 if( asprintf( &val.psz_string, "%s",
642 p_vout->p_libvlc->psz_datadir ) == -1 )
643 val.psz_string = NULL;
647 if( !val.psz_string )
649 msg_Err( p_vout, "no path specified for snapshots" );
652 var_Get( p_vout, "snapshot-format", &format );
653 if( !format.psz_string || !*format.psz_string )
655 if( format.psz_string ) free( format.psz_string );
656 format.psz_string = strdup( "png" );
660 * Did the user specify a directory? If not, path = NULL.
662 path = utf8_opendir ( (const char *)val.psz_string );
665 char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
666 if( psz_prefix == NULL )
667 psz_prefix = strdup( "vlcsnap-" );
670 char *psz_tmp = str_format( p_vout, psz_prefix );
671 filename_sanitize( psz_tmp );
673 psz_prefix = psz_tmp;
677 if( var_GetBool( p_vout, "snapshot-sequential" ) == VLC_TRUE )
679 int i_num = var_GetInteger( p_vout, "snapshot-num" );
683 asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s", val.psz_string,
684 psz_prefix, i_num++, format.psz_string );
686 while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
687 var_SetInteger( p_vout, "snapshot-num", i_num );
691 asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s", val.psz_string,
693 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
699 else // The user specified a full path name (including file name)
701 psz_filename = str_format( p_vout, val.psz_string );
702 path_sanitize( psz_filename );
705 free( val.psz_string );
706 free( format.psz_string );
708 fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" );
709 fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" );
711 if( fmt_out.i_width == 0 && fmt_out.i_height > 0 )
713 float f = (float)p_vout->fmt_in.i_height / fmt_out.i_height;
714 fmt_out.i_width = p_vout->fmt_in.i_width / f;
716 else if( fmt_out.i_height == 0 && fmt_out.i_width > 0 )
718 float f = (float)p_vout->fmt_in.i_width / fmt_out.i_width;
719 fmt_out.i_height = p_vout->fmt_in.i_height / f;
722 /* Save the snapshot */
723 fmt_in = p_vout->fmt_in;
724 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
725 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
726 if( i_ret != VLC_SUCCESS )
728 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
729 free( psz_filename );
730 image_HandlerDelete( p_image );
734 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
735 vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
736 "%s", psz_filename );
737 free( psz_filename );
739 if( var_GetBool( p_vout, "snapshot-preview" ) )
741 /* Inject a subpicture with the snapshot */
742 memset( &fmt_out, 0, sizeof(fmt_out) );
743 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
744 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
745 image_HandlerDelete( p_image );
746 if( !p_pif ) return VLC_EGENERIC;
748 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
749 if( p_subpic == NULL )
751 p_pif->pf_release( p_pif );
755 p_subpic->i_channel = 0;
756 p_subpic->i_start = mdate();
757 p_subpic->i_stop = mdate() + 4000000;
758 p_subpic->b_ephemer = VLC_TRUE;
759 p_subpic->b_fade = VLC_TRUE;
760 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
761 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
763 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
764 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture,
766 p_pif->pf_release( p_pif );
768 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
772 image_HandlerDelete( p_image );
778 /*****************************************************************************
780 *****************************************************************************/
782 void vout_EnableFilter( vout_thread_t *p_vout, char *psz_name,
783 vlc_bool_t b_add, vlc_bool_t b_setconfig )
786 char *psz_string = config_GetPsz( p_vout, "vout-filter" );
788 /* Todo : Use some generic chain manipulation functions */
789 if( !psz_string ) psz_string = strdup("");
791 psz_parser = strstr( psz_string, psz_name );
796 psz_parser = psz_string;
797 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
798 psz_string, psz_name );
808 memmove( psz_parser, psz_parser + strlen(psz_name) +
809 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
810 strlen(psz_parser + strlen(psz_name)) + 1 );
812 /* Remove trailing : : */
813 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
815 *(psz_string+strlen(psz_string ) -1 ) = '\0';
825 config_PutPsz( p_vout, "vout-filter", psz_string );
827 var_SetString( p_vout, "vout-filter", psz_string );
831 /*****************************************************************************
832 * vout_ControlDefault: default methods for video output control.
833 *****************************************************************************/
834 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
841 if( p_vout->p_parent_intf )
843 vlc_object_release( p_vout->p_parent_intf );
844 p_vout->p_parent_intf = NULL;
850 p_vout->b_snapshot = VLC_TRUE;
855 msg_Dbg( p_vout, "control query not supported" );
860 /*****************************************************************************
861 * InitWindowSize: find the initial dimensions the video window should have.
862 *****************************************************************************
863 * This function will check the "width", "height" and "zoom" config options and
864 * will calculate the size that the video window should have.
865 *****************************************************************************/
866 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
867 unsigned *pi_height )
870 int i_width, i_height;
873 #define FP_FACTOR 1000 /* our fixed point factor */
875 var_Get( p_vout, "width", &val );
877 var_Get( p_vout, "height", &val );
878 i_height = val.i_int;
879 var_Get( p_vout, "zoom", &val );
880 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
882 if( i_width > 0 && i_height > 0)
884 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
885 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
888 else if( i_width > 0 )
890 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
891 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
892 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
893 FP_FACTOR / p_vout->fmt_in.i_visible_width );
896 else if( i_height > 0 )
898 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
899 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
900 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
901 FP_FACTOR / p_vout->fmt_in.i_visible_height );
905 if( p_vout->fmt_in.i_sar_num == 0 || p_vout->fmt_in.i_sar_den == 0 ) {
906 msg_Warn( p_vout, "fucked up aspect" );
907 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom / FP_FACTOR );
908 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom /FP_FACTOR);
910 else if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
912 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
913 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
914 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
919 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
921 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
922 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
926 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
927 p_vout->i_window_height );
932 /*****************************************************************************
933 * Object variables callbacks
934 *****************************************************************************/
935 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
936 vlc_value_t oldval, vlc_value_t newval, void *p_data )
938 vout_thread_t *p_vout = (vout_thread_t *)p_this;
939 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
940 InitWindowSize( p_vout, &p_vout->i_window_width,
941 &p_vout->i_window_height );
942 vout_Control( p_vout, VOUT_SET_SIZE, p_vout->i_window_width,
943 p_vout->i_window_height );
947 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
948 vlc_value_t oldval, vlc_value_t newval, void *p_data )
950 vout_thread_t *p_vout = (vout_thread_t *)p_this;
951 int64_t i_aspect_num, i_aspect_den;
952 unsigned int i_width, i_height;
954 (void)oldval; (void)p_data;
956 /* Restore defaults */
957 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
958 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
959 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
960 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
962 if( !strcmp( psz_cmd, "crop" ) )
964 char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
967 /* We're using the 3:4 syntax */
968 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
969 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
971 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
972 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
974 i_width = p_vout->fmt_in.i_sar_den*p_vout->fmt_render.i_visible_height *
975 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
976 i_height = p_vout->fmt_render.i_visible_width*p_vout->fmt_in.i_sar_num *
977 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
979 if( i_width < p_vout->fmt_render.i_visible_width )
981 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
982 (p_vout->fmt_render.i_visible_width - i_width) / 2;
983 p_vout->fmt_in.i_visible_width = i_width;
987 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
988 (p_vout->fmt_render.i_visible_height - i_height) / 2;
989 p_vout->fmt_in.i_visible_height = i_height;
994 psz_parser = strchr( newval.psz_string, 'x' );
997 /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
998 unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
1000 i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
1001 if( psz_end != psz_parser ) goto crop_end;
1003 psz_parser = strchr( ++psz_end, '+' );
1004 i_crop_height = strtol( psz_end, &psz_end, 10 );
1005 if( psz_end != psz_parser ) goto crop_end;
1007 psz_parser = strchr( ++psz_end, '+' );
1008 i_crop_left = strtol( psz_end, &psz_end, 10 );
1009 if( psz_end != psz_parser ) goto crop_end;
1012 i_crop_top = strtol( psz_end, &psz_end, 10 );
1013 if( *psz_end != '\0' ) goto crop_end;
1015 i_width = i_crop_width;
1016 p_vout->fmt_in.i_visible_width = i_width;
1018 i_height = i_crop_height;
1019 p_vout->fmt_in.i_visible_height = i_height;
1021 p_vout->fmt_in.i_x_offset = i_crop_left;
1022 p_vout->fmt_in.i_y_offset = i_crop_top;
1026 /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
1027 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1029 psz_parser = strchr( newval.psz_string, '+' );
1030 i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
1031 if( psz_end != psz_parser ) goto crop_end;
1033 psz_parser = strchr( ++psz_end, '+' );
1034 i_crop_top = strtol( psz_end, &psz_end, 10 );
1035 if( psz_end != psz_parser ) goto crop_end;
1037 psz_parser = strchr( ++psz_end, '+' );
1038 i_crop_right = strtol( psz_end, &psz_end, 10 );
1039 if( psz_end != psz_parser ) goto crop_end;
1042 i_crop_bottom = strtol( psz_end, &psz_end, 10 );
1043 if( *psz_end != '\0' ) goto crop_end;
1045 i_width = p_vout->fmt_render.i_visible_width
1046 - i_crop_left - i_crop_right;
1047 p_vout->fmt_in.i_visible_width = i_width;
1049 i_height = p_vout->fmt_render.i_visible_height
1050 - i_crop_top - i_crop_bottom;
1051 p_vout->fmt_in.i_visible_height = i_height;
1053 p_vout->fmt_in.i_x_offset = i_crop_left;
1054 p_vout->fmt_in.i_y_offset = i_crop_top;
1058 else if( !strcmp( psz_cmd, "crop-top" )
1059 || !strcmp( psz_cmd, "crop-left" )
1060 || !strcmp( psz_cmd, "crop-bottom" )
1061 || !strcmp( psz_cmd, "crop-right" ) )
1063 unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
1065 i_crop_top = var_GetInteger( p_vout, "crop-top" );
1066 i_crop_left = var_GetInteger( p_vout, "crop-left" );
1067 i_crop_right = var_GetInteger( p_vout, "crop-right" );
1068 i_crop_bottom = var_GetInteger( p_vout, "crop-bottom" );
1070 i_width = p_vout->fmt_render.i_visible_width
1071 - i_crop_left - i_crop_right;
1072 p_vout->fmt_in.i_visible_width = i_width;
1074 i_height = p_vout->fmt_render.i_visible_height
1075 - i_crop_top - i_crop_bottom;
1076 p_vout->fmt_in.i_visible_height = i_height;
1078 p_vout->fmt_in.i_x_offset = i_crop_left;
1079 p_vout->fmt_in.i_y_offset = i_crop_top;
1083 InitWindowSize( p_vout, &p_vout->i_window_width,
1084 &p_vout->i_window_height );
1086 p_vout->i_changes |= VOUT_CROP_CHANGE;
1088 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
1089 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
1090 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
1091 p_vout->fmt_in.i_visible_width,
1092 p_vout->fmt_in.i_visible_height );
1097 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
1098 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1100 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1101 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
1104 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
1105 (void)psz_cmd; (void)oldval; (void)p_data;
1107 /* Restore defaults */
1108 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
1109 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
1110 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
1111 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
1113 if( !psz_parser ) goto aspect_end;
1115 i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
1116 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
1118 i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
1119 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
1121 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
1122 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
1123 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
1124 p_vout->fmt_in.i_sar_num = i_sar_num;
1125 p_vout->fmt_in.i_sar_den = i_sar_den;
1126 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
1127 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1130 if( p_vout->i_par_num && p_vout->i_par_den )
1132 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
1133 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
1134 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
1135 p_vout->i_par_den / p_vout->i_par_num;
1136 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
1139 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
1141 vlc_ureduce( &i_aspect_num, &i_aspect_den,
1142 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
1143 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
1144 i_aspect_num, i_aspect_den,
1145 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
1147 var_Get( p_vout, "crop", &val );
1148 return CropCallback( p_this, "crop", val, val, 0 );
1153 static int OnTopCallback( 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;
1157 playlist_t *p_playlist = pl_Yield( p_this );
1158 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
1159 (void)psz_cmd; (void)oldval; (void)p_data;
1161 /* Modify playlist as well because the vout might have to be restarted */
1162 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
1163 var_Set( p_playlist, "video-on-top", newval );
1165 pl_Release( p_this );
1169 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
1170 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1172 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1174 playlist_t *p_playlist = pl_Yield( p_this );
1175 (void)psz_cmd; (void)oldval; (void)p_data;
1177 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1179 /* Modify playlist as well because the vout might have to be restarted */
1180 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
1181 var_Set( p_playlist, "fullscreen", newval );
1182 pl_Release( p_playlist );
1184 val.b_bool = VLC_TRUE;
1185 var_Set( p_vout, "intf-change", val );
1189 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
1190 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1192 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1193 vout_Control( p_vout, VOUT_SNAPSHOT );
1194 (void)psz_cmd; (void)oldval; (void)newval; (void)p_data;
1198 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
1199 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1201 vout_thread_t *p_vout = (vout_thread_t *)p_this;
1203 if( !strncmp( psz_cmd, "video-title-show", 16 ) )
1204 p_vout->b_title_show = newval.b_bool;
1205 else if( !strncmp( psz_cmd, "video-title-timeout", 19 ) )
1206 p_vout->i_title_timeout = (mtime_t) newval.i_int;
1207 else if( !strncmp( psz_cmd, "video-title-position", 20 ) )
1208 p_vout->i_title_position = newval.i_int;