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_GetGlobalMutex( "sdl" );
139 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
140 if( p_vout->p_sys == NULL )
142 vlc_mutex_unlock( lock );
146 vlc_mutex_lock( lock );
148 if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
150 vlc_mutex_unlock( lock );
151 free( p_vout->p_sys );
155 /* Allocate structure */
157 p_vout->pf_init = Init;
158 p_vout->pf_end = End;
159 p_vout->pf_manage = Manage;
160 p_vout->pf_render = NULL;
161 p_vout->pf_display = Display;
164 psz_method = config_GetPsz( p_vout, "vout" );
167 while( *psz_method && *psz_method != ':' )
174 setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
179 /* Initialize library */
180 if( SDL_Init( SDL_INIT_VIDEO
182 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
183 | SDL_INIT_EVENTTHREAD
186 /* In debug mode you may want vlc to dump a core instead of staying
188 | SDL_INIT_NOPARACHUTE
192 msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() );
193 free( p_vout->p_sys );
194 vlc_mutex_unlock( lock );
198 vlc_mutex_unlock( lock );
200 p_vout->p_sys->b_cursor = 1;
201 p_vout->p_sys->b_cursor_autohidden = 0;
202 p_vout->p_sys->i_lastmoved = mdate();
204 if( OpenDisplay( p_vout ) )
206 msg_Err( p_vout, "cannot set up SDL (%s)", SDL_GetError() );
207 SDL_QuitSubSystem( SDL_INIT_VIDEO );
208 free( p_vout->p_sys );
215 /*****************************************************************************
216 * Init: initialize SDL video thread output method
217 *****************************************************************************
218 * This function initialize the SDL display device.
219 *****************************************************************************/
220 static int Init( vout_thread_t *p_vout )
225 p_vout->p_sys->i_surfaces = 0;
227 I_OUTPUTPICTURES = 0;
229 /* Initialize the output structure */
230 if( p_vout->p_sys->p_overlay == NULL )
232 /* All we have is an RGB image with square pixels */
233 p_vout->output.i_width = p_vout->p_sys->i_width;
234 p_vout->output.i_height = p_vout->p_sys->i_height;
235 p_vout->output.i_aspect = p_vout->output.i_width
237 / p_vout->output.i_height;
241 /* We may need to convert the chroma, but at least we keep the
243 p_vout->output.i_width = p_vout->render.i_width;
244 p_vout->output.i_height = p_vout->render.i_height;
245 p_vout->output.i_aspect = p_vout->render.i_aspect;
248 /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
249 while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
253 /* Find an empty picture slot */
254 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
256 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
258 p_pic = p_vout->p_picture + i_index;
263 /* Allocate the picture if we found one */
264 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
269 p_pic->i_status = DESTROYED_PICTURE;
270 p_pic->i_type = DIRECT_PICTURE;
272 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
280 /*****************************************************************************
281 * End: terminate Sys video thread output method
282 *****************************************************************************
283 * Terminate an output method created by OpenVideo
284 *****************************************************************************/
285 static void End( vout_thread_t *p_vout )
289 /* Free the output buffers we allocated */
290 for( i_index = I_OUTPUTPICTURES ; i_index ; )
293 if( p_vout->p_sys->p_overlay == NULL )
299 SDL_UnlockYUVOverlay(
300 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
302 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
304 free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
308 /*****************************************************************************
309 * CloseVideo: destroy Sys video thread output method
310 *****************************************************************************
311 * Terminate an output method created by vout_SDLCreate
312 *****************************************************************************/
313 static void Close ( vlc_object_t *p_this )
315 vout_thread_t * p_vout = (vout_thread_t *)p_this;
317 CloseDisplay( p_vout );
318 SDL_QuitSubSystem( SDL_INIT_VIDEO );
320 free( p_vout->p_sys );
323 /*****************************************************************************
324 * Manage: handle Sys events
325 *****************************************************************************
326 * This function should be called regularly by video output thread. It returns
327 * a non null value if an error occurred.
328 *****************************************************************************/
329 static int Manage( vout_thread_t *p_vout )
331 SDL_Event event; /* SDL event */
333 unsigned int i_width, i_height, i_x, i_y;
336 while( SDL_PollEvent(&event) )
340 case SDL_VIDEORESIZE: /* Resizing of window */
341 /* Update dimensions */
342 p_vout->i_changes |= VOUT_SIZE_CHANGE;
343 p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
344 p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
347 case SDL_MOUSEMOTION:
348 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
349 p_vout->p_sys->i_height,
350 &i_x, &i_y, &i_width, &i_height );
352 val.i_int = ( event.motion.x - i_x )
353 * p_vout->render.i_width / i_width;
354 var_Set( p_vout, "mouse-x", val );
355 val.i_int = ( event.motion.y - i_y )
356 * p_vout->render.i_height / i_height;
357 var_Set( p_vout, "mouse-y", val );
359 val.b_bool = VLC_TRUE;
360 var_Set( p_vout, "mouse-moved", val );
362 if( p_vout->p_sys->b_cursor &&
363 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
365 if( p_vout->p_sys->b_cursor_autohidden )
367 p_vout->p_sys->b_cursor_autohidden = 0;
372 p_vout->p_sys->i_lastmoved = mdate();
377 case SDL_MOUSEBUTTONUP:
378 switch( event.button.button )
380 case SDL_BUTTON_LEFT:
381 val.b_bool = VLC_TRUE;
382 var_Set( p_vout, "mouse-clicked", val );
385 case SDL_BUTTON_RIGHT:
387 intf_thread_t *p_intf;
388 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
392 p_intf->b_menu_change = 1;
393 vlc_object_release( p_intf );
400 case SDL_MOUSEBUTTONDOWN:
401 switch( event.button.button )
403 case SDL_BUTTON_LEFT:
404 /* In this part we will eventually manage
405 * clicks for DVD navigation for instance. */
407 /* detect double-clicks */
408 if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
409 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
411 p_vout->p_sys->i_lastpressed = mdate();
423 vlc_object_kill( p_vout->p_libvlc );
426 case SDL_KEYDOWN: /* if a key is pressed */
428 switch( event.key.keysym.sym )
431 if( p_vout->b_fullscreen )
433 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
437 vlc_object_kill( p_vout->p_libvlc );
441 case SDLK_q: /* quit */
442 vlc_object_kill( p_vout->p_libvlc );
445 case SDLK_f: /* switch to fullscreen */
446 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
449 case SDLK_c: /* toggle grayscale */
450 p_vout->b_grayscale = ! p_vout->b_grayscale;
451 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
454 case SDLK_i: /* toggle info */
455 p_vout->b_info = ! p_vout->b_info;
456 p_vout->i_changes |= VOUT_INFO_CHANGE;
459 case SDLK_s: /* toggle scaling */
460 p_vout->b_scale = ! p_vout->b_scale;
461 p_vout->i_changes |= VOUT_SCALE_CHANGE;
464 case SDLK_SPACE: /* toggle interface */
465 p_vout->b_interface = ! p_vout->b_interface;
466 p_vout->i_changes |= VOUT_INTF_CHANGE;
471 intf_thread_t *p_intf;
472 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
476 p_intf->b_menu_change = 1;
477 vlc_object_release( p_intf );
496 audio_volume_t i_volume;
497 if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
499 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
503 msg_Dbg( p_vout, "audio volume: operation not supported" );
510 audio_volume_t i_volume;
511 if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
513 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
517 msg_Dbg( p_vout, "audio volume: operation not supported" );
532 /* Fullscreen change */
533 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
535 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
537 p_vout->p_sys->b_cursor_autohidden = 0;
538 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
539 ! p_vout->p_sys->b_cursor_autohidden );
541 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
542 p_vout->i_changes |= VOUT_SIZE_CHANGE;
548 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
550 msg_Dbg( p_vout, "video display resized (%dx%d)",
551 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
553 CloseDisplay( p_vout );
554 OpenDisplay( p_vout );
556 /* We don't need to signal the vout thread about the size change if
557 * we can handle rescaling ourselves */
558 if( p_vout->p_sys->p_overlay != NULL )
559 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
564 if( ! p_vout->p_sys->b_cursor_autohidden &&
565 ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
567 /* Hide the mouse automatically */
568 p_vout->p_sys->b_cursor_autohidden = 1;
575 /*****************************************************************************
576 * Display: displays previously rendered output
577 *****************************************************************************
578 * This function sends the currently rendered image to the display.
579 *****************************************************************************/
580 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
582 unsigned int x, y, w, h;
585 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
592 if( p_vout->p_sys->p_overlay == NULL )
595 SDL_Flip( p_vout->p_sys->p_display );
599 /* Overlay picture */
600 SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
601 SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
602 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
606 /* following functions are local */
608 /*****************************************************************************
609 * OpenDisplay: open and initialize SDL device
610 *****************************************************************************
611 * Open and initialize display according to preferences specified in the vout
613 *****************************************************************************/
614 static int OpenDisplay( vout_thread_t *p_vout )
619 /* SDL fucked up fourcc definitions on bigendian machines */
620 uint32_t i_sdl_chroma;
621 char *psz_chroma = NULL;
622 uint32_t i_chroma = 0;
624 /* Set main window's size */
625 p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
626 p_vout->i_window_width;
627 p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
628 p_vout->i_window_height;
630 /* Initialize flags and cursor */
631 i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
632 i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
634 i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
635 SDL_DEFAULT_BPP, i_flags );
638 msg_Err( p_vout, "no video mode available" );
642 p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
643 p_vout->p_sys->i_height,
646 if( p_vout->p_sys->p_display == NULL )
648 msg_Err( p_vout, "cannot set video mode" );
652 SDL_LockSurface( p_vout->p_sys->p_display );
654 if( ( psz_chroma = config_GetPsz( p_vout, "sdl-chroma" ) ) )
656 if( strlen( psz_chroma ) >= 4 )
658 memcpy(&i_chroma, psz_chroma, 4);
659 msg_Dbg( p_vout, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma, (char*)&i_chroma );
668 /* Choose the chroma we will try first. */
671 if( !psz_chroma ) i_chroma = 0;
672 switch( i_chroma ? i_chroma : p_vout->render.i_chroma )
674 case VLC_FOURCC('Y','U','Y','2'):
675 case VLC_FOURCC('Y','U','N','V'):
676 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
677 i_sdl_chroma = SDL_YUY2_OVERLAY;
679 case VLC_FOURCC('U','Y','V','Y'):
680 case VLC_FOURCC('U','Y','N','V'):
681 case VLC_FOURCC('Y','4','2','2'):
682 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
683 i_sdl_chroma = SDL_UYVY_OVERLAY;
685 case VLC_FOURCC('Y','V','Y','U'):
686 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
687 i_sdl_chroma = SDL_YVYU_OVERLAY;
689 case VLC_FOURCC('Y','V','1','2'):
690 case VLC_FOURCC('I','4','2','0'):
691 case VLC_FOURCC('I','Y','U','V'):
693 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
694 i_sdl_chroma = SDL_YV12_OVERLAY;
697 free( psz_chroma ); psz_chroma = NULL;
699 p_vout->p_sys->p_overlay =
700 SDL_CreateYUVOverlay( 32, 32, i_sdl_chroma,
701 p_vout->p_sys->p_display );
702 /* FIXME: if the first overlay we find is software, don't stop,
703 * because we may find a hardware one later ... */
705 while( i_chroma && !p_vout->p_sys->p_overlay );
708 /* If this best choice failed, fall back to other chromas */
709 if( p_vout->p_sys->p_overlay == NULL )
711 p_vout->output.i_chroma = VLC_FOURCC('I','Y','U','V');
712 p_vout->p_sys->p_overlay =
713 SDL_CreateYUVOverlay( 32, 32, SDL_IYUV_OVERLAY,
714 p_vout->p_sys->p_display );
717 if( p_vout->p_sys->p_overlay == NULL )
719 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
720 p_vout->p_sys->p_overlay =
721 SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
722 p_vout->p_sys->p_display );
725 if( p_vout->p_sys->p_overlay == NULL )
727 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
728 p_vout->p_sys->p_overlay =
729 SDL_CreateYUVOverlay( 32, 32, SDL_YUY2_OVERLAY,
730 p_vout->p_sys->p_display );
733 if( p_vout->p_sys->p_overlay == NULL )
735 msg_Warn( p_vout, "no SDL overlay for 0x%.8x (%4.4s)",
736 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma );
738 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
741 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
742 p_vout->output.pf_setpalette = SetPalette;
745 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
748 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
751 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
754 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
757 msg_Err( p_vout, "unknown screen depth %i",
758 p_vout->p_sys->p_display->format->BitsPerPixel );
759 SDL_UnlockSurface( p_vout->p_sys->p_display );
760 SDL_FreeSurface( p_vout->p_sys->p_display );
764 p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
765 p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
766 p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
768 SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
769 VOUT_TITLE " (software RGB SDL output)" );
773 if( p_vout->p_sys->p_overlay->hw_overlay )
775 SDL_WM_SetCaption( VOUT_TITLE " (hardware YUV SDL output)",
776 VOUT_TITLE " (hardware YUV SDL output)" );
780 SDL_WM_SetCaption( VOUT_TITLE " (software YUV SDL output)",
781 VOUT_TITLE " (software YUV SDL output)" );
785 SDL_EventState( SDL_KEYUP, SDL_IGNORE ); /* ignore keys up */
790 /*****************************************************************************
791 * CloseDisplay: close and reset SDL device
792 *****************************************************************************
793 * This function returns all resources allocated by OpenDisplay and restore
794 * the original state of the device.
795 *****************************************************************************/
796 static void CloseDisplay( vout_thread_t *p_vout )
798 SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
799 SDL_UnlockSurface ( p_vout->p_sys->p_display );
800 SDL_FreeSurface( p_vout->p_sys->p_display );
803 /*****************************************************************************
804 * NewPicture: allocate a picture
805 *****************************************************************************
806 * Returns 0 on success, -1 otherwise
807 *****************************************************************************/
808 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
810 int i_width = p_vout->output.i_width;
811 int i_height = p_vout->output.i_height;
813 if( p_vout->p_sys->p_overlay == NULL )
816 if( p_vout->p_sys->i_surfaces )
818 /* We already allocated this surface, return */
822 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
824 if( p_pic->p_sys == NULL )
829 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
832 p_pic->p->i_pixel_pitch = 1;
836 p_pic->p->i_pixel_pitch = 2;
840 p_pic->p->i_pixel_pitch = 4;
846 p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
847 p_pic->p->i_lines = p_vout->p_sys->p_display->h;
848 p_pic->p->i_visible_lines = p_vout->p_sys->p_display->h;
849 p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
850 p_pic->p->i_visible_pitch =
851 p_pic->p->i_pixel_pitch * p_vout->p_sys->p_display->w;
853 p_vout->p_sys->i_surfaces++;
859 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
861 if( p_pic->p_sys == NULL )
866 p_pic->p_sys->p_overlay =
867 SDL_CreateYUVOverlay( i_width, i_height,
868 p_vout->output.i_chroma,
869 p_vout->p_sys->p_display );
871 if( p_pic->p_sys->p_overlay == NULL )
873 free( p_pic->p_sys );
877 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
879 p_pic->Y_PIXELS = p_pic->p_sys->p_overlay->pixels[0];
880 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_overlay->h;
881 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h;
882 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[0];
884 switch( p_vout->output.i_chroma )
886 case SDL_YV12_OVERLAY:
887 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
888 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
890 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
891 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
892 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
893 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
894 p_pic->p[U_PLANE].i_pixel_pitch = 1;
895 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
897 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
898 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
899 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
900 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
901 p_pic->p[V_PLANE].i_pixel_pitch = 1;
902 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
907 case SDL_IYUV_OVERLAY:
908 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
909 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
911 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
912 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
913 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
914 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
915 p_pic->p[U_PLANE].i_pixel_pitch = 1;
916 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
918 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
919 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
920 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
921 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
922 p_pic->p[V_PLANE].i_pixel_pitch = 1;
923 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
929 p_pic->p[Y_PLANE].i_pixel_pitch = 2;
930 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w * 2;
940 /*****************************************************************************
941 * SetPalette: sets an 8 bpp palette
942 *****************************************************************************/
943 static void SetPalette( vout_thread_t *p_vout,
944 uint16_t *red, uint16_t *green, uint16_t *blue )
946 SDL_Color colors[256];
949 /* Fill colors with color information */
950 for( i = 0; i < 256; i++ )
952 colors[ i ].r = red[ i ] >> 8;
953 colors[ i ].g = green[ i ] >> 8;
954 colors[ i ].b = blue[ i ] >> 8;
958 if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
960 msg_Err( p_vout, "failed to set palette" );