1 /*****************************************************************************
2 * sdl.c: SDL video output display method
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
5 * $Id: sdl.c,v 1.10 2003/03/17 17:11:32 sam 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
47 #define SDL_MAX_DIRECTBUFFERS 10
48 #define SDL_DEFAULT_BPP 16
50 /*****************************************************************************
51 * vout_sys_t: video output SDL method descriptor
52 *****************************************************************************
53 * This structure is part of the video output thread descriptor.
54 * It describes the SDL specific properties of an output thread.
55 *****************************************************************************/
58 SDL_Surface * p_display; /* display device */
64 SDL_Overlay * p_overlay; /* An overlay we keep to grab the XVideo port */
70 vlc_bool_t b_cursor_autohidden;
72 mtime_t i_lastpressed; /* to track dbl-clicks */
75 /*****************************************************************************
76 * picture_sys_t: direct buffer method descriptor
77 *****************************************************************************
78 * This structure is part of the picture descriptor, it describes the
79 * SDL specific properties of a direct buffer.
80 *****************************************************************************/
83 SDL_Overlay *p_overlay;
86 /*****************************************************************************
88 *****************************************************************************/
89 static int Open ( vlc_object_t * );
90 static void Close ( vlc_object_t * );
91 static int Init ( vout_thread_t * );
92 static void End ( vout_thread_t * );
93 static int Manage ( vout_thread_t * );
94 static void Display ( vout_thread_t *, picture_t * );
96 static int OpenDisplay ( vout_thread_t * );
97 static void CloseDisplay ( vout_thread_t * );
98 static int NewPicture ( vout_thread_t *, picture_t * );
99 static void SetPalette ( vout_thread_t *,
100 uint16_t *, uint16_t *, uint16_t * );
102 /*****************************************************************************
104 *****************************************************************************/
106 set_description( _("Simple DirectMedia Layer video module") );
107 set_capability( "video output", 60 );
108 add_shortcut( "sdl" );
109 set_callbacks( Open, Close );
110 /* XXX: check for conflicts with the SDL audio output */
111 var_Create( p_module->p_libvlc, "sdl", VLC_VAR_MUTEX );
114 /*****************************************************************************
115 * OpenVideo: allocate SDL video thread output method
116 *****************************************************************************
117 * This function allocate and initialize a SDL vout method. It uses some of the
118 * vout properties to choose the correct mode, and change them according to the
119 * mode actually used.
120 *****************************************************************************/
121 static int Open ( vlc_object_t *p_this )
123 vout_thread_t * p_vout = (vout_thread_t *)p_this;
130 var_Get( p_this->p_libvlc, "sdl", &lockval );
131 vlc_mutex_lock( lockval.p_address );
133 if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
135 vlc_mutex_unlock( lockval.p_address );
139 /* Allocate structure */
140 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
141 if( p_vout->p_sys == NULL )
143 msg_Err( p_vout, "out of memory" );
144 vlc_mutex_unlock( lockval.p_address );
148 p_vout->pf_init = Init;
149 p_vout->pf_end = End;
150 p_vout->pf_manage = Manage;
151 p_vout->pf_render = NULL;
152 p_vout->pf_display = Display;
155 psz_method = config_GetPsz( p_vout, "vout" );
158 while( *psz_method && *psz_method != ':' )
165 setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );
170 /* Initialize library */
171 if( SDL_Init( SDL_INIT_VIDEO
173 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
174 | SDL_INIT_EVENTTHREAD
177 /* In debug mode you may want vlc to dump a core instead of staying
179 | SDL_INIT_NOPARACHUTE
183 msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() );
184 free( p_vout->p_sys );
185 vlc_mutex_unlock( lockval.p_address );
189 vlc_mutex_unlock( lockval.p_address );
191 p_vout->p_sys->b_cursor = 1;
192 p_vout->p_sys->b_cursor_autohidden = 0;
193 p_vout->p_sys->i_lastmoved = mdate();
195 if( OpenDisplay( p_vout ) )
197 msg_Err( p_vout, "cannot set up SDL (%s)", SDL_GetError() );
198 SDL_QuitSubSystem( SDL_INIT_VIDEO );
199 free( p_vout->p_sys );
206 /*****************************************************************************
207 * Init: initialize SDL video thread output method
208 *****************************************************************************
209 * This function initialize the SDL display device.
210 *****************************************************************************/
211 static int Init( vout_thread_t *p_vout )
216 p_vout->p_sys->i_surfaces = 0;
218 I_OUTPUTPICTURES = 0;
220 /* Initialize the output structure */
221 if( p_vout->p_sys->p_overlay == NULL )
223 /* All we have is an RGB image with square pixels */
224 p_vout->output.i_width = p_vout->p_sys->i_width;
225 p_vout->output.i_height = p_vout->p_sys->i_height;
226 p_vout->output.i_aspect = p_vout->output.i_width
228 / p_vout->output.i_height;
232 /* We may need to convert the chroma, but at least we keep the
234 p_vout->output.i_width = p_vout->render.i_width;
235 p_vout->output.i_height = p_vout->render.i_height;
236 p_vout->output.i_aspect = p_vout->render.i_aspect;
239 /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */
240 while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )
244 /* Find an empty picture slot */
245 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
247 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
249 p_pic = p_vout->p_picture + i_index;
254 /* Allocate the picture if we found one */
255 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
260 p_pic->i_status = DESTROYED_PICTURE;
261 p_pic->i_type = DIRECT_PICTURE;
263 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
271 /*****************************************************************************
272 * End: terminate Sys video thread output method
273 *****************************************************************************
274 * Terminate an output method created by OpenVideo
275 *****************************************************************************/
276 static void End( vout_thread_t *p_vout )
280 /* Free the output buffers we allocated */
281 for( i_index = I_OUTPUTPICTURES ; i_index ; )
284 if( p_vout->p_sys->p_overlay == NULL )
290 SDL_UnlockYUVOverlay(
291 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
293 PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );
295 free( PP_OUTPUTPICTURE[ i_index ]->p_sys );
299 /*****************************************************************************
300 * CloseVideo: destroy Sys video thread output method
301 *****************************************************************************
302 * Terminate an output method created by vout_SDLCreate
303 *****************************************************************************/
304 static void Close ( vlc_object_t *p_this )
306 vout_thread_t * p_vout = (vout_thread_t *)p_this;
308 CloseDisplay( p_vout );
309 SDL_QuitSubSystem( SDL_INIT_VIDEO );
311 free( p_vout->p_sys );
314 /*****************************************************************************
315 * Manage: handle Sys events
316 *****************************************************************************
317 * This function should be called regularly by video output thread. It returns
318 * a non null value if an error occured.
319 *****************************************************************************/
320 static int Manage( vout_thread_t *p_vout )
322 SDL_Event event; /* SDL event */
324 int i_width, i_height, i_x, i_y;
327 while( SDL_PollEvent(&event) )
331 case SDL_VIDEORESIZE: /* Resizing of window */
332 /* Update dimensions */
333 p_vout->i_changes |= VOUT_SIZE_CHANGE;
334 p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
335 p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
338 case SDL_MOUSEMOTION:
339 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
340 p_vout->p_sys->i_height,
341 &i_x, &i_y, &i_width, &i_height );
343 val.i_int = ( event.motion.x - i_x )
344 * p_vout->render.i_width / i_width;
345 var_Set( p_vout, "mouse-x", val );
346 val.i_int = ( event.motion.y - i_y )
347 * p_vout->render.i_height / i_height;
348 var_Set( p_vout, "mouse-y", val );
350 val.b_bool = VLC_TRUE;
351 var_Set( p_vout, "mouse-moved", val );
353 if( p_vout->p_sys->b_cursor &&
354 (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
356 if( p_vout->p_sys->b_cursor_autohidden )
358 p_vout->p_sys->b_cursor_autohidden = 0;
363 p_vout->p_sys->i_lastmoved = mdate();
368 case SDL_MOUSEBUTTONUP:
369 switch( event.button.button )
371 case SDL_BUTTON_LEFT:
372 val.b_bool = VLC_TRUE;
373 var_Set( p_vout, "mouse-clicked", val );
376 case SDL_BUTTON_RIGHT:
378 intf_thread_t *p_intf;
379 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
383 p_intf->b_menu_change = 1;
384 vlc_object_release( p_intf );
391 case SDL_MOUSEBUTTONDOWN:
392 switch( event.button.button )
394 case SDL_BUTTON_LEFT:
395 /* In this part we will eventually manage
396 * clicks for DVD navigation for instance. */
398 /* detect double-clicks */
399 if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
400 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
402 p_vout->p_sys->i_lastpressed = mdate();
406 input_Seek( p_vout, 15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
410 input_Seek( p_vout, -15, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
416 p_vout->p_vlc->b_die = 1;
419 case SDL_KEYDOWN: /* if a key is pressed */
421 switch( event.key.keysym.sym )
424 if( p_vout->b_fullscreen )
426 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
430 p_vout->p_vlc->b_die = 1;
434 case SDLK_q: /* quit */
435 p_vout->p_vlc->b_die = 1;
438 case SDLK_f: /* switch to fullscreen */
439 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
442 case SDLK_c: /* toggle grayscale */
443 p_vout->b_grayscale = ! p_vout->b_grayscale;
444 p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
447 case SDLK_i: /* toggle info */
448 p_vout->b_info = ! p_vout->b_info;
449 p_vout->i_changes |= VOUT_INFO_CHANGE;
452 case SDLK_s: /* toggle scaling */
453 p_vout->b_scale = ! p_vout->b_scale;
454 p_vout->i_changes |= VOUT_SCALE_CHANGE;
457 case SDLK_SPACE: /* toggle interface */
458 p_vout->b_interface = ! p_vout->b_interface;
459 p_vout->i_changes |= VOUT_INTF_CHANGE;
464 intf_thread_t *p_intf;
465 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
469 p_intf->b_menu_change = 1;
470 vlc_object_release( p_intf );
476 input_Seek( p_vout, -5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
480 input_Seek( p_vout, 5, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
484 input_Seek( p_vout, 60, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
488 input_Seek( p_vout, -60, INPUT_SEEK_SECONDS | INPUT_SEEK_CUR );
491 case SDLK_F1: network_ChannelJoin( p_vout, 1 ); break;
492 case SDLK_F2: network_ChannelJoin( p_vout, 2 ); break;
493 case SDLK_F3: network_ChannelJoin( p_vout, 3 ); break;
494 case SDLK_F4: network_ChannelJoin( p_vout, 4 ); break;
495 case SDLK_F5: network_ChannelJoin( p_vout, 5 ); break;
496 case SDLK_F6: network_ChannelJoin( p_vout, 6 ); break;
497 case SDLK_F7: network_ChannelJoin( p_vout, 7 ); break;
498 case SDLK_F8: network_ChannelJoin( p_vout, 8 ); break;
499 case SDLK_F9: network_ChannelJoin( p_vout, 9 ); break;
500 case SDLK_F10: network_ChannelJoin( p_vout, 10 ); break;
501 case SDLK_F11: network_ChannelJoin( p_vout, 11 ); break;
502 case SDLK_F12: network_ChannelJoin( p_vout, 12 ); break;
506 audio_volume_t i_volume;
507 if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
509 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
513 msg_Dbg( p_vout, "audio volume: operation not supported" );
520 audio_volume_t i_volume;
521 if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
523 msg_Dbg( p_vout, "audio volume is now %d", i_volume );
527 msg_Dbg( p_vout, "audio volume: operation not supported" );
542 /* Fullscreen change */
543 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
545 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
547 p_vout->p_sys->b_cursor_autohidden = 0;
548 SDL_ShowCursor( p_vout->p_sys->b_cursor &&
549 ! p_vout->p_sys->b_cursor_autohidden );
551 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
552 p_vout->i_changes |= VOUT_SIZE_CHANGE;
558 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
560 msg_Dbg( p_vout, "video display resized (%dx%d)",
561 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
563 CloseDisplay( p_vout );
564 OpenDisplay( p_vout );
566 /* We don't need to signal the vout thread about the size change if
567 * we can handle rescaling ourselves */
568 if( p_vout->p_sys->p_overlay != NULL )
569 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
574 if( ! p_vout->p_sys->b_cursor_autohidden &&
575 ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
577 /* Hide the mouse automatically */
578 p_vout->p_sys->b_cursor_autohidden = 1;
585 /*****************************************************************************
586 * Display: displays previously rendered output
587 *****************************************************************************
588 * This function sends the currently rendered image to the display.
589 *****************************************************************************/
590 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
595 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
602 if( p_vout->p_sys->p_overlay == NULL )
605 SDL_Flip( p_vout->p_sys->p_display );
609 /* Overlay picture */
610 SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay);
611 SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
612 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
616 /* following functions are local */
618 /*****************************************************************************
619 * OpenDisplay: open and initialize SDL device
620 *****************************************************************************
621 * Open and initialize display according to preferences specified in the vout
623 *****************************************************************************/
624 static int OpenDisplay( vout_thread_t *p_vout )
629 /* SDL fucked up fourcc definitions on bigendian machines */
630 uint32_t i_sdl_chroma;
632 /* Set main window's size */
633 p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
634 p_vout->i_window_width;
635 p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
636 p_vout->i_window_height;
638 /* Initialize flags and cursor */
639 i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
640 i_flags |= p_vout->b_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
642 i_bpp = SDL_VideoModeOK( p_vout->p_sys->i_width, p_vout->p_sys->i_height,
643 SDL_DEFAULT_BPP, i_flags );
646 msg_Err( p_vout, "no video mode available" );
650 p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
651 p_vout->p_sys->i_height,
654 if( p_vout->p_sys->p_display == NULL )
656 msg_Err( p_vout, "cannot set video mode" );
660 SDL_LockSurface( p_vout->p_sys->p_display );
662 /* Choose the chroma we will try first. */
663 switch( p_vout->render.i_chroma )
665 case VLC_FOURCC('Y','U','Y','2'):
666 case VLC_FOURCC('Y','U','N','V'):
667 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
668 i_sdl_chroma = SDL_YUY2_OVERLAY;
670 case VLC_FOURCC('U','Y','V','Y'):
671 case VLC_FOURCC('U','Y','N','V'):
672 case VLC_FOURCC('Y','4','2','2'):
673 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
674 i_sdl_chroma = SDL_UYVY_OVERLAY;
676 case VLC_FOURCC('Y','V','Y','U'):
677 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
678 i_sdl_chroma = SDL_YVYU_OVERLAY;
680 case VLC_FOURCC('Y','V','1','2'):
681 case VLC_FOURCC('I','4','2','0'):
682 case VLC_FOURCC('I','Y','U','V'):
684 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
685 i_sdl_chroma = SDL_YV12_OVERLAY;
689 p_vout->p_sys->p_overlay =
690 SDL_CreateYUVOverlay( 32, 32, i_sdl_chroma, p_vout->p_sys->p_display );
691 /* FIXME: if the first overlay we find is software, don't stop,
692 * because we may find a hardware one later ... */
694 /* If this best choice failed, fall back to other chromas */
695 if( p_vout->p_sys->p_overlay == NULL )
697 p_vout->output.i_chroma = VLC_FOURCC('I','Y','U','V');
698 p_vout->p_sys->p_overlay =
699 SDL_CreateYUVOverlay( 32, 32, SDL_IYUV_OVERLAY,
700 p_vout->p_sys->p_display );
703 if( p_vout->p_sys->p_overlay == NULL )
705 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
706 p_vout->p_sys->p_overlay =
707 SDL_CreateYUVOverlay( 32, 32, SDL_YV12_OVERLAY,
708 p_vout->p_sys->p_display );
711 if( p_vout->p_sys->p_overlay == NULL )
713 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
714 p_vout->p_sys->p_overlay =
715 SDL_CreateYUVOverlay( 32, 32, SDL_YUY2_OVERLAY,
716 p_vout->p_sys->p_display );
719 if( p_vout->p_sys->p_overlay == NULL )
721 msg_Warn( p_vout, "no SDL overlay for 0x%.8x (%4.4s)",
722 p_vout->render.i_chroma, (char*)&p_vout->render.i_chroma );
724 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
727 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
728 p_vout->output.pf_setpalette = SetPalette;
731 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
734 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
737 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
740 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
743 msg_Err( p_vout, "unknown screen depth %i",
744 p_vout->p_sys->p_display->format->BitsPerPixel );
745 SDL_UnlockSurface( p_vout->p_sys->p_display );
746 SDL_FreeSurface( p_vout->p_sys->p_display );
750 p_vout->output.i_rmask = p_vout->p_sys->p_display->format->Rmask;
751 p_vout->output.i_gmask = p_vout->p_sys->p_display->format->Gmask;
752 p_vout->output.i_bmask = p_vout->p_sys->p_display->format->Bmask;
754 SDL_WM_SetCaption( VOUT_TITLE " (software RGB SDL output)",
755 VOUT_TITLE " (software RGB SDL output)" );
759 if( p_vout->p_sys->p_overlay->hw_overlay )
761 SDL_WM_SetCaption( VOUT_TITLE " (hardware YUV SDL output)",
762 VOUT_TITLE " (hardware YUV SDL output)" );
766 SDL_WM_SetCaption( VOUT_TITLE " (software YUV SDL output)",
767 VOUT_TITLE " (software YUV SDL output)" );
771 SDL_EventState( SDL_KEYUP, SDL_IGNORE ); /* ignore keys up */
776 /*****************************************************************************
777 * CloseDisplay: close and reset SDL device
778 *****************************************************************************
779 * This function returns all resources allocated by OpenDisplay and restore
780 * the original state of the device.
781 *****************************************************************************/
782 static void CloseDisplay( vout_thread_t *p_vout )
784 SDL_FreeYUVOverlay( p_vout->p_sys->p_overlay );
785 SDL_UnlockSurface ( p_vout->p_sys->p_display );
786 SDL_FreeSurface( p_vout->p_sys->p_display );
789 /*****************************************************************************
790 * NewPicture: allocate a picture
791 *****************************************************************************
792 * Returns 0 on success, -1 otherwise
793 *****************************************************************************/
794 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
796 int i_width = p_vout->output.i_width;
797 int i_height = p_vout->output.i_height;
799 if( p_vout->p_sys->p_overlay == NULL )
802 if( p_vout->p_sys->i_surfaces )
804 /* We already allocated this surface, return */
808 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
810 if( p_pic->p_sys == NULL )
815 switch( p_vout->p_sys->p_display->format->BitsPerPixel )
818 p_pic->p->i_pixel_pitch = 1;
822 p_pic->p->i_pixel_pitch = 2;
826 p_pic->p->i_pixel_pitch = 4;
832 p_pic->p->p_pixels = p_vout->p_sys->p_display->pixels;
833 p_pic->p->i_lines = p_vout->p_sys->p_display->h;
834 p_pic->p->i_pitch = p_vout->p_sys->p_display->pitch;
835 p_pic->p->i_visible_pitch =
836 p_pic->p->i_pixel_pitch * p_vout->p_sys->p_display->w;
838 p_vout->p_sys->i_surfaces++;
844 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
846 if( p_pic->p_sys == NULL )
851 p_pic->p_sys->p_overlay =
852 SDL_CreateYUVOverlay( i_width, i_height,
853 p_vout->output.i_chroma,
854 p_vout->p_sys->p_display );
856 if( p_pic->p_sys->p_overlay == NULL )
858 free( p_pic->p_sys );
862 SDL_LockYUVOverlay( p_pic->p_sys->p_overlay );
864 p_pic->Y_PIXELS = p_pic->p_sys->p_overlay->pixels[0];
865 p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_overlay->h;
866 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[0];
868 switch( p_vout->output.i_chroma )
870 case SDL_YV12_OVERLAY:
871 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
872 p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w;
874 p_pic->U_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
875 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
876 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
877 p_pic->p[U_PLANE].i_pixel_pitch = 1;
878 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
880 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[1];
881 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
882 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
883 p_pic->p[V_PLANE].i_pixel_pitch = 1;
884 p_pic->p[V_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
889 case SDL_IYUV_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[1];
894 p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
895 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[1];
896 p_pic->p[U_PLANE].i_pixel_pitch = 1;
897 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w / 2;
899 p_pic->V_PIXELS = p_pic->p_sys->p_overlay->pixels[2];
900 p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_overlay->h / 2;
901 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_overlay->pitches[2];
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;
909 p_pic->p[Y_PLANE].i_pixel_pitch = 2;
910 p_pic->p[U_PLANE].i_visible_pitch = p_pic->p_sys->p_overlay->w * 2;
920 /*****************************************************************************
921 * SetPalette: sets an 8 bpp palette
922 *****************************************************************************/
923 static void SetPalette( vout_thread_t *p_vout,
924 uint16_t *red, uint16_t *green, uint16_t *blue )
926 SDL_Color colors[256];
929 /* Fill colors with color information */
930 for( i = 0; i < 256; i++ )
932 colors[ i ].r = red[ i ] >> 8;
933 colors[ i ].g = green[ i ] >> 8;
934 colors[ i ].b = blue[ i ] >> 8;
938 if( SDL_SetColors( p_vout->p_sys->p_display, colors, 0, 256 ) == 0 )
940 msg_Err( p_vout, "failed setting palette" );