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 */
30 #include <stdlib.h> /* free() */
31 #include <string.h> /* strerror() */
34 #include <vlc_interface.h>
38 #include <sys/types.h>
40 # include <netinet/in.h> /* BSD: struct in_addr */
43 #include SDL_INCLUDE_FILE
45 /* SDL is not able to crop overlays - so use only 1 direct buffer */
46 #define SDL_MAX_DIRECTBUFFERS 1
47 #define SDL_DEFAULT_BPP 16
49 /*****************************************************************************
50 * vout_sys_t: video output SDL method descriptor
51 *****************************************************************************
52 * This structure is part of the video output thread descriptor.
53 * It describes the SDL specific properties of an output thread.
54 *****************************************************************************/
57 SDL_Surface * p_display; /* display device */
63 SDL_Overlay * p_overlay; /* An overlay we keep to grab the XVideo port */
69 vlc_bool_t b_cursor_autohidden;
71 mtime_t i_lastpressed; /* to track dbl-clicks */
74 /*****************************************************************************
75 * picture_sys_t: direct buffer method descriptor
76 *****************************************************************************
77 * This structure is part of the picture descriptor, it describes the
78 * SDL specific properties of a direct buffer.
79 *****************************************************************************/
82 SDL_Overlay *p_overlay;
85 /*****************************************************************************
87 *****************************************************************************/
88 static int Open ( vlc_object_t * );
89 static void Close ( vlc_object_t * );
90 static int Init ( vout_thread_t * );
91 static void End ( vout_thread_t * );
92 static int Manage ( vout_thread_t * );
93 static void Display ( vout_thread_t *, picture_t * );
95 static int OpenDisplay ( vout_thread_t * );
96 static void CloseDisplay ( vout_thread_t * );
97 static int NewPicture ( vout_thread_t *, picture_t * );
98 static void SetPalette ( vout_thread_t *,
99 uint16_t *, uint16_t *, uint16_t * );
101 #define CHROMA_TEXT N_("SDL chroma format")
102 #define CHROMA_LONGTEXT N_( \
103 "Force the SDL renderer to use a specific chroma format instead of " \
104 "trying to improve performances by using the most efficient one.")
106 /*****************************************************************************
108 *****************************************************************************/
110 set_shortname( "SDL" );
111 set_category( CAT_VIDEO );
112 set_subcategory( SUBCAT_VIDEO_VOUT );
113 set_description( _("Simple DirectMedia Layer video output") );
114 set_capability( "video output", 60 );
115 add_shortcut( "sdl" );
116 add_string( "sdl-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, VLC_TRUE );
117 set_callbacks( Open, Close );
118 /* XXX: check for conflicts with the SDL audio output */
119 var_Create( p_module->p_libvlc_global, "sdl", VLC_VAR_MUTEX );
120 #if defined( __i386__ ) || defined( __x86_64__ )
121 /* On i386, SDL is linked against svgalib */
122 linked_with_a_crap_library_which_uses_atexit();
126 /*****************************************************************************
127 * OpenVideo: allocate SDL video thread output method
128 *****************************************************************************
129 * This function allocate and initialize a SDL vout method. It uses some of the
130 * vout properties to choose the correct mode, and change them according to the
131 * mode actually used.
132 *****************************************************************************/
133 static int Open ( vlc_object_t *p_this )
135 vout_thread_t * p_vout = (vout_thread_t *)p_this;
142 var_Get( p_this->p_libvlc_global, "sdl", &lockval );
143 vlc_mutex_lock( lockval.p_address );
145 if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
147 vlc_mutex_unlock( lockval.p_address );
151 /* Allocate structure */
152 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
153 if( p_vout->p_sys == NULL )
155 msg_Err( p_vout, "out of memory" );
156 vlc_mutex_unlock( lockval.p_address );
160 p_vout->pf_init = Init;
161 p_vout->pf_end = End;
162 p_vout->pf_manage = Manage;
163 p_vout->pf_render = NULL;
164 p_vout->pf_display = Display;
167 psz_method = config_GetPsz( p_vout, "vout" );
170 while( *psz_method && *psz_method != ':' )
177 setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
182 /* Initialize library */
183 if( SDL_Init( SDL_INIT_VIDEO
185 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
186 | SDL_INIT_EVENTTHREAD
189 /* In debug mode you may want vlc to dump a core instead of staying
191 | SDL_INIT_NOPARACHUTE
195 msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() );
196 free( p_vout->p_sys );
197 vlc_mutex_unlock( lockval.p_address );
201 vlc_mutex_unlock( lockval.p_address );
203 p_vout->p_sys->b_cursor = 1;
204 p_vout->p_sys->b_cursor_autohidden = 0;
205 p_vout->p_sys->i_lastmoved = mdate();
207 if( OpenDisplay( p_vout ) )
209 msg_Err( p_vout, "cannot set up SDL (%s)", SDL_GetError() );
210 SDL_QuitSubSystem( SDL_INIT_VIDEO );
211 free( p_vout->p_sys );
218 /*****************************************************************************
219 * Init: initialize SDL video thread output method
220 *****************************************************************************
221 * This function initialize the SDL display device.
222 *****************************************************************************/
223 static int Init( vout_thread_t *p_vout )
228 p_vout->p_sys->i_surfaces = 0;
230 I_OUTPUTPICTURES = 0;
232 /* Initialize the output structure */
233 if( p_vout->p_sys->p_overlay == NULL )
235 /* All we have is an RGB image with square pixels */
236 p_vout->output.i_width = p_vout->p_sys->i_width;
237 p_vout->output.i_height = p_vout->p_sys->i_height;
238 p_vout->output.i_aspect = p_vout->output.i_width
240 / p_vout->output.i_height;
244 /* We may need to convert the chroma, but at least we keep the
246 p_vout->output.i_width = p_vout->render.i_width;
247 p_vout->output.i_height = p_vout->render.i_height;
248 p_vout->output.i_aspect = p_vout->render.i_aspect;
251 /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
252 while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
256 /* Find an empty picture slot */
257 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
259 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
261 p_pic = p_vout->p_picture + i_index;
266 /* Allocate the picture if we found one */
267 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
272 p_pic->i_status = DESTROYED_PICTURE;
273 p_pic->i_type = DIRECT_PICTURE;
275 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
283 /*****************************************************************************
284 * End: terminate Sys video thread output method
285 *****************************************************************************
286 * Terminate an output method created by OpenVideo
287 *****************************************************************************/
288 static void End( vout_thread_t *p_vout )
292 /* Free the output buffers we allocated */
293 for( i_index = I_OUTPUTPICTURES ; i_index ; )
296 if( p_vout->p_sys->p_overlay == NULL )
302 SDL_UnlockYUVOverlay(
303 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
305 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
307 free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
311 /*****************************************************************************
312 * CloseVideo: destroy Sys video thread output method
313 *****************************************************************************
314 * Terminate an output method created by vout_SDLCreate
315 *****************************************************************************/
316 static void Close ( vlc_object_t *p_this )
318 vout_thread_t * p_vout = (vout_thread_t *)p_this;
320 CloseDisplay( p_vout );
321 SDL_QuitSubSystem( SDL_INIT_VIDEO );
323 free( p_vout->p_sys );
326 /*****************************************************************************
327 * Manage: handle Sys events
328 *****************************************************************************
329 * This function should be called regularly by video output thread. It returns
330 * a non null value if an error occurred.
331 *****************************************************************************/
332 static int Manage( vout_thread_t *p_vout )
334 SDL_Event event; /* SDL event */
336 unsigned int i_width, i_height, i_x, i_y;
339 while( SDL_PollEvent(&event) )
343 case SDL_VIDEORESIZE: /* Resizing of window */
344 /* Update dimensions */
345 p_vout->i_changes |= VOUT_SIZE_CHANGE;
346 p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
347 p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
350 case SDL_MOUSEMOTION:
351 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
352 p_vout->p_sys->i_height,
353 &i_x, &i_y, &i_width, &i_height );
355 val.i_int = ( event.motion.x - i_x )
356 * p_vout->render.i_width / i_width;
357 var_Set( p_vout, "mouse-x", val );
358 val.i_int = ( event.motion.y - i_y )
359 * p_vout->render.i_height / i_height;
360 var_Set( p_vout, "mouse-y", val );
362 val.b_bool = VLC_TRUE;
363 var_Set( p_vout, "mouse-moved", val );
365 if( p_vout->p_sys->b_cursor &&
366 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
368 if( p_vout->p_sys->b_cursor_autohidden )
370 p_vout->p_sys->b_cursor_autohidden = 0;
375 p_vout->p_sys->i_lastmoved = mdate();
380 case SDL_MOUSEBUTTONUP:
381 switch( event.button.button )
383 case SDL_BUTTON_LEFT:
384 val.b_bool = VLC_TRUE;
385 var_Set( p_vout, "mouse-clicked", val );
388 case SDL_BUTTON_RIGHT:
390 intf_thread_t *p_intf;
391 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
395 p_intf->b_menu_change = 1;
396 vlc_object_release( p_intf );
403 case SDL_MOUSEBUTTONDOWN:
404 switch( event.button.button )
406 case SDL_BUTTON_LEFT:
407 /* In this part we will eventually manage
408 * clicks for DVD navigation for instance. */
410 /* detect double-clicks */
411 if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
412 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
414 p_vout->p_sys->i_lastpressed = mdate();
426 p_vout->p_libvlc->b_die = 1;
429 case SDL_KEYDOWN: /* if a key is pressed */
431 switch( event.key.keysym.sym )
434 if( p_vout->b_fullscreen )
436 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
440 p_vout->p_libvlc->b_die = 1;
444 case SDLK_q: /* quit */
445 p_vout->p_libvlc->b_die = 1;
448 case SDLK_f: /* switch to fullscreen */
449 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
452 case SDLK_c: /* toggle grayscale */
453 p_vout->b_grayscale = ! p_vout->b_grayscale;
454 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
457 case SDLK_i: /* toggle info */
458 p_vout->b_info = ! p_vout->b_info;
459 p_vout->i_changes |= VOUT_INFO_CHANGE;
462 case SDLK_s: /* toggle scaling */
463 p_vout->b_scale = ! p_vout->b_scale;
464 p_vout->i_changes |= VOUT_SCALE_CHANGE;
467 case SDLK_SPACE: /* toggle interface */
468 p_vout->b_interface = ! p_vout->b_interface;
469 p_vout->i_changes |= VOUT_INTF_CHANGE;
474 intf_thread_t *p_intf;
475 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
479 p_intf->b_menu_change = 1;
480 vlc_object_release( p_intf );
499 audio_volume_t i_volume;
500 if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
502 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
506 msg_Dbg( p_vout, "audio volume: operation not supported" );
513 audio_volume_t i_volume;
514 if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
516 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
520 msg_Dbg( p_vout, "audio volume: operation not supported" );
535 /* Fullscreen change */
536 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
538 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
540 p_vout->p_sys->b_cursor_autohidden = 0;
541 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
542 ! p_vout->p_sys->b_cursor_autohidden );
544 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
545 p_vout->i_changes |= VOUT_SIZE_CHANGE;
551 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
553 msg_Dbg( p_vout, "video display resized (%dx%d)",
554 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
556 CloseDisplay( p_vout );
557 OpenDisplay( p_vout );
559 /* We don't need to signal the vout thread about the size change if
560 * we can handle rescaling ourselves */
561 if( p_vout->p_sys->p_overlay != NULL )
562 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
567 if( ! p_vout->p_sys->b_cursor_autohidden &&
568 ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
570 /* Hide the mouse automatically */
571 p_vout->p_sys->b_cursor_autohidden = 1;
578 /*****************************************************************************
579 * Display: displays previously rendered output
580 *****************************************************************************
581 * This function sends the currently rendered image to the display.
582 *****************************************************************************/
583 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
585 unsigned int x, y, w, h;
588 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
595 if( p_vout->p_sys->p_overlay == NULL )
598 SDL_Flip( p_vout->p_sys->p_display );
602 /* Overlay picture */
603 SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
604 SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
605 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
609 /* following functions are local */
611 /*****************************************************************************
612 * OpenDisplay: open and initialize SDL device
613 *****************************************************************************
614 * Open and initialize display according to preferences specified in the vout
616 *****************************************************************************/
617 static int OpenDisplay( vout_thread_t *p_vout )
622 /* SDL fucked up fourcc definitions on bigendian machines */
623 uint32_t i_sdl_chroma;
624 char *psz_chroma = NULL;
625 uint32_t i_chroma = 0;
627 /* Set main window's size */
628 p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
629 p_vout->i_window_width;
630 p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
631 p_vout->i_window_height;
633 /* Initialize flags and cursor */
634 i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
635 i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
637 i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
638 SDL_DEFAULT_BPP, i_flags );
641 msg_Err( p_vout, "no video mode available" );
645 p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
646 p_vout->p_sys->i_height,
649 if( p_vout->p_sys->p_display == NULL )
651 msg_Err( p_vout, "cannot set video mode" );
655 SDL_LockSurface( p_vout->p_sys->p_display );
657 if( ( psz_chroma = config_GetPsz( p_vout, "sdl-chroma" ) ) )
659 if( strlen( psz_chroma ) >= 4 )
661 memcpy(&i_chroma, psz_chroma, 4);
662 msg_Dbg( p_vout, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma, (char*)&i_chroma );
671 /* Choose the chroma we will try first. */
674 if( !psz_chroma ) i_chroma = 0;
675 switch( i_chroma ? i_chroma : p_vout->render.i_chroma )
677 case VLC_FOURCC('Y','U','Y','2'):
678 case VLC_FOURCC('Y','U','N','V'):
679 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
680 i_sdl_chroma = SDL_YUY2_OVERLAY;
682 case VLC_FOURCC('U','Y','V','Y'):
683 case VLC_FOURCC('U','Y','N','V'):
684 case VLC_FOURCC('Y','4','2','2'):
685 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
686 i_sdl_chroma = SDL_UYVY_OVERLAY;
688 case VLC_FOURCC('Y','V','Y','U'):
689 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
690 i_sdl_chroma = SDL_YVYU_OVERLAY;
692 case VLC_FOURCC('Y','V','1','2'):
693 case VLC_FOURCC('I','4','2','0'):
694 case VLC_FOURCC('I','Y','U','V'):
696 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
697 i_sdl_chroma = SDL_YV12_OVERLAY;
700 free( psz_chroma ); psz_chroma = NULL;
702 p_vout->p_sys->p_overlay =
703 SDL_CreateYUVOverlay( 32, 32, i_sdl_chroma,
704 p_vout->p_sys->p_display );
705 /* FIXME: if the first overlay we find is software, don't stop,
706 * because we may find a hardware one later ... */
708 while( i_chroma && !p_vout->p_sys->p_overlay );
711 /* If this best choice failed, fall back to other chromas */
712 if( p_vout->p_sys->p_overlay == NULL )
714 p_vout->output.i_chroma = VLC_FOURCC('I','Y','U','V');
715 p_vout->p_sys->p_overlay =
716 SDL_CreateYUVOverlay( 32, 32, SDL_IYUV_OVERLAY,
717 p_vout->p_sys->p_display );
720 if( p_vout->p_sys->p_overlay == NULL )
722 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
723 p_vout->p_sys->p_overlay =
724 SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
725 p_vout->p_sys->p_display );
728 if( p_vout->p_sys->p_overlay == NULL )
730 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
731 p_vout->p_sys->p_overlay =
732 SDL_CreateYUVOverlay( 32, 32, SDL_YUY2_OVERLAY,
733 p_vout->p_sys->p_display );
736 if( p_vout->p_sys->p_overlay == NULL )
738 msg_Warn( p_vout, "no SDL overlay for 0x%.8x (%4.4s)",
739 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma );
741 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
744 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
745 p_vout->output.pf_setpalette = SetPalette;
748 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
751 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
754 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
757 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
760 msg_Err( p_vout, "unknown screen depth %i",
761 p_vout->p_sys->p_display->format->BitsPerPixel );
762 SDL_UnlockSurface( p_vout->p_sys->p_display );
763 SDL_FreeSurface( p_vout->p_sys->p_display );
767 p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
768 p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
769 p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
771 SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
772 VOUT_TITLE " (software RGB SDL output)" );
776 if( p_vout->p_sys->p_overlay->hw_overlay )
778 SDL_WM_SetCaption( VOUT_TITLE " (hardware YUV SDL output)",
779 VOUT_TITLE " (hardware YUV SDL output)" );
783 SDL_WM_SetCaption( VOUT_TITLE " (software YUV SDL output)",
784 VOUT_TITLE " (software YUV SDL output)" );
788 SDL_EventState( SDL_KEYUP, SDL_IGNORE ); /* ignore keys up */
793 /*****************************************************************************
794 * CloseDisplay: close and reset SDL device
795 *****************************************************************************
796 * This function returns all resources allocated by OpenDisplay and restore
797 * the original state of the device.
798 *****************************************************************************/
799 static void CloseDisplay( vout_thread_t *p_vout )
801 SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
802 SDL_UnlockSurface ( p_vout->p_sys->p_display );
803 SDL_FreeSurface( p_vout->p_sys->p_display );
806 /*****************************************************************************
807 * NewPicture: allocate a picture
808 *****************************************************************************
809 * Returns 0 on success, -1 otherwise
810 *****************************************************************************/
811 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
813 int i_width = p_vout->output.i_width;
814 int i_height = p_vout->output.i_height;
816 if( p_vout->p_sys->p_overlay == NULL )
819 if( p_vout->p_sys->i_surfaces )
821 /* We already allocated this surface, return */
825 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
827 if( p_pic->p_sys == NULL )
832 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
835 p_pic->p->i_pixel_pitch = 1;
839 p_pic->p->i_pixel_pitch = 2;
843 p_pic->p->i_pixel_pitch = 4;
849 p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
850 p_pic->p->i_lines = p_vout->p_sys->p_display->h;
851 p_pic->p->i_visible_lines = p_vout->p_sys->p_display->h;
852 p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
853 p_pic->p->i_visible_pitch =
854 p_pic->p->i_pixel_pitch * p_vout->p_sys->p_display->w;
856 p_vout->p_sys->i_surfaces++;
862 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
864 if( p_pic->p_sys == NULL )
869 p_pic->p_sys->p_overlay =
870 SDL_CreateYUVOverlay( i_width, i_height,
871 p_vout->output.i_chroma,
872 p_vout->p_sys->p_display );
874 if( p_pic->p_sys->p_overlay == NULL )
876 free( p_pic->p_sys );
880 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
882 p_pic->Y_PIXELS = p_pic->p_sys->p_overlay->pixels[0];
883 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_overlay->h;
884 p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h;
885 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[0];
887 switch( p_vout->output.i_chroma )
889 case SDL_YV12_OVERLAY:
890 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
891 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
893 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
894 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
895 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
896 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
897 p_pic->p[U_PLANE].i_pixel_pitch = 1;
898 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
900 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
901 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
902 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
903 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
904 p_pic->p[V_PLANE].i_pixel_pitch = 1;
905 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
910 case SDL_IYUV_OVERLAY:
911 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
912 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
914 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
915 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
916 p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
917 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
918 p_pic->p[U_PLANE].i_pixel_pitch = 1;
919 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
921 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
922 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
923 p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_overlay->h / 2;
924 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
925 p_pic->p[V_PLANE].i_pixel_pitch = 1;
926 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
932 p_pic->p[Y_PLANE].i_pixel_pitch = 2;
933 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w * 2;
943 /*****************************************************************************
944 * SetPalette: sets an 8 bpp palette
945 *****************************************************************************/
946 static void SetPalette( vout_thread_t *p_vout,
947 uint16_t *red, uint16_t *green, uint16_t *blue )
949 SDL_Color colors[256];
952 /* Fill colors with color information */
953 for( i = 0; i < 256; i++ )
955 colors[ i ].r = red[ i ] >> 8;
956 colors[ i ].g = green[ i ] >> 8;
957 colors[ i ].b = blue[ i ] >> 8;
961 if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
963 msg_Err( p_vout, "failed to set palette" );