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 ******************************/
125 static void unlock(void)
127 if (frame
&& framelocked
) frame
->Unlock(frame
);
128 if (primary
&& primarylocked
) primary
->Unlock(primary
);
131 static int get_parity(strarg_t
*arg
) {
132 if (strargcmp(arg
, "top") == 0)
134 if (strargcmp(arg
, "bottom") == 0)
139 static int check_parity(void *arg
) {
140 return get_parity(arg
) != -1;
143 static int get_mode(strarg_t
*arg
) {
144 if (strargcmp(arg
, "single") == 0)
146 if (strargcmp(arg
, "double") == 0)
148 if (strargcmp(arg
, "triple") == 0)
153 static int check_mode(void *arg
) {
154 return get_mode(arg
) != 0;
157 static int preinit(const char *arg
)
160 strarg_t mode_str
= {0, NULL
};
161 strarg_t par_str
= {0, NULL
};
162 strarg_t dfb_params
= {0, NULL
};
163 const opt_t subopts
[] = {
164 {"input", OPT_ARG_BOOL
, &use_input
, NULL
},
165 {"buffermode", OPT_ARG_STR
, &mode_str
, check_mode
},
166 {"fieldparity", OPT_ARG_STR
, &par_str
, check_parity
},
167 {"layer", OPT_ARG_INT
, &layer_id
, NULL
},
168 {"dfbopts", OPT_ARG_STR
, &dfb_params
, NULL
},
172 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
174 if (dfb
) return 0; // we are already initialized!
177 buffer_mode
= 1 + vo_doublebuffering
; // honor -double switch
181 if (subopt_parse(arg
, subopts
) != 0) {
182 mp_msg( MSGT_VO
, MSGL_ERR
,
183 "\n-vo directfb command line help:\n"
184 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
185 "\nOptions (use 'no' prefix to disable):\n"
186 " input Use DirectFB for keyboard input\n"
189 " n=0..xx Use layer with id n for output (0=primary)\n"
190 " buffermode=(single|double|triple)\n"
191 " single Use single buffering\n"
192 " double Use double buffering\n"
193 " triple Use triple buffering\n"
194 " fieldparity=(top|bottom)\n"
195 " top Top field first\n"
196 " bottom Bottom field first\n"
198 " Specify a parameter list for DirectFB\n"
203 buffer_mode
= get_mode(&mode_str
);
205 field_parity
= get_parity(&par_str
);
208 if (dfb_params
.len
> 0)
211 char arg0
[10] = "mplayer";
212 char *arg1
= malloc(dfb_params
.len
+ 7);
218 strcpy(arg1
, "--dfb:");
219 strncat(arg1
, dfb_params
.str
, dfb_params
.len
);
225 DFBCHECK (DirectFBInit (&argc
,&a
));
230 DFBCHECK (DirectFBInit (NULL
,NULL
));
233 if (((directfb_major_version
<= 0) &&
234 (directfb_minor_version
<= 9) &&
235 (directfb_micro_version
< 15)))
237 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Unsupported DirectFB version\n");
245 // uncomment this if you do not wish to create a new VT for DirectFB
246 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
248 // uncomment this if you want to allow VT switching
249 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
251 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
252 DFBCHECK (DirectFBSetOption ("no-cursor",""));
255 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
261 DFBCHECK (DirectFBCreate (&dfb
));
268 ret
= dfb
->GetInputDevice (dfb
, DIDID_KEYBOARD
, &keyboard
);
270 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Keyboard init OK\n");
273 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Keyboard init FAILED\n");
279 * Create an input buffer for the keyboard.
281 if (keyboard
) DFBCHECK (keyboard
->CreateEventBuffer (keyboard
, &buffer
));
283 // just to start clean ...
284 if (buffer
) buffer
->Reset(buffer
);
286 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit OK\n");
292 static DFBSurfacePixelFormat
convformat(uint32_t format
)
294 // add more formats !!!
296 case IMGFMT_RGB32
: return DSPF_RGB32
; break;
297 case IMGFMT_BGR32
: return DSPF_RGB32
; break;
298 case IMGFMT_RGB24
: return DSPF_RGB24
; break;
299 case IMGFMT_BGR24
: return DSPF_RGB24
; break;
300 case IMGFMT_RGB16
: return DSPF_RGB16
; break;
301 case IMGFMT_BGR16
: return DSPF_RGB16
; break;
302 case IMGFMT_RGB15
: return DSPF_ARGB1555
; break;
303 case IMGFMT_BGR15
: return DSPF_ARGB1555
; break;
304 case IMGFMT_RGB12
: return DSPF_ARGB4444
; break;
305 case IMGFMT_BGR12
: return DSPF_ARGB4444
; break;
306 case IMGFMT_YUY2
: return DSPF_YUY2
; break;
307 case IMGFMT_UYVY
: return DSPF_UYVY
; break;
308 case IMGFMT_YV12
: return DSPF_YV12
; break;
309 case IMGFMT_I420
: return DSPF_I420
; break;
310 // case IMGFMT_IYUV: return DSPF_IYUV; break;
311 case IMGFMT_RGB8
: return DSPF_RGB332
; break;
312 case IMGFMT_BGR8
: return DSPF_RGB332
; break;
319 typedef struct enum1_s
{
329 static DFBEnumerationResult
test_format_callback(unsigned int id
,
330 DFBDisplayLayerDescription desc
,
333 enum1_t
*params
=(enum1_t
*)data
;
334 IDirectFBDisplayLayer
*layer
;
337 if ((layer_id
== -1 )||(layer_id
== id
)) {
339 ret
= dfb
->GetDisplayLayer( dfb
, id
, &layer
);
341 DirectFBError( "dfb->GetDisplayLayer failed", ret
);
344 DFBDisplayLayerConfig dlc
;
346 if (params
->setsize
) {
347 dlc
.flags
= DLCONF_WIDTH
|DLCONF_HEIGHT
;
348 dlc
.width
= params
->width
;
349 dlc
.height
= params
->height
;
350 layer
->SetConfiguration(layer
,&dlc
);
354 dlc
.flags
= DLCONF_PIXELFORMAT
;
355 dlc
.pixelformat
= convformat(params
->format
);
357 layer
->SetOpacity(layer
,0);
359 ret
= layer
->TestConfiguration(layer
,&dlc
,NULL
);
361 layer
->Release(layer
);
363 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
366 // printf("Test OK\n");
367 if (params
->result
) {
368 if ((!params
->scale
) && (desc
.caps
& DLCAPS_SCREEN_LOCATION
)) {
371 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
376 if (desc
.caps
& DLCAPS_SCREEN_LOCATION
) params
->scale
=1;
377 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
387 static int query_format(uint32_t format
)
389 int ret
= VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_OSD
; // osd should be removed the in future -> will be handled outside...
393 if (!convformat(format
)) return 0;
394 // temporarily disable YV12
395 // if (format == IMGFMT_YV12) return 0;
396 // if (format == IMGFMT_I420) return 0;
397 if (format
== IMGFMT_IYUV
) return 0;
399 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Format query: %s\n",vo_format_name(format
));
401 params
.format
=format
;
406 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
409 if (params
.scale
) ret
|=VFCAP_HWSCALE_UP
|VFCAP_HWSCALE_DOWN
;
416 typedef struct videomode_s
{
427 static DFBEnumerationResult
video_modes_callback(int width
, int height
,
430 videomode_t
*params
=(videomode_t
*)data
;
432 int overx
=0,overy
=0,closer
=0,over
=0;
435 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Validator entered %i %i %i\n",width,height,bpp);
437 overx
=width
-params
->out_width
;
438 overy
=height
-params
->out_height
;
440 if (!params
->width
) {
442 params
->height
=height
;
445 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Mode added %i %i %i\n",width
,height
,bpp
);
448 if ((params
->overy
<0)||(params
->overx
<0)) we_are_under
=1; // stored mode is smaller than req mode
449 if (abs(overx
*overy
)<abs(params
->overx
* params
->overy
)) closer
=1; // current mode is closer to desired res
450 if ((overx
>=0)&&(overy
>=0)) over
=1; // current mode is bigger or equaul to desired res
451 if ((closer
&& (over
|| we_are_under
)) || (we_are_under
&& over
)) {
453 params
->height
=height
;
456 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Better mode added %i %i %i\n",width
,height
,bpp
);
462 #define CONFIG_ERROR -1
464 static int config(uint32_t s_width
, uint32_t s_height
, uint32_t d_width
,
465 uint32_t d_height
, uint32_t flags
, char *title
,
474 int fs
= flags
& VOFLAG_FULLSCREEN
;
475 int vm
= flags
& VOFLAG_MODESWITCHING
;
477 DFBSurfaceDescription dsc
;
479 DFBDisplayLayerConfig dlc
;
480 DFBSurfaceCapabilities caps
;
484 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config entered [%ix%i]\n",s_width
,s_height
);
485 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: With requested format: %s\n",vo_format_name(format
));
489 frame
->Release(frame
);
494 primary
->Release(primary
);
499 layer
->Release(layer
);
508 params
.out_width
=d_width
;
509 params
.out_height
=d_height
;
529 default: params
.bpp
=0;
532 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - trying to change videomode\n");
533 DFBCHECK (dfb
->EnumVideoModes(dfb
,video_modes_callback
,¶ms
));
534 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,params
.bpp
);
536 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,24);
538 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,32);
540 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,16);
542 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,8);
549 // just to be sure clear primary layer
550 ret
= dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
);
552 ret
= layer
->GetSurface(layer
,&primary
);
554 primary
->Clear(primary
,0,0,0,0xff);
555 ret
= primary
->Flip(primary
,NULL
,0);
557 primary
->Clear(primary
,0,0,0,0xff);
559 primary
->Release(primary
);
562 layer
->Release(layer
);
568 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - looking for suitable layer\n");
569 params
.format
=format
;
572 params
.width
=s_width
;
573 params
.height
=s_height
;
576 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
578 if (!params
.result
) {
579 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - no suitable layer found\n");
580 params
.id
= DLID_PRIMARY
;
583 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - layer %i\n",params
.id
);
587 DFBCHECK (dfb
->GetDisplayLayer( dfb
, params
.id
, &layer
));
589 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - switching layer to exclusive mode\n");
590 ret
= layer
->SetCooperativeLevel (layer
, DLSCL_EXCLUSIVE
);
593 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");
594 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret
);
597 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (size)\n");
598 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
600 dlc
.height
= s_height
;
602 ret
= layer
->SetConfiguration(layer
,&dlc
);
605 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (size)\n");
606 DirectFBError("MPlayer - Layer size change.",ret
);
610 // look if we need to change the pixel format of the layer
611 // and just to be sure also fetch all layer properties
612 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
| DLCONF_OPTIONS
| DLCONF_BUFFERMODE
;
614 ret
= layer
->GetConfiguration(layer
,&dlc
);
616 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
;
619 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - could not get layer properties!\n");
621 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer reports format:%x\n",dlc
.pixelformat
);
624 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
626 dlc
.flags
= DLCONF_PIXELFORMAT
;
627 dlc
.pixelformat
= convformat(params
.format
);
629 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Desired pixelformat: %x\n",dlc
.pixelformat
);
631 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (format)\n");
632 ret
= layer
->SetConfiguration(layer
,&dlc
);
636 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc
.flags
);
637 DirectFBError("MPlayer - layer pixelformat change",ret
);
639 // ugly fbdev workaround - try to switch pixelformat via videomode change
640 switch (dlc
.pixelformat
) {
642 case DSPF_RGB32
: bpp
=32;break;
643 case DSPF_RGB24
: bpp
=24;break;
644 case DSPF_RGB16
: bpp
=16;break;
645 case DSPF_ARGB1555
: bpp
=15;break;
646 case DSPF_ARGB4444
: bpp
=12; break;
647 case DSPF_RGB332
: bpp
=8;break;
650 switch (dlc
.pixelformat
) {
658 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Trying to recover via videomode change (VM).\n");
660 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
661 if (DFB_OK
==layer
->GetConfiguration(layer
,&dlc
)) {
662 // try to set videomode
663 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Videomode %ix%i BPP %i\n",dlc
.width
,dlc
.height
,bpp
);
664 ret
= dfb
->SetVideoMode(dfb
,dlc
.width
,dlc
.height
,bpp
);
665 if (ret
) DirectFBError("MPlayer - VM - pixelformat change",ret
);
669 //get current pixel format
670 dlc
.flags
= DLCONF_PIXELFORMAT
;
671 ret
= layer
->GetConfiguration(layer
,&dlc
);
673 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret
);
675 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer now has pixelformat [%x]\n",dlc
.pixelformat
);
678 // check if we were succesful
679 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
680 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Recovery failed!.\n");
686 default: return CONFIG_ERROR
;
693 // try triple, double... buffering
695 dlc
.flags
= DLCONF_BUFFERMODE
;
697 if (buffer_mode
> 2) {
698 dlc
.buffermode
= DLBM_TRIPLE
;
699 ret
= layer
->SetConfiguration( layer
, &dlc
);
706 if (buffer_mode
> 1) {
707 dlc
.buffermode
= DLBM_BACKVIDEO
;
708 ret
= layer
->SetConfiguration( layer
, &dlc
);
710 dlc
.buffermode
= DLBM_BACKSYSTEM
;
711 ret
= layer
->SetConfiguration( layer
, &dlc
);
715 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Double buffering is active\n");
719 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Triple buffering is active\n");
723 if (field_parity
!= -1) {
724 dlc
.flags
= DLCONF_OPTIONS
;
725 ret
= layer
->GetConfiguration( layer
, &dlc
);
727 dlc
.options
|= DLOP_FIELD_PARITY
;
728 ret
= layer
->SetConfiguration( layer
, &dlc
);
730 layer
->SetFieldParity( layer
, field_parity
);
734 mp_msg( MSGT_VO
, MSGL_DBG2
, "DirectFB: Requested field parity: ");
735 switch (field_parity
) {
737 mp_msg( MSGT_VO
, MSGL_DBG2
, "Don't care\n");
740 mp_msg( MSGT_VO
, MSGL_DBG2
, "Top field first\n");
743 mp_msg( MSGT_VO
, MSGL_DBG2
, "Bottom field first\n");
749 ret
= layer
->GetSurface(layer
,&primary
);
752 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - could not get surface\n");
753 return CONFIG_ERROR
; // what shall we report on failure?
756 // test surface for flipping
757 DFBCHECK(primary
->GetCapabilities(primary
,&caps
));
758 primary
->Clear(primary
,0,0,0,0xff);
760 if (caps
& (DSCAPS_FLIPPING
765 ret
= primary
->Flip(primary
,NULL
,0);
768 primary
->Clear(primary
,0,0,0,0xff);
770 // if we have 3 buffers clean once more
771 if (caps
& DSCAPS_TRIPLE
) {
772 primary
->Flip(primary
,NULL
,0);
773 primary
->Clear(primary
,0,0,0,0xff);
780 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - flipping = %i\n",flipping
);
782 // is scale needed ? Aspect ratio and layer pos/size
786 DFBCHECK(primary
->GetSize(primary
,&width
,&height
));
788 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - surface size = %ix%i\n",width
,height
);
790 aspect_save_orig(s_width
,s_height
);
791 aspect_save_prescale(d_width
,d_height
);
793 aspect_save_screenres(10000,10000);
794 aspect(&out_width
,&out_height
,A_ZOOM
);
796 ret
= layer
->SetScreenLocation(layer
,(1-(float)out_width
/10000)/2,(1-(float)out_height
/10000)/2,((float)out_width
/10000),((float)out_height
/10000));
798 if (ret
) mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (position)\n");
805 aspect_save_screenres(width
,height
);
808 aspect(&out_width
,&out_height
,A_ZOOM
);
810 aspect(&out_width
,&out_height
,A_NOZOOM
);
813 xoffset
= (width
- out_width
) / 2;
814 yoffset
= (height
- out_height
) / 2;
817 if (((s_width
==out_width
)&&(s_height
==out_height
)) || (params
.scale
)) {
824 // temporary buffer in case of not flipping or scaling
825 if ((!flipping
) || stretch
) {
827 DFBCHECK (primary
->GetPixelFormat (primary
, &dsc
.pixelformat
));
829 dsc
.flags
= DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
| DSDESC_WIDTH
;
832 dsc
.height
= s_height
;
834 DFBCHECK (dfb
->CreateSurface( dfb
, &dsc
, &frame
));
835 DFBCHECK(frame
->GetSize(frame
,&width
,&height
));
836 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Frame is active.\n");
839 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
841 DFBCHECK (frame
->GetPixelFormat(frame
,&pixel_format
));
843 DFBCHECK (primary
->GetPixelFormat(primary
,&pixel_format
));
846 // finally turn on layer
847 layer
->SetOpacity(layer
,255);
849 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height);
854 static void check_events(void)
861 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events entered\n");
862 if (buffer
->GetEvent(buffer
, DFB_EVENT (&event
)) == DFB_OK
) {
864 if (event
.type
== DIET_KEYPRESS
) {
865 switch (event
.key_symbol
) {
867 mplayer_put_key(KEY_ESC
);
869 case DIKS_PAGE_UP
: mplayer_put_key(KEY_PAGE_UP
);break;
870 case DIKS_PAGE_DOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
871 case DIKS_CURSOR_UP
: mplayer_put_key(KEY_UP
);break;
872 case DIKS_CURSOR_DOWN
: mplayer_put_key(KEY_DOWN
);break;
873 case DIKS_CURSOR_LEFT
: mplayer_put_key(KEY_LEFT
);break;
874 case DIKS_CURSOR_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
875 case DIKS_INSERT
: mplayer_put_key(KEY_INSERT
);break;
876 case DIKS_DELETE
: mplayer_put_key(KEY_DELETE
);break;
877 case DIKS_HOME
: mplayer_put_key(KEY_HOME
);break;
878 case DIKS_END
: mplayer_put_key(KEY_END
);break;
880 default:mplayer_put_key(event
.key_symbol
);
884 // empty buffer, because of repeating (keyboard repeat is faster than key handling
885 // and this causes problems during seek)
886 // temporary workaround should be solved in the future
887 buffer
->Reset(buffer
);
890 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events finished\n");
893 static void flip_page(void)
895 DFBSurfaceBlittingFlags flags
=DSBLIT_NOFX
;
897 unlock(); // unlock frame & primary
899 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Flip page entered");
901 DFBCHECK (primary
->SetBlittingFlags(primary
,flags
));
911 DFBCHECK (primary
->StretchBlit(primary
,frame
,NULL
,&rect
));
915 DFBCHECK (primary
->Blit(primary
,frame
,NULL
,xoffset
,yoffset
));
923 case 1: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAIT
));
925 case 2: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_ONSYNC
));
927 default:; // should never be reached
931 DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAITFORSYNC
));
939 static void uninit(void)
942 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit entered\n");
950 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing buffer\n");
951 if (buffer) buffer->Release (buffer);
952 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing keyboard\n");
953 if (keyboard) keyboard->Release (keyboard);
956 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing frame\n");
957 frame
->Release (frame
);
962 // if (layer) layer->SetOpacity(layer,0);
965 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing layer\n");
966 layer
->Release(layer
);
971 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing primary\n");
972 primary
->Release (primary
);
977 /* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n");
981 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");
985 static uint32_t directfb_set_video_eq(const char *data
, int value
) //data==name
988 DFBColorAdjustment ca
;
989 float factor
= (float)0xffff / 200.0;
991 DFBDisplayLayerDescription desc
;
997 layer
->GetDescription(layer
,&desc
);
1001 if (! strcmp( data
,"brightness" )) {
1002 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1003 ca
.brightness
= value
* factor
+0x8000;
1004 ca
.flags
|= DCAF_BRIGHTNESS
;
1005 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Brightness 0x%X %i\n",ca
.brightness
,value
);
1006 } else return VO_FALSE
;
1009 if (! strcmp( data
,"contrast" )) {
1010 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1011 ca
.contrast
= value
* factor
+ 0x8000;
1012 ca
.flags
|= DCAF_CONTRAST
;
1013 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Contrast 0x%X %i\n",ca
.contrast
,value
);
1014 } else return VO_FALSE
;
1017 if (! strcmp( data
,"hue" )) {
1018 if ((desc
.caps
& DLCAPS_HUE
)) {
1019 ca
.hue
= value
* factor
+ 0x8000;
1020 ca
.flags
|= DCAF_HUE
;
1021 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Hue 0x%X %i\n",ca
.hue
,value
);
1022 } else return VO_FALSE
;
1025 if (! strcmp( data
,"saturation" )) {
1026 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1027 ca
.saturation
= value
* factor
+ 0x8000;
1028 ca
.flags
|= DCAF_SATURATION
;
1029 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Saturation 0x%X %i\n",ca
.saturation
,value
);
1030 } else return VO_FALSE
;
1033 if (ca
.flags
!= DCAF_NONE
) {
1034 layer
->SetColorAdjustment(layer
,&ca
);
1043 static uint32_t directfb_get_video_eq(const char *data
, int *value
) // data==name
1046 DFBColorAdjustment ca
;
1047 float factor
= 200.0 / (float)0xffff;
1049 DFBDisplayLayerDescription desc
;
1055 layer
->GetDescription(layer
,&desc
);
1057 layer
->GetColorAdjustment(layer
,&ca
);
1059 if (! strcmp( data
,"brightness" )) {
1060 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1061 *value
= (int) ((ca
.brightness
-0x8000) * factor
);
1062 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Brightness 0x%X %i\n",ca
.brightness
,*value
);
1064 } else return VO_FALSE
;
1067 if (! strcmp( data
,"contrast" )) {
1068 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1069 *value
= (int) ((ca
.contrast
-0x8000) * factor
);
1070 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Contrast 0x%X %i\n",ca
.contrast
,*value
);
1072 } else return VO_FALSE
;
1075 if (! strcmp( data
,"hue" )) {
1076 if ((desc
.caps
& DLCAPS_HUE
)) {
1077 *value
= (int) ((ca
.hue
-0x8000) * factor
);
1078 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Hue 0x%X %i\n",ca
.hue
,*value
);
1080 } else return VO_FALSE
;
1083 if (! strcmp( data
,"saturation" )) {
1084 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1085 *value
= (int) ((ca
.saturation
-0x8000) * factor
);
1086 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Saturation 0x%X %i\n",ca
.saturation
,*value
);
1088 } else return VO_FALSE
;
1094 static uint32_t get_image(mp_image_t
*mpi
)
1101 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n");
1102 if(mpi
->flags
&MP_IMGFLAG_READABLE
) return VO_FALSE
; // slow video ram
1103 if(mpi
->type
==MP_IMGTYPE_STATIC
) return VO_FALSE
; // it is not static
1105 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1107 if(mpi
->flags
&(MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_ACCEPT_WIDTH
)){
1108 // we're lucky or codec accepts stride => ok, let's go!
1111 err
= frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
);
1114 err
= primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
);
1119 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: DR lock failed!");
1123 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1126 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
1127 mpi
->planes
[1]=dst
+ pitch
*height
;
1128 mpi
->planes
[2]=mpi
->planes
[1] + pitch
*height
/4;
1130 mpi
->planes
[2]=dst
+ pitch
*height
;
1131 mpi
->planes
[1]=mpi
->planes
[2] + pitch
*height
/4;
1134 mpi
->stride
[0]=pitch
;
1135 mpi
->stride
[1]=mpi
->stride
[2]=pitch
/2;
1137 //YUY2 and RGB formats
1140 mpi
->stride
[0]=pitch
;
1146 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1147 mpi
->planes
[0]= dst
+ yoffset
* pitch
+ xoffset
;
1148 mpi
->planes
[1]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1149 mpi
->planes
[2]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1151 mpi
->planes
[0]=dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3);
1155 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1156 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1163 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1172 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1177 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1180 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1184 p
= FFMIN(w
, pitch
);
1187 dst2
= dst
+ pitch
*height
- y
*pitch
+ y
*pitch
/4 - x
/2;
1191 fast_memcpy(dst
,srcp
,p
);
1196 if (pixel_format
== DSPF_YV12
) {
1202 for (i
=0;i
<h
/2;i
++) {
1203 fast_memcpy(dst
,srcp
,p
);
1208 dst
= dst2
+ pitch
*height
/4;
1211 for (i
=0;i
<h
/2;i
++) {
1212 fast_memcpy(dst
,srcp
,p
);
1223 for (i
=0;i
<h
/2;i
++) {
1224 fast_memcpy(dst
,srcp
,p
);
1229 dst
= dst2
+ pitch
*height
/4;
1232 for (i
=0;i
<h
/2;i
++) {
1233 fast_memcpy(dst
,srcp
,p
);
1246 static uint32_t put_image(mp_image_t
*mpi
){
1249 // static IDirectFBSurface *tmp = NULL;
1250 // DFBSurfaceDescription dsc;
1251 // DFBRectangle rect;
1253 // 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);
1258 if((mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))) {
1259 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing to do\n");
1263 if (mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1264 // memcpy all planes - sad but necessary
1271 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1273 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1276 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1280 p
= FFMIN(mpi
->w
, pitch
);
1282 src
= mpi
->planes
[0]+mpi
->y
*mpi
->stride
[0]+mpi
->x
;
1284 for (i
=0;i
<mpi
->h
;i
++) {
1285 fast_memcpy(dst
+i
*pitch
,src
+i
*mpi
->stride
[0],p
);
1289 if (pixel_format
== DSPF_YV12
) {
1291 dst
+= pitch
*height
;
1293 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1295 for (i
=0;i
<mpi
->h
/2;i
++) {
1296 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1299 dst
+= pitch
*height
/4;
1300 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1302 for (i
=0;i
<mpi
->h
/2;i
++) {
1303 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1308 dst
+= pitch
*height
;
1310 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1312 for (i
=0;i
<mpi
->h
/2;i
++) {
1313 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1316 dst
+= pitch
*height
/4;
1317 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1319 for (i
=0;i
<mpi
->h
/2;i
++) {
1320 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1327 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1330 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1331 dsc.preallocated[0].data = mpi->planes[0];
1332 dsc.preallocated[0].pitch = mpi->stride[0];
1333 dsc.width = mpi->width;
1334 dsc.height = mpi->height;
1335 dsc.pixelformat = convformat(mpi->imgfmt);
1337 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1345 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1347 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1355 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non-planar branch\n");
1357 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1359 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]);
1361 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1363 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]);
1373 static int control(uint32_t request
, void *data
)
1376 case VOCTRL_QUERY_FORMAT
:
1377 return query_format(*((uint32_t*)data
));
1378 case VOCTRL_GET_IMAGE
:
1379 return get_image(data
);
1380 case VOCTRL_DRAW_IMAGE
:
1381 return put_image(data
);
1382 case VOCTRL_SET_EQUALIZER
:
1384 struct voctrl_set_equalizer_args
*args
= data
;
1385 return directfb_set_video_eq(args
->name
, args
->value
);
1387 case VOCTRL_GET_EQUALIZER
:
1389 struct voctrl_get_equalizer_args
*args
= data
;
1390 return directfb_get_video_eq(args
->name
, args
->valueptr
);
1398 static int draw_frame(uint8_t *src
[])
1403 // hopefully will be removed soon
1405 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
1406 unsigned char *srca
, int stride
)
1411 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1414 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1417 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1421 switch(pixel_format
) {
1424 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 4*x0
,pitch
);
1428 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 3*x0
,pitch
);
1432 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1435 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1438 vo_draw_alpha_rgb12(w
, h
, src
, srca
, stride
,
1439 ((uint8_t *) dst
) + pitch
* y0
+ 2 * x0
,
1444 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
,pitch
);
1448 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
+ 1,pitch
);
1453 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 1*x0
,pitch
);
1460 static void draw_osd(void)
1462 vo_draw_text(width
,height
,draw_alpha
);