1 /*****************************************************************************
2 * vout_intf.c : video output interface
3 *****************************************************************************
4 * Copyright (C) 2000-2004 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* free() */
32 #include "vlc_video.h"
33 #include "video_output.h"
34 #include "vlc_image.h"
37 /*****************************************************************************
39 *****************************************************************************/
40 static void InitWindowSize( vout_thread_t *, unsigned *, unsigned * );
42 /* Object variables callbacks */
43 static int ZoomCallback( vlc_object_t *, char const *,
44 vlc_value_t, vlc_value_t, void * );
45 static int CropCallback( vlc_object_t *, char const *,
46 vlc_value_t, vlc_value_t, void * );
47 static int AspectCallback( vlc_object_t *, char const *,
48 vlc_value_t, vlc_value_t, void * );
49 static int OnTopCallback( vlc_object_t *, char const *,
50 vlc_value_t, vlc_value_t, void * );
51 static int FullscreenCallback( vlc_object_t *, char const *,
52 vlc_value_t, vlc_value_t, void * );
53 static int SnapshotCallback( vlc_object_t *, char const *,
54 vlc_value_t, vlc_value_t, void * );
56 /*****************************************************************************
57 * vout_RequestWindow: Create/Get a video window if possible.
58 *****************************************************************************
59 * This function looks for the main interface and tries to request
60 * a new video window. If it fails then the vout will still need to create the
62 *****************************************************************************/
63 void *vout_RequestWindow( vout_thread_t *p_vout,
64 int *pi_x_hint, int *pi_y_hint,
65 unsigned int *pi_width_hint,
66 unsigned int *pi_height_hint )
68 intf_thread_t *p_intf = NULL;
75 if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
77 /* Get requested coordinates */
78 var_Get( p_vout, "video-x", &val );
79 *pi_x_hint = val.i_int ;
80 var_Get( p_vout, "video-y", &val );
81 *pi_y_hint = val.i_int;
83 *pi_width_hint = p_vout->i_window_width;
84 *pi_height_hint = p_vout->i_window_height;
86 /* Check whether someone provided us with a window ID */
87 var_Get( p_vout->p_vlc, "drawable", &val );
88 if( val.i_int ) return (void *)val.i_int;
90 /* Find if the main interface supports embedding */
91 p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
92 if( !p_list ) return NULL;
94 for( i = 0; i < p_list->i_count; i++ )
96 p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
97 if( p_intf->b_block && p_intf->pf_request_window ) break;
103 vlc_list_release( p_list );
107 vlc_object_yield( p_intf );
108 vlc_list_release( p_list );
110 p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
111 pi_width_hint, pi_height_hint );
113 if( !p_window ) vlc_object_release( p_intf );
114 else p_vout->p_parent_intf = p_intf;
119 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
121 intf_thread_t *p_intf = p_vout->p_parent_intf;
123 if( !p_intf ) return;
125 vlc_mutex_lock( &p_intf->object_lock );
128 vlc_mutex_unlock( &p_intf->object_lock );
132 if( !p_intf->pf_release_window )
134 msg_Err( p_vout, "no pf_release_window");
135 vlc_mutex_unlock( &p_intf->object_lock );
136 vlc_object_release( p_intf );
140 p_intf->pf_release_window( p_intf, p_window );
142 p_vout->p_parent_intf = NULL;
143 vlc_mutex_unlock( &p_intf->object_lock );
144 vlc_object_release( p_intf );
147 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
148 int i_query, va_list args )
150 intf_thread_t *p_intf = p_vout->p_parent_intf;
153 if( !p_intf ) return VLC_EGENERIC;
155 vlc_mutex_lock( &p_intf->object_lock );
158 vlc_mutex_unlock( &p_intf->object_lock );
162 if( !p_intf->pf_control_window )
164 msg_Err( p_vout, "no pf_control_window");
165 vlc_mutex_unlock( &p_intf->object_lock );
169 i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
170 vlc_mutex_unlock( &p_intf->object_lock );
174 /*****************************************************************************
175 * vout_IntfInit: called during the vout creation to initialise misc things.
176 *****************************************************************************/
177 void vout_IntfInit( vout_thread_t *p_vout )
179 vlc_value_t val, text, old_val;
180 vlc_bool_t b_force_par = VLC_FALSE;
182 /* Create a few object variables we'll need later on */
183 var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
184 var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
185 var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
186 var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
187 var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
188 var_Get( p_vout, "align", &val );
189 p_vout->i_alignment = val.i_int;
191 var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
192 var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
194 /* Zoom object var */
195 var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
196 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
198 text.psz_string = _("Zoom");
199 var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
201 var_Get( p_vout, "zoom", &old_val );
202 if( old_val.f_float == 0.25 ||
203 old_val.f_float == 0.5 ||
204 old_val.f_float == 1 ||
205 old_val.f_float == 2 )
207 var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
210 val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
211 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
212 val.f_float = 0.5; text.psz_string = _("1:2 Half");
213 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
214 val.f_float = 1; text.psz_string = _("1:1 Original");
215 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
216 val.f_float = 2; text.psz_string = _("2:1 Double");
217 var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
219 var_Set( p_vout, "zoom", old_val );
221 var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
223 /* Crop object var */
224 var_Create( p_vout, "crop", VLC_VAR_STRING |
225 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
227 text.psz_string = _("Crop");
228 var_Change( p_vout, "crop", VLC_VAR_SETTEXT, &text, NULL );
231 var_Change( p_vout, "crop", VLC_VAR_DELCHOICE, &val, 0 );
232 val.psz_string = ""; text.psz_string = _("Default");
233 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
234 val.psz_string = "001:1"; text.psz_string = _("1:1");
235 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
236 val.psz_string = "004:3"; text.psz_string = _("4:3");
237 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
238 val.psz_string = "16:9"; text.psz_string = _("16:9");
239 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
240 val.psz_string = "221:100"; text.psz_string = _("221:100");
241 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
243 var_AddCallback( p_vout, "crop", CropCallback, NULL );
244 var_Get( p_vout, "crop", &old_val );
245 if( old_val.psz_string && *old_val.psz_string )
246 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
247 if( old_val.psz_string ) free( old_val.psz_string );
249 /* Monitor pixel aspect-ratio */
250 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
251 var_Get( p_vout, "monitor-par", &val );
252 if( val.psz_string && *val.psz_string )
254 char *psz_parser = strchr( val.psz_string, ':' );
255 unsigned int i_aspect_num = 0, i_aspect_den = 0;
259 i_aspect_num = strtol( val.psz_string, 0, 0 );
260 i_aspect_den = strtol( ++psz_parser, 0, 0 );
264 i_aspect = atof( val.psz_string );
265 vlc_ureduce( &i_aspect_num, &i_aspect_den,
266 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
268 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
270 p_vout->i_par_num = i_aspect_num;
271 p_vout->i_par_den = i_aspect_den;
273 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
274 p_vout->i_par_num, p_vout->i_par_den, 0 );
276 msg_Dbg( p_vout, "monitor pixel aspect-ratio overriding: %i:%i",
277 p_vout->i_par_num, p_vout->i_par_den );
278 b_force_par = VLC_TRUE;
280 if( val.psz_string ) free( val.psz_string );
282 /* Aspect-ratio object var */
283 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
284 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
286 text.psz_string = _("Aspect-ratio");
287 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
290 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
291 val.psz_string = ""; text.psz_string = _("Default");
292 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
293 val.psz_string = "001:1"; text.psz_string = _("1:1");
294 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
295 val.psz_string = "004:3"; text.psz_string = _("4:3");
296 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
297 val.psz_string = "16:9"; text.psz_string = _("16:9");
298 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
299 val.psz_string = "221:100"; text.psz_string = _("221:100");
300 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
302 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
303 var_Get( p_vout, "aspect-ratio", &old_val );
304 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
305 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
306 if( old_val.psz_string ) free( old_val.psz_string );
308 /* Initialize the dimensions of the video window */
309 InitWindowSize( p_vout, &p_vout->i_window_width,
310 &p_vout->i_window_height );
312 /* Add a variable to indicate if the window should be on top of others */
313 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
314 text.psz_string = _("Always on top");
315 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
316 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
318 /* Add a variable to indicate whether we want window decoration or not */
319 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
321 /* Add a fullscreen variable */
322 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
323 text.psz_string = _("Fullscreen");
324 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
325 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
328 /* user requested fullscreen */
329 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
331 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
333 /* Add a snapshot variable */
334 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
335 text.psz_string = _("Snapshot");
336 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
337 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
339 /* Mouse coordinates */
340 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
341 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
342 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
343 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
344 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
346 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
347 val.b_bool = VLC_TRUE;
348 var_Set( p_vout, "intf-change", val );
351 /*****************************************************************************
352 * vout_Snapshot: generates a snapshot.
353 *****************************************************************************/
354 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
356 image_handler_t *p_image = image_HandlerCreate( p_vout );
357 video_format_t fmt_in = {0}, fmt_out = {0};
359 subpicture_t *p_subpic;
361 vlc_value_t val, format;
364 var_Get( p_vout, "snapshot-path", &val );
365 if( val.psz_string && !*val.psz_string )
367 free( val.psz_string );
371 #if defined(SYS_DARWIN) || defined(SYS_BEOS)
372 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
374 asprintf( &val.psz_string, "%s/Desktop",
375 p_vout->p_vlc->psz_homedir );
378 #elif defined(WIN32) && !defined(UNDER_CE)
379 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
381 /* Get the My Pictures folder path */
383 char *p_mypicturesdir = NULL;
384 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
386 #ifndef CSIDL_FLAG_CREATE
387 # define CSIDL_FLAG_CREATE 0x8000
389 #ifndef CSIDL_MYPICTURES
390 # define CSIDL_MYPICTURES 0x27
392 #ifndef SHGFP_TYPE_CURRENT
393 # define SHGFP_TYPE_CURRENT 0
396 HINSTANCE shfolder_dll;
397 SHGETFOLDERPATH SHGetFolderPath ;
399 /* load the shfolder dll to retrieve SHGetFolderPath */
400 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
402 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
403 _T("SHGetFolderPathA") );
404 if( SHGetFolderPath != NULL )
406 p_mypicturesdir = (char *)malloc( MAX_PATH );
407 if( p_mypicturesdir )
410 if( S_OK != SHGetFolderPath( NULL,
411 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
412 NULL, SHGFP_TYPE_CURRENT,
415 free( p_mypicturesdir );
416 p_mypicturesdir = NULL;
420 FreeLibrary( shfolder_dll );
423 if( p_mypicturesdir == NULL )
425 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
426 p_vout->p_vlc->psz_homedir );
430 asprintf( &val.psz_string, p_mypicturesdir );
431 free( p_mypicturesdir );
436 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
438 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
439 p_vout->p_vlc->psz_homedir );
443 if( !val.psz_string )
445 msg_Err( p_vout, "no directory specified for snapshots" );
448 var_Get( p_vout, "snapshot-format", &format );
449 if( !format.psz_string || !*format.psz_string )
451 if( format.psz_string ) free( format.psz_string );
452 format.psz_string = strdup( "png" );
455 asprintf( &psz_filename, "%s/vlcsnap-%u.%s", val.psz_string,
456 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
458 free( val.psz_string );
459 free( format.psz_string );
461 /* Save the snapshot */
462 fmt_in = p_vout->fmt_in;
463 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
464 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
465 if( i_ret != VLC_SUCCESS )
467 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
468 free( psz_filename );
469 image_HandlerDelete( p_image );
473 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
474 free( psz_filename );
476 /* Inject a subpicture with the snapshot */
477 memset( &fmt_out, 0, sizeof(fmt_out) );
478 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
479 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
480 image_HandlerDelete( p_image );
481 if( !p_pif ) return VLC_EGENERIC;
483 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
484 if( p_subpic == NULL )
486 p_pif->pf_release( p_pif );
490 p_subpic->i_channel = 0;
491 p_subpic->i_start = mdate();
492 p_subpic->i_stop = mdate() + 4000000;
493 p_subpic->b_ephemer = VLC_TRUE;
494 p_subpic->b_fade = VLC_TRUE;
495 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
496 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
498 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
499 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture, p_pif );
500 p_pif->pf_release( p_pif );
502 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
507 /*****************************************************************************
508 * vout_ControlDefault: default methods for video output control.
509 *****************************************************************************/
510 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
516 if( p_vout->p_parent_intf )
518 vlc_object_release( p_vout->p_parent_intf );
519 p_vout->p_parent_intf = NULL;
525 p_vout->b_snapshot = VLC_TRUE;
530 msg_Dbg( p_vout, "control query not supported" );
535 /*****************************************************************************
536 * InitWindowSize: find the initial dimensions the video window should have.
537 *****************************************************************************
538 * This function will check the "width", "height" and "zoom" config options and
539 * will calculate the size that the video window should have.
540 *****************************************************************************/
541 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
542 unsigned *pi_height )
545 int i_width, i_height;
548 #define FP_FACTOR 1000 /* our fixed point factor */
550 var_Get( p_vout, "width", &val );
552 var_Get( p_vout, "height", &val );
553 i_height = val.i_int;
554 var_Get( p_vout, "zoom", &val );
555 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
557 if( i_width > 0 && i_height > 0)
559 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
560 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
563 else if( i_width > 0 )
565 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
566 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
567 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
568 FP_FACTOR / p_vout->fmt_in.i_visible_width );
571 else if( i_height > 0 )
573 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
574 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
575 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
576 FP_FACTOR / p_vout->fmt_in.i_visible_height );
580 if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
582 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
583 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
584 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
589 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
591 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
592 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
596 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
597 p_vout->i_window_height );
602 /*****************************************************************************
603 * Object variables callbacks
604 *****************************************************************************/
605 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
606 vlc_value_t oldval, vlc_value_t newval, void *p_data )
608 vout_thread_t *p_vout = (vout_thread_t *)p_this;
609 InitWindowSize( p_vout, &p_vout->i_window_width,
610 &p_vout->i_window_height );
611 vout_Control( p_vout, VOUT_SET_ZOOM );
615 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
616 vlc_value_t oldval, vlc_value_t newval, void *p_data )
618 vout_thread_t *p_vout = (vout_thread_t *)p_this;
619 int64_t i_aspect_num, i_aspect_den;
620 unsigned int i_width, i_height;
622 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
624 /* Restore defaults */
625 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
626 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
627 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
628 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
630 if( !psz_parser ) goto crop_end;
632 i_aspect_num = strtol( newval.psz_string, &psz_end, 0 );
633 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
635 i_aspect_den = strtol( ++psz_parser, &psz_end, 0 );
636 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
638 i_width = p_vout->fmt_in.i_sar_den * p_vout->fmt_render.i_visible_height *
639 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
640 i_height = p_vout->fmt_render.i_visible_width * p_vout->fmt_in.i_sar_num *
641 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
643 if( i_width < p_vout->fmt_render.i_visible_width )
645 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
646 (p_vout->fmt_render.i_visible_width - i_width) / 2;
647 p_vout->fmt_in.i_visible_width = i_width;
651 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
652 (p_vout->fmt_render.i_visible_height - i_height) / 2;
653 p_vout->fmt_in.i_visible_height = i_height;
657 InitWindowSize( p_vout, &p_vout->i_window_width,
658 &p_vout->i_window_height );
660 p_vout->i_changes |= VOUT_CROP_CHANGE;
662 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
663 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
664 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
665 p_vout->fmt_in.i_visible_width,
666 p_vout->fmt_in.i_visible_height );
671 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
672 vlc_value_t oldval, vlc_value_t newval, void *p_data )
674 vout_thread_t *p_vout = (vout_thread_t *)p_this;
675 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
678 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
680 /* Restore defaults */
681 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
682 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
683 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
684 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
686 if( !psz_parser ) goto aspect_end;
688 i_aspect_num = strtol( newval.psz_string, &psz_end, 0 );
689 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
691 i_aspect_den = strtol( ++psz_parser, &psz_end, 0 );
692 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
694 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
695 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
696 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
697 p_vout->fmt_in.i_sar_num = i_sar_num;
698 p_vout->fmt_in.i_sar_den = i_sar_den;
699 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
700 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
703 if( p_vout->i_par_num && p_vout->i_par_den )
705 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
706 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
707 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
708 p_vout->i_par_den / p_vout->i_par_num;
709 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
712 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
714 vlc_ureduce( &i_aspect_num, &i_aspect_den,
715 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
716 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
717 i_aspect_num, i_aspect_den,
718 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
720 var_Get( p_vout, "crop", &val );
721 return CropCallback( p_this, 0, val, val, 0 );
726 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
727 vlc_value_t oldval, vlc_value_t newval, void *p_data )
729 vout_thread_t *p_vout = (vout_thread_t *)p_this;
730 playlist_t *p_playlist;
731 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
733 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
737 /* Modify playlist as well because the vout might have to be restarted */
738 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
739 var_Set( p_playlist, "video-on-top", newval );
741 vlc_object_release( p_playlist );
746 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
747 vlc_value_t oldval, vlc_value_t newval, void *p_data )
749 vout_thread_t *p_vout = (vout_thread_t *)p_this;
750 playlist_t *p_playlist;
753 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
755 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
759 /* Modify playlist as well because the vout might have to be restarted */
760 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
761 var_Set( p_playlist, "fullscreen", newval );
763 vlc_object_release( p_playlist );
766 /* Disable "always on top" in fullscreen mode */
767 var_Get( p_vout, "video-on-top", &val );
768 if( newval.b_bool && val.b_bool )
770 val.b_bool = VLC_FALSE;
771 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
773 else if( !newval.b_bool && val.b_bool )
775 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
778 val.b_bool = VLC_TRUE;
779 var_Set( p_vout, "intf-change", val );
783 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
784 vlc_value_t oldval, vlc_value_t newval, void *p_data )
786 vout_thread_t *p_vout = (vout_thread_t *)p_this;
787 vout_Control( p_vout, VOUT_SNAPSHOT );