1 /*****************************************************************************
2 * sdl.c: SDL video output display method
3 *****************************************************************************
4 * Copyright (C) 1998-2001 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <errno.h> /* ENOMEM */
32 #include <vlc_interface.h>
36 #include <sys/types.h>
38 # include <netinet/in.h> /* BSD: struct in_addr */
41 #include SDL_INCLUDE_FILE
43 /* SDL is not able to crop overlays - so use only 1 direct buffer */
44 #define SDL_MAX_DIRECTBUFFERS 1
45 #define SDL_DEFAULT_BPP 16
47 /*****************************************************************************
48 * vout_sys_t: video output SDL method descriptor
49 *****************************************************************************
50 * This structure is part of the video output thread descriptor.
51 * It describes the SDL specific properties of an output thread.
52 *****************************************************************************/
55 SDL_Surface * p_display; /* display device */
61 SDL_Overlay * p_overlay; /* An overlay we keep to grab the XVideo port */
67 vlc_bool_t b_cursor_autohidden;
69 mtime_t i_lastpressed; /* to track dbl-clicks */
72 /*****************************************************************************
73 * picture_sys_t: direct buffer method descriptor
74 *****************************************************************************
75 * This structure is part of the picture descriptor, it describes the
76 * SDL specific properties of a direct buffer.
77 *****************************************************************************/
80 SDL_Overlay *p_overlay;
83 /*****************************************************************************
85 *****************************************************************************/
86 static int Open ( vlc_object_t * );
87 static void Close ( vlc_object_t * );
88 static int Init ( vout_thread_t * );
89 static void End ( vout_thread_t * );
90 static int Manage ( vout_thread_t * );
91 static void Display ( vout_thread_t *, picture_t * );
93 static int OpenDisplay ( vout_thread_t * );
94 static void CloseDisplay ( vout_thread_t * );
95 static int NewPicture ( vout_thread_t *, picture_t * );
96 static void SetPalette ( vout_thread_t *,
97 uint16_t *, uint16_t *, uint16_t * );
99 #define CHROMA_TEXT N_("SDL chroma format")
100 #define CHROMA_LONGTEXT N_( \
101 "Force the SDL renderer to use a specific chroma format instead of " \
102 "trying to improve performances by using the most efficient one.")
104 /*****************************************************************************
106 *****************************************************************************/
108 set_shortname( "SDL" );
109 set_category( CAT_VIDEO );
110 set_subcategory( SUBCAT_VIDEO_VOUT );
111 set_description( _("Simple DirectMedia Layer video output") );
112 set_capability( "video output", 60 );
113 add_shortcut( "sdl" );
114 add_string( "sdl-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, VLC_TRUE );
115 set_callbacks( Open, Close );
116 #if defined( __i386__ ) || defined( __x86_64__ )
117 /* On i386, SDL is linked against svgalib */
118 linked_with_a_crap_library_which_uses_atexit();
122 /*****************************************************************************
123 * OpenVideo: allocate SDL video thread output method
124 *****************************************************************************
125 * This function allocate and initialize a SDL vout method. It uses some of the
126 * vout properties to choose the correct mode, and change them according to the
127 * mode actually used.
128 *****************************************************************************/
129 static int Open ( vlc_object_t *p_this )
131 vout_thread_t * p_vout = (vout_thread_t *)p_this;
132 /* XXX: check for conflicts with the SDL audio output */
133 vlc_mutex_t *lock = var_AcquireMutex( "sdl" );
142 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
143 if( p_vout->p_sys == NULL )
145 vlc_mutex_unlock( lock );
149 if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
151 vlc_mutex_unlock( lock );
152 free( p_vout->p_sys );
156 /* Allocate structure */
158 p_vout->pf_init = Init;
159 p_vout->pf_end = End;
160 p_vout->pf_manage = Manage;
161 p_vout->pf_render = NULL;
162 p_vout->pf_display = Display;
165 psz_method = config_GetPsz( p_vout, "vout" );
168 while( *psz_method && *psz_method != ':' )
175 setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
180 /* Initialize library */
181 if( SDL_Init( SDL_INIT_VIDEO
183 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
184 | SDL_INIT_EVENTTHREAD
187 /* In debug mode you may want vlc to dump a core instead of staying
189 | SDL_INIT_NOPARACHUTE
193 msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() );
194 free( p_vout->p_sys );
195 vlc_mutex_unlock( lock );
199 vlc_mutex_unlock( lock );
201 p_vout->p_sys->b_cursor = 1;
202 p_vout->p_sys->b_cursor_autohidden = 0;
203 p_vout->p_sys->i_lastmoved = mdate();
205 if( OpenDisplay( p_vout ) )
207 msg_Err( p_vout, "cannot set up SDL (%s)", SDL_GetError() );
208 SDL_QuitSubSystem( SDL_INIT_VIDEO );
209 free( p_vout->p_sys );
216 /*****************************************************************************
217 * Init: initialize SDL video thread output method
218 *****************************************************************************
219 * This function initialize the SDL display device.
220 *****************************************************************************/
221 static int Init( vout_thread_t *p_vout )
226 p_vout->p_sys->i_surfaces = 0;
228 I_OUTPUTPICTURES = 0;
230 /* Initialize the output structure */
231 if( p_vout->p_sys->p_overlay == NULL )
233 /* All we have is an RGB image with square pixels */
234 p_vout->output.i_width = p_vout->p_sys->i_width;
235 p_vout->output.i_height = p_vout->p_sys->i_height;
236 p_vout->output.i_aspect = p_vout->output.i_width
238 / p_vout->output.i_height;
242 /* We may need to convert the chroma, but at least we keep the
244 p_vout->output.i_width = p_vout->render.i_width;
245 p_vout->output.i_height = p_vout->render.i_height;
246 p_vout->output.i_aspect = p_vout->render.i_aspect;
249 /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
250 while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
254 /* Find an empty picture slot */
255 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
257 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
259 p_pic = p_vout->p_picture + i_index;
264 /* Allocate the picture if we found one */
265 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
270 p_pic->i_status = DESTROYED_PICTURE;
271 p_pic->i_type = DIRECT_PICTURE;
273 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
281 /*****************************************************************************
282 * End: terminate Sys video thread output method
283 *****************************************************************************
284 * Terminate an output method created by OpenVideo
285 *****************************************************************************/
286 static void End( vout_thread_t *p_vout )
290 /* Free the output buffers we allocated */
291 for( i_index = I_OUTPUTPICTURES ; i_index ; )
294 if( p_vout->p_sys->p_overlay == NULL )
300 SDL_UnlockYUVOverlay(
301 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
303 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
305 free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
309 /*****************************************************************************
310 * CloseVideo: destroy Sys video thread output method
311 *****************************************************************************
312 * Terminate an output method created by vout_SDLCreate
313 *****************************************************************************/
314 static void Close ( vlc_object_t *p_this )
316 vout_thread_t * p_vout = (vout_thread_t *)p_this;
318 CloseDisplay( p_vout );
319 SDL_QuitSubSystem( SDL_INIT_VIDEO );
321 free( p_vout->p_sys );
324 /*****************************************************************************
325 * Manage: handle Sys events
326 *****************************************************************************
327 * This function should be called regularly by video output thread. It returns
328 * a non null value if an error occurred.
329 *****************************************************************************/
330 static int Manage( vout_thread_t *p_vout )
332 SDL_Event event; /* SDL event */
334 unsigned int i_width, i_height, i_x, i_y;
337 while( SDL_PollEvent(&event) )
341 case SDL_VIDEORESIZE: /* Resizing of window */
342 /* Update dimensions */
343 p_vout->i_changes |= VOUT_SIZE_CHANGE;
344 p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
345 p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
348 case SDL_MOUSEMOTION:
349 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
350 p_vout->p_sys->i_height,
351 &i_x, &i_y, &i_width, &i_height );
353 val.i_int = ( event.motion.x - i_x )
354 * p_vout->render.i_width / i_width;
355 var_Set( p_vout, "mouse-x", val );
356 val.i_int = ( event.motion.y - i_y )
357 * p_vout->render.i_height / i_height;
358 var_Set( p_vout, "mouse-y", val );
360 val.b_bool = VLC_TRUE;
361 var_Set( p_vout, "mouse-moved", val );
363 if( p_vout->p_sys->b_cursor &&
364 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
366 if( p_vout->p_sys->b_cursor_autohidden )
368 p_vout->p_sys->b_cursor_autohidden = 0;
373 p_vout->p_sys->i_lastmoved = mdate();
378 case SDL_MOUSEBUTTONUP:
379 switch( event.button.button )
381 case SDL_BUTTON_LEFT:
382 val.b_bool = VLC_TRUE;
383 var_Set( p_vout, "mouse-clicked", val );
386 case SDL_BUTTON_RIGHT:
388 intf_thread_t *p_intf;
389 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
393 p_intf->b_menu_change = 1;
394 vlc_object_release( p_intf );
401 case SDL_MOUSEBUTTONDOWN:
402 switch( event.button.button )
404 case SDL_BUTTON_LEFT:
405 /* In this part we will eventually manage
406 * clicks for DVD navigation for instance. */
408 /* detect double-clicks */
409 if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
410 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
412 p_vout->p_sys->i_lastpressed = mdate();
424 vlc_object_kill( p_vout->p_libvlc );
427 case SDL_KEYDOWN: /* if a key is pressed */
429 switch( event.key.keysym.sym )
432 if( p_vout->b_fullscreen )
434 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
438 vlc_object_kill( p_vout->p_libvlc );
442 case SDLK_q: /* quit */
443 vlc_object_kill( p_vout->p_libvlc );
446 case SDLK_f: /* switch to fullscreen */
447 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
450 case SDLK_c: /* toggle grayscale */
451 p_vout->b_grayscale = ! p_vout->b_grayscale;
452 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
455 case SDLK_i: /* toggle info */
456 p_vout->b_info = ! p_vout->b_info;
457 p_vout->i_changes |= VOUT_INFO_CHANGE;
460 case SDLK_s: /* toggle scaling */
461 p_vout->b_scale = ! p_vout->b_scale;
462 p_vout->i_changes |= VOUT_SCALE_CHANGE;
465 case SDLK_SPACE: /* toggle interface */
466 p_vout->b_interface = ! p_vout->b_interface;
467 p_vout->i_changes |= VOUT_INTF_CHANGE;
472 intf_thread_t *p_intf;
473 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
477 p_intf->b_menu_change = 1;
478 vlc_object_release( p_intf );
497 audio_volume_t i_volume;
498 if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
500 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
504 msg_Dbg( p_vout, "audio volume: operation not supported" );
511 audio_volume_t i_volume;
512 if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
514 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
518 msg_Dbg( p_vout, "audio volume: operation not supported" );
533 /* Fullscreen change */
534 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
536 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
538 p_vout->p_sys->b_cursor_autohidden = 0;
539 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
540 ! p_vout->p_sys->b_cursor_autohidden );
542 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
543 p_vout->i_changes |= VOUT_SIZE_CHANGE;
549 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
551 msg_Dbg( p_vout, "video display resized (%dx%d)",
552 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
554 CloseDisplay( p_vout );
555 OpenDisplay( p_vout );
557 /* We don't need to signal the vout thread about the size change if
558 * we can handle rescaling ourselves */
559 if( p_vout->p_sys->p_overlay != NULL )
560 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
565 if( ! p_vout->p_sys->b_cursor_autohidden &&
566 ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
568 /* Hide the mouse automatically */
569 p_vout->p_sys->b_cursor_autohidden = 1;
576 /*****************************************************************************
577 * Display: displays previously rendered output
578 *****************************************************************************
579 * This function sends the currently rendered image to the display.
580 *****************************************************************************/
581 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
583 unsigned int x, y, w, h;
586 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
593 if( p_vout->p_sys->p_overlay == NULL )
596 SDL_Flip( p_vout->p_sys->p_display );
600 /* Overlay picture */
601 SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
602 SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
603 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
607 /* following functions are local */
609 /*****************************************************************************
610 * OpenDisplay: open and initialize SDL device
611 *****************************************************************************
612 * Open and initialize display according to preferences specified in the vout
614 *****************************************************************************/
615 static int OpenDisplay( vout_thread_t *p_vout )
620 /* SDL fucked up fourcc definitions on bigendian machines */
621 uint32_t i_sdl_chroma;
622 char *psz_chroma = NULL;
623 uint32_t i_chroma = 0;
625 /* Set main window's size */
626 p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
627 p_vout->i_window_width;
628 p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
629 p_vout->i_window_height;
631 /* Initialize flags and cursor */
632 i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
633 i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
635 i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
636 SDL_DEFAULT_BPP, i_flags );
639 msg_Err( p_vout, "no video mode available" );
643 p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
644 p_vout->p_sys->i_height,
647 if( p_vout->p_sys->p_display == NULL )
649 msg_Err( p_vout, "cannot set video mode" );
653 SDL_LockSurface( p_vout->p_sys->p_display );
655 if( ( psz_chroma = config_GetPsz( p_vout, "sdl-chroma" ) ) )
657 if( strlen( psz_chroma ) >= 4 )
659 memcpy(&i_chroma, psz_chroma, 4);
660 msg_Dbg( p_vout, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma, (char*)&i_chroma );
669 /* Choose the chroma we will try first. */
672 if( !psz_chroma ) i_chroma = 0;
673 switch( i_chroma ? i_chroma : p_vout->render.i_chroma )
675 case VLC_FOURCC('Y','U','Y','2'):
676 case VLC_FOURCC('Y','U','N','V'):
677 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
678 i_sdl_chroma = SDL_YUY2_OVERLAY;
680 case VLC_FOURCC('U','Y','V','Y'):
681 case VLC_FOURCC('U','Y','N','V'):
682 case VLC_FOURCC('Y','4','2','2'):
683 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
684 i_sdl_chroma = SDL_UYVY_OVERLAY;
686 case VLC_FOURCC('Y','V','Y','U'):
687 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
688 i_sdl_chroma = SDL_YVYU_OVERLAY;
690 case VLC_FOURCC('Y','V','1','2'):
691 case VLC_FOURCC('I','4','2','0'):
692 case VLC_FOURCC('I','Y','U','V'):
694 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
695 i_sdl_chroma = SDL_YV12_OVERLAY;
698 free( psz_chroma ); psz_chroma = NULL;
700 p_vout->p_sys->p_overlay =
701 SDL_CreateYUVOverlay( 32, 32, i_sdl_chroma,
702 p_vout->p_sys->p_display );
703 /* FIXME: if the first overlay we find is software, don't stop,
704 * because we may find a hardware one later ... */
706 while( i_chroma && !p_vout->p_sys->p_overlay );
709 /* If this best choice failed, fall back to other chromas */
710 if( p_vout->p_sys->p_overlay == NULL )
712 p_vout->output.i_chroma = VLC_FOURCC('I','Y','U','V');
713 p_vout->p_sys->p_overlay =
714 SDL_CreateYUVOverlay( 32, 32, SDL_IYUV_OVERLAY,
715 p_vout->p_sys->p_display );
718 if( p_vout->p_sys->p_overlay == NULL )
720 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
721 p_vout->p_sys->p_overlay =
722 SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
723 p_vout->p_sys->p_display );
726 if( p_vout->p_sys->p_overlay == NULL )
728 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
729 p_vout->p_sys->p_overlay =
730 SDL_CreateYUVOverlay( 32, 32, SDL_YUY2_OVERLAY,
731 p_vout->p_sys->p_display );
734 if( p_vout->p_sys->p_overlay == NULL )
736 msg_Warn( p_vout, "no SDL overlay for 0x%.8x (%4.4s)",
737 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma );
739 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
742 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
743 p_vout->output.pf_setpalette = SetPalette;
746 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
749 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
752 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
755 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
758 msg_Err( p_vout, "unknown screen depth %i",
759 p_vout->p_sys->p_display->format->BitsPerPixel );
760 SDL_UnlockSurface( p_vout->p_sys->p_display );
761 SDL_FreeSurface( p_vout->p_sys->p_display );
765 p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
766 p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
767 p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
769 SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
770 VOUT_TITLE " (software RGB SDL output)" );
774 if( p_vout->p_sys->p_overlay->hw_overlay )
776 SDL_WM_SetCaption( VOUT_TITLE " (hardware YUV SDL output)",
777 VOUT_TITLE " (hardware YUV SDL output)" );
781 SDL_WM_SetCaption( VOUT_TITLE " (software YUV SDL output)",
782 VOUT_TITLE " (software YUV SDL output)" );
786 SDL_EventState( SDL_KEYUP, SDL_IGNORE ); /* ignore keys up */
791 /*****************************************************************************
792 * CloseDisplay: close and reset SDL device
793 *****************************************************************************
794 * This function returns all resources allocated by OpenDisplay and restore
795 * the original state of the device.
796 *****************************************************************************/
797 static void CloseDisplay( vout_thread_t *p_vout )
799 SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
800 SDL_UnlockSurface ( p_vout->p_sys->p_display );
801 SDL_FreeSurface( p_vout->p_sys->p_display );
804 /*****************************************************************************
805 * NewPicture: allocate a picture
806 *****************************************************************************
807 * Returns 0 on success, -1 otherwise
808 *****************************************************************************/
809 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
811 int i_width = p_vout->output.i_width;
812 int i_height = p_vout->output.i_height;
814 if( p_vout->p_sys->p_overlay == NULL )
817 if( p_vout->p_sys->i_surfaces )
819 /* We already allocated this surface, return */
823 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
825 if( p_pic->p_sys == NULL )
830 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
833 p_pic->p->i_pixel_pitch = 1;
837 p_pic->p->i_pixel_pitch = 2;
841 p_pic->p->i_pixel_pitch = 4;
847 p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
848 p_pic->p->i_lines = p_vout->p_sys->p_display->h;
849 p_pic->p->i_visible_lines = p_vout->p_sys->p_display->h;
850 p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
851 p_pic->p->i_visible_pitch =
852 p_pic->p->i_pixel_pitch * p_vout->p_sys->p_display->w;
854 p_vout->p_sys->i_surfaces++;
860 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
862 if( p_pic->p_sys == NULL )
867 p_pic->p_sys->p_overlay =
868 SDL_CreateYUVOverlay( i_width, i_height,
869 p_vout->output.i_chroma,
870 p_vout->p_sys->p_display );
872 if( p_pic->p_sys->p_overlay == NULL )
874 free( p_pic->p_sys );
878 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
880 p_pic->Y_PIXELS = p_pic->p_sys->p_overlay->pixels[0];
881 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_overlay->h;
882 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h;
883 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[0];
885 switch( p_vout->output.i_chroma )
887 case SDL_YV12_OVERLAY:
888 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
889 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
891 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
892 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
893 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
894 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
895 p_pic->p[U_PLANE].i_pixel_pitch = 1;
896 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
898 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
899 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
900 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
901 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
902 p_pic->p[V_PLANE].i_pixel_pitch = 1;
903 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
908 case SDL_IYUV_OVERLAY:
909 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
910 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
912 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
913 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
914 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
915 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
916 p_pic->p[U_PLANE].i_pixel_pitch = 1;
917 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
919 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
920 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
921 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
922 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
923 p_pic->p[V_PLANE].i_pixel_pitch = 1;
924 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
930 p_pic->p[Y_PLANE].i_pixel_pitch = 2;
931 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w * 2;
941 /*****************************************************************************
942 * SetPalette: sets an 8 bpp palette
943 *****************************************************************************/
944 static void SetPalette( vout_thread_t *p_vout,
945 uint16_t *red, uint16_t *green, uint16_t *blue )
947 SDL_Color colors[256];
950 /* Fill colors with color information */
951 for( i = 0; i < 256; i++ )
953 colors[ i ].r = red[ i ] >> 8;
954 colors[ i ].g = green[ i ] >> 8;
955 colors[ i ].b = blue[ i ] >> 8;
959 if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
961 msg_Err( p_vout, "failed to set palette" );