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"
72 #include "x11_common.h"
75 #include "subopt-helper.h"
77 static const vo_info_t info
=
79 "SDL YUV/RGB/BGR renderer (SDL v1.1.7+ only!)",
81 "Ryan C. Gordon <icculus@lokigames.com>, Felix Buenemann <atmosfear@users.sourceforge.net>",
85 const LIBVO_EXTERN(sdl
)
87 #include "sdl_common.h"
88 //#include <SDL/SDL_syswm.h>
91 #ifdef SDL_ENABLE_LOCKS
92 #define SDL_OVR_LOCK(x) if (SDL_LockYUVOverlay (priv->overlay)) { \
93 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock YUV overlay\n"); \
96 #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay);
98 #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf)) { \
99 if(SDL_LockSurface (srf)) { \
100 mp_msg(MSGT_VO,MSGL_V, "SDL: Couldn't lock RGB surface\n"); \
105 #define SDL_SRF_UNLOCK(srf) if(SDL_MUSTLOCK(srf)) \
106 SDL_UnlockSurface (srf);
108 #define SDL_OVR_LOCK(x)
109 #define SDL_OVR_UNLOCK
110 #define SDL_SRF_LOCK(srf, x)
111 #define SDL_SRF_UNLOCK(srf)
114 /** Private SDL Data structure **/
116 static struct sdl_priv_s
{
118 /* output driver used by sdl */
121 /* SDL display surface */
122 SDL_Surface
*surface
;
124 /* SDL RGB surface */
125 SDL_Surface
*rgbsurface
;
127 /* SDL YUV overlay */
128 SDL_Overlay
*overlay
;
130 /* available fullscreen modes */
131 SDL_Rect
**fullmodes
;
133 /* surface attributes for fullscreen and windowed mode */
134 Uint32 sdlflags
, sdlfullflags
;
136 /* save the windowed output extents */
148 /* use direct blitting to surface */
151 /* current fullscreen mode, 0 = highest available fullscreen mode */
155 int framePlaneY
, framePlaneUV
, framePlaneYUY
;
156 int stridePlaneY
, stridePlaneUV
, stridePlaneYUY
;
165 /* fullscreen behaviour; see init */
168 /* is X running (0/1) */
174 /* original image dimensions */
177 /* destination dimensions */
178 int dstwidth
, dstheight
;
180 /* Draw image at coordinate y on the SDL surfaces */
183 /* The image is displayed between those y coordinates in priv->surface */
184 int y_screen_top
, y_screen_bottom
;
186 /* 1 if the OSD has changed otherwise 0 */
189 /* source image format (YUV/RGB/...) */
192 /* dirty_off_frame[0] contains a bounding box around the osd contents drawn above the image
193 dirty_off_frame[1] is the corresponding thing for OSD contents drawn below the image
195 SDL_Rect dirty_off_frame
[2];
198 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
);
199 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
);
200 static int setup_surfaces(void);
201 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
);
202 static void erase_rectangle(int x
, int y
, int w
, int h
);
204 /* Expand 'rect' to contain the rectangle specified by x, y, w and h */
205 static void expand_rect(SDL_Rect
* rect
, int x
, int y
, int w
, int h
)
207 if(rect
->x
< 0 || rect
->y
< 0) {
221 if(rect
->x
+ rect
->w
< x
+ w
)
222 rect
->w
= x
+ w
- rect
->x
;
224 if(rect
->y
+ rect
->h
< y
+ h
)
225 rect
->h
= y
+ h
- rect
->y
;
228 /** libvo Plugin functions **/
231 * draw_alpha is used for osd and subtitle display.
235 static void draw_alpha(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
236 struct sdl_priv_s
*priv
= &sdl_priv
;
238 if(priv
->osd_has_changed
) {
239 /* OSD did change. Store a bounding box of everything drawn into the OSD */
241 /* Make sure we don't mark part of the frame area dirty */
243 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, priv
->y
- y0
);
245 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, h
);
247 else if(priv
->y
+ priv
->height
<= y0
+ h
) {
248 /* Make sure we don't mark part of the frame area dirty */
249 if(y0
< priv
->y
+ priv
->height
)
250 expand_rect(&priv
->dirty_off_frame
[1], x0
,
251 priv
->y
+ priv
->height
,
252 w
, h
- ((priv
->y
+ priv
->height
) - y0
));
254 expand_rect(&priv
->dirty_off_frame
[1], x0
, y0
, w
, h
);
257 else { /* OSD contents didn't change only draw parts that was erased by the frame */
259 src
= src
+ (priv
->y
- y0
) * stride
;
260 srca
= srca
+ (priv
->y
- y0
) * stride
;
265 if(priv
->y
+ priv
->height
<= y0
+ h
)
266 h
= priv
->y
+ priv
->height
- y0
;
272 switch(priv
->format
) {
276 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
281 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
285 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
290 x0
*= priv
->surface
->format
->BytesPerPixel
;
291 switch(priv
->format
) {
294 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
298 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
302 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
306 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
311 x0
*= priv
->rgbsurface
->format
->BytesPerPixel
;
312 switch(priv
->format
) {
315 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
319 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
323 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
327 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
337 * Take a null-terminated array of pointers, and find the last element.
339 * params : array == array of which we want to find the last element.
340 * returns : index of last NON-NULL element.
343 static inline int findArrayEnd (SDL_Rect
**array
)
346 while ( array
[i
++] ); /* keep loopin' ... */
348 /* return the index of the last array element */
354 * Open and prepare SDL output.
356 * params : *plugin ==
358 * returns : 0 on success, -1 on failure
361 static int sdl_open (void *plugin
, void *name
)
363 struct sdl_priv_s
*priv
= &sdl_priv
;
364 const SDL_VideoInfo
*vidInfo
= NULL
;
365 /*static int opened = 0;
372 /* other default values */
373 #ifdef SDL_NOHWSURFACE
374 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using software-surface\n");
375 priv
->sdlflags
= SDL_SWSURFACE
|SDL_RESIZABLE
|SDL_ANYFORMAT
;
376 priv
->sdlfullflags
= SDL_SWSURFACE
|SDL_FULLSCREEN
|SDL_ANYFORMAT
;
377 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
379 /*if((strcmp(priv->driver, "dga") == 0) && (priv->mode)) {
380 if( mp_msg_test(MSGT_VO,MSGL_V) ) {
381 printf("SDL: using software-surface\n"); }
382 priv->sdlflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
383 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
386 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using hardware-surface\n");
387 priv
->sdlflags
= SDL_HWSURFACE
|SDL_RESIZABLE
/*|SDL_ANYFORMAT*/;
388 priv
->sdlfullflags
= SDL_HWSURFACE
|SDL_FULLSCREEN
/*|SDL_ANYFORMAT*/;
389 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
393 #if !defined( __AMIGAOS4__ ) && !defined( __APPLE__ )
394 priv
->sdlfullflags
|= SDL_DOUBLEBUF
;
395 if (vo_doublebuffering
)
396 priv
->sdlflags
|= SDL_DOUBLEBUF
;
399 /* get information about the graphics adapter */
400 vidInfo
= SDL_GetVideoInfo ();
402 /* collect all fullscreen & hardware modes available */
403 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
405 /* non hardware accelerated fullscreen modes */
406 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
407 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
410 /* test for normal resizeable & windowed hardware accellerated surfaces */
411 if (!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) {
413 /* test for NON hardware accelerated resizeable surfaces - poor you.
414 * That's all we have. If this fails there's nothing left.
415 * Theoretically there could be Fullscreenmodes left - we ignore this for now.
417 priv
->sdlflags
&= ~SDL_HWSURFACE
;
418 if ((!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) && (!priv
->fullmodes
)) {
419 mp_tmsg(MSGT_VO
,MSGL_ERR
, "[VO_SDL] Couldn't get any acceptable SDL Mode for output.\n");
425 /* YUV overlays need at least 16-bit color depth, but the
426 * display might less. The SDL AAlib target says it can only do
427 * 8-bits, for example. So, if the display is less than 16-bits,
428 * we'll force the BPP to 16, and pray that SDL can emulate for us.
430 priv
->bpp
= vidInfo
->vfmt
->BitsPerPixel
;
431 if (priv
->mode
== YUV
&& priv
->bpp
< 16) {
433 mp_msg(MSGT_VO
,MSGL_V
, "SDL: Your SDL display target wants to be at a color "
434 "depth of (%d), but we need it to be at least 16 "
435 "bits, so we need to emulate 16-bit color. This is "
436 "going to slow things down; you might want to "
437 "increase your display's color depth, if possible.\n",
449 * Close SDL, Cleanups, Free Memory
452 * returns : non-zero on success, zero on error.
455 static int sdl_close (void)
457 struct sdl_priv_s
*priv
= &sdl_priv
;
462 /* Cleanup YUV Overlay structure */
464 SDL_FreeYUVOverlay(priv
->overlay
);
468 /* Free RGB Surface */
469 if (priv
->rgbsurface
) {
470 SDL_FreeSurface(priv
->rgbsurface
);
471 priv
->rgbsurface
=NULL
;
474 /* Free our blitting surface */
476 SDL_FreeSurface(priv
->surface
);
480 /* DON'T attempt to free the fullscreen modes array. SDL_Quit* does this for us */
486 * Do aspect ratio calculations
488 * params : srcw == sourcewidth
489 * srch == sourceheight
490 * dstw == destinationwidth
491 * dsth == destinationheight
493 * returns : SDL_Rect structure with new x and y, w and h
497 static SDL_Rect
aspect(int srcw
, int srch
, int dstw
, int dsth
) {
499 mp_msg(MSGT_VO
,MSGL_V
, "SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres
.w
, newres
.h
, newres
.x
, newres
.y
);
500 newres
.h
= ((float)dstw
/ (float)srcw
* (float)srch
) * ((float)dsth
/((float)dstw
/(MONITOR_ASPECT
)));
501 if(newres
.h
> dsth
) {
502 newres
.w
= ((float)dsth
/ (float)newres
.h
) * dstw
;
504 newres
.x
= (dstw
- newres
.w
) / 2;
510 newres
.y
= (dsth
- newres
.h
) / 2;
513 mp_msg(MSGT_VO
,MSGL_V
, "SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
520 * Sets the specified fullscreen mode.
522 * params : mode == index of the desired fullscreen mode
523 * returns : doesn't return
527 static void set_fullmode (int mode
)
529 struct sdl_priv_s
*priv
= &sdl_priv
;
530 SDL_Surface
*newsurface
= NULL
;
531 int haspect
, waspect
= 0;
533 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
535 mode
= priv
->fullmode
= findArrayEnd(priv
->fullmodes
) - 1;
537 /* Calculate proper aspect ratio for fullscreen
538 * Height smaller than expected: add horizontal black bars (haspect)*/
539 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
);
540 /* Height bigger than expected: add vertical black bars (waspect)*/
542 haspect
= 0; /* set haspect to zero because image will be scaled horizontal instead of vertical */
543 waspect
= priv
->fullmodes
[mode
]->w
- ((float) ((float) priv
->fullmodes
[mode
]->h
/ (float) priv
->height
) * (float) priv
->width
);
545 // printf ("W-Aspect: %i H-Aspect: %i\n", waspect, haspect);
547 /* change to given fullscreen mode and hide the mouse cursor */
548 newsurface
= SDL_SetVideoMode(priv
->fullmodes
[mode
]->w
- waspect
, priv
->fullmodes
[mode
]->h
- haspect
, priv
->bpp
, priv
->sdlfullflags
);
550 /* if we were successful hide the mouse cursor and save the mode */
553 SDL_FreeSurface(priv
->surface
);
554 priv
->surface
= newsurface
;
560 /* Set video mode. Not fullscreen */
561 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
)
563 struct sdl_priv_s
*priv
= &sdl_priv
;
564 SDL_Surface
* newsurface
;
567 SDL_FreeSurface(priv
->rgbsurface
);
568 else if(priv
->overlay
)
569 SDL_FreeYUVOverlay(priv
->overlay
);
571 priv
->rgbsurface
= NULL
;
572 priv
->overlay
= NULL
;
574 newsurface
= SDL_SetVideoMode(width
, height
, bpp
, sdlflags
);
578 /* priv->surface will be NULL the first time this function is called. */
580 SDL_FreeSurface(priv
->surface
);
582 priv
->surface
= newsurface
;
583 priv
->dstwidth
= width
;
584 priv
->dstheight
= height
;
591 mp_msg(MSGT_VO
,MSGL_WARN
, "set_video_mode: SDL_SetVideoMode failed: %s\n", SDL_GetError());
594 static void set_fullmode (int mode
) {
595 struct sdl_priv_s
*priv
= &sdl_priv
;
596 SDL_Surface
*newsurface
= NULL
;
597 int screen_surface_w
, screen_surface_h
;
600 SDL_FreeSurface(priv
->rgbsurface
);
601 else if(priv
->overlay
)
602 SDL_FreeYUVOverlay(priv
->overlay
);
604 priv
->rgbsurface
= NULL
;
605 priv
->overlay
= NULL
;
607 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
608 /* But select a mode where the full video enter */
609 if(priv
->X
&& priv
->fulltype
& VOFLAG_FULLSCREEN
) {
610 screen_surface_w
= priv
->XWidth
;
611 screen_surface_h
= priv
->XHeight
;
615 mode
= 0; // Default to the biggest mode avaible
616 if ( mp_msg_test(MSGT_VO
,MSGL_V
) ) for(i
=0;priv
->fullmodes
[i
];++i
)
617 mp_msg(MSGT_VO
,MSGL_V
, "SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
618 for(i
= findArrayEnd(priv
->fullmodes
) - 1; i
>=0; i
--) {
619 if( (priv
->fullmodes
[i
]->w
>= priv
->dstwidth
) &&
620 (priv
->fullmodes
[i
]->h
>= priv
->dstheight
) ) {
622 for (j
= findArrayEnd(priv
->fullmodes
) - 1; j
>=0; j
--) {
623 if (priv
->fullmodes
[j
]->w
> priv
->fullmodes
[imax
]->w
624 && priv
->fullmodes
[j
]->h
== priv
->fullmodes
[imax
]->h
)
631 mp_msg(MSGT_VO
,MSGL_V
, "SET SDL Mode: %d: %d x %d\n", mode
, priv
->fullmodes
[mode
]->w
, priv
->fullmodes
[mode
]->h
);
632 priv
->fullmode
= mode
;
633 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
634 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
637 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
638 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
641 aspect_save_screenres(screen_surface_w
, screen_surface_h
);
643 /* calculate new video size/aspect */
644 if(priv
->mode
== YUV
) {
645 if(priv
->fulltype
&VOFLAG_FULLSCREEN
)
646 aspect_save_screenres(priv
->XWidth
, priv
->XHeight
);
648 aspect(&priv
->dstwidth
, &priv
->dstheight
, A_ZOOM
);
651 /* try to change to given fullscreenmode */
652 newsurface
= SDL_SetVideoMode(priv
->dstwidth
, screen_surface_h
, priv
->bpp
,
656 * In Mac OS X (and possibly others?) SDL_SetVideoMode() appears to
657 * destroy the datastructure previously retrived, so we need to
658 * re-assign it. The comment in sdl_close() seems to imply that we
659 * should not free() anything.
663 const SDL_VideoInfo
*vidInfo
= NULL
;
664 vidInfo
= SDL_GetVideoInfo ();
666 /* collect all fullscreen & hardware modes available */
667 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
669 /* non hardware accelerated fullscreen modes */
670 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
671 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
678 /* if creation of new surface was successful, save it and hide mouse cursor */
681 SDL_FreeSurface(priv
->surface
);
682 priv
->surface
= newsurface
;
684 SDL_SRF_LOCK(priv
->surface
, -1)
685 SDL_FillRect(priv
->surface
, NULL
, 0);
686 SDL_SRF_UNLOCK(priv
->surface
)
690 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Set_fullmode: SDL_SetVideoMode failed: %s.\n", SDL_GetError());
695 * Initialize an SDL surface and an SDL YUV overlay.
697 * params : width == width of video we'll be displaying.
698 * height == height of video we'll be displaying.
699 * fullscreen == want to be fullscreen?
700 * title == Title for window titlebar.
701 * returns : non-zero on success, zero on error.
705 config(uint32_t width
, uint32_t height
, uint32_t d_width
, uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
)
706 //static int sdl_setup (int width, int height)
708 struct sdl_priv_s
*priv
= &sdl_priv
;
712 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Mapping I420 to IYUV.\n");
713 format
= SDL_IYUV_OVERLAY
;
734 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Unsupported image format (0x%X).\n",format
);
738 if ( vo_config_count
) sdl_close();
740 mp_msg(MSGT_VO
,MSGL_V
, "SDL: Using 0x%X (%s) image format\n", format
, vo_format_name(format
));
742 if(priv
->mode
!= YUV
) {
743 priv
->sdlflags
|= SDL_ANYFORMAT
;
744 priv
->sdlfullflags
|= SDL_ANYFORMAT
;
747 /* SDL can only scale YUV data */
748 if(priv
->mode
== RGB
|| priv
->mode
== BGR
) {
753 aspect_save_orig(width
,height
);
754 aspect_save_prescale(d_width
? d_width
: width
, d_height
? d_height
: height
);
756 /* Save the original Image size */
758 priv
->height
= height
;
759 priv
->dstwidth
= d_width
? d_width
: width
;
760 priv
->dstheight
= d_height
? d_height
: height
;
762 priv
->format
= format
;
764 if (sdl_open(NULL
, NULL
) != 0)
767 /* Set output window title */
768 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title
);
769 //SDL_WM_SetCaption (title, title);
772 aspect_save_screenres(priv
->XWidth
,priv
->XHeight
);
773 aspect(&priv
->dstwidth
,&priv
->dstheight
,A_NOZOOM
);
776 priv
->windowsize
.w
= priv
->dstwidth
;
777 priv
->windowsize
.h
= priv
->dstheight
;
779 /* bit 0 (0x01) means fullscreen (-fs)
780 * bit 1 (0x02) means mode switching (-vm)
781 * bit 2 (0x04) enables software scaling (-zoom)
782 * bit 3 (0x08) enables flipping (-flip)
784 // printf("SDL: flags are set to: %i\n", flags);
785 // printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height);
786 if(flags
&VOFLAG_FLIPPING
) {
787 mp_msg(MSGT_VO
,MSGL_V
, "SDL: using flipped video (only with RGB/BGR/packed YUV)\n");
790 if(flags
&VOFLAG_FULLSCREEN
) {
791 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen without modeswitching\n");
792 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Info - please use -vm or -zoom to switch to the best resolution.\n");
793 priv
->fulltype
= VOFLAG_FULLSCREEN
;
794 set_fullmode(priv
->fullmode
);
795 /*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)))
798 if(flags
&VOFLAG_MODESWITCHING
) {
799 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
800 priv
->fulltype
= VOFLAG_MODESWITCHING
;
801 set_fullmode(priv
->fullmode
);
802 /*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags)))
805 if(flags
&VOFLAG_SWSCALE
) {
806 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
807 priv
->fulltype
= VOFLAG_SWSCALE
;
808 set_fullmode(priv
->fullmode
);
811 if((strcmp(priv
->driver
, "x11") == 0)
812 ||(strcmp(priv
->driver
, "windib") == 0)
813 ||(strcmp(priv
->driver
, "directx") == 0)
814 ||(strcmp(priv
->driver
, "Quartz") == 0)
815 ||(strcmp(priv
->driver
, "cgx") == 0)
816 ||(strcmp(priv
->driver
, "os4video") == 0)
817 ||((strcmp(priv
->driver
, "aalib") == 0) && priv
->X
)){
818 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting windowed mode\n");
819 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
822 mp_msg(MSGT_VO
,MSGL_V
, "SDL: setting zoomed fullscreen with modeswitching\n");
823 priv
->fulltype
= VOFLAG_SWSCALE
;
824 set_fullmode(priv
->fullmode
);
828 if(!priv
->surface
) { // cannot SetVideoMode
829 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Failed to set video mode: %s.\n", SDL_GetError());
836 /* Free priv->rgbsurface or priv->overlay if they are != NULL.
837 * Setup priv->rgbsurface or priv->overlay depending on source format.
838 * The size of the created surface or overlay depends on the size of
839 * priv->surface, priv->width, priv->height, priv->dstwidth and priv->dstheight.
841 static int setup_surfaces(void)
843 struct sdl_priv_s
*priv
= &sdl_priv
;
844 float v_scale
= ((float) priv
->dstheight
) / priv
->height
;
845 int surfwidth
, surfheight
;
847 surfwidth
= priv
->width
;
848 surfheight
= priv
->height
+ (priv
->surface
->h
- priv
->dstheight
) / v_scale
;
850 /* Place the image in the middle of the screen */
851 priv
->y
= (surfheight
- priv
->height
) / 2;
852 priv
->y_screen_top
= priv
->y
* v_scale
;
853 priv
->y_screen_bottom
= priv
->y_screen_top
+ priv
->dstheight
;
855 priv
->dirty_off_frame
[0].x
= -1;
856 priv
->dirty_off_frame
[0].y
= -1;
857 priv
->dirty_off_frame
[1].x
= -1;
858 priv
->dirty_off_frame
[1].y
= -1;
860 /* Make sure the entire screen is updated */
864 SDL_FreeSurface(priv
->rgbsurface
);
865 else if(priv
->overlay
)
866 SDL_FreeYUVOverlay(priv
->overlay
);
868 priv
->rgbsurface
= NULL
;
869 priv
->overlay
= NULL
;
871 if(priv
->mode
!= YUV
&& (priv
->format
&0xFF) == priv
->bpp
) {
872 if(strcmp(priv
->driver
, "x11") == 0) {
874 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->surface
->format
->BytesPerPixel
;
875 priv
->stridePlaneRGB
= priv
->width
* priv
->surface
->format
->BytesPerPixel
;
876 erase_rectangle(0, 0, priv
->surface
->w
, priv
->surface
->h
);
881 switch(priv
->format
) {
882 /* Initialize and create the RGB Surface used for video out in BGR/RGB mode */
883 //SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
884 // SDL_SWSURFACE,SDL_HWSURFACE,SDL_SRCCOLORKEY, priv->flags? guess: exchange Rmask and Bmask for BGR<->RGB
885 // 32 bit: a:ff000000 r:ff000 g:ff00 b:ff
886 // 24 bit: r:ff0000 g:ff00 b:ff
887 // 16 bit: r:1111100000000000b g:0000011111100000b b:0000000000011111b
888 // 15 bit: r:111110000000000b g:000001111100000b b:000000000011111b
889 // FIXME: colorkey detect based on bpp, FIXME static bpp value, FIXME alpha value correct?
891 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31, 992, 31744, 0);
894 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31744, 992, 31, 0);
897 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 31, 2016, 63488, 0);
900 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 63488, 2016, 31, 0);
903 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
906 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0xFF0000, 0x00FF00, 0x0000FF, 0);
909 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0/*0xFF000000*/);
912 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0/*0xFF000000*/);
915 /* Initialize and create the YUV Overlay used for video out */
916 if (!(priv
->overlay
= SDL_CreateYUVOverlay (surfwidth
, surfheight
, priv
->format
, priv
->surface
))) {
917 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Couldn't create a YUV overlay: %s.\n", SDL_GetError());
920 priv
->framePlaneY
= priv
->width
* priv
->height
;
921 priv
->framePlaneUV
= (priv
->width
* priv
->height
) >> 2;
922 priv
->framePlaneYUY
= priv
->width
* priv
->height
* 2;
923 priv
->stridePlaneY
= priv
->width
;
924 priv
->stridePlaneUV
= priv
->width
/2;
925 priv
->stridePlaneYUY
= priv
->width
* 2;
928 if(priv
->mode
!= YUV
) {
929 if(!priv
->rgbsurface
) {
930 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Couldn't create an RGB surface: %s.\n", SDL_GetError());
936 if((priv
->format
&0xFF) != priv
->bpp
)
937 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
);
939 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->rgbsurface
->format
->BytesPerPixel
;
940 priv
->stridePlaneRGB
= priv
->width
* priv
->rgbsurface
->format
->BytesPerPixel
;
943 erase_rectangle(0, 0, surfwidth
, surfheight
);
950 * Draw a frame to the SDL YUV overlay.
952 * params : *src[] == the Y, U, and V planes that make up the frame.
953 * returns : non-zero on success, zero on error.
956 //static int sdl_draw_frame (frame_t *frame)
957 static int draw_frame(uint8_t *src
[])
959 struct sdl_priv_s
*priv
= &sdl_priv
;
962 uint8_t *mysrc
= src
[0];
964 switch(priv
->format
){
969 dst
= (uint8_t *) *(priv
->overlay
->pixels
) + priv
->overlay
->pitches
[0]*priv
->y
;
971 mysrc
+=priv
->framePlaneYUY
;
972 for(i
= 0; i
< priv
->height
; i
++) {
973 mysrc
-=priv
->stridePlaneYUY
;
974 fast_memcpy (dst
, mysrc
, priv
->stridePlaneYUY
);
975 dst
+=priv
->overlay
->pitches
[0];
978 else fast_memcpy (dst
, src
[0], priv
->framePlaneYUY
);
991 SDL_SRF_LOCK(priv
->surface
, -1)
992 dst
= (uint8_t *) priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
994 mysrc
+=priv
->framePlaneRGB
;
995 for(i
= 0; i
< priv
->height
; i
++) {
996 mysrc
-=priv
->stridePlaneRGB
;
997 fast_memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
998 dst
+= priv
->surface
->pitch
;
1001 else fast_memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1002 SDL_SRF_UNLOCK(priv
->surface
)
1004 SDL_SRF_LOCK(priv
->rgbsurface
, -1)
1005 dst
= (uint8_t *) priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1007 mysrc
+=priv
->framePlaneRGB
;
1008 for(i
= 0; i
< priv
->height
; i
++) {
1009 mysrc
-=priv
->stridePlaneRGB
;
1010 fast_memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
1011 dst
+= priv
->rgbsurface
->pitch
;
1014 else fast_memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1015 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1026 * Draw a slice (16 rows of image) to the SDL YUV overlay.
1028 * params : *src[] == the Y, U, and V planes that make up the slice.
1029 * returns : non-zero on error, zero on success.
1032 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
1033 static int draw_slice(uint8_t *image
[], int stride
[], int w
,int h
,int x
,int y
)
1035 struct sdl_priv_s
*priv
= &sdl_priv
;
1042 dst
= priv
->overlay
->pixels
[0] + priv
->overlay
->pitches
[0]*y
+ x
;
1043 memcpy_pic(dst
, image
[0], w
, h
, priv
->overlay
->pitches
[0], stride
[0]);
1044 x
/=2;y
/=2;w
/=2;h
/=2;
1046 switch(priv
->format
) {
1048 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1049 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[2], stride
[1]);
1051 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1052 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[1], stride
[2]);
1057 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1058 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[1], stride
[1]);
1060 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1061 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[2], stride
[2]);
1065 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Unsupported image format in draw_slice, contact MPlayer developers!\n");
1076 * Checks for SDL keypress and window resize events
1079 * returns : doesn't return
1082 static void check_events (void)
1084 struct sdl_priv_s
*priv
= &sdl_priv
;
1086 SDLKey keypressed
= SDLK_UNKNOWN
;
1088 /* Poll the waiting SDL Events */
1089 while ( SDL_PollEvent(&event
) ) {
1090 switch (event
.type
) {
1092 /* capture window resize events */
1093 case SDL_VIDEORESIZE
:
1095 set_video_mode(event
.resize
.w
, event
.resize
.h
, priv
->bpp
, priv
->sdlflags
);
1097 /* save video extents, to restore them after going fullscreen */
1098 //if(!(priv->surface->flags & SDL_FULLSCREEN)) {
1099 priv
->windowsize
.w
= priv
->surface
->w
;
1100 priv
->windowsize
.h
= priv
->surface
->h
;
1102 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Window resize\n");
1105 /* graphics mode selection shortcuts */
1107 keypressed
= event
.key
.keysym
.sym
;
1108 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Key pressed: '%i'\n", keypressed
);
1110 /* c key pressed. c cycles through available fullscreenmodes, if we have some */
1111 if ( ((keypressed
== SDLK_c
)) && (priv
->fullmodes
) ) {
1112 /* select next fullscreen mode */
1114 if (priv
->fullmode
> (findArrayEnd(priv
->fullmodes
) - 1)) priv
->fullmode
= 0;
1115 set_fullmode(priv
->fullmode
);
1117 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Set next available fullscreen mode.\n");
1120 else if ( keypressed
== SDLK_n
) {
1122 aspect(&priv
->dstwidth
, &priv
->dstheight
,A_NOZOOM
);
1124 if (priv
->surface
->w
!= priv
->dstwidth
|| priv
->surface
->h
!= priv
->dstheight
) {
1125 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
1126 priv
->windowsize
.w
= priv
->surface
->w
;
1127 priv
->windowsize
.h
= priv
->surface
->h
;
1128 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Normal size\n");
1130 if (priv
->surface
->w
!= priv
->dstwidth
* 2 || priv
->surface
->h
!= priv
->dstheight
* 2) {
1131 set_video_mode(priv
->dstwidth
* 2, priv
->dstheight
* 2, priv
->bpp
, priv
->sdlflags
);
1132 priv
->windowsize
.w
= priv
->surface
->w
;
1133 priv
->windowsize
.h
= priv
->surface
->h
;
1134 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Double size\n");
1138 else sdl_default_handle_event(&event
);
1141 default: sdl_default_handle_event(&event
); break;
1146 /* Erase (paint it black) the rectangle specified by x, y, w and h in the surface
1147 or overlay which is used for OSD
1149 static void erase_rectangle(int x
, int y
, int w
, int h
)
1151 struct sdl_priv_s
*priv
= &sdl_priv
;
1153 switch(priv
->format
) {
1158 SDL_OVR_LOCK((void) 0)
1161 erase_area_1(x
, w
, h
,
1162 priv
->overlay
->pitches
[0], 0,
1163 priv
->overlay
->pixels
[0] +
1164 priv
->overlay
->pitches
[0]*y
);
1166 /* Erase U and V planes */
1172 erase_area_1(x
, w
, h
,
1173 priv
->overlay
->pitches
[1], 128,
1174 priv
->overlay
->pixels
[1] +
1175 priv
->overlay
->pitches
[1]*y
);
1177 erase_area_1(x
, w
, h
,
1178 priv
->overlay
->pitches
[2], 128,
1179 priv
->overlay
->pixels
[2] +
1180 priv
->overlay
->pitches
[2]*y
);
1188 /* yuy2 and yvyu represent black the same way */
1189 uint8_t yuy2_black
[] = {0, 128, 0, 128};
1191 SDL_OVR_LOCK((void) 0)
1192 erase_area_4(x
*2, w
*2, h
,
1193 priv
->overlay
->pitches
[0],
1194 *((uint32_t*) yuy2_black
),
1195 priv
->overlay
->pixels
[0] +
1196 priv
->overlay
->pitches
[0]*y
);
1203 uint8_t uyvy_black
[] = {128, 0, 128, 0};
1205 SDL_OVR_LOCK((void) 0)
1206 erase_area_4(x
*2, w
*2, h
,
1207 priv
->overlay
->pitches
[0],
1208 *((uint32_t*) uyvy_black
),
1209 priv
->overlay
->pixels
[0] +
1210 priv
->overlay
->pitches
[0]*y
);
1225 rect
.w
= w
; rect
.h
= h
;
1226 rect
.x
= x
; rect
.y
= y
;
1229 SDL_SRF_LOCK(priv
->surface
, (void) 0)
1230 SDL_FillRect(priv
->surface
, &rect
, 0);
1231 SDL_SRF_UNLOCK(priv
->surface
)
1234 SDL_SRF_LOCK(priv
->rgbsurface
, (void) 0)
1235 SDL_FillRect(priv
->rgbsurface
, &rect
, 0);
1236 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1243 static void draw_osd(void)
1244 { struct sdl_priv_s
*priv
= &sdl_priv
;
1246 priv
->osd_has_changed
= vo_osd_changed(0);
1248 if(priv
->osd_has_changed
)
1252 for(i
= 0; i
< 2; i
++) {
1253 if(priv
->dirty_off_frame
[i
].x
< 0 || priv
->dirty_off_frame
[i
].y
< 0)
1256 erase_rectangle(priv
->dirty_off_frame
[i
].x
, priv
->dirty_off_frame
[i
].y
,
1257 priv
->dirty_off_frame
[i
].w
, priv
->dirty_off_frame
[i
].h
);
1259 priv
->dirty_off_frame
[i
].x
= -1;
1260 priv
->dirty_off_frame
[i
].y
= -1;
1264 /* update osd/subtitles */
1265 if(priv
->mode
== YUV
)
1266 vo_draw_text(priv
->overlay
->w
, priv
->overlay
->h
, draw_alpha
);
1269 vo_draw_text(priv
->surface
->w
, priv
->surface
->h
, draw_alpha
);
1271 vo_draw_text(priv
->rgbsurface
->w
, priv
->rgbsurface
->h
, draw_alpha
);
1275 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1276 * are given in bytes. 4 bytes at a time.
1278 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
)
1280 int x_end
= x_start
/4 + width
/4;
1282 uint32_t* data
= (uint32_t*) pixels
;
1287 for(y
= 0; y
< height
; y
++) {
1288 for(x
= x_start
; x
< x_end
; x
++)
1289 data
[y
*pitch
+ x
] = color
;
1293 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1294 * are given in bytes. 1 byte at a time.
1296 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
)
1300 for(y
= 0; y
< height
; y
++) {
1301 memset(&pixels
[y
*pitch
+ x_start
], color
, width
);
1306 * Display the surface we have written our data to
1308 * params : mode == index of the desired fullscreen mode
1309 * returns : doesn't return
1312 static void flip_page (void)
1314 struct sdl_priv_s
*priv
= &sdl_priv
;
1316 switch(priv
->format
) {
1326 /* blit to the RGB surface */
1327 if(SDL_BlitSurface (priv
->rgbsurface
, NULL
, priv
->surface
, NULL
))
1328 mp_tmsg(MSGT_VO
,MSGL_WARN
, "[VO_SDL] Blit failed: %s.\n", SDL_GetError());
1332 //SDL_UpdateRect(priv->surface, 0, 0, priv->surface->clip_rect.w, priv->surface->clip_rect.h);
1333 if(priv
->osd_has_changed
) {
1334 priv
->osd_has_changed
= 0;
1335 SDL_UpdateRects(priv
->surface
, 1, &priv
->surface
->clip_rect
);
1338 SDL_UpdateRect(priv
->surface
, 0, priv
->y_screen_top
,
1339 priv
->surface
->clip_rect
.w
, priv
->y_screen_bottom
);
1341 /* check if we have a double buffered surface and flip() if we do. */
1342 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1343 SDL_Flip(priv
->surface
);
1347 /* blit to the YUV overlay */
1348 SDL_DisplayYUVOverlay (priv
->overlay
, &priv
->surface
->clip_rect
);
1350 /* check if we have a double buffered surface and flip() if we do. */
1351 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1352 SDL_Flip(priv
->surface
);
1354 //SDL_LockYUVOverlay (priv->overlay); // removed because unused!?
1359 query_format(uint32_t format
)
1363 // it seems buggy (not hw accelerated), so just use YV12 instead!
1364 // case IMGFMT_I420:
1365 // case IMGFMT_IYUV:
1369 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_OSD
|
1370 VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1379 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_FLIP
;
1389 struct sdl_priv_s
*priv
= &sdl_priv
;
1391 mp_msg(MSGT_VO
,MSGL_V
, "SDL: activating XScreensaver/DPMS\n");
1400 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Closed Plugin\n");
1404 static int preinit(const char *arg
)
1406 struct sdl_priv_s
*priv
= &sdl_priv
;
1407 char * sdl_driver
= NULL
;
1410 const opt_t subopts
[] = {
1411 {"forcexv", OPT_ARG_BOOL
, &sdl_forcexv
, NULL
},
1412 {"hwaccel", OPT_ARG_BOOL
, &sdl_hwaccel
, NULL
},
1413 {"driver", OPT_ARG_MSTRZ
, &sdl_driver
, NULL
},
1414 {NULL
, 0, NULL
, NULL
}
1420 if (subopt_parse(arg
, subopts
) != 0) return -1;
1422 priv
->rgbsurface
= NULL
;
1423 priv
->overlay
= NULL
;
1424 priv
->surface
= NULL
;
1426 mp_msg(MSGT_VO
,MSGL_DBG3
, "SDL: Opening Plugin\n");
1429 setenv("SDL_VIDEODRIVER", sdl_driver
, 1);
1433 /* does the user want SDL to try and force Xv */
1434 if(sdl_forcexv
) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);
1435 else setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "0", 1);
1437 /* does the user want to disable Xv and use software scaling instead */
1438 if(sdl_hwaccel
) setenv("SDL_VIDEO_YUV_HWACCEL", "1", 1);
1439 else setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
1441 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */
1442 priv
->fullmode
= -2;
1444 priv
->fullmodes
= NULL
;
1447 /* initialize the SDL Video system */
1448 if (!vo_sdl_init()) {
1449 mp_tmsg(MSGT_VO
,MSGL_ERR
, "[VO_SDL] SDL initialization failed: %s.\n", SDL_GetError());
1454 SDL_VideoDriverName(priv
->driver
, 8);
1455 mp_tmsg(MSGT_VO
,MSGL_INFO
, "[VO_SDL] Using driver: %s.\n", priv
->driver
);
1460 mp_msg(MSGT_VO
,MSGL_V
, "SDL: deactivating XScreensaver/DPMS\n");
1461 priv
->XWidth
= vo_screenwidth
;
1462 priv
->XHeight
= vo_screenheight
;
1464 mp_msg(MSGT_VO
,MSGL_V
, "SDL: X11 Resolution %ix%i\n", priv
->XWidth
, priv
->XHeight
);
1471 static uint32_t get_image(mp_image_t
*mpi
)
1473 struct sdl_priv_s
*priv
= &sdl_priv
;
1475 if(priv
->format
!= mpi
->imgfmt
) return VO_FALSE
;
1476 if(mpi
->type
== MP_IMGTYPE_STATIC
|| mpi
->type
== MP_IMGTYPE_TEMP
) {
1477 if(mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1478 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1479 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1480 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
) {
1481 mpi
->planes
[1] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1482 mpi
->stride
[1] = priv
->overlay
->pitches
[1];
1483 mpi
->planes
[2] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1484 mpi
->stride
[2] = priv
->overlay
->pitches
[2];
1486 mpi
->planes
[2] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1487 mpi
->stride
[2] = priv
->overlay
->pitches
[1];
1488 mpi
->planes
[1] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1489 mpi
->stride
[1] = priv
->overlay
->pitches
[2];
1492 else if(IMGFMT_IS_RGB(priv
->format
) || IMGFMT_IS_BGR(priv
->format
)) {
1494 if(mpi
->type
== MP_IMGTYPE_STATIC
&& (priv
->surface
->flags
& SDL_DOUBLEBUF
))
1497 mpi
->planes
[0] = (uint8_t *)priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
1498 mpi
->stride
[0] = priv
->surface
->pitch
;
1501 mpi
->planes
[0] = (uint8_t *)priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1502 mpi
->stride
[0] = priv
->rgbsurface
->pitch
;
1506 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1507 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1510 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1517 static int control(uint32_t request
, void *data
)
1519 struct sdl_priv_s
*priv
= &sdl_priv
;
1521 case VOCTRL_GET_IMAGE
:
1522 return get_image(data
);
1523 case VOCTRL_QUERY_FORMAT
:
1524 return query_format(*((uint32_t*)data
));
1525 case VOCTRL_FULLSCREEN
:
1526 if (priv
->surface
->flags
& SDL_FULLSCREEN
) {
1527 set_video_mode(priv
->windowsize
.w
, priv
->windowsize
.h
, priv
->bpp
, priv
->sdlflags
);
1529 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Windowed mode\n");
1530 } else if (priv
->fullmodes
) {
1531 set_fullmode(priv
->fullmode
);
1532 mp_msg(MSGT_VO
,MSGL_DBG2
, "SDL: Set fullscreen mode\n");