4 * (was video_out_sdl.c from OMS project/mpeg2dec -> http://linuxvideo.org)
6 * Copyright (C) Ryan C. Gordon <icculus@lokigames.com> - April 22, 2000
8 * Copyright (C) Felix Buenemann <atmosfear@users.sourceforge.net> - 2001
10 * (for extensive code enhancements)
12 * Current maintainer for MPlayer project (report bugs to that address):
13 * Felix Buenemann <atmosfear@users.sourceforge.net>
15 * This file is a video out driver using the SDL library (http://libsdl.org/),
16 * to be used with MPlayer, further info from http://www.mplayerhq.hu
18 * -- old disclaimer --
20 * A mpeg2dec display driver that does output through the
21 * Simple DirectMedia Layer (SDL) library. This effectively gives us all
22 * sorts of output options: X11, SVGAlib, fbcon, AAlib, GGI. Win32, MacOS
23 * and BeOS support, too. Yay. SDL info, source, and binaries can be found
24 * at http://slouken.devolution.com/SDL/
26 * -- end old disclaimer --
28 * This file is part of MPlayer.
30 * MPlayer is free software; you can redistribute it and/or modify
31 * it under the terms of the GNU General Public License as published by
32 * the Free Software Foundation; either version 2 of the License, or
33 * (at your option) any later version.
35 * MPlayer is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
40 * You should have received a copy of the GNU General Public License along
41 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
42 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
45 /* define to force software-surface (video surface stored in system memory)*/
46 #undef SDL_NOHWSURFACE
48 /* define to enable surface locks, this might be needed on SMP machines */
49 #undef SDL_ENABLE_LOCKS
51 /* MONITOR_ASPECT MUST BE FLOAT */
52 #define MONITOR_ASPECT 4.0/3.0
62 #include "video_out.h"
63 #include "video_out_internal.h"
65 #include "fastmemcpy.h"
68 #include "libmpcodecs/vfcap.h"
73 #include "x11_common.h"
76 #include "subopt-helper.h"
78 static const vo_info_t info
=
80 "SDL YUV/RGB/BGR renderer (SDL v1.1.7+ only!)",
82 "Ryan C. Gordon <icculus@lokigames.com>, Felix Buenemann <atmosfear@users.sourceforge.net>",
86 const LIBVO_EXTERN(sdl
)
88 #include "sdl_common.h"
89 //#include <SDL/SDL_syswm.h>
92 #ifdef SDL_ENABLE_LOCKS
93 #define SDL_OVR_LOCK(x) if (SDL_LockYUVOverlay (priv->overlay)) { \
94 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); \
97 #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay);
99 #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf)) { \
100 if(SDL_LockSurface (srf)) { \
101 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); \
106 #define SDL_SRF_UNLOCK(srf) if(SDL_MUSTLOCK(srf)) \
107 SDL_UnlockSurface (srf);
109 #define SDL_OVR_LOCK(x)
110 #define SDL_OVR_UNLOCK
111 #define SDL_SRF_LOCK(srf, x)
112 #define SDL_SRF_UNLOCK(srf)
115 /** Private SDL Data structure **/
117 static struct sdl_priv_s
{
119 /* output driver used by sdl */
122 /* SDL display surface */
123 SDL_Surface
*surface
;
125 /* SDL RGB surface */
126 SDL_Surface
*rgbsurface
;
128 /* SDL YUV overlay */
129 SDL_Overlay
*overlay
;
131 /* available fullscreen modes */
132 SDL_Rect
**fullmodes
;
134 /* surface attributes for fullscreen and windowed mode */
135 Uint32 sdlflags
, sdlfullflags
;
137 /* save the windowed output extents */
149 /* use direct blitting to surface */
152 /* current fullscreen mode, 0 = highest available fullscreen mode */
156 int framePlaneY
, framePlaneUV
, framePlaneYUY
;
157 int stridePlaneY
, stridePlaneUV
, stridePlaneYUY
;
166 /* fullscreen behaviour; see init */
169 /* is X running (0/1) */
175 /* original image dimensions */
178 /* destination dimensions */
179 int dstwidth
, dstheight
;
181 /* Draw image at coordinate y on the SDL surfaces */
184 /* The image is displayed between those y coordinates in priv->surface */
185 int y_screen_top
, y_screen_bottom
;
187 /* 1 if the OSD has changed otherwise 0 */
190 /* source image format (YUV/RGB/...) */
193 /* dirty_off_frame[0] contains a bounding box around the osd contents drawn above the image
194 dirty_off_frame[1] is the corresponding thing for OSD contents drawn below the image
196 SDL_Rect dirty_off_frame
[2];
199 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
);
200 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
);
201 static int setup_surfaces(void);
202 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
);
203 static void erase_rectangle(int x
, int y
, int w
, int h
);
205 /* Expand 'rect' to contain the rectangle specified by x, y, w and h */
206 static void expand_rect(SDL_Rect
* rect
, int x
, int y
, int w
, int h
)
208 if(rect
->x
< 0 || rect
->y
< 0) {
222 if(rect
->x
+ rect
->w
< x
+ w
)
223 rect
->w
= x
+ w
- rect
->x
;
225 if(rect
->y
+ rect
->h
< y
+ h
)
226 rect
->h
= y
+ h
- rect
->y
;
229 /** libvo Plugin functions **/
232 * draw_alpha is used for osd and subtitle display.
236 static void draw_alpha(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
237 struct sdl_priv_s
*priv
= &sdl_priv
;
239 if(priv
->osd_has_changed
) {
240 /* OSD did change. Store a bounding box of everything drawn into the OSD */
242 /* Make sure we don't mark part of the frame area dirty */
244 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, priv
->y
- y0
);
246 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, h
);
248 else if(priv
->y
+ priv
->height
<= y0
+ h
) {
249 /* Make sure we don't mark part of the frame area dirty */
250 if(y0
< priv
->y
+ priv
->height
)
251 expand_rect(&priv
->dirty_off_frame
[1], x0
,
252 priv
->y
+ priv
->height
,
253 w
, h
- ((priv
->y
+ priv
->height
) - y0
));
255 expand_rect(&priv
->dirty_off_frame
[1], x0
, y0
, w
, h
);
258 else { /* OSD contents didn't change only draw parts that was erased by the frame */
260 src
= src
+ (priv
->y
- y0
) * stride
;
261 srca
= srca
+ (priv
->y
- y0
) * stride
;
266 if(priv
->y
+ priv
->height
<= y0
+ h
)
267 h
= priv
->y
+ priv
->height
- y0
;
273 switch(priv
->format
) {
277 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
282 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
286 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
291 x0
*= priv
->surface
->format
->BytesPerPixel
;
292 switch(priv
->format
) {
295 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
299 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
303 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
307 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
312 x0
*= priv
->rgbsurface
->format
->BytesPerPixel
;
313 switch(priv
->format
) {
316 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
320 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
324 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
328 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
338 * Take a null-terminated array of pointers, and find the last element.
340 * params : array == array of which we want to find the last element.
341 * returns : index of last NON-NULL element.
344 static inline int findArrayEnd (SDL_Rect
**array
)
347 while ( array
[i
++] ); /* keep loopin' ... */
349 /* return the index of the last array element */
355 * Open and prepare SDL output.
357 * params : *plugin ==
359 * returns : 0 on success, -1 on failure
362 static int sdl_open (void *plugin
, void *name
)
364 struct sdl_priv_s
*priv
= &sdl_priv
;
365 const SDL_VideoInfo
*vidInfo
= NULL
;
366 /*static int opened = 0;
373 /* other default values */
374 #ifdef SDL_NOHWSURFACE
375 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using software-surface\n");
376 priv
->sdlflags
= SDL_SWSURFACE
|SDL_RESIZABLE
|SDL_ANYFORMAT
;
377 priv
->sdlfullflags
= SDL_SWSURFACE
|SDL_FULLSCREEN
|SDL_ANYFORMAT
;
378 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
380 /*if((strcmp(priv->driver, "dga") == 0) && (priv->mode)) {
381 if( mp_msg_test(MSGT_VO,MSGL_V) ) {
382 printf("SDL: using software-surface\n"); }
383 priv->sdlflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
384 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
387 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using hardware-surface\n");
388 priv
->sdlflags
= SDL_HWSURFACE
|SDL_RESIZABLE
/*|SDL_ANYFORMAT*/;
389 priv
->sdlfullflags
= SDL_HWSURFACE
|SDL_FULLSCREEN
/*|SDL_ANYFORMAT*/;
390 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
394 #if !defined( __AMIGAOS4__ ) && !defined( __APPLE__ )
395 priv
->sdlfullflags
|= SDL_DOUBLEBUF
;
396 if (vo_doublebuffering
)
397 priv
->sdlflags
|= SDL_DOUBLEBUF
;
400 /* get information about the graphics adapter */
401 vidInfo
= SDL_GetVideoInfo ();
403 /* collect all fullscreen & hardware modes available */
404 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
406 /* non hardware accelerated fullscreen modes */
407 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
408 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
411 /* test for normal resizeable & windowed hardware accellerated surfaces */
412 if (!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) {
414 /* test for NON hardware accelerated resizeable surfaces - poor you.
415 * That's all we have. If this fails there's nothing left.
416 * Theoretically there could be Fullscreenmodes left - we ignore this for now.
418 priv
->sdlflags
&= ~SDL_HWSURFACE
;
419 if ((!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) && (!priv
->fullmodes
)) {
420 mp_tmsg(MSGT_VO
,MSGL_ERR
, "[VO_SDL] Couldn't get any acceptable SDL Mode for output.\n");
426 /* YUV overlays need at least 16-bit color depth, but the
427 * display might less. The SDL AAlib target says it can only do
428 * 8-bits, for example. So, if the display is less than 16-bits,
429 * we'll force the BPP to 16, and pray that SDL can emulate for us.
431 priv
->bpp
= vidInfo
->vfmt
->BitsPerPixel
;
432 if (priv
->mode
== YUV
&& priv
->bpp
< 16) {
434 mp_msg(MSGT_VO
,MSGL_V
, "SDL: Your SDL display target wants to be at a color "
435 "depth of (%d), but we need it to be at least 16 "
436 "bits, so we need to emulate 16-bit color. This is "
437 "going to slow things down; you might want to "
438 "increase your display's color depth, if possible.\n",
450 * Close SDL, Cleanups, Free Memory
453 * returns : non-zero on success, zero on error.
456 static int sdl_close (void)
458 struct sdl_priv_s
*priv
= &sdl_priv
;
463 /* Cleanup YUV Overlay structure */
465 SDL_FreeYUVOverlay(priv
->overlay
);
469 /* Free RGB Surface */
470 if (priv
->rgbsurface
) {
471 SDL_FreeSurface(priv
->rgbsurface
);
472 priv
->rgbsurface
=NULL
;
475 /* Free our blitting surface */
477 SDL_FreeSurface(priv
->surface
);
481 /* DON'T attempt to free the fullscreen modes array. SDL_Quit* does this for us */
487 * Do aspect ratio calculations
489 * params : srcw == sourcewidth
490 * srch == sourceheight
491 * dstw == destinationwidth
492 * dsth == destinationheight
494 * returns : SDL_Rect structure with new x and y, w and h
498 static SDL_Rect
aspect(int srcw
, int srch
, int dstw
, int dsth
) {
500 mp_msg(MSGT_VO
,MSGL_V
, "SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres
.w
, newres
.h
, newres
.x
, newres
.y
);
501 newres
.h
= ((float)dstw
/ (float)srcw
* (float)srch
) * ((float)dsth
/((float)dstw
/(MONITOR_ASPECT
)));
502 if(newres
.h
> dsth
) {
503 newres
.w
= ((float)dsth
/ (float)newres
.h
) * dstw
;
505 newres
.x
= (dstw
- newres
.w
) / 2;
511 newres
.y
= (dsth
- newres
.h
) / 2;
514 mp_msg(MSGT_VO
,MSGL_V
, "SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
521 * Sets the specified fullscreen mode.
523 * params : mode == index of the desired fullscreen mode
524 * returns : doesn't return
528 static void set_fullmode (int mode
)
530 struct sdl_priv_s
*priv
= &sdl_priv
;
531 SDL_Surface
*newsurface
= NULL
;
532 int haspect
, waspect
= 0;
534 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
536 mode
= priv
->fullmode
= findArrayEnd(priv
->fullmodes
) - 1;
538 /* Calculate proper aspect ratio for fullscreen
539 * Height smaller than expected: add horizontal black bars (haspect)*/
540 haspect
= (priv
->width
* (float) ((float) priv
->fullmodes
[mode
]->h
/ (float) priv
->fullmodes
[mode
]->w
) - priv
->height
) * (float) ((float) priv
->fullmodes
[mode
]->w
/ (float) priv
->width
);
541 /* Height bigger than expected: add vertical black bars (waspect)*/
543 haspect
= 0; /* set haspect to zero because image will be scaled horizontal instead of vertical */
544 waspect
= priv
->fullmodes
[mode
]->w
- ((float) ((float) priv
->fullmodes
[mode
]->h
/ (float) priv
->height
) * (float) priv
->width
);
546 // printf ("W-Aspect: %i H-Aspect: %i\n", waspect, haspect);
548 /* change to given fullscreen mode and hide the mouse cursor */
549 newsurface
= SDL_SetVideoMode(priv
->fullmodes
[mode
]->w
- waspect
, priv
->fullmodes
[mode
]->h
- haspect
, priv
->bpp
, priv
->sdlfullflags
);
551 /* if we were successful hide the mouse cursor and save the mode */
554 SDL_FreeSurface(priv
->surface
);
555 priv
->surface
= newsurface
;
561 /* Set video mode. Not fullscreen */
562 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
)
564 struct sdl_priv_s
*priv
= &sdl_priv
;
565 SDL_Surface
* newsurface
;
568 SDL_FreeSurface(priv
->rgbsurface
);
569 else if(priv
->overlay
)
570 SDL_FreeYUVOverlay(priv
->overlay
);
572 priv
->rgbsurface
= NULL
;
573 priv
->overlay
= NULL
;
575 newsurface
= SDL_SetVideoMode(width
, height
, bpp
, sdlflags
);
579 /* priv->surface will be NULL the first time this function is called. */
581 SDL_FreeSurface(priv
->surface
);
583 priv
->surface
= newsurface
;
584 priv
->dstwidth
= width
;
585 priv
->dstheight
= height
;
592 mp_msg(MSGT_VO
,MSGL_WARN
, "set_video_mode: SDL_SetVideoMode failed: %s\n", SDL_GetError());
595 static void set_fullmode (int mode
) {
596 struct sdl_priv_s
*priv
= &sdl_priv
;
597 SDL_Surface
*newsurface
= NULL
;
598 int screen_surface_w
, screen_surface_h
;
601 SDL_FreeSurface(priv
->rgbsurface
);
602 else if(priv
->overlay
)
603 SDL_FreeYUVOverlay(priv
->overlay
);
605 priv
->rgbsurface
= NULL
;
606 priv
->overlay
= NULL
;
608 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
609 /* But select a mode where the full video enter */
610 if(priv
->X
&& priv
->fulltype
& VOFLAG_FULLSCREEN
) {
611 screen_surface_w
= priv
->XWidth
;
612 screen_surface_h
= priv
->XHeight
;
616 mode
= 0; // Default to the biggest mode avaible
617 if ( mp_msg_test(MSGT_VO
,MSGL_V
) ) for(i
=0;priv
->fullmodes
[i
];++i
)
618 mp_msg(MSGT_VO
,MSGL_V
, "SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
619 for(i
= findArrayEnd(priv
->fullmodes
) - 1; i
>=0; i
--) {
620 if( (priv
->fullmodes
[i
]->w
>= priv
->dstwidth
) &&
621 (priv
->fullmodes
[i
]->h
>= priv
->dstheight
) ) {
623 for (j
= findArrayEnd(priv
->fullmodes
) - 1; j
>=0; j
--) {
624 if (priv
->fullmodes
[j
]->w
> priv
->fullmodes
[imax
]->w
625 && priv
->fullmodes
[j
]->h
== priv
->fullmodes
[imax
]->h
)
632 mp_msg(MSGT_VO
,MSGL_V
, "SET SDL Mode: %d: %d x %d\n", mode
, priv
->fullmodes
[mode
]->w
, priv
->fullmodes
[mode
]->h
);
633 priv
->fullmode
= mode
;
634 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
635 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
638 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
639 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
642 aspect_save_screenres(screen_surface_w
, screen_surface_h
);
644 /* calculate new video size/aspect */
645 if(priv
->mode
== YUV
) {
646 if(priv
->fulltype
&VOFLAG_FULLSCREEN
)
647 aspect_save_screenres(priv
->XWidth
, priv
->XHeight
);
649 aspect(&priv
->dstwidth
, &priv
->dstheight
, A_ZOOM
);
652 /* try to change to given fullscreenmode */
653 newsurface
= SDL_SetVideoMode(priv
->dstwidth
, screen_surface_h
, priv
->bpp
,
657 * In Mac OS X (and possibly others?) SDL_SetVideoMode() appears to
658 * destroy the datastructure previously retrived, so we need to
659 * re-assign it. The comment in sdl_close() seems to imply that we
660 * should not free() anything.
664 const SDL_VideoInfo
*vidInfo
= NULL
;
665 vidInfo
= SDL_GetVideoInfo ();
667 /* collect all fullscreen & hardware modes available */
668 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
670 /* non hardware accelerated fullscreen modes */
671 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
672 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
679 /* if creation of new surface was successful, save it and hide mouse cursor */
682 SDL_FreeSurface(priv
->surface
);
683 priv
->surface
= newsurface
;
685 SDL_SRF_LOCK(priv
->surface
, -1)
686 SDL_FillRect(priv
->surface
, NULL
, 0);
687 SDL_SRF_UNLOCK(priv
->surface
)
691 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Set_fullmode: SDL_SetVideoMode failed: %s.\n", SDL_GetError());
696 * Initialize an SDL surface and an SDL YUV overlay.
698 * params : width == width of video we'll be displaying.
699 * height == height of video we'll be displaying.
700 * fullscreen == want to be fullscreen?
701 * title == Title for window titlebar.
702 * returns : non-zero on success, zero on error.
706 config(uint32_t width
, uint32_t height
, uint32_t d_width
, uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
)
707 //static int sdl_setup (int width, int height)
709 struct sdl_priv_s
*priv
= &sdl_priv
;
713 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Mapping I420 to IYUV.\n");
714 format
= SDL_IYUV_OVERLAY
;
735 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Unsupported image format (0x%X).\n",format
);
739 if ( vo_config_count
) sdl_close();
741 mp_msg(MSGT_VO
,MSGL_V
, "SDL: Using 0x%X (%s) image format\n", format
, vo_format_name(format
));
743 if(priv
->mode
!= YUV
) {
744 priv
->sdlflags
|= SDL_ANYFORMAT
;
745 priv
->sdlfullflags
|= SDL_ANYFORMAT
;
748 /* SDL can only scale YUV data */
749 if(priv
->mode
== RGB
|| priv
->mode
== BGR
) {
754 aspect_save_orig(width
,height
);
755 aspect_save_prescale(d_width
? d_width
: width
, d_height
? d_height
: height
);
757 /* Save the original Image size */
759 priv
->height
= height
;
760 priv
->dstwidth
= d_width
? d_width
: width
;
761 priv
->dstheight
= d_height
? d_height
: height
;
763 priv
->format
= format
;
765 if (sdl_open(NULL
, NULL
) != 0)
768 /* Set output window title */
769 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title
);
770 //SDL_WM_SetCaption (title, title);
773 aspect_save_screenres(priv
->XWidth
,priv
->XHeight
);
774 aspect(&priv
->dstwidth
,&priv
->dstheight
,A_NOZOOM
);
777 priv
->windowsize
.w
= priv
->dstwidth
;
778 priv
->windowsize
.h
= priv
->dstheight
;
780 /* bit 0 (0x01) means fullscreen (-fs)
781 * bit 1 (0x02) means mode switching (-vm)
782 * bit 2 (0x04) enables software scaling (-zoom)
783 * bit 3 (0x08) enables flipping (-flip)
785 // printf("SDL: flags are set to: %i\n", flags);
786 // printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height);
787 if(flags
&VOFLAG_FLIPPING
) {
788 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n");
791 if(flags
&VOFLAG_FULLSCREEN
) {
792 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen without modeswitching\n");
793 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Info - please use -vm or -zoom to switch to the best resolution.\n");
794 priv
->fulltype
= VOFLAG_FULLSCREEN
;
795 set_fullmode(priv
->fullmode
);
796 /*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)))
799 if(flags
&VOFLAG_MODESWITCHING
) {
800 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
801 priv
->fulltype
= VOFLAG_MODESWITCHING
;
802 set_fullmode(priv
->fullmode
);
803 /*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags)))
806 if(flags
&VOFLAG_SWSCALE
) {
807 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
808 priv
->fulltype
= VOFLAG_SWSCALE
;
809 set_fullmode(priv
->fullmode
);
812 if((strcmp(priv
->driver
, "x11") == 0)
813 ||(strcmp(priv
->driver
, "windib") == 0)
814 ||(strcmp(priv
->driver
, "directx") == 0)
815 ||(strcmp(priv
->driver
, "Quartz") == 0)
816 ||(strcmp(priv
->driver
, "cgx") == 0)
817 ||(strcmp(priv
->driver
, "os4video") == 0)
818 ||((strcmp(priv
->driver
, "aalib") == 0) && priv
->X
)){
819 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting windowed mode\n");
820 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
823 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
824 priv
->fulltype
= VOFLAG_SWSCALE
;
825 set_fullmode(priv
->fullmode
);
829 if(!priv
->surface
) { // cannot SetVideoMode
830 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Failed to set video mode: %s.\n", SDL_GetError());
837 /* Free priv->rgbsurface or priv->overlay if they are != NULL.
838 * Setup priv->rgbsurface or priv->overlay depending on source format.
839 * The size of the created surface or overlay depends on the size of
840 * priv->surface, priv->width, priv->height, priv->dstwidth and priv->dstheight.
842 static int setup_surfaces(void)
844 struct sdl_priv_s
*priv
= &sdl_priv
;
845 float v_scale
= ((float) priv
->dstheight
) / priv
->height
;
846 int surfwidth
, surfheight
;
848 surfwidth
= priv
->width
;
849 surfheight
= priv
->height
+ (priv
->surface
->h
- priv
->dstheight
) / v_scale
;
851 /* Place the image in the middle of the screen */
852 priv
->y
= (surfheight
- priv
->height
) / 2;
853 priv
->y_screen_top
= priv
->y
* v_scale
;
854 priv
->y_screen_bottom
= priv
->y_screen_top
+ priv
->dstheight
;
856 priv
->dirty_off_frame
[0].x
= -1;
857 priv
->dirty_off_frame
[0].y
= -1;
858 priv
->dirty_off_frame
[1].x
= -1;
859 priv
->dirty_off_frame
[1].y
= -1;
861 /* Make sure the entire screen is updated */
865 SDL_FreeSurface(priv
->rgbsurface
);
866 else if(priv
->overlay
)
867 SDL_FreeYUVOverlay(priv
->overlay
);
869 priv
->rgbsurface
= NULL
;
870 priv
->overlay
= NULL
;
872 if(priv
->mode
!= YUV
&& (priv
->format
&0xFF) == priv
->bpp
) {
873 if(strcmp(priv
->driver
, "x11") == 0) {
875 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->surface
->format
->BytesPerPixel
;
876 priv
->stridePlaneRGB
= priv
->width
* priv
->surface
->format
->BytesPerPixel
;
877 erase_rectangle(0, 0, priv
->surface
->w
, priv
->surface
->h
);
882 switch(priv
->format
) {
883 /* Initialize and create the RGB Surface used for video out in BGR/RGB mode */
884 //SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
885 // SDL_SWSURFACE,SDL_HWSURFACE,SDL_SRCCOLORKEY, priv->flags? guess: exchange Rmask and Bmask for BGR<->RGB
886 // 32 bit: a:ff000000 r:ff000 g:ff00 b:ff
887 // 24 bit: r:ff0000 g:ff00 b:ff
888 // 16 bit: r:1111100000000000b g:0000011111100000b b:0000000000011111b
889 // 15 bit: r:111110000000000b g:000001111100000b b:000000000011111b
890 // FIXME: colorkey detect based on bpp, FIXME static bpp value, FIXME alpha value correct?
892 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31, 992, 31744, 0);
895 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31744, 992, 31, 0);
898 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 31, 2016, 63488, 0);
901 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 63488, 2016, 31, 0);
904 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
907 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0xFF0000, 0x00FF00, 0x0000FF, 0);
910 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0/*0xFF000000*/);
913 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0/*0xFF000000*/);
916 /* Initialize and create the YUV Overlay used for video out */
917 if (!(priv
->overlay
= SDL_CreateYUVOverlay (surfwidth
, surfheight
, priv
->format
, priv
->surface
))) {
918 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Couldn't create a YUV overlay: %s.\n", SDL_GetError());
921 priv
->framePlaneY
= priv
->width
* priv
->height
;
922 priv
->framePlaneUV
= (priv
->width
* priv
->height
) >> 2;
923 priv
->framePlaneYUY
= priv
->width
* priv
->height
* 2;
924 priv
->stridePlaneY
= priv
->width
;
925 priv
->stridePlaneUV
= priv
->width
/2;
926 priv
->stridePlaneYUY
= priv
->width
* 2;
929 if(priv
->mode
!= YUV
) {
930 if(!priv
->rgbsurface
) {
931 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Couldn't create an RGB surface: %s.\n", SDL_GetError());
937 if((priv
->format
&0xFF) != priv
->bpp
)
938 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Using depth/colorspace conversion, this will slow things down (%ibpp -> %ibpp).\n", priv
->format
&0xFF, priv
->bpp
);
940 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->rgbsurface
->format
->BytesPerPixel
;
941 priv
->stridePlaneRGB
= priv
->width
* priv
->rgbsurface
->format
->BytesPerPixel
;
944 erase_rectangle(0, 0, surfwidth
, surfheight
);
951 * Draw a frame to the SDL YUV overlay.
953 * params : *src[] == the Y, U, and V planes that make up the frame.
954 * returns : non-zero on success, zero on error.
957 //static int sdl_draw_frame (frame_t *frame)
958 static int draw_frame(uint8_t *src
[])
960 struct sdl_priv_s
*priv
= &sdl_priv
;
963 uint8_t *mysrc
= src
[0];
965 switch(priv
->format
){
970 dst
= (uint8_t *) *(priv
->overlay
->pixels
) + priv
->overlay
->pitches
[0]*priv
->y
;
972 mysrc
+=priv
->framePlaneYUY
;
973 for(i
= 0; i
< priv
->height
; i
++) {
974 mysrc
-=priv
->stridePlaneYUY
;
975 fast_memcpy (dst
, mysrc
, priv
->stridePlaneYUY
);
976 dst
+=priv
->overlay
->pitches
[0];
979 else fast_memcpy (dst
, src
[0], priv
->framePlaneYUY
);
992 SDL_SRF_LOCK(priv
->surface
, -1)
993 dst
= (uint8_t *) priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
995 mysrc
+=priv
->framePlaneRGB
;
996 for(i
= 0; i
< priv
->height
; i
++) {
997 mysrc
-=priv
->stridePlaneRGB
;
998 fast_memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
999 dst
+= priv
->surface
->pitch
;
1002 else fast_memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1003 SDL_SRF_UNLOCK(priv
->surface
)
1005 SDL_SRF_LOCK(priv
->rgbsurface
, -1)
1006 dst
= (uint8_t *) priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1008 mysrc
+=priv
->framePlaneRGB
;
1009 for(i
= 0; i
< priv
->height
; i
++) {
1010 mysrc
-=priv
->stridePlaneRGB
;
1011 fast_memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
1012 dst
+= priv
->rgbsurface
->pitch
;
1015 else fast_memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1016 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1027 * Draw a slice (16 rows of image) to the SDL YUV overlay.
1029 * params : *src[] == the Y, U, and V planes that make up the slice.
1030 * returns : non-zero on error, zero on success.
1033 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
1034 static int draw_slice(uint8_t *image
[], int stride
[], int w
,int h
,int x
,int y
)
1036 struct sdl_priv_s
*priv
= &sdl_priv
;
1043 dst
= priv
->overlay
->pixels
[0] + priv
->overlay
->pitches
[0]*y
+ x
;
1044 memcpy_pic(dst
, image
[0], w
, h
, priv
->overlay
->pitches
[0], stride
[0]);
1045 x
/=2;y
/=2;w
/=2;h
/=2;
1047 switch(priv
->format
) {
1049 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1050 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[2], stride
[1]);
1052 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1053 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[1], stride
[2]);
1058 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1059 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[1], stride
[1]);
1061 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1062 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[2], stride
[2]);
1066 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Unsupported image format in draw_slice, contact MPlayer developers!\n");
1077 * Checks for SDL keypress and window resize events
1080 * returns : doesn't return
1083 static void check_events (void)
1085 struct sdl_priv_s
*priv
= &sdl_priv
;
1087 SDLKey keypressed
= SDLK_UNKNOWN
;
1089 /* Poll the waiting SDL Events */
1090 while ( SDL_PollEvent(&event
) ) {
1091 switch (event
.type
) {
1093 /* capture window resize events */
1094 case SDL_VIDEORESIZE
:
1096 set_video_mode(event
.resize
.w
, event
.resize
.h
, priv
->bpp
, priv
->sdlflags
);
1098 /* save video extents, to restore them after going fullscreen */
1099 //if(!(priv->surface->flags & SDL_FULLSCREEN)) {
1100 priv
->windowsize
.w
= priv
->surface
->w
;
1101 priv
->windowsize
.h
= priv
->surface
->h
;
1103 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Window resize\n");
1106 /* graphics mode selection shortcuts */
1108 keypressed
= event
.key
.keysym
.sym
;
1109 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Key pressed: '%i'\n", keypressed
);
1111 /* c key pressed. c cycles through available fullscreenmodes, if we have some */
1112 if ( ((keypressed
== SDLK_c
)) && (priv
->fullmodes
) ) {
1113 /* select next fullscreen mode */
1115 if (priv
->fullmode
> (findArrayEnd(priv
->fullmodes
) - 1)) priv
->fullmode
= 0;
1116 set_fullmode(priv
->fullmode
);
1118 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Set next available fullscreen mode.\n");
1121 else if ( keypressed
== SDLK_n
) {
1123 aspect(&priv
->dstwidth
, &priv
->dstheight
,A_NOZOOM
);
1125 if (priv
->surface
->w
!= priv
->dstwidth
|| priv
->surface
->h
!= priv
->dstheight
) {
1126 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
1127 priv
->windowsize
.w
= priv
->surface
->w
;
1128 priv
->windowsize
.h
= priv
->surface
->h
;
1129 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Normal size\n");
1131 if (priv
->surface
->w
!= priv
->dstwidth
* 2 || priv
->surface
->h
!= priv
->dstheight
* 2) {
1132 set_video_mode(priv
->dstwidth
* 2, priv
->dstheight
* 2, priv
->bpp
, priv
->sdlflags
);
1133 priv
->windowsize
.w
= priv
->surface
->w
;
1134 priv
->windowsize
.h
= priv
->surface
->h
;
1135 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Double size\n");
1139 else sdl_default_handle_event(&event
);
1142 default: sdl_default_handle_event(&event
); break;
1147 /* Erase (paint it black) the rectangle specified by x, y, w and h in the surface
1148 or overlay which is used for OSD
1150 static void erase_rectangle(int x
, int y
, int w
, int h
)
1152 struct sdl_priv_s
*priv
= &sdl_priv
;
1154 switch(priv
->format
) {
1159 SDL_OVR_LOCK((void) 0)
1162 erase_area_1(x
, w
, h
,
1163 priv
->overlay
->pitches
[0], 0,
1164 priv
->overlay
->pixels
[0] +
1165 priv
->overlay
->pitches
[0]*y
);
1167 /* Erase U and V planes */
1173 erase_area_1(x
, w
, h
,
1174 priv
->overlay
->pitches
[1], 128,
1175 priv
->overlay
->pixels
[1] +
1176 priv
->overlay
->pitches
[1]*y
);
1178 erase_area_1(x
, w
, h
,
1179 priv
->overlay
->pitches
[2], 128,
1180 priv
->overlay
->pixels
[2] +
1181 priv
->overlay
->pitches
[2]*y
);
1189 SDL_OVR_LOCK((void) 0)
1190 erase_area_4(x
*2, w
*2, h
,
1191 priv
->overlay
->pitches
[0],
1192 be2me_32(0x00800080), /* yuy2 and yvyu represent black the same way */
1193 priv
->overlay
->pixels
[0] +
1194 priv
->overlay
->pitches
[0]*y
);
1201 SDL_OVR_LOCK((void) 0)
1202 erase_area_4(x
*2, w
*2, h
,
1203 priv
->overlay
->pitches
[0],
1204 be2me_32(0x80008000),
1205 priv
->overlay
->pixels
[0] +
1206 priv
->overlay
->pitches
[0]*y
);
1221 rect
.w
= w
; rect
.h
= h
;
1222 rect
.x
= x
; rect
.y
= y
;
1225 SDL_SRF_LOCK(priv
->surface
, (void) 0)
1226 SDL_FillRect(priv
->surface
, &rect
, 0);
1227 SDL_SRF_UNLOCK(priv
->surface
)
1230 SDL_SRF_LOCK(priv
->rgbsurface
, (void) 0)
1231 SDL_FillRect(priv
->rgbsurface
, &rect
, 0);
1232 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1239 static void draw_osd(void)
1240 { struct sdl_priv_s
*priv
= &sdl_priv
;
1242 priv
->osd_has_changed
= vo_osd_changed(0);
1244 if(priv
->osd_has_changed
)
1248 for(i
= 0; i
< 2; i
++) {
1249 if(priv
->dirty_off_frame
[i
].x
< 0 || priv
->dirty_off_frame
[i
].y
< 0)
1252 erase_rectangle(priv
->dirty_off_frame
[i
].x
, priv
->dirty_off_frame
[i
].y
,
1253 priv
->dirty_off_frame
[i
].w
, priv
->dirty_off_frame
[i
].h
);
1255 priv
->dirty_off_frame
[i
].x
= -1;
1256 priv
->dirty_off_frame
[i
].y
= -1;
1260 /* update osd/subtitles */
1261 if(priv
->mode
== YUV
)
1262 vo_draw_text(priv
->overlay
->w
, priv
->overlay
->h
, draw_alpha
);
1265 vo_draw_text(priv
->surface
->w
, priv
->surface
->h
, draw_alpha
);
1267 vo_draw_text(priv
->rgbsurface
->w
, priv
->rgbsurface
->h
, draw_alpha
);
1271 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1272 * are given in bytes. 4 bytes at a time.
1274 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
)
1276 int x_end
= x_start
/4 + width
/4;
1278 uint32_t* data
= (uint32_t*) pixels
;
1283 for(y
= 0; y
< height
; y
++) {
1284 for(x
= x_start
; x
< x_end
; x
++)
1285 data
[y
*pitch
+ x
] = color
;
1289 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1290 * are given in bytes. 1 byte at a time.
1292 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
)
1296 for(y
= 0; y
< height
; y
++) {
1297 memset(&pixels
[y
*pitch
+ x_start
], color
, width
);
1302 * Display the surface we have written our data to
1304 * params : mode == index of the desired fullscreen mode
1305 * returns : doesn't return
1308 static void flip_page (void)
1310 struct sdl_priv_s
*priv
= &sdl_priv
;
1312 switch(priv
->format
) {
1322 /* blit to the RGB surface */
1323 if(SDL_BlitSurface (priv
->rgbsurface
, NULL
, priv
->surface
, NULL
))
1324 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Blit failed: %s.\n", SDL_GetError());
1328 //SDL_UpdateRect(priv->surface, 0, 0, priv->surface->clip_rect.w, priv->surface->clip_rect.h);
1329 if(priv
->osd_has_changed
) {
1330 priv
->osd_has_changed
= 0;
1331 SDL_UpdateRects(priv
->surface
, 1, &priv
->surface
->clip_rect
);
1334 SDL_UpdateRect(priv
->surface
, 0, priv
->y_screen_top
,
1335 priv
->surface
->clip_rect
.w
, priv
->y_screen_bottom
);
1337 /* check if we have a double buffered surface and flip() if we do. */
1338 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1339 SDL_Flip(priv
->surface
);
1343 /* blit to the YUV overlay */
1344 SDL_DisplayYUVOverlay (priv
->overlay
, &priv
->surface
->clip_rect
);
1346 /* check if we have a double buffered surface and flip() if we do. */
1347 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1348 SDL_Flip(priv
->surface
);
1350 //SDL_LockYUVOverlay (priv->overlay); // removed because unused!?
1355 query_format(uint32_t format
)
1359 // it seems buggy (not hw accelerated), so just use YV12 instead!
1360 // case IMGFMT_I420:
1361 // case IMGFMT_IYUV:
1365 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_OSD
|
1366 VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1375 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_FLIP
;
1385 struct sdl_priv_s
*priv
= &sdl_priv
;
1387 mp_msg(MSGT_VO
,MSGL_V
, "SDL: activating XScreensaver/DPMS\n");
1396 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Closed Plugin\n");
1400 static int preinit(const char *arg
)
1402 struct sdl_priv_s
*priv
= &sdl_priv
;
1403 char * sdl_driver
= NULL
;
1406 const opt_t subopts
[] = {
1407 {"forcexv", OPT_ARG_BOOL
, &sdl_forcexv
, NULL
},
1408 {"hwaccel", OPT_ARG_BOOL
, &sdl_hwaccel
, NULL
},
1409 {"driver", OPT_ARG_MSTRZ
, &sdl_driver
, NULL
},
1410 {NULL
, 0, NULL
, NULL
}
1416 if (subopt_parse(arg
, subopts
) != 0) return -1;
1418 priv
->rgbsurface
= NULL
;
1419 priv
->overlay
= NULL
;
1420 priv
->surface
= NULL
;
1422 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Opening Plugin\n");
1425 setenv("SDL_VIDEODRIVER", sdl_driver
, 1);
1429 /* does the user want SDL to try and force Xv */
1430 if(sdl_forcexv
) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);
1431 else setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "0", 1);
1433 /* does the user want to disable Xv and use software scaling instead */
1434 if(sdl_hwaccel
) setenv("SDL_VIDEO_YUV_HWACCEL", "1", 1);
1435 else setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
1437 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */
1438 priv
->fullmode
= -2;
1440 priv
->fullmodes
= NULL
;
1443 /* initialize the SDL Video system */
1444 if (!vo_sdl_init()) {
1445 mp_tmsg(MSGT_VO
,MSGL_ERR
, "[VO_SDL] SDL initialization failed: %s.\n", SDL_GetError());
1450 SDL_VideoDriverName(priv
->driver
, 8);
1451 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Using driver: %s.\n", priv
->driver
);
1456 mp_msg(MSGT_VO
,MSGL_V
, "SDL: deactivating XScreensaver/DPMS\n");
1457 priv
->XWidth
= vo_screenwidth
;
1458 priv
->XHeight
= vo_screenheight
;
1460 mp_msg(MSGT_VO
,MSGL_V
, "SDL: X11 Resolution %ix%i\n", priv
->XWidth
, priv
->XHeight
);
1467 static uint32_t get_image(mp_image_t
*mpi
)
1469 struct sdl_priv_s
*priv
= &sdl_priv
;
1471 if(priv
->format
!= mpi
->imgfmt
) return VO_FALSE
;
1472 if(mpi
->type
== MP_IMGTYPE_STATIC
|| mpi
->type
== MP_IMGTYPE_TEMP
) {
1473 if(mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1474 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1475 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1476 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
) {
1477 mpi
->planes
[1] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1478 mpi
->stride
[1] = priv
->overlay
->pitches
[1];
1479 mpi
->planes
[2] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1480 mpi
->stride
[2] = priv
->overlay
->pitches
[2];
1482 mpi
->planes
[2] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1483 mpi
->stride
[2] = priv
->overlay
->pitches
[1];
1484 mpi
->planes
[1] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1485 mpi
->stride
[1] = priv
->overlay
->pitches
[2];
1488 else if(IMGFMT_IS_RGB(priv
->format
) || IMGFMT_IS_BGR(priv
->format
)) {
1490 if(mpi
->type
== MP_IMGTYPE_STATIC
&& (priv
->surface
->flags
& SDL_DOUBLEBUF
))
1493 mpi
->planes
[0] = (uint8_t *)priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
1494 mpi
->stride
[0] = priv
->surface
->pitch
;
1497 mpi
->planes
[0] = (uint8_t *)priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1498 mpi
->stride
[0] = priv
->rgbsurface
->pitch
;
1502 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1503 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1506 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1513 static int control(uint32_t request
, void *data
)
1515 struct sdl_priv_s
*priv
= &sdl_priv
;
1517 case VOCTRL_GET_IMAGE
:
1518 return get_image(data
);
1519 case VOCTRL_QUERY_FORMAT
:
1520 return query_format(*((uint32_t*)data
));
1521 case VOCTRL_FULLSCREEN
:
1522 if (priv
->surface
->flags
& SDL_FULLSCREEN
) {
1523 set_video_mode(priv
->windowsize
.w
, priv
->windowsize
.h
, priv
->bpp
, priv
->sdlflags
);
1525 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Windowed mode\n");
1526 } else if (priv
->fullmodes
) {
1527 set_fullmode(priv
->fullmode
);
1528 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Set fullscreen mode\n");