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"
45 static const vo_info_t info
= {
46 "Direct Framebuffer Device",
48 "Jiri Svoboda Jiri.Svoboda@seznam.cz",
49 "v 2.0 (for DirectFB version >=0.9.22)"
52 const LIBVO_EXTERN(directfb
)
54 /******************************
55 * vo_directfb globals *
56 ******************************/
58 #define DFBCHECK(x...) \
64 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
65 DirectFBErrorFatal( #x, err ); \
73 // main DirectFB handle
74 static IDirectFB
*dfb
= NULL
;
76 static IDirectFBInputDevice
*keyboard
= NULL
;
77 // A buffer for input events.
78 static IDirectFBEventBuffer
*buffer
= NULL
;
81 * filled during config
84 // handle of used layer
85 static IDirectFBDisplayLayer
*layer
= NULL
;
86 // surface of used layer
87 static IDirectFBSurface
*primary
= NULL
;
88 static int primarylocked
= 0;
89 // handle of temporary surface (if used)
90 static IDirectFBSurface
*frame
= NULL
;
91 static int framelocked
= 0;
92 // flipping mode flag (layer/surface)
93 static int flipping
= 0;
95 static int stretch
= 0;
97 static int xoffset
=0,yoffset
=0;
99 static int out_width
=0,out_height
=0;
100 // frame/primary size
101 static int width
=0,height
=0;
102 // frame primary format
103 DFBSurfacePixelFormat pixel_format
;
105 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
106 unsigned char *srca, int stride, unsigned char *dst,
110 /******************************
111 * cmd line parameteres *
112 ******************************/
114 /* command line/config file options */
115 static int layer_id
= -1;
116 static int buffer_mode
= 1;
117 static int use_input
= 1;
118 static int field_parity
= -1;
120 /******************************
122 ******************************/
125 if (frame
&& framelocked
) frame
->Unlock(frame
);
126 if (primary
&& primarylocked
) primary
->Unlock(primary
);
129 static int get_parity(strarg_t
*arg
) {
130 if (strargcmp(arg
, "top") == 0)
132 if (strargcmp(arg
, "bottom") == 0)
137 static int check_parity(void *arg
) {
138 return get_parity(arg
) != -1;
141 static int get_mode(strarg_t
*arg
) {
142 if (strargcmp(arg
, "single") == 0)
144 if (strargcmp(arg
, "double") == 0)
146 if (strargcmp(arg
, "triple") == 0)
151 static int check_mode(void *arg
) {
152 return get_mode(arg
) != 0;
155 static int preinit(const char *arg
)
158 strarg_t mode_str
= {0, NULL
};
159 strarg_t par_str
= {0, NULL
};
160 strarg_t dfb_params
= {0, NULL
};
161 const opt_t subopts
[] = {
162 {"input", OPT_ARG_BOOL
, &use_input
, NULL
},
163 {"buffermode", OPT_ARG_STR
, &mode_str
, check_mode
},
164 {"fieldparity", OPT_ARG_STR
, &par_str
, check_parity
},
165 {"layer", OPT_ARG_INT
, &layer_id
, NULL
},
166 {"dfbopts", OPT_ARG_STR
, &dfb_params
, NULL
},
170 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
172 if (dfb
) return 0; // we are already initialized!
175 buffer_mode
= 1 + vo_doublebuffering
; // honor -double switch
179 if (subopt_parse(arg
, subopts
) != 0) {
180 mp_msg( MSGT_VO
, MSGL_ERR
,
181 "\n-vo directfb command line help:\n"
182 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
183 "\nOptions (use 'no' prefix to disable):\n"
184 " input Use DirectFB for keyboard input\n"
187 " n=0..xx Use layer with id n for output (0=primary)\n"
188 " buffermode=(single|double|triple)\n"
189 " single Use single buffering\n"
190 " double Use double buffering\n"
191 " triple Use triple buffering\n"
192 " fieldparity=(top|bottom)\n"
193 " top Top field first\n"
194 " bottom Bottom field first\n"
196 " Specify a parameter list for DirectFB\n"
201 buffer_mode
= get_mode(&mode_str
);
203 field_parity
= get_parity(&par_str
);
206 if (dfb_params
.len
> 0)
209 char arg0
[10] = "mplayer";
210 char *arg1
= malloc(dfb_params
.len
+ 7);
216 strcpy(arg1
, "--dfb:");
217 strncat(arg1
, dfb_params
.str
, dfb_params
.len
);
223 DFBCHECK (DirectFBInit (&argc
,&a
));
228 DFBCHECK (DirectFBInit (NULL
,NULL
));
231 if (((directfb_major_version
<= 0) &&
232 (directfb_minor_version
<= 9) &&
233 (directfb_micro_version
< 15)))
235 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Unsupported DirectFB version\n");
243 // uncomment this if you do not wish to create a new VT for DirectFB
244 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
246 // uncomment this if you want to allow VT switching
247 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
249 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
250 DFBCHECK (DirectFBSetOption ("no-cursor",""));
253 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
259 DFBCHECK (DirectFBCreate (&dfb
));
266 ret
= dfb
->GetInputDevice (dfb
, DIDID_KEYBOARD
, &keyboard
);
268 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Keyboard init OK\n");
271 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Keyboard init FAILED\n");
277 * Create an input buffer for the keyboard.
279 if (keyboard
) DFBCHECK (keyboard
->CreateEventBuffer (keyboard
, &buffer
));
281 // just to start clean ...
282 if (buffer
) buffer
->Reset(buffer
);
284 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit OK\n");
290 DFBSurfacePixelFormat
convformat(uint32_t format
)
292 // add more formats !!!
294 case IMGFMT_RGB32
: return DSPF_RGB32
; break;
295 case IMGFMT_BGR32
: return DSPF_RGB32
; break;
296 case IMGFMT_RGB24
: return DSPF_RGB24
; break;
297 case IMGFMT_BGR24
: return DSPF_RGB24
; break;
298 case IMGFMT_RGB16
: return DSPF_RGB16
; break;
299 case IMGFMT_BGR16
: return DSPF_RGB16
; break;
300 case IMGFMT_RGB15
: return DSPF_ARGB1555
; break;
301 case IMGFMT_BGR15
: return DSPF_ARGB1555
; break;
302 case IMGFMT_RGB12
: return DSPF_ARGB4444
; break;
303 case IMGFMT_BGR12
: return DSPF_ARGB4444
; break;
304 case IMGFMT_YUY2
: return DSPF_YUY2
; break;
305 case IMGFMT_UYVY
: return DSPF_UYVY
; break;
306 case IMGFMT_YV12
: return DSPF_YV12
; break;
307 case IMGFMT_I420
: return DSPF_I420
; break;
308 // case IMGFMT_IYUV: return DSPF_IYUV; break;
309 case IMGFMT_RGB8
: return DSPF_RGB332
; break;
310 case IMGFMT_BGR8
: return DSPF_RGB332
; break;
317 typedef struct enum1_s
{
327 DFBEnumerationResult
test_format_callback( unsigned int id
,
328 DFBDisplayLayerDescription desc
,
331 enum1_t
*params
=(enum1_t
*)data
;
332 IDirectFBDisplayLayer
*layer
;
335 if ((layer_id
== -1 )||(layer_id
== id
)) {
337 ret
= dfb
->GetDisplayLayer( dfb
, id
, &layer
);
339 DirectFBError( "dfb->GetDisplayLayer failed", ret
);
342 DFBDisplayLayerConfig dlc
;
344 if (params
->setsize
) {
345 dlc
.flags
= DLCONF_WIDTH
|DLCONF_HEIGHT
;
346 dlc
.width
= params
->width
;
347 dlc
.height
= params
->height
;
348 layer
->SetConfiguration(layer
,&dlc
);
352 dlc
.flags
= DLCONF_PIXELFORMAT
;
353 dlc
.pixelformat
= convformat(params
->format
);
355 layer
->SetOpacity(layer
,0);
357 ret
= layer
->TestConfiguration(layer
,&dlc
,NULL
);
359 layer
->Release(layer
);
361 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
364 // printf("Test OK\n");
365 if (params
->result
) {
366 if ((!params
->scale
) && (desc
.caps
& DLCAPS_SCREEN_LOCATION
)) {
369 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
374 if (desc
.caps
& DLCAPS_SCREEN_LOCATION
) params
->scale
=1;
375 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
385 static int query_format(uint32_t format
)
387 int ret
= VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_OSD
; // osd should be removed the in future -> will be handled outside...
391 if (!convformat(format
)) return 0;
392 // temporarily disable YV12
393 // if (format == IMGFMT_YV12) return 0;
394 // if (format == IMGFMT_I420) return 0;
395 if (format
== IMGFMT_IYUV
) return 0;
397 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Format query: %s\n",vo_format_name(format
));
399 params
.format
=format
;
404 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
407 if (params
.scale
) ret
|=VFCAP_HWSCALE_UP
|VFCAP_HWSCALE_DOWN
;
414 typedef struct videomode_s
{
425 DFBEnumerationResult
video_modes_callback( int width
,int height
,int bpp
, void *data
)
427 videomode_t
*params
=(videomode_t
*)data
;
429 int overx
=0,overy
=0,closer
=0,over
=0;
432 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Validator entered %i %i %i\n",width,height,bpp);
434 overx
=width
-params
->out_width
;
435 overy
=height
-params
->out_height
;
437 if (!params
->width
) {
439 params
->height
=height
;
442 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Mode added %i %i %i\n",width
,height
,bpp
);
445 if ((params
->overy
<0)||(params
->overx
<0)) we_are_under
=1; // stored mode is smaller than req mode
446 if (abs(overx
*overy
)<abs(params
->overx
* params
->overy
)) closer
=1; // current mode is closer to desired res
447 if ((overx
>=0)&&(overy
>=0)) over
=1; // current mode is bigger or equaul to desired res
448 if ((closer
&& (over
|| we_are_under
)) || (we_are_under
&& over
)) {
450 params
->height
=height
;
453 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Better mode added %i %i %i\n",width
,height
,bpp
);
459 #define CONFIG_ERROR -1
461 static int config(uint32_t s_width
, uint32_t s_height
, uint32_t d_width
,
462 uint32_t d_height
, uint32_t flags
, char *title
,
471 int fs
= flags
& VOFLAG_FULLSCREEN
;
472 int vm
= flags
& VOFLAG_MODESWITCHING
;
474 DFBSurfaceDescription dsc
;
476 DFBDisplayLayerConfig dlc
;
477 DFBSurfaceCapabilities caps
;
481 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config entered [%ix%i]\n",s_width
,s_height
);
482 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: With requested format: %s\n",vo_format_name(format
));
486 frame
->Release(frame
);
491 primary
->Release(primary
);
496 layer
->Release(layer
);
505 params
.out_width
=d_width
;
506 params
.out_height
=d_height
;
526 default: params
.bpp
=0;
529 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - trying to change videomode\n");
530 DFBCHECK (dfb
->EnumVideoModes(dfb
,video_modes_callback
,¶ms
));
531 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,params
.bpp
);
533 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,24);
535 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,32);
537 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,16);
539 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,8);
546 // just to be sure clear primary layer
547 ret
= dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
);
549 ret
= layer
->GetSurface(layer
,&primary
);
551 primary
->Clear(primary
,0,0,0,0xff);
552 ret
= primary
->Flip(primary
,NULL
,0);
554 primary
->Clear(primary
,0,0,0,0xff);
556 primary
->Release(primary
);
559 layer
->Release(layer
);
565 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - looking for suitable layer\n");
566 params
.format
=format
;
569 params
.width
=s_width
;
570 params
.height
=s_height
;
573 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
575 if (!params
.result
) {
576 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - no suitable layer found\n");
577 params
.id
= DLID_PRIMARY
;
580 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - layer %i\n",params
.id
);
584 DFBCHECK (dfb
->GetDisplayLayer( dfb
, params
.id
, &layer
));
586 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - switching layer to exclusive mode\n");
587 ret
= layer
->SetCooperativeLevel (layer
, DLSCL_EXCLUSIVE
);
590 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");
591 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret
);
594 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (size)\n");
595 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
597 dlc
.height
= s_height
;
599 ret
= layer
->SetConfiguration(layer
,&dlc
);
602 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (size)\n");
603 DirectFBError("MPlayer - Layer size change.",ret
);
607 // look if we need to change the pixel format of the layer
608 // and just to be sure also fetch all layer properties
609 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
| DLCONF_OPTIONS
| DLCONF_BUFFERMODE
;
611 ret
= layer
->GetConfiguration(layer
,&dlc
);
613 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
;
616 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - could not get layer properties!\n");
618 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer reports format:%x\n",dlc
.pixelformat
);
621 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
623 dlc
.flags
= DLCONF_PIXELFORMAT
;
624 dlc
.pixelformat
= convformat(params
.format
);
626 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Desired pixelformat: %x\n",dlc
.pixelformat
);
628 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (format)\n");
629 ret
= layer
->SetConfiguration(layer
,&dlc
);
633 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc
.flags
);
634 DirectFBError("MPlayer - layer pixelformat change",ret
);
636 // ugly fbdev workaround - try to switch pixelformat via videomode change
637 switch (dlc
.pixelformat
) {
639 case DSPF_RGB32
: bpp
=32;break;
640 case DSPF_RGB24
: bpp
=24;break;
641 case DSPF_RGB16
: bpp
=16;break;
642 case DSPF_ARGB1555
: bpp
=15;break;
643 case DSPF_ARGB4444
: bpp
=12; break;
644 case DSPF_RGB332
: bpp
=8;break;
647 switch (dlc
.pixelformat
) {
655 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Trying to recover via videomode change (VM).\n");
657 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
658 if (DFB_OK
==layer
->GetConfiguration(layer
,&dlc
)) {
659 // try to set videomode
660 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Videomode %ix%i BPP %i\n",dlc
.width
,dlc
.height
,bpp
);
661 ret
= dfb
->SetVideoMode(dfb
,dlc
.width
,dlc
.height
,bpp
);
662 if (ret
) DirectFBError("MPlayer - VM - pixelformat change",ret
);
666 //get current pixel format
667 dlc
.flags
= DLCONF_PIXELFORMAT
;
668 ret
= layer
->GetConfiguration(layer
,&dlc
);
670 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret
);
672 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer now has pixelformat [%x]\n",dlc
.pixelformat
);
675 // check if we were succesful
676 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
677 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Recovery failed!.\n");
683 default: return CONFIG_ERROR
;
690 // try triple, double... buffering
692 dlc
.flags
= DLCONF_BUFFERMODE
;
694 if (buffer_mode
> 2) {
695 dlc
.buffermode
= DLBM_TRIPLE
;
696 ret
= layer
->SetConfiguration( layer
, &dlc
);
703 if (buffer_mode
> 1) {
704 dlc
.buffermode
= DLBM_BACKVIDEO
;
705 ret
= layer
->SetConfiguration( layer
, &dlc
);
707 dlc
.buffermode
= DLBM_BACKSYSTEM
;
708 ret
= layer
->SetConfiguration( layer
, &dlc
);
712 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Double buffering is active\n");
716 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Triple buffering is active\n");
720 if (field_parity
!= -1) {
721 dlc
.flags
= DLCONF_OPTIONS
;
722 ret
= layer
->GetConfiguration( layer
, &dlc
);
724 dlc
.options
|= DLOP_FIELD_PARITY
;
725 ret
= layer
->SetConfiguration( layer
, &dlc
);
727 layer
->SetFieldParity( layer
, field_parity
);
731 mp_msg( MSGT_VO
, MSGL_DBG2
, "DirectFB: Requested field parity: ");
732 switch (field_parity
) {
734 mp_msg( MSGT_VO
, MSGL_DBG2
, "Don't care\n");
737 mp_msg( MSGT_VO
, MSGL_DBG2
, "Top field first\n");
740 mp_msg( MSGT_VO
, MSGL_DBG2
, "Bottom field first\n");
746 ret
= layer
->GetSurface(layer
,&primary
);
749 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - could not get surface\n");
750 return CONFIG_ERROR
; // what shall we report on failure?
753 // test surface for flipping
754 DFBCHECK(primary
->GetCapabilities(primary
,&caps
));
755 primary
->Clear(primary
,0,0,0,0xff);
757 if (caps
& (DSCAPS_FLIPPING
762 ret
= primary
->Flip(primary
,NULL
,0);
765 primary
->Clear(primary
,0,0,0,0xff);
767 // if we have 3 buffers clean once more
768 if (caps
& DSCAPS_TRIPLE
) {
769 primary
->Flip(primary
,NULL
,0);
770 primary
->Clear(primary
,0,0,0,0xff);
777 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - flipping = %i\n",flipping
);
779 // is scale needed ? Aspect ratio and layer pos/size
783 DFBCHECK(primary
->GetSize(primary
,&width
,&height
));
785 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - surface size = %ix%i\n",width
,height
);
787 aspect_save_orig(s_width
,s_height
);
788 aspect_save_prescale(d_width
,d_height
);
790 aspect_save_screenres(10000,10000);
791 aspect(&out_width
,&out_height
,A_ZOOM
);
793 ret
= layer
->SetScreenLocation(layer
,(1-(float)out_width
/10000)/2,(1-(float)out_height
/10000)/2,((float)out_width
/10000),((float)out_height
/10000));
795 if (ret
) mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (position)\n");
802 aspect_save_screenres(width
,height
);
805 aspect(&out_width
,&out_height
,A_ZOOM
);
807 aspect(&out_width
,&out_height
,A_NOZOOM
);
810 xoffset
= (width
- out_width
) / 2;
811 yoffset
= (height
- out_height
) / 2;
814 if (((s_width
==out_width
)&&(s_height
==out_height
)) || (params
.scale
)) {
821 // temporary buffer in case of not flipping or scaling
822 if ((!flipping
) || stretch
) {
824 DFBCHECK (primary
->GetPixelFormat (primary
, &dsc
.pixelformat
));
826 dsc
.flags
= DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
| DSDESC_WIDTH
;
829 dsc
.height
= s_height
;
831 DFBCHECK (dfb
->CreateSurface( dfb
, &dsc
, &frame
));
832 DFBCHECK(frame
->GetSize(frame
,&width
,&height
));
833 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Frame is active.\n");
836 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
838 DFBCHECK (frame
->GetPixelFormat(frame
,&pixel_format
));
840 DFBCHECK (primary
->GetPixelFormat(primary
,&pixel_format
));
843 // finally turn on layer
844 layer
->SetOpacity(layer
,255);
846 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height);
851 #include "osdep/keycodes.h"
853 static void check_events(void)
860 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events entered\n");
861 if (buffer
->GetEvent(buffer
, DFB_EVENT (&event
)) == DFB_OK
) {
863 if (event
.type
== DIET_KEYPRESS
) {
864 switch (event
.key_symbol
) {
866 mplayer_put_key(KEY_ESC
);
868 case DIKS_PAGE_UP
: mplayer_put_key(KEY_PAGE_UP
);break;
869 case DIKS_PAGE_DOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
870 case DIKS_CURSOR_UP
: mplayer_put_key(KEY_UP
);break;
871 case DIKS_CURSOR_DOWN
: mplayer_put_key(KEY_DOWN
);break;
872 case DIKS_CURSOR_LEFT
: mplayer_put_key(KEY_LEFT
);break;
873 case DIKS_CURSOR_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
874 case DIKS_INSERT
: mplayer_put_key(KEY_INSERT
);break;
875 case DIKS_DELETE
: mplayer_put_key(KEY_DELETE
);break;
876 case DIKS_HOME
: mplayer_put_key(KEY_HOME
);break;
877 case DIKS_END
: mplayer_put_key(KEY_END
);break;
879 default:mplayer_put_key(event
.key_symbol
);
883 // empty buffer, because of repeating (keyboard repeat is faster than key handling
884 // and this causes problems during seek)
885 // temporary workaround should be solved in the future
886 buffer
->Reset(buffer
);
889 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events finished\n");
892 static void flip_page(void)
894 DFBSurfaceBlittingFlags flags
=DSBLIT_NOFX
;
896 unlock(); // unlock frame & primary
898 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Flip page entered");
900 DFBCHECK (primary
->SetBlittingFlags(primary
,flags
));
910 DFBCHECK (primary
->StretchBlit(primary
,frame
,NULL
,&rect
));
914 DFBCHECK (primary
->Blit(primary
,frame
,NULL
,xoffset
,yoffset
));
922 case 1: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAIT
));
924 case 2: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_ONSYNC
));
926 default:; // should never be reached
930 DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAITFORSYNC
));
938 static void uninit(void)
941 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit entered\n");
949 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing buffer\n");
950 if (buffer) buffer->Release (buffer);
951 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing keyboard\n");
952 if (keyboard) keyboard->Release (keyboard);
955 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing frame\n");
956 frame
->Release (frame
);
961 // if (layer) layer->SetOpacity(layer,0);
964 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing layer\n");
965 layer
->Release(layer
);
970 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing primary\n");
971 primary
->Release (primary
);
976 /* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n");
980 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");
984 static uint32_t directfb_set_video_eq(char *data
, int value
) //data==name
987 DFBColorAdjustment ca
;
988 float factor
= (float)0xffff / 200.0;
990 DFBDisplayLayerDescription desc
;
996 layer
->GetDescription(layer
,&desc
);
1000 if (! strcmp( data
,"brightness" )) {
1001 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1002 ca
.brightness
= value
* factor
+0x8000;
1003 ca
.flags
|= DCAF_BRIGHTNESS
;
1004 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Brightness 0x%X %i\n",ca
.brightness
,value
);
1005 } else return VO_FALSE
;
1008 if (! strcmp( data
,"contrast" )) {
1009 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1010 ca
.contrast
= value
* factor
+ 0x8000;
1011 ca
.flags
|= DCAF_CONTRAST
;
1012 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Contrast 0x%X %i\n",ca
.contrast
,value
);
1013 } else return VO_FALSE
;
1016 if (! strcmp( data
,"hue" )) {
1017 if ((desc
.caps
& DLCAPS_HUE
)) {
1018 ca
.hue
= value
* factor
+ 0x8000;
1019 ca
.flags
|= DCAF_HUE
;
1020 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Hue 0x%X %i\n",ca
.hue
,value
);
1021 } else return VO_FALSE
;
1024 if (! strcmp( data
,"saturation" )) {
1025 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1026 ca
.saturation
= value
* factor
+ 0x8000;
1027 ca
.flags
|= DCAF_SATURATION
;
1028 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Saturation 0x%X %i\n",ca
.saturation
,value
);
1029 } else return VO_FALSE
;
1032 if (ca
.flags
!= DCAF_NONE
) {
1033 layer
->SetColorAdjustment(layer
,&ca
);
1042 static uint32_t directfb_get_video_eq(char *data
, int *value
) // data==name
1045 DFBColorAdjustment ca
;
1046 float factor
= 200.0 / (float)0xffff;
1048 DFBDisplayLayerDescription desc
;
1054 layer
->GetDescription(layer
,&desc
);
1056 layer
->GetColorAdjustment(layer
,&ca
);
1058 if (! strcmp( data
,"brightness" )) {
1059 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1060 *value
= (int) ((ca
.brightness
-0x8000) * factor
);
1061 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Brightness 0x%X %i\n",ca
.brightness
,*value
);
1063 } else return VO_FALSE
;
1066 if (! strcmp( data
,"contrast" )) {
1067 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1068 *value
= (int) ((ca
.contrast
-0x8000) * factor
);
1069 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Contrast 0x%X %i\n",ca
.contrast
,*value
);
1071 } else return VO_FALSE
;
1074 if (! strcmp( data
,"hue" )) {
1075 if ((desc
.caps
& DLCAPS_HUE
)) {
1076 *value
= (int) ((ca
.hue
-0x8000) * factor
);
1077 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Hue 0x%X %i\n",ca
.hue
,*value
);
1079 } else return VO_FALSE
;
1082 if (! strcmp( data
,"saturation" )) {
1083 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1084 *value
= (int) ((ca
.saturation
-0x8000) * factor
);
1085 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Saturation 0x%X %i\n",ca
.saturation
,*value
);
1087 } else return VO_FALSE
;
1093 static uint32_t get_image(mp_image_t
*mpi
)
1100 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n");
1101 if(mpi
->flags
&MP_IMGFLAG_READABLE
) return VO_FALSE
; // slow video ram
1102 if(mpi
->type
==MP_IMGTYPE_STATIC
) return VO_FALSE
; // it is not static
1104 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1106 if(mpi
->flags
&(MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_ACCEPT_WIDTH
)){
1107 // we're lucky or codec accepts stride => ok, let's go!
1110 err
= frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
);
1113 err
= primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
);
1118 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: DR lock failed!");
1122 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1125 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
1126 mpi
->planes
[1]=dst
+ pitch
*height
;
1127 mpi
->planes
[2]=mpi
->planes
[1] + pitch
*height
/4;
1129 mpi
->planes
[2]=dst
+ pitch
*height
;
1130 mpi
->planes
[1]=mpi
->planes
[2] + pitch
*height
/4;
1133 mpi
->stride
[0]=pitch
;
1134 mpi
->stride
[1]=mpi
->stride
[2]=pitch
/2;
1136 //YUY2 and RGB formats
1139 mpi
->stride
[0]=pitch
;
1145 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1146 mpi
->planes
[0]= dst
+ yoffset
* pitch
+ xoffset
;
1147 mpi
->planes
[1]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1148 mpi
->planes
[2]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1150 mpi
->planes
[0]=dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3);
1154 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1155 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1162 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1171 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1176 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1179 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1183 p
= FFMIN(w
, pitch
);
1186 dst2
= dst
+ pitch
*height
- y
*pitch
+ y
*pitch
/4 - x
/2;
1190 fast_memcpy(dst
,srcp
,p
);
1195 if (pixel_format
== DSPF_YV12
) {
1201 for (i
=0;i
<h
/2;i
++) {
1202 fast_memcpy(dst
,srcp
,p
);
1207 dst
= dst2
+ pitch
*height
/4;
1210 for (i
=0;i
<h
/2;i
++) {
1211 fast_memcpy(dst
,srcp
,p
);
1222 for (i
=0;i
<h
/2;i
++) {
1223 fast_memcpy(dst
,srcp
,p
);
1228 dst
= dst2
+ pitch
*height
/4;
1231 for (i
=0;i
<h
/2;i
++) {
1232 fast_memcpy(dst
,srcp
,p
);
1245 static uint32_t put_image(mp_image_t
*mpi
){
1248 // static IDirectFBSurface *tmp = NULL;
1249 // DFBSurfaceDescription dsc;
1250 // DFBRectangle rect;
1252 // 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);
1257 if((mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))) {
1258 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing to do\n");
1262 if (mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1263 // memcpy all planes - sad but necessary
1270 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1272 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1275 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1279 p
= FFMIN(mpi
->w
, pitch
);
1281 src
= mpi
->planes
[0]+mpi
->y
*mpi
->stride
[0]+mpi
->x
;
1283 for (i
=0;i
<mpi
->h
;i
++) {
1284 fast_memcpy(dst
+i
*pitch
,src
+i
*mpi
->stride
[0],p
);
1288 if (pixel_format
== DSPF_YV12
) {
1290 dst
+= pitch
*height
;
1292 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1294 for (i
=0;i
<mpi
->h
/2;i
++) {
1295 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1298 dst
+= pitch
*height
/4;
1299 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1301 for (i
=0;i
<mpi
->h
/2;i
++) {
1302 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1307 dst
+= pitch
*height
;
1309 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1311 for (i
=0;i
<mpi
->h
/2;i
++) {
1312 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1315 dst
+= pitch
*height
/4;
1316 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1318 for (i
=0;i
<mpi
->h
/2;i
++) {
1319 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1326 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1329 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1330 dsc.preallocated[0].data = mpi->planes[0];
1331 dsc.preallocated[0].pitch = mpi->stride[0];
1332 dsc.width = mpi->width;
1333 dsc.height = mpi->height;
1334 dsc.pixelformat = convformat(mpi->imgfmt);
1336 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1344 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1346 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1354 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non-planar branch\n");
1356 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1358 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]);
1360 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1362 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]);
1372 static int control(uint32_t request
, void *data
)
1375 case VOCTRL_QUERY_FORMAT
:
1376 return query_format(*((uint32_t*)data
));
1377 case VOCTRL_GET_IMAGE
:
1378 return get_image(data
);
1379 case VOCTRL_DRAW_IMAGE
:
1380 return put_image(data
);
1381 case VOCTRL_SET_EQUALIZER
:
1383 struct voctrl_set_equalizer_args
*args
= data
;
1384 return directfb_set_video_eq(args
->name
, args
->value
);
1386 case VOCTRL_GET_EQUALIZER
:
1388 struct voctrl_get_equalizer_args
*args
= data
;
1389 return directfb_get_video_eq(args
->name
, args
->valueptr
);
1397 static int draw_frame(uint8_t *src
[])
1402 // hopefully will be removed soon
1404 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
1405 unsigned char *srca
, int stride
)
1410 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1413 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1416 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1420 switch(pixel_format
) {
1423 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 4*x0
,pitch
);
1427 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 3*x0
,pitch
);
1431 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1434 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1437 vo_draw_alpha_rgb12(w
, h
, src
, srca
, stride
,
1438 ((uint8_t *) dst
) + pitch
* y0
+ 2 * x0
,
1443 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
,pitch
);
1447 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
+ 1,pitch
);
1452 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 1*x0
,pitch
);
1459 static void draw_osd(void)
1461 vo_draw_text(width
,height
,draw_alpha
);