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