2 * MPlayer video driver for DirectFramebuffer device
4 * copyright (C) 2002 Jiri Svoboda <Jiri.Svoboda@seznam.cz>
6 * based on vo_directfb2.c
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <directfb_version.h>
30 #include <libavutil/common.h>
33 #include "video_out.h"
34 #include "video_out_internal.h"
35 #include "fastmemcpy.h"
39 #include "subopt-helper.h"
41 #include "input/keycodes.h"
46 static const vo_info_t info
= {
47 "Direct Framebuffer Device",
49 "Jiri Svoboda Jiri.Svoboda@seznam.cz",
50 "v 2.0 (for DirectFB version >=0.9.22)"
53 const LIBVO_EXTERN(directfb
)
55 /******************************
56 * vo_directfb globals *
57 ******************************/
59 #define DFBCHECK(x...) \
65 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
66 DirectFBErrorFatal( #x, err ); \
74 // main DirectFB handle
75 static IDirectFB
*dfb
= NULL
;
77 static IDirectFBInputDevice
*keyboard
= NULL
;
78 // A buffer for input events.
79 static IDirectFBEventBuffer
*buffer
= NULL
;
82 * filled during config
85 // handle of used layer
86 static IDirectFBDisplayLayer
*layer
= NULL
;
87 // surface of used layer
88 static IDirectFBSurface
*primary
= NULL
;
89 static int primarylocked
= 0;
90 // handle of temporary surface (if used)
91 static IDirectFBSurface
*frame
= NULL
;
92 static int framelocked
= 0;
93 // flipping mode flag (layer/surface)
94 static int flipping
= 0;
96 static int stretch
= 0;
98 static int xoffset
=0,yoffset
=0;
100 static int out_width
=0,out_height
=0;
101 // frame/primary size
102 static int width
=0,height
=0;
103 // frame primary format
104 DFBSurfacePixelFormat pixel_format
;
106 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
107 unsigned char *srca, int stride, unsigned char *dst,
111 /******************************
112 * cmd line parameteres *
113 ******************************/
115 /* command line/config file options */
116 static int layer_id
= -1;
117 static int buffer_mode
= 1;
118 static int use_input
= 1;
119 static int field_parity
= -1;
121 /******************************
123 ******************************/
126 if (frame
&& framelocked
) frame
->Unlock(frame
);
127 if (primary
&& primarylocked
) primary
->Unlock(primary
);
130 static int get_parity(strarg_t
*arg
) {
131 if (strargcmp(arg
, "top") == 0)
133 if (strargcmp(arg
, "bottom") == 0)
138 static int check_parity(void *arg
) {
139 return get_parity(arg
) != -1;
142 static int get_mode(strarg_t
*arg
) {
143 if (strargcmp(arg
, "single") == 0)
145 if (strargcmp(arg
, "double") == 0)
147 if (strargcmp(arg
, "triple") == 0)
152 static int check_mode(void *arg
) {
153 return get_mode(arg
) != 0;
156 static int preinit(const char *arg
)
159 strarg_t mode_str
= {0, NULL
};
160 strarg_t par_str
= {0, NULL
};
161 strarg_t dfb_params
= {0, NULL
};
162 const opt_t subopts
[] = {
163 {"input", OPT_ARG_BOOL
, &use_input
, NULL
},
164 {"buffermode", OPT_ARG_STR
, &mode_str
, check_mode
},
165 {"fieldparity", OPT_ARG_STR
, &par_str
, check_parity
},
166 {"layer", OPT_ARG_INT
, &layer_id
, NULL
},
167 {"dfbopts", OPT_ARG_STR
, &dfb_params
, NULL
},
171 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
173 if (dfb
) return 0; // we are already initialized!
176 buffer_mode
= 1 + vo_doublebuffering
; // honor -double switch
180 if (subopt_parse(arg
, subopts
) != 0) {
181 mp_msg( MSGT_VO
, MSGL_ERR
,
182 "\n-vo directfb command line help:\n"
183 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
184 "\nOptions (use 'no' prefix to disable):\n"
185 " input Use DirectFB for keyboard input\n"
188 " n=0..xx Use layer with id n for output (0=primary)\n"
189 " buffermode=(single|double|triple)\n"
190 " single Use single buffering\n"
191 " double Use double buffering\n"
192 " triple Use triple buffering\n"
193 " fieldparity=(top|bottom)\n"
194 " top Top field first\n"
195 " bottom Bottom field first\n"
197 " Specify a parameter list for DirectFB\n"
202 buffer_mode
= get_mode(&mode_str
);
204 field_parity
= get_parity(&par_str
);
207 if (dfb_params
.len
> 0)
210 char arg0
[10] = "mplayer";
211 char *arg1
= malloc(dfb_params
.len
+ 7);
217 strcpy(arg1
, "--dfb:");
218 strncat(arg1
, dfb_params
.str
, dfb_params
.len
);
224 DFBCHECK (DirectFBInit (&argc
,&a
));
229 DFBCHECK (DirectFBInit (NULL
,NULL
));
232 if (((directfb_major_version
<= 0) &&
233 (directfb_minor_version
<= 9) &&
234 (directfb_micro_version
< 15)))
236 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Unsupported DirectFB version\n");
244 // uncomment this if you do not wish to create a new VT for DirectFB
245 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
247 // uncomment this if you want to allow VT switching
248 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
250 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
251 DFBCHECK (DirectFBSetOption ("no-cursor",""));
254 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
260 DFBCHECK (DirectFBCreate (&dfb
));
267 ret
= dfb
->GetInputDevice (dfb
, DIDID_KEYBOARD
, &keyboard
);
269 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Keyboard init OK\n");
272 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Keyboard init FAILED\n");
278 * Create an input buffer for the keyboard.
280 if (keyboard
) DFBCHECK (keyboard
->CreateEventBuffer (keyboard
, &buffer
));
282 // just to start clean ...
283 if (buffer
) buffer
->Reset(buffer
);
285 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit OK\n");
291 DFBSurfacePixelFormat
convformat(uint32_t format
)
293 // add more formats !!!
295 case IMGFMT_RGB32
: return DSPF_RGB32
; break;
296 case IMGFMT_BGR32
: return DSPF_RGB32
; break;
297 case IMGFMT_RGB24
: return DSPF_RGB24
; break;
298 case IMGFMT_BGR24
: return DSPF_RGB24
; break;
299 case IMGFMT_RGB16
: return DSPF_RGB16
; break;
300 case IMGFMT_BGR16
: return DSPF_RGB16
; break;
301 case IMGFMT_RGB15
: return DSPF_ARGB1555
; break;
302 case IMGFMT_BGR15
: return DSPF_ARGB1555
; break;
303 case IMGFMT_RGB12
: return DSPF_ARGB4444
; break;
304 case IMGFMT_BGR12
: return DSPF_ARGB4444
; break;
305 case IMGFMT_YUY2
: return DSPF_YUY2
; break;
306 case IMGFMT_UYVY
: return DSPF_UYVY
; break;
307 case IMGFMT_YV12
: return DSPF_YV12
; break;
308 case IMGFMT_I420
: return DSPF_I420
; break;
309 // case IMGFMT_IYUV: return DSPF_IYUV; break;
310 case IMGFMT_RGB8
: return DSPF_RGB332
; break;
311 case IMGFMT_BGR8
: return DSPF_RGB332
; break;
318 typedef struct enum1_s
{
328 DFBEnumerationResult
test_format_callback( unsigned int id
,
329 DFBDisplayLayerDescription desc
,
332 enum1_t
*params
=(enum1_t
*)data
;
333 IDirectFBDisplayLayer
*layer
;
336 if ((layer_id
== -1 )||(layer_id
== id
)) {
338 ret
= dfb
->GetDisplayLayer( dfb
, id
, &layer
);
340 DirectFBError( "dfb->GetDisplayLayer failed", ret
);
343 DFBDisplayLayerConfig dlc
;
345 if (params
->setsize
) {
346 dlc
.flags
= DLCONF_WIDTH
|DLCONF_HEIGHT
;
347 dlc
.width
= params
->width
;
348 dlc
.height
= params
->height
;
349 layer
->SetConfiguration(layer
,&dlc
);
353 dlc
.flags
= DLCONF_PIXELFORMAT
;
354 dlc
.pixelformat
= convformat(params
->format
);
356 layer
->SetOpacity(layer
,0);
358 ret
= layer
->TestConfiguration(layer
,&dlc
,NULL
);
360 layer
->Release(layer
);
362 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
365 // printf("Test OK\n");
366 if (params
->result
) {
367 if ((!params
->scale
) && (desc
.caps
& DLCAPS_SCREEN_LOCATION
)) {
370 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
375 if (desc
.caps
& DLCAPS_SCREEN_LOCATION
) params
->scale
=1;
376 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
386 static int query_format(uint32_t format
)
388 int ret
= VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_OSD
; // osd should be removed the in future -> will be handled outside...
392 if (!convformat(format
)) return 0;
393 // temporarily disable YV12
394 // if (format == IMGFMT_YV12) return 0;
395 // if (format == IMGFMT_I420) return 0;
396 if (format
== IMGFMT_IYUV
) return 0;
398 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Format query: %s\n",vo_format_name(format
));
400 params
.format
=format
;
405 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
408 if (params
.scale
) ret
|=VFCAP_HWSCALE_UP
|VFCAP_HWSCALE_DOWN
;
415 typedef struct videomode_s
{
426 DFBEnumerationResult
video_modes_callback( int width
,int height
,int bpp
, void *data
)
428 videomode_t
*params
=(videomode_t
*)data
;
430 int overx
=0,overy
=0,closer
=0,over
=0;
433 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Validator entered %i %i %i\n",width,height,bpp);
435 overx
=width
-params
->out_width
;
436 overy
=height
-params
->out_height
;
438 if (!params
->width
) {
440 params
->height
=height
;
443 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Mode added %i %i %i\n",width
,height
,bpp
);
446 if ((params
->overy
<0)||(params
->overx
<0)) we_are_under
=1; // stored mode is smaller than req mode
447 if (abs(overx
*overy
)<abs(params
->overx
* params
->overy
)) closer
=1; // current mode is closer to desired res
448 if ((overx
>=0)&&(overy
>=0)) over
=1; // current mode is bigger or equaul to desired res
449 if ((closer
&& (over
|| we_are_under
)) || (we_are_under
&& over
)) {
451 params
->height
=height
;
454 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Better mode added %i %i %i\n",width
,height
,bpp
);
460 #define CONFIG_ERROR -1
462 static int config(uint32_t s_width
, uint32_t s_height
, uint32_t d_width
,
463 uint32_t d_height
, uint32_t flags
, char *title
,
472 int fs
= flags
& VOFLAG_FULLSCREEN
;
473 int vm
= flags
& VOFLAG_MODESWITCHING
;
475 DFBSurfaceDescription dsc
;
477 DFBDisplayLayerConfig dlc
;
478 DFBSurfaceCapabilities caps
;
482 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config entered [%ix%i]\n",s_width
,s_height
);
483 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: With requested format: %s\n",vo_format_name(format
));
487 frame
->Release(frame
);
492 primary
->Release(primary
);
497 layer
->Release(layer
);
506 params
.out_width
=d_width
;
507 params
.out_height
=d_height
;
527 default: params
.bpp
=0;
530 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - trying to change videomode\n");
531 DFBCHECK (dfb
->EnumVideoModes(dfb
,video_modes_callback
,¶ms
));
532 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,params
.bpp
);
534 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,24);
536 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,32);
538 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,16);
540 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,8);
547 // just to be sure clear primary layer
548 ret
= dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
);
550 ret
= layer
->GetSurface(layer
,&primary
);
552 primary
->Clear(primary
,0,0,0,0xff);
553 ret
= primary
->Flip(primary
,NULL
,0);
555 primary
->Clear(primary
,0,0,0,0xff);
557 primary
->Release(primary
);
560 layer
->Release(layer
);
566 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - looking for suitable layer\n");
567 params
.format
=format
;
570 params
.width
=s_width
;
571 params
.height
=s_height
;
574 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
576 if (!params
.result
) {
577 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - no suitable layer found\n");
578 params
.id
= DLID_PRIMARY
;
581 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - layer %i\n",params
.id
);
585 DFBCHECK (dfb
->GetDisplayLayer( dfb
, params
.id
, &layer
));
587 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - switching layer to exclusive mode\n");
588 ret
= layer
->SetCooperativeLevel (layer
, DLSCL_EXCLUSIVE
);
591 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - cannot switch layer to exclusive mode. This could cause\nproblems. You may need to select correct pixel format manually!\n");
592 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret
);
595 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (size)\n");
596 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
598 dlc
.height
= s_height
;
600 ret
= layer
->SetConfiguration(layer
,&dlc
);
603 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (size)\n");
604 DirectFBError("MPlayer - Layer size change.",ret
);
608 // look if we need to change the pixel format of the layer
609 // and just to be sure also fetch all layer properties
610 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
| DLCONF_OPTIONS
| DLCONF_BUFFERMODE
;
612 ret
= layer
->GetConfiguration(layer
,&dlc
);
614 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
;
617 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - could not get layer properties!\n");
619 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer reports format:%x\n",dlc
.pixelformat
);
622 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
624 dlc
.flags
= DLCONF_PIXELFORMAT
;
625 dlc
.pixelformat
= convformat(params
.format
);
627 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Desired pixelformat: %x\n",dlc
.pixelformat
);
629 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (format)\n");
630 ret
= layer
->SetConfiguration(layer
,&dlc
);
634 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc
.flags
);
635 DirectFBError("MPlayer - layer pixelformat change",ret
);
637 // ugly fbdev workaround - try to switch pixelformat via videomode change
638 switch (dlc
.pixelformat
) {
640 case DSPF_RGB32
: bpp
=32;break;
641 case DSPF_RGB24
: bpp
=24;break;
642 case DSPF_RGB16
: bpp
=16;break;
643 case DSPF_ARGB1555
: bpp
=15;break;
644 case DSPF_ARGB4444
: bpp
=12; break;
645 case DSPF_RGB332
: bpp
=8;break;
648 switch (dlc
.pixelformat
) {
656 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Trying to recover via videomode change (VM).\n");
658 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
659 if (DFB_OK
==layer
->GetConfiguration(layer
,&dlc
)) {
660 // try to set videomode
661 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Videomode %ix%i BPP %i\n",dlc
.width
,dlc
.height
,bpp
);
662 ret
= dfb
->SetVideoMode(dfb
,dlc
.width
,dlc
.height
,bpp
);
663 if (ret
) DirectFBError("MPlayer - VM - pixelformat change",ret
);
667 //get current pixel format
668 dlc
.flags
= DLCONF_PIXELFORMAT
;
669 ret
= layer
->GetConfiguration(layer
,&dlc
);
671 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret
);
673 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer now has pixelformat [%x]\n",dlc
.pixelformat
);
676 // check if we were succesful
677 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
678 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Recovery failed!.\n");
684 default: return CONFIG_ERROR
;
691 // try triple, double... buffering
693 dlc
.flags
= DLCONF_BUFFERMODE
;
695 if (buffer_mode
> 2) {
696 dlc
.buffermode
= DLBM_TRIPLE
;
697 ret
= layer
->SetConfiguration( layer
, &dlc
);
704 if (buffer_mode
> 1) {
705 dlc
.buffermode
= DLBM_BACKVIDEO
;
706 ret
= layer
->SetConfiguration( layer
, &dlc
);
708 dlc
.buffermode
= DLBM_BACKSYSTEM
;
709 ret
= layer
->SetConfiguration( layer
, &dlc
);
713 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Double buffering is active\n");
717 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Triple buffering is active\n");
721 if (field_parity
!= -1) {
722 dlc
.flags
= DLCONF_OPTIONS
;
723 ret
= layer
->GetConfiguration( layer
, &dlc
);
725 dlc
.options
|= DLOP_FIELD_PARITY
;
726 ret
= layer
->SetConfiguration( layer
, &dlc
);
728 layer
->SetFieldParity( layer
, field_parity
);
732 mp_msg( MSGT_VO
, MSGL_DBG2
, "DirectFB: Requested field parity: ");
733 switch (field_parity
) {
735 mp_msg( MSGT_VO
, MSGL_DBG2
, "Don't care\n");
738 mp_msg( MSGT_VO
, MSGL_DBG2
, "Top field first\n");
741 mp_msg( MSGT_VO
, MSGL_DBG2
, "Bottom field first\n");
747 ret
= layer
->GetSurface(layer
,&primary
);
750 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - could not get surface\n");
751 return CONFIG_ERROR
; // what shall we report on failure?
754 // test surface for flipping
755 DFBCHECK(primary
->GetCapabilities(primary
,&caps
));
756 primary
->Clear(primary
,0,0,0,0xff);
758 if (caps
& (DSCAPS_FLIPPING
763 ret
= primary
->Flip(primary
,NULL
,0);
766 primary
->Clear(primary
,0,0,0,0xff);
768 // if we have 3 buffers clean once more
769 if (caps
& DSCAPS_TRIPLE
) {
770 primary
->Flip(primary
,NULL
,0);
771 primary
->Clear(primary
,0,0,0,0xff);
778 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - flipping = %i\n",flipping
);
780 // is scale needed ? Aspect ratio and layer pos/size
784 DFBCHECK(primary
->GetSize(primary
,&width
,&height
));
786 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - surface size = %ix%i\n",width
,height
);
788 aspect_save_orig(s_width
,s_height
);
789 aspect_save_prescale(d_width
,d_height
);
791 aspect_save_screenres(10000,10000);
792 aspect(&out_width
,&out_height
,A_ZOOM
);
794 ret
= layer
->SetScreenLocation(layer
,(1-(float)out_width
/10000)/2,(1-(float)out_height
/10000)/2,((float)out_width
/10000),((float)out_height
/10000));
796 if (ret
) mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (position)\n");
803 aspect_save_screenres(width
,height
);
806 aspect(&out_width
,&out_height
,A_ZOOM
);
808 aspect(&out_width
,&out_height
,A_NOZOOM
);
811 xoffset
= (width
- out_width
) / 2;
812 yoffset
= (height
- out_height
) / 2;
815 if (((s_width
==out_width
)&&(s_height
==out_height
)) || (params
.scale
)) {
822 // temporary buffer in case of not flipping or scaling
823 if ((!flipping
) || stretch
) {
825 DFBCHECK (primary
->GetPixelFormat (primary
, &dsc
.pixelformat
));
827 dsc
.flags
= DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
| DSDESC_WIDTH
;
830 dsc
.height
= s_height
;
832 DFBCHECK (dfb
->CreateSurface( dfb
, &dsc
, &frame
));
833 DFBCHECK(frame
->GetSize(frame
,&width
,&height
));
834 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Frame is active.\n");
837 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
839 DFBCHECK (frame
->GetPixelFormat(frame
,&pixel_format
));
841 DFBCHECK (primary
->GetPixelFormat(primary
,&pixel_format
));
844 // finally turn on layer
845 layer
->SetOpacity(layer
,255);
847 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height);
852 static void check_events(void)
859 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events entered\n");
860 if (buffer
->GetEvent(buffer
, DFB_EVENT (&event
)) == DFB_OK
) {
862 if (event
.type
== DIET_KEYPRESS
) {
863 switch (event
.key_symbol
) {
865 mplayer_put_key(KEY_ESC
);
867 case DIKS_PAGE_UP
: mplayer_put_key(KEY_PAGE_UP
);break;
868 case DIKS_PAGE_DOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
869 case DIKS_CURSOR_UP
: mplayer_put_key(KEY_UP
);break;
870 case DIKS_CURSOR_DOWN
: mplayer_put_key(KEY_DOWN
);break;
871 case DIKS_CURSOR_LEFT
: mplayer_put_key(KEY_LEFT
);break;
872 case DIKS_CURSOR_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
873 case DIKS_INSERT
: mplayer_put_key(KEY_INSERT
);break;
874 case DIKS_DELETE
: mplayer_put_key(KEY_DELETE
);break;
875 case DIKS_HOME
: mplayer_put_key(KEY_HOME
);break;
876 case DIKS_END
: mplayer_put_key(KEY_END
);break;
878 default:mplayer_put_key(event
.key_symbol
);
882 // empty buffer, because of repeating (keyboard repeat is faster than key handling
883 // and this causes problems during seek)
884 // temporary workaround should be solved in the future
885 buffer
->Reset(buffer
);
888 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events finished\n");
891 static void flip_page(void)
893 DFBSurfaceBlittingFlags flags
=DSBLIT_NOFX
;
895 unlock(); // unlock frame & primary
897 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Flip page entered");
899 DFBCHECK (primary
->SetBlittingFlags(primary
,flags
));
909 DFBCHECK (primary
->StretchBlit(primary
,frame
,NULL
,&rect
));
913 DFBCHECK (primary
->Blit(primary
,frame
,NULL
,xoffset
,yoffset
));
921 case 1: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAIT
));
923 case 2: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_ONSYNC
));
925 default:; // should never be reached
929 DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAITFORSYNC
));
937 static void uninit(void)
940 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit entered\n");
948 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing buffer\n");
949 if (buffer) buffer->Release (buffer);
950 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing keyboard\n");
951 if (keyboard) keyboard->Release (keyboard);
954 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing frame\n");
955 frame
->Release (frame
);
960 // if (layer) layer->SetOpacity(layer,0);
963 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing layer\n");
964 layer
->Release(layer
);
969 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing primary\n");
970 primary
->Release (primary
);
975 /* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n");
979 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");
983 static uint32_t directfb_set_video_eq(char *data
, int value
) //data==name
986 DFBColorAdjustment ca
;
987 float factor
= (float)0xffff / 200.0;
989 DFBDisplayLayerDescription desc
;
995 layer
->GetDescription(layer
,&desc
);
999 if (! strcmp( data
,"brightness" )) {
1000 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1001 ca
.brightness
= value
* factor
+0x8000;
1002 ca
.flags
|= DCAF_BRIGHTNESS
;
1003 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Brightness 0x%X %i\n",ca
.brightness
,value
);
1004 } else return VO_FALSE
;
1007 if (! strcmp( data
,"contrast" )) {
1008 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1009 ca
.contrast
= value
* factor
+ 0x8000;
1010 ca
.flags
|= DCAF_CONTRAST
;
1011 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Contrast 0x%X %i\n",ca
.contrast
,value
);
1012 } else return VO_FALSE
;
1015 if (! strcmp( data
,"hue" )) {
1016 if ((desc
.caps
& DLCAPS_HUE
)) {
1017 ca
.hue
= value
* factor
+ 0x8000;
1018 ca
.flags
|= DCAF_HUE
;
1019 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Hue 0x%X %i\n",ca
.hue
,value
);
1020 } else return VO_FALSE
;
1023 if (! strcmp( data
,"saturation" )) {
1024 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1025 ca
.saturation
= value
* factor
+ 0x8000;
1026 ca
.flags
|= DCAF_SATURATION
;
1027 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Saturation 0x%X %i\n",ca
.saturation
,value
);
1028 } else return VO_FALSE
;
1031 if (ca
.flags
!= DCAF_NONE
) {
1032 layer
->SetColorAdjustment(layer
,&ca
);
1041 static uint32_t directfb_get_video_eq(char *data
, int *value
) // data==name
1044 DFBColorAdjustment ca
;
1045 float factor
= 200.0 / (float)0xffff;
1047 DFBDisplayLayerDescription desc
;
1053 layer
->GetDescription(layer
,&desc
);
1055 layer
->GetColorAdjustment(layer
,&ca
);
1057 if (! strcmp( data
,"brightness" )) {
1058 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1059 *value
= (int) ((ca
.brightness
-0x8000) * factor
);
1060 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Brightness 0x%X %i\n",ca
.brightness
,*value
);
1062 } else return VO_FALSE
;
1065 if (! strcmp( data
,"contrast" )) {
1066 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1067 *value
= (int) ((ca
.contrast
-0x8000) * factor
);
1068 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Contrast 0x%X %i\n",ca
.contrast
,*value
);
1070 } else return VO_FALSE
;
1073 if (! strcmp( data
,"hue" )) {
1074 if ((desc
.caps
& DLCAPS_HUE
)) {
1075 *value
= (int) ((ca
.hue
-0x8000) * factor
);
1076 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Hue 0x%X %i\n",ca
.hue
,*value
);
1078 } else return VO_FALSE
;
1081 if (! strcmp( data
,"saturation" )) {
1082 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1083 *value
= (int) ((ca
.saturation
-0x8000) * factor
);
1084 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Saturation 0x%X %i\n",ca
.saturation
,*value
);
1086 } else return VO_FALSE
;
1092 static uint32_t get_image(mp_image_t
*mpi
)
1099 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n");
1100 if(mpi
->flags
&MP_IMGFLAG_READABLE
) return VO_FALSE
; // slow video ram
1101 if(mpi
->type
==MP_IMGTYPE_STATIC
) return VO_FALSE
; // it is not static
1103 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1105 if(mpi
->flags
&(MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_ACCEPT_WIDTH
)){
1106 // we're lucky or codec accepts stride => ok, let's go!
1109 err
= frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
);
1112 err
= primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
);
1117 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: DR lock failed!");
1121 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1124 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
1125 mpi
->planes
[1]=dst
+ pitch
*height
;
1126 mpi
->planes
[2]=mpi
->planes
[1] + pitch
*height
/4;
1128 mpi
->planes
[2]=dst
+ pitch
*height
;
1129 mpi
->planes
[1]=mpi
->planes
[2] + pitch
*height
/4;
1132 mpi
->stride
[0]=pitch
;
1133 mpi
->stride
[1]=mpi
->stride
[2]=pitch
/2;
1135 //YUY2 and RGB formats
1138 mpi
->stride
[0]=pitch
;
1144 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1145 mpi
->planes
[0]= dst
+ yoffset
* pitch
+ xoffset
;
1146 mpi
->planes
[1]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1147 mpi
->planes
[2]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1149 mpi
->planes
[0]=dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3);
1153 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1154 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1161 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1170 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1175 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1178 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1182 p
= FFMIN(w
, pitch
);
1185 dst2
= dst
+ pitch
*height
- y
*pitch
+ y
*pitch
/4 - x
/2;
1189 fast_memcpy(dst
,srcp
,p
);
1194 if (pixel_format
== DSPF_YV12
) {
1200 for (i
=0;i
<h
/2;i
++) {
1201 fast_memcpy(dst
,srcp
,p
);
1206 dst
= dst2
+ pitch
*height
/4;
1209 for (i
=0;i
<h
/2;i
++) {
1210 fast_memcpy(dst
,srcp
,p
);
1221 for (i
=0;i
<h
/2;i
++) {
1222 fast_memcpy(dst
,srcp
,p
);
1227 dst
= dst2
+ pitch
*height
/4;
1230 for (i
=0;i
<h
/2;i
++) {
1231 fast_memcpy(dst
,srcp
,p
);
1244 static uint32_t put_image(mp_image_t
*mpi
){
1247 // static IDirectFBSurface *tmp = NULL;
1248 // DFBSurfaceDescription dsc;
1249 // DFBRectangle rect;
1251 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image entered %i %i %i %i %i %i\n",mpi->x,mpi->y,mpi->w,mpi->h,mpi->width,mpi->height);
1256 if((mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))) {
1257 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing to do\n");
1261 if (mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1262 // memcpy all planes - sad but necessary
1269 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1271 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1274 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1278 p
= FFMIN(mpi
->w
, pitch
);
1280 src
= mpi
->planes
[0]+mpi
->y
*mpi
->stride
[0]+mpi
->x
;
1282 for (i
=0;i
<mpi
->h
;i
++) {
1283 fast_memcpy(dst
+i
*pitch
,src
+i
*mpi
->stride
[0],p
);
1287 if (pixel_format
== DSPF_YV12
) {
1289 dst
+= pitch
*height
;
1291 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1293 for (i
=0;i
<mpi
->h
/2;i
++) {
1294 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1297 dst
+= pitch
*height
/4;
1298 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1300 for (i
=0;i
<mpi
->h
/2;i
++) {
1301 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1306 dst
+= pitch
*height
;
1308 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1310 for (i
=0;i
<mpi
->h
/2;i
++) {
1311 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1314 dst
+= pitch
*height
/4;
1315 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1317 for (i
=0;i
<mpi
->h
/2;i
++) {
1318 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1325 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1328 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1329 dsc.preallocated[0].data = mpi->planes[0];
1330 dsc.preallocated[0].pitch = mpi->stride[0];
1331 dsc.width = mpi->width;
1332 dsc.height = mpi->height;
1333 dsc.pixelformat = convformat(mpi->imgfmt);
1335 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1343 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1345 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1353 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non-planar branch\n");
1355 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1357 mem2agpcpy_pic(dst
,mpi
->planes
[0] + mpi
->y
* mpi
->stride
[0] + mpi
->x
* (mpi
->bpp
>> 3) ,mpi
->w
* (mpi
->bpp
>> 3),mpi
->h
,pitch
,mpi
->stride
[0]);
1359 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1361 mem2agpcpy_pic(dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3),mpi
->planes
[0] + mpi
->y
* mpi
->stride
[0] + mpi
->x
* (mpi
->bpp
>> 3) ,mpi
->w
* (mpi
->bpp
>> 3),mpi
->h
,pitch
,mpi
->stride
[0]);
1371 static int control(uint32_t request
, void *data
)
1374 case VOCTRL_QUERY_FORMAT
:
1375 return query_format(*((uint32_t*)data
));
1376 case VOCTRL_GET_IMAGE
:
1377 return get_image(data
);
1378 case VOCTRL_DRAW_IMAGE
:
1379 return put_image(data
);
1380 case VOCTRL_SET_EQUALIZER
:
1382 struct voctrl_set_equalizer_args
*args
= data
;
1383 return directfb_set_video_eq(args
->name
, args
->value
);
1385 case VOCTRL_GET_EQUALIZER
:
1387 struct voctrl_get_equalizer_args
*args
= data
;
1388 return directfb_get_video_eq(args
->name
, args
->valueptr
);
1396 static int draw_frame(uint8_t *src
[])
1401 // hopefully will be removed soon
1403 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
1404 unsigned char *srca
, int stride
)
1409 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1412 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1415 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1419 switch(pixel_format
) {
1422 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 4*x0
,pitch
);
1426 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 3*x0
,pitch
);
1430 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1433 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1436 vo_draw_alpha_rgb12(w
, h
, src
, srca
, stride
,
1437 ((uint8_t *) dst
) + pitch
* y0
+ 2 * x0
,
1442 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
,pitch
);
1446 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
+ 1,pitch
);
1451 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 1*x0
,pitch
);
1458 static void draw_osd(void)
1460 vo_draw_text(width
,height
,draw_alpha
);