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