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:10"; text.psz_string = "16:10";
239 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
240 val.psz_string = "16:9"; text.psz_string = "16:9";
241 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
242 val.psz_string = "221:100"; text.psz_string = "221:100";
243 var_Change( p_vout, "crop", VLC_VAR_ADDCHOICE, &val, &text );
245 var_AddCallback( p_vout, "crop", CropCallback, NULL );
246 var_Get( p_vout, "crop", &old_val );
247 if( old_val.psz_string && *old_val.psz_string )
248 var_Change( p_vout, "crop", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
249 if( old_val.psz_string ) free( old_val.psz_string );
251 /* Monitor pixel aspect-ratio */
252 var_Create( p_vout, "monitor-par", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
253 var_Get( p_vout, "monitor-par", &val );
254 if( val.psz_string && *val.psz_string )
256 char *psz_parser = strchr( val.psz_string, ':' );
257 unsigned int i_aspect_num = 0, i_aspect_den = 0;
261 i_aspect_num = strtol( val.psz_string, 0, 0 );
262 i_aspect_den = strtol( ++psz_parser, 0, 0 );
266 i_aspect = atof( val.psz_string );
267 vlc_ureduce( &i_aspect_num, &i_aspect_den,
268 i_aspect *VOUT_ASPECT_FACTOR, VOUT_ASPECT_FACTOR, 0 );
270 if( !i_aspect_num || !i_aspect_den ) i_aspect_num = i_aspect_den = 1;
272 p_vout->i_par_num = i_aspect_num;
273 p_vout->i_par_den = i_aspect_den;
275 vlc_ureduce( &p_vout->i_par_num, &p_vout->i_par_den,
276 p_vout->i_par_num, p_vout->i_par_den, 0 );
278 msg_Dbg( p_vout, "monitor pixel aspect-ratio overriding: %i:%i",
279 p_vout->i_par_num, p_vout->i_par_den );
280 b_force_par = VLC_TRUE;
282 if( val.psz_string ) free( val.psz_string );
284 /* Aspect-ratio object var */
285 var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING |
286 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
288 text.psz_string = _("Aspect-ratio");
289 var_Change( p_vout, "aspect-ratio", VLC_VAR_SETTEXT, &text, NULL );
292 var_Change( p_vout, "aspect-ratio", VLC_VAR_DELCHOICE, &val, 0 );
293 val.psz_string = ""; text.psz_string = _("Default");
294 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
295 val.psz_string = "001:1"; text.psz_string = "1:1";
296 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
297 val.psz_string = "004:3"; text.psz_string = "4:3";
298 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
299 val.psz_string = "16:9"; text.psz_string = "16:9";
300 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
301 val.psz_string = "221:100"; text.psz_string = "221:100";
302 var_Change( p_vout, "aspect-ratio", VLC_VAR_ADDCHOICE, &val, &text );
304 var_AddCallback( p_vout, "aspect-ratio", AspectCallback, NULL );
305 var_Get( p_vout, "aspect-ratio", &old_val );
306 if( (old_val.psz_string && *old_val.psz_string) || b_force_par )
307 var_Change( p_vout, "aspect-ratio", VLC_VAR_TRIGGER_CALLBACKS, 0, 0 );
308 if( old_val.psz_string ) free( old_val.psz_string );
310 /* Initialize the dimensions of the video window */
311 InitWindowSize( p_vout, &p_vout->i_window_width,
312 &p_vout->i_window_height );
314 /* Add a variable to indicate if the window should be on top of others */
315 var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
316 text.psz_string = _("Always on top");
317 var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
318 var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
320 /* Add a variable to indicate whether we want window decoration or not */
321 var_Create( p_vout, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
323 /* Add a fullscreen variable */
324 var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
325 text.psz_string = _("Fullscreen");
326 var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
327 var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
330 /* user requested fullscreen */
331 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
333 var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
335 /* Add a snapshot variable */
336 var_Create( p_vout, "video-snapshot", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
337 text.psz_string = _("Snapshot");
338 var_Change( p_vout, "video-snapshot", VLC_VAR_SETTEXT, &text, NULL );
339 var_AddCallback( p_vout, "video-snapshot", SnapshotCallback, NULL );
341 /* Mouse coordinates */
342 var_Create( p_vout, "mouse-x", VLC_VAR_INTEGER );
343 var_Create( p_vout, "mouse-y", VLC_VAR_INTEGER );
344 var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
345 var_Create( p_vout, "mouse-moved", VLC_VAR_BOOL );
346 var_Create( p_vout, "mouse-clicked", VLC_VAR_INTEGER );
348 var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
349 val.b_bool = VLC_TRUE;
350 var_Set( p_vout, "intf-change", val );
353 /*****************************************************************************
354 * vout_Snapshot: generates a snapshot.
355 *****************************************************************************/
356 int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic )
358 image_handler_t *p_image = image_HandlerCreate( p_vout );
359 video_format_t fmt_in = {0}, fmt_out = {0};
361 subpicture_t *p_subpic;
363 vlc_value_t val, format;
366 var_Get( p_vout, "snapshot-path", &val );
367 if( val.psz_string && !*val.psz_string )
369 free( val.psz_string );
373 #if defined(SYS_DARWIN) || defined(SYS_BEOS)
374 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
376 asprintf( &val.psz_string, "%s/Desktop",
377 p_vout->p_vlc->psz_homedir );
380 #elif defined(WIN32) && !defined(UNDER_CE)
381 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
383 /* Get the My Pictures folder path */
385 char *p_mypicturesdir = NULL;
386 typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
388 #ifndef CSIDL_FLAG_CREATE
389 # define CSIDL_FLAG_CREATE 0x8000
391 #ifndef CSIDL_MYPICTURES
392 # define CSIDL_MYPICTURES 0x27
394 #ifndef SHGFP_TYPE_CURRENT
395 # define SHGFP_TYPE_CURRENT 0
398 HINSTANCE shfolder_dll;
399 SHGETFOLDERPATH SHGetFolderPath ;
401 /* load the shfolder dll to retrieve SHGetFolderPath */
402 if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
404 SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
405 _T("SHGetFolderPathA") );
406 if( SHGetFolderPath != NULL )
408 p_mypicturesdir = (char *)malloc( MAX_PATH );
409 if( p_mypicturesdir )
412 if( S_OK != SHGetFolderPath( NULL,
413 CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
414 NULL, SHGFP_TYPE_CURRENT,
417 free( p_mypicturesdir );
418 p_mypicturesdir = NULL;
422 FreeLibrary( shfolder_dll );
425 if( p_mypicturesdir == NULL )
427 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
428 p_vout->p_vlc->psz_homedir );
432 asprintf( &val.psz_string, p_mypicturesdir );
433 free( p_mypicturesdir );
438 if( !val.psz_string && p_vout->p_vlc->psz_homedir )
440 asprintf( &val.psz_string, "%s/" CONFIG_DIR,
441 p_vout->p_vlc->psz_homedir );
445 if( !val.psz_string )
447 msg_Err( p_vout, "no directory specified for snapshots" );
450 var_Get( p_vout, "snapshot-format", &format );
451 if( !format.psz_string || !*format.psz_string )
453 if( format.psz_string ) free( format.psz_string );
454 format.psz_string = strdup( "png" );
457 asprintf( &psz_filename, "%s/vlcsnap-%u.%s", val.psz_string,
458 (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
460 free( val.psz_string );
461 free( format.psz_string );
463 /* Save the snapshot */
464 fmt_in = p_vout->fmt_in;
465 fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
466 i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename );
467 if( i_ret != VLC_SUCCESS )
469 msg_Err( p_vout, "could not create snapshot %s", psz_filename );
470 free( psz_filename );
471 image_HandlerDelete( p_image );
475 msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
476 free( psz_filename );
478 /* Inject a subpicture with the snapshot */
479 memset( &fmt_out, 0, sizeof(fmt_out) );
480 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
481 p_pif = image_Convert( p_image, p_pic, &fmt_in, &fmt_out );
482 image_HandlerDelete( p_image );
483 if( !p_pif ) return VLC_EGENERIC;
485 p_subpic = spu_CreateSubpicture( p_vout->p_spu );
486 if( p_subpic == NULL )
488 p_pif->pf_release( p_pif );
492 p_subpic->i_channel = 0;
493 p_subpic->i_start = mdate();
494 p_subpic->i_stop = mdate() + 4000000;
495 p_subpic->b_ephemer = VLC_TRUE;
496 p_subpic->b_fade = VLC_TRUE;
497 p_subpic->i_original_picture_width = p_vout->render.i_width * 4;
498 p_subpic->i_original_picture_height = p_vout->render.i_height * 4;
500 p_subpic->p_region = spu_CreateRegion( p_vout->p_spu, &fmt_out );
501 vout_CopyPicture( p_image->p_parent, &p_subpic->p_region->picture, p_pif );
502 p_pif->pf_release( p_pif );
504 spu_DisplaySubpicture( p_vout->p_spu, p_subpic );
509 /*****************************************************************************
510 * vout_ControlDefault: default methods for video output control.
511 *****************************************************************************/
512 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
518 if( p_vout->p_parent_intf )
520 vlc_object_release( p_vout->p_parent_intf );
521 p_vout->p_parent_intf = NULL;
527 p_vout->b_snapshot = VLC_TRUE;
532 msg_Dbg( p_vout, "control query not supported" );
537 /*****************************************************************************
538 * InitWindowSize: find the initial dimensions the video window should have.
539 *****************************************************************************
540 * This function will check the "width", "height" and "zoom" config options and
541 * will calculate the size that the video window should have.
542 *****************************************************************************/
543 static void InitWindowSize( vout_thread_t *p_vout, unsigned *pi_width,
544 unsigned *pi_height )
547 int i_width, i_height;
550 #define FP_FACTOR 1000 /* our fixed point factor */
552 var_Get( p_vout, "width", &val );
554 var_Get( p_vout, "height", &val );
555 i_height = val.i_int;
556 var_Get( p_vout, "zoom", &val );
557 ll_zoom = (uint64_t)( FP_FACTOR * val.f_float );
559 if( i_width > 0 && i_height > 0)
561 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
562 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
565 else if( i_width > 0 )
567 *pi_width = (int)( i_width * ll_zoom / FP_FACTOR );
568 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
569 p_vout->fmt_in.i_sar_den * i_width / p_vout->fmt_in.i_sar_num /
570 FP_FACTOR / p_vout->fmt_in.i_visible_width );
573 else if( i_height > 0 )
575 *pi_height = (int)( i_height * ll_zoom / FP_FACTOR );
576 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
577 p_vout->fmt_in.i_sar_num * i_height / p_vout->fmt_in.i_sar_den /
578 FP_FACTOR / p_vout->fmt_in.i_visible_height );
582 if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
584 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom *
585 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den / FP_FACTOR );
586 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom
591 *pi_width = (int)( p_vout->fmt_in.i_visible_width * ll_zoom
593 *pi_height = (int)( p_vout->fmt_in.i_visible_height * ll_zoom *
594 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num / FP_FACTOR );
598 msg_Dbg( p_vout, "window size: %dx%d", p_vout->i_window_width,
599 p_vout->i_window_height );
604 /*****************************************************************************
605 * Object variables callbacks
606 *****************************************************************************/
607 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
608 vlc_value_t oldval, vlc_value_t newval, void *p_data )
610 vout_thread_t *p_vout = (vout_thread_t *)p_this;
611 InitWindowSize( p_vout, &p_vout->i_window_width,
612 &p_vout->i_window_height );
613 vout_Control( p_vout, VOUT_SET_SIZE, 0, 0 );
617 static int CropCallback( vlc_object_t *p_this, char const *psz_cmd,
618 vlc_value_t oldval, vlc_value_t newval, void *p_data )
620 vout_thread_t *p_vout = (vout_thread_t *)p_this;
621 int64_t i_aspect_num, i_aspect_den;
622 unsigned int i_width, i_height;
624 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
626 /* Restore defaults */
627 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset;
628 p_vout->fmt_in.i_visible_width = p_vout->fmt_render.i_visible_width;
629 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset;
630 p_vout->fmt_in.i_visible_height = p_vout->fmt_render.i_visible_height;
632 if( !psz_parser ) goto crop_end;
634 i_aspect_num = strtol( newval.psz_string, &psz_end, 0 );
635 if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
637 i_aspect_den = strtol( ++psz_parser, &psz_end, 0 );
638 if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
640 i_width = p_vout->fmt_in.i_sar_den * p_vout->fmt_render.i_visible_height *
641 i_aspect_num / i_aspect_den / p_vout->fmt_in.i_sar_num;
642 i_height = p_vout->fmt_render.i_visible_width * p_vout->fmt_in.i_sar_num *
643 i_aspect_den / i_aspect_num / p_vout->fmt_in.i_sar_den;
645 if( i_width < p_vout->fmt_render.i_visible_width )
647 p_vout->fmt_in.i_x_offset = p_vout->fmt_render.i_x_offset +
648 (p_vout->fmt_render.i_visible_width - i_width) / 2;
649 p_vout->fmt_in.i_visible_width = i_width;
653 p_vout->fmt_in.i_y_offset = p_vout->fmt_render.i_y_offset +
654 (p_vout->fmt_render.i_visible_height - i_height) / 2;
655 p_vout->fmt_in.i_visible_height = i_height;
659 InitWindowSize( p_vout, &p_vout->i_window_width,
660 &p_vout->i_window_height );
662 p_vout->i_changes |= VOUT_CROP_CHANGE;
664 msg_Dbg( p_vout, "cropping picture %ix%i to %i,%i,%ix%i",
665 p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
666 p_vout->fmt_in.i_x_offset, p_vout->fmt_in.i_y_offset,
667 p_vout->fmt_in.i_visible_width,
668 p_vout->fmt_in.i_visible_height );
673 static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
674 vlc_value_t oldval, vlc_value_t newval, void *p_data )
676 vout_thread_t *p_vout = (vout_thread_t *)p_this;
677 unsigned int i_aspect_num, i_aspect_den, i_sar_num, i_sar_den;
680 char *psz_end, *psz_parser = strchr( newval.psz_string, ':' );
682 /* Restore defaults */
683 p_vout->fmt_in.i_sar_num = p_vout->fmt_render.i_sar_num;
684 p_vout->fmt_in.i_sar_den = p_vout->fmt_render.i_sar_den;
685 p_vout->fmt_in.i_aspect = p_vout->fmt_render.i_aspect;
686 p_vout->render.i_aspect = p_vout->fmt_render.i_aspect;
688 if( !psz_parser ) goto aspect_end;
690 i_aspect_num = strtol( newval.psz_string, &psz_end, 0 );
691 if( psz_end == newval.psz_string || !i_aspect_num ) goto aspect_end;
693 i_aspect_den = strtol( ++psz_parser, &psz_end, 0 );
694 if( psz_end == psz_parser || !i_aspect_den ) goto aspect_end;
696 i_sar_num = i_aspect_num * p_vout->fmt_render.i_visible_height;
697 i_sar_den = i_aspect_den * p_vout->fmt_render.i_visible_width;
698 vlc_ureduce( &i_sar_num, &i_sar_den, i_sar_num, i_sar_den, 0 );
699 p_vout->fmt_in.i_sar_num = i_sar_num;
700 p_vout->fmt_in.i_sar_den = i_sar_den;
701 p_vout->fmt_in.i_aspect = i_aspect_num * VOUT_ASPECT_FACTOR / i_aspect_den;
702 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
705 if( p_vout->i_par_num && p_vout->i_par_den )
707 p_vout->fmt_in.i_sar_num *= p_vout->i_par_den;
708 p_vout->fmt_in.i_sar_den *= p_vout->i_par_num;
709 p_vout->fmt_in.i_aspect = p_vout->fmt_in.i_aspect *
710 p_vout->i_par_den / p_vout->i_par_num;
711 p_vout->render.i_aspect = p_vout->fmt_in.i_aspect;
714 p_vout->i_changes |= VOUT_ASPECT_CHANGE;
716 vlc_ureduce( &i_aspect_num, &i_aspect_den,
717 p_vout->fmt_in.i_aspect, VOUT_ASPECT_FACTOR, 0 );
718 msg_Dbg( p_vout, "new aspect-ratio %i:%i, sample aspect-ratio %i:%i",
719 i_aspect_num, i_aspect_den,
720 p_vout->fmt_in.i_sar_num, p_vout->fmt_in.i_sar_den );
722 var_Get( p_vout, "crop", &val );
723 return CropCallback( p_this, 0, val, val, 0 );
728 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
729 vlc_value_t oldval, vlc_value_t newval, void *p_data )
731 vout_thread_t *p_vout = (vout_thread_t *)p_this;
732 playlist_t *p_playlist;
733 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
735 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
739 /* Modify playlist as well because the vout might have to be restarted */
740 var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
741 var_Set( p_playlist, "video-on-top", newval );
743 vlc_object_release( p_playlist );
748 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
749 vlc_value_t oldval, vlc_value_t newval, void *p_data )
751 vout_thread_t *p_vout = (vout_thread_t *)p_this;
752 playlist_t *p_playlist;
755 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
757 p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
761 /* Modify playlist as well because the vout might have to be restarted */
762 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
763 var_Set( p_playlist, "fullscreen", newval );
765 vlc_object_release( p_playlist );
768 /* Disable "always on top" in fullscreen mode */
769 var_Get( p_vout, "video-on-top", &val );
770 if( newval.b_bool && val.b_bool )
772 val.b_bool = VLC_FALSE;
773 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
775 else if( !newval.b_bool && val.b_bool )
777 vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
780 val.b_bool = VLC_TRUE;
781 var_Set( p_vout, "intf-change", val );
785 static int SnapshotCallback( vlc_object_t *p_this, char const *psz_cmd,
786 vlc_value_t oldval, vlc_value_t newval, void *p_data )
788 vout_thread_t *p_vout = (vout_thread_t *)p_this;
789 vout_Control( p_vout, VOUT_SNAPSHOT );