]> git.sesse.net Git - vlc/blob - plugins/sdl/vout_sdl.c
Some heavy changes today:
[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.74 2001/12/30 07:09:56 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 YUV_420_PICTURE:
231             p_vout->output.i_chroma = p_vout->render.i_chroma;
232             p_vout->output.i_width  = p_vout->render.i_width;
233             p_vout->output.i_height = p_vout->render.i_height;
234             p_vout->output.i_aspect = p_vout->render.i_aspect;
235             break;
236
237         default:
238             /* All we have is a 16bpp image with square pixels */
239             /* FIXME: and if screen depth != 16 ?! */
240             p_vout->output.i_chroma = RGB_16BPP_PICTURE;
241             p_vout->output.i_width = p_vout->p_sys->i_width;
242             p_vout->output.i_height = p_vout->p_sys->i_height;
243             p_vout->output.i_aspect = p_vout->p_sys->i_width
244                              * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
245             break;
246     }
247
248     /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
249     while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
250     {
251         p_pic = NULL;
252
253         /* Find an empty picture slot */
254         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
255         {
256             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
257             {
258                 p_pic = p_vout->p_picture + i_index;
259                 break;
260             }
261         }
262
263         /* Allocate the picture if we found one */
264         if( p_pic == NULL || SDLNewPicture( p_vout, p_pic ) )
265         {
266             break;
267         }
268
269         p_pic->i_status        = DESTROYED_PICTURE;
270         p_pic->i_type          = DIRECT_PICTURE;
271
272         p_pic->i_left_margin   =
273         p_pic->i_right_margin  =
274         p_pic->i_top_margin    =
275         p_pic->i_bottom_margin = 0;
276
277         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
278
279         I_OUTPUTPICTURES++;
280     }
281
282     return( 0 );
283 }
284
285 /*****************************************************************************
286  * vout_End: terminate Sys video thread output method
287  *****************************************************************************
288  * Terminate an output method created by vout_SDLCreate
289  *****************************************************************************/
290 static void vout_End( vout_thread_t *p_vout )
291 {
292     int i_index;
293
294     /* Free the output buffers we allocated */
295     for( i_index = I_OUTPUTPICTURES ; i_index ; )
296     {
297         i_index--;
298         switch( p_vout->output.i_chroma )
299         {
300             case YUV_420_PICTURE:
301                 SDL_UnlockYUVOverlay(
302                         PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
303                 SDL_FreeYUVOverlay(
304                         PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
305                 break;
306
307             case RGB_16BPP_PICTURE:
308                 break;
309
310             default:
311                 break;
312         }
313         free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
314     }
315 }
316
317 /*****************************************************************************
318  * vout_Destroy: destroy Sys video thread output method
319  *****************************************************************************
320  * Terminate an output method created by vout_SDLCreate
321  *****************************************************************************/
322 static void vout_Destroy( vout_thread_t *p_vout )
323 {
324     SDLCloseDisplay( p_vout );
325
326     SDL_QuitSubSystem( SDL_INIT_VIDEO );
327
328     free( p_vout->p_sys );
329 }
330
331 static __inline__ void vout_Seek( off_t i_seek )
332 {
333 #define area p_main->p_intf->p_input->stream.p_selected_area
334     off_t i_tell = area->i_tell;
335
336     i_tell += i_seek * (off_t)50 * p_main->p_intf->p_input->stream.i_mux_rate;
337
338     i_tell = ( i_tell <= area->i_start ) ? area->i_start
339            : ( i_tell >= area->i_size ) ? area->i_size
340            : i_tell;
341
342     input_Seek( p_main->p_intf->p_input, i_tell );
343 #undef area
344 }
345
346 /*****************************************************************************
347  * vout_Manage: handle Sys events
348  *****************************************************************************
349  * This function should be called regularly by video output thread. It returns
350  * a non null value if an error occured.
351  *****************************************************************************/
352 static int vout_Manage( vout_thread_t *p_vout )
353 {
354     SDL_Event event;                                            /* SDL event */
355
356     /* Process events */
357     while( SDL_PollEvent(&event) )
358     {
359         switch( event.type )
360         {
361         case SDL_VIDEORESIZE:                          /* Resizing of window */
362             p_vout->p_sys->i_width = event.resize.w;
363             p_vout->p_sys->i_height = event.resize.h;
364             SDLCloseDisplay( p_vout );
365             SDLOpenDisplay( p_vout );
366             break;
367
368         case SDL_MOUSEMOTION:
369             if( p_vout->p_sys->b_cursor &&
370                 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
371             {
372                 if( p_vout->p_sys->b_cursor_autohidden )
373                 {
374                     p_vout->p_sys->b_cursor_autohidden = 0;
375                     SDL_ShowCursor( 1 );
376                 }
377                 else
378                 {
379                     p_vout->p_sys->i_lastmoved = mdate();
380                 }
381             }
382             break;
383
384         case SDL_MOUSEBUTTONUP:
385             switch( event.button.button )
386             {
387             case SDL_BUTTON_RIGHT:
388                 p_main->p_intf->b_menu_change = 1;
389                 break;
390             }
391             break;
392
393         case SDL_MOUSEBUTTONDOWN:
394             switch( event.button.button )
395             {
396             case SDL_BUTTON_LEFT:
397                 /* In this part we will eventually manage
398                  * clicks for DVD navigation for instance. For the
399                  * moment just pause the stream. */
400                 input_SetStatus( p_main->p_intf->p_input, INPUT_STATUS_PAUSE );
401                 break;
402
403             case 4:
404                 vout_Seek( 15 );
405                 break;
406
407             case 5:
408                 vout_Seek( -15 );
409                 break;
410             }
411             break;
412
413         case SDL_QUIT:
414             p_main->p_intf->b_die = 1;
415             break;
416
417         case SDL_KEYDOWN:                             /* if a key is pressed */
418
419             switch( event.key.keysym.sym )
420             {
421             case SDLK_q:                                             /* quit */
422             case SDLK_ESCAPE:
423                 p_main->p_intf->b_die = 1;
424                 break;
425
426             case SDLK_f:                             /* switch to fullscreen */
427                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
428                 break;
429
430             case SDLK_c:                                 /* toggle grayscale */
431                 p_vout->b_grayscale = ! p_vout->b_grayscale;
432                 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
433                 break;
434
435             case SDLK_i:                                      /* toggle info */
436                 p_vout->b_info = ! p_vout->b_info;
437                 p_vout->i_changes |= VOUT_INFO_CHANGE;
438                 break;
439
440             case SDLK_s:                                   /* toggle scaling */
441                 p_vout->b_scale = ! p_vout->b_scale;
442                 p_vout->i_changes |= VOUT_SCALE_CHANGE;
443                 break;
444
445             case SDLK_SPACE:                             /* toggle interface */
446                 p_vout->b_interface = ! p_vout->b_interface;
447                 p_vout->i_changes |= VOUT_INTF_CHANGE;
448                 break;
449             
450             case SDLK_MENU:
451                 p_main->p_intf->b_menu_change = 1;
452                 break;
453
454             case SDLK_LEFT:
455                 vout_Seek( -5 );
456                 break;
457
458             case SDLK_RIGHT:
459                 vout_Seek( 5 );
460                 break;
461
462             case SDLK_UP:
463                 vout_Seek( 60 );
464                 break;
465
466             case SDLK_DOWN:
467                 vout_Seek( -60 );
468                 break;
469
470             case SDLK_F10: network_ChannelJoin( 0 ); break;
471             case SDLK_F1:  network_ChannelJoin( 1 ); break;
472             case SDLK_F2:  network_ChannelJoin( 2 ); break;
473             case SDLK_F3:  network_ChannelJoin( 3 ); break;
474             case SDLK_F4:  network_ChannelJoin( 4 ); break;
475             case SDLK_F5:  network_ChannelJoin( 5 ); break;
476             case SDLK_F6:  network_ChannelJoin( 6 ); break;
477             case SDLK_F7:  network_ChannelJoin( 7 ); break;
478             case SDLK_F8:  network_ChannelJoin( 8 ); break;
479             case SDLK_F9:  network_ChannelJoin( 9 ); break;
480
481             default:
482                 intf_DbgMsg( "unhandled key %i", event.key.keysym.sym );
483                 break;
484             }
485             break;
486
487         default:
488             break;
489         }
490     }
491
492     /* Fullscreen change */
493     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
494     {
495         p_vout->b_fullscreen = ! p_vout->b_fullscreen;
496
497         SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
498
499         p_vout->p_sys->b_cursor_autohidden = 0;
500         SDL_ShowCursor( p_vout->p_sys->b_cursor &&
501                         ! p_vout->p_sys->b_cursor_autohidden );
502
503         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
504     }
505
506     /* Pointer change */
507     if( ! p_vout->p_sys->b_cursor_autohidden &&
508         ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
509     {
510         /* Hide the mouse automatically */
511         p_vout->p_sys->b_cursor_autohidden = 1;
512         SDL_ShowCursor( 0 );
513     }
514
515     return( 0 );
516 }
517
518 /*****************************************************************************
519  * vout_Display: displays previously rendered output
520  *****************************************************************************
521  * This function sends the currently rendered image to the display.
522  *****************************************************************************/
523 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
524 {
525     int x, y, w, h;
526     SDL_Rect disp;
527
528     vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
529                        &x, &y, &w, &h );
530     disp.x = x;
531     disp.y = y;
532     disp.w = w;
533     disp.h = h;
534
535     switch( p_vout->output.i_chroma )
536     {
537         case RGB_16BPP_PICTURE:
538             SDL_Flip(p_vout->p_sys->p_display);
539             break;
540
541         case YUV_420_PICTURE:
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             break;
549     }
550 }
551
552 /* following functions are local */
553
554 /*****************************************************************************
555  * SDLOpenDisplay: open and initialize SDL device
556  *****************************************************************************
557  * Open and initialize display according to preferences specified in the vout
558  * thread fields.
559  *****************************************************************************/
560 static int SDLOpenDisplay( vout_thread_t *p_vout )
561 {
562     Uint32 i_flags;
563     int    i_bpp;
564
565     /* Initialize flags and cursor */
566     i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
567     i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
568
569     i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
570                              SDL_DEFAULT_BPP, i_flags );
571     if( i_bpp == 0 )
572     {
573         intf_ErrMsg( "vout error: no video mode available" );
574         return( 1 );
575     }
576
577     p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
578                                                  p_vout->p_sys->i_height,
579                                                  i_bpp, i_flags );
580
581     if( p_vout->p_sys->p_display == NULL )
582     {
583         intf_ErrMsg( "vout error: cannot set video mode" );
584         return( 1 );
585     }
586
587     SDL_LockSurface( p_vout->p_sys->p_display );
588
589     p_vout->p_sys->p_overlay =
590         SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
591                               p_vout->p_sys->p_display );
592
593     if( p_vout->p_sys->p_overlay == NULL )
594     {
595         intf_ErrMsg( "vout error: cannot set overlay" );
596         SDL_UnlockSurface( p_vout->p_sys->p_display );
597         SDL_FreeSurface( p_vout->p_sys->p_display );
598         return( 1 );
599     }
600
601     if( p_vout->p_sys->p_overlay->hw_overlay )
602     {
603         SDL_WM_SetCaption( VOUT_TITLE " (hardware SDL output)",
604                            VOUT_TITLE " (hardware SDL output)" );
605     }
606     else
607     {
608         SDL_WM_SetCaption( VOUT_TITLE " (software SDL output)",
609                            VOUT_TITLE " (software SDL output)" );
610     }
611
612     SDL_EventState( SDL_KEYUP, SDL_IGNORE );               /* ignore keys up */
613
614     return( 0 );
615 }
616
617 /*****************************************************************************
618  * SDLCloseDisplay: close and reset SDL device
619  *****************************************************************************
620  * This function returns all resources allocated by SDLOpenDisplay and restore
621  * the original state of the device.
622  *****************************************************************************/
623 static void SDLCloseDisplay( vout_thread_t *p_vout )
624 {
625     SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
626     SDL_UnlockSurface ( p_vout->p_sys->p_display );
627     SDL_FreeSurface( p_vout->p_sys->p_display );
628 }
629
630 /*****************************************************************************
631  * SDLNewPicture: allocate a picture
632  *****************************************************************************
633  * Returns 0 on success, -1 otherwise
634  *****************************************************************************/
635 static int SDLNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
636 {
637 #define P p_pic->planes
638     int i_width  = p_vout->output.i_width;
639     int i_height = p_vout->output.i_height;
640
641     switch( p_vout->output.i_chroma )
642     {
643         case RGB_16BPP_PICTURE:
644             if( p_vout->p_sys->i_surfaces )
645             {
646                 /* We already allocated this surface, return */
647                 return -1;
648             }
649
650             p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
651
652             if( p_pic->p_sys == NULL )
653             {
654                 return -1;
655             }
656
657             P[ RGB_PLANE ].p_data = p_vout->p_sys->p_display->pixels;
658             P[ RGB_PLANE ].i_bytes = 2 * i_width * i_height;
659             P[ RGB_PLANE ].i_line_bytes = 2 * i_width;
660
661             p_vout->p_sys->i_surfaces++;
662
663             p_pic->i_planes = 1;
664
665             return 0;
666
667         case YUV_420_PICTURE:
668             p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
669
670             if( p_pic->p_sys == NULL )
671             {
672                 return -1;
673             }
674
675             p_pic->p_sys->p_overlay =
676                 SDL_CreateYUVOverlay( i_width, i_height,
677                                       SDL_YV12_OVERLAY,
678                                       p_vout->p_sys->p_display );
679
680             if( p_pic->p_sys->p_overlay == NULL )
681             {
682                 free( p_pic->p_sys );
683                 return -1;
684             }
685
686             SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
687
688             /* FIXME: try to get the right i_bytes value from p_overlay */
689             P[ Y_PLANE ].p_data = p_pic->p_sys->p_overlay->pixels[ 0 ];
690             P[ Y_PLANE ].i_bytes = i_width * i_height;
691             P[ Y_PLANE ].i_line_bytes = i_width;
692
693             P[ U_PLANE ].p_data = p_pic->p_sys->p_overlay->pixels[ 2 ];
694             P[ U_PLANE ].i_bytes = i_width * i_height / 4;
695             P[ U_PLANE ].i_line_bytes = i_width / 2;
696
697             P[ V_PLANE ].p_data = p_pic->p_sys->p_overlay->pixels[ 1 ];
698             P[ V_PLANE ].i_bytes = i_width * i_height / 4;
699             P[ V_PLANE ].i_line_bytes = i_width / 2;
700
701             p_pic->i_planes = 3;
702
703             return 0;
704
705         default:
706             /* Unknown chroma, tell the guy to get lost */
707             p_pic->i_planes = 0;
708
709             return -1;
710     }
711 #undef P
712 }
713