]> git.sesse.net Git - vlc/blob - plugins/sdl/vout_sdl.c
1105c1362b00677b6ce88005553457122af0bf2e
[vlc] / plugins / sdl / vout_sdl.c
1 /*****************************************************************************
2  * vout_sdl.c: SDL video output display method
3  *****************************************************************************
4  * Copyright (C) 1998-2001 VideoLAN
5  * $Id: vout_sdl.c,v 1.75 2002/01/02 14:37:42 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Pierre Baillet <oct@zoy.org>
9  *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <errno.h>                                                 /* ENOMEM */
30 #include <stdlib.h>                                                /* free() */
31 #include <string.h>                                            /* strerror() */
32
33 #include <videolan/vlc.h>
34
35 #include <sys/types.h>
36 #ifndef WIN32
37 #   include <netinet/in.h>                            /* BSD: struct in_addr */
38 #endif
39
40 #include SDL_INCLUDE_FILE
41
42 #include "netutils.h"
43
44 #include "video.h"
45 #include "video_output.h"
46
47 #include "interface.h"
48
49 #include "stream_control.h"                 /* needed by input_ext-intf.h... */
50 #include "input_ext-intf.h"
51
52 #define SDL_MAX_DIRECTBUFFERS 5
53 #define SDL_DEFAULT_BPP 16
54
55 /*****************************************************************************
56  * vout_sys_t: video output SDL method descriptor
57  *****************************************************************************
58  * This structure is part of the video output thread descriptor.
59  * It describes the SDL specific properties of an output thread.
60  *****************************************************************************/
61 typedef struct vout_sys_s
62 {
63     SDL_Surface *   p_display;                             /* display device */
64     SDL_Overlay *   p_overlay; /* An overlay we keep to grab the XVideo port */
65
66     int i_width;
67     int i_height;
68
69     int i_surfaces;
70
71     boolean_t   b_cursor;
72     boolean_t   b_cursor_autohidden;
73     mtime_t     i_lastmoved;
74
75 } vout_sys_t;
76
77 /*****************************************************************************
78  * picture_sys_t: direct buffer method descriptor
79  *****************************************************************************
80  * This structure is part of the picture descriptor, it describes the
81  * SDL specific properties of a direct buffer.
82  *****************************************************************************/
83 typedef struct picture_sys_s
84 {
85     SDL_Overlay *p_overlay;
86
87 } picture_sys_t;
88
89 /*****************************************************************************
90  * Local prototypes.
91  *****************************************************************************/
92 static int  vout_Probe      ( probedata_t *p_data );
93 static int  vout_Create     ( struct vout_thread_s * );
94 static int  vout_Init       ( struct vout_thread_s * );
95 static void vout_End        ( struct vout_thread_s * );
96 static void vout_Destroy    ( struct vout_thread_s * );
97 static int  vout_Manage     ( struct vout_thread_s * );
98 static void vout_Display    ( struct vout_thread_s *, struct picture_s * );
99
100 static int  SDLOpenDisplay      ( vout_thread_t *p_vout );
101 static void SDLCloseDisplay     ( vout_thread_t *p_vout );
102 static int  SDLNewPicture       ( vout_thread_t *p_vout, picture_t *p_pic );
103
104 /*****************************************************************************
105  * Functions exported as capabilities. They are declared as static so that
106  * we don't pollute the namespace too much.
107  *****************************************************************************/
108 void _M( vout_getfunctions )( function_list_t * p_function_list )
109 {
110     p_function_list->pf_probe = vout_Probe;
111     p_function_list->functions.vout.pf_create     = vout_Create;
112     p_function_list->functions.vout.pf_init       = vout_Init;
113     p_function_list->functions.vout.pf_end        = vout_End;
114     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
115     p_function_list->functions.vout.pf_manage     = vout_Manage;
116     p_function_list->functions.vout.pf_display    = vout_Display;
117     p_function_list->functions.vout.pf_setpalette = NULL;
118 }
119
120 /*****************************************************************************
121  * vout_Probe: probe the video driver and return a score
122  *****************************************************************************
123  * This function tries to initialize SDL and returns a score to the
124  * plugin manager so that it can select the best plugin.
125  *****************************************************************************/
126 static int vout_Probe( probedata_t *p_data )
127 {
128     if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
129     {
130         return( 0 );
131     }
132
133     return( 100 );
134 }
135
136 /*****************************************************************************
137  * vout_Create: allocate SDL video thread output method
138  *****************************************************************************
139  * This function allocate and initialize a SDL vout method. It uses some of the
140  * vout properties to choose the correct mode, and change them according to the
141  * mode actually used.
142  *****************************************************************************/
143 static int vout_Create( vout_thread_t *p_vout )
144 {
145     /* Allocate structure */
146     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
147     if( p_vout->p_sys == NULL )
148     {
149         intf_ErrMsg( "vout error: can't create p_sys (%s)", strerror(ENOMEM) );
150         return( 1 );
151     }
152
153     /* Initialize library */
154     if( SDL_Init( SDL_INIT_VIDEO
155 #ifndef WIN32
156     /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
157                 | SDL_INIT_EVENTTHREAD
158 #endif
159 #ifdef DEBUG
160     /* In debug mode you may want vlc to dump a core instead of staying
161      * stuck */
162                 | SDL_INIT_NOPARACHUTE
163 #endif
164                 ) < 0 )
165     {
166         intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
167         free( p_vout->p_sys );
168         return( 1 );
169     }
170
171     p_vout->p_sys->b_cursor = 1; /* TODO should be done with a main_GetInt.. */
172     p_vout->p_sys->b_cursor_autohidden = 0;
173     p_vout->p_sys->i_lastmoved = mdate();
174
175     if( p_vout->render.i_height * p_vout->render.i_aspect
176          >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
177     {
178         p_vout->p_sys->i_width = p_vout->render.i_height
179             * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
180         p_vout->p_sys->i_height = p_vout->render.i_height;
181     }
182     else
183     {
184         p_vout->p_sys->i_width = p_vout->render.i_width;
185         p_vout->p_sys->i_height = p_vout->render.i_width
186             * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;
187     }
188
189 #if 0
190     if( p_vout->p_sys->i_width <= 300 && p_vout->p_sys->i_height <= 300 )
191     {
192         p_vout->p_sys->i_width <<= 1;
193         p_vout->p_sys->i_height <<= 1;
194     }
195     else if( p_vout->p_sys->i_width <= 400 && p_vout->p_sys->i_height <= 400 )
196     {
197         p_vout->p_sys->i_width += p_vout->p_sys->i_width >> 1;
198         p_vout->p_sys->i_height += p_vout->p_sys->i_height >> 1;
199     }
200 #endif
201
202     if( SDLOpenDisplay( p_vout ) )
203     {
204         intf_ErrMsg( "vout error: can't set up SDL (%s)", SDL_GetError() );
205         SDL_QuitSubSystem( SDL_INIT_VIDEO );
206         free( p_vout->p_sys );
207         return( 1 );
208     }
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 static int vout_Init( vout_thread_t *p_vout )
219 {
220     int i_index;
221     picture_t *p_pic;
222
223     p_vout->p_sys->i_surfaces = 0;
224
225     I_OUTPUTPICTURES = 0;
226
227     /* Initialize the output structure */
228     switch( p_vout->render.i_chroma )
229     {
230         case FOURCC_I420:
231         case FOURCC_IYUV:
232         case FOURCC_YV12:
233             p_vout->output.i_chroma = p_vout->render.i_chroma;
234             p_vout->output.i_width  = p_vout->render.i_width;
235             p_vout->output.i_height = p_vout->render.i_height;
236             p_vout->output.i_aspect = p_vout->render.i_aspect;
237             break;
238
239         default:
240             /* All we have is a 16bpp image with square pixels */
241             /* FIXME: and if screen depth != 16 ?! */
242             p_vout->output.i_chroma = FOURCC_BI_BITFIELDS | DEPTH_16BPP;
243             p_vout->output.i_width = p_vout->p_sys->i_width;
244             p_vout->output.i_height = p_vout->p_sys->i_height;
245             p_vout->output.i_aspect = p_vout->p_sys->i_width
246                              * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
247             break;
248     }
249
250     /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
251     while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
252     {
253         p_pic = NULL;
254
255         /* Find an empty picture slot */
256         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
257         {
258             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
259             {
260                 p_pic = p_vout->p_picture + i_index;
261                 break;
262             }
263         }
264
265         /* Allocate the picture if we found one */
266         if( p_pic == NULL || SDLNewPicture( p_vout, p_pic ) )
267         {
268             break;
269         }
270
271         p_pic->i_status        = DESTROYED_PICTURE;
272         p_pic->i_type          = DIRECT_PICTURE;
273
274         p_pic->i_left_margin   =
275         p_pic->i_right_margin  =
276         p_pic->i_top_margin    =
277         p_pic->i_bottom_margin = 0;
278
279         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
280
281         I_OUTPUTPICTURES++;
282     }
283
284     return( 0 );
285 }
286
287 /*****************************************************************************
288  * vout_End: terminate Sys video thread output method
289  *****************************************************************************
290  * Terminate an output method created by vout_SDLCreate
291  *****************************************************************************/
292 static void vout_End( vout_thread_t *p_vout )
293 {
294     int i_index;
295
296     /* Free the output buffers we allocated */
297     for( i_index = I_OUTPUTPICTURES ; i_index ; )
298     {
299         i_index--;
300         switch( p_vout->output.i_chroma )
301         {
302             case FOURCC_I420:
303             case FOURCC_IYUV:
304             case FOURCC_YV12:
305                 SDL_UnlockYUVOverlay(
306                         PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
307                 SDL_FreeYUVOverlay(
308                         PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
309                 break;
310
311             default:
312                 /* RGB picture */
313                 break;
314         }
315         free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
316     }
317 }
318
319 /*****************************************************************************
320  * vout_Destroy: destroy Sys video thread output method
321  *****************************************************************************
322  * Terminate an output method created by vout_SDLCreate
323  *****************************************************************************/
324 static void vout_Destroy( vout_thread_t *p_vout )
325 {
326     SDLCloseDisplay( p_vout );
327
328     SDL_QuitSubSystem( SDL_INIT_VIDEO );
329
330     free( p_vout->p_sys );
331 }
332
333 static __inline__ void vout_Seek( off_t i_seek )
334 {
335 #define area p_main->p_intf->p_input->stream.p_selected_area
336     off_t i_tell = area->i_tell;
337
338     i_tell += i_seek * (off_t)50 * p_main->p_intf->p_input->stream.i_mux_rate;
339
340     i_tell = ( i_tell <= area->i_start ) ? area->i_start
341            : ( i_tell >= area->i_size ) ? area->i_size
342            : i_tell;
343
344     input_Seek( p_main->p_intf->p_input, i_tell );
345 #undef area
346 }
347
348 /*****************************************************************************
349  * vout_Manage: handle Sys events
350  *****************************************************************************
351  * This function should be called regularly by video output thread. It returns
352  * a non null value if an error occured.
353  *****************************************************************************/
354 static int vout_Manage( vout_thread_t *p_vout )
355 {
356     SDL_Event event;                                            /* SDL event */
357
358     /* Process events */
359     while( SDL_PollEvent(&event) )
360     {
361         switch( event.type )
362         {
363         case SDL_VIDEORESIZE:                          /* Resizing of window */
364             p_vout->p_sys->i_width = event.resize.w;
365             p_vout->p_sys->i_height = event.resize.h;
366             SDLCloseDisplay( p_vout );
367             SDLOpenDisplay( p_vout );
368             break;
369
370         case SDL_MOUSEMOTION:
371             if( p_vout->p_sys->b_cursor &&
372                 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
373             {
374                 if( p_vout->p_sys->b_cursor_autohidden )
375                 {
376                     p_vout->p_sys->b_cursor_autohidden = 0;
377                     SDL_ShowCursor( 1 );
378                 }
379                 else
380                 {
381                     p_vout->p_sys->i_lastmoved = mdate();
382                 }
383             }
384             break;
385
386         case SDL_MOUSEBUTTONUP:
387             switch( event.button.button )
388             {
389             case SDL_BUTTON_RIGHT:
390                 p_main->p_intf->b_menu_change = 1;
391                 break;
392             }
393             break;
394
395         case SDL_MOUSEBUTTONDOWN:
396             switch( event.button.button )
397             {
398             case SDL_BUTTON_LEFT:
399                 /* In this part we will eventually manage
400                  * clicks for DVD navigation for instance. For the
401                  * moment just pause the stream. */
402                 input_SetStatus( p_main->p_intf->p_input, INPUT_STATUS_PAUSE );
403                 break;
404
405             case 4:
406                 vout_Seek( 15 );
407                 break;
408
409             case 5:
410                 vout_Seek( -15 );
411                 break;
412             }
413             break;
414
415         case SDL_QUIT:
416             p_main->p_intf->b_die = 1;
417             break;
418
419         case SDL_KEYDOWN:                             /* if a key is pressed */
420
421             switch( event.key.keysym.sym )
422             {
423             case SDLK_q:                                             /* quit */
424             case SDLK_ESCAPE:
425                 p_main->p_intf->b_die = 1;
426                 break;
427
428             case SDLK_f:                             /* switch to fullscreen */
429                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
430                 break;
431
432             case SDLK_c:                                 /* toggle grayscale */
433                 p_vout->b_grayscale = ! p_vout->b_grayscale;
434                 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
435                 break;
436
437             case SDLK_i:                                      /* toggle info */
438                 p_vout->b_info = ! p_vout->b_info;
439                 p_vout->i_changes |= VOUT_INFO_CHANGE;
440                 break;
441
442             case SDLK_s:                                   /* toggle scaling */
443                 p_vout->b_scale = ! p_vout->b_scale;
444                 p_vout->i_changes |= VOUT_SCALE_CHANGE;
445                 break;
446
447             case SDLK_SPACE:                             /* toggle interface */
448                 p_vout->b_interface = ! p_vout->b_interface;
449                 p_vout->i_changes |= VOUT_INTF_CHANGE;
450                 break;
451             
452             case SDLK_MENU:
453                 p_main->p_intf->b_menu_change = 1;
454                 break;
455
456             case SDLK_LEFT:
457                 vout_Seek( -5 );
458                 break;
459
460             case SDLK_RIGHT:
461                 vout_Seek( 5 );
462                 break;
463
464             case SDLK_UP:
465                 vout_Seek( 60 );
466                 break;
467
468             case SDLK_DOWN:
469                 vout_Seek( -60 );
470                 break;
471
472             case SDLK_F10: network_ChannelJoin( 0 ); break;
473             case SDLK_F1:  network_ChannelJoin( 1 ); break;
474             case SDLK_F2:  network_ChannelJoin( 2 ); break;
475             case SDLK_F3:  network_ChannelJoin( 3 ); break;
476             case SDLK_F4:  network_ChannelJoin( 4 ); break;
477             case SDLK_F5:  network_ChannelJoin( 5 ); break;
478             case SDLK_F6:  network_ChannelJoin( 6 ); break;
479             case SDLK_F7:  network_ChannelJoin( 7 ); break;
480             case SDLK_F8:  network_ChannelJoin( 8 ); break;
481             case SDLK_F9:  network_ChannelJoin( 9 ); break;
482
483             default:
484                 intf_DbgMsg( "unhandled key %i", event.key.keysym.sym );
485                 break;
486             }
487             break;
488
489         default:
490             break;
491         }
492     }
493
494     /* Fullscreen change */
495     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
496     {
497         p_vout->b_fullscreen = ! p_vout->b_fullscreen;
498
499         SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
500
501         p_vout->p_sys->b_cursor_autohidden = 0;
502         SDL_ShowCursor( p_vout->p_sys->b_cursor &&
503                         ! p_vout->p_sys->b_cursor_autohidden );
504
505         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
506     }
507
508     /* Pointer change */
509     if( ! p_vout->p_sys->b_cursor_autohidden &&
510         ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
511     {
512         /* Hide the mouse automatically */
513         p_vout->p_sys->b_cursor_autohidden = 1;
514         SDL_ShowCursor( 0 );
515     }
516
517     return( 0 );
518 }
519
520 /*****************************************************************************
521  * vout_Display: displays previously rendered output
522  *****************************************************************************
523  * This function sends the currently rendered image to the display.
524  *****************************************************************************/
525 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
526 {
527     int x, y, w, h;
528     SDL_Rect disp;
529
530     vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
531                        &x, &y, &w, &h );
532     disp.x = x;
533     disp.y = y;
534     disp.w = w;
535     disp.h = h;
536
537     switch( p_vout->output.i_chroma )
538     {
539         case FOURCC_I420:
540         case FOURCC_IYUV:
541         case FOURCC_YV12:
542             SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
543             SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
544             SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
545             break;
546
547         default:
548             /* RGB picture */
549             SDL_Flip(p_vout->p_sys->p_display);
550             break;
551     }
552 }
553
554 /* following functions are local */
555
556 /*****************************************************************************
557  * SDLOpenDisplay: open and initialize SDL device
558  *****************************************************************************
559  * Open and initialize display according to preferences specified in the vout
560  * thread fields.
561  *****************************************************************************/
562 static int SDLOpenDisplay( vout_thread_t *p_vout )
563 {
564     Uint32 i_flags;
565     int    i_bpp;
566
567     /* Initialize flags and cursor */
568     i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
569     i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
570
571     i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
572                              SDL_DEFAULT_BPP, i_flags );
573     if( i_bpp == 0 )
574     {
575         intf_ErrMsg( "vout error: no video mode available" );
576         return( 1 );
577     }
578
579     p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
580                                                  p_vout->p_sys->i_height,
581                                                  i_bpp, i_flags );
582
583     if( p_vout->p_sys->p_display == NULL )
584     {
585         intf_ErrMsg( "vout error: cannot set video mode" );
586         return( 1 );
587     }
588
589     SDL_LockSurface( p_vout->p_sys->p_display );
590
591     p_vout->p_sys->p_overlay =
592         SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
593                               p_vout->p_sys->p_display );
594
595     if( p_vout->p_sys->p_overlay == NULL )
596     {
597         intf_ErrMsg( "vout error: cannot set overlay" );
598         SDL_UnlockSurface( p_vout->p_sys->p_display );
599         SDL_FreeSurface( p_vout->p_sys->p_display );
600         return( 1 );
601     }
602
603     if( p_vout->p_sys->p_overlay->hw_overlay )
604     {
605         SDL_WM_SetCaption( VOUT_TITLE " (hardware SDL output)",
606                            VOUT_TITLE " (hardware SDL output)" );
607     }
608     else
609     {
610         SDL_WM_SetCaption( VOUT_TITLE " (software SDL output)",
611                            VOUT_TITLE " (software SDL output)" );
612     }
613
614     SDL_EventState( SDL_KEYUP, SDL_IGNORE );               /* ignore keys up */
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     SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
628     SDL_UnlockSurface ( p_vout->p_sys->p_display );
629     SDL_FreeSurface( p_vout->p_sys->p_display );
630 }
631
632 /*****************************************************************************
633  * SDLNewPicture: allocate a picture
634  *****************************************************************************
635  * Returns 0 on success, -1 otherwise
636  *****************************************************************************/
637 static int SDLNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
638 {
639 #define P p_pic->planes
640     int i_width  = p_vout->output.i_width;
641     int i_height = p_vout->output.i_height;
642
643     switch( p_vout->output.i_chroma )
644     {
645         case FOURCC_I420:
646         case FOURCC_IYUV:
647         case FOURCC_YV12:
648             p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
649
650             if( p_pic->p_sys == NULL )
651             {
652                 return -1;
653             }
654
655             p_pic->p_sys->p_overlay =
656                 SDL_CreateYUVOverlay( i_width, i_height,
657                                       SDL_YV12_OVERLAY,
658                                       p_vout->p_sys->p_display );
659
660             if( p_pic->p_sys->p_overlay == NULL )
661             {
662                 free( p_pic->p_sys );
663                 return -1;
664             }
665
666             SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
667
668             /* FIXME: try to get the right i_bytes value from p_overlay */
669             P[ Y_PLANE ].p_data = p_pic->p_sys->p_overlay->pixels[ 0 ];
670             P[ Y_PLANE ].i_bytes = i_width * i_height;
671             P[ Y_PLANE ].i_line_bytes = i_width;
672
673             P[ U_PLANE ].p_data = p_pic->p_sys->p_overlay->pixels[ 2 ];
674             P[ U_PLANE ].i_bytes = i_width * i_height / 4;
675             P[ U_PLANE ].i_line_bytes = i_width / 2;
676
677             P[ V_PLANE ].p_data = p_pic->p_sys->p_overlay->pixels[ 1 ];
678             P[ V_PLANE ].i_bytes = i_width * i_height / 4;
679             P[ V_PLANE ].i_line_bytes = i_width / 2;
680
681             p_pic->i_planes = 3;
682
683             return 0;
684
685         case FOURCC_BI_BITFIELDS | DEPTH_16BPP:
686             if( p_vout->p_sys->i_surfaces )
687             {
688                 /* We already allocated this surface, return */
689                 return -1;
690             }
691
692             p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
693
694             if( p_pic->p_sys == NULL )
695             {
696                 return -1;
697             }
698
699             P[ MAIN_PLANE ].p_data = p_vout->p_sys->p_display->pixels;
700             P[ MAIN_PLANE ].i_bytes = 2 * i_width * i_height;
701             P[ MAIN_PLANE ].i_line_bytes = 2 * i_width;
702
703             p_vout->p_sys->i_surfaces++;
704
705             p_pic->i_planes = 1;
706
707             return 0;
708
709         default:
710             /* Unknown chroma, tell the guy to get lost */
711             p_pic->i_planes = 0;
712
713             return -1;
714     }
715 #undef P
716 }
717