comparison libvo/vo_directfb.c @ 5189:c663455448e8

updates by Jiri.Svoboda@seznam.cz
author arpi
date Mon, 18 Mar 2002 23:20:13 +0000
parents 693b917ac916
children c9ccddcbdd81
comparison
equal deleted inserted replaced
5188:d127ec93d5d1 5189:c663455448e8
56 #include "video_out.h" 56 #include "video_out.h"
57 #include "video_out_internal.h" 57 #include "video_out_internal.h"
58 #include "fastmemcpy.h" 58 #include "fastmemcpy.h"
59 #include "sub.h" 59 #include "sub.h"
60 #include "../postproc/rgb2rgb.h" 60 #include "../postproc/rgb2rgb.h"
61 #include "aspect.h"
62 #include "../mp_image.h"
61 63
62 LIBVO_EXTERN(directfb) 64 LIBVO_EXTERN(directfb)
63 65
64 static vo_info_t vo_info = { 66 static vo_info_t vo_info = {
65 "Direct Framebuffer Device", 67 "Direct Framebuffer Device",
80 static IDirectFB *dfb = NULL; 82 static IDirectFB *dfb = NULL;
81 static IDirectFBSurface *primary = NULL; 83 static IDirectFBSurface *primary = NULL;
82 static IDirectFBInputDevice *keyboard = NULL; 84 static IDirectFBInputDevice *keyboard = NULL;
83 static IDirectFBDisplayLayer *videolayer = NULL; 85 static IDirectFBDisplayLayer *videolayer = NULL;
84 static DFBDisplayLayerConfig dlc; 86 static DFBDisplayLayerConfig dlc;
85 static int screen_width = 0; 87 static unsigned int screen_width = 0;
86 static int screen_height = 0; 88 static unsigned int screen_height = 0;
87 static DFBSurfacePixelFormat frame_format; 89 static DFBSurfacePixelFormat frame_format;
88 static unsigned int frame_pixel_size = 0; 90 static unsigned int frame_pixel_size = 0;
89 static unsigned int source_pixel_size = 0; 91 static unsigned int source_pixel_size = 0;
90 static int xoffset=0,yoffset=0; 92 static int xoffset=0,yoffset=0;
91 #define DFBCHECK(x...) \ 93 #define DFBCHECK(x...) \
124 extern char *fb_dev_name; 126 extern char *fb_dev_name;
125 #else 127 #else
126 char *fb_dev_name; 128 char *fb_dev_name;
127 #endif 129 #endif
128 130
131 static int preinitdone=0;
132
129 static void (*draw_alpha_p)(int w, int h, unsigned char *src, 133 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
130 unsigned char *srca, int stride, unsigned char *dst, 134 unsigned char *srca, int stride, unsigned char *dst,
131 int dstride); 135 int dstride);
132 136
133 static int in_width; 137 static uint32_t in_width;
134 static int in_height; 138 static uint32_t in_height;
135 static int out_width; 139 static uint32_t out_width=1;
136 static int out_height; 140 static uint32_t out_height=1;
137 static uint32_t pixel_format; 141 static uint32_t pixel_format;
138 static int fs; 142 static int fs;
139 static int flip; 143 static int flip;
140 static int stretch=0; 144 static int stretch=0;
141 struct modes_t { 145 struct modes_t {
143 unsigned int width; 147 unsigned int width;
144 unsigned int height; 148 unsigned int height;
145 int overx,overy; 149 int overx,overy;
146 } modes [4]; 150 } modes [4];
147 static unsigned int best_bpp=5; 151 static unsigned int best_bpp=5;
148 static unsigned int preinit_done=0; 152 // videolayer stuff
149 static int no_yuy2=1; 153 static int videolayeractive=0;
150 static int no_uyvy_support=1; 154 //some info about videolayer - filled on preinit
155 struct vlayer_t {
156 int iv12;
157 int i420;
158 int yuy2;
159 int uyvy;
160 int brightness;
161 int saturation;
162 int contrast;
163 int hue;
164 } videolayercaps;
165 // workabout for DirectFB bug
166 static int buggyYV12BitBlt=0;
167 static int memcpyBitBlt=0;
168 #define DIRECTRENDER
169 #ifdef DIRECTRENDER
170 static int dr_enabled=0;
171 static int framelocked=0;
172 #endif
151 173
152 174
153 DFBEnumerationResult enum_modes_callback( unsigned int width,unsigned int height,unsigned int bpp, void *data) 175 DFBEnumerationResult enum_modes_callback( unsigned int width,unsigned int height,unsigned int bpp, void *data)
154 { 176 {
155 int overx=0,overy=0; 177 int overx=0,overy=0;
156 unsigned int index=bpp/8-1; 178 unsigned int index=bpp/8-1;
157 int allow_under=0; 179 int allow_under=0;
158 180
159 //printf("Validator entered %i %i %i\n",width,height,bpp); 181 if (verbose) printf("DirectFB: Validator entered %i %i %i\n",width,height,bpp);
160 182
161 overx=width-out_width; 183 overx=width-out_width;
162 overy=height-out_height; 184 overy=height-out_height;
163 if (!modes[index].valid) { 185 if (!modes[index].valid) {
164 modes[index].valid=1; 186 modes[index].valid=1;
173 modes[index].valid=1; 195 modes[index].valid=1;
174 modes[index].width=width; 196 modes[index].width=width;
175 modes[index].height=height; 197 modes[index].height=height;
176 modes[index].overx=overx; 198 modes[index].overx=overx;
177 modes[index].overy=overy; 199 modes[index].overy=overy;
178 // printf("Better mode added %i %i %i\n",width,height,bpp); 200 if (verbose) printf("DirectFB:Better mode added %i %i %i\n",width,height,bpp);
179 }; 201 };
180 }; 202 };
181 203
182 return DFENUM_OK; 204 return DFENUM_OK;
183 } 205 }
186 DFBEnumerationResult enum_layers_callback( unsigned int id, 208 DFBEnumerationResult enum_layers_callback( unsigned int id,
187 DFBDisplayLayerCapabilities caps, 209 DFBDisplayLayerCapabilities caps,
188 void *data ) 210 void *data )
189 { 211 {
190 IDirectFBDisplayLayer **layer = (IDirectFBDisplayLayer **)data; 212 IDirectFBDisplayLayer **layer = (IDirectFBDisplayLayer **)data;
191 /* 213 if (verbose) {
192 printf( "\nLayer %d:\n", id ); 214 printf("\nDirectFB: Layer %d:\n", id );
193 215
194 if (caps & DLCAPS_SURFACE) 216 if (caps & DLCAPS_SURFACE)
195 printf( " - Has a surface.\n" ); 217 printf( " - Has a surface.\n" );
196 218
197 if (caps & DLCAPS_ALPHACHANNEL) 219 if (caps & DLCAPS_ALPHACHANNEL)
223 245
224 if (caps & DLCAPS_SATURATION) 246 if (caps & DLCAPS_SATURATION)
225 printf( " - Saturation can be adjusted.\n" ); 247 printf( " - Saturation can be adjusted.\n" );
226 248
227 printf("\n"); 249 printf("\n");
228 */ 250 }
229 /* We take the first layer not being the primary */ 251 /* We take the first layer not being the primary */
230 if (id != DLID_PRIMARY) { 252 if (id != DLID_PRIMARY) {
231 DFBResult ret; 253 DFBResult ret;
232 254
233 ret = dfb->GetDisplayLayer( dfb, id, layer ); 255 ret = dfb->GetDisplayLayer( dfb, id, layer );
244 { 266 {
245 DFBSurfaceDescription dsc; 267 DFBSurfaceDescription dsc;
246 DFBResult ret; 268 DFBResult ret;
247 DFBDisplayLayerConfigFlags failed; 269 DFBDisplayLayerConfigFlags failed;
248 270
249
250 if (preinit_done) return 1;
251
252 /* 271 /*
253 * (Initialize) 272 * (Initialize)
254 */ 273 */
255 274
256 // if (!dfb) { 275 if (verbose) printf("DirectFB: Preinit entered\n");
276
277 if (preinitdone) return 0;
257 278
258 DFBCHECK (DirectFBInit (NULL,NULL)); 279 DFBCHECK (DirectFBInit (NULL,NULL));
259
260 if ((directfb_major_version >= 0) &&
261 (directfb_minor_version >= 9) &&
262 (directfb_micro_version >= 7))
263 no_uyvy_support = 0;
264 else
265 {
266 no_uyvy_support = 1;
267 printf("vo_directfb: no UYVY support. Version: %d.%d.%d\n",
268 directfb_major_version, directfb_minor_version,
269 directfb_micro_version);
270 }
271 280
272 if ((directfb_major_version >= 0) && 281 if ((directfb_major_version >= 0) &&
273 (directfb_minor_version >= 9) && 282 (directfb_minor_version >= 9) &&
274 (directfb_micro_version >= 7)) 283 (directfb_micro_version >= 7))
275 { 284 {
276 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) fb_dev_name = "/dev/fb0"; 285 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) fb_dev_name = "/dev/fb0";
277 DFBCHECK (DirectFBSetOption ("fbdev",fb_dev_name)); 286 DFBCHECK (DirectFBSetOption ("fbdev",fb_dev_name));
278 } 287 }
279 288
289 // disable YV12 for dfb 0.9.9 - there is a bug in dfb!
290 if ((directfb_major_version <= 0) &&
291 (directfb_minor_version <= 9) &&
292 (directfb_micro_version <= 9)) {
293 buggyYV12BitBlt=1;
294 if (verbose) printf("DirectFB: Buggy YV12BitBlt!\n");
295 }
296
280 // uncomment this if you do not wish to create a new vt for DirectFB 297 // uncomment this if you do not wish to create a new vt for DirectFB
281 // DFBCHECK (DirectFBSetOption ("no-vt-switch",fb_dev_name)); 298 DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
282 299
283 // uncomment this if you want to allow vt switching 300 // uncomment this if you want to allow vt switching
284 // DFBCHECK (DirectFBSetOption ("vt-switching",fb_dev_name)); 301 DFBCHECK (DirectFBSetOption ("vt-switching",""));
302 #ifdef HAVE_DIRECTFB099
303 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
304 DFBCHECK (DirectFBSetOption ("no-cursor",""));
305 #endif
306
285 DFBCHECK (DirectFBSetOption ("bg-color","00000000")); 307 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
286 308
287 DFBCHECK (DirectFBCreate (&dfb)); 309 DFBCHECK (DirectFBCreate (&dfb));
288 DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN)); 310 DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
289 311
291 313
292 /* Enumerate display layers */ 314 /* Enumerate display layers */
293 DFBCHECK (dfb->EnumDisplayLayers( dfb, enum_layers_callback, &videolayer )); 315 DFBCHECK (dfb->EnumDisplayLayers( dfb, enum_layers_callback, &videolayer ));
294 316
295 if (!videolayer) { 317 if (!videolayer) {
296 // no yuy2 layer -> fallback to RGB 318 if (verbose) printf("DirectFB: No videolayer found\n");
319 // no videolayer found
297 // printf( "\nNo additional layers have been found.\n" ); 320 // printf( "\nNo additional layers have been found.\n" );
298 no_yuy2 = 1; 321 videolayeractive=0;
299 // preinit_done = 1; 322
300 } else { 323 } else {
301 324
302 // there is an additional layer so test it for YUV 325 // there is an additional layer so test it for YUV formats
303 dlc.flags = /*DLCONF_WIDTH | DLCONF_HEIGHT | */DLCONF_PIXELFORMAT; //| DLCONF_OPTIONS; 326 // some videolayers support RGB formats - not used now
304 /* dlc.width = dsc.width; 327 if (verbose) printf("DirectFB: Testing videolayer caps\n");
305 dlc.height = dsc.height;*/ 328
306 dlc.pixelformat = DSPF_YUY2; 329 dlc.flags = DLCONF_PIXELFORMAT;
307 // dlc.options = DLOP_INTERLACED_VIDEO; 330 #ifdef HAVE_DIRECTFB099
308 331 dlc.pixelformat = DSPF_YV12;
309 /* Test the configuration, getting failed fields */
310 ret = videolayer->TestConfiguration( videolayer, &dlc, &failed ); 332 ret = videolayer->TestConfiguration( videolayer, &dlc, &failed );
311 if (ret == DFB_UNSUPPORTED && no_uyvy_support == 0) { 333 if (ret==DFB_OK) {
312 // printf("Videolayer does not support YUY2"); 334 videolayercaps.iv12=1;
313 dlc.pixelformat = DSPF_UYVY; 335 if (verbose) printf("DirectFB: Videolayer supports YV12 format\n");
314 ret = videolayer->TestConfiguration( videolayer, &dlc, &failed ); 336 } else {
315 if (ret != DFB_UNSUPPORTED) { no_yuy2 = 0;} 337 videolayercaps.iv12=0;
316 } else { no_yuy2 = 0;} 338 if (verbose) printf("DirectFB: Videolayer doesn't support YV12 format\n");
339 };
340
341 dlc.pixelformat = DSPF_I420;
342 ret = videolayer->TestConfiguration( videolayer, &dlc, &failed );
343 if (ret==DFB_OK) {
344 videolayercaps.i420=1;
345 if (verbose) printf("DirectFB: Videolayer supports I420 format\n");
346 } else {
347 videolayercaps.i420=0;
348 if (verbose) printf("DirectFB: Videolayer doesn't support I420 format\n");
349 };
350 #else
351 videolayercaps.yuy2=0;
352 #endif
353
354 dlc.pixelformat = DSPF_YUY2;
355 ret = videolayer->TestConfiguration( videolayer, &dlc, &failed );
356 if (ret==DFB_OK) {
357 videolayercaps.yuy2=1;
358 if (verbose) printf("DirectFB: Videolayer supports YUY2 format\n");
359 } else {
360 videolayercaps.yuy2=0;
361 if (verbose) printf("DirectFB: Videolayer doesn't support YUY2 format\n");
362 };
363
364 dlc.pixelformat = DSPF_UYVY;
365 ret = videolayer->TestConfiguration( videolayer, &dlc, &failed );
366 if (ret==DFB_OK) {
367 videolayercaps.uyvy=1;
368 if (verbose) printf("DirectFB: Videolayer supports UYVY format\n");
369 } else {
370 videolayercaps.uyvy=0;
371 if (verbose) printf("DirectFB: Videolayer doesn't support UYVY format\n");
372 };
373
374 // test for color caps
375 {
376 DFBDisplayLayerCapabilities caps;
377 videolayer->GetCapabilities(videolayer,&caps);
378 if (caps & DLCAPS_BRIGHTNESS) {
379 videolayercaps.brightness=1;
380 } else {
381 videolayercaps.brightness=0;
382 };
383
384 if (caps & DLCAPS_CONTRAST) {
385 videolayercaps.contrast=1;
386 } else {
387 videolayercaps.contrast=0;
388 };
389
390 if (caps & DLCAPS_HUE) {
391 videolayercaps.hue=1;
392 } else {
393 videolayercaps.hue=0;
394 };
395
396 if (caps & DLCAPS_SATURATION) {
397 videolayercaps.saturation=1;
398 } else {
399 videolayercaps.saturation=0;
400 };
401
402
403 }
404
405
406 // is there a working yuv ? if no we will not use videolayer
407 if ((videolayercaps.iv12==0)&&(videolayercaps.i420==0)&&(videolayercaps.yuy2==0)&&(videolayercaps.uyvy==0)) {
408 // videolayer doesn't work with yuv so release it
409 videolayeractive=0;
410 videolayer->SetOpacity(videolayer,0);
411 videolayer->Release(videolayer);
412 } else {
413 videolayeractive=1;
414 };
317 } 415 }
318 416
319 417 // just look at RGB things for main layer
320 // just look at RGB things
321 modes[0].valid=0; 418 modes[0].valid=0;
322 modes[1].valid=0; 419 modes[1].valid=0;
323 modes[2].valid=0; 420 modes[2].valid=0;
324 modes[3].valid=0; 421 modes[3].valid=0;
325 DFBCHECK (dfb->EnumVideoModes(dfb,enum_modes_callback,NULL)); 422 DFBCHECK (dfb->EnumVideoModes(dfb,enum_modes_callback,NULL));
326 // printf("No YUY2 %i\n",no_yuy2); 423 preinitdone=1;
327 // }
328 preinit_done=1;
329 return 0; 424 return 0;
330 425
331 } 426 }
332 427
333 428
343 438
344 439
345 int vm = fullscreen & 0x02; 440 int vm = fullscreen & 0x02;
346 int zoom = fullscreen & 0x04; 441 int zoom = fullscreen & 0x04;
347 442
443 if (verbose) printf("DirectFB: Config entered [%ix%i]\n",width,height);
444
348 fs = fullscreen & 0x01; 445 fs = fullscreen & 0x01;
349 flip = fullscreen & 0x08; 446 flip = fullscreen & 0x08;
350 447
351 pixel_format=format; 448 pixel_format=format;
352 449
355 452
356 if (d_width) { 453 if (d_width) {
357 out_width = d_width; 454 out_width = d_width;
358 out_height = d_height; 455 out_height = d_height;
359 } else { 456 } else {
360 d_width = out_width = width; 457 d_width = out_width = in_width;
361 d_height = out_height = height; 458 d_height = out_height = in_height;
362 } 459 }
363 460
364 461 // just look at RGB things for main layer - once again - now we now desired screen size
365 // if (!preinit(NULL)) return 1; 462 modes[0].valid=0;
463 modes[1].valid=0;
464 modes[2].valid=0;
465 modes[3].valid=0;
466 DFBCHECK (dfb->EnumVideoModes(dfb,enum_modes_callback,NULL));
366 467
367 468
368 if (vm) { 469 if (vm) {
369 // need better algorithm just hack 470 // need better algorithm just hack
370 if (modes[source_pixel_size-1].valid) dfb->SetVideoMode(dfb,modes[source_pixel_size-1].width,modes[source_pixel_size-1].height,source_pixel_size); 471 if (modes[source_pixel_size-1].valid) dfb->SetVideoMode(dfb,modes[source_pixel_size-1].width,modes[source_pixel_size-1].height,source_pixel_size);
371 } 472 }
372 473
373 474
374 if (!no_yuy2) { 475 if (videolayeractive) {
476 videolayeractive=0; // will be enabled on succes later
477
375 // try to set proper w a h values matching image size 478 // try to set proper w a h values matching image size
376 dlc.flags = DLCONF_WIDTH | DLCONF_HEIGHT;// | DLCONF_OPTIONS; 479 dlc.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
377 dlc.width = in_width; 480 dlc.width = in_width;
378 dlc.height = in_height; 481 dlc.height = in_height;
379 482
380 ret = videolayer->SetConfiguration( videolayer, &dlc ); 483 ret = videolayer->SetConfiguration( videolayer, &dlc );
381 484
382 /* if (ret) { 485 if (ret) {
383 printf("Set layer size failed\n"); 486 if (verbose) printf("DirectFB: Set layer size failed\n");
384 }; 487 };
488
489 // try to set correct pixel format (closest to required)
490
491 dlc.flags = DLCONF_PIXELFORMAT;
492 dlc.pixelformat = 0;
493 switch (pixel_format) {
494 case IMGFMT_YV12:
495 #ifdef HAVE_DIRECTFB099
496 if (videolayercaps.i420==1) {
497 dlc.pixelformat=DSPF_I420;
498 break;
499 } else if (videolayercaps.iv12==1) {
500 dlc.pixelformat=DSPF_YV12;
501 break;
502 };
503
504 #endif
505 case IMGFMT_YUY2: if (videolayercaps.yuy2==1) {
506 dlc.pixelformat=DSPF_YUY2;
507 break;
508 // temporary disabled - do not have conv tool to uyvy
509 /* } else if (videolayercaps.uyvy==1) {
510 dlc.pixelformat=DSPF_UYVY;
511 break;
385 */ 512 */
386 dlc.flags = DLCONF_PIXELFORMAT;// | DLCONF_OPTIONS; 513 #ifdef HAVE_DIRECTFB099
387 //dlc.pixelformat = DSPF_YUY2; should be set by preinit 514 } else if (videolayercaps.i420==1) {
388 //dlc.options = (vcaps & DVCAPS_INTERLACED) ? DLOP_INTERLACED_VIDEO : 0; 515 dlc.pixelformat=DSPF_I420;
389 no_yuy2=1; 516 break;
390 /* switch (dlc.pixelformat) { 517 } else if (videolayercaps.iv12==1) {
391 case DSPF_ARGB: printf("Directfb frame format ARGB\n"); 518 dlc.pixelformat=DSPF_YV12;
392 frame_pixel_size = 4; 519 break;
393 break; 520 #endif
394 case DSPF_RGB32: printf("Directfb frame format RGB32\n"); 521 };
395 frame_pixel_size = 4; 522 // shouldn't happen - if it reaches here -> bug
396 break; 523 dsc.pixelformat = DSPF_RGB24; break;
397 case DSPF_RGB24: printf("Directfb frame format RGB24\n"); 524
398 frame_pixel_size = 3; 525 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; break;
399 break; 526 case IMGFMT_BGR32: dsc.pixelformat = DSPF_ARGB; break;
400 case DSPF_RGB16: printf("Directfb frame format RGB16\n"); 527 case IMGFMT_RGB24: dsc.pixelformat = DSPF_RGB24; break;
401 frame_pixel_size = 2; 528 case IMGFMT_BGR24: dsc.pixelformat = DSPF_RGB24; break;
402 break; 529 case IMGFMT_RGB16: dsc.pixelformat = DSPF_RGB16; break;
403 case DSPF_RGB15: printf("Directfb frame format RGB15\n"); 530 case IMGFMT_BGR16: dsc.pixelformat = DSPF_RGB16; break;
404 frame_pixel_size = 2; 531 case IMGFMT_RGB15: dsc.pixelformat = DSPF_RGB15; break;
405 break; 532 case IMGFMT_BGR15: dsc.pixelformat = DSPF_RGB15; break;
406 case DSPF_YUY2: printf("Directfb frame format YUY2\n"); 533 default: dsc.pixelformat = DSPF_RGB24; break;
407 frame_pixel_size = 2; 534 }
408 break; 535
409 case DSPF_UYVY: printf("Directfb frame format UYVY\n"); 536 if (verbose) switch (dlc.pixelformat) {
410 frame_pixel_size = 2; 537 case DSPF_ARGB: printf("DirectFB: layer format ARGB\n");
411 break; 538 break;
412 default: printf("Directfb - unknown format ->exit\n"); return 1; 539 case DSPF_RGB32: printf("DirectFB: layer format RGB32\n");
540 break;
541 case DSPF_RGB24: printf("DirectFB: layer format RGB24\n");
542 break;
543 case DSPF_RGB16: printf("DirectFB: layer format RGB16\n");
544 break;
545 case DSPF_RGB15: printf("DirectFB: layer format RGB15\n");
546 break;
547 case DSPF_YUY2: printf("DirectFB: layer format YUY2\n");
548 break;
549 case DSPF_UYVY: printf("DirectFB: layer format UYVY\n");
550 break;
551 #ifdef HAVE_DIRECTFB099
552 case DSPF_YV12: printf("DirectFB: layer format YV12\n");
553 break;
554 case DSPF_I420: printf("DirectFB: layer format I420\n");
555 break;
556 #endif
557 default: printf("DirectFB: - unknown format ->exit\n"); return 1;
413 } 558 }
414 */ ret =videolayer->SetConfiguration( videolayer, &dlc ); 559
560 ret =videolayer->SetConfiguration( videolayer, &dlc );
415 if (!ret) { 561 if (!ret) {
416 // printf("SetConfiguration for layer OK\n"); 562 if (verbose) printf("DirectFB: SetConfiguration for layer OK\n");
417 ret = videolayer->GetSurface( videolayer, &primary ); 563 ret = videolayer->GetSurface( videolayer, &primary );
418 if (!ret){ 564 if (!ret){
419 no_yuy2=0; 565 videolayeractive=1;
420 // printf("Get surface for layer OK\n"); 566 if (verbose) printf("DirectFB: Get surface for layer OK\n");
421 /* dsc.width=in_width;
422 dsc.height=in_height;
423 dsc.flags = DSDESC_CAPS | DSDESC_HEIGHT | DSDESC_WIDTH;
424 dsc.caps = DSCAPS_VIDEOONLY;//| DSCAPS_FLIPPING;
425 primary->SetConfiguration(priamry,&dsc);*/
426 }; 567 };
427 }; 568 };
428 569
429 } 570 }
430 571
431 // mam pro flip pouzit tenhle flip nebo bitblt 572 // for flipping we will use BitBlt not integrated directfb flip
432 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; 573 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
433 dsc.caps = DSCAPS_PRIMARY | DSCAPS_VIDEOONLY;//| DSCAPS_FLIPPING; 574 dsc.caps = DSCAPS_PRIMARY | DSCAPS_VIDEOONLY;//| DSCAPS_FLIPPING;
434 575
435 switch (format) { 576 switch (format) {
436 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; source_pixel_size= 4; break; 577 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; source_pixel_size= 4; break;
442 case IMGFMT_RGB15: dsc.pixelformat = DSPF_RGB15; source_pixel_size= 2; break; 583 case IMGFMT_RGB15: dsc.pixelformat = DSPF_RGB15; source_pixel_size= 2; break;
443 case IMGFMT_BGR15: dsc.pixelformat = DSPF_RGB15; source_pixel_size= 2; break; 584 case IMGFMT_BGR15: dsc.pixelformat = DSPF_RGB15; source_pixel_size= 2; break;
444 default: dsc.pixelformat = DSPF_RGB24; source_pixel_size=2; break; //YUV formats 585 default: dsc.pixelformat = DSPF_RGB24; source_pixel_size=2; break; //YUV formats
445 }; 586 };
446 587
447 588 if (!videolayeractive) {
448 589 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
449 if (no_yuy2) { 590
450 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary )); 591 }
451 }
452 else {// try to set pos for YUY2 layer and proper aspect ratio
453
454 extern float monitor_aspect;
455
456 float h=(float)out_height,w=(float)out_width/monitor_aspect;
457 float aspect=h/w;
458 // printf("in out d: %d %d, %d %d, %d %d\n",in_width,in_height,out_width,out_height,d_width,d_height);
459 // printf ("Aspect y/x=%f/%f=%f\n",h,w,aspect);
460
461 // if (fs) {
462 // scale fullscreen
463 if (aspect>1) {
464 aspect=w/h;
465 ret = videolayer->SetScreenLocation(videolayer,(1-aspect)/2,0,aspect,1);
466 } else {
467 ret = videolayer->SetScreenLocation(videolayer,0,(1-aspect)/2,1,aspect);
468 }
469 // } else {
470 // beacase I can't get real screen size values I can't scale properly in other way then fullscreen
471 // };
472 // if (ret) printf("SetScreenLocation failed\n");
473 }
474 592
475 DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height)); 593 DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
476 594
477 DFBCHECK (primary->GetPixelFormat (primary, &frame_format)); 595 DFBCHECK (primary->GetPixelFormat (primary, &frame_format));
478 596
479 // temporary buffer buffer 597 // temporary buffer buffer
480 dsc.flags = DSDESC_CAPS | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH; 598 dsc.flags = DSDESC_CAPS | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH;
481 dsc.caps = DSCAPS_SYSTEMONLY;
482 599
483 dsc.width = in_width; 600 dsc.width = in_width;
484 dsc.height = in_height; 601 dsc.height = in_height;
485 602
486 // at this time use pixel req format or format of main disp 603 // at this time use pixel req format or format of main disp
487 /*
488 switch (frame_format) {
489 case DSPF_ARGB: printf("Directfb frame format ARGB\n");
490 break;
491 case DSPF_RGB32: printf("Directfb frame format RGB32\n");
492 break;
493 case DSPF_RGB24: printf("Directfb frame format RGB24\n");
494 break;
495 case DSPF_RGB16: printf("Directfb frame format RGB16\n");
496 break;
497 case DSPF_RGB15: printf("Directfb frame format RGB15\n");
498 break;
499 case DSPF_YUY2: printf("Directfb frame format YUY2\n");
500 break;
501 default: printf("Directfb - unknown format ->exit\n"); return 1;
502 }
503 */
504 604
505 switch (format) { 605 switch (format) {
506 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; break; 606 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; break;
507 case IMGFMT_BGR32: dsc.pixelformat = DSPF_ARGB; break; 607 case IMGFMT_BGR32: dsc.pixelformat = DSPF_ARGB; break;
508 case IMGFMT_RGB24: dsc.pixelformat = DSPF_RGB24; break; 608 case IMGFMT_RGB24: dsc.pixelformat = DSPF_RGB24; break;
516 616
517 617
518 /* 618 /*
519 * Create a surface based on the description of the source frame 619 * Create a surface based on the description of the source frame
520 */ 620 */
521 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &frame)); 621 #ifdef HAVE_DIRECTFB099
522 622 if (((dsc.pixelformat==DSPF_YV12)||(dsc.pixelformat==DSPF_I420)) && buggyYV12BitBlt) {
623 memcpyBitBlt = 1;
624 } else {
625 memcpyBitBlt = 0;
626 };
627 #else
628 memcpyBitBlt = 0;
629 #endif
630
631 // prevent from memcpy from videomemory to videomemory
632 /* if (memcpyBitBlt) {
633 dsc.caps = DSCAPS_SYSTEMONLY;
634 } else {
635 dsc.caps = DSCAPS_VIDEOONLY;
636 }
637 ret = dfb->CreateSurface( dfb, &dsc, &frame);
638 if (ret) {
639 if (verbose) printf ("DirectFB: Trying do create buffer in system memory (2)\n");*/
640 dsc.caps = DSCAPS_SYSTEMONLY;
641 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &frame));
642 // }
643
523 DFBCHECK (frame->GetPixelFormat (frame, &frame_format)); 644 DFBCHECK (frame->GetPixelFormat (frame, &frame_format));
524 645
525 switch (frame_format) { 646 switch (frame_format) {
526 case DSPF_ARGB: //printf("Directfb frame format ARGB\n"); 647 case DSPF_ARGB: if (verbose) printf("DirectFB: frame format ARGB\n");
527 frame_pixel_size = 4; 648 frame_pixel_size = 4;
528 break; 649 break;
529 case DSPF_RGB32: //printf("Directfb frame format RGB32\n"); 650 case DSPF_RGB32: if (verbose) printf("DirectFB: frame format RGB32\n");
530 frame_pixel_size = 4; 651 frame_pixel_size = 4;
531 break; 652 break;
532 case DSPF_RGB24: //printf("Directfb frame format RGB24\n"); 653 case DSPF_RGB24: if (verbose) printf("DirectFB: frame format RGB24\n");
533 frame_pixel_size = 3; 654 frame_pixel_size = 3;
534 break; 655 break;
535 case DSPF_RGB16: //printf("Directfb frame format RGB16\n"); 656 case DSPF_RGB16: if (verbose) printf("DirectFB: frame format RGB16\n");
536 frame_pixel_size = 2; 657 frame_pixel_size = 2;
537 break; 658 break;
538 case DSPF_RGB15: //printf("Directfb frame format RGB15\n"); 659 case DSPF_RGB15: if (verbose) printf("DirectFB: frame format RGB15\n");
539 frame_pixel_size = 2; 660 frame_pixel_size = 2;
540 break; 661 break;
541 case DSPF_YUY2: //printf("Directfb frame format YUY2\n"); 662 case DSPF_YUY2: if (verbose) printf("DirectFB: frame format YUY2\n");
542 frame_pixel_size = 2; 663 frame_pixel_size = 2;
543 break; 664 break;
544 case DSPF_UYVY: //printf("Directfb frame format UYVY\n"); 665 case DSPF_UYVY: if (verbose) printf("DirectFB: frame format UYVY\n");
545 frame_pixel_size = 2; 666 frame_pixel_size = 2;
546 break; 667 break;
547 default: printf("Directfb - unknown format ->exit\n"); return 1; 668 #ifdef HAVE_DIRECTFB099
669 case DSPF_YV12: if (verbose) printf("DirectFB: frame format YV12\n");
670 frame_pixel_size = 1;
671 break;
672 case DSPF_I420: if (verbose) printf("DirectFB: frame format I420\n");
673 frame_pixel_size = 1;
674 break;
675 #endif
676 default: printf("DirectFB: - unknown format ->exit\n"); return 1;
548 } 677 }
549 678
550
551 if (zoom) {
552 printf("-zoom is not yet supported\n");
553 // return 1;
554 }
555 /*
556 if (fs) {
557 printf("-fs can degrade image and performance\n");
558 // return 1;
559 }
560 */
561 if ((out_width < in_width || out_height < in_height) && (!fs)) { 679 if ((out_width < in_width || out_height < in_height) && (!fs)) {
562 printf("Screensize is smaller than video size !\n"); 680 printf("Screensize is smaller than video size !\n");
563 // return 1; // doesn't matter we will 681 // return 1; // doesn't matter we will rescale
564 } 682 }
565 683
566 if ((fs) && (no_yuy2)) {
567 // aspect ratio correction for fullscreen
568 out_height=d_height*screen_width/d_width;
569 if (out_height <= screen_height) {out_width=screen_width;} else {out_width=screen_width*screen_height/d_height; out_height=screen_height;};
570 // printf("Going fullscreen !\n");
571 }
572 684
573 685
574 /* 686 /*
575 * (Get keyboard) 687 * (Get keyboard)
576 */ 688 */
578 690
579 /* 691 /*
580 * Create an input buffer for the keyboard. 692 * Create an input buffer for the keyboard.
581 */ 693 */
582 #ifdef HAVE_DIRECTFB099 694 #ifdef HAVE_DIRECTFB099
583 DFBCHECK (keyboard->CreateEventBuffer (DICAPS_ALL, &buffer)); 695 DFBCHECK (keyboard->CreateEventBuffer (keyboard, &buffer));
584 #else 696 #else
585 DFBCHECK (keyboard->CreateInputBuffer (keyboard, &buffer)); 697 DFBCHECK (keyboard->CreateInputBuffer (keyboard, &buffer));
586 #endif 698 #endif
587 699
588 // yuv2rgb transform init 700 // yuv2rgb transform init
589 701
590 if (((format == IMGFMT_YV12) || (format == IMGFMT_YUY2)) && no_yuy2){ yuv2rgb_init(frame_pixel_size * 8,MODE_RGB);}; 702 if (((format == IMGFMT_YV12) || (format == IMGFMT_YUY2)) && (!videolayeractive)){ yuv2rgb_init(frame_pixel_size * 8,MODE_RGB);};
591 703
592 if (((out_width != in_width) || (out_height != in_height)) && (no_yuy2)) {stretch = 1;} else stretch=0; //yuy doesn't like strech and should not be needed 704 // picture size and position
593 705
594 if (no_yuy2) { 706 aspect_save_orig(in_width,in_height);
595 xoffset = (screen_width - out_width) / 2; 707 aspect_save_prescale(d_width,d_height);
596 yoffset = (screen_height - out_height) / 2; 708 if (videolayeractive) {// try to set pos for YUY2 layer and proper aspect ratio
597 } else { 709 aspect_save_screenres(10000,10000);
598 xoffset = 0; 710 aspect(&out_width,&out_height,A_ZOOM);
599 yoffset = 0; 711
600 } 712 ret = videolayer->SetScreenLocation(videolayer,(1-(float)out_width/10000)/2,(1-(float)out_height/10000)/2,((float)out_width/10000),((float)out_height/10000));
601 // printf("in out d: %d %d, %d %d, %d %d\n",in_width,in_height,out_width,out_height,d_width,d_height); 713
714 xoffset = 0;
715 yoffset = 0;
716 } else {
717 // aspect ratio correction for zoom to fullscreen
718 aspect_save_screenres(screen_width,screen_height);
719
720 if(fs) /* -fs */
721 aspect(&out_width,&out_height,A_ZOOM);
722 else
723 aspect(&out_width,&out_height,A_NOZOOM);
724
725
726 xoffset = (screen_width - out_width) / 2;
727 yoffset = (screen_height - out_height) / 2;
728 }
729
730 if (((out_width != in_width) || (out_height != in_height)) && (!videolayeractive)) {stretch = 1;} else stretch=0; //yuy doesn't like strech and should not be needed
731
732 if ((verbose)&&(memcpyBitBlt)) printf("DirectFB: Using memcpyBitBlt\n");
733 #ifdef DIRECTRENDER
734 //direct rendering is enabled in case of sane buffer and im format
735 if ((format==IMGFMT_RGB32)&&(frame_format ==DSPF_ARGB) ||
736 (format==IMGFMT_BGR32)&&(frame_format ==DSPF_ARGB) ||
737 (format==IMGFMT_RGB24)&&(frame_format ==DSPF_RGB24) ||
738 (format==IMGFMT_BGR24)&&(frame_format ==DSPF_RGB24) ||
739 (format==IMGFMT_RGB16)&&(frame_format ==DSPF_RGB16) ||
740 (format==IMGFMT_BGR16)&&(frame_format ==DSPF_RGB16) ||
741 (format==IMGFMT_RGB15)&&(frame_format ==DSPF_RGB15) ||
742 (format==IMGFMT_BGR15)&&(frame_format ==DSPF_RGB15) ||
743 #ifdef HAVE_DIRECTFB099
744 (format==IMGFMT_YUY2)&&(frame_format ==DSPF_YUY2) ||
745 (format==IMGFMT_YV12)&&(frame_format ==DSPF_I420) ||
746 (format==IMGFMT_YV12)&&(frame_format ==DSPF_YV12)){
747 #else
748 (format==IMGFMT_YUY2)&&(frame_format ==DSPF_YUY2)){
749 #endif
750 dr_enabled=1;
751 if (verbose) printf("DirectFB: Direct rendering supported\n");
752 } else {
753 dr_enabled=0;
754 if (verbose) printf("DirectFB: Direct rendering not supported\n");
755 };
756 #endif
757
758
759 if (verbose) printf("DirectFB: Config finished [%ix%i]\n",out_width,out_height);
602 760
603 return 0; 761 return 0;
604 } 762 }
605 763
606 static uint32_t query_format(uint32_t format) 764 static uint32_t query_format(uint32_t format)
607 { 765 {
608 int ret = 0x4; /* osd/sub is supported on every bpp */ 766 int ret = 0x4; /* osd/sub is supported on every bpp */
609 767
610 // preinit(NULL); 768 // preinit(NULL);
611 769
612 // printf("Format query: %s\n",vo_format_name(format)); 770 if (verbose ) printf("DirectFB: Format query: %s\n",vo_format_name(format));
613 switch (format) { 771 switch (format) {
614 772
615 // RGB mode works only if color depth is same as on screen and this driver doesn't know before init 773 // RGB mode works only if color depth is same as on screen and this driver doesn't know before init
616 // so we couldn't report supported formats well 774 // so we couldn't report supported formats well
617 775
625 case IMGFMT_RGB16: 783 case IMGFMT_RGB16:
626 case IMGFMT_BGR16: 784 case IMGFMT_BGR16:
627 case IMGFMT_RGB15: 785 case IMGFMT_RGB15:
628 case IMGFMT_BGR15: if (modes[1].valid) return ret|0x2; 786 case IMGFMT_BGR15: if (modes[1].valid) return ret|0x2;
629 break; 787 break;
630 case IMGFMT_YUY2: if (!no_yuy2) return ret|0x2; 788 case IMGFMT_YUY2: if (videolayeractive) {
789 if (videolayercaps.yuy2) {
790 return ret|0x2;
791 } else {
792 return ret|0x1;
793 };
794 };
631 break; 795 break;
632 case IMGFMT_YV12: if (!no_yuy2) return ret|0x2; else return ret|0x1; 796 case IMGFMT_YV12: if ((videolayeractive) &&
797 (videolayercaps.i420 || videolayercaps.iv12))
798 return ret|0x2; else return ret|0x1;
633 break; 799 break;
634 // YV12 should work in all cases 800 // YV12 should work in all cases
635 } 801 }
636 802
637 return 0; 803 return 0;
647 { 813 {
648 void *dst; 814 void *dst;
649 int pitch; 815 int pitch;
650 int len; 816 int len;
651 817
818 #ifdef DIRECTRENDER
819 if(framelocked) {
820 frame->Unlock(frame);
821 framelocked=0;
822 };
823 #endif
652 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); 824 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch));
653 825
654 switch(frame_format) { 826 switch(frame_format) {
655 case DSPF_RGB32: 827 case DSPF_RGB32:
656 case DSPF_ARGB: 828 case DSPF_ARGB:
674 break; 846 break;
675 847
676 case DSPF_UYVY: 848 case DSPF_UYVY:
677 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + frame_pixel_size*x0 + 1,pitch); 849 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + frame_pixel_size*x0 + 1,pitch);
678 break; 850 break;
851
852 #ifdef HAVE_DIRECTFB099
853 case DSPF_I420:
854 case DSPF_YV12:
855 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + frame_pixel_size*x0,pitch);
856 break;
857 #endif
679 } 858 }
680 DFBCHECK (frame->Unlock(frame)); 859 DFBCHECK (frame->Unlock(frame));
681 } 860 }
682 861
683 static uint32_t draw_frame(uint8_t *src[]) 862 static uint32_t draw_frame(uint8_t *src[])
684 { 863 {
685 void *dst; 864 void *dst;
686 int pitch; 865 int pitch;
687 int len; 866 int len;
688 867
868 // printf("Drawframe\n");
869 #ifdef DIRECTRENDER
870 if(framelocked) {
871 frame->Unlock(frame);
872 framelocked=0;
873 };
874 #endif
875
689 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); 876 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch));
690 877
691 switch (frame_format) { 878 switch (frame_format) {
692 case DSPF_ARGB: 879 case DSPF_ARGB:
693 case DSPF_RGB32: 880 case DSPF_RGB32:
694 case DSPF_RGB24: 881 case DSPF_RGB24:
695 case DSPF_RGB16: 882 case DSPF_RGB16:
696 case DSPF_RGB15:switch (pixel_format) { 883 case DSPF_RGB15: switch (pixel_format) {
697 case IMGFMT_YV12: 884 case IMGFMT_YV12:
698 yuv2rgb(dst,src[0],src[1],src[2],in_width,in_height,pitch,in_width,in_width/2); 885 yuv2rgb(dst,src[0],src[1],src[2],in_width,in_height,pitch,in_width,in_width/2);
699 break; 886 break;
700 /* how to handle this? need conversion from YUY2 to RGB*/ 887 /* how to handle this? need conversion from YUY2 to RGB*/
701 /* case IMGFMT_YUY2: 888 /* case IMGFMT_YUY2:
702 yuv2rgb(dst,src[0],src[0]+1,src[0]+3,1,in_height*in_width/2,frame_pixel_size*2,4,4); //odd pixels 889 yuv2rgb(dst,src[0],src[0]+1,src[0]+3,1,in_height*in_width/2,frame_pixel_size*2,4,4); //odd pixels
703 yuv2rgb(dst+1,src[0]+2,src[0]+1,src[0]+3,1,in_height*in_width/2,frame_pixel_size*2,4,4); //even pixels 890 yuv2rgb(dst+1,src[0]+2,src[0]+1,src[0]+3,1,in_height*in_width/2,frame_pixel_size*2,4,4); //even pixels
704 break;*/ 891 break;*/
705 // RGB - just copy 892 // RGB - just copy
706 default: if (source_pixel_size==frame_pixel_size) {memcpy(dst,src[0],in_width * in_height * frame_pixel_size);}; 893 default: if (source_pixel_size==frame_pixel_size) {
707 894 if (pitch==(in_width*frame_pixel_size)) {
708 } 895 memcpy(dst,src[0],in_width * in_height * source_pixel_size);
709 break; 896 } else {
897 int i;
898 int sp=in_width*source_pixel_size;
899 int ll=min(sp,pitch);
900 for (i=0;i<in_height;i++) {
901 memcpy(dst+i*pitch,src[0]+i*sp,ll);
902 };
903 };
904 };
905 };
906 break;
710 case DSPF_YUY2: 907 case DSPF_YUY2:
711 switch (pixel_format) { 908 switch (pixel_format) {
712 case IMGFMT_YV12: yv12toyuy2(src[0],src[1],src[2],dst,in_width,in_height,in_width,in_width >>1,pitch); 909 case IMGFMT_YV12: yv12toyuy2(src[0],src[1],src[2],dst,in_width,in_height,in_width,in_width >>1,pitch);
713 break; 910 break;
714 case IMGFMT_YUY2: { 911 case IMGFMT_YUY2: if (pitch==(in_width*2)) {
715 int i; 912 memcpy(dst,src[0],in_width * in_height * source_pixel_size);
716 for (i=0;i<in_height;i++) { 913 } else {
914 int i;
915 for (i=0;i<in_height;i++) {
717 memcpy(dst+i*pitch,src[0]+i*in_width*2,in_width*2); 916 memcpy(dst+i*pitch,src[0]+i*in_width*2,in_width*2);
718 } 917 }
719 } 918 }
720 /*len = in_width * in_height * pitch; 919 break;
721 memcpy(dst,src[0],len);*/
722 break;
723 // hopefully there will be no RGB in this case otherwise convert - not implemented 920 // hopefully there will be no RGB in this case otherwise convert - not implemented
724 } 921 };
725 break; 922 break;
923
924 #ifdef HAVE_DIRECTFB099
925 case DSPF_YV12:
926 switch (pixel_format) {
927 case IMGFMT_YV12: {
928 int i;
929 int p=min(in_width,pitch);
930 for (i=0;i<in_height;i++) {
931 memcpy(dst+i*pitch,src[0]+i*in_width,p);
932 }
933 dst += pitch*in_height;
934 p = p/2;
935 for (i=0;i<in_height/2;i++) {
936 memcpy(dst+i*pitch/2,src[2]+i*in_width/2,p);
937 }
938 dst += pitch*in_height/4;
939 for (i=0;i<in_height/2;i++) {
940 memcpy(dst+i*pitch/2,src[1]+i*in_width/2,p);
941 }
942 };
943 break;
944 case IMGFMT_YUY2: yuy2toyv12(src[0],dst,dst+pitch*in_height+pitch*in_height/4,dst+pitch*in_height,in_width,in_height,pitch,pitch/2,pitch/2);
945 break;
946 // hopefully there will be no RGB in this case otherwise convert - not implemented
947 }
948 break;
949 case DSPF_I420:
950 switch (pixel_format) {
951 case IMGFMT_YV12: {
952 int i;
953 int p=min(in_width,pitch);
954 for (i=0;i<in_height;i++) {
955 memcpy(dst+i*pitch,src[0]+i*in_width,p);
956 }
957 dst += pitch*in_height;
958 p = p/2;
959 for (i=0;i<in_height/2;i++) {
960 memcpy(dst+i*pitch/2,src[1]+i*in_width/2,p);
961 }
962 dst += pitch*in_height/4;
963 for (i=0;i<in_height/2;i++) {
964 memcpy(dst+i*pitch/2,src[2]+i*in_width/2,p);
965 }
966 };
967 break;
968 case IMGFMT_YUY2: yuy2toyv12(src[0],dst,dst+pitch*in_height,dst+pitch*in_height+pitch*in_height/4,in_width,in_height,pitch,pitch/2,pitch/2);
969 break;
970 // hopefully there will be no RGB in this case otherwise convert - not implemented
971 }
972 break;
973 #endif
726 } 974 }
727 DFBCHECK (frame->Unlock(frame)); 975 DFBCHECK (frame->Unlock(frame));
728 return 0; 976 return 0;
729 } 977 }
730 978
735 void *dst; 983 void *dst;
736 uint8_t *s; 984 uint8_t *s;
737 int pitch; 985 int pitch;
738 int i; 986 int i;
739 987
988 #ifdef DIRECTRENDER
989 if(framelocked) {
990 frame->Unlock(frame);
991 framelocked=0;
992 };
993 #endif
994
740 err = frame->Lock(frame,DSLF_WRITE,&dst,&pitch); 995 err = frame->Lock(frame,DSLF_WRITE,&dst,&pitch);
741 996 // err = primary->Lock(primary,DSLF_WRITE,&dst,&pitch); // for direct rendering
742 // printf("Drawslice\n"); 997
743 998 // printf("Drawslice w=%i h=%i x=%i y=%i pitch=%i\n",w,h,x,y,pitch);
999
1000 if (err) {
1001 printf("DirectFB: Frame lock failed!");
1002 return 1;
1003 };
744 switch (frame_format) { 1004 switch (frame_format) {
745 case DSPF_ARGB: 1005 case DSPF_ARGB:
746 case DSPF_RGB32: 1006 case DSPF_RGB32:
747 case DSPF_RGB24: 1007 case DSPF_RGB24:
748 case DSPF_RGB16: 1008 case DSPF_RGB16:
749 case DSPF_RGB15: 1009 case DSPF_RGB15:
750 switch (pixel_format) { 1010 switch (pixel_format) {
751 case IMGFMT_YV12: 1011 case IMGFMT_YV12:
752 yuv2rgb(dst+ y * pitch + frame_pixel_size*x ,src[0],src[1],src[2],w,h,pitch,stride[0],stride[1]); 1012 yuv2rgb(dst+ y * pitch + frame_pixel_size*x ,src[0],src[1],src[2],w,h,pitch,stride[0],stride[1]);
753 break; 1013 break;
754 // how to handle this? need conversion
755 /* case IMGFMT_YUY2: {
756 int i;
757 for (i=0;i<=h;i++) {
758 yuv2rgb(dst+ (i+y) * pitch + frame_pixel_size*x,src[0]+i*stride[0],src[0]+1+i*stride[0],src[0]+3+i*stride[0],1,(w+1)/2,frame_pixel_size*2,4,4); //odd pixels
759 yuv2rgb(dst+ (i+y) * pitch + frame_pixel_size*x +1,src[0]+i*stride[0]+2,src[0]+1+i*stride[0],src[0]+3+i*stride[0],1,(w)/2,frame_pixel_size*2,4,4); //odd pixels
760 };
761 };
762 break;
763 */
764 default: if (source_pixel_size==frame_pixel_size) { 1014 default: if (source_pixel_size==frame_pixel_size) {
765 dst += x * frame_pixel_size; 1015 dst += x * frame_pixel_size;
766 s = src[0]; 1016 s = src[0];
767 for (i=y;i<=(y+h);i++) { 1017 for (i=y;i<(y+h);i++) {
768 memcpy(dst,s,w); 1018 memcpy(dst,s,w);
769 dst += (pitch); 1019 dst += (pitch);
770 s += stride[0]; 1020 s += stride[0];
771 }; 1021 };
772 } 1022 }
776 break; 1026 break;
777 case DSPF_YUY2: 1027 case DSPF_YUY2:
778 switch (pixel_format) { 1028 switch (pixel_format) {
779 case IMGFMT_YV12: yv12toyuy2(src[0],src[1],src[2],dst + pitch*y + frame_pixel_size*x ,w,h,stride[0],stride[1],pitch); 1029 case IMGFMT_YV12: yv12toyuy2(src[0],src[1],src[2],dst + pitch*y + frame_pixel_size*x ,w,h,stride[0],stride[1],pitch);
780 break; 1030 break;
781 case IMGFMT_YUY2: {
782 dst += x * frame_pixel_size;
783 s = src[0];
784 for (i=y;i<=(y+h);i++) {
785 memcpy(dst,s,w);
786 dst += (pitch);
787 s += stride[0];
788 };
789 };
790 break;
791 // hopefully there will be no RGB in this case otherwise convert - not implemented 1031 // hopefully there will be no RGB in this case otherwise convert - not implemented
792 } 1032 }
793 break; 1033 break;
1034
1035 #ifdef HAVE_DIRECTFB099
1036 case DSPF_YV12:
1037 switch (pixel_format) {
1038 case IMGFMT_YV12: {
1039 int i;
1040 dst += x;
1041 for (i=y;i<(y+h);i++) {
1042 memcpy(dst+i*pitch,src[0]+i*stride[0],w);
1043 }
1044 dst += pitch*in_height - (x)/2;
1045 for (i=y/2;i<(y+h)/2;i++) {
1046 memcpy(dst+i*pitch/2,src[2]+i*stride[2],w/2);
1047 }
1048 dst += pitch*in_height/4;
1049 for (i=y/2;i<(y+h)/2;i++) {
1050 memcpy(dst+i*pitch/2,src[1]+i*stride[1],w/2);
1051 }
1052 };
1053 break;
1054 /* case IMGFMT_YUY2: {
1055 int i;
1056 for (i=y;i<(y+h);i++) {
1057 yuy2toyv12(src[0]+i*stride[0],dst+i*pitch+x*frame_pixel_size,dst+pitch*(in_height+i/2)+x*frame_pixel_size/2,dst+pitch*(in_height+in_height/4+i/2)+x*frame_pixel_size/2,w,h,pitch,pitch/2,pitch/2);
1058 }
1059 }
1060
1061 break;
1062 */ // hopefully there will be no RGB in this case otherwise convert - not implemented
1063 }
1064 break;
1065
1066 case DSPF_I420:
1067 switch (pixel_format) {
1068 case IMGFMT_YV12: {
1069 int i;
1070 dst += x;
1071 for (i=y;i<(y+h);i++) {
1072 memcpy(dst+i*pitch,src[0]+i*stride[0],w);
1073 }
1074 dst += pitch*in_height - (x)/2;
1075 for (i=y/2;i<(y+h)/2;i++) {
1076 memcpy(dst+i*pitch/2,src[1]+i*stride[1],w/2);
1077 }
1078 dst += pitch*in_height/4;
1079 for (i=y/2;i<(y+h)/2;i++) {
1080 memcpy(dst+i*pitch/2,src[2]+i*stride[2],w/2);
1081 }
1082 };
1083 break;
1084 /* case IMGFMT_YUY2: {
1085 int i;
1086 for (i=y;i<(y+h);i++) {
1087 yuy2toyv12(src[0]+i*stride[0],dst+i*pitch+x*frame_pixel_size,dst+pitch*(in_height+in_height/4+i/2)+x*frame_pixel_size/2,dst+pitch*(in_height+i/2)+x*frame_pixel_size/2,w,h,pitch,pitch/2,pitch/2);
1088 }
1089 }
1090
1091 break;
1092 */ // hopefully there will be no RGB in this case otherwise convert - not implemented
1093 }
1094 break;
1095 #endif
794 }; 1096 };
795 1097
796 frame->Unlock(frame); 1098 frame->Unlock(frame);
797 1099 // primary->Unlock(primary);
1100
798 return 0; 1101 return 0;
799 } 1102 }
800 1103
801 extern void mplayer_put_key(int code); 1104 extern void mplayer_put_key(int code);
802 1105
804 1107
805 static void check_events(void) 1108 static void check_events(void)
806 { 1109 {
807 1110
808 DFBInputEvent event; 1111 DFBInputEvent event;
809 #ifdef HAVE_DIRECTFB099 1112 //if (verbose) printf ("DirectFB: Check events entered\n");
810 if (buffer->GetEvent (buffer, DFB_EVENT(&event)) == DFB_OK) { 1113 if (buffer->GetEvent(buffer, &event) == DFB_OK) {
811 #else
812 if (buffer->GetEvent (buffer, &event) == DFB_OK) {
813 #endif
814 if (event.type == DIET_KEYPRESS) { 1114 if (event.type == DIET_KEYPRESS) {
815 switch (event.keycode) { 1115 switch (event.keycode) {
816 case DIKC_ESCAPE: 1116 case DIKC_ESCAPE:
817 mplayer_put_key('q'); 1117 mplayer_put_key('q');
818 break; 1118 break;
840 // empty buffer, because of repeating (keyboard repeat is faster than key handling 1140 // empty buffer, because of repeating (keyboard repeat is faster than key handling
841 // and this causes problems during seek) 1141 // and this causes problems during seek)
842 // temporary workabout should be solved in the future 1142 // temporary workabout should be solved in the future
843 1143
844 buffer->Reset(buffer); 1144 buffer->Reset(buffer);
1145 //if (verbose) printf ("DirectFB: Check events finished\n");
845 1146
846 } 1147 }
847 1148
848 static void draw_osd(void) 1149 static void draw_osd(void)
849 { 1150 {
852 1153
853 static void flip_page(void) 1154 static void flip_page(void)
854 { 1155 {
855 DFBSurfaceBlittingFlags flags=DSBLIT_NOFX; 1156 DFBSurfaceBlittingFlags flags=DSBLIT_NOFX;
856 1157
1158 // if (verbose) printf("DirectFB: Flip page entered");
1159
857 DFBCHECK (primary->SetBlittingFlags(primary,flags)); 1160 DFBCHECK (primary->SetBlittingFlags(primary,flags));
858 1161
1162 #ifdef DIRECTRENDER
1163 if(framelocked) {
1164 frame->Unlock(frame);
1165 framelocked=0;
1166 };
1167 #endif
859 if (stretch) { 1168 if (stretch) {
860 DFBRectangle rect; 1169 DFBRectangle rect;
861 rect.x=xoffset; 1170 rect.x=xoffset;
862 rect.y=yoffset; 1171 rect.y=yoffset;
863 rect.w=out_width; 1172 rect.w=out_width;
864 rect.h=out_height; 1173 rect.h=out_height;
865 1174
866 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect)); 1175 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect));
867 } 1176 }
868 else { 1177 else {
869 DFBCHECK (primary->Blit(primary,frame,NULL,xoffset,yoffset)); 1178 #ifdef HAVE_DIRECTFB099
1179 if (!memcpyBitBlt) {
1180 #endif
1181 DFBCHECK (primary->Blit(primary,frame,NULL,xoffset,yoffset));
1182 #ifdef HAVE_DIRECTFB099
1183 } else {
1184
1185 int err,err2;
1186 void *dst,*src;
1187 int pitch,pitch2;
1188
1189 // printf("MemcpyBlit");
1190
1191 err = frame->Lock(frame,DSLF_READ,&src,&pitch);
1192 err2 = primary->Lock(primary,DSLF_WRITE,&dst,&pitch2);
1193
1194 // printf("DirectFB: pitch=%i pitch2=%i\n",pitch,pitch2);
1195
1196
1197 if (pitch==pitch2) {
1198 memcpy(dst,src,in_height * pitch * 1.5);
1199 } else
1200 {
1201 int i;
1202 int p=min(pitch,pitch2);
1203 for (i=0;i<in_height;i++) {
1204 memcpy (dst+i*pitch2,src+i*pitch,p);
1205 };
1206 dst+= in_height * pitch2;
1207 src+= in_height * pitch;
1208 p=p/2;
1209 for (i=0;i<in_height/2;i++) {
1210 memcpy (dst+i*pitch2/2,src+i*pitch/2,p);
1211 };
1212 dst+= in_height * pitch2/4;
1213 src+= in_height * pitch/4;
1214 for (i=0;i<in_height/2;i++) {
1215 memcpy (dst+i*pitch2/2,src+i*pitch/2,p);
1216 };
1217 }
1218 frame->Unlock(frame);
1219 primary->Unlock(primary);
1220 };
1221 #endif
870 }; 1222 };
871 // DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC)); 1223 // DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
872 } 1224 }
873 1225
874 static void uninit(void) 1226 static void uninit(void)
875 { 1227 {
876 if (verbose > 0) 1228 if (verbose ) printf("DirectFB: uninit entered\n");
877 printf("uninit\n");
878
879 /* 1229 /*
880 * (Release) 1230 * (Release)
881 */ 1231 */
882 // printf("Release buffer\n"); 1232 if (verbose ) printf("DirectFB: Release buffer\n");
883 buffer->Release (buffer); 1233 buffer->Release (buffer);
884 // printf("Release keyb\n"); 1234 if (verbose ) printf("DirectFB: Release keyboard\n");
885 keyboard->Release (keyboard); 1235 keyboard->Release (keyboard);
886 // printf("Release frame\n"); 1236 if (verbose ) printf("DirectFB: Release frame\n");
887 frame->Release (frame); 1237 frame->Release (frame);
888 1238
889 // we will not release dfb and layer because there could be a new film 1239 // we will not release dfb and layer because there could be a new film
890 1240
891 // printf("Release primary\n"); 1241 if (verbose ) printf("DirectFB: Release primary\n");
892 primary->Release (primary); 1242 primary->Release (primary);
893 // switch off BES 1243 // switch off BES
894 if (videolayer) videolayer->SetOpacity(videolayer,0); 1244 if (videolayer) videolayer->SetOpacity(videolayer,0);
895 // printf("Release videolayer\n"); 1245
896 // if (videolayer) videolayer->Release(videolayer); 1246 #ifdef HAVE_DIRECTFB099
897 // printf("Release dfb\n"); 1247 if (verbose&&videolayer ) printf("DirectFB: Release videolayer\n");
898 // dfb->Release (dfb); 1248 if (videolayer) videolayer->Release(videolayer);
899 // preinit_done=0; 1249
900 1250 if (verbose ) printf("DirectFB: Release DirectFB library\n");
901 } 1251 dfb->Release (dfb);
1252 preinitdone=0;
1253 #endif
1254
1255 if (verbose ) printf("DirectFB: Uninit done.\n");
1256 }
1257
1258 static int directfb_set_video_eq( const vidix_video_eq_t *info)
1259 {
1260 if (videolayeractive) {
1261 DFBColorAdjustment ca;
1262 float factor = (float)0xffff / 2000.0;
1263
1264 ca.flags=DCAF_NONE;
1265
1266 if ((videolayercaps.brightness)&&(info->cap&VEQ_CAP_BRIGHTNESS)) {
1267 ca.brightness = info->brightness * factor +0x8000;
1268 ca.flags |= DCAF_BRIGHTNESS;
1269 if (verbose) printf("DirectFB: SetVEq Brightness 0x%X %i\n",ca.brightness,info->brightness);
1270 }
1271
1272 if ((videolayercaps.contrast)&&(info->cap&VEQ_CAP_CONTRAST)) {
1273 ca.contrast = info->contrast * factor + 0x8000;
1274 ca.flags |= DCAF_CONTRAST;
1275 if (verbose) printf("DirectFB: SetVEq Contrast 0x%X %i\n",ca.contrast,info->contrast);
1276 }
1277
1278 if ((videolayercaps.hue)&&(info->cap&VEQ_CAP_HUE)) {
1279 ca.hue = info->hue * factor + 0x8000;
1280 ca.flags |= DCAF_HUE;
1281 if (verbose) printf("DirectFB: SetVEq Hue 0x%X %i\n",ca.hue,info->hue);
1282 }
1283
1284 if ((videolayercaps.saturation)&&(info->cap&VEQ_CAP_HUE)) {
1285 ca.saturation = info->saturation * factor + 0x8000;
1286 ca.flags |= DCAF_SATURATION;
1287 if (verbose) printf("DirectFB: SetVEq Saturation 0x%X %i\n",ca.saturation,info->saturation);
1288 }
1289
1290 videolayer->SetColorAdjustment(videolayer,&ca);
1291 };
1292 return 0;
1293
1294 }
1295
1296 static int directfb_get_video_eq( vidix_video_eq_t *info)
1297 {
1298 if (videolayeractive) {
1299 DFBColorAdjustment ca;
1300 float factor = 2000.0 / (float)0xffff;
1301 videolayer->GetColorAdjustment(videolayer,&ca);
1302
1303 if ((videolayercaps.brightness)&&(ca.flags&DCAF_BRIGHTNESS)) {
1304 info->brightness = (ca.brightness-0x8000) * factor;
1305 info->cap |= VEQ_CAP_BRIGHTNESS;
1306 if (verbose) printf("DirectFB: GetVEq Brightness 0x%X %i\n",ca.brightness,info->brightness);
1307 }
1308
1309 if ((videolayercaps.contrast)&&(ca.flags&DCAF_CONTRAST)) {
1310 info->contrast = (ca.contrast-0x8000) * factor;
1311 info->cap |= VEQ_CAP_CONTRAST;
1312 if (verbose) printf("DirectFB: GetVEq Contrast 0x%X %i\n",ca.contrast,info->contrast);
1313 }
1314
1315 if ((videolayercaps.hue)&&(ca.flags&DCAF_HUE)) {
1316 info->hue = (ca.hue-0x8000) * factor;
1317 info->cap |= VEQ_CAP_HUE;
1318 if (verbose) printf("DirectFB: GetVEq Hue 0x%X %i\n",ca.hue,info->hue);
1319 }
1320
1321 if ((videolayercaps.saturation)&&(ca.flags&DCAF_SATURATION)) {
1322 info->saturation = (ca.saturation-0x8000) * factor;
1323 info->cap |= VEQ_CAP_SATURATION;
1324 if (verbose) printf("DirectFB: GetVEq Saturation 0x%X %i\n",ca.saturation,info->saturation);
1325 }
1326
1327 };
1328 return 0;
1329 }
1330 static void query_vaa(vo_vaa_t *vaa)
1331 {
1332 memset(vaa,0,sizeof(vo_vaa_t));
1333 vaa->get_video_eq = directfb_get_video_eq;
1334 vaa->set_video_eq = directfb_set_video_eq;
1335 }
1336
1337 #ifdef DIRECTRENDER
1338 static uint32_t get_image(mp_image_t *mpi){
1339 int err;
1340 void *dst;
1341 uint8_t *s;
1342 int pitch;
1343 int i;
1344
1345 // printf("DirectFB: get_image() called\n");
1346
1347 // now we are always in system memory (in this version - mybe will change in future)
1348 // if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram
1349
1350 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1351 if((mpi->width==pitch/frame_pixel_size) ||
1352 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){
1353 // we're lucky or codec accepts stride => ok, let's go!
1354 if(mpi->flags&MP_IMGFLAG_PLANAR){
1355
1356 #ifdef HAVE_DIRECTFB099
1357 err = frame->Lock(frame,DSLF_WRITE/*|DSLF_READ*/,&dst,&pitch);
1358 // err = primary->Lock(primary,DSLF_WRITE,&dst,&pitch); // for real direct rendering
1359
1360 if (err) {
1361 printf("DirectFB: Frame lock failed!");
1362 return VO_FALSE;
1363 };
1364 framelocked=1;
1365
1366 //YV12 format
1367 mpi->planes[0]=dst;
1368 switch(frame_format) {
1369 case DSPF_I420: mpi->planes[1]=dst + pitch*in_height;
1370 mpi->planes[2]=mpi->planes[1] + pitch*in_height/4;
1371 break;
1372 case DSPF_YV12: mpi->planes[2]=dst + pitch*in_height;
1373 mpi->planes[1]=mpi->planes[1] + pitch*in_height/4;
1374 break;
1375
1376 }
1377 mpi->width=mpi->stride[0]=pitch;
1378 mpi->stride[1]=mpi->stride[2]=pitch/2;
1379 #else
1380 return VO_FALSE;
1381 #endif
1382 } else {
1383 err = frame->Lock(frame,DSLF_WRITE/*|DSLF_READ*/,&dst,&pitch);
1384 // err = primary->Lock(primary,DSLF_WRITE,&dst,&pitch); // for real direct rendering
1385
1386 if (err) {
1387 printf("DirectFB: Frame lock failed!");
1388 return VO_FALSE;
1389 };
1390 framelocked=1;
1391 //YUY2 and RGB formats
1392 mpi->planes[0]=dst;
1393 mpi->width=pitch/frame_pixel_size;
1394 mpi->stride[0]=pitch;
1395 }
1396 mpi->flags|=MP_IMGFLAG_DIRECT;
1397 // printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1398 return VO_TRUE;
1399 }
1400
1401 if(framelocked) {
1402 frame->Unlock(frame);
1403 framelocked=0;
1404 };
1405 return VO_FALSE;
1406 }
1407 #endif
902 1408
903 static uint32_t control(uint32_t request, void *data, ...) 1409 static uint32_t control(uint32_t request, void *data, ...)
904 { 1410 {
905 switch (request) { 1411 switch (request) {
1412 case VOCTRL_QUERY_VAA:
1413 query_vaa((vo_vaa_t*)data);
1414 return VO_TRUE;
906 case VOCTRL_QUERY_FORMAT: 1415 case VOCTRL_QUERY_FORMAT:
907 return query_format(*((uint32_t*)data)); 1416 return query_format(*((uint32_t*)data));
1417 #ifdef DIRECTRENDER
1418 case VOCTRL_GET_IMAGE:
1419 // printf("DirectFB: control(VOCTRL_GET_IMAGE) called\n");
1420 if (dr_enabled) return get_image(data);
1421 #endif
908 } 1422 }
909 return VO_NOTIMPL; 1423 return VO_NOTIMPL;
910 } 1424 }