1 /*****************************************************************************
2 * sdl.c: SDL video output display method
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
5 * $Id: sdl.c,v 1.13 2003/05/05 16:09:37 gbazin Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Pierre Baillet <oct@zoy.org>
9 * Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
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.
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.
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 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <errno.h> /* ENOMEM */
30 #include <stdlib.h> /* free() */
31 #include <string.h> /* strerror() */
38 #include <sys/types.h>
40 # include <netinet/in.h> /* BSD: struct in_addr */
43 #include SDL_INCLUDE_FILE
45 #define SDL_MAX_DIRECTBUFFERS 10
46 #define SDL_DEFAULT_BPP 16
48 /*****************************************************************************
49 * vout_sys_t: video output SDL method descriptor
50 *****************************************************************************
51 * This structure is part of the video output thread descriptor.
52 * It describes the SDL specific properties of an output thread.
53 *****************************************************************************/
56 SDL_Surface * p_display; /* display device */
62 SDL_Overlay * p_overlay; /* An overlay we keep to grab the XVideo port */
68 vlc_bool_t b_cursor_autohidden;
70 mtime_t i_lastpressed; /* to track dbl-clicks */
73 /*****************************************************************************
74 * picture_sys_t: direct buffer method descriptor
75 *****************************************************************************
76 * This structure is part of the picture descriptor, it describes the
77 * SDL specific properties of a direct buffer.
78 *****************************************************************************/
81 SDL_Overlay *p_overlay;
84 /*****************************************************************************
86 *****************************************************************************/
87 static int Open ( vlc_object_t * );
88 static void Close ( vlc_object_t * );
89 static int Init ( vout_thread_t * );
90 static void End ( vout_thread_t * );
91 static int Manage ( vout_thread_t * );
92 static void Display ( vout_thread_t *, picture_t * );
94 static int OpenDisplay ( vout_thread_t * );
95 static void CloseDisplay ( vout_thread_t * );
96 static int NewPicture ( vout_thread_t *, picture_t * );
97 static void SetPalette ( vout_thread_t *,
98 uint16_t *, uint16_t *, uint16_t * );
100 /*****************************************************************************
102 *****************************************************************************/
104 set_description( _("Simple DirectMedia Layer video output") );
105 set_capability( "video output", 60 );
106 add_shortcut( "sdl" );
107 set_callbacks( Open, Close );
108 /* XXX: check for conflicts with the SDL audio output */
109 var_Create( p_module->p_libvlc, "sdl", VLC_VAR_MUTEX );
110 #if defined( __i386__ )
111 /* On i386, SDL is linked against svgalib */
112 linked_with_a_crap_library_which_uses_atexit();
116 /*****************************************************************************
117 * OpenVideo: allocate SDL video thread output method
118 *****************************************************************************
119 * This function allocate and initialize a SDL vout method. It uses some of the
120 * vout properties to choose the correct mode, and change them according to the
121 * mode actually used.
122 *****************************************************************************/
123 static int Open ( vlc_object_t *p_this )
125 vout_thread_t * p_vout = (vout_thread_t *)p_this;
132 var_Get( p_this->p_libvlc, "sdl", &lockval );
133 vlc_mutex_lock( lockval.p_address );
135 if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
137 vlc_mutex_unlock( lockval.p_address );
141 /* Allocate structure */
142 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
143 if( p_vout->p_sys == NULL )
145 msg_Err( p_vout, "out of memory" );
146 vlc_mutex_unlock( lockval.p_address );
150 p_vout->pf_init = Init;
151 p_vout->pf_end = End;
152 p_vout->pf_manage = Manage;
153 p_vout->pf_render = NULL;
154 p_vout->pf_display = Display;
157 psz_method = config_GetPsz( p_vout, "vout" );
160 while( *psz_method && *psz_method != ':' )
167 setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
172 /* Initialize library */
173 if( SDL_Init( SDL_INIT_VIDEO
175 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
176 | SDL_INIT_EVENTTHREAD
179 /* In debug mode you may want vlc to dump a core instead of staying
181 | SDL_INIT_NOPARACHUTE
185 msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() );
186 free( p_vout->p_sys );
187 vlc_mutex_unlock( lockval.p_address );
191 vlc_mutex_unlock( lockval.p_address );
193 p_vout->p_sys->b_cursor = 1;
194 p_vout->p_sys->b_cursor_autohidden = 0;
195 p_vout->p_sys->i_lastmoved = mdate();
197 if( OpenDisplay( p_vout ) )
199 msg_Err( p_vout, "cannot set up SDL (%s)", SDL_GetError() );
200 SDL_QuitSubSystem( SDL_INIT_VIDEO );
201 free( p_vout->p_sys );
208 /*****************************************************************************
209 * Init: initialize SDL video thread output method
210 *****************************************************************************
211 * This function initialize the SDL display device.
212 *****************************************************************************/
213 static int Init( vout_thread_t *p_vout )
218 p_vout->p_sys->i_surfaces = 0;
220 I_OUTPUTPICTURES = 0;
222 /* Initialize the output structure */
223 if( p_vout->p_sys->p_overlay == NULL )
225 /* All we have is an RGB image with square pixels */
226 p_vout->output.i_width = p_vout->p_sys->i_width;
227 p_vout->output.i_height = p_vout->p_sys->i_height;
228 p_vout->output.i_aspect = p_vout->output.i_width
230 / p_vout->output.i_height;
234 /* We may need to convert the chroma, but at least we keep the
236 p_vout->output.i_width = p_vout->render.i_width;
237 p_vout->output.i_height = p_vout->render.i_height;
238 p_vout->output.i_aspect = p_vout->render.i_aspect;
241 /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
242 while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
246 /* Find an empty picture slot */
247 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
249 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
251 p_pic = p_vout->p_picture + i_index;
256 /* Allocate the picture if we found one */
257 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
262 p_pic->i_status = DESTROYED_PICTURE;
263 p_pic->i_type = DIRECT_PICTURE;
265 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
273 /*****************************************************************************
274 * End: terminate Sys video thread output method
275 *****************************************************************************
276 * Terminate an output method created by OpenVideo
277 *****************************************************************************/
278 static void End( vout_thread_t *p_vout )
282 /* Free the output buffers we allocated */
283 for( i_index = I_OUTPUTPICTURES ; i_index ; )
286 if( p_vout->p_sys->p_overlay == NULL )
292 SDL_UnlockYUVOverlay(
293 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
295 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
297 free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
301 /*****************************************************************************
302 * CloseVideo: destroy Sys video thread output method
303 *****************************************************************************
304 * Terminate an output method created by vout_SDLCreate
305 *****************************************************************************/
306 static void Close ( vlc_object_t *p_this )
308 vout_thread_t * p_vout = (vout_thread_t *)p_this;
310 CloseDisplay( p_vout );
311 SDL_QuitSubSystem( SDL_INIT_VIDEO );
313 free( p_vout->p_sys );
316 /*****************************************************************************
317 * Manage: handle Sys events
318 *****************************************************************************
319 * This function should be called regularly by video output thread. It returns
320 * a non null value if an error occured.
321 *****************************************************************************/
322 static int Manage( vout_thread_t *p_vout )
324 SDL_Event event; /* SDL event */
326 int i_width, i_height, i_x, i_y;
329 while( SDL_PollEvent(&event) )
333 case SDL_VIDEORESIZE: /* Resizing of window */
334 /* Update dimensions */
335 p_vout->i_changes |= VOUT_SIZE_CHANGE;
336 p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
337 p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
340 case SDL_MOUSEMOTION:
341 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
342 p_vout->p_sys->i_height,
343 &i_x, &i_y, &i_width, &i_height );
345 val.i_int = ( event.motion.x - i_x )
346 * p_vout->render.i_width / i_width;
347 var_Set( p_vout, "mouse-x", val );
348 val.i_int = ( event.motion.y - i_y )
349 * p_vout->render.i_height / i_height;
350 var_Set( p_vout, "mouse-y", val );
352 val.b_bool = VLC_TRUE;
353 var_Set( p_vout, "mouse-moved", val );
355 if( p_vout->p_sys->b_cursor &&
356 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
358 if( p_vout->p_sys->b_cursor_autohidden )
360 p_vout->p_sys->b_cursor_autohidden = 0;
365 p_vout->p_sys->i_lastmoved = mdate();
370 case SDL_MOUSEBUTTONUP:
371 switch( event.button.button )
373 case SDL_BUTTON_LEFT:
374 val.b_bool = VLC_TRUE;
375 var_Set( p_vout, "mouse-clicked", val );
378 case SDL_BUTTON_RIGHT:
380 intf_thread_t *p_intf;
381 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
385 p_intf->b_menu_change = 1;
386 vlc_object_release( p_intf );
393 case SDL_MOUSEBUTTONDOWN:
394 switch( event.button.button )
396 case SDL_BUTTON_LEFT:
397 /* In this part we will eventually manage
398 * clicks for DVD navigation for instance. */
400 /* detect double-clicks */
401 if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
402 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
404 p_vout->p_sys->i_lastpressed = mdate();
408 input_Seek( p_vout, 15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
412 input_Seek( p_vout, -15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
418 p_vout->p_vlc->b_die = 1;
421 case SDL_KEYDOWN: /* if a key is pressed */
423 switch( event.key.keysym.sym )
426 if( p_vout->b_fullscreen )
428 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
432 p_vout->p_vlc->b_die = 1;
436 case SDLK_q: /* quit */
437 p_vout->p_vlc->b_die = 1;
440 case SDLK_f: /* switch to fullscreen */
441 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
444 case SDLK_c: /* toggle grayscale */
445 p_vout->b_grayscale = ! p_vout->b_grayscale;
446 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
449 case SDLK_i: /* toggle info */
450 p_vout->b_info = ! p_vout->b_info;
451 p_vout->i_changes |= VOUT_INFO_CHANGE;
454 case SDLK_s: /* toggle scaling */
455 p_vout->b_scale = ! p_vout->b_scale;
456 p_vout->i_changes |= VOUT_SCALE_CHANGE;
459 case SDLK_SPACE: /* toggle interface */
460 p_vout->b_interface = ! p_vout->b_interface;
461 p_vout->i_changes |= VOUT_INTF_CHANGE;
466 intf_thread_t *p_intf;
467 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
471 p_intf->b_menu_change = 1;
472 vlc_object_release( p_intf );
478 input_Seek( p_vout, -5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
482 input_Seek( p_vout, 5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
486 input_Seek( p_vout, 60, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
490 input_Seek( p_vout, -60, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
495 audio_volume_t i_volume;
496 if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
498 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
502 msg_Dbg( p_vout, "audio volume: operation not supported" );
509 audio_volume_t i_volume;
510 if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
512 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
516 msg_Dbg( p_vout, "audio volume: operation not supported" );
531 /* Fullscreen change */
532 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
534 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
536 p_vout->p_sys->b_cursor_autohidden = 0;
537 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
538 ! p_vout->p_sys->b_cursor_autohidden );
540 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
541 p_vout->i_changes |= VOUT_SIZE_CHANGE;
547 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
549 msg_Dbg( p_vout, "video display resized (%dx%d)",
550 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
552 CloseDisplay( p_vout );
553 OpenDisplay( p_vout );
555 /* We don't need to signal the vout thread about the size change if
556 * we can handle rescaling ourselves */
557 if( p_vout->p_sys->p_overlay != NULL )
558 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
563 if( ! p_vout->p_sys->b_cursor_autohidden &&
564 ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
566 /* Hide the mouse automatically */
567 p_vout->p_sys->b_cursor_autohidden = 1;
574 /*****************************************************************************
575 * Display: displays previously rendered output
576 *****************************************************************************
577 * This function sends the currently rendered image to the display.
578 *****************************************************************************/
579 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
584 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
591 if( p_vout->p_sys->p_overlay == NULL )
594 SDL_Flip( p_vout->p_sys->p_display );
598 /* Overlay picture */
599 SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
600 SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
601 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
605 /* following functions are local */
607 /*****************************************************************************
608 * OpenDisplay: open and initialize SDL device
609 *****************************************************************************
610 * Open and initialize display according to preferences specified in the vout
612 *****************************************************************************/
613 static int OpenDisplay( vout_thread_t *p_vout )
618 /* SDL fucked up fourcc definitions on bigendian machines */
619 uint32_t i_sdl_chroma;
621 /* Set main window's size */
622 p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
623 p_vout->i_window_width;
624 p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
625 p_vout->i_window_height;
627 /* Initialize flags and cursor */
628 i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
629 i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
631 i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
632 SDL_DEFAULT_BPP, i_flags );
635 msg_Err( p_vout, "no video mode available" );
639 p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
640 p_vout->p_sys->i_height,
643 if( p_vout->p_sys->p_display == NULL )
645 msg_Err( p_vout, "cannot set video mode" );
649 SDL_LockSurface( p_vout->p_sys->p_display );
651 /* Choose the chroma we will try first. */
652 switch( p_vout->render.i_chroma )
654 case VLC_FOURCC('Y','U','Y','2'):
655 case VLC_FOURCC('Y','U','N','V'):
656 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
657 i_sdl_chroma = SDL_YUY2_OVERLAY;
659 case VLC_FOURCC('U','Y','V','Y'):
660 case VLC_FOURCC('U','Y','N','V'):
661 case VLC_FOURCC('Y','4','2','2'):
662 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
663 i_sdl_chroma = SDL_UYVY_OVERLAY;
665 case VLC_FOURCC('Y','V','Y','U'):
666 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
667 i_sdl_chroma = SDL_YVYU_OVERLAY;
669 case VLC_FOURCC('Y','V','1','2'):
670 case VLC_FOURCC('I','4','2','0'):
671 case VLC_FOURCC('I','Y','U','V'):
673 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
674 i_sdl_chroma = SDL_YV12_OVERLAY;
678 p_vout->p_sys->p_overlay =
679 SDL_CreateYUVOverlay( 32, 32, i_sdl_chroma, p_vout->p_sys->p_display );
680 /* FIXME: if the first overlay we find is software, don't stop,
681 * because we may find a hardware one later ... */
683 /* If this best choice failed, fall back to other chromas */
684 if( p_vout->p_sys->p_overlay == NULL )
686 p_vout->output.i_chroma = VLC_FOURCC('I','Y','U','V');
687 p_vout->p_sys->p_overlay =
688 SDL_CreateYUVOverlay( 32, 32, SDL_IYUV_OVERLAY,
689 p_vout->p_sys->p_display );
692 if( p_vout->p_sys->p_overlay == NULL )
694 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
695 p_vout->p_sys->p_overlay =
696 SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
697 p_vout->p_sys->p_display );
700 if( p_vout->p_sys->p_overlay == NULL )
702 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
703 p_vout->p_sys->p_overlay =
704 SDL_CreateYUVOverlay( 32, 32, SDL_YUY2_OVERLAY,
705 p_vout->p_sys->p_display );
708 if( p_vout->p_sys->p_overlay == NULL )
710 msg_Warn( p_vout, "no SDL overlay for 0x%.8x (%4.4s)",
711 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma );
713 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
716 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
717 p_vout->output.pf_setpalette = SetPalette;
720 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
723 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
726 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
729 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
732 msg_Err( p_vout, "unknown screen depth %i",
733 p_vout->p_sys->p_display->format->BitsPerPixel );
734 SDL_UnlockSurface( p_vout->p_sys->p_display );
735 SDL_FreeSurface( p_vout->p_sys->p_display );
739 p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
740 p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
741 p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
743 SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
744 VOUT_TITLE " (software RGB SDL output)" );
748 if( p_vout->p_sys->p_overlay->hw_overlay )
750 SDL_WM_SetCaption( VOUT_TITLE " (hardware YUV SDL output)",
751 VOUT_TITLE " (hardware YUV SDL output)" );
755 SDL_WM_SetCaption( VOUT_TITLE " (software YUV SDL output)",
756 VOUT_TITLE " (software YUV SDL output)" );
760 SDL_EventState( SDL_KEYUP, SDL_IGNORE ); /* ignore keys up */
765 /*****************************************************************************
766 * CloseDisplay: close and reset SDL device
767 *****************************************************************************
768 * This function returns all resources allocated by OpenDisplay and restore
769 * the original state of the device.
770 *****************************************************************************/
771 static void CloseDisplay( vout_thread_t *p_vout )
773 SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
774 SDL_UnlockSurface ( p_vout->p_sys->p_display );
775 SDL_FreeSurface( p_vout->p_sys->p_display );
778 /*****************************************************************************
779 * NewPicture: allocate a picture
780 *****************************************************************************
781 * Returns 0 on success, -1 otherwise
782 *****************************************************************************/
783 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
785 int i_width = p_vout->output.i_width;
786 int i_height = p_vout->output.i_height;
788 if( p_vout->p_sys->p_overlay == NULL )
791 if( p_vout->p_sys->i_surfaces )
793 /* We already allocated this surface, return */
797 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
799 if( p_pic->p_sys == NULL )
804 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
807 p_pic->p->i_pixel_pitch = 1;
811 p_pic->p->i_pixel_pitch = 2;
815 p_pic->p->i_pixel_pitch = 4;
821 p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
822 p_pic->p->i_lines = p_vout->p_sys->p_display->h;
823 p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
824 p_pic->p->i_visible_pitch =
825 p_pic->p->i_pixel_pitch * p_vout->p_sys->p_display->w;
827 p_vout->p_sys->i_surfaces++;
833 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
835 if( p_pic->p_sys == NULL )
840 p_pic->p_sys->p_overlay =
841 SDL_CreateYUVOverlay( i_width, i_height,
842 p_vout->output.i_chroma,
843 p_vout->p_sys->p_display );
845 if( p_pic->p_sys->p_overlay == NULL )
847 free( p_pic->p_sys );
851 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
853 p_pic->Y_PIXELS = p_pic->p_sys->p_overlay->pixels[0];
854 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_overlay->h;
855 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[0];
857 switch( p_vout->output.i_chroma )
859 case SDL_YV12_OVERLAY:
860 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
861 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
863 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
864 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
865 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
866 p_pic->p[U_PLANE].i_pixel_pitch = 1;
867 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
869 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
870 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
871 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
872 p_pic->p[V_PLANE].i_pixel_pitch = 1;
873 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
878 case SDL_IYUV_OVERLAY:
879 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
880 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
882 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
883 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
884 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
885 p_pic->p[U_PLANE].i_pixel_pitch = 1;
886 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
888 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
889 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
890 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
891 p_pic->p[V_PLANE].i_pixel_pitch = 1;
892 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
898 p_pic->p[Y_PLANE].i_pixel_pitch = 2;
899 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w * 2;
909 /*****************************************************************************
910 * SetPalette: sets an 8 bpp palette
911 *****************************************************************************/
912 static void SetPalette( vout_thread_t *p_vout,
913 uint16_t *red, uint16_t *green, uint16_t *blue )
915 SDL_Color colors[256];
918 /* Fill colors with color information */
919 for( i = 0; i < 256; i++ )
921 colors[ i ].r = red[ i ] >> 8;
922 colors[ i ].g = green[ i ] >> 8;
923 colors[ i ].b = blue[ i ] >> 8;
927 if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
929 msg_Err( p_vout, "failed setting palette" );