1 /*****************************************************************************
2 * vout_sdl.c: SDL video output display method
3 *****************************************************************************
4 * Copyright (C) 1998, 1999, 2000 VideoLAN
5 * $Id: vout_sdl.c,v 1.62 2001/08/06 20:45:55 gbazin Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Pierre Baillet <oct@zoy.org>
9 * Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 #define MODULE_NAME sdl
27 #include "modules_inner.h"
29 /*****************************************************************************
31 *****************************************************************************/
34 #include <errno.h> /* ENOMEM */
35 #include <stdlib.h> /* free() */
36 #include <string.h> /* strerror() */
38 #include <sys/types.h>
40 # include <netinet/in.h> /* BSD: struct in_addr */
43 #include SDL_INCLUDE_FILE
52 #include "video_output.h"
55 #include "interface.h"
56 /* FIXME: get rid of this */
57 #include "keystrokes.h"
62 #include "modules_export.h"
64 /*****************************************************************************
65 * FIXME: this file is ... *
67 * XXX XXX FIXME XXX XXX XXX XXX *
68 * XXX XXX XXX XXX XXX XXX XXX XXX *
69 * XXX XXX XXX XXX FIXME XXX *
70 * XXX XXX XXX TODO XXX XXX XXX *
71 * XXX XXX XXX XXX XXX XXX *
72 * FIXME FIXME FIXME XXX XXX *
74 *****************************************************************************/
76 /*****************************************************************************
77 * vout_sys_t: video output SDL method descriptor
78 *****************************************************************************
79 * This structure is part of the video output thread descriptor.
80 * It describes the SDL specific properties of an output thread.
81 *****************************************************************************/
82 typedef struct vout_sys_s
87 SDL_Surface * p_display; /* display device */
88 SDL_Overlay * p_overlay; /* overlay device */
92 boolean_t b_reopen_display;
94 boolean_t b_cursor_autohidden;
97 Uint8 * p_sdl_buf[2]; /* Buffer information */
101 /*****************************************************************************
103 *****************************************************************************/
104 static int vout_Probe ( probedata_t *p_data );
105 static int vout_Create ( struct vout_thread_s * );
106 static int vout_Init ( struct vout_thread_s * );
107 static void vout_End ( struct vout_thread_s * );
108 static void vout_Destroy ( struct vout_thread_s * );
109 static int vout_Manage ( struct vout_thread_s * );
110 static void vout_Display ( struct vout_thread_s * );
111 static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
112 u16 *blue, u16 *transp );
114 static int SDLOpenDisplay ( vout_thread_t *p_vout );
115 static void SDLCloseDisplay ( vout_thread_t *p_vout );
116 static void OutputCoords ( const picture_t *p_pic, const boolean_t scale,
117 const int win_w, const int win_h,
118 int *dx, int *dy, int *w, int *h );
120 /*****************************************************************************
121 * Functions exported as capabilities. They are declared as static so that
122 * we don't pollute the namespace too much.
123 *****************************************************************************/
124 void _M( vout_getfunctions )( function_list_t * p_function_list )
126 p_function_list->pf_probe = vout_Probe;
127 p_function_list->functions.vout.pf_create = vout_Create;
128 p_function_list->functions.vout.pf_init = vout_Init;
129 p_function_list->functions.vout.pf_end = vout_End;
130 p_function_list->functions.vout.pf_destroy = vout_Destroy;
131 p_function_list->functions.vout.pf_manage = vout_Manage;
132 p_function_list->functions.vout.pf_display = vout_Display;
133 p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
136 /*****************************************************************************
137 * vout_Probe: probe the video driver and return a score
138 *****************************************************************************
139 * This function tries to initialize SDL and returns a score to the
140 * plugin manager so that it can select the best plugin.
141 *****************************************************************************/
142 static int vout_Probe( probedata_t *p_data )
144 if( TestMethod( VOUT_METHOD_VAR, "sdl" ) )
152 /*****************************************************************************
153 * vout_Create: allocate SDL video thread output method
154 *****************************************************************************
155 * This function allocate and initialize a SDL vout method. It uses some of the
156 * vout properties to choose the correct mode, and change them according to the
157 * mode actually used.
158 *****************************************************************************/
159 static int vout_Create( vout_thread_t *p_vout )
161 /* Allocate structure */
162 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
163 if( p_vout->p_sys == NULL )
165 intf_ErrMsg( "vout error: can't create p_sys (%s)", strerror(ENOMEM) );
169 /* Initialize library */
170 if( SDL_Init( SDL_INIT_VIDEO
172 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
173 | SDL_INIT_EVENTTHREAD
176 /* In debug mode you may want vlc to dump a core instead of staying
178 | SDL_INIT_NOPARACHUTE
182 intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
183 free( p_vout->p_sys );
187 p_vout->p_sys->b_cursor = 1; /* TODO should be done with a main_GetInt.. */
189 p_vout->p_sys->b_cursor_autohidden = 0;
190 p_vout->p_sys->i_lastmoved = mdate();
192 p_vout->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
193 VOUT_FULLSCREEN_DEFAULT );
194 p_vout->p_sys->b_overlay = main_GetIntVariable( VOUT_OVERLAY_VAR,
195 VOUT_OVERLAY_DEFAULT );
196 p_vout->p_sys->i_width = main_GetIntVariable( VOUT_WIDTH_VAR,
197 VOUT_WIDTH_DEFAULT );
198 p_vout->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
199 VOUT_HEIGHT_DEFAULT );
201 p_vout->p_sys->p_display = NULL;
202 p_vout->p_sys->p_overlay = NULL;
204 if( SDLOpenDisplay(p_vout) )
206 intf_ErrMsg( "vout error: can't set up SDL (%s)", SDL_GetError() );
207 free( p_vout->p_sys );
211 /* FIXME: get rid of this ASAP, it's FUCKING UGLY */
212 { intf_thread_t * p_intf = p_main->p_intf;
213 intf_AssignKey(p_intf, SDLK_q, INTF_KEY_QUIT, 0);
214 intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
215 /* intf_AssignKey(p_intf,3,'Q'); */
216 intf_AssignKey(p_intf, SDLK_0, INTF_KEY_SET_CHANNEL,0);
217 intf_AssignKey(p_intf, SDLK_1, INTF_KEY_SET_CHANNEL,1);
218 intf_AssignKey(p_intf, SDLK_2, INTF_KEY_SET_CHANNEL,2);
219 intf_AssignKey(p_intf, SDLK_3, INTF_KEY_SET_CHANNEL,3);
220 intf_AssignKey(p_intf, SDLK_4, INTF_KEY_SET_CHANNEL,4);
221 intf_AssignKey(p_intf, SDLK_5, INTF_KEY_SET_CHANNEL,5);
222 intf_AssignKey(p_intf, SDLK_6, INTF_KEY_SET_CHANNEL,6);
223 intf_AssignKey(p_intf, SDLK_7, INTF_KEY_SET_CHANNEL,7);
224 intf_AssignKey(p_intf, SDLK_8, INTF_KEY_SET_CHANNEL,8);
225 intf_AssignKey(p_intf, SDLK_9, INTF_KEY_SET_CHANNEL,9);
226 intf_AssignKey(p_intf, SDLK_PLUS, INTF_KEY_INC_VOLUME, 0);
227 intf_AssignKey(p_intf, SDLK_MINUS, INTF_KEY_DEC_VOLUME, 0);
228 intf_AssignKey(p_intf, SDLK_m, INTF_KEY_TOGGLE_VOLUME, 0);
229 /* intf_AssignKey(p_intf,'M','M'); */
230 intf_AssignKey(p_intf, SDLK_g, INTF_KEY_DEC_GAMMA, 0);
231 /* intf_AssignKey(p_intf,'G','G'); */
232 intf_AssignKey(p_intf, SDLK_c, INTF_KEY_TOGGLE_GRAYSCALE, 0);
233 intf_AssignKey(p_intf, SDLK_SPACE, INTF_KEY_TOGGLE_INTERFACE, 0);
234 intf_AssignKey(p_intf, SDLK_i, INTF_KEY_TOGGLE_INFO, 0);
235 intf_AssignKey(p_intf, SDLK_s, INTF_KEY_TOGGLE_SCALING, 0);
236 intf_AssignKey(p_intf, SDLK_d, INTF_KEY_DUMP_STREAM, 0); }
241 /*****************************************************************************
242 * vout_Init: initialize SDL video thread output method
243 *****************************************************************************
244 * This function initialize the SDL display device.
245 *****************************************************************************/
246 static int vout_Init( vout_thread_t *p_vout )
248 /* This hack is hugly, but hey, you are, too. */
250 SDL_Overlay * p_overlay;
252 p_overlay = SDL_CreateYUVOverlay(
253 main_GetIntVariable( VOUT_WIDTH_VAR,VOUT_WIDTH_DEFAULT ),
254 main_GetIntVariable( VOUT_HEIGHT_VAR,VOUT_HEIGHT_DEFAULT ),
256 p_vout->p_sys->p_display );
258 if( p_overlay == NULL )
260 intf_ErrMsg( "vout error: could not create SDL overlay" );
261 p_vout->b_need_render = 1;
265 intf_WarnMsg( 2, "vout: YUV acceleration %s",
266 p_overlay->hw_overlay ? "activated" : "unavailable !" );
267 p_vout->b_need_render = !p_overlay->hw_overlay;
269 SDL_FreeYUVOverlay( p_overlay );
274 /*****************************************************************************
275 * vout_End: terminate Sys video thread output method
276 *****************************************************************************
277 * Terminate an output method created by vout_SDLCreate
278 *****************************************************************************/
279 static void vout_End( vout_thread_t *p_vout )
281 SDLCloseDisplay( p_vout );
282 SDL_QuitSubSystem( SDL_INIT_VIDEO );
285 /*****************************************************************************
286 * vout_Destroy: destroy Sys video thread output method
287 *****************************************************************************
288 * Terminate an output method created by vout_SDLCreate
289 *****************************************************************************/
290 static void vout_Destroy( vout_thread_t *p_vout )
292 free( p_vout->p_sys );
295 /*****************************************************************************
296 * vout_Manage: handle Sys events
297 *****************************************************************************
298 * This function should be called regularly by video output thread. It returns
299 * a non null value if an error occured.
300 *****************************************************************************/
301 static int vout_Manage( vout_thread_t *p_vout )
303 SDL_Event event; /* SDL event */
307 while( SDL_PollEvent(&event) )
311 case SDL_VIDEORESIZE: /* Resizing of window */
312 p_vout->i_width = event.resize.w;
313 p_vout->i_height = event.resize.h;
314 p_vout->i_changes |= VOUT_SIZE_CHANGE;
317 case SDL_MOUSEMOTION:
318 if( p_vout->p_sys->b_cursor &&
319 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
321 if( p_vout->p_sys->b_cursor_autohidden )
323 p_vout->p_sys->b_cursor_autohidden = 0;
328 p_vout->p_sys->i_lastmoved = mdate();
333 case SDL_MOUSEBUTTONUP:
334 switch( event.button.button )
336 case SDL_BUTTON_RIGHT:
337 p_main->p_intf->b_menu_change = 1;
342 case SDL_MOUSEBUTTONDOWN:
343 switch( event.button.button )
345 case SDL_BUTTON_MIDDLE:
346 p_vout->i_changes |= VOUT_CURSOR_CHANGE;
352 intf_ProcessKey( p_main->p_intf, SDLK_q );
355 case SDL_KEYDOWN: /* if a key is pressed */
357 switch( event.key.keysym.sym )
359 case SDLK_f: /* switch to fullscreen */
360 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
363 case SDLK_y: /* switch to hard YUV */
364 p_vout->i_changes |= VOUT_YUV_CHANGE;
367 case SDLK_c: /* toggle grayscale */
368 p_vout->b_grayscale = ! p_vout->b_grayscale;
369 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
372 case SDLK_i: /* toggle info */
373 p_vout->b_info = ! p_vout->b_info;
374 p_vout->i_changes |= VOUT_INFO_CHANGE;
377 case SDLK_s: /* toggle scaling */
378 p_vout->b_scale = ! p_vout->b_scale;
379 p_vout->i_changes |= VOUT_SCALE_CHANGE;
382 case SDLK_SPACE: /* toggle interface */
383 p_vout->b_interface = ! p_vout->b_interface;
384 p_vout->i_changes |= VOUT_INTF_CHANGE;
388 network_ChannelJoin( 0 );
391 network_ChannelJoin( 1 );
394 network_ChannelJoin( 2 );
397 network_ChannelJoin( 3 );
400 network_ChannelJoin( 4 );
403 network_ChannelJoin( 5 );
406 network_ChannelJoin( 6 );
409 network_ChannelJoin( 7 );
412 network_ChannelJoin( 8 );
415 network_ChannelJoin( 9 );
419 p_main->p_intf->b_menu_change = 1;
423 p_key = SDL_GetKeyName( event.key.keysym.sym ) ;
424 if( intf_ProcessKey( p_main->p_intf,
425 (char )event.key.keysym.sym ) )
427 intf_DbgMsg( "unhandled key '%c' (%i)",
428 (char)event.key.keysym.sym,
429 event.key.keysym.sym );
443 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
445 p_vout->p_sys->i_width = p_vout->i_width;
446 p_vout->p_sys->i_height = p_vout->i_height;
448 /* Need to reopen display */
449 SDLCloseDisplay( p_vout );
450 if( SDLOpenDisplay( p_vout ) )
452 intf_ErrMsg( "vout error: can't reopen display after resize" );
455 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
461 if( p_vout->i_changes & VOUT_YUV_CHANGE )
463 p_vout->b_need_render = ! p_vout->b_need_render;
465 /* Need to reopen display */
466 SDLCloseDisplay( p_vout );
467 if( SDLOpenDisplay( p_vout ) )
469 intf_ErrMsg( "error: can't reopen display after YUV change" );
472 p_vout->i_changes &= ~VOUT_YUV_CHANGE;
478 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
480 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
482 SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
484 p_vout->p_sys->b_cursor_autohidden = 0;
485 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
486 ! p_vout->p_sys->b_cursor_autohidden );
488 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
494 if( ! p_vout->p_sys->b_cursor_autohidden &&
495 ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
497 /* Hide the mouse automatically */
498 p_vout->p_sys->b_cursor_autohidden = 1;
502 if( p_vout->i_changes & VOUT_CURSOR_CHANGE )
504 p_vout->p_sys->b_cursor = ! p_vout->p_sys->b_cursor;
506 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
507 ! p_vout->p_sys->b_cursor_autohidden );
509 p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
515 /*****************************************************************************
516 * vout_SetPalette: sets an 8 bpp palette
517 *****************************************************************************
518 * This function sets the palette given as an argument. It does not return
519 * anything, but could later send information on which colors it was unable
521 *****************************************************************************/
522 static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
523 u16 *blue, u16 *transp)
525 /* Create a display surface with a grayscale palette */
526 SDL_Color colors[256];
529 /* Fill colors with color information */
530 for( i = 0; i < 256; i++ )
532 colors[ i ].r = red[ i ] >> 8;
533 colors[ i ].g = green[ i ] >> 8;
534 colors[ i ].b = blue[ i ] >> 8;
538 if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
540 intf_ErrMsg( "vout error: failed setting palette" );
545 /*****************************************************************************
546 * vout_Display: displays previously rendered output
547 *****************************************************************************
548 * This function send the currently rendered image to the display, wait until
549 * it is displayed and switch the two rendering buffer, preparing next frame.
550 *****************************************************************************/
551 static void vout_Display( vout_thread_t *p_vout )
555 if((p_vout->p_sys->p_display != NULL) && !p_vout->p_sys->b_reopen_display)
557 if( !p_vout->b_need_render )
560 * p_vout->p_rendered_pic->p_y/u/v contains the YUV buffers to
563 /* TODO: support for streams other than 4:2:0 */
564 /* create the overlay if necessary */
565 if( p_vout->p_sys->p_overlay == NULL )
567 p_vout->p_sys->p_overlay = SDL_CreateYUVOverlay(
568 p_vout->p_rendered_pic->i_width,
569 p_vout->p_rendered_pic->i_height,
571 p_vout->p_sys->p_display );
573 if( p_vout->p_sys->p_overlay != NULL )
575 intf_WarnMsg( 2, "vout: YUV acceleration %s",
576 p_vout->p_sys->p_overlay->hw_overlay
577 ? "activated" : "unavailable !" );
581 if( p_vout->p_sys->p_overlay == NULL )
583 /* Overlay allocation failed, switch back to software mode */
584 intf_ErrMsg( "vout error: could not create SDL overlay" );
585 p_vout->b_need_render = 1;
589 int i_x, i_y, i_w, i_h;
591 SDL_LockYUVOverlay( p_vout->p_sys->p_overlay );
592 /* copy the data into video buffers */
594 memcpy( p_vout->p_sys->p_overlay->pixels[0],
595 p_vout->p_rendered_pic->p_y,
596 p_vout->p_sys->p_overlay->h *
597 p_vout->p_sys->p_overlay->pitches[0] );
599 memcpy( p_vout->p_sys->p_overlay->pixels[1],
600 p_vout->p_rendered_pic->p_v,
601 p_vout->p_sys->p_overlay->h *
602 p_vout->p_sys->p_overlay->pitches[1] / 2 );
604 memcpy( p_vout->p_sys->p_overlay->pixels[2],
605 p_vout->p_rendered_pic->p_u,
606 p_vout->p_sys->p_overlay->h *
607 p_vout->p_sys->p_overlay->pitches[2] / 2 );
609 OutputCoords( p_vout->p_rendered_pic, 1,
610 p_vout->p_sys->i_width,
611 p_vout->p_sys->i_height,
619 SDL_DisplayYUVOverlay( p_vout->p_sys->p_overlay , &disp );
620 SDL_UnlockYUVOverlay(p_vout->p_sys->p_overlay);
626 /* Software YUV: change display frame */
627 SDL_Flip( p_vout->p_sys->p_display );
631 /* following functions are local */
633 /*****************************************************************************
634 * SDLOpenDisplay: open and initialize SDL device
635 *****************************************************************************
636 * Open and initialize display according to preferences specified in the vout
638 *****************************************************************************/
639 static int SDLOpenDisplay( vout_thread_t *p_vout )
641 SDL_Rect clipping_rect;
645 * TODO: Check that we can request for a DOUBLEBUF HWSURFACE display
648 /* init flags and cursor */
649 flags = SDL_ANYFORMAT | SDL_HWPALETTE;
651 if( p_vout->b_fullscreen )
653 flags |= SDL_FULLSCREEN;
657 flags |= SDL_RESIZABLE;
660 if( p_vout->b_need_render )
662 flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
666 flags |= SDL_SWSURFACE; /* save video memory */
669 bpp = SDL_VideoModeOK( p_vout->p_sys->i_width,
670 p_vout->p_sys->i_height,
671 p_vout->i_screen_depth, flags );
675 intf_ErrMsg( "vout error: no video mode available" );
679 p_vout->p_sys->p_display = SDL_SetVideoMode(p_vout->p_sys->i_width,
680 p_vout->p_sys->i_height,
683 if( p_vout->p_sys->p_display == NULL )
685 intf_ErrMsg( "vout error: cannot set video mode" );
689 SDL_LockSurface( p_vout->p_sys->p_display );
691 SDL_WM_SetCaption( VOUT_TITLE " (SDL output)",
692 VOUT_TITLE " (SDL output)" );
693 SDL_EventState(SDL_KEYUP , SDL_IGNORE); /* ignore keys up */
695 if( p_vout->b_need_render )
697 p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
698 SDL_Flip(p_vout->p_sys->p_display);
699 p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
700 SDL_Flip(p_vout->p_sys->p_display);
702 /* Set clipping for text */
705 clipping_rect.w = p_vout->p_sys->p_display->w;
706 clipping_rect.h = p_vout->p_sys->p_display->h;
707 SDL_SetClipRect(p_vout->p_sys->p_display, &clipping_rect);
709 /* Set thread information */
710 p_vout->i_width = p_vout->p_sys->p_display->w;
711 p_vout->i_height = p_vout->p_sys->p_display->h;
712 p_vout->i_bytes_per_line = p_vout->p_sys->p_display->pitch;
714 p_vout->i_screen_depth =
715 p_vout->p_sys->p_display->format->BitsPerPixel;
716 p_vout->i_bytes_per_pixel =
717 p_vout->p_sys->p_display->format->BytesPerPixel;
719 p_vout->i_red_mask = p_vout->p_sys->p_display->format->Rmask;
720 p_vout->i_green_mask = p_vout->p_sys->p_display->format->Gmask;
721 p_vout->i_blue_mask = p_vout->p_sys->p_display->format->Bmask;
723 /* FIXME: palette in 8bpp ?? */
724 /* Set and initialize buffers */
725 p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
726 p_vout->p_sys->p_sdl_buf[ 1 ] );
730 p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
731 p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
733 /* Set thread information */
734 p_vout->i_width = p_vout->p_sys->p_display->w;
735 p_vout->i_height = p_vout->p_sys->p_display->h;
736 p_vout->i_bytes_per_line = p_vout->p_sys->p_display->pitch;
738 p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
739 p_vout->p_sys->p_sdl_buf[ 1 ] );
742 p_vout->p_sys->b_reopen_display = 0;
747 /*****************************************************************************
748 * SDLCloseDisplay: close and reset SDL device
749 *****************************************************************************
750 * This function returns all resources allocated by SDLOpenDisplay and restore
751 * the original state of the device.
752 *****************************************************************************/
753 static void SDLCloseDisplay( vout_thread_t *p_vout )
755 if( p_vout->p_sys->p_display != NULL )
757 if( p_vout->p_sys->p_overlay != NULL )
759 SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
760 p_vout->p_sys->p_overlay = NULL;
763 SDL_UnlockSurface ( p_vout->p_sys->p_display );
764 SDL_FreeSurface( p_vout->p_sys->p_display );
765 p_vout->p_sys->p_display = NULL;
769 /*****************************************************************************
770 * OutputCoords: compute the dimensions of the destination image
771 *****************************************************************************
772 * This based on some code in SetBufferPicture... , it is also in use in the
773 * the xvideo plugin. Maybe we should think about putting standard video
774 * processing functions in a common library ?
775 *****************************************************************************/
776 static void OutputCoords( const picture_t *p_pic, const boolean_t scale,
777 const int win_w, const int win_h,
778 int *dx, int *dy, int *w, int *h )
782 *w = p_pic->i_width; *h = p_pic->i_height;
787 switch( p_pic->i_aspect_ratio )
793 case AR_16_9_PICTURE:
797 case AR_221_1_PICTURE:
798 *h = win_w * 100 / 221;
801 case AR_SQUARE_PICTURE:
803 *h = win_w * p_pic->i_height / p_pic->i_width;
810 switch( p_pic->i_aspect_ratio )
816 case AR_16_9_PICTURE:
820 case AR_221_1_PICTURE:
821 *w = win_h * 221 / 100;
824 case AR_SQUARE_PICTURE:
826 *w = win_h * p_pic->i_width / p_pic->i_height;
832 /* Set picture position */
833 *dx = (win_w - *w) / 2;
834 *dy = (win_h - *h) / 2;