]> git.sesse.net Git - vlc/blob - plugins/sdl/vout_sdl.c
* added --intf option to vlc
[vlc] / plugins / sdl / vout_sdl.c
1 /*****************************************************************************
2  * vout_sdl.c: SDL video output display method
3  *****************************************************************************
4  * Copyright (C) 1998, 1999, 2000 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *          Pierre Baillet <oct@zoy.org>
8  *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <errno.h>                                                 /* ENOMEM */
31 #include <stdlib.h>                                                /* free() */
32 #include <string.h>                                            /* strerror() */
33
34 #include <SDL/SDL.h>
35
36 #include "config.h"
37 #include "common.h"
38 #include "threads.h"
39 #include "mtime.h"
40 #include "tests.h"
41 #include "modules.h"
42
43 #include "video.h"
44 #include "video_output.h"
45
46 #include "intf_msg.h"
47 #include "interface.h"
48 /* FIXME: get rid of this */
49 #include "keystrokes.h"
50 #include "main.h"
51
52 /*****************************************************************************
53  * FIXME: this file is ...                                                   *
54  *                                                                           *
55  *              XXX   XXX     FIXME     XXX     XXX   XXX   XXX              *
56  *              XXX   XXX   XXX   XXX   XXX     XXX   XXX   XXX              *
57  *              XXX   XXX   XXX         XXX       FIXME     XXX              *
58  *              XXX   XXX   XXX  TODO   XXX        XXX      XXX              *
59  *              XXX   XXX   XXX   XXX   XXX        XXX                       *
60  *                FIXME       FIXME       FIXME    XXX      XXX              *
61  *                                                                           *
62  *****************************************************************************/
63
64 /*****************************************************************************
65  * vout_sys_t: video output SDL method descriptor
66  *****************************************************************************
67  * This structure is part of the video output thread descriptor.
68  * It describes the SDL specific properties of an output thread.
69  *****************************************************************************/
70 typedef struct vout_sys_s
71 {
72     int i_width;
73     int i_height;
74     SDL_Surface *   p_display;                             /* display device */
75     SDL_Overlay *   p_overlay;                             /* overlay device */
76     boolean_t   b_fullscreen;
77     boolean_t   b_overlay;
78     boolean_t   b_cursor;
79     boolean_t   b_reopen_display;
80     Uint8   *   p_sdl_buf[2];                          /* Buffer information */
81 } vout_sys_t;
82
83 /*****************************************************************************
84  * Local prototypes.
85  *****************************************************************************/
86 static int  vout_Probe     ( probedata_t *p_data );
87 static int  vout_Create    ( struct vout_thread_s * );
88 static int  vout_Init      ( struct vout_thread_s * );
89 static void vout_End       ( struct vout_thread_s * );
90 static void vout_Destroy   ( struct vout_thread_s * );
91 static int  vout_Manage    ( struct vout_thread_s * );
92 static void vout_Display   ( struct vout_thread_s * );
93
94 static int  SDLOpenDisplay      ( vout_thread_t *p_vout );
95 static void SDLCloseDisplay     ( vout_thread_t *p_vout );
96
97 /*****************************************************************************
98  * Functions exported as capabilities. They are declared as static so that
99  * we don't pollute the namespace too much.
100  *****************************************************************************/
101 void vout_getfunctions( function_list_t * p_function_list )
102 {
103     p_function_list->pf_probe = vout_Probe;
104     p_function_list->functions.vout.pf_create     = vout_Create;
105     p_function_list->functions.vout.pf_init       = vout_Init;
106     p_function_list->functions.vout.pf_end        = vout_End;
107     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
108     p_function_list->functions.vout.pf_manage     = vout_Manage;
109     p_function_list->functions.vout.pf_display    = vout_Display;
110     p_function_list->functions.vout.pf_setpalette = NULL;
111 }
112
113 /*****************************************************************************
114  * vout_Probe: probe the video driver and return a score
115  *****************************************************************************
116  * This function tries to initialize SDL and returns a score to the
117  * plugin manager so that it can select the best plugin.
118  *****************************************************************************/
119 static int vout_Probe( probedata_t *p_data )
120 {
121     if( TestMethod( VOUT_METHOD_VAR, "sdl" ) )
122     {
123         return( 999 );
124     }
125
126     return( 40 );
127 }
128
129 /*****************************************************************************
130  * vout_Create: allocate SDL video thread output method
131  *****************************************************************************
132  * This function allocate and initialize a SDL vout method. It uses some of the
133  * vout properties to choose the correct mode, and change them according to the
134  * mode actually used.
135  *****************************************************************************/
136 int vout_Create( vout_thread_t *p_vout )
137 {
138     /* Allocate structure */
139     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
140     if( p_vout->p_sys == NULL )
141     {
142         intf_ErrMsg( "vout error: can't create p_sys (%s)", strerror(ENOMEM) );
143         return( 1 );
144     }
145
146     /* Initialize library */
147     if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE)
148             < 0 )
149     {
150         intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
151         free( p_vout->p_sys );
152         return( 1 );
153     }
154
155     /* Force the software yuv even if it is not used */
156     /* If we don't do this, p_vout is not correctly initialized
157        and it's impossible to switch between soft/hard yuv */
158     /* FIXME: this is a broken way to do !! fix this !! */
159     p_vout->b_need_render = 1;
160
161     p_vout->p_sys->b_cursor = 1; /* TODO should be done with a main_GetInt.. */
162     p_vout->p_sys->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
163                                 VOUT_FULLSCREEN_DEFAULT );
164     p_vout->p_sys->b_overlay = main_GetIntVariable( VOUT_OVERLAY_VAR,
165                                 VOUT_OVERLAY_DEFAULT );
166     p_vout->p_sys->i_width = main_GetIntVariable( VOUT_WIDTH_VAR, 
167                                 VOUT_WIDTH_DEFAULT );
168     p_vout->p_sys->i_height = main_GetIntVariable( VOUT_HEIGHT_VAR,
169                                 VOUT_HEIGHT_DEFAULT );
170
171     p_vout->p_sys->p_display = NULL;
172     p_vout->p_sys->p_overlay = NULL;
173
174     if( SDLOpenDisplay(p_vout) )
175     {
176         intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
177         free( p_vout->p_sys );
178         return( 1 );
179     }
180
181     /* FIXME: get rid of this ASAP, it's FUCKING UGLY */
182     { intf_thread_t * p_intf = p_main->p_intf;
183     intf_AssignKey(p_intf, SDLK_q,      INTF_KEY_QUIT, 0);
184     intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
185     /* intf_AssignKey(p_intf,3,'Q'); */
186     intf_AssignKey(p_intf, SDLK_0,      INTF_KEY_SET_CHANNEL,0);
187     intf_AssignKey(p_intf, SDLK_1,      INTF_KEY_SET_CHANNEL,1);
188     intf_AssignKey(p_intf, SDLK_2,      INTF_KEY_SET_CHANNEL,2);
189     intf_AssignKey(p_intf, SDLK_3,      INTF_KEY_SET_CHANNEL,3);
190     intf_AssignKey(p_intf, SDLK_4,      INTF_KEY_SET_CHANNEL,4);
191     intf_AssignKey(p_intf, SDLK_5,      INTF_KEY_SET_CHANNEL,5);
192     intf_AssignKey(p_intf, SDLK_6,      INTF_KEY_SET_CHANNEL,6);
193     intf_AssignKey(p_intf, SDLK_7,      INTF_KEY_SET_CHANNEL,7);
194     intf_AssignKey(p_intf, SDLK_8,      INTF_KEY_SET_CHANNEL,8);
195     intf_AssignKey(p_intf, SDLK_9,      INTF_KEY_SET_CHANNEL,9);
196     intf_AssignKey(p_intf, SDLK_PLUS,   INTF_KEY_INC_VOLUME, 0);
197     intf_AssignKey(p_intf, SDLK_MINUS,  INTF_KEY_DEC_VOLUME, 0);
198     intf_AssignKey(p_intf, SDLK_m,      INTF_KEY_TOGGLE_VOLUME, 0);
199     /* intf_AssignKey(p_intf,'M','M'); */
200     intf_AssignKey(p_intf, SDLK_g,      INTF_KEY_DEC_GAMMA, 0);
201     /* intf_AssignKey(p_intf,'G','G'); */
202     intf_AssignKey(p_intf, SDLK_c,      INTF_KEY_TOGGLE_GRAYSCALE, 0);
203     intf_AssignKey(p_intf, SDLK_SPACE,  INTF_KEY_TOGGLE_INTERFACE, 0);
204     intf_AssignKey(p_intf, SDLK_i,      INTF_KEY_TOGGLE_INFO, 0);
205     intf_AssignKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, 0); }
206
207     return( 0 );
208 }
209
210 /*****************************************************************************
211  * vout_Init: initialize SDL video thread output method
212  *****************************************************************************
213  * This function initialize the SDL display device.
214  *****************************************************************************/
215 int vout_Init( vout_thread_t *p_vout )
216 {
217     return( 0 );
218 }
219
220 /*****************************************************************************
221  * vout_End: terminate Sys video thread output method
222  *****************************************************************************
223  * Terminate an output method created by vout_SDLCreate
224  *****************************************************************************/
225 void vout_End( vout_thread_t *p_vout )
226 {
227     SDLCloseDisplay( p_vout );
228     SDL_Quit();
229 }
230
231 /*****************************************************************************
232  * vout_Destroy: destroy Sys video thread output method
233  *****************************************************************************
234  * Terminate an output method created by vout_SDLCreate
235  *****************************************************************************/
236 void vout_Destroy( vout_thread_t *p_vout )
237 {
238     free( p_vout->p_sys );
239 }
240
241 /*****************************************************************************
242  * vout_Manage: handle Sys events
243  *****************************************************************************
244  * This function should be called regularly by video output thread. It returns
245  * a non null value if an error occured.
246  *****************************************************************************/
247 int vout_Manage( vout_thread_t *p_vout )
248 {
249     SDL_Event event;                                            /* SDL event */
250     Uint8   i_key;
251
252     /* Process events */
253     while( SDL_PollEvent(&event) )
254     {
255         switch( event.type )
256         {
257         case SDL_VIDEORESIZE:                          /* Resizing of window */
258             p_vout->i_width = event.resize.w;
259             p_vout->i_height = event.resize.h;
260             p_vout->i_changes |= VOUT_SIZE_CHANGE;
261             break;
262
263         case SDL_MOUSEBUTTONDOWN:
264             switch( event.button.button )
265             {
266             case SDL_BUTTON_MIDDLE:
267                 p_vout->i_changes |= VOUT_CURSOR_CHANGE;
268                 break;
269
270             case SDL_BUTTON_RIGHT:
271                 p_main->p_intf->b_menu_change = 1;
272                 break;
273             }
274             break;
275
276         case SDL_QUIT:
277             intf_ProcessKey( p_main->p_intf, SDLK_q );
278             break;
279
280         case SDL_KEYDOWN:                             /* if a key is pressed */
281             i_key = event.key.keysym.sym;
282
283             switch( i_key )
284             {
285             case SDLK_f:                             /* switch to fullscreen */
286                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
287                 break;
288
289             case SDLK_y:                               /* switch to hard YUV */
290                 p_vout->i_changes |= VOUT_YUV_CHANGE;
291                 break;
292
293             case SDLK_c:                                 /* toggle grayscale */
294                 p_vout->b_grayscale = ! p_vout->b_grayscale;
295                 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
296                 break;
297
298             case SDLK_i:                                      /* toggle info */
299                 p_vout->b_info = ! p_vout->b_info;
300                 p_vout->i_changes |= VOUT_INFO_CHANGE;
301                 break;
302
303             case SDLK_s:                                   /* toggle scaling */
304                 p_vout->b_scale = ! p_vout->b_scale;
305                 p_vout->i_changes |= VOUT_SCALE_CHANGE;
306                 break;
307
308             case SDLK_SPACE:                             /* toggle interface */
309                 p_vout->b_interface = ! p_vout->b_interface;
310                 p_vout->i_changes |= VOUT_INTF_CHANGE;
311                 break;
312
313             default:
314                 if( intf_ProcessKey( p_main->p_intf, (char )i_key ) )
315                 {
316                    intf_DbgMsg( "unhandled key '%c' (%i)", (char)i_key, i_key );                }
317                 break;
318             }
319             break;
320
321         default:
322             break;
323         }
324     }
325
326     /*
327      * Size Change 
328      */
329     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
330     {
331         p_vout->p_sys->i_width = p_vout->i_width;
332         p_vout->p_sys->i_height = p_vout->i_height;
333
334         /* Need to reopen display */
335         SDLCloseDisplay( p_vout );
336         if( SDLOpenDisplay( p_vout ) )
337         {
338           intf_ErrMsg( "error: can't open DISPLAY default display" );
339           return( 1 );
340         }
341         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
342     }
343     
344     /*
345      * YUV Change 
346      */
347     if( p_vout->i_changes & VOUT_YUV_CHANGE )
348     {
349         p_vout->b_need_render = ! p_vout->b_need_render;
350         
351         /* Need to reopen display */
352         SDLCloseDisplay( p_vout );
353         if( SDLOpenDisplay( p_vout ) )
354         {
355           intf_ErrMsg( "error: can't open DISPLAY default display" );
356           return( 1 );
357         }
358         p_vout->i_changes &= ~VOUT_YUV_CHANGE;
359     }
360
361     /*
362      * Fullscreen change
363      */
364     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
365     {
366         p_vout->p_sys->b_fullscreen = ! p_vout->p_sys->b_fullscreen;
367
368         if( p_vout->p_sys->b_fullscreen )
369         {
370             p_vout->p_sys->b_fullscreen = 0;
371             p_vout->p_sys->b_cursor = 1;
372             SDL_ShowCursor( 1 );
373         }
374         else
375         {
376             p_vout->p_sys->b_fullscreen = 1;
377             p_vout->p_sys->b_cursor = 0;
378             SDL_ShowCursor( 0 );
379         }
380
381         SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
382
383         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
384     }
385
386     /*
387      * Pointer change
388      */
389     if( p_vout->i_changes & VOUT_CURSOR_CHANGE )
390     {
391         if( p_vout->p_sys->b_cursor )
392         {
393             SDL_ShowCursor( 0 );
394             p_vout->p_sys->b_cursor = 0;
395         }
396         else
397         {
398             SDL_ShowCursor( 1 );
399             p_vout->p_sys->b_cursor = 1;
400         }
401         p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
402     }
403     
404     return( 0 );
405 }
406
407 /*****************************************************************************
408  * vout_SetPalette: sets an 8 bpp palette
409  *****************************************************************************
410  * This function sets the palette given as an argument. It does not return
411  * anything, but could later send information on which colors it was unable
412  * to set.
413  *****************************************************************************/
414 void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
415                          u16 *blue, u16 *transp)
416 {
417      /* Create a display surface with a grayscale palette */
418     SDL_Color colors[256];
419     int i;
420   
421     /* Fill colors with color information */
422     for( i = 0; i < 256; i++ )
423     {
424         colors[ i ].r = red[ i ] >> 8;
425         colors[ i ].g = green[ i ] >> 8;
426         colors[ i ].b = blue[ i ] >> 8;
427     }
428     
429     /* Set palette */
430     if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
431     {
432         intf_ErrMsg( "vout error: failed setting palette" );
433     }
434
435 }
436
437 /*****************************************************************************
438  * vout_Display: displays previously rendered output
439  *****************************************************************************
440  * This function send the currently rendered image to the display, wait until
441  * it is displayed and switch the two rendering buffer, preparing next frame.
442  *****************************************************************************/
443 void vout_Display( vout_thread_t *p_vout )
444 {
445     SDL_Rect    disp;
446     if((p_vout->p_sys->p_display != NULL) && !p_vout->p_sys->b_reopen_display)
447     {
448         if( p_vout->b_need_render )
449         {  
450             /* Change display frame */
451             SDL_Flip( p_vout->p_sys->p_display );
452         }
453         else
454         {
455         
456             /*
457              * p_vout->p_rendered_pic->p_y/u/v contains the YUV buffers to
458              * render 
459              */
460             /* TODO: support for streams other than 4:2:0 */
461             /* create the overlay if necessary */
462             if( p_vout->p_sys->p_overlay == NULL )
463             {
464                 p_vout->p_sys->p_overlay = SDL_CreateYUVOverlay( 
465                                              p_vout->p_rendered_pic->i_width, 
466                                              p_vout->p_rendered_pic->i_height,
467                                              SDL_YV12_OVERLAY, 
468                                              p_vout->p_sys->p_display
469                                            );
470                 intf_Msg("vout: YUV acceleration %s",
471                             p_vout->p_sys->p_overlay->hw_overlay
472                             ? "activated" : "unavailable !" ); 
473             }
474
475             SDL_LockYUVOverlay(p_vout->p_sys->p_overlay);
476             /* copy the data into video buffers */
477             /* Y first */
478             memcpy(p_vout->p_sys->p_overlay->pixels[0],
479                    p_vout->p_rendered_pic->p_y,
480                    p_vout->p_sys->p_overlay->h *
481                    p_vout->p_sys->p_overlay->pitches[0]);
482             /* then V */
483             memcpy(p_vout->p_sys->p_overlay->pixels[1],
484                    p_vout->p_rendered_pic->p_v,
485                    p_vout->p_sys->p_overlay->h *
486                    p_vout->p_sys->p_overlay->pitches[1] / 2);
487             /* and U */
488             memcpy(p_vout->p_sys->p_overlay->pixels[2],
489                    p_vout->p_rendered_pic->p_u,
490                    p_vout->p_sys->p_overlay->h *
491                    p_vout->p_sys->p_overlay->pitches[2] / 2);
492
493             disp.w = (&p_vout->p_buffer[p_vout->i_buffer_index])->i_pic_width;
494             disp.h = (&p_vout->p_buffer[p_vout->i_buffer_index])->i_pic_height;
495             disp.x = (p_vout->i_width - disp.w)/2;
496             disp.y = (p_vout->i_height - disp.h)/2;
497
498             SDL_DisplayYUVOverlay( p_vout->p_sys->p_overlay , &disp );
499             SDL_UnlockYUVOverlay(p_vout->p_sys->p_overlay);
500         }
501     }
502 }
503
504 /* following functions are local */
505
506 /*****************************************************************************
507  * SDLOpenDisplay: open and initialize SDL device
508  *****************************************************************************
509  * Open and initialize display according to preferences specified in the vout
510  * thread fields.
511  *****************************************************************************/
512 static int SDLOpenDisplay( vout_thread_t *p_vout )
513 {
514     SDL_Rect    clipping_rect;
515     Uint32      flags;
516     int bpp;
517     /* Open display 
518      * TODO: Check that we can request for a DOUBLEBUF HWSURFACE display
519      */
520
521     /* init flags and cursor */
522     flags = SDL_ANYFORMAT | SDL_HWPALETTE;
523
524     if( p_vout->p_sys->b_fullscreen )
525         flags |= SDL_FULLSCREEN;
526     else
527         flags |= SDL_RESIZABLE;
528
529     if( p_vout->b_need_render )
530         flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
531     else
532         flags |= SDL_SWSURFACE; /* save video memory */
533
534     bpp = SDL_VideoModeOK(p_vout->p_sys->i_width,
535                           p_vout->p_sys->i_height,
536                           p_vout->i_screen_depth, flags);
537
538     if(bpp == 0)
539     {
540         intf_ErrMsg( "error: can't open DISPLAY default display" );
541         return( 1 );
542     }
543
544     p_vout->p_sys->p_display = SDL_SetVideoMode(p_vout->p_sys->i_width,
545                                                 p_vout->p_sys->i_height,
546                                                 bpp, flags);
547
548     if( p_vout->p_sys->p_display == NULL )
549     {
550         intf_ErrMsg( "error: can't open DISPLAY default display" );
551         return( 1 );
552     }
553
554     SDL_LockSurface(p_vout->p_sys->p_display);
555
556     if( p_vout->p_sys->b_fullscreen )
557         SDL_ShowCursor( 0 );
558     else
559         SDL_ShowCursor( 1 );
560
561     SDL_WM_SetCaption( VOUT_TITLE , VOUT_TITLE );
562     SDL_EventState(SDL_KEYUP , SDL_IGNORE);                /* ignore keys up */
563     SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);          
564
565     if( p_vout->b_need_render )
566     {
567         p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
568         SDL_Flip(p_vout->p_sys->p_display);
569         p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
570         SDL_Flip(p_vout->p_sys->p_display);
571
572         /* Set clipping for text */
573         clipping_rect.x = 0;
574         clipping_rect.y = 0;
575         clipping_rect.w = p_vout->p_sys->p_display->w;
576         clipping_rect.h = p_vout->p_sys->p_display->h;
577         SDL_SetClipRect(p_vout->p_sys->p_display, &clipping_rect);
578
579         /* Set thread information */
580         p_vout->i_width =           p_vout->p_sys->p_display->w;
581         p_vout->i_height =          p_vout->p_sys->p_display->h;
582         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
583
584         p_vout->i_screen_depth =
585             p_vout->p_sys->p_display->format->BitsPerPixel;
586         p_vout->i_bytes_per_pixel =
587             p_vout->p_sys->p_display->format->BytesPerPixel;
588
589         p_vout->i_red_mask =        p_vout->p_sys->p_display->format->Rmask;
590         p_vout->i_green_mask =      p_vout->p_sys->p_display->format->Gmask;
591         p_vout->i_blue_mask =       p_vout->p_sys->p_display->format->Bmask;
592
593         /* FIXME: palette in 8bpp ?? */
594         /* Set and initialize buffers */
595         vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
596                                  p_vout->p_sys->p_sdl_buf[ 1 ] );
597     }
598     else
599     {
600         p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
601         p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
602
603         /* Set thread information */
604         p_vout->i_width =           p_vout->p_sys->p_display->w;
605         p_vout->i_height =          p_vout->p_sys->p_display->h;
606         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
607
608         vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
609                                  p_vout->p_sys->p_sdl_buf[ 1 ] );
610     }
611
612     p_vout->p_sys->b_reopen_display = 0;
613
614     return( 0 );
615 }
616
617 /*****************************************************************************
618  * SDLCloseDisplay: close and reset SDL device
619  *****************************************************************************
620  * This function returns all resources allocated by SDLOpenDisplay and restore
621  * the original state of the device.
622  *****************************************************************************/
623 static void SDLCloseDisplay( vout_thread_t *p_vout )
624 {
625     if( p_vout->p_sys->p_display != NULL )
626     {
627         if( p_vout->p_sys->p_overlay != NULL )
628         {            
629             SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
630             p_vout->p_sys->p_overlay = NULL;
631         }
632
633         SDL_UnlockSurface ( p_vout->p_sys->p_display );
634         SDL_FreeSurface( p_vout->p_sys->p_display );
635         p_vout->p_sys->p_display = NULL;
636     }
637 }
638