Mercurial > mplayer.hg
annotate libvo/vo_sdl.c @ 414:a8b17d1f2551
using shmem_alloc instead of malloc
author | arpi_esp |
---|---|
date | Sat, 14 Apr 2001 19:30:52 +0000 |
parents | b61c5c4484f8 |
children | 6937ae376998 |
rev | line source |
---|---|
1 | 1 /* |
351 | 2 * vo_sdl.c |
3 * | |
4 * (was video_out_sdl.c from OMS project) | |
1 | 5 * |
6 * Copyright (C) Ryan C. Gordon <icculus@lokigames.com> - April 22, 2000. | |
7 * | |
8 * A mpeg2dec display driver that does output through the | |
9 * Simple DirectMedia Layer (SDL) library. This effectively gives us all | |
10 * sorts of output options: X11, SVGAlib, fbcon, AAlib, GGI. Win32, MacOS | |
11 * and BeOS support, too. Yay. SDL info, source, and binaries can be found | |
12 * at http://slouken.devolution.com/SDL/ | |
13 * | |
14 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | |
15 * | |
16 * mpeg2dec is free software; you can redistribute it and/or modify | |
17 * it under the terms of the GNU General Public License as published by | |
18 * the Free Software Foundation; either version 2, or (at your option) | |
19 * any later version. | |
20 * | |
21 * mpeg2dec is distributed in the hope that it will be useful, | |
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 * GNU General Public License for more details. | |
25 * | |
26 * You should have received a copy of the GNU General Public License | |
27 * along with GNU Make; see the file COPYING. If not, write to | |
28 * the Free Software Foundation, | |
29 * | |
30 * Changes: | |
31 * Dominik Schnitzer <dominik@schnitzer.at> - November 08, 2000. | |
84 | 32 * - Added resizing support, fullscreen: changed the sdlmodes selection |
1 | 33 * routine. |
34 * - SDL bugfixes: removed the atexit(SLD_Quit), SDL_Quit now resides in | |
35 * the plugin_exit routine. | |
36 * - Commented the source :) | |
37 * - Shortcuts: for switching between Fullscreen/Windowed mode and for | |
38 * cycling between the different Fullscreen modes. | |
39 * - Small bugfixes: proper width/height of movie | |
40 * Dominik Schnitzer <dominik@schnitzer.at> - November 11, 2000. | |
41 * - Cleanup code, more comments | |
42 * - Better error handling | |
43 * Bruno Barreyra <barreyra@ufl.edu> - December 10, 2000. | |
44 * - Eliminated memcpy's for entire frames | |
84 | 45 * Felix Buenemann <Felix.Buenemann@ePost.de> - March 11, 2001 |
46 * - Added aspect-ratio awareness for fullscreen | |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
47 * Felix Buenemann <Felix.Buenemann@gmx.de> - March 11, 2001 |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
48 * - Fixed aspect-ratio awareness, did only vertical scaling (black bars above |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
49 * and below), now also does horizontal scaling (black bars left and right), |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
50 * so you get the biggest possible picture with correct aspect-ratio. |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
51 * Felix Buenemann <Atmosfear@users.sourceforge.net> - March 12, 2001 |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
52 * - Minor bugfix to aspect-ratio vor non-4:3-resolutions (like 1280x1024) |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
53 * - Bugfix to check_events() to reveal mouse cursor after 'q'-quit in |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
54 * fullscreen-mode |
351 | 55 * Felix Buenemann <Atmosfear@users.sourceforge.net> - April 10, 2001 |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
56 * - Changed keypress-detection from keydown to keyup, seems to fix keyrepeat |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
57 * bug (key had to be pressed twice to be detected) |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
58 * - Changed key-handling: 'f' cycles fullscreen/windowed, ESC/RETURN/'q' quits |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
59 * - Bugfix which avoids exit, because return is passed to sdl-output on startup, |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
60 * which caused the player to exit (keyboard-buffer problem? better solution |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
61 * recommed) |
351 | 62 * Felix Buenemann <Atmosfear@users.sourceforge.net> - April 11, 2001 |
63 * - OSD and subtitle support added | |
64 * - some minor code-changes | |
355
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
65 * - added code to comply with new fullscreen meaning |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
66 * - changed fullscreen-mode-cycling from '+' to 'c' (interferred with audiosync |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
67 * adjustment) |
386 | 68 * Felix Buenemann <Atmosfear@users.sourceforge.net> - April 13, 2001 |
69 * - added keymapping to toggle OSD ('o' key) | |
394
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
70 * - added some defines to modify some sdl-out internas (see comments) |
1 | 71 */ |
72 | |
73 #include <stdio.h> | |
74 #include <stdlib.h> | |
75 #include <string.h> | |
76 #include <inttypes.h> | |
77 | |
78 #include "config.h" | |
79 #include "video_out.h" | |
80 #include "video_out_internal.h" | |
81 | |
354 | 82 #include "fastmemcpy.h" |
350 | 83 |
1 | 84 LIBVO_EXTERN(sdl) |
85 | |
86 //#include "log.h" | |
87 //#define LOG if(0)printf | |
88 | |
394
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
89 /* define if you want to force Xv SDL output? */ |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
90 #undef SDL_FORCEXV |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
91 /* define to force software-surface (video surface stored in system memory)*/ |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
92 #undef SDL_NOHWSURFACE |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
93 /* define to disable usage of the xvideo extension */ |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
94 #undef SDL_NOXV |
351 | 95 |
1 | 96 static vo_info_t vo_info = |
97 { | |
84 | 98 "SDL YUV overlay (SDL v1.1.7+ only!)", |
1 | 99 "sdl", |
100 "Ryan C. Gordon <icculus@lokigames.com>", | |
101 "" | |
102 }; | |
103 | |
104 #include <SDL/SDL.h> | |
105 | |
106 /** Private SDL Data structure **/ | |
107 | |
108 static struct sdl_priv_s { | |
109 | |
110 /* SDL YUV surface & overlay */ | |
111 SDL_Surface *surface; | |
112 SDL_Overlay *overlay; | |
113 // SDL_Overlay *current_frame; | |
114 | |
115 /* available fullscreen modes */ | |
116 SDL_Rect **fullmodes; | |
117 | |
118 /* surface attributes for fullscreen and windowed mode */ | |
119 Uint32 sdlflags, sdlfullflags; | |
120 | |
121 /* save the windowed output extents */ | |
122 SDL_Rect windowsize; | |
123 | |
124 /* Bits per Pixel */ | |
125 Uint8 bpp; | |
126 | |
127 /* current fullscreen mode, 0 = highest available fullscreen mode */ | |
128 int fullmode; | |
129 | |
130 /* YUV ints */ | |
131 int framePlaneY, framePlaneUV; | |
132 int stridePlaneY, stridePlaneUV; | |
133 int width,height; | |
134 int format; | |
135 } sdl_priv; | |
136 | |
137 | |
351 | 138 /** libvo Plugin functions **/ |
139 | |
140 /** | |
141 * draw_alpha is used for osd and subtitle display. | |
142 * | |
143 **/ | |
144 | |
145 //void vo_draw_alpha_yv12(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); | |
146 //void vo_draw_alpha_yuy2(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride); | |
147 | |
148 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
408 | 149 struct sdl_priv_s *priv = &sdl_priv; |
150 int x,y; | |
351 | 151 |
408 | 152 switch(priv->format) { |
153 case IMGFMT_YV12: | |
154 case IMGFMT_I420: | |
155 case IMGFMT_IYUV: | |
156 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->width*y0+x0,priv->width); | |
157 break; | |
158 case IMGFMT_YUY2: | |
159 case IMGFMT_UYVY: | |
160 case IMGFMT_YVYU: | |
161 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+2*(priv->width*y0+x0),2*priv->width); | |
162 break; | |
163 } | |
351 | 164 } |
1 | 165 |
166 | |
167 /** | |
168 * Take a null-terminated array of pointers, and find the last element. | |
169 * | |
170 * params : array == array of which we want to find the last element. | |
171 * returns : index of last NON-NULL element. | |
172 **/ | |
173 | |
174 static inline int findArrayEnd (SDL_Rect **array) | |
175 { | |
176 int i = 0; | |
177 while ( array[i++] ); /* keep loopin' ... */ | |
178 | |
179 /* return the index of the last array element */ | |
180 return i - 1; | |
181 } | |
182 | |
183 | |
184 /** | |
185 * Open and prepare SDL output. | |
186 * | |
187 * params : *plugin == | |
188 * *name == | |
189 * returns : 0 on success, -1 on failure | |
190 **/ | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
191 |
1 | 192 static int sdl_open (void *plugin, void *name) |
193 { | |
194 struct sdl_priv_s *priv = &sdl_priv; | |
195 const SDL_VideoInfo *vidInfo = NULL; | |
196 static int opened = 0; | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
197 |
1 | 198 if (opened) |
199 return 0; | |
200 opened = 1; | |
201 | |
202 // LOG (LOG_DEBUG, "SDL video out: Opened Plugin"); | |
351 | 203 |
204 /* does the user want SDL to try and force Xv */ | |
205 #ifdef SDL_FORCEXV | |
206 setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1); | |
207 #endif | |
394
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
208 #ifdef SDL_NOXV |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
209 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1); |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
210 #endif |
1 | 211 |
84 | 212 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */ |
1 | 213 priv->fullmode = -2; |
214 /* other default values */ | |
394
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
215 #ifdef SDL_NOHWSURFACE |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
216 printf("SDL: using software-surface\n"); |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
217 priv->sdlflags = SDL_SWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT; |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
218 priv->sdlfullflags = SDL_SWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_ASYNCBLIT; |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
219 #else |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
220 printf("SDL: using hardware-surface\n"); |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
221 priv->sdlflags = SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT; //SDL_HWACCEL |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
222 priv->sdlfullflags = SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_ASYNCBLIT; //SDL_HWACCEL |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
223 #endif |
1 | 224 priv->surface = NULL; |
225 priv->overlay = NULL; | |
226 priv->fullmodes = NULL; | |
351 | 227 priv->bpp = 0; //added atmos |
1 | 228 |
229 /* initialize the SDL Video system */ | |
230 if (SDL_Init (SDL_INIT_VIDEO)) { | |
231 // LOG (LOG_ERROR, "SDL video out: Initializing of SDL failed (SDL_Init). Please use the latest version of SDL."); | |
232 return -1; | |
233 } | |
234 | |
235 /* No Keyrepeats! */ | |
236 SDL_EnableKeyRepeat(0,0); | |
237 | |
238 /* get information about the graphics adapter */ | |
239 vidInfo = SDL_GetVideoInfo (); | |
240 | |
241 /* collect all fullscreen & hardware modes available */ | |
242 if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) { | |
243 | |
244 /* non hardware accelerated fullscreen modes */ | |
245 priv->sdlfullflags &= ~SDL_HWSURFACE; | |
246 priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags); | |
247 } | |
248 | |
249 /* test for normal resizeable & windowed hardware accellerated surfaces */ | |
250 if (!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) { | |
251 | |
252 /* test for NON hardware accelerated resizeable surfaces - poor you. | |
253 * That's all we have. If this fails there's nothing left. | |
254 * Theoretically there could be Fullscreenmodes left - we ignore this for now. | |
255 */ | |
256 priv->sdlflags &= ~SDL_HWSURFACE; | |
257 if ((!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) && (!priv->fullmodes)) { | |
258 // LOG (LOG_ERROR, "SDL video out: Couldn't get any acceptable SDL Mode for output. (SDL_ListModes failed)"); | |
259 return -1; | |
260 } | |
261 } | |
262 | |
263 | |
264 /* YUV overlays need at least 16-bit color depth, but the | |
265 * display might less. The SDL AAlib target says it can only do | |
266 * 8-bits, for example. So, if the display is less than 16-bits, | |
267 * we'll force the BPP to 16, and pray that SDL can emulate for us. | |
268 */ | |
269 priv->bpp = vidInfo->vfmt->BitsPerPixel; | |
270 if (priv->bpp < 16) { | |
271 /* | |
272 LOG (LOG_WARNING, "SDL video out: Your SDL display target wants to be at a color depth of (%d), but we need it to be at\ | |
273 least 16 bits, so we need to emulate 16-bit color. This is going to slow things down; you might want to\ | |
274 increase your display's color depth, if possible", priv->bpp); | |
275 */ | |
276 priv->bpp = 16; | |
277 } | |
278 | |
279 /* We dont want those in out event queue */ | |
280 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
281 SDL_EventState(SDL_KEYDOWN, SDL_IGNORE); |
1 | 282 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); |
283 SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); | |
284 SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); | |
285 SDL_EventState(SDL_QUIT, SDL_IGNORE); | |
286 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE); | |
287 SDL_EventState(SDL_USEREVENT, SDL_IGNORE); | |
288 | |
289 /* Success! */ | |
290 return 0; | |
291 } | |
292 | |
293 | |
294 /** | |
295 * Close SDL, Cleanups, Free Memory | |
296 * | |
297 * params : *plugin | |
298 * returns : non-zero on success, zero on error. | |
299 **/ | |
300 | |
301 static int sdl_close (void) | |
302 { | |
303 struct sdl_priv_s *priv = &sdl_priv; | |
304 | |
305 /* Cleanup YUV Overlay structure */ | |
306 if (priv->overlay) | |
307 SDL_FreeYUVOverlay(priv->overlay); | |
308 | |
309 /* Free our blitting surface */ | |
310 if (priv->surface) | |
311 SDL_FreeSurface(priv->surface); | |
312 | |
351 | 313 /* DONT attempt to free the fullscreen modes array. SDL_Quit* does this for us */ |
1 | 314 |
315 /* Cleanup SDL */ | |
351 | 316 SDL_Quit(); /* might have to be changed to quitsubsystem only, if plugins become |
317 changeable on the fly */ | |
318 | |
319 // LOG (LOG_DEBUG, "SDL video out: Closed Plugin"); | |
1 | 320 |
321 return 0; | |
322 } | |
323 | |
324 | |
325 /** | |
326 * Sets the specified fullscreen mode. | |
327 * | |
328 * params : mode == index of the desired fullscreen mode | |
329 * returns : doesn't return | |
330 **/ | |
331 | |
332 static void set_fullmode (int mode) | |
333 { | |
334 struct sdl_priv_s *priv = &sdl_priv; | |
335 SDL_Surface *newsurface = NULL; | |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
336 int haspect, waspect = 0; |
1 | 337 |
338 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */ | |
339 if (mode < 0) | |
340 mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1; | |
341 | |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
342 /* Calculate proper aspect ratio for fullscreen |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
343 * Height smaller than expected: add horizontal black bars (haspect)*/ |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
344 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); |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
345 /* Height bigger than expected: add vertical black bars (waspect)*/ |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
346 if (haspect < 0) { |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
347 haspect = 0; /* set haspect to zero because image will be scaled horizontal instead of vertical */ |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
348 waspect = priv->fullmodes[mode]->w - ((float) ((float) priv->fullmodes[mode]->h / (float) priv->height) * (float) priv->width); |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
349 } |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
350 // printf ("W-Aspect: %i H-Aspect: %i\n", waspect, haspect); |
84 | 351 |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
352 /* change to given fullscreen mode and hide the mouse cursor */ |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
353 newsurface = SDL_SetVideoMode(priv->fullmodes[mode]->w - waspect, priv->fullmodes[mode]->h - haspect, priv->bpp, priv->sdlfullflags); |
1 | 354 |
355 /* if we were successfull hide the mouse cursor and save the mode */ | |
356 if (newsurface) { | |
357 priv->surface = newsurface; | |
358 SDL_ShowCursor(0); | |
359 } | |
360 } | |
361 | |
362 | |
363 /** | |
364 * Initialize an SDL surface and an SDL YUV overlay. | |
365 * | |
366 * params : width == width of video we'll be displaying. | |
367 * height == height of video we'll be displaying. | |
368 * fullscreen == want to be fullscreen? | |
369 * title == Title for window titlebar. | |
370 * returns : non-zero on success, zero on error. | |
371 **/ | |
372 | |
373 static uint32_t | |
374 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | |
375 //static int sdl_setup (int width, int height) | |
376 { | |
377 struct sdl_priv_s *priv = &sdl_priv; | |
357 | 378 unsigned int sdl_format; |
351 | 379 |
1 | 380 |
381 switch(format){ | |
351 | 382 case IMGFMT_YV12: |
383 sdl_format=SDL_YV12_OVERLAY; | |
384 printf("SDL: Using YV12 image format\n"); | |
385 break; | |
386 case IMGFMT_YUY2: | |
387 sdl_format=SDL_YUY2_OVERLAY; | |
388 printf("SDL: Using YUY2 image format\n"); | |
389 break; | |
408 | 390 case IMGFMT_UYVY: |
391 sdl_format=SDL_UYVY_OVERLAY; | |
392 printf("SDL: Using UYVY image format\n"); | |
393 break; | |
1 | 394 default: |
395 printf("SDL: Unsupported image format (0x%X)\n",format); | |
396 return -1; | |
397 } | |
398 | |
399 sdl_open (NULL, NULL); | |
400 | |
351 | 401 /* Set output window title */ |
355
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
402 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", "SDL Video Out"); |
351 | 403 |
1 | 404 /* Save the original Image size */ |
84 | 405 |
1 | 406 priv->width = width; |
407 priv->height = height; | |
408 priv->format = format; | |
409 | |
355
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
410 /* bit 0 (0x01) means fullscreen (-fs) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
411 * bit 1 (0x02) means mode switching (-vm) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
412 * bit 2 (0x04) enables software scaling (-zoom) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
413 */ |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
414 // printf("SDL: fullscreenflag is set to: %i\n", fullscreen); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
415 // printf("SDL: Width: %i Height: %i D_Width %i D_Height: %i\n", width, height, d_width, d_height); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
416 switch(fullscreen){ |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
417 case 0x01: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
418 case 0x05: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
419 printf("SDL: setting zoomed fullscreen without modeswitching\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
420 priv->windowsize.w = d_width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
421 priv->windowsize.h = d_height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
422 if(priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
423 SDL_ShowCursor(0); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
424 break; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
425 case 0x02: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
426 case 0x03: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
427 printf("SDL: setting nonzoomed fullscreen with modeswitching\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
428 priv->windowsize.w = width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
429 priv->windowsize.h = height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
430 if(priv->surface = SDL_SetVideoMode (width, height, priv->bpp, priv->sdlfullflags)) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
431 SDL_ShowCursor(0); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
432 break; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
433 case 0x06: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
434 case 0x07: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
435 printf("SDL: setting zoomed fullscreen with modeswitching\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
436 priv->windowsize.w = width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
437 priv->windowsize.h = height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
438 priv->surface=NULL; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
439 set_fullmode(priv->fullmode); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
440 break; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
441 default: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
442 printf("SDL: setting windowed mode\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
443 priv->windowsize.w = d_width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
444 priv->windowsize.h = d_height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
445 priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlflags); |
1 | 446 } |
447 if(!priv->surface) return -1; // cannot SetVideoMode | |
448 | |
449 /* Initialize and create the YUV Overlay used for video out */ | |
450 if (!(priv->overlay = SDL_CreateYUVOverlay (width, height, sdl_format, priv->surface))) { | |
451 printf ("SDL video out: Couldn't create an SDL-based YUV overlay\n"); | |
452 return -1; | |
453 } | |
454 priv->framePlaneY = width * height; | |
455 priv->framePlaneUV = (width * height) >> 2; | |
456 priv->stridePlaneY = width; | |
457 priv->stridePlaneUV = width/2; | |
458 | |
459 return 0; | |
460 } | |
461 | |
462 | |
463 /** | |
464 * Draw a frame to the SDL YUV overlay. | |
465 * | |
466 * params : *src[] == the Y, U, and V planes that make up the frame. | |
467 * returns : non-zero on success, zero on error. | |
468 **/ | |
469 | |
470 //static int sdl_draw_frame (frame_t *frame) | |
471 static uint32_t draw_frame(uint8_t *src[]) | |
472 { | |
473 struct sdl_priv_s *priv = &sdl_priv; | |
474 uint8_t *dst; | |
475 | |
476 // priv->current_frame = (SDL_Overlay*) frame->private; | |
477 // SDL_UnlockYUVOverlay (priv->current_frame); | |
478 | |
479 if (SDL_LockYUVOverlay (priv->overlay)) { | |
480 // LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay"); | |
481 return -1; | |
482 } | |
483 | |
484 switch(priv->format){ | |
485 case IMGFMT_YV12: | |
408 | 486 case IMGFMT_I420: |
487 case IMGFMT_IYUV: | |
1 | 488 dst = (uint8_t *) *(priv->overlay->pixels); |
489 memcpy (dst, src[0], priv->framePlaneY); | |
490 dst += priv->framePlaneY; | |
491 memcpy (dst, src[2], priv->framePlaneUV); | |
492 dst += priv->framePlaneUV; | |
493 memcpy (dst, src[1], priv->framePlaneUV); | |
494 break; | |
408 | 495 |
1 | 496 case IMGFMT_YUY2: |
408 | 497 case IMGFMT_UYVY: |
498 case IMGFMT_YVYU: | |
1 | 499 dst = (uint8_t *) *(priv->overlay->pixels); |
500 memcpy (dst, src[0], priv->width*priv->height*2); | |
501 break; | |
502 } | |
503 | |
504 SDL_UnlockYUVOverlay (priv->overlay); | |
505 return 0; | |
506 } | |
507 | |
508 | |
509 /** | |
510 * Draw a slice (16 rows of image) to the SDL YUV overlay. | |
511 * | |
512 * params : *src[] == the Y, U, and V planes that make up the slice. | |
513 * returns : non-zero on error, zero on success. | |
514 **/ | |
515 | |
516 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num) | |
517 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
518 { | |
519 struct sdl_priv_s *priv = &sdl_priv; | |
520 uint8_t *dst; | |
521 uint8_t *src; | |
522 int i; | |
523 | |
524 //priv->current_frame = priv->overlay; | |
525 | |
526 if (SDL_LockYUVOverlay (priv->overlay)) { | |
527 // LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay"); | |
528 return -1; | |
529 } | |
530 | |
531 dst = (uint8_t *) *(priv->overlay->pixels) | |
532 + (priv->stridePlaneY * y + x); | |
533 src = image[0]; | |
534 for(i=0;i<h;i++){ | |
535 memcpy(dst,src,w); | |
536 src+=stride[0]; | |
537 dst+=priv->stridePlaneY; | |
538 } | |
539 | |
540 x/=2;y/=2;w/=2;h/=2; | |
541 | |
542 dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY | |
543 + (priv->stridePlaneUV * y + x); | |
544 src = image[2]; | |
545 for(i=0;i<h;i++){ | |
546 memcpy(dst,src,w); | |
547 src+=stride[2]; | |
548 dst+=priv->stridePlaneUV; | |
549 } | |
550 | |
551 dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY | |
552 + priv->framePlaneUV + (priv->stridePlaneUV * y + x); | |
553 src = image[1]; | |
554 for(i=0;i<h;i++){ | |
555 memcpy(dst,src,w); | |
556 src+=stride[1]; | |
557 dst+=priv->stridePlaneUV; | |
558 } | |
559 | |
560 #if 0 | |
561 dst = (uint8_t *) *(priv->overlay->pixels) + (priv->slicePlaneY * slice_num); | |
562 memcpy (dst, src[0], priv->slicePlaneY); | |
563 dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY + (priv->slicePlaneUV * slice_num); | |
564 memcpy (dst, src[2], priv->slicePlaneUV); | |
565 dst += priv->framePlaneUV; | |
566 memcpy (dst, src[1], priv->slicePlaneUV); | |
567 #endif | |
568 | |
569 SDL_UnlockYUVOverlay (priv->overlay); | |
570 | |
571 return 0; | |
572 } | |
573 | |
574 | |
575 | |
576 /** | |
577 * Checks for SDL keypress and window resize events | |
578 * | |
579 * params : none | |
580 * returns : doesn't return | |
581 **/ | |
582 | |
583 #include "../linux/keycodes.h" | |
584 extern void mplayer_put_key(int code); | |
585 | |
586 static void check_events (void) | |
587 { | |
588 struct sdl_priv_s *priv = &sdl_priv; | |
589 SDL_Event event; | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
590 SDLKey keypressed = 0; |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
591 static int firstcheck = 0; |
1 | 592 |
593 /* Poll the waiting SDL Events */ | |
594 while ( SDL_PollEvent(&event) ) { | |
595 switch (event.type) { | |
596 | |
597 /* capture window resize events */ | |
598 case SDL_VIDEORESIZE: | |
599 priv->surface = SDL_SetVideoMode(event.resize.w, event.resize.h, priv->bpp, priv->sdlflags); | |
600 | |
601 /* save video extents, to restore them after going fullscreen */ | |
602 //if(!(priv->surface->flags & SDL_FULLSCREEN)) { | |
603 priv->windowsize.w = priv->surface->w; | |
604 priv->windowsize.h = priv->surface->h; | |
605 //} | |
606 // LOG (LOG_DEBUG, "SDL video out: Window resize"); | |
607 break; | |
608 | |
609 | |
610 /* graphics mode selection shortcuts */ | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
611 case SDL_KEYUP: |
1 | 612 keypressed = event.key.keysym.sym; |
265
1d02e6f7c63a
Only small change to allow pausing of movie (p or SPACE).
atmosfear
parents:
97
diff
changeset
|
613 |
357 | 614 /* c key pressed. c cycles through available fullscreenmodes, if we have some */ |
355
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
615 if ( ((keypressed == SDLK_c)) && (priv->fullmodes) ) { |
1 | 616 /* select next fullscreen mode */ |
617 priv->fullmode++; | |
618 if (priv->fullmode > (findArrayEnd(priv->fullmodes) - 1)) priv->fullmode = 0; | |
619 set_fullmode(priv->fullmode); | |
620 | |
621 // LOG (LOG_DEBUG, "SDL video out: Set next available fullscreen mode."); | |
622 } | |
623 | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
624 /* f key pressed toggles/exits fullscreenmode */ |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
625 else if ( keypressed == SDLK_f ) { |
265
1d02e6f7c63a
Only small change to allow pausing of movie (p or SPACE).
atmosfear
parents:
97
diff
changeset
|
626 if (priv->surface->flags & SDL_FULLSCREEN) { |
1 | 627 priv->surface = SDL_SetVideoMode(priv->windowsize.w, priv->windowsize.h, priv->bpp, priv->sdlflags); |
628 SDL_ShowCursor(1); | |
629 // LOG (LOG_DEBUG, "SDL video out: Windowed mode"); | |
630 } | |
631 else if (priv->fullmodes){ | |
632 set_fullmode(priv->fullmode); | |
633 | |
634 // LOG (LOG_DEBUG, "SDL video out: Set fullscreen mode."); | |
635 } | |
636 } | |
637 | |
638 else switch(keypressed){ | |
639 // case SDLK_q: if(!(priv->surface->flags & SDL_FULLSCREEN))mplayer_put_key('q');break; | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
640 case SDLK_RETURN: |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
641 if (!firstcheck) { firstcheck = 1; break; } |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
642 case SDLK_ESCAPE: |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
643 case SDLK_q: |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
644 SDL_ShowCursor(1); |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
645 mplayer_put_key('q'); |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
646 break; |
386 | 647 case SDLK_o: mplayer_put_key('o');break; |
265
1d02e6f7c63a
Only small change to allow pausing of movie (p or SPACE).
atmosfear
parents:
97
diff
changeset
|
648 case SDLK_p: mplayer_put_key('p');break; |
1d02e6f7c63a
Only small change to allow pausing of movie (p or SPACE).
atmosfear
parents:
97
diff
changeset
|
649 case SDLK_SPACE: mplayer_put_key(' ');break; |
1 | 650 case SDLK_UP: mplayer_put_key(KEY_UP);break; |
651 case SDLK_DOWN: mplayer_put_key(KEY_DOWN);break; | |
652 case SDLK_LEFT: mplayer_put_key(KEY_LEFT);break; | |
653 case SDLK_RIGHT: mplayer_put_key(KEY_RIGHT);break; | |
654 case SDLK_PLUS: | |
655 case SDLK_KP_PLUS: mplayer_put_key('+');break; | |
656 case SDLK_MINUS: | |
657 case SDLK_KP_MINUS: mplayer_put_key('-');break; | |
658 } | |
659 | |
660 break; | |
661 } | |
662 } | |
663 } | |
664 | |
665 | |
666 /** | |
667 * Display the surface we have written our data to and check for events. | |
668 * | |
669 * params : mode == index of the desired fullscreen mode | |
670 * returns : doesn't return | |
671 **/ | |
672 | |
673 static void flip_page (void) | |
674 { | |
675 struct sdl_priv_s *priv = &sdl_priv; | |
676 | |
351 | 677 //vo_draw_alpha_yuy2(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride) |
678 vo_draw_text(priv->width,priv->height,draw_alpha); | |
679 | |
1 | 680 /* check and react on keypresses and window resizes */ |
681 check_events(); | |
682 | |
683 /* blit to the YUV overlay */ | |
684 SDL_DisplayYUVOverlay (priv->overlay, &priv->surface->clip_rect); | |
685 | |
686 /* check if we have a double buffered surface and flip() if we do. */ | |
687 if ( priv->surface->flags & SDL_DOUBLEBUF ) | |
688 SDL_Flip(priv->surface); | |
689 | |
690 SDL_LockYUVOverlay (priv->overlay); | |
691 } | |
692 | |
693 #if 0 | |
694 static frame_t* sdl_allocate_image_buffer(int width, int height) | |
695 { | |
696 struct sdl_priv_s *priv = &sdl_priv; | |
697 frame_t *frame; | |
698 | |
699 if (!(frame = malloc (sizeof (frame_t)))) | |
700 return NULL; | |
701 | |
702 if (!(frame->private = (void*) SDL_CreateYUVOverlay (width, height, | |
703 SDL_IYUV_OVERLAY, priv->surface))) | |
704 { | |
705 // LOG (LOG_ERROR, "SDL video out: Couldn't create an SDL-based YUV overlay"); | |
706 return NULL; | |
707 } | |
708 | |
709 frame->base[0] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[0]; | |
710 frame->base[1] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[1]; | |
711 frame->base[2] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[2]; | |
712 | |
713 SDL_LockYUVOverlay ((SDL_Overlay*) frame->private); | |
714 return frame; | |
715 } | |
716 | |
717 static void sdl_free_image_buffer(frame_t* frame) | |
718 { | |
719 SDL_FreeYUVOverlay((SDL_Overlay*) frame->private); | |
720 free(frame); | |
721 } | |
722 #endif | |
723 | |
724 static uint32_t | |
725 query_format(uint32_t format) | |
726 { | |
727 switch(format){ | |
728 case IMGFMT_YV12: | |
408 | 729 case IMGFMT_I420: |
730 case IMGFMT_IYUV: | |
1 | 731 case IMGFMT_YUY2: |
408 | 732 case IMGFMT_UYVY: |
733 case IMGFMT_YVYU: | |
1 | 734 // case IMGFMT_RGB|24: |
735 // case IMGFMT_BGR|24: | |
736 return 1; | |
737 } | |
738 return 0; | |
739 } | |
740 | |
741 static const vo_info_t* | |
742 get_info(void) | |
743 { | |
744 return &vo_info; | |
745 } | |
746 | |
747 | |
748 static void | |
749 uninit(void) | |
750 { | |
751 sdl_close(); | |
752 } | |
753 |