]> git.sesse.net Git - vlc/blob - plugins/sdl/vout_sdl.c
. removed tests against i_rate and i_new_rate calculation from the
[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:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31
32 #include <SDL/SDL.h>
33
34 #include "config.h"
35 #include "common.h"
36 #include "threads.h"
37 #include "mtime.h"
38 #include "tests.h"
39 #include "modules.h"
40
41 /* FIXME: it's up to the _interface_ to do this, not the video output */
42 #include "stream_control.h"
43 #include "input_ext-intf.h"
44
45 #include "video.h"
46 #include "video_output.h"
47
48 #include "intf_msg.h"
49 #include "interface.h"
50 /* FIXME: get rid of this */
51 #include "keystrokes.h"
52 #include "main.h"
53
54 /*****************************************************************************
55  * FIXME: this file is ...                                                   *
56  *                                                                           *
57  *              XXX   XXX     FIXME     XXX     XXX   XXX   XXX              *
58  *              XXX   XXX   XXX   XXX   XXX     XXX   XXX   XXX              *
59  *              XXX   XXX   XXX         XXX       FIXME     XXX              *
60  *              XXX   XXX   XXX  TODO   XXX        XXX      XXX              *
61  *              XXX   XXX   XXX   XXX   XXX        XXX                       *
62  *                FIXME       FIXME       FIXME    XXX      XXX              *
63  *                                                                           *
64  *****************************************************************************/
65
66 /*****************************************************************************
67  * vout_sys_t: video output SDL method descriptor
68  *****************************************************************************
69  * This structure is part of the video output thread descriptor.
70  * It describes the SDL specific properties of an output thread.
71  *****************************************************************************/
72 typedef struct vout_sys_s
73 {
74     int i_width;
75     int i_height;
76     SDL_Surface *   p_display;                             /* display device */
77     SDL_Overlay *   p_overlay;                             /* overlay device */
78     boolean_t   b_fullscreen;
79     boolean_t   b_overlay;
80     boolean_t   b_cursor;
81     boolean_t   b_reopen_display;
82     Uint8   *   p_sdl_buf[2];                           /* Buffer information */
83 }   vout_sys_t;
84
85 /*****************************************************************************
86  * Local prototypes.
87  *****************************************************************************/
88 static int  vout_Probe     ( probedata_t *p_data );
89 static int  vout_Create    ( struct vout_thread_s * );
90 static int  vout_Init      ( struct vout_thread_s * );
91 static void vout_End       ( struct vout_thread_s * );
92 static void vout_Destroy   ( struct vout_thread_s * );
93 static int  vout_Manage    ( struct vout_thread_s * );
94 static void vout_Display   ( struct vout_thread_s * );
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 = NULL;
113 }
114
115 /*****************************************************************************
116  * intf_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( 40 );
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 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     /* p_intf->p_intf_getKey = intf_getKey; */
186     intf_AssignKey(p_intf, SDLK_q,      INTF_KEY_QUIT, 0);
187     intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
188     /* intf_AssignKey(p_intf,3,'Q'); */
189     intf_AssignKey(p_intf, SDLK_0,      INTF_KEY_SET_CHANNEL,0);
190     intf_AssignKey(p_intf, SDLK_1,      INTF_KEY_SET_CHANNEL,1);
191     intf_AssignKey(p_intf, SDLK_2,      INTF_KEY_SET_CHANNEL,2);
192     intf_AssignKey(p_intf, SDLK_3,      INTF_KEY_SET_CHANNEL,3);
193     intf_AssignKey(p_intf, SDLK_4,      INTF_KEY_SET_CHANNEL,4);
194     intf_AssignKey(p_intf, SDLK_5,      INTF_KEY_SET_CHANNEL,5);
195     intf_AssignKey(p_intf, SDLK_6,      INTF_KEY_SET_CHANNEL,6);
196     intf_AssignKey(p_intf, SDLK_7,      INTF_KEY_SET_CHANNEL,7);
197     intf_AssignKey(p_intf, SDLK_8,      INTF_KEY_SET_CHANNEL,8);
198     intf_AssignKey(p_intf, SDLK_9,      INTF_KEY_SET_CHANNEL,9);
199     intf_AssignKey(p_intf, SDLK_PLUS,   INTF_KEY_INC_VOLUME, 0);
200     intf_AssignKey(p_intf, SDLK_MINUS,  INTF_KEY_DEC_VOLUME, 0);
201     intf_AssignKey(p_intf, SDLK_m,      INTF_KEY_TOGGLE_VOLUME, 0);
202     /* intf_AssignKey(p_intf,'M','M'); */
203     intf_AssignKey(p_intf, SDLK_g,      INTF_KEY_DEC_GAMMA, 0);
204     /* intf_AssignKey(p_intf,'G','G'); */
205     intf_AssignKey(p_intf, SDLK_c,      INTF_KEY_TOGGLE_GRAYSCALE, 0);
206     intf_AssignKey(p_intf, SDLK_SPACE,  INTF_KEY_TOGGLE_INTERFACE, 0);
207     intf_AssignKey(p_intf, SDLK_i,      INTF_KEY_TOGGLE_INFO, 0);
208     intf_AssignKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, 0); }
209
210     return( 0 );
211 }
212
213 /*****************************************************************************
214  * vout_Init: initialize SDL video thread output method
215  *****************************************************************************
216  * This function initialize the SDL display device.
217  *****************************************************************************/
218 int vout_Init( vout_thread_t *p_vout )
219 {
220     return( 0 );
221 }
222
223 /*****************************************************************************
224  * vout_End: terminate Sys video thread output method
225  *****************************************************************************
226  * Terminate an output method created by vout_SDLCreate
227  *****************************************************************************/
228 void vout_End( vout_thread_t *p_vout )
229 {
230     SDLCloseDisplay( p_vout );
231     SDL_Quit();
232 }
233
234 /*****************************************************************************
235  * vout_Destroy: destroy Sys video thread output method
236  *****************************************************************************
237  * Terminate an output method created by vout_SDLCreate
238  *****************************************************************************/
239 void vout_Destroy( vout_thread_t *p_vout )
240 {
241     free( p_vout->p_sys );
242 }
243
244 /*****************************************************************************
245  * vout_Manage: handle Sys events
246  *****************************************************************************
247  * This function should be called regularly by video output thread. It returns
248  * a non null value if an error occured.
249  *****************************************************************************/
250 int vout_Manage( vout_thread_t *p_vout )
251 {
252     SDL_Event event;                                            /* SDL event */
253     Uint8   i_key;
254
255     /* FIXME: do this nicely */
256     input_thread_t * p_input = p_main->p_intf->p_input;
257
258     /* Process events */
259     while( SDL_PollEvent(&event) )
260     {
261         switch( event.type )
262         {
263         case SDL_VIDEORESIZE:                          /* Resizing of window */
264             p_vout->i_width = event.resize.w;
265             p_vout->i_height = event.resize.h;
266             p_vout->i_changes |= VOUT_SIZE_CHANGE;
267             break;
268
269         case SDL_MOUSEBUTTONDOWN:
270             switch( event.button.button )
271             {
272             case SDL_BUTTON_MIDDLE:
273                 p_vout->i_changes |= VOUT_CURSOR_CHANGE;
274                 break;
275
276             case SDL_BUTTON_RIGHT:
277                 p_main->p_intf->b_menu_change = 1;
278                 break;
279             }
280             break;
281
282         case SDL_QUIT:
283             intf_ProcessKey( p_main->p_intf, SDLK_q );
284             break;
285
286         case SDL_KEYDOWN:                             /* if a key is pressed */
287             i_key = event.key.keysym.sym;
288
289             switch( i_key )
290             {
291             case SDLK_f:                             /* switch to fullscreen */
292                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
293                 break;
294
295             case SDLK_y:                               /* switch to hard YUV */
296                 p_vout->i_changes |= VOUT_YUV_CHANGE;
297                 break;
298
299             case SDLK_c:                                 /* toggle grayscale */
300                 p_vout->b_grayscale = ! p_vout->b_grayscale;
301                 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
302                 break;
303
304             case SDLK_i:                                      /* toggle info */
305                 p_vout->b_info = ! p_vout->b_info;
306                 p_vout->i_changes |= VOUT_INFO_CHANGE;
307                 break;
308
309             case SDLK_s:                                   /* toggle scaling */
310                 p_vout->b_scale = ! p_vout->b_scale;
311                 p_vout->i_changes |= VOUT_SCALE_CHANGE;
312                 break;
313
314             case SDLK_SPACE:                             /* toggle interface */
315                 p_vout->b_interface = ! p_vout->b_interface;
316                 p_vout->i_changes |= VOUT_INTF_CHANGE;
317                 break;
318
319             /* FIXME : this is temporary */
320             case SDLK_p:
321                 if( p_input != NULL )
322                 {
323                     input_SetRate( p_input, INPUT_RATE_PAUSE );
324                 }
325                 break;
326
327             case SDLK_a:
328                 if( p_input != NULL )
329                 {
330                     input_SetRate( p_input, INPUT_RATE_FASTER );
331                 }
332                 break;
333
334             case SDLK_z:
335                 if( p_input != NULL )
336                 {
337                     input_SetRate( p_input, INPUT_RATE_SLOWER );
338                 }
339                 break;
340
341             case SDLK_j:
342                 if( p_input != NULL )
343                 {
344                     /* Jump forwards */
345                     input_Seek( p_input, p_input->stream.i_tell
346                                  + p_input->stream.i_size / 20 );
347                                                                /* gabuzomeu */
348                 }
349                 break;
350
351             case SDLK_b:
352                 if( p_input != NULL )
353                 {
354                     /* Jump backwards */
355                     input_Seek( p_input, p_input->stream.i_tell
356                                  - p_input->stream.i_size / 20 );
357                 }
358                 break;
359
360             default:
361                 if( intf_ProcessKey( p_main->p_intf, (char )i_key ) )
362                 {
363                    intf_DbgMsg( "unhandled key '%c' (%i)", (char)i_key, i_key );                }
364                 break;
365             }
366             break;
367
368         default:
369             break;
370         }
371     }
372
373     /*
374      * Size Change 
375      */
376     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
377     {
378         p_vout->p_sys->i_width = p_vout->i_width;
379         p_vout->p_sys->i_height = p_vout->i_height;
380
381         /* Need to reopen display */
382         SDLCloseDisplay( p_vout );
383         if( SDLOpenDisplay( p_vout ) )
384         {
385           intf_ErrMsg( "error: can't open DISPLAY default display" );
386           return( 1 );
387         }
388         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
389     }
390     
391     /*
392      * YUV Change 
393      */
394     if( p_vout->i_changes & VOUT_YUV_CHANGE )
395     {
396         p_vout->b_need_render = ! p_vout->b_need_render;
397         
398         /* Need to reopen display */
399         SDLCloseDisplay( p_vout );
400         if( SDLOpenDisplay( p_vout ) )
401         {
402           intf_ErrMsg( "error: can't open DISPLAY default display" );
403           return( 1 );
404         }
405         p_vout->i_changes &= ~VOUT_YUV_CHANGE;
406     }
407
408     /*
409      * Fullscreen change
410      */
411     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
412     {
413         p_vout->p_sys->b_fullscreen = ! p_vout->p_sys->b_fullscreen;
414
415         if( p_vout->p_sys->b_fullscreen )
416         {
417             p_vout->p_sys->b_fullscreen = 0;
418             p_vout->p_sys->b_cursor = 1;
419             SDL_ShowCursor( 1 );
420         }
421         else
422         {
423             p_vout->p_sys->b_fullscreen = 1;
424             p_vout->p_sys->b_cursor = 0;
425             SDL_ShowCursor( 0 );
426         }
427
428         SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
429
430         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
431     }
432
433     /*
434      * Pointer change
435      */
436     if( p_vout->i_changes & VOUT_CURSOR_CHANGE )
437     {
438         if( p_vout->p_sys->b_cursor )
439         {
440             SDL_ShowCursor( 0 );
441             p_vout->p_sys->b_cursor = 0;
442         }
443         else
444         {
445             SDL_ShowCursor( 1 );
446             p_vout->p_sys->b_cursor = 1;
447         }
448         p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
449     }
450     
451     return( 0 );
452 }
453
454 /*****************************************************************************
455  * vout_SetPalette: sets an 8 bpp palette
456  *****************************************************************************
457  * This function sets the palette given as an argument. It does not return
458  * anything, but could later send information on which colors it was unable
459  * to set.
460  *****************************************************************************/
461 void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
462                          u16 *blue, u16 *transp)
463 {
464      /* Create a display surface with a grayscale palette */
465     SDL_Color colors[256];
466     int i;
467   
468     /* Fill colors with color information */
469     for( i = 0; i < 256; i++ )
470     {
471         colors[ i ].r = red[ i ] >> 8;
472         colors[ i ].g = green[ i ] >> 8;
473         colors[ i ].b = blue[ i ] >> 8;
474     }
475     
476     /* Set palette */
477     if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
478     {
479         intf_ErrMsg( "vout error: failed setting palette" );
480     }
481
482 }
483
484 /*****************************************************************************
485  * vout_Display: displays previously rendered output
486  *****************************************************************************
487  * This function send the currently rendered image to the display, wait until
488  * it is displayed and switch the two rendering buffer, preparing next frame.
489  *****************************************************************************/
490 void vout_Display( vout_thread_t *p_vout )
491 {
492     SDL_Rect    disp;
493     if((p_vout->p_sys->p_display != NULL) && !p_vout->p_sys->b_reopen_display)
494     {
495         if( p_vout->b_need_render )
496         {  
497             /* Change display frame */
498             SDL_Flip( p_vout->p_sys->p_display );
499         }
500         else
501         {
502         
503             /*
504              * p_vout->p_rendered_pic->p_y/u/v contains the YUV buffers to
505              * render 
506              */
507             /* TODO: support for streams other than 4:2:0 */
508             /* create the overlay if necessary */
509             if( p_vout->p_sys->p_overlay == NULL )
510             {
511                 p_vout->p_sys->p_overlay = SDL_CreateYUVOverlay( 
512                                              p_vout->p_rendered_pic->i_width, 
513                                              p_vout->p_rendered_pic->i_height,
514                                              SDL_YV12_OVERLAY, 
515                                              p_vout->p_sys->p_display
516                                            );
517                 intf_Msg("vout: YUV acceleration %s",
518                             p_vout->p_sys->p_overlay->hw_overlay
519                             ? "activated" : "unavailable !" ); 
520             }
521
522             SDL_LockYUVOverlay(p_vout->p_sys->p_overlay);
523             /* copy the data into video buffers */
524             /* Y first */
525             memcpy(p_vout->p_sys->p_overlay->pixels[0],
526                    p_vout->p_rendered_pic->p_y,
527                    p_vout->p_sys->p_overlay->h *
528                    p_vout->p_sys->p_overlay->pitches[0]);
529             /* then V */
530             memcpy(p_vout->p_sys->p_overlay->pixels[1],
531                    p_vout->p_rendered_pic->p_v,
532                    p_vout->p_sys->p_overlay->h *
533                    p_vout->p_sys->p_overlay->pitches[1] / 2);
534             /* and U */
535             memcpy(p_vout->p_sys->p_overlay->pixels[2],
536                    p_vout->p_rendered_pic->p_u,
537                    p_vout->p_sys->p_overlay->h *
538                    p_vout->p_sys->p_overlay->pitches[2] / 2);
539
540             disp.w = (&p_vout->p_buffer[p_vout->i_buffer_index])->i_pic_width;
541             disp.h = (&p_vout->p_buffer[p_vout->i_buffer_index])->i_pic_height;
542             disp.x = (p_vout->i_width - disp.w)/2;
543             disp.y = (p_vout->i_height - disp.h)/2;
544
545             SDL_DisplayYUVOverlay( p_vout->p_sys->p_overlay , &disp );
546             SDL_UnlockYUVOverlay(p_vout->p_sys->p_overlay);
547         }
548     }
549 }
550
551 /* following functions are local */
552
553 /*****************************************************************************
554  * SDLOpenDisplay: open and initialize SDL device
555  *****************************************************************************
556  * Open and initialize display according to preferences specified in the vout
557  * thread fields.
558  *****************************************************************************/
559 static int SDLOpenDisplay( vout_thread_t *p_vout )
560 {
561     SDL_Rect    clipping_rect;
562     Uint32      flags;
563     int bpp;
564     /* Open display 
565      * TODO: Check that we can request for a DOUBLEBUF HWSURFACE display
566      */
567
568     /* init flags and cursor */
569     flags = SDL_ANYFORMAT | SDL_HWPALETTE;
570
571     if( p_vout->p_sys->b_fullscreen )
572         flags |= SDL_FULLSCREEN;
573     else
574         flags |= SDL_RESIZABLE;
575
576     if( p_vout->b_need_render )
577         flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
578     else
579         flags |= SDL_SWSURFACE; /* save video memory */
580
581     bpp = SDL_VideoModeOK(p_vout->p_sys->i_width,
582                           p_vout->p_sys->i_height,
583                           p_vout->i_screen_depth, flags);
584
585     if(bpp == 0)
586     {
587         intf_ErrMsg( "error: can't open DISPLAY default display" );
588         return( 1 );
589     }
590
591     p_vout->p_sys->p_display = SDL_SetVideoMode(p_vout->p_sys->i_width,
592                                                 p_vout->p_sys->i_height,
593                                                 bpp, flags);
594
595     if( p_vout->p_sys->p_display == NULL )
596     {
597         intf_ErrMsg( "error: can't open DISPLAY default display" );
598         return( 1 );
599     }
600
601     SDL_LockSurface(p_vout->p_sys->p_display);
602
603     if( p_vout->p_sys->b_fullscreen )
604         SDL_ShowCursor( 0 );
605     else
606         SDL_ShowCursor( 1 );
607
608     SDL_WM_SetCaption( VOUT_TITLE , VOUT_TITLE );
609     SDL_EventState(SDL_KEYUP , SDL_IGNORE);                /* ignore keys up */
610     SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);          
611
612     if( p_vout->b_need_render )
613     {
614         p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
615         SDL_Flip(p_vout->p_sys->p_display);
616         p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
617         SDL_Flip(p_vout->p_sys->p_display);
618
619         /* Set clipping for text */
620         clipping_rect.x = 0;
621         clipping_rect.y = 0;
622         clipping_rect.w = p_vout->p_sys->p_display->w;
623         clipping_rect.h = p_vout->p_sys->p_display->h;
624         SDL_SetClipRect(p_vout->p_sys->p_display, &clipping_rect);
625
626         /* Set thread information */
627         p_vout->i_width =           p_vout->p_sys->p_display->w;
628         p_vout->i_height =          p_vout->p_sys->p_display->h;
629         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
630
631         p_vout->i_screen_depth =
632             p_vout->p_sys->p_display->format->BitsPerPixel;
633         p_vout->i_bytes_per_pixel =
634             p_vout->p_sys->p_display->format->BytesPerPixel;
635
636         p_vout->i_red_mask =        p_vout->p_sys->p_display->format->Rmask;
637         p_vout->i_green_mask =      p_vout->p_sys->p_display->format->Gmask;
638         p_vout->i_blue_mask =       p_vout->p_sys->p_display->format->Bmask;
639
640         /* FIXME: palette in 8bpp ?? */
641         /* Set and initialize buffers */
642         vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
643                                  p_vout->p_sys->p_sdl_buf[ 1 ] );
644     }
645     else
646     {
647         p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
648         p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
649
650         /* Set thread information */
651         p_vout->i_width =           p_vout->p_sys->p_display->w;
652         p_vout->i_height =          p_vout->p_sys->p_display->h;
653         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
654
655         vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
656                                  p_vout->p_sys->p_sdl_buf[ 1 ] );
657     }
658
659     p_vout->p_sys->b_reopen_display = 0;
660
661     return( 0 );
662 }
663
664 /*****************************************************************************
665  * SDLCloseDisplay: close and reset SDL device
666  *****************************************************************************
667  * This function returns all resources allocated by SDLOpenDisplay and restore
668  * the original state of the device.
669  *****************************************************************************/
670 static void SDLCloseDisplay( vout_thread_t *p_vout )
671 {
672     if( p_vout->p_sys->p_display != NULL )
673     {
674         if( p_vout->p_sys->p_overlay != NULL )
675         {            
676             SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
677             p_vout->p_sys->p_overlay = NULL;
678         }
679
680         SDL_UnlockSurface ( p_vout->p_sys->p_display );
681         SDL_FreeSurface( p_vout->p_sys->p_display );
682         p_vout->p_sys->p_display = NULL;
683     }
684 }
685