Mercurial > mplayer.hg
annotate libvo/vo_sdl.c @ 400:ae91bfef2a94
fixed debug printfs
author | arpi_esp |
---|---|
date | Sat, 14 Apr 2001 03:13:48 +0000 |
parents | f4fb35ef4c06 |
children | b61c5c4484f8 |
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){ | |
149 struct sdl_priv_s *priv = &sdl_priv; | |
150 int x,y; | |
151 | |
152 if (priv->format==IMGFMT_YV12) | |
153 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+priv->width*y0+x0,priv->width); | |
154 else | |
155 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) *(priv->overlay->pixels))+2*(priv->width*y0+x0),2*priv->width); | |
156 | |
157 } | |
1 | 158 |
159 | |
160 /** | |
161 * Take a null-terminated array of pointers, and find the last element. | |
162 * | |
163 * params : array == array of which we want to find the last element. | |
164 * returns : index of last NON-NULL element. | |
165 **/ | |
166 | |
167 static inline int findArrayEnd (SDL_Rect **array) | |
168 { | |
169 int i = 0; | |
170 while ( array[i++] ); /* keep loopin' ... */ | |
171 | |
172 /* return the index of the last array element */ | |
173 return i - 1; | |
174 } | |
175 | |
176 | |
177 /** | |
178 * Open and prepare SDL output. | |
179 * | |
180 * params : *plugin == | |
181 * *name == | |
182 * returns : 0 on success, -1 on failure | |
183 **/ | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
184 |
1 | 185 static int sdl_open (void *plugin, void *name) |
186 { | |
187 struct sdl_priv_s *priv = &sdl_priv; | |
188 const SDL_VideoInfo *vidInfo = NULL; | |
189 static int opened = 0; | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
190 |
1 | 191 if (opened) |
192 return 0; | |
193 opened = 1; | |
194 | |
195 // LOG (LOG_DEBUG, "SDL video out: Opened Plugin"); | |
351 | 196 |
197 /* does the user want SDL to try and force Xv */ | |
198 #ifdef SDL_FORCEXV | |
199 setenv("SDL_VIDEO_X11_NODIRECTCOLOR", "1", 1); | |
200 #endif | |
394
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
201 #ifdef SDL_NOXV |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
202 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1); |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
203 #endif |
1 | 204 |
84 | 205 /* default to no fullscreen mode, we'll set this as soon we have the avail. modes */ |
1 | 206 priv->fullmode = -2; |
207 /* other default values */ | |
394
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
208 #ifdef SDL_NOHWSURFACE |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
209 printf("SDL: using software-surface\n"); |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
210 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
|
211 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
|
212 #else |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
213 printf("SDL: using hardware-surface\n"); |
f4fb35ef4c06
- added some defines to modify some sdl-out internas (see comments)
atmosfear
parents:
386
diff
changeset
|
214 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
|
215 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
|
216 #endif |
1 | 217 priv->surface = NULL; |
218 priv->overlay = NULL; | |
219 priv->fullmodes = NULL; | |
351 | 220 priv->bpp = 0; //added atmos |
1 | 221 |
222 /* initialize the SDL Video system */ | |
223 if (SDL_Init (SDL_INIT_VIDEO)) { | |
224 // LOG (LOG_ERROR, "SDL video out: Initializing of SDL failed (SDL_Init). Please use the latest version of SDL."); | |
225 return -1; | |
226 } | |
227 | |
228 /* No Keyrepeats! */ | |
229 SDL_EnableKeyRepeat(0,0); | |
230 | |
231 /* get information about the graphics adapter */ | |
232 vidInfo = SDL_GetVideoInfo (); | |
233 | |
234 /* collect all fullscreen & hardware modes available */ | |
235 if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) { | |
236 | |
237 /* non hardware accelerated fullscreen modes */ | |
238 priv->sdlfullflags &= ~SDL_HWSURFACE; | |
239 priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags); | |
240 } | |
241 | |
242 /* test for normal resizeable & windowed hardware accellerated surfaces */ | |
243 if (!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) { | |
244 | |
245 /* test for NON hardware accelerated resizeable surfaces - poor you. | |
246 * That's all we have. If this fails there's nothing left. | |
247 * Theoretically there could be Fullscreenmodes left - we ignore this for now. | |
248 */ | |
249 priv->sdlflags &= ~SDL_HWSURFACE; | |
250 if ((!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) && (!priv->fullmodes)) { | |
251 // LOG (LOG_ERROR, "SDL video out: Couldn't get any acceptable SDL Mode for output. (SDL_ListModes failed)"); | |
252 return -1; | |
253 } | |
254 } | |
255 | |
256 | |
257 /* YUV overlays need at least 16-bit color depth, but the | |
258 * display might less. The SDL AAlib target says it can only do | |
259 * 8-bits, for example. So, if the display is less than 16-bits, | |
260 * we'll force the BPP to 16, and pray that SDL can emulate for us. | |
261 */ | |
262 priv->bpp = vidInfo->vfmt->BitsPerPixel; | |
263 if (priv->bpp < 16) { | |
264 /* | |
265 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\ | |
266 least 16 bits, so we need to emulate 16-bit color. This is going to slow things down; you might want to\ | |
267 increase your display's color depth, if possible", priv->bpp); | |
268 */ | |
269 priv->bpp = 16; | |
270 } | |
271 | |
272 /* We dont want those in out event queue */ | |
273 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
274 SDL_EventState(SDL_KEYDOWN, SDL_IGNORE); |
1 | 275 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); |
276 SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); | |
277 SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); | |
278 SDL_EventState(SDL_QUIT, SDL_IGNORE); | |
279 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE); | |
280 SDL_EventState(SDL_USEREVENT, SDL_IGNORE); | |
281 | |
282 /* Success! */ | |
283 return 0; | |
284 } | |
285 | |
286 | |
287 /** | |
288 * Close SDL, Cleanups, Free Memory | |
289 * | |
290 * params : *plugin | |
291 * returns : non-zero on success, zero on error. | |
292 **/ | |
293 | |
294 static int sdl_close (void) | |
295 { | |
296 struct sdl_priv_s *priv = &sdl_priv; | |
297 | |
298 /* Cleanup YUV Overlay structure */ | |
299 if (priv->overlay) | |
300 SDL_FreeYUVOverlay(priv->overlay); | |
301 | |
302 /* Free our blitting surface */ | |
303 if (priv->surface) | |
304 SDL_FreeSurface(priv->surface); | |
305 | |
351 | 306 /* DONT attempt to free the fullscreen modes array. SDL_Quit* does this for us */ |
1 | 307 |
308 /* Cleanup SDL */ | |
351 | 309 SDL_Quit(); /* might have to be changed to quitsubsystem only, if plugins become |
310 changeable on the fly */ | |
311 | |
312 // LOG (LOG_DEBUG, "SDL video out: Closed Plugin"); | |
1 | 313 |
314 return 0; | |
315 } | |
316 | |
317 | |
318 /** | |
319 * Sets the specified fullscreen mode. | |
320 * | |
321 * params : mode == index of the desired fullscreen mode | |
322 * returns : doesn't return | |
323 **/ | |
324 | |
325 static void set_fullmode (int mode) | |
326 { | |
327 struct sdl_priv_s *priv = &sdl_priv; | |
328 SDL_Surface *newsurface = NULL; | |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
329 int haspect, waspect = 0; |
1 | 330 |
331 /* if we haven't set a fullmode yet, default to the lowest res fullmode first */ | |
332 if (mode < 0) | |
333 mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1; | |
334 | |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
335 /* Calculate proper aspect ratio for fullscreen |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
336 * 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
|
337 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
|
338 /* 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
|
339 if (haspect < 0) { |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
340 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
|
341 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
|
342 } |
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
343 // printf ("W-Aspect: %i H-Aspect: %i\n", waspect, haspect); |
84 | 344 |
97
cab74dfde6dd
Felix B¸«änemann added support for horizontal scaling for aspect-ratio in
atmosfear
parents:
84
diff
changeset
|
345 /* 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
|
346 newsurface = SDL_SetVideoMode(priv->fullmodes[mode]->w - waspect, priv->fullmodes[mode]->h - haspect, priv->bpp, priv->sdlfullflags); |
1 | 347 |
348 /* if we were successfull hide the mouse cursor and save the mode */ | |
349 if (newsurface) { | |
350 priv->surface = newsurface; | |
351 SDL_ShowCursor(0); | |
352 } | |
353 } | |
354 | |
355 | |
356 /** | |
357 * Initialize an SDL surface and an SDL YUV overlay. | |
358 * | |
359 * params : width == width of video we'll be displaying. | |
360 * height == height of video we'll be displaying. | |
361 * fullscreen == want to be fullscreen? | |
362 * title == Title for window titlebar. | |
363 * returns : non-zero on success, zero on error. | |
364 **/ | |
365 | |
366 static uint32_t | |
367 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | |
368 //static int sdl_setup (int width, int height) | |
369 { | |
370 struct sdl_priv_s *priv = &sdl_priv; | |
357 | 371 unsigned int sdl_format; |
351 | 372 |
1 | 373 |
374 switch(format){ | |
351 | 375 case IMGFMT_YV12: |
376 sdl_format=SDL_YV12_OVERLAY; | |
377 printf("SDL: Using YV12 image format\n"); | |
378 break; | |
379 case IMGFMT_YUY2: | |
380 sdl_format=SDL_YUY2_OVERLAY; | |
381 printf("SDL: Using YUY2 image format\n"); | |
382 break; | |
1 | 383 default: |
384 printf("SDL: Unsupported image format (0x%X)\n",format); | |
385 return -1; | |
386 } | |
387 | |
388 sdl_open (NULL, NULL); | |
389 | |
351 | 390 /* Set output window title */ |
355
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
391 SDL_WM_SetCaption (".: MPlayer : F = Fullscreen/Windowed : C = Cycle Fullscreen Resolutions :.", "SDL Video Out"); |
351 | 392 |
1 | 393 /* Save the original Image size */ |
84 | 394 |
1 | 395 priv->width = width; |
396 priv->height = height; | |
397 priv->format = format; | |
398 | |
355
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
399 /* bit 0 (0x01) means fullscreen (-fs) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
400 * bit 1 (0x02) means mode switching (-vm) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
401 * bit 2 (0x04) enables software scaling (-zoom) |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
402 */ |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
403 // printf("SDL: fullscreenflag is set to: %i\n", fullscreen); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
404 // 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
|
405 switch(fullscreen){ |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
406 case 0x01: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
407 case 0x05: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
408 printf("SDL: setting zoomed fullscreen without modeswitching\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
409 priv->windowsize.w = d_width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
410 priv->windowsize.h = d_height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
411 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
|
412 SDL_ShowCursor(0); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
413 break; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
414 case 0x02: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
415 case 0x03: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
416 printf("SDL: setting nonzoomed fullscreen with modeswitching\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
417 priv->windowsize.w = width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
418 priv->windowsize.h = height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
419 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
|
420 SDL_ShowCursor(0); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
421 break; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
422 case 0x06: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
423 case 0x07: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
424 printf("SDL: setting zoomed fullscreen with modeswitching\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
425 priv->windowsize.w = width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
426 priv->windowsize.h = height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
427 priv->surface=NULL; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
428 set_fullmode(priv->fullmode); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
429 break; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
430 default: |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
431 printf("SDL: setting windowed mode\n"); |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
432 priv->windowsize.w = d_width; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
433 priv->windowsize.h = d_height; |
70833462dee9
- added code to comply with new fullscreen meaning
atmosfear
parents:
354
diff
changeset
|
434 priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlflags); |
1 | 435 } |
436 if(!priv->surface) return -1; // cannot SetVideoMode | |
437 | |
438 /* Initialize and create the YUV Overlay used for video out */ | |
439 if (!(priv->overlay = SDL_CreateYUVOverlay (width, height, sdl_format, priv->surface))) { | |
440 printf ("SDL video out: Couldn't create an SDL-based YUV overlay\n"); | |
441 return -1; | |
442 } | |
443 priv->framePlaneY = width * height; | |
444 priv->framePlaneUV = (width * height) >> 2; | |
445 priv->stridePlaneY = width; | |
446 priv->stridePlaneUV = width/2; | |
447 | |
448 return 0; | |
449 } | |
450 | |
451 | |
452 /** | |
453 * Draw a frame to the SDL YUV overlay. | |
454 * | |
455 * params : *src[] == the Y, U, and V planes that make up the frame. | |
456 * returns : non-zero on success, zero on error. | |
457 **/ | |
458 | |
459 //static int sdl_draw_frame (frame_t *frame) | |
460 static uint32_t draw_frame(uint8_t *src[]) | |
461 { | |
462 struct sdl_priv_s *priv = &sdl_priv; | |
463 uint8_t *dst; | |
464 | |
465 // priv->current_frame = (SDL_Overlay*) frame->private; | |
466 // SDL_UnlockYUVOverlay (priv->current_frame); | |
467 | |
468 if (SDL_LockYUVOverlay (priv->overlay)) { | |
469 // LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay"); | |
470 return -1; | |
471 } | |
472 | |
473 switch(priv->format){ | |
474 case IMGFMT_YV12: | |
475 dst = (uint8_t *) *(priv->overlay->pixels); | |
476 memcpy (dst, src[0], priv->framePlaneY); | |
477 dst += priv->framePlaneY; | |
478 memcpy (dst, src[2], priv->framePlaneUV); | |
479 dst += priv->framePlaneUV; | |
480 memcpy (dst, src[1], priv->framePlaneUV); | |
481 break; | |
482 case IMGFMT_YUY2: | |
483 dst = (uint8_t *) *(priv->overlay->pixels); | |
484 memcpy (dst, src[0], priv->width*priv->height*2); | |
485 break; | |
486 } | |
487 | |
488 SDL_UnlockYUVOverlay (priv->overlay); | |
489 | |
490 return 0; | |
491 } | |
492 | |
493 | |
494 /** | |
495 * Draw a slice (16 rows of image) to the SDL YUV overlay. | |
496 * | |
497 * params : *src[] == the Y, U, and V planes that make up the slice. | |
498 * returns : non-zero on error, zero on success. | |
499 **/ | |
500 | |
501 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num) | |
502 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
503 { | |
504 struct sdl_priv_s *priv = &sdl_priv; | |
505 uint8_t *dst; | |
506 uint8_t *src; | |
507 int i; | |
508 | |
509 //priv->current_frame = priv->overlay; | |
510 | |
511 if (SDL_LockYUVOverlay (priv->overlay)) { | |
512 // LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay"); | |
513 return -1; | |
514 } | |
515 | |
516 dst = (uint8_t *) *(priv->overlay->pixels) | |
517 + (priv->stridePlaneY * y + x); | |
518 src = image[0]; | |
519 for(i=0;i<h;i++){ | |
520 memcpy(dst,src,w); | |
521 src+=stride[0]; | |
522 dst+=priv->stridePlaneY; | |
523 } | |
524 | |
525 x/=2;y/=2;w/=2;h/=2; | |
526 | |
527 dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY | |
528 + (priv->stridePlaneUV * y + x); | |
529 src = image[2]; | |
530 for(i=0;i<h;i++){ | |
531 memcpy(dst,src,w); | |
532 src+=stride[2]; | |
533 dst+=priv->stridePlaneUV; | |
534 } | |
535 | |
536 dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY | |
537 + priv->framePlaneUV + (priv->stridePlaneUV * y + x); | |
538 src = image[1]; | |
539 for(i=0;i<h;i++){ | |
540 memcpy(dst,src,w); | |
541 src+=stride[1]; | |
542 dst+=priv->stridePlaneUV; | |
543 } | |
544 | |
545 #if 0 | |
546 dst = (uint8_t *) *(priv->overlay->pixels) + (priv->slicePlaneY * slice_num); | |
547 memcpy (dst, src[0], priv->slicePlaneY); | |
548 dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY + (priv->slicePlaneUV * slice_num); | |
549 memcpy (dst, src[2], priv->slicePlaneUV); | |
550 dst += priv->framePlaneUV; | |
551 memcpy (dst, src[1], priv->slicePlaneUV); | |
552 #endif | |
553 | |
554 SDL_UnlockYUVOverlay (priv->overlay); | |
555 | |
556 return 0; | |
557 } | |
558 | |
559 | |
560 | |
561 /** | |
562 * Checks for SDL keypress and window resize events | |
563 * | |
564 * params : none | |
565 * returns : doesn't return | |
566 **/ | |
567 | |
568 #include "../linux/keycodes.h" | |
569 extern void mplayer_put_key(int code); | |
570 | |
571 static void check_events (void) | |
572 { | |
573 struct sdl_priv_s *priv = &sdl_priv; | |
574 SDL_Event event; | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
575 SDLKey keypressed = 0; |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
576 static int firstcheck = 0; |
1 | 577 |
578 /* Poll the waiting SDL Events */ | |
579 while ( SDL_PollEvent(&event) ) { | |
580 switch (event.type) { | |
581 | |
582 /* capture window resize events */ | |
583 case SDL_VIDEORESIZE: | |
584 priv->surface = SDL_SetVideoMode(event.resize.w, event.resize.h, priv->bpp, priv->sdlflags); | |
585 | |
586 /* save video extents, to restore them after going fullscreen */ | |
587 //if(!(priv->surface->flags & SDL_FULLSCREEN)) { | |
588 priv->windowsize.w = priv->surface->w; | |
589 priv->windowsize.h = priv->surface->h; | |
590 //} | |
591 // LOG (LOG_DEBUG, "SDL video out: Window resize"); | |
592 break; | |
593 | |
594 | |
595 /* graphics mode selection shortcuts */ | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
596 case SDL_KEYUP: |
1 | 597 keypressed = event.key.keysym.sym; |
265
1d02e6f7c63a
Only small change to allow pausing of movie (p or SPACE).
atmosfear
parents:
97
diff
changeset
|
598 |
357 | 599 /* 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
|
600 if ( ((keypressed == SDLK_c)) && (priv->fullmodes) ) { |
1 | 601 /* select next fullscreen mode */ |
602 priv->fullmode++; | |
603 if (priv->fullmode > (findArrayEnd(priv->fullmodes) - 1)) priv->fullmode = 0; | |
604 set_fullmode(priv->fullmode); | |
605 | |
606 // LOG (LOG_DEBUG, "SDL video out: Set next available fullscreen mode."); | |
607 } | |
608 | |
331
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
609 /* f key pressed toggles/exits fullscreenmode */ |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
610 else if ( keypressed == SDLK_f ) { |
265
1d02e6f7c63a
Only small change to allow pausing of movie (p or SPACE).
atmosfear
parents:
97
diff
changeset
|
611 if (priv->surface->flags & SDL_FULLSCREEN) { |
1 | 612 priv->surface = SDL_SetVideoMode(priv->windowsize.w, priv->windowsize.h, priv->bpp, priv->sdlflags); |
613 SDL_ShowCursor(1); | |
614 // LOG (LOG_DEBUG, "SDL video out: Windowed mode"); | |
615 } | |
616 else if (priv->fullmodes){ | |
617 set_fullmode(priv->fullmode); | |
618 | |
619 // LOG (LOG_DEBUG, "SDL video out: Set fullscreen mode."); | |
620 } | |
621 } | |
622 | |
623 else switch(keypressed){ | |
624 // 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
|
625 case SDLK_RETURN: |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
626 if (!firstcheck) { firstcheck = 1; break; } |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
627 case SDLK_ESCAPE: |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
628 case SDLK_q: |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
629 SDL_ShowCursor(1); |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
630 mplayer_put_key('q'); |
0f1737e626fa
- Changed keypress-detection from keydown to keyup, seems to fix keyrepeat
atmosfear
parents:
265
diff
changeset
|
631 break; |
386 | 632 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
|
633 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
|
634 case SDLK_SPACE: mplayer_put_key(' ');break; |
1 | 635 case SDLK_UP: mplayer_put_key(KEY_UP);break; |
636 case SDLK_DOWN: mplayer_put_key(KEY_DOWN);break; | |
637 case SDLK_LEFT: mplayer_put_key(KEY_LEFT);break; | |
638 case SDLK_RIGHT: mplayer_put_key(KEY_RIGHT);break; | |
639 case SDLK_PLUS: | |
640 case SDLK_KP_PLUS: mplayer_put_key('+');break; | |
641 case SDLK_MINUS: | |
642 case SDLK_KP_MINUS: mplayer_put_key('-');break; | |
643 } | |
644 | |
645 break; | |
646 } | |
647 } | |
648 } | |
649 | |
650 | |
651 /** | |
652 * Display the surface we have written our data to and check for events. | |
653 * | |
654 * params : mode == index of the desired fullscreen mode | |
655 * returns : doesn't return | |
656 **/ | |
657 | |
658 static void flip_page (void) | |
659 { | |
660 struct sdl_priv_s *priv = &sdl_priv; | |
661 | |
351 | 662 //vo_draw_alpha_yuy2(int w,int h, unsigned char* src, unsigned char *srca, int srcstride, unsigned char* dstbase,int dststride) |
663 vo_draw_text(priv->width,priv->height,draw_alpha); | |
664 | |
1 | 665 /* check and react on keypresses and window resizes */ |
666 check_events(); | |
667 | |
668 /* blit to the YUV overlay */ | |
669 SDL_DisplayYUVOverlay (priv->overlay, &priv->surface->clip_rect); | |
670 | |
671 /* check if we have a double buffered surface and flip() if we do. */ | |
672 if ( priv->surface->flags & SDL_DOUBLEBUF ) | |
673 SDL_Flip(priv->surface); | |
674 | |
675 SDL_LockYUVOverlay (priv->overlay); | |
676 } | |
677 | |
678 #if 0 | |
679 static frame_t* sdl_allocate_image_buffer(int width, int height) | |
680 { | |
681 struct sdl_priv_s *priv = &sdl_priv; | |
682 frame_t *frame; | |
683 | |
684 if (!(frame = malloc (sizeof (frame_t)))) | |
685 return NULL; | |
686 | |
687 if (!(frame->private = (void*) SDL_CreateYUVOverlay (width, height, | |
688 SDL_IYUV_OVERLAY, priv->surface))) | |
689 { | |
690 // LOG (LOG_ERROR, "SDL video out: Couldn't create an SDL-based YUV overlay"); | |
691 return NULL; | |
692 } | |
693 | |
694 frame->base[0] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[0]; | |
695 frame->base[1] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[1]; | |
696 frame->base[2] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[2]; | |
697 | |
698 SDL_LockYUVOverlay ((SDL_Overlay*) frame->private); | |
699 return frame; | |
700 } | |
701 | |
702 static void sdl_free_image_buffer(frame_t* frame) | |
703 { | |
704 SDL_FreeYUVOverlay((SDL_Overlay*) frame->private); | |
705 free(frame); | |
706 } | |
707 #endif | |
708 | |
709 static uint32_t | |
710 query_format(uint32_t format) | |
711 { | |
712 switch(format){ | |
713 case IMGFMT_YV12: | |
714 case IMGFMT_YUY2: | |
715 // case IMGFMT_RGB|24: | |
716 // case IMGFMT_BGR|24: | |
717 return 1; | |
718 } | |
719 return 0; | |
720 } | |
721 | |
722 static const vo_info_t* | |
723 get_info(void) | |
724 { | |
725 return &vo_info; | |
726 } | |
727 | |
728 | |
729 static void | |
730 uninit(void) | |
731 { | |
732 sdl_close(); | |
733 } | |
734 |