Mercurial > mplayer.hg
annotate libvo/vo_directfb2.c @ 7594:a715a0960762
This just corrects a function name to match the other demuxer's
"xxx_check_file" convention, adds a verbose note about (to match the other
demuxers)
patch by Kees Cook <mplayer@outflux.net>
author | arpi |
---|---|
date | Fri, 04 Oct 2002 19:23:36 +0000 |
parents | fcbe94c83ff6 |
children | 530d1c5f0c78 |
rev | line source |
---|---|
6952 | 1 /* |
2 MPlayer video driver for DirectFramebuffer device | |
3 | |
4 (C) 2002 | |
5 | |
6 Written by Jiri Svoboda <Jiri.Svoboda@seznam.cz> | |
7 | |
8 This library is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU Lesser General Public | |
10 License as published by the Free Software Foundation; either | |
11 version 2 of the License, or (at your option) any later version. | |
12 | |
13 This library is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 Lesser General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Lesser General Public | |
19 License along with this library; if not, write to the | |
20 Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. | |
22 */ | |
23 | |
24 // directfb includes | |
25 | |
26 #include <directfb.h> | |
27 | |
28 // other things | |
29 | |
30 #include <stdio.h> | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 #include <fcntl.h> | |
34 #include <unistd.h> | |
35 #include <errno.h> | |
36 #include <ctype.h> | |
37 #include <assert.h> | |
38 | |
39 #include <sys/mman.h> | |
40 #include <sys/ioctl.h> | |
41 #include <sys/kd.h> | |
42 | |
43 #include "config.h" | |
44 #include "video_out.h" | |
45 #include "video_out_internal.h" | |
46 #include "fastmemcpy.h" | |
47 #include "sub.h" | |
48 | |
49 #include "aspect.h" | |
50 | |
51 #ifndef min | |
52 #define min(x,y) (((x)<(y))?(x):(y)) | |
53 #endif | |
54 | |
55 | |
56 LIBVO_EXTERN(directfb) | |
57 | |
58 static vo_info_t vo_info = { | |
59 "Direct Framebuffer Device", | |
60 "directfb", | |
61 "Jiri Svoboda Jiri.Svoboda@seznam.cz", | |
62 "version 2.0beta" | |
63 }; | |
64 | |
65 extern int verbose; | |
66 | |
67 /****************************** | |
68 * vo_directfb globals * | |
69 ******************************/ | |
70 | |
71 #define DFBCHECK(x...) \ | |
72 { \ | |
73 DFBResult err = x; \ | |
74 \ | |
75 if (err != DFB_OK) \ | |
76 { \ | |
77 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ | |
78 DirectFBErrorFatal( #x, err ); \ | |
79 } \ | |
80 } | |
81 | |
82 /* | |
83 * filled by preinit | |
84 */ | |
85 | |
86 // main DirectFB handle | |
87 static IDirectFB *dfb = NULL; | |
88 // keyboard handle | |
89 static IDirectFBInputDevice *keyboard = NULL; | |
90 // A buffer for input events. | |
91 static IDirectFBEventBuffer *buffer = NULL; | |
92 | |
93 /* | |
94 * filled during config | |
95 */ | |
96 | |
97 // handle of used layer | |
98 static IDirectFBDisplayLayer *layer = NULL; | |
99 // surface of used layer | |
100 static IDirectFBSurface *primary = NULL; | |
101 static int primarylocked = 0; | |
102 // handle of temporary surface (if used) | |
103 static IDirectFBSurface *frame = NULL; | |
104 static int framelocked = 0; | |
105 // flipping mode flag (layer/surface) | |
106 static int flipping = 0; | |
107 // scaling flag | |
108 static int stretch = 0; | |
109 // pictrure position | |
110 static int xoffset=0,yoffset=0; | |
111 // picture size | |
112 static int out_width=0,out_height=0; | |
113 // frame/primary size | |
114 static int width=0,height=0; | |
115 // frame primary format | |
116 DFBSurfacePixelFormat pixel_format; | |
117 /* | |
118 static void (*draw_alpha_p)(int w, int h, unsigned char *src, | |
119 unsigned char *srca, int stride, unsigned char *dst, | |
120 int dstride); | |
121 */ | |
122 | |
123 /****************************** | |
124 * cmd line parameteres * | |
125 ******************************/ | |
126 | |
127 /* command line/config file options */ | |
128 #ifdef HAVE_FBDEV | |
129 extern char *fb_dev_name; | |
130 #else | |
131 char *fb_dev_name; | |
132 #endif | |
133 | |
134 /****************************** | |
135 * implementation * | |
136 ******************************/ | |
137 | |
138 void unlock() { | |
139 if (frame && framelocked) frame->Unlock(frame); | |
140 if (primary && primarylocked) primary->Unlock(primary); | |
141 } | |
142 | |
143 | |
144 static uint32_t preinit(const char *arg) | |
145 { | |
146 | |
147 DFBResult ret; | |
148 | |
149 if (verbose) printf("DirectFB: Preinit entered\n"); | |
150 | |
151 DFBCHECK (DirectFBInit (NULL,NULL)); | |
152 | |
153 if (((directfb_major_version <= 0) && | |
154 (directfb_minor_version <= 9) && | |
155 (directfb_micro_version < 13))) | |
156 { | |
157 printf("DirectFB: Unsupported DirectFB version\n"); | |
158 return 1; | |
159 } | |
160 | |
161 /* | |
162 * (set options) | |
163 */ | |
164 | |
165 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) fb_dev_name = "/dev/fb0"; | |
166 DFBCHECK (DirectFBSetOption ("fbdev",fb_dev_name)); | |
167 | |
168 // uncomment this if you do not wish to create a new vt for DirectFB | |
169 // DFBCHECK (DirectFBSetOption ("no-vt-switch","")); | |
170 | |
171 // uncomment this if you want to allow vt switching | |
172 // DFBCHECK (DirectFBSetOption ("vt-switching","")); | |
173 | |
174 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9) | |
175 DFBCHECK (DirectFBSetOption ("no-cursor","")); | |
176 | |
177 // bg color fix | |
178 DFBCHECK (DirectFBSetOption ("bg-color","00000000")); | |
179 | |
180 /* | |
181 * (Initialize) | |
182 */ | |
183 | |
184 DFBCHECK (DirectFBCreate (&dfb)); | |
185 DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN)); | |
186 | |
187 /* | |
188 * (Get keyboard) | |
189 */ | |
190 | |
191 ret = dfb->GetInputDevice (dfb, DIDID_KEYBOARD, &keyboard); | |
192 | |
193 if (ret==DFB_OK) { | |
194 if (verbose) { | |
195 printf("DirectFB: Keyboard init OK\n"); | |
196 } | |
197 } else { | |
198 keyboard = NULL; | |
199 printf("DirectFB: Keyboard init FAILED\n"); | |
200 } | |
201 | |
202 /* | |
203 * Create an input buffer for the keyboard. | |
204 */ | |
205 if (keyboard) DFBCHECK (keyboard->CreateEventBuffer (keyboard, &buffer)); | |
206 | |
207 // just to start with clean ... | |
208 if (buffer) buffer->Reset(buffer); | |
209 | |
210 if (verbose) { | |
211 printf("DirectFB: Preinit OK\n"); | |
212 } | |
213 | |
214 return 0; | |
215 | |
216 } | |
217 | |
218 DFBSurfacePixelFormat convformat(uint32_t format) | |
219 { | |
220 // add more formats !!! | |
221 switch (format) { | |
222 case IMGFMT_RGB32: return DSPF_RGB32; break; | |
223 case IMGFMT_BGR32: return DSPF_RGB32; break; | |
224 case IMGFMT_RGB24: return DSPF_RGB24; break; | |
225 case IMGFMT_BGR24: return DSPF_RGB24; break; | |
226 case IMGFMT_RGB16: return DSPF_RGB16; break; | |
227 case IMGFMT_BGR16: return DSPF_RGB16; break; | |
228 case IMGFMT_RGB15: return DSPF_RGB15; break; | |
229 case IMGFMT_BGR15: return DSPF_RGB15; break; | |
230 case IMGFMT_YUY2: return DSPF_YUY2; break; | |
231 case IMGFMT_UYVY: return DSPF_UYVY; break; | |
232 case IMGFMT_YV12: return DSPF_YV12; break; | |
233 case IMGFMT_I420: return DSPF_I420; break; | |
234 // case IMGFMT_IYUV: return DSPF_IYUV; break; | |
235 default: return 0; | |
236 } | |
237 return 0; | |
238 } | |
239 | |
240 typedef struct enum1_s { | |
241 uint32_t format; | |
242 int scale; | |
243 int result; | |
244 unsigned int id; | |
245 unsigned int width; | |
246 unsigned int height; | |
247 int setsize; | |
248 } enum1_t; | |
249 | |
250 DFBEnumerationResult test_format_callback( unsigned int id, | |
251 DFBDisplayLayerDescription desc, | |
252 void *data) | |
253 { | |
254 enum1_t *params =(enum1_t *)data; | |
255 IDirectFBDisplayLayer *layer; | |
256 DFBResult ret; | |
257 | |
258 ret = dfb->GetDisplayLayer( dfb, id, &layer); | |
259 if (ret) { | |
260 DirectFBError( "dfb->GetDisplayLayer failed", ret ); | |
261 return DFENUM_OK; | |
262 } else { | |
263 DFBDisplayLayerConfig dlc; | |
264 | |
265 if (params->setsize) { | |
266 dlc.flags = DLCONF_WIDTH |DLCONF_HEIGHT; | |
267 dlc.width = params->width; | |
268 dlc.height = params->height; | |
269 layer->SetConfiguration(layer,&dlc); | |
270 } | |
271 | |
272 | |
273 dlc.flags = DLCONF_PIXELFORMAT; | |
274 dlc.pixelformat = convformat(params->format); | |
275 | |
276 layer->SetOpacity(layer,0); | |
277 ret = layer->TestConfiguration(layer,&dlc,NULL); | |
278 | |
279 layer->Release(layer); | |
280 | |
281 if (verbose) printf("DirectFB: Test format - layer %i scale/pos %i\n",id,(desc.caps & DLCAPS_SCREEN_LOCATION)); | |
282 | |
283 if (!ret) { | |
284 // printf("Test OK\n"); | |
285 if (params->result) { | |
286 if ((!params->scale) && (desc.caps & DLCAPS_SCREEN_LOCATION)) { | |
287 params->scale=1; | |
288 params->id=id; | |
289 if (verbose) printf("DirectFB: Test format - added layer %i scale/pos %i\n",id,(desc.caps & DLCAPS_SCREEN_LOCATION)); | |
290 | |
291 } | |
292 } else { | |
293 params->result=1; | |
294 params->id=id; | |
295 if (desc.caps & DLCAPS_SCREEN_LOCATION) params->scale=1; | |
296 if (verbose) printf("DirectFB: Test format - added layer %i scale/pos %i\n",id,(desc.caps & DLCAPS_SCREEN_LOCATION)); | |
297 }; | |
298 }; | |
299 }; | |
300 | |
301 return DFENUM_OK; | |
302 } | |
303 | |
304 static uint32_t query_format(uint32_t format) | |
305 { | |
306 int ret = VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD; // osd should be removed in future -> will be handled outside... | |
307 enum1_t params; | |
308 | |
309 | |
310 if (!convformat(format)) return 0; | |
311 // temporary disable YV12 | |
312 // if (format == IMGFMT_YV12) return 0; | |
313 // if (format == IMGFMT_I420) return 0; | |
314 if (format == IMGFMT_IYUV) return 0; | |
315 | |
316 if (verbose) printf("DirectFB: Format query: %s\n",vo_format_name(format)); | |
317 | |
318 params.format=format; | |
319 params.scale=0; | |
320 params.result=0; | |
321 params.setsize=0; | |
322 | |
323 DFBCHECK (dfb->EnumDisplayLayers(dfb,test_format_callback,¶ms)); | |
324 | |
325 if (params.result) { | |
326 if (params.scale) ret |=VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN; | |
327 return ret; | |
328 } | |
329 | |
330 return 0; | |
331 } | |
332 | |
333 typedef struct videomode_s { | |
334 int width; | |
335 int height; | |
336 int out_width; | |
337 int out_height; | |
338 int overx; | |
339 int overy; | |
340 int bpp; | |
341 } videomode_t; | |
342 | |
343 | |
344 DFBEnumerationResult video_modes_callback( unsigned int width,unsigned int height,unsigned int bpp, void *data) | |
345 { | |
346 videomode_t *params =(videomode_t *)data; | |
347 | |
348 int overx=0,overy=0,closer=0,over=0; | |
349 int we_are_under=0; | |
350 | |
351 if (verbose) printf("DirectFB: Validator entered %i %i %i\n",width,height,bpp); | |
352 | |
353 overx=width-params->out_width; | |
354 overy=height-params->out_height; | |
355 | |
356 if (!params->width) { | |
357 params->width=width; | |
358 params->height=height; | |
359 params->overx=overx; | |
360 params->overy=overy; | |
361 if (verbose) printf("DirectFB: Mode added %i %i %i\n",width,height,bpp); | |
362 } | |
363 | |
364 if ((params->overy<0)||(params->overx<0)) we_are_under=1; // stored mode is smaller than req mode | |
365 if (abs(overx*overy)<abs(params->overx * params->overy)) closer=1; // current mode is closer to desired res | |
366 if ((overx>=0)&&(overy>=0)) over=1; // current mode is bigger or equaul to desired res | |
367 if ((closer && (over || we_are_under)) || (we_are_under && over)) { | |
368 params->width=width; | |
369 params->height=height; | |
370 params->overx=overx; | |
371 params->overy=overy; | |
372 if (verbose) printf("DirectFB: Better mode added %i %i %i\n",width,height,bpp); | |
373 }; | |
374 | |
375 return DFENUM_OK; | |
376 } | |
377 | |
378 #define CONFIG_ERROR -1 | |
379 | |
380 static uint32_t config(uint32_t s_width, uint32_t s_height, uint32_t d_width, | |
381 uint32_t d_height, uint32_t fullscreen, char *title, | |
7272 | 382 uint32_t format) |
6952 | 383 { |
384 /* | |
385 * (Locals) | |
386 */ | |
387 | |
388 // decode flags | |
389 | |
390 int fs = fullscreen & 0x01; | |
391 int vm = fullscreen & 0x02; | |
392 int zoom = fullscreen & 0x04; | |
393 int flip = fullscreen & 0x08; | |
394 | |
395 DFBSurfaceDescription dsc; | |
396 DFBResult ret; | |
397 DFBDisplayLayerConfig dlc; | |
398 DFBSurfaceCapabilities caps; | |
399 | |
400 enum1_t params; | |
401 | |
402 if (verbose) { | |
403 printf("DirectFB: Config entered [%ix%i]\n",s_width,s_height); | |
404 printf("DirectFB: With requested format: %s\n",vo_format_name(format)); | |
405 } | |
406 // initial clean-up | |
407 if (frame) { | |
408 frame->Release(frame); | |
409 frame=NULL; | |
410 } | |
411 | |
412 if (primary) { | |
413 primary->Release(primary); | |
414 primary=NULL; | |
415 } | |
416 | |
417 if (layer) { | |
418 layer->Release(layer); | |
419 layer=NULL; | |
420 } | |
421 | |
422 | |
423 // vm things | |
424 | |
425 if (vm) { | |
426 videomode_t params; | |
427 params.out_width=d_width; | |
428 params.out_height=d_height; | |
429 params.width=0; | |
430 params.height=0; | |
431 switch (format) { | |
432 case IMGFMT_RGB32: | |
433 case IMGFMT_BGR32: | |
434 params.bpp=32; | |
435 break; | |
436 case IMGFMT_RGB24: | |
437 case IMGFMT_BGR24: | |
438 params.bpp=24; | |
439 break; | |
440 case IMGFMT_RGB16: | |
441 case IMGFMT_BGR16: | |
442 case IMGFMT_RGB15: | |
443 case IMGFMT_BGR15: | |
444 params.bpp=16; | |
445 break; | |
446 default: params.bpp=0; | |
447 | |
448 } | |
449 if (verbose) printf("DirectFB: Config - videomode change\n"); | |
450 DFBCHECK (dfb->EnumVideoModes(dfb,video_modes_callback,¶ms)); | |
451 ret=dfb->SetVideoMode(dfb,params.width,params.height,params.bpp); | |
452 if (ret) { | |
453 ret=dfb->SetVideoMode(dfb,params.width,params.height,24); | |
454 if (ret) { | |
455 ret=dfb->SetVideoMode(dfb,params.width,params.height,32); | |
456 if (ret) { | |
457 ret=dfb->SetVideoMode(dfb,params.width,params.height,16); | |
458 if (ret) { | |
459 ret=dfb->SetVideoMode(dfb,params.width,params.height,8); | |
460 } | |
461 } | |
462 } | |
463 } | |
464 } // vm end | |
465 | |
466 // find best layer | |
467 | |
468 if (verbose) printf("DirectFB: Config - find suitable layer\n"); | |
469 params.format=format; | |
470 params.scale=0; | |
471 params.result=0; | |
472 params.width=s_width; | |
473 params.height=s_height; | |
474 params.setsize=1; | |
475 | |
476 DFBCHECK (dfb->EnumDisplayLayers(dfb,test_format_callback,¶ms)); | |
477 | |
478 if (!params.result) { | |
479 printf("DirectFB: ConfigError - no suitable layer found\n"); | |
480 params.id = DLID_PRIMARY; | |
481 } | |
6985
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
482 /* Uncomment following if you want to use tvout on CRTC2 (requieres patch for DirectFB from Ville Syrjala) |
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
483 params.id=2; |
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
484 params.scale=0; |
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
485 params.result=1; |
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
486 */ |
6952 | 487 if (verbose) printf("DirectFB: Config - layer %i\n",params.id); |
488 | |
489 | |
490 // try to setp-up proper configuration | |
491 | |
492 | |
493 DFBCHECK (dfb->GetDisplayLayer( dfb, params.id, &layer)); | |
494 | |
495 if (params.scale) { | |
496 if (verbose) printf("DirectFB: Config - set layer config (size)\n"); | |
497 dlc.flags = DLCONF_WIDTH | DLCONF_HEIGHT; | |
498 dlc.width = s_width; | |
499 dlc.height = s_height; | |
500 | |
501 ret = layer->SetConfiguration(layer,&dlc); | |
502 | |
503 if (ret && (params.scale || verbose)) printf("DirectFB: ConfigError in layer configuration (size)\n"); | |
504 | |
505 } | |
506 | |
507 dlc.flags = DLCONF_PIXELFORMAT; | |
508 dlc.pixelformat = convformat(params.format); | |
509 | |
510 // printf("DirectFB: Format [%x]\n",dlc.pixelformat); | |
511 | |
512 if (verbose) printf("DirectFB: Config - set layer config (format)\n"); | |
513 ret = layer->SetConfiguration(layer,&dlc); | |
514 | |
515 if (ret) { | |
516 printf("DirectFB: ConfigError in layer configuration (format)\n"); | |
517 return CONFIG_ERROR; | |
518 }; | |
519 | |
520 | |
521 // flipping of layer | |
522 | |
523 dlc.flags = DLCONF_BUFFERMODE; | |
524 dlc.buffermode = DLBM_BACKVIDEO; | |
525 ret = layer->SetConfiguration( layer, &dlc ); | |
526 if (ret!=DFB_OK) { | |
527 dlc.buffermode = DLBM_BACKSYSTEM; | |
528 ret = layer->SetConfiguration( layer, &dlc ); | |
529 } | |
530 | |
531 // get layer surface | |
532 | |
533 ret = layer->GetSurface(layer,&primary); | |
534 | |
535 if (ret) { | |
536 printf("DirectFB: ConfigError in obtaining surface\n"); | |
537 return CONFIG_ERROR; // what shall we report on fail? | |
538 } | |
539 | |
540 // test surface for flipping | |
541 DFBCHECK(primary->GetCapabilities(primary,&caps)); | |
7272 | 542 // primary->Clear(primary,0,0,0,0); |
6952 | 543 flipping = 0; |
544 if (caps & DSCAPS_FLIPPING) { | |
545 ret = primary->Flip(primary,NULL,0); | |
546 if (ret==DFB_OK) { | |
7272 | 547 // primary->Clear(primary,0,0,0,0); |
6952 | 548 flipping = 1; |
549 } | |
550 }; | |
551 | |
552 if (verbose) printf("DirectFB: Config - flipping = %i\n",flipping); | |
553 | |
554 // is scale needed ? Aspect ratio and layer pos/size | |
555 | |
556 | |
557 // get surface size | |
558 DFBCHECK(primary->GetSize(primary,&width,&height)); | |
559 | |
560 if (verbose) printf("DirectFB: Config - surface size = %ix%i\n",width,height); | |
561 | |
562 aspect_save_orig(s_width,s_height); | |
563 aspect_save_prescale(d_width,d_height); | |
564 if (params.scale) { | |
565 aspect_save_screenres(10000,10000); | |
566 aspect(&out_width,&out_height,A_ZOOM); | |
567 | |
568 ret = layer->SetScreenLocation(layer,(1-(float)out_width/10000)/2,(1-(float)out_height/10000)/2,((float)out_width/10000),((float)out_height/10000)); | |
569 | |
570 if (ret) printf("DirectFB: ConfigError in layer configuration (position)\n"); | |
571 | |
572 xoffset = 0; | |
573 yoffset = 0; | |
574 | |
575 } else { | |
576 | |
577 aspect_save_screenres(width,height); | |
578 | |
579 if(fs) /* -fs */ | |
580 aspect(&out_width,&out_height,A_ZOOM); | |
581 else | |
582 aspect(&out_width,&out_height,A_NOZOOM); | |
583 | |
584 | |
585 xoffset = (width - out_width) / 2; | |
586 yoffset = (height - out_height) / 2; | |
587 } | |
588 | |
589 if (((s_width==out_width)&&(s_height==out_height)) || (params.scale)) { | |
590 stretch = 0; | |
591 } else { | |
592 stretch = 1; | |
593 } | |
594 | |
595 | |
596 // temporary buffer in case of not flipping or scaling | |
597 if ((!flipping) || stretch) { | |
598 | |
599 DFBCHECK (primary->GetPixelFormat (primary, &dsc.pixelformat)); | |
600 | |
601 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH; | |
602 | |
603 dsc.width = s_width; | |
604 dsc.height = s_height; | |
605 | |
606 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &frame)); | |
607 DFBCHECK(frame->GetSize(frame,&width,&height)); | |
6985
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
608 if (verbose) printf("DirectFB: Frame is active.\n"); |
6952 | 609 } |
610 | |
611 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver | |
612 if (frame) { | |
613 DFBCHECK (frame->GetPixelFormat(frame,&pixel_format)); | |
614 } else { | |
615 DFBCHECK (primary->GetPixelFormat(primary,&pixel_format)); | |
616 }; | |
617 | |
618 // finally turn on layer | |
619 layer->SetOpacity(layer,255); | |
620 | |
621 if (verbose) printf("DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height); | |
622 | |
623 return 0; | |
624 } | |
625 | |
626 static const vo_info_t *get_info(void) | |
627 { | |
628 return &vo_info; | |
629 } | |
630 | |
631 extern void mplayer_put_key(int code); | |
632 | |
633 #include "../linux/keycodes.h" | |
634 | |
635 static void check_events(void) | |
636 { | |
637 | |
638 if (buffer) { | |
639 | |
640 DFBInputEvent event; | |
641 | |
642 //if (verbose) printf ("DirectFB: Check events entered\n"); | |
643 if (buffer->GetEvent(buffer, DFB_EVENT (&event)) == DFB_OK) { | |
644 | |
645 if (event.type == DIET_KEYPRESS) { | |
646 switch (event.key_symbol) { | |
647 case DIKS_ESCAPE: | |
648 mplayer_put_key('q'); | |
649 break; | |
650 case DIKS_PAGE_UP: mplayer_put_key(KEY_PAGE_UP);break; | |
651 case DIKS_PAGE_DOWN: mplayer_put_key(KEY_PAGE_DOWN);break; | |
652 case DIKS_CURSOR_UP: mplayer_put_key(KEY_UP);break; | |
653 case DIKS_CURSOR_DOWN: mplayer_put_key(KEY_DOWN);break; | |
654 case DIKS_CURSOR_LEFT: mplayer_put_key(KEY_LEFT);break; | |
655 case DIKS_CURSOR_RIGHT: mplayer_put_key(KEY_RIGHT);break; | |
656 case DIKS_INSERT: mplayer_put_key(KEY_INSERT);break; | |
657 case DIKS_DELETE: mplayer_put_key(KEY_DELETE);break; | |
658 case DIKS_HOME: mplayer_put_key(KEY_HOME);break; | |
659 case DIKS_END: mplayer_put_key(KEY_END);break; | |
660 | |
661 default:mplayer_put_key(event.key_symbol); | |
662 }; | |
663 }; | |
664 }; | |
665 // empty buffer, because of repeating (keyboard repeat is faster than key handling | |
666 // and this causes problems during seek) | |
667 // temporary workabout should be solved in the future | |
668 buffer->Reset(buffer); | |
669 | |
670 } | |
671 //if (verbose) printf ("DirectFB: Check events finished\n"); | |
672 } | |
673 | |
674 static void flip_page(void) | |
675 { | |
676 DFBSurfaceBlittingFlags flags=DSBLIT_NOFX; | |
677 | |
678 unlock(); // unlock frame & primary | |
679 | |
680 // if (verbose) printf("DirectFB: Flip page entered"); | |
681 | |
682 DFBCHECK (primary->SetBlittingFlags(primary,flags)); | |
683 | |
684 if (frame) { | |
685 if (stretch) { | |
686 DFBRectangle rect; | |
687 rect.x=xoffset; | |
688 rect.y=yoffset; | |
689 rect.w=out_width; | |
690 rect.h=out_height; | |
691 | |
692 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect)); | |
693 | |
694 } else { | |
695 | |
696 DFBCHECK (primary->Blit(primary,frame,NULL,xoffset,yoffset)); | |
697 | |
698 }; | |
699 }; | |
700 | |
701 | |
702 if (flipping) { | |
703 DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC)); | |
704 } | |
705 | |
706 } | |
707 | |
708 | |
709 | |
710 static void uninit(void) | |
711 { | |
712 | |
713 if (verbose ) printf("DirectFB: Uninit entered\n"); | |
714 | |
715 unlock(); | |
716 | |
717 /* | |
718 * (Release) | |
719 */ | |
720 if (verbose ) printf("DirectFB: Release buffer\n"); | |
721 if (buffer) buffer->Release (buffer); | |
722 if (verbose ) printf("DirectFB: Release keyboard\n"); | |
723 if (keyboard) keyboard->Release (keyboard); | |
724 if (frame) { | |
725 if (verbose ) printf("DirectFB: Release frame\n"); | |
726 frame->Release (frame); | |
727 }; | |
728 | |
729 if (verbose ) printf("DirectFB: Release primary\n"); | |
730 if (primary) primary->Release (primary); | |
731 | |
732 // switch off BES | |
733 // if (layer) layer->SetOpacity(layer,0); | |
734 | |
735 if (layer) layer->Release(layer); | |
736 | |
737 if (verbose ) printf("DirectFB: Release DirectFB library\n"); | |
738 | |
739 dfb->Release (dfb); | |
740 | |
741 if (verbose ) printf("DirectFB: Uninit done.\n"); | |
742 } | |
743 | |
744 | |
745 static uint32_t directfb_set_video_eq(char *data, int value) //data==name | |
746 { | |
747 | |
748 DFBColorAdjustment ca; | |
749 float factor = (float)0xffff / 200.0; | |
750 | |
751 DFBDisplayLayerDescription desc; | |
752 | |
753 unlock(); | |
754 | |
755 if (layer) { | |
756 | |
757 layer->GetDescription(layer,&desc); | |
758 | |
759 ca.flags=DCAF_NONE; | |
760 | |
761 if (! strcmp( data,"brightness" )) { | |
762 if (desc.caps & DLCAPS_BRIGHTNESS) { | |
763 ca.brightness = value * factor +0x8000; | |
764 ca.flags |= DCAF_BRIGHTNESS; | |
765 if (verbose) printf("DirectFB: SetVEq Brightness 0x%X %i\n",ca.brightness,value); | |
766 } else return VO_FALSE; | |
767 } | |
768 | |
769 if (! strcmp( data,"contrast" )) { | |
770 if ((desc.caps & DLCAPS_CONTRAST)) { | |
771 ca.contrast = value * factor + 0x8000; | |
772 ca.flags |= DCAF_CONTRAST; | |
773 if (verbose) printf("DirectFB: SetVEq Contrast 0x%X %i\n",ca.contrast,value); | |
774 } else return VO_FALSE; | |
775 } | |
776 | |
777 if (! strcmp( data,"hue" )) { | |
778 if ((desc.caps & DLCAPS_HUE)) { | |
779 ca.hue = value * factor + 0x8000; | |
780 ca.flags |= DCAF_HUE; | |
781 if (verbose) printf("DirectFB: SetVEq Hue 0x%X %i\n",ca.hue,value); | |
782 } else return VO_FALSE; | |
783 } | |
784 | |
785 if (! strcmp( data,"saturation" )) { | |
786 if ((desc.caps & DLCAPS_SATURATION)) { | |
787 ca.saturation = value * factor + 0x8000; | |
788 ca.flags |= DCAF_SATURATION; | |
789 if (verbose) printf("DirectFB: SetVEq Saturation 0x%X %i\n",ca.saturation,value); | |
790 } else return VO_FALSE; | |
791 } | |
792 | |
793 if (ca.flags != DCAF_NONE) { | |
794 layer->SetColorAdjustment(layer,&ca); | |
795 return VO_TRUE; | |
796 } | |
797 } | |
798 | |
799 return VO_FALSE; | |
800 | |
801 } | |
802 | |
803 static uint32_t directfb_get_video_eq(char *data, int *value) // data==name | |
804 { | |
805 | |
806 DFBColorAdjustment ca; | |
807 float factor = 200.0 / (float)0xffff; | |
808 | |
809 DFBDisplayLayerDescription desc; | |
810 | |
811 if (layer) { | |
812 | |
813 unlock(); | |
814 | |
815 layer->GetDescription(layer,&desc); | |
816 | |
817 layer->GetColorAdjustment(layer,&ca); | |
818 | |
819 if (! strcmp( data,"brightness" )) { | |
820 if (desc.caps & DLCAPS_BRIGHTNESS) { | |
821 *value = (int) ((ca.brightness-0x8000) * factor); | |
822 if (verbose) printf("DirectFB: GetVEq Brightness 0x%X %i\n",ca.brightness,*value); | |
823 return VO_TRUE; | |
824 } else return VO_FALSE; | |
825 } | |
826 | |
827 if (! strcmp( data,"contrast" )) { | |
828 if ((desc.caps & DLCAPS_CONTRAST)) { | |
829 *value = (int) ((ca.contrast-0x8000) * factor); | |
830 if (verbose) printf("DirectFB: GetVEq Contrast 0x%X %i\n",ca.contrast,*value); | |
831 return VO_TRUE; | |
832 } else return VO_FALSE; | |
833 } | |
834 | |
835 if (! strcmp( data,"hue" )) { | |
836 if ((desc.caps & DLCAPS_HUE)) { | |
837 *value = (int) ((ca.hue-0x8000) * factor); | |
838 if (verbose) printf("DirectFB: GetVEq Hue 0x%X %i\n",ca.hue,*value); | |
839 return VO_TRUE; | |
840 } else return VO_FALSE; | |
841 } | |
842 | |
843 if (! strcmp( data,"saturation" )) { | |
844 if ((desc.caps & DLCAPS_SATURATION)) { | |
845 *value = (int) ((ca.saturation-0x8000) * factor); | |
846 if (verbose) printf("DirectFB: GetVEq Saturation 0x%X %i\n",ca.saturation,*value); | |
847 return VO_TRUE; | |
848 } else return VO_FALSE; | |
849 } | |
850 } | |
851 return VO_FALSE; | |
852 } | |
853 | |
854 static uint32_t get_image(mp_image_t *mpi) | |
855 { | |
856 | |
857 int err; | |
858 void *dst; | |
859 int pitch; | |
860 | |
861 // if (verbose) printf("DirectFB: get_image() called\n"); | |
862 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram | |
863 if(mpi->type==MP_IMGTYPE_STATIC) return VO_FALSE; // it is not static | |
864 | |
865 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags); | |
866 | |
6985
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
867 if((mpi->width==pitch) || |
6952 | 868 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ |
869 // we're lucky or codec accepts stride => ok, let's go! | |
870 | |
871 if (frame) { | |
872 err = frame->Lock(frame,DSLF_WRITE,&dst,&pitch); | |
873 framelocked=1; | |
874 } else { | |
875 err = primary->Lock(primary,DSLF_WRITE,&dst,&pitch); | |
876 primarylocked=1; | |
877 } | |
878 | |
879 if (err) { | |
880 if (verbose) printf("DirectFB: DR lock failed!"); | |
881 return VO_FALSE; | |
882 }; | |
883 | |
884 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
885 //YV12 format | |
886 mpi->planes[0]=dst; | |
887 if(mpi->flags&MP_IMGFLAG_SWAPPED){ | |
888 mpi->planes[1]=dst + pitch*height; | |
889 mpi->planes[2]=mpi->planes[1] + pitch*height/4; | |
890 } else { | |
891 mpi->planes[2]=dst + pitch*height; | |
892 mpi->planes[1]=mpi->planes[2] + pitch*height/4; | |
893 } | |
6985
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
894 mpi->width=width; |
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
895 mpi->stride[0]=pitch; |
6952 | 896 mpi->stride[1]=mpi->stride[2]=pitch/2; |
897 } else { | |
898 //YUY2 and RGB formats | |
899 mpi->planes[0]=dst; | |
900 mpi->width=width; | |
901 mpi->stride[0]=pitch; | |
902 } | |
903 mpi->flags|=MP_IMGFLAG_DIRECT; | |
904 // if (verbose) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n"); | |
905 return VO_TRUE; | |
906 | |
907 } | |
908 return VO_FALSE; | |
909 } | |
910 | |
911 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) | |
912 { | |
913 int i; | |
914 unsigned int pitch; | |
915 void *dst; | |
916 void *dst2; | |
917 void *srcp; | |
918 unsigned int p; | |
919 | |
920 unlock(); | |
921 | |
922 if (frame) { | |
923 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); | |
924 framelocked = 1; | |
925 } else { | |
926 DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); | |
927 primarylocked = 1; | |
928 }; | |
929 | |
930 p=min(w,pitch); | |
931 | |
932 dst += y*pitch + x; | |
933 dst2 = dst + pitch*height - y*pitch + y*pitch/4 - x/2; | |
934 srcp = src[0]; | |
935 | |
936 for (i=0;i<h;i++) { | |
937 memcpy(dst,srcp,p); | |
938 dst += pitch; | |
939 srcp += stride[0]; | |
940 } | |
941 | |
942 if (pixel_format == DSPF_YV12) { | |
943 | |
944 dst = dst2; | |
945 srcp = src[2]; | |
946 p = p/2; | |
947 | |
948 for (i=0;i<h/2;i++) { | |
949 memcpy(dst,srcp,p); | |
950 dst += pitch/2; | |
951 srcp += stride[2]; | |
952 } | |
953 | |
954 dst = dst2 + pitch*height/4; | |
955 srcp = src[1]; | |
956 | |
957 for (i=0;i<h/2;i++) { | |
958 memcpy(dst,srcp,p); | |
959 dst += pitch/2; | |
960 srcp += stride[1]; | |
961 } | |
962 | |
963 } else { | |
964 | |
965 dst = dst2; | |
966 srcp = src[1]; | |
967 p = p/2; | |
968 | |
969 for (i=0;i<h/2;i++) { | |
970 memcpy(dst,srcp,p); | |
971 dst += pitch/2; | |
972 srcp += stride[1]; | |
973 } | |
974 | |
975 dst = dst2 + pitch*height/4; | |
976 srcp = src[2]; | |
977 | |
978 for (i=0;i<h/2;i++) { | |
979 memcpy(dst,srcp,p); | |
980 dst += pitch/2; | |
981 srcp += stride[2]; | |
982 } | |
983 | |
984 } | |
985 | |
986 unlock(); | |
987 | |
988 return 0; | |
989 } | |
990 | |
991 | |
992 static uint32_t put_image(mp_image_t *mpi){ | |
993 | |
994 | |
995 static IDirectFBSurface *tmp = NULL; | |
996 DFBSurfaceDescription dsc; | |
997 DFBRectangle rect; | |
998 | |
999 // if (verbose) printf("DirectFB: Put_image entered %i %i %i %i %i %i\n",mpi->x,mpi->y,mpi->w,mpi->h,mpi->width,mpi->height); | |
1000 | |
1001 unlock(); | |
1002 | |
1003 // already out? | |
6985
6074119e09a0
Put/get_image fixed. Deleted forgotten development comments
zdar
parents:
6952
diff
changeset
|
1004 if((mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))) { |
6952 | 1005 // if (verbose) printf("DirectFB: Put_image - nothing todo\n"); |
1006 return VO_TRUE; | |
1007 } | |
1008 | |
1009 if (mpi->flags&MP_IMGFLAG_PLANAR) { | |
1010 // memcpy all planes - sad but necessary | |
1011 int i; | |
1012 unsigned int pitch; | |
1013 void *dst; | |
1014 void *src; | |
1015 unsigned int p; | |
1016 | |
1017 // if (verbose) printf("DirectFB: Put_image - planar branch\n"); | |
1018 if (frame) { | |
1019 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); | |
1020 framelocked = 1; | |
1021 } else { | |
1022 DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); | |
1023 primarylocked = 1; | |
1024 }; | |
1025 | |
1026 p=min(mpi->w,pitch); | |
1027 | |
1028 src = mpi->planes[0]+mpi->y*mpi->stride[0]+mpi->x; | |
1029 | |
1030 for (i=0;i<mpi->h;i++) { | |
1031 memcpy(dst+i*pitch,src+i*mpi->stride[0],p); | |
1032 } | |
1033 | |
1034 if (pixel_format == DSPF_YV12) { | |
1035 | |
1036 dst += pitch*height; | |
1037 p = p/2; | |
1038 src = mpi->planes[2]+mpi->y*mpi->stride[2]+mpi->x/2; | |
1039 | |
1040 for (i=0;i<mpi->h/2;i++) { | |
1041 memcpy(dst+i*pitch/2,src+i*mpi->stride[2],p); | |
1042 } | |
1043 | |
1044 dst += pitch*height/4; | |
1045 src = mpi->planes[1]+mpi->y*mpi->stride[1]+mpi->x/2; | |
1046 | |
1047 for (i=0;i<mpi->h/2;i++) { | |
1048 memcpy(dst+i*pitch/2,src+i*mpi->stride[1],p); | |
1049 } | |
1050 | |
1051 } else { | |
1052 | |
1053 dst += pitch*height; | |
1054 p = p/2; | |
1055 src = mpi->planes[1]+mpi->y*mpi->stride[1]+mpi->x/2; | |
1056 | |
1057 for (i=0;i<mpi->h/2;i++) { | |
1058 memcpy(dst+i*pitch/2,src+i*mpi->stride[1],p); | |
1059 } | |
1060 | |
1061 dst += pitch*height/4; | |
1062 src = mpi->planes[2]+mpi->y*mpi->stride[2]+mpi->x/2; | |
1063 | |
1064 for (i=0;i<mpi->h/2;i++) { | |
1065 memcpy(dst+i*pitch/2,src+i*mpi->stride[2],p); | |
1066 } | |
1067 | |
1068 } | |
1069 unlock(); | |
1070 | |
1071 } else { | |
1072 | |
1073 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED; | |
1074 dsc.preallocated[0].data = mpi->planes[0]; | |
1075 dsc.preallocated[0].pitch = mpi->stride[0]; | |
1076 dsc.width = mpi->width; | |
1077 dsc.height = mpi->height; | |
1078 dsc.pixelformat = convformat(mpi->imgfmt); | |
1079 | |
1080 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp)); | |
1081 | |
1082 rect.x=mpi->x; | |
1083 rect.y=mpi->y; | |
1084 rect.w=mpi->w; | |
1085 rect.h=mpi->h; | |
1086 | |
1087 if (frame) { | |
1088 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0)); | |
1089 } else { | |
1090 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset)); | |
1091 }; | |
1092 tmp->Release(tmp); | |
1093 } | |
1094 return VO_TRUE; | |
1095 } | |
1096 | |
1097 | |
1098 | |
1099 static uint32_t control(uint32_t request, void *data, ...) | |
1100 { | |
1101 switch (request) { | |
1102 case VOCTRL_QUERY_FORMAT: | |
1103 return query_format(*((uint32_t*)data)); | |
1104 case VOCTRL_GET_IMAGE: | |
1105 return get_image(data); | |
1106 case VOCTRL_DRAW_IMAGE: | |
1107 return put_image(data); | |
1108 case VOCTRL_SET_EQUALIZER: | |
1109 { | |
1110 va_list ap; | |
1111 int value; | |
1112 | |
1113 va_start(ap, data); | |
1114 value = va_arg(ap, int); | |
1115 va_end(ap); | |
1116 | |
1117 return(directfb_set_video_eq(data, value)); | |
1118 } | |
1119 case VOCTRL_GET_EQUALIZER: | |
1120 { | |
1121 va_list ap; | |
1122 int *value; | |
1123 | |
1124 va_start(ap, data); | |
1125 value = va_arg(ap, int*); | |
1126 va_end(ap); | |
1127 | |
1128 return(directfb_get_video_eq(data, value)); | |
1129 } | |
1130 }; | |
1131 return VO_NOTIMPL; | |
1132 } | |
1133 | |
1134 // unused function | |
1135 | |
1136 static uint32_t draw_frame(uint8_t *src[]) | |
1137 { | |
1138 return -1; | |
1139 } | |
1140 | |
1141 // hopefully will be removed soon | |
1142 | |
1143 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, | |
1144 unsigned char *srca, int stride) | |
1145 { | |
1146 void *dst; | |
1147 int pitch; | |
1148 | |
1149 unlock(); // isnt it silly I have to unlock surface and than lock again :-) | |
1150 | |
1151 if (frame) { | |
1152 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); | |
1153 framelocked = 1; | |
1154 } else { | |
1155 DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch)); | |
1156 primarylocked = 1; | |
1157 }; | |
1158 | |
1159 switch(pixel_format) { | |
1160 case DSPF_RGB32: | |
1161 case DSPF_ARGB: | |
1162 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 4*x0,pitch); | |
1163 break; | |
1164 | |
1165 case DSPF_RGB24: | |
1166 vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 3*x0,pitch); | |
1167 break; | |
1168 | |
1169 case DSPF_RGB16: | |
1170 vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 2*x0,pitch); | |
1171 break; | |
1172 | |
1173 case DSPF_RGB15: | |
1174 vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 2*x0,pitch); | |
1175 break; | |
1176 | |
1177 case DSPF_YUY2: | |
1178 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 2*x0,pitch); | |
1179 break; | |
1180 | |
1181 case DSPF_UYVY: | |
1182 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 2*x0 + 1,pitch); | |
1183 break; | |
1184 | |
1185 case DSPF_I420: | |
1186 case DSPF_YV12: | |
1187 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 1*x0,pitch); | |
1188 break; | |
1189 } | |
1190 | |
1191 unlock(); | |
1192 } | |
1193 | |
1194 static void draw_osd(void) | |
1195 { | |
1196 vo_draw_text(width,height,draw_alpha); | |
1197 } |