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