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 [The Movie Player for Linux] project, further info
17 * from http://www.mplayerhq.hu
19 * -- old disclaimer --
21 * A mpeg2dec display driver that does output through the
22 * Simple DirectMedia Layer (SDL) library. This effectively gives us all
23 * sorts of output options: X11, SVGAlib, fbcon, AAlib, GGI. Win32, MacOS
24 * and BeOS support, too. Yay. SDL info, source, and binaries can be found
25 * at http://slouken.devolution.com/SDL/
27 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
29 * mpeg2dec is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2, or (at your option)
34 * mpeg2dec is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with GNU Make; see the file COPYING. If not, write to
41 * the Free Software Foundation.
43 * -- end old disclaimer --
46 * Dominik Schnitzer <dominik@schnitzer.at> - November 08, 2000.
47 * - Added resizing support, fullscreen: changed the sdlmodes selection
49 * - SDL bugfixes: removed the atexit(SLD_Quit), SDL_Quit now resides in
50 * the plugin_exit routine.
51 * - Commented the source :)
52 * - Shortcuts: for switching between Fullscreen/Windowed mode and for
53 * cycling between the different Fullscreen modes.
54 * - Small bugfixes: proper width/height of movie
55 * Dominik Schnitzer <dominik@schnitzer.at> - November 11, 2000.
56 * - Cleanup code, more comments
57 * - Better error handling
58 * Bruno Barreyra <barreyra@ufl.edu> - December 10, 2000.
59 * - Eliminated memcpy's for entire frames
60 * Felix Buenemann <Atmosfear@users.sourceforge.net> - March 11, 2001
61 * - Added aspect-ratio awareness for fullscreen
62 * Felix Buenemann <Atmosfear@users.sourceforge.net> - March 11, 2001
63 * - Fixed aspect-ratio awareness, did only vertical scaling (black bars above
64 * and below), now also does horizontal scaling (black bars left and right),
65 * so you get the biggest possible picture with correct aspect-ratio.
66 * Felix Buenemann <Atmosfear@users.sourceforge.net> - March 12, 2001
67 * - Minor bugfix to aspect-ratio for non-4:3-resolutions (like 1280x1024)
68 * - Bugfix to check_events() to reveal mouse cursor after 'q'-quit in
70 * Felix Buenemann <Atmosfear@users.sourceforge.net> - April 10, 2001
71 * - Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
72 * bug (key had to be pressed twice to be detected)
73 * - Changed key-handling: 'f' cycles fullscreen/windowed, ESC/RETURN/'q' quits
74 * - Bugfix which avoids exit, because return is passed to sdl-output on startup,
75 * which caused the player to exit (keyboard-buffer problem? better solution
77 * Felix Buenemann <Atmosfear@users.sourceforge.net> - April 11, 2001
78 * - OSD and subtitle support added
79 * - some minor code-changes
80 * - added code to comply with new fullscreen meaning
81 * - changed fullscreen-mode-cycling from '+' to 'c' (interferred with audiosync
83 * Felix Buenemann <Atmosfear@users.sourceforge.net> - April 13, 2001
84 * - added keymapping to toggle OSD ('o' key)
85 * - added some defines to modify some sdl-out internas (see comments)
87 * Felix Buenemann: further changes will be visible through cvs log, don't want
88 * to update this all the time (CVS info on http://mplayer.sourceforge.net)
92 /* define to force software-surface (video surface stored in system memory)*/
93 #undef SDL_NOHWSURFACE
95 /* define to enable surface locks, this might be needed on SMP machines */
96 #undef SDL_ENABLE_LOCKS
98 //#define BUGGY_SDL //defined by configure
100 /* MONITOR_ASPECT MUST BE FLOAT */
101 #define MONITOR_ASPECT 4.0/3.0
106 #include <inttypes.h>
109 #include "video_out.h"
110 #include "video_out_internal.h"
112 #include "fastmemcpy.h"
115 #include "libmpcodecs/vfcap.h"
118 #include <X11/Xlib.h>
119 #include "x11_common.h"
122 #include "input/input.h"
123 #include "input/mouse.h"
129 static vo_info_t info
=
131 "SDL YUV/RGB/BGR renderer (SDL v1.1.7+ only!)",
133 "Ryan C. Gordon <icculus@lokigames.com>, Felix Buenemann <atmosfear@users.sourceforge.net>",
140 //#include <SDL/SDL_syswm.h>
142 #if defined(__MINGW32__) || defined(HPUX) || defined(sgi) || (defined(sun) && defined(__svr4__))
143 /* setenv is missing on win32, solaris, IRIX and HPUX */
144 static void setenv(const char *name
, const char *val
, int _xx
)
146 int len
= strlen(name
) + strlen(val
) + 2;
147 char *env
= malloc(len
);
164 #ifdef SDL_ENABLE_LOCKS
165 #define SDL_OVR_LOCK(x) if (SDL_LockYUVOverlay (priv->overlay)) { \
166 if(verbose) printf("SDL: Couldn't lock YUV overlay\n"); \
169 #define SDL_OVR_UNLOCK SDL_UnlockYUVOverlay (priv->overlay);
171 #define SDL_SRF_LOCK(srf, x) if(SDL_MUSTLOCK(srf)) { \
172 if(SDL_LockSurface (srf)) { \
173 if(verbose) printf("SDL: Couldn't lock RGB surface\n"); \
178 #define SDL_SRF_UNLOCK(srf) if(SDL_MUSTLOCK(srf)) \
179 SDL_UnlockSurface (srf);
181 #define SDL_OVR_LOCK(x)
182 #define SDL_OVR_UNLOCK
183 #define SDL_SRF_LOCK(srf, x)
184 #define SDL_SRF_UNLOCK(srf)
187 /** Private SDL Data structure **/
189 static struct sdl_priv_s
{
191 /* output driver used by sdl */
194 /* SDL display surface */
195 SDL_Surface
*surface
;
197 /* SDL RGB surface */
198 SDL_Surface
*rgbsurface
;
200 /* SDL YUV overlay */
201 SDL_Overlay
*overlay
;
203 /* available fullscreen modes */
204 SDL_Rect
**fullmodes
;
206 /* surface attributes for fullscreen and windowed mode */
207 Uint32 sdlflags
, sdlfullflags
;
209 /* save the windowed output extents */
221 /* use direct blitting to surface */
224 /* current fullscreen mode, 0 = highest available fullscreen mode */
228 int framePlaneY
, framePlaneUV
, framePlaneYUY
;
229 int stridePlaneY
, stridePlaneUV
, stridePlaneYUY
;
238 /* fullscreen behaviour; see init */
241 /* is X running (0/1) */
247 /* original image dimensions */
250 /* destination dimensions */
251 int dstwidth
, dstheight
;
253 /* Draw image at coordinate y on the SDL surfaces */
256 /* The image is displayed between those y coordinates in priv->surface */
257 int y_screen_top
, y_screen_bottom
;
259 /* 1 if the OSD has changed otherwise 0 */
262 /* source image format (YUV/RGB/...) */
265 /* dirty_off_frame[0] contains a bounding box around the osd contents drawn above the image
266 dirty_off_frame[1] is the corresponding thing for OSD contents drawn below the image
268 SDL_Rect dirty_off_frame
[2];
271 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
);
272 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
);
273 static int setup_surfaces(void);
274 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
);
275 static void erase_rectangle(int x
, int y
, int w
, int h
);
277 /* Expand 'rect' to contain the rectangle specified by x, y, w and h */
278 static void expand_rect(SDL_Rect
* rect
, int x
, int y
, int w
, int h
)
280 if(rect
->x
< 0 || rect
->y
< 0) {
294 if(rect
->x
+ rect
->w
< x
+ w
)
295 rect
->w
= x
+ w
- rect
->x
;
297 if(rect
->y
+ rect
->h
< y
+ h
)
298 rect
->h
= y
+ h
- rect
->y
;
301 /** libvo Plugin functions **/
304 * draw_alpha is used for osd and subtitle display.
308 static void draw_alpha(int x0
,int y0
, int w
,int h
, unsigned char* src
, unsigned char *srca
, int stride
){
309 struct sdl_priv_s
*priv
= &sdl_priv
;
311 if(priv
->osd_has_changed
) {
312 /* OSD did change. Store a bounding box of everything drawn into the OSD */
314 /* Make sure we don't mark part of the frame area dirty */
316 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, priv
->y
- y0
);
318 expand_rect(&priv
->dirty_off_frame
[0], x0
, y0
, w
, h
);
320 else if(priv
->y
+ priv
->height
<= y0
+ h
) {
321 /* Make sure we don't mark part of the frame area dirty */
322 if(y0
< priv
->y
+ priv
->height
)
323 expand_rect(&priv
->dirty_off_frame
[1], x0
,
324 priv
->y
+ priv
->height
,
325 w
, h
- ((priv
->y
+ priv
->height
) - y0
));
327 expand_rect(&priv
->dirty_off_frame
[1], x0
, y0
, w
, h
);
330 else { /* OSD contents didn't change only draw parts that was erased by the frame */
332 src
= src
+ (priv
->y
- y0
) * stride
;
333 srca
= srca
+ (priv
->y
- y0
) * stride
;
338 if(priv
->y
+ priv
->height
<= y0
+ h
)
339 h
= priv
->y
+ priv
->height
- y0
;
345 switch(priv
->format
) {
349 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
354 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
358 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) *(priv
->overlay
->pixels
))+priv
->overlay
->pitches
[0]*y0
+x0
,priv
->overlay
->pitches
[0]);
363 x0
*= priv
->surface
->format
->BytesPerPixel
;
364 switch(priv
->format
) {
367 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
371 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
375 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
379 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->surface
->pixels
)+y0
*priv
->surface
->pitch
+x0
,priv
->surface
->pitch
);
384 x0
*= priv
->rgbsurface
->format
->BytesPerPixel
;
385 switch(priv
->format
) {
388 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
392 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
396 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
400 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) priv
->rgbsurface
->pixels
)+y0
*priv
->rgbsurface
->pitch
+x0
,priv
->rgbsurface
->pitch
);
410 * Take a null-terminated array of pointers, and find the last element.
412 * params : array == array of which we want to find the last element.
413 * returns : index of last NON-NULL element.
416 static inline int findArrayEnd (SDL_Rect
**array
)
419 while ( array
[i
++] ); /* keep loopin' ... */
421 /* return the index of the last array element */
427 * Open and prepare SDL output.
429 * params : *plugin ==
431 * returns : 0 on success, -1 on failure
434 static int sdl_open (void *plugin
, void *name
)
436 struct sdl_priv_s
*priv
= &sdl_priv
;
437 const SDL_VideoInfo
*vidInfo
= NULL
;
438 /*static int opened = 0;
445 /* other default values */
446 #ifdef SDL_NOHWSURFACE
447 if(verbose
) printf("SDL: using software-surface\n");
448 priv
->sdlflags
= SDL_SWSURFACE
|SDL_RESIZABLE
|SDL_ANYFORMAT
;
449 priv
->sdlfullflags
= SDL_SWSURFACE
|SDL_FULLSCREEN
|SDL_ANYFORMAT
;
450 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
452 /*if((strcmp(priv->driver, "dga") == 0) && (priv->mode)) {
453 if(verbose) printf("SDL: using software-surface\n");
454 priv->sdlflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
455 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_ANYFORMAT;
458 if(verbose
) printf("SDL: using hardware-surface\n");
459 priv
->sdlflags
= SDL_HWSURFACE
|SDL_RESIZABLE
/*|SDL_ANYFORMAT*/;
460 priv
->sdlfullflags
= SDL_HWSURFACE
|SDL_FULLSCREEN
/*|SDL_ANYFORMAT*/;
461 // XXX:FIXME: ASYNCBLIT should be enabled for SMP systems
466 priv
->sdlfullflags
|= SDL_DOUBLEBUF
;
467 if (vo_doublebuffering
)
468 priv
->sdlflags
|= SDL_DOUBLEBUF
;
471 /* Setup Keyrepeats (500/30 are defaults) */
472 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);
474 /* get information about the graphics adapter */
475 vidInfo
= SDL_GetVideoInfo ();
477 /* collect all fullscreen & hardware modes available */
478 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
480 /* non hardware accelerated fullscreen modes */
481 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
482 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
485 /* test for normal resizeable & windowed hardware accellerated surfaces */
486 if (!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) {
488 /* test for NON hardware accelerated resizeable surfaces - poor you.
489 * That's all we have. If this fails there's nothing left.
490 * Theoretically there could be Fullscreenmodes left - we ignore this for now.
492 priv
->sdlflags
&= ~SDL_HWSURFACE
;
493 if ((!SDL_ListModes (vidInfo
->vfmt
, priv
->sdlflags
)) && (!priv
->fullmodes
)) {
494 printf("SDL: Couldn't get any acceptable SDL Mode for output.\n");
500 /* YUV overlays need at least 16-bit color depth, but the
501 * display might less. The SDL AAlib target says it can only do
502 * 8-bits, for example. So, if the display is less than 16-bits,
503 * we'll force the BPP to 16, and pray that SDL can emulate for us.
505 priv
->bpp
= vidInfo
->vfmt
->BitsPerPixel
;
506 if (priv
->mode
== YUV
&& priv
->bpp
< 16) {
508 if(verbose
) printf("SDL: Your SDL display target wants to be at a color "
509 "depth of (%d), but we need it to be at least 16 "
510 "bits, so we need to emulate 16-bit color. This is "
511 "going to slow things down; you might want to "
512 "increase your display's color depth, if possible.\n",
518 /* We don't want those in our event queue.
519 * We use SDL_KEYUP cause SDL_KEYDOWN seems to cause problems
520 * with keys need to be pressed twice, to be recognized.
523 SDL_EventState(SDL_ACTIVEEVENT
, SDL_IGNORE
);
524 SDL_EventState(SDL_MOUSEMOTION
, SDL_IGNORE
);
525 // SDL_EventState(SDL_QUIT, SDL_IGNORE);
526 SDL_EventState(SDL_SYSWMEVENT
, SDL_IGNORE
);
527 SDL_EventState(SDL_USEREVENT
, SDL_IGNORE
);
536 * Close SDL, Cleanups, Free Memory
539 * returns : non-zero on success, zero on error.
542 static int sdl_close (void)
544 struct sdl_priv_s
*priv
= &sdl_priv
;
549 /* Cleanup YUV Overlay structure */
551 SDL_FreeYUVOverlay(priv
->overlay
);
555 /* Free RGB Surface */
556 if (priv
->rgbsurface
) {
557 SDL_FreeSurface(priv
->rgbsurface
);
558 priv
->rgbsurface
=NULL
;
561 /* Free our blitting surface */
563 SDL_FreeSurface(priv
->surface
);
567 /* DON'T attempt to free the fullscreen modes array. SDL_Quit* does this for us */
573 * Do aspect ratio calculations
575 * params : srcw == sourcewidth
576 * srch == sourceheight
577 * dstw == destinationwidth
578 * dsth == destinationheight
580 * returns : SDL_Rect structure with new x and y, w and h
584 static SDL_Rect
aspect(int srcw
, int srch
, int dstw
, int dsth
) {
586 if(verbose
> 1) printf("SDL Aspect: src: %ix%i dst: %ix%i\n", srcw
, srch
, dstw
, dsth
);
587 newres
.h
= ((float)dstw
/ (float)srcw
* (float)srch
) * ((float)dsth
/((float)dstw
/(MONITOR_ASPECT
)));
588 if(newres
.h
> dsth
) {
589 newres
.w
= ((float)dsth
/ (float)newres
.h
) * dstw
;
591 newres
.x
= (dstw
- newres
.w
) / 2;
597 newres
.y
= (dsth
- newres
.h
) / 2;
600 if(verbose
) printf("SDL Aspect-Destinationres: %ix%i (x: %i, y: %i)\n", newres
.w
, newres
.h
, newres
.x
, newres
.y
);
607 * Sets the specified fullscreen mode.
609 * params : mode == index of the desired fullscreen mode
610 * returns : doesn't return
614 static void set_fullmode (int mode
)
616 struct sdl_priv_s
*priv
= &sdl_priv
;
617 SDL_Surface
*newsurface
= NULL
;
618 int haspect
, waspect
= 0;
620 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
622 mode
= priv
->fullmode
= findArrayEnd(priv
->fullmodes
) - 1;
624 /* Calculate proper aspect ratio for fullscreen
625 * Height smaller than expected: add horizontal black bars (haspect)*/
626 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
);
627 /* Height bigger than expected: add vertical black bars (waspect)*/
629 haspect
= 0; /* set haspect to zero because image will be scaled horizontal instead of vertical */
630 waspect
= priv
->fullmodes
[mode
]->w
- ((float) ((float) priv
->fullmodes
[mode
]->h
/ (float) priv
->height
) * (float) priv
->width
);
632 // printf ("W-Aspect: %i H-Aspect: %i\n", waspect, haspect);
634 /* change to given fullscreen mode and hide the mouse cursor */
635 newsurface
= SDL_SetVideoMode(priv
->fullmodes
[mode
]->w
- waspect
, priv
->fullmodes
[mode
]->h
- haspect
, priv
->bpp
, priv
->sdlfullflags
);
637 /* if we were successfull hide the mouse cursor and save the mode */
640 SDL_FreeSurface(priv
->surface
);
641 priv
->surface
= newsurface
;
647 /* Set video mode. Not fullscreen */
648 static void set_video_mode(int width
, int height
, int bpp
, uint32_t sdlflags
)
650 struct sdl_priv_s
*priv
= &sdl_priv
;
651 SDL_Surface
* newsurface
;
654 SDL_FreeSurface(priv
->rgbsurface
);
655 else if(priv
->overlay
)
656 SDL_FreeYUVOverlay(priv
->overlay
);
658 priv
->rgbsurface
= NULL
;
659 priv
->overlay
= NULL
;
661 newsurface
= SDL_SetVideoMode(width
, height
, bpp
, sdlflags
);
665 /* priv->surface will be NULL the first time this function is called. */
667 SDL_FreeSurface(priv
->surface
);
669 priv
->surface
= newsurface
;
670 priv
->dstwidth
= width
;
671 priv
->dstheight
= height
;
676 printf("set_video_mode: SDL_SetVideoMode failed: %s\n", SDL_GetError());
679 static void set_fullmode (int mode
) {
680 struct sdl_priv_s
*priv
= &sdl_priv
;
681 SDL_Surface
*newsurface
= NULL
;
682 int screen_surface_w
, screen_surface_h
;
685 SDL_FreeSurface(priv
->rgbsurface
);
686 else if(priv
->overlay
)
687 SDL_FreeYUVOverlay(priv
->overlay
);
689 priv
->rgbsurface
= NULL
;
690 priv
->overlay
= NULL
;
692 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
693 /* But select a mode where the full video enter */
694 if(priv
->X
&& priv
->fulltype
& FS
) {
695 screen_surface_w
= priv
->XWidth
;
696 screen_surface_h
= priv
->XHeight
;
700 mode
= 0; // Default to the biggest mode avaible
701 if (verbose
) for(i
=0;priv
->fullmodes
[i
];++i
)
702 printf("SDL Mode: %d: %d x %d\n", i
, priv
->fullmodes
[i
]->w
, priv
->fullmodes
[i
]->h
);
703 for(i
= findArrayEnd(priv
->fullmodes
) - 1; i
>=0; i
--) {
704 if( (priv
->fullmodes
[i
]->w
>= priv
->dstwidth
) &&
705 (priv
->fullmodes
[i
]->h
>= priv
->dstheight
) ) {
707 for (j
= findArrayEnd(priv
->fullmodes
) - 1; j
>=0; j
--) {
708 if (priv
->fullmodes
[j
]->w
> priv
->fullmodes
[imax
]->w
709 && priv
->fullmodes
[j
]->h
== priv
->fullmodes
[imax
]->h
)
716 if (verbose
) printf("SET SDL Mode: %d: %d x %d\n", mode
, priv
->fullmodes
[mode
]->w
, priv
->fullmodes
[mode
]->h
);
717 priv
->fullmode
= mode
;
718 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
719 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
722 screen_surface_h
= priv
->fullmodes
[mode
]->h
;
723 screen_surface_w
= priv
->fullmodes
[mode
]->w
;
726 aspect_save_screenres(screen_surface_w
, screen_surface_h
);
728 /* calculate new video size/aspect */
729 if(priv
->mode
== YUV
) {
730 if(priv
->fulltype
&FS
)
731 aspect_save_screenres(priv
->XWidth
, priv
->XHeight
);
733 aspect(&priv
->dstwidth
, &priv
->dstheight
, A_ZOOM
);
736 /* try to change to given fullscreenmode */
737 newsurface
= SDL_SetVideoMode(priv
->dstwidth
, screen_surface_h
, priv
->bpp
,
741 * In Mac OS X (and possibly others?) SDL_SetVideoMode() appears to
742 * destroy the datastructure previously retrived, so we need to
743 * re-assign it. The comment in sdl_close() seems to imply that we
744 * should not free() anything.
748 const SDL_VideoInfo
*vidInfo
= NULL
;
749 vidInfo
= SDL_GetVideoInfo ();
751 /* collect all fullscreen & hardware modes available */
752 if (!(priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
))) {
754 /* non hardware accelerated fullscreen modes */
755 priv
->sdlfullflags
&= ~SDL_HWSURFACE
;
756 priv
->fullmodes
= SDL_ListModes (vidInfo
->vfmt
, priv
->sdlfullflags
);
763 /* if creation of new surface was successfull, save it and hide mouse cursor */
766 SDL_FreeSurface(priv
->surface
);
767 priv
->surface
= newsurface
;
769 SDL_SRF_LOCK(priv
->surface
, -1)
770 SDL_FillRect(priv
->surface
, NULL
, 0);
771 SDL_SRF_UNLOCK(priv
->surface
)
775 printf("set_fullmode: SDL_SetVideoMode failed: %s\n", SDL_GetError());
780 * Initialize an SDL surface and an SDL YUV overlay.
782 * params : width == width of video we'll be displaying.
783 * height == height of video we'll be displaying.
784 * fullscreen == want to be fullscreen?
785 * title == Title for window titlebar.
786 * returns : non-zero on success, zero on error.
790 config(uint32_t width
, uint32_t height
, uint32_t d_width
, uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
)
791 //static int sdl_setup (int width, int height)
793 struct sdl_priv_s
*priv
= &sdl_priv
;
797 printf("SDL: Mapping I420 to IYUV\n");
798 format
= SDL_IYUV_OVERLAY
;
819 printf("SDL: Unsupported image format (0x%X)\n",format
);
823 if ( vo_config_count
) sdl_close();
825 if(verbose
) printf("SDL: Using 0x%X (%s) image format\n", format
,
826 vo_format_name(format
));
828 if(priv
->mode
!= YUV
) {
829 priv
->sdlflags
|= SDL_ANYFORMAT
;
830 priv
->sdlfullflags
|= SDL_ANYFORMAT
;
833 /* SDL can only scale YUV data */
834 if(priv
->mode
== RGB
|| priv
->mode
== BGR
) {
839 aspect_save_orig(width
,height
);
840 aspect_save_prescale(d_width
? d_width
: width
, d_height
? d_height
: height
);
842 /* Save the original Image size */
844 priv
->height
= height
;
845 priv
->dstwidth
= d_width
? d_width
: width
;
846 priv
->dstheight
= d_height
? d_height
: height
;
848 priv
->format
= format
;
850 if (sdl_open(NULL
, NULL
) != 0)
853 /* Set output window title */
854 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", title
);
855 //SDL_WM_SetCaption (title, title);
858 aspect_save_screenres(priv
->XWidth
,priv
->XHeight
);
859 aspect(&priv
->dstwidth
,&priv
->dstheight
,A_NOZOOM
);
862 priv
->windowsize
.w
= priv
->dstwidth
;
863 priv
->windowsize
.h
= priv
->dstheight
;
865 /* bit 0 (0x01) means fullscreen (-fs)
866 * bit 1 (0x02) means mode switching (-vm)
867 * bit 2 (0x04) enables software scaling (-zoom)
868 * bit 3 (0x08) enables flipping (-flip)
870 // printf("SDL: flags are set to: %i\n", flags);
871 // printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height);
873 if(verbose
) printf("SDL: using flipped video (only with RGB/BGR/packed YUV)\n");
877 if(verbose
) printf("SDL: setting zoomed fullscreen without modeswitching\n");
878 printf("SDL: Info - please use -vm or -zoom to switch to best resolution.\n");
880 set_fullmode(priv
->fullmode
);
881 /*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)))
885 if(verbose
) printf("SDL: setting zoomed fullscreen with modeswitching\n");
887 set_fullmode(priv
->fullmode
);
888 /*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags)))
892 if(verbose
) printf("SDL: setting zoomed fullscreen with modeswitching\n");
893 priv
->fulltype
= ZOOM
;
894 set_fullmode(priv
->fullmode
);
897 if((strcmp(priv
->driver
, "x11") == 0)
898 ||(strcmp(priv
->driver
, "windib") == 0)
899 ||(strcmp(priv
->driver
, "directx") == 0)
900 ||(strcmp(priv
->driver
, "Quartz") == 0)
901 ||(strcmp(priv
->driver
, "cgx") == 0)
902 ||((strcmp(priv
->driver
, "aalib") == 0) && priv
->X
)){
903 if(verbose
) printf("SDL: setting windowed mode\n");
904 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
907 if(verbose
) printf("SDL: setting zoomed fullscreen with modeswitching\n");
908 priv
->fulltype
= ZOOM
;
909 set_fullmode(priv
->fullmode
);
913 if(!priv
->surface
) { // cannot SetVideoMode
914 printf("SDL: failed to set video mode: %s\n", SDL_GetError());
921 /* Free priv->rgbsurface or priv->overlay if they are != NULL.
922 * Setup priv->rgbsurface or priv->overlay depending on source format.
923 * The size of the created surface or overlay depends on the size of
924 * priv->surface, priv->width, priv->height, priv->dstwidth and priv->dstheight.
926 static int setup_surfaces(void)
928 struct sdl_priv_s
*priv
= &sdl_priv
;
929 float v_scale
= ((float) priv
->dstheight
) / priv
->height
;
930 int surfwidth
, surfheight
;
932 surfwidth
= priv
->width
;
933 surfheight
= priv
->height
+ (priv
->surface
->h
- priv
->dstheight
) / v_scale
;
935 /* Place the image in the middle of the screen */
936 priv
->y
= (surfheight
- priv
->height
) / 2;
937 priv
->y_screen_top
= priv
->y
* v_scale
;
938 priv
->y_screen_bottom
= priv
->y_screen_top
+ priv
->dstheight
;
940 priv
->dirty_off_frame
[0].x
= -1;
941 priv
->dirty_off_frame
[0].y
= -1;
942 priv
->dirty_off_frame
[1].x
= -1;
943 priv
->dirty_off_frame
[1].y
= -1;
945 /* Make sure the entire screen is updated */
949 SDL_FreeSurface(priv
->rgbsurface
);
950 else if(priv
->overlay
)
951 SDL_FreeYUVOverlay(priv
->overlay
);
953 priv
->rgbsurface
= NULL
;
954 priv
->overlay
= NULL
;
956 if(priv
->mode
!= YUV
&& (priv
->format
&0xFF) == priv
->bpp
) {
957 if(strcmp(priv
->driver
, "x11") == 0) {
959 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->surface
->format
->BytesPerPixel
;
960 priv
->stridePlaneRGB
= priv
->width
* priv
->surface
->format
->BytesPerPixel
;
961 erase_rectangle(0, 0, priv
->surface
->w
, priv
->surface
->h
);
966 switch(priv
->format
) {
967 /* Initialize and create the RGB Surface used for video out in BGR/RGB mode */
968 //SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
969 // SDL_SWSURFACE,SDL_HWSURFACE,SDL_SRCCOLORKEY, priv->flags? guess: exchange Rmask and Bmask for BGR<->RGB
970 // 32 bit: a:ff000000 r:ff000 g:ff00 b:ff
971 // 24 bit: r:ff0000 g:ff00 b:ff
972 // 16 bit: r:1111100000000000b g:0000011111100000b b:0000000000011111b
973 // 15 bit: r:111110000000000b g:000001111100000b b:000000000011111b
974 // FIXME: colorkey detect based on bpp, FIXME static bpp value, FIXME alpha value correct?
976 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31, 992, 31744, 0);
979 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 15, 31744, 992, 31, 0);
982 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 31, 2016, 63488, 0);
985 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 16, 63488, 2016, 31, 0);
988 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0);
991 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 24, 0xFF0000, 0x00FF00, 0x0000FF, 0);
994 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0/*0xFF000000*/);
997 priv
->rgbsurface
= SDL_CreateRGBSurface (SDL_SRCCOLORKEY
, surfwidth
, surfheight
, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0/*0xFF000000*/);
1000 /* Initialize and create the YUV Overlay used for video out */
1001 if (!(priv
->overlay
= SDL_CreateYUVOverlay (surfwidth
, surfheight
, priv
->format
, priv
->surface
))) {
1002 printf ("SDL: Couldn't create a YUV overlay: %s\n", SDL_GetError());
1005 priv
->framePlaneY
= priv
->width
* priv
->height
;
1006 priv
->framePlaneUV
= (priv
->width
* priv
->height
) >> 2;
1007 priv
->framePlaneYUY
= priv
->width
* priv
->height
* 2;
1008 priv
->stridePlaneY
= priv
->width
;
1009 priv
->stridePlaneUV
= priv
->width
/2;
1010 priv
->stridePlaneYUY
= priv
->width
* 2;
1013 if(priv
->mode
!= YUV
) {
1014 if(!priv
->rgbsurface
) {
1015 printf ("SDL: Couldn't create a RGB surface: %s\n", SDL_GetError());
1021 if((priv
->format
&0xFF) != priv
->bpp
)
1022 printf("SDL: using depth/colorspace conversion, this will slow things"
1023 "down (%ibpp -> %ibpp).\n", priv
->format
&0xFF, priv
->bpp
);
1025 priv
->framePlaneRGB
= priv
->width
* priv
->height
* priv
->rgbsurface
->format
->BytesPerPixel
;
1026 priv
->stridePlaneRGB
= priv
->width
* priv
->rgbsurface
->format
->BytesPerPixel
;
1029 erase_rectangle(0, 0, surfwidth
, surfheight
);
1036 * Draw a frame to the SDL YUV overlay.
1038 * params : *src[] == the Y, U, and V planes that make up the frame.
1039 * returns : non-zero on success, zero on error.
1042 //static int sdl_draw_frame (frame_t *frame)
1043 static uint32_t draw_frame(uint8_t *src
[])
1045 struct sdl_priv_s
*priv
= &sdl_priv
;
1048 uint8_t *mysrc
= src
[0];
1050 switch(priv
->format
){
1055 dst
= (uint8_t *) *(priv
->overlay
->pixels
) + priv
->overlay
->pitches
[0]*priv
->y
;
1057 mysrc
+=priv
->framePlaneYUY
;
1058 for(i
= 0; i
< priv
->height
; i
++) {
1059 mysrc
-=priv
->stridePlaneYUY
;
1060 memcpy (dst
, mysrc
, priv
->stridePlaneYUY
);
1061 dst
+=priv
->overlay
->pitches
[0];
1064 else memcpy (dst
, src
[0], priv
->framePlaneYUY
);
1077 SDL_SRF_LOCK(priv
->surface
, -1)
1078 dst
= (uint8_t *) priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
1080 mysrc
+=priv
->framePlaneRGB
;
1081 for(i
= 0; i
< priv
->height
; i
++) {
1082 mysrc
-=priv
->stridePlaneRGB
;
1083 memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
1084 dst
+= priv
->surface
->pitch
;
1087 else memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1088 SDL_SRF_UNLOCK(priv
->surface
)
1090 SDL_SRF_LOCK(priv
->rgbsurface
, -1)
1091 dst
= (uint8_t *) priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1093 mysrc
+=priv
->framePlaneRGB
;
1094 for(i
= 0; i
< priv
->height
; i
++) {
1095 mysrc
-=priv
->stridePlaneRGB
;
1096 memcpy (dst
, mysrc
, priv
->stridePlaneRGB
);
1097 dst
+= priv
->rgbsurface
->pitch
;
1100 else memcpy (dst
, src
[0], priv
->framePlaneRGB
);
1101 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1112 * Draw a slice (16 rows of image) to the SDL YUV overlay.
1114 * params : *src[] == the Y, U, and V planes that make up the slice.
1115 * returns : non-zero on error, zero on success.
1118 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
1119 static uint32_t draw_slice(uint8_t *image
[], int stride
[], int w
,int h
,int x
,int y
)
1121 struct sdl_priv_s
*priv
= &sdl_priv
;
1128 dst
= priv
->overlay
->pixels
[0] + priv
->overlay
->pitches
[0]*y
+ x
;
1129 memcpy_pic(dst
, image
[0], w
, h
, priv
->overlay
->pitches
[0], stride
[0]);
1130 x
/=2;y
/=2;w
/=2;h
/=2;
1132 switch(priv
->format
) {
1134 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1135 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[2], stride
[1]);
1137 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1138 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[1], stride
[2]);
1143 dst
= priv
->overlay
->pixels
[1] + priv
->overlay
->pitches
[1]*y
+ x
;
1144 memcpy_pic(dst
, image
[1], w
, h
, priv
->overlay
->pitches
[1], stride
[1]);
1146 dst
= priv
->overlay
->pixels
[2] + priv
->overlay
->pitches
[2]*y
+ x
;
1147 memcpy_pic(dst
, image
[2], w
, h
, priv
->overlay
->pitches
[2], stride
[2]);
1151 printf("SDL: unsupported image format in draw_slice, contact MPlayer developers!\n");
1162 * Checks for SDL keypress and window resize events
1165 * returns : doesn't return
1168 #include "osdep/keycodes.h"
1169 extern void mplayer_put_key(int code
);
1171 #define shift_key (event.key.keysym.mod==(KMOD_LSHIFT||KMOD_RSHIFT))
1172 static void check_events (void)
1174 struct sdl_priv_s
*priv
= &sdl_priv
;
1176 SDLKey keypressed
= 0;
1178 /* Poll the waiting SDL Events */
1179 while ( SDL_PollEvent(&event
) ) {
1180 switch (event
.type
) {
1182 /* capture window resize events */
1183 case SDL_VIDEORESIZE
:
1185 set_video_mode(event
.resize
.w
, event
.resize
.h
, priv
->bpp
, priv
->sdlflags
);
1187 /* save video extents, to restore them after going fullscreen */
1188 //if(!(priv->surface->flags & SDL_FULLSCREEN)) {
1189 priv
->windowsize
.w
= priv
->surface
->w
;
1190 priv
->windowsize
.h
= priv
->surface
->h
;
1192 if(verbose
> 2) printf("SDL: Window resize\n");
1195 case SDL_MOUSEBUTTONDOWN
:
1196 if(vo_nomouse_input
)
1198 if(event
.button
.button
== 4 || event
.button
.button
== 5)
1199 mplayer_put_key(MOUSE_BASE
+event
.button
.button
-1);
1201 mplayer_put_key((MOUSE_BASE
+event
.button
.button
-1) | MP_KEY_DOWN
);
1204 case SDL_MOUSEBUTTONUP
:
1205 if(vo_nomouse_input
)
1207 mplayer_put_key(MOUSE_BASE
+event
.button
.button
-1);
1210 /* graphics mode selection shortcuts */
1213 switch(event
.key
.keysym
.sym
) {
1214 case SDLK_UP
: mplayer_put_key(KEY_UP
); break;
1215 case SDLK_DOWN
: mplayer_put_key(KEY_DOWN
); break;
1216 case SDLK_LEFT
: mplayer_put_key(KEY_LEFT
); break;
1217 case SDLK_RIGHT
: mplayer_put_key(KEY_RIGHT
); break;
1218 case SDLK_LESS
: mplayer_put_key(shift_key
?'>':'<'); break;
1219 case SDLK_GREATER
: mplayer_put_key('>'); break;
1221 case SDLK_KP_MULTIPLY
:
1223 case SDLK_KP_DIVIDE
:
1231 keypressed
= event
.key
.keysym
.sym
;
1232 if(verbose
> 1) printf("SDL: Key pressed: '%i'\n", keypressed
);
1234 /* c key pressed. c cycles through available fullscreenmodes, if we have some */
1235 if ( ((keypressed
== SDLK_c
)) && (priv
->fullmodes
) ) {
1236 /* select next fullscreen mode */
1238 if (priv
->fullmode
> (findArrayEnd(priv
->fullmodes
) - 1)) priv
->fullmode
= 0;
1239 set_fullmode(priv
->fullmode
);
1241 if(verbose
> 1) printf("SDL: Set next available fullscreen mode.\n");
1244 else if ( keypressed
== SDLK_n
) {
1246 aspect(&priv
->dstwidth
, &priv
->dstheight
,A_NOZOOM
);
1248 if (priv
->surface
->w
!= priv
->dstwidth
|| priv
->surface
->h
!= priv
->dstheight
) {
1249 set_video_mode(priv
->dstwidth
, priv
->dstheight
, priv
->bpp
, priv
->sdlflags
);
1250 priv
->windowsize
.w
= priv
->surface
->w
;
1251 priv
->windowsize
.h
= priv
->surface
->h
;
1252 if(verbose
> 1) printf("SDL: Normal size\n");
1254 if (priv
->surface
->w
!= priv
->dstwidth
* 2 || priv
->surface
->h
!= priv
->dstheight
* 2) {
1255 set_video_mode(priv
->dstwidth
* 2, priv
->dstheight
* 2, priv
->bpp
, priv
->sdlflags
);
1256 priv
->windowsize
.w
= priv
->surface
->w
;
1257 priv
->windowsize
.h
= priv
->surface
->h
;
1258 if(verbose
> 1) printf("SDL: Double size\n");
1262 else switch(keypressed
){
1263 case SDLK_RETURN
: mplayer_put_key(KEY_ENTER
);break;
1264 case SDLK_ESCAPE
: mplayer_put_key(KEY_ESC
);break;
1265 case SDLK_q
: mplayer_put_key('q');break;
1266 case SDLK_F1
: mplayer_put_key(KEY_F
+1);break;
1267 case SDLK_F2
: mplayer_put_key(KEY_F
+2);break;
1268 case SDLK_F3
: mplayer_put_key(KEY_F
+3);break;
1269 case SDLK_F4
: mplayer_put_key(KEY_F
+4);break;
1270 case SDLK_F5
: mplayer_put_key(KEY_F
+5);break;
1271 case SDLK_F6
: mplayer_put_key(KEY_F
+6);break;
1272 case SDLK_F7
: mplayer_put_key(KEY_F
+7);break;
1273 case SDLK_F8
: mplayer_put_key(KEY_F
+8);break;
1274 case SDLK_F9
: mplayer_put_key(KEY_F
+9);break;
1275 case SDLK_F10
: mplayer_put_key(KEY_F
+10);break;
1276 case SDLK_F11
: mplayer_put_key(KEY_F
+11);break;
1277 case SDLK_F12
: mplayer_put_key(KEY_F
+12);break;
1278 /*case SDLK_o: mplayer_put_key('o');break;
1279 case SDLK_SPACE: mplayer_put_key(' ');break;
1280 case SDLK_p: mplayer_put_key('p');break;*/
1281 case SDLK_7
: mplayer_put_key(shift_key
?'/':'7');
1282 case SDLK_PLUS
: mplayer_put_key(shift_key
?'*':'+');
1283 case SDLK_KP_PLUS
: mplayer_put_key('+');break;
1285 case SDLK_KP_MINUS
: mplayer_put_key('-');break;
1286 case SDLK_TAB
: mplayer_put_key('\t');break;
1287 case SDLK_PAGEUP
: mplayer_put_key(KEY_PAGE_UP
);break;
1288 case SDLK_PAGEDOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
1295 case SDLK_KP_MULTIPLY
:
1297 case SDLK_KP_DIVIDE
:
1300 case SDLK_UP
: mplayer_put_key(KEY_UP
);break;
1301 case SDLK_DOWN
: mplayer_put_key(KEY_DOWN
);break;
1302 case SDLK_LEFT
: mplayer_put_key(KEY_LEFT
);break;
1303 case SDLK_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
1304 case SDLK_LESS
: mplayer_put_key(shift_key
?'>':'<'); break;
1305 case SDLK_GREATER
: mplayer_put_key('>'); break;
1307 case SDLK_KP_MULTIPLY
: mplayer_put_key('*'); break;
1309 case SDLK_KP_DIVIDE
: mplayer_put_key('/'); break;
1311 case SDLK_KP0
: mplayer_put_key(KEY_KP0
); break;
1312 case SDLK_KP1
: mplayer_put_key(KEY_KP1
); break;
1313 case SDLK_KP2
: mplayer_put_key(KEY_KP2
); break;
1314 case SDLK_KP3
: mplayer_put_key(KEY_KP3
); break;
1315 case SDLK_KP4
: mplayer_put_key(KEY_KP4
); break;
1316 case SDLK_KP5
: mplayer_put_key(KEY_KP5
); break;
1317 case SDLK_KP6
: mplayer_put_key(KEY_KP6
); break;
1318 case SDLK_KP7
: mplayer_put_key(KEY_KP7
); break;
1319 case SDLK_KP8
: mplayer_put_key(KEY_KP8
); break;
1320 case SDLK_KP9
: mplayer_put_key(KEY_KP9
); break;
1321 case SDLK_KP_PERIOD
: mplayer_put_key(KEY_KPDEC
); break;
1322 case SDLK_KP_ENTER
: mplayer_put_key(KEY_KPENTER
); break;
1324 //printf("got scancode: %d keysym: %d mod: %d %d\n", event.key.keysym.scancode, keypressed, event.key.keysym.mod);
1325 mplayer_put_key(keypressed
);
1329 case SDL_QUIT
: mplayer_put_key('q');break;
1335 /* Erase (paint it black) the rectangle specified by x, y, w and h in the surface
1336 or overlay which is used for OSD
1338 static void erase_rectangle(int x
, int y
, int w
, int h
)
1340 struct sdl_priv_s
*priv
= &sdl_priv
;
1342 switch(priv
->format
) {
1347 SDL_OVR_LOCK((void) 0)
1350 erase_area_1(x
, w
, h
,
1351 priv
->overlay
->pitches
[0], 0,
1352 priv
->overlay
->pixels
[0] +
1353 priv
->overlay
->pitches
[0]*y
);
1355 /* Erase U and V planes */
1361 erase_area_1(x
, w
, h
,
1362 priv
->overlay
->pitches
[1], 128,
1363 priv
->overlay
->pixels
[1] +
1364 priv
->overlay
->pitches
[1]*y
);
1366 erase_area_1(x
, w
, h
,
1367 priv
->overlay
->pitches
[2], 128,
1368 priv
->overlay
->pixels
[2] +
1369 priv
->overlay
->pitches
[2]*y
);
1377 /* yuy2 and yvyu represent black the same way */
1378 uint8_t yuy2_black
[] = {0, 128, 0, 128};
1380 SDL_OVR_LOCK((void) 0)
1381 erase_area_4(x
*2, w
*2, h
,
1382 priv
->overlay
->pitches
[0],
1383 *((uint32_t*) yuy2_black
),
1384 priv
->overlay
->pixels
[0] +
1385 priv
->overlay
->pitches
[0]*y
);
1392 uint8_t uyvy_black
[] = {128, 0, 128, 0};
1394 SDL_OVR_LOCK((void) 0)
1395 erase_area_4(x
*2, w
*2, h
,
1396 priv
->overlay
->pitches
[0],
1397 *((uint32_t*) uyvy_black
),
1398 priv
->overlay
->pixels
[0] +
1399 priv
->overlay
->pitches
[0]*y
);
1414 rect
.w
= w
; rect
.h
= h
;
1415 rect
.x
= x
; rect
.y
= y
;
1418 SDL_SRF_LOCK(priv
->surface
, (void) 0)
1419 SDL_FillRect(priv
->surface
, &rect
, 0);
1420 SDL_SRF_UNLOCK(priv
->surface
)
1423 SDL_SRF_LOCK(priv
->rgbsurface
, (void) 0)
1424 SDL_FillRect(priv
->rgbsurface
, &rect
, 0);
1425 SDL_SRF_UNLOCK(priv
->rgbsurface
)
1432 static void draw_osd(void)
1433 { struct sdl_priv_s
*priv
= &sdl_priv
;
1435 priv
->osd_has_changed
= vo_osd_changed(0);
1437 if(priv
->osd_has_changed
)
1441 for(i
= 0; i
< 2; i
++) {
1442 if(priv
->dirty_off_frame
[i
].x
< 0 || priv
->dirty_off_frame
[i
].y
< 0)
1445 erase_rectangle(priv
->dirty_off_frame
[i
].x
, priv
->dirty_off_frame
[i
].y
,
1446 priv
->dirty_off_frame
[i
].w
, priv
->dirty_off_frame
[i
].h
);
1448 priv
->dirty_off_frame
[i
].x
= -1;
1449 priv
->dirty_off_frame
[i
].y
= -1;
1453 /* update osd/subtitles */
1454 if(priv
->mode
== YUV
)
1455 vo_draw_text(priv
->overlay
->w
, priv
->overlay
->h
, draw_alpha
);
1458 vo_draw_text(priv
->surface
->w
, priv
->surface
->h
, draw_alpha
);
1460 vo_draw_text(priv
->rgbsurface
->w
, priv
->rgbsurface
->h
, draw_alpha
);
1464 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1465 * are given in bytes. 4 bytes at a time.
1467 static void erase_area_4(int x_start
, int width
, int height
, int pitch
, uint32_t color
, uint8_t* pixels
)
1469 int x_end
= x_start
/4 + width
/4;
1471 uint32_t* data
= (uint32_t*) pixels
;
1476 for(y
= 0; y
< height
; y
++) {
1477 for(x
= x_start
; x
< x_end
; x
++)
1478 data
[y
*pitch
+ x
] = color
;
1482 /* Fill area beginning at 'pixels' with 'color'. 'x_start', 'width' and 'pitch'
1483 * are given in bytes. 1 byte at a time.
1485 static void erase_area_1(int x_start
, int width
, int height
, int pitch
, uint8_t color
, uint8_t* pixels
)
1489 for(y
= 0; y
< height
; y
++) {
1490 memset(&pixels
[y
*pitch
+ x_start
], color
, width
);
1495 * Display the surface we have written our data to
1497 * params : mode == index of the desired fullscreen mode
1498 * returns : doesn't return
1501 static void flip_page (void)
1503 struct sdl_priv_s
*priv
= &sdl_priv
;
1505 switch(priv
->format
) {
1515 /* blit to the RGB surface */
1516 if(SDL_BlitSurface (priv
->rgbsurface
, NULL
, priv
->surface
, NULL
))
1517 printf("SDL: Blit failed: %s\n", SDL_GetError());
1521 //SDL_UpdateRect(priv->surface, 0, 0, priv->surface->clip_rect.w, priv->surface->clip_rect.h);
1522 if(priv
->osd_has_changed
) {
1523 priv
->osd_has_changed
= 0;
1524 SDL_UpdateRects(priv
->surface
, 1, &priv
->surface
->clip_rect
);
1527 SDL_UpdateRect(priv
->surface
, 0, priv
->y_screen_top
,
1528 priv
->surface
->clip_rect
.w
, priv
->y_screen_bottom
);
1530 /* check if we have a double buffered surface and flip() if we do. */
1531 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1532 SDL_Flip(priv
->surface
);
1536 /* blit to the YUV overlay */
1537 SDL_DisplayYUVOverlay (priv
->overlay
, &priv
->surface
->clip_rect
);
1539 /* check if we have a double buffered surface and flip() if we do. */
1540 if ( priv
->surface
->flags
& SDL_DOUBLEBUF
)
1541 SDL_Flip(priv
->surface
);
1543 //SDL_LockYUVOverlay (priv->overlay); // removed because unused!?
1548 query_format(uint32_t format
)
1552 // it seems buggy (not hw accelerated), so just use YV12 instead!
1553 // case IMGFMT_I420:
1554 // case IMGFMT_IYUV:
1558 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_OSD
|
1559 VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1568 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_FLIP
;
1578 struct sdl_priv_s
*priv
= &sdl_priv
;
1580 if(verbose
) printf("SDL: activating XScreensaver/DPMS\n");
1587 if(SDL_WasInit(SDL_INIT_VIDEO
))
1588 SDL_QuitSubSystem(SDL_INIT_VIDEO
);
1590 if(verbose
> 2) printf("SDL: Closed Plugin\n");
1594 static uint32_t preinit(const char *arg
)
1596 struct sdl_priv_s
*priv
= &sdl_priv
;
1598 priv
->rgbsurface
= NULL
;
1599 priv
->overlay
= NULL
;
1600 priv
->surface
= NULL
;
1602 if(verbose
> 2) printf("SDL: Opening Plugin\n");
1604 if(vo_subdevice
) setenv("SDL_VIDEODRIVER", vo_subdevice
, 1);
1606 /* does the user want SDL to try and force Xv */
1607 if(sdl_forcexv
) setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1);
1609 /* does the user want to disable Xv and use software scaling instead */
1610 if(sdl_noxv
) setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
1612 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */
1613 priv
->fullmode
= -2;
1615 priv
->fullmodes
= NULL
;
1618 /* initialize the SDL Video system */
1619 if (!SDL_WasInit(SDL_INIT_VIDEO
)) {
1620 if (SDL_Init (SDL_INIT_VIDEO
|SDL_INIT_NOPARACHUTE
)) {
1621 printf("SDL: Initializing of SDL failed: %s.\n", SDL_GetError());
1626 SDL_VideoDriverName(priv
->driver
, 8);
1627 printf("SDL: Using driver: %s\n", priv
->driver
);
1632 if(verbose
) printf("SDL: deactivating XScreensaver/DPMS\n");
1633 priv
->XWidth
= vo_screenwidth
;
1634 priv
->XHeight
= vo_screenheight
;
1636 if(verbose
) printf("SDL: X11 Resolution %ix%i\n", priv
->XWidth
, priv
->XHeight
);
1643 static uint32_t get_image(mp_image_t
*mpi
)
1645 struct sdl_priv_s
*priv
= &sdl_priv
;
1647 if(priv
->format
!= mpi
->imgfmt
) return VO_FALSE
;
1648 if(mpi
->type
== MP_IMGTYPE_STATIC
|| mpi
->type
== MP_IMGTYPE_TEMP
) {
1649 if(mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1650 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1651 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1652 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
) {
1653 mpi
->planes
[1] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1654 mpi
->stride
[1] = priv
->overlay
->pitches
[1];
1655 mpi
->planes
[2] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1656 mpi
->stride
[2] = priv
->overlay
->pitches
[2];
1658 mpi
->planes
[2] = priv
->overlay
->pixels
[1] + priv
->y
*priv
->overlay
->pitches
[1]/2;
1659 mpi
->stride
[2] = priv
->overlay
->pitches
[1];
1660 mpi
->planes
[1] = priv
->overlay
->pixels
[2] + priv
->y
*priv
->overlay
->pitches
[2]/2;
1661 mpi
->stride
[1] = priv
->overlay
->pitches
[2];
1664 else if(IMGFMT_IS_RGB(priv
->format
) || IMGFMT_IS_BGR(priv
->format
)) {
1666 if(mpi
->type
== MP_IMGTYPE_STATIC
&& (priv
->surface
->flags
& SDL_DOUBLEBUF
))
1669 mpi
->planes
[0] = priv
->surface
->pixels
+ priv
->y
*priv
->surface
->pitch
;
1670 mpi
->stride
[0] = priv
->surface
->pitch
;
1673 mpi
->planes
[0] = priv
->rgbsurface
->pixels
+ priv
->y
*priv
->rgbsurface
->pitch
;
1674 mpi
->stride
[0] = priv
->rgbsurface
->pitch
;
1678 mpi
->planes
[0] = priv
->overlay
->pixels
[0] + priv
->y
*priv
->overlay
->pitches
[0];
1679 mpi
->stride
[0] = priv
->overlay
->pitches
[0];
1682 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1689 static uint32_t control(uint32_t request
, void *data
, ...)
1691 struct sdl_priv_s
*priv
= &sdl_priv
;
1693 case VOCTRL_GET_IMAGE
:
1694 return get_image(data
);
1695 case VOCTRL_QUERY_FORMAT
:
1696 return query_format(*((uint32_t*)data
));
1697 case VOCTRL_FULLSCREEN
:
1698 if (priv
->surface
->flags
& SDL_FULLSCREEN
) {
1699 set_video_mode(priv
->windowsize
.w
, priv
->windowsize
.h
, priv
->bpp
, priv
->sdlflags
);
1701 if(verbose
> 1) printf("SDL: Windowed mode\n");
1702 } else if (priv
->fullmodes
) {
1703 set_fullmode(priv
->fullmode
);
1704 if(verbose
> 1) printf("SDL: Set fullscreen mode\n");