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.
29 #define DFB_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
44 #include "video_out.h"
45 #include "video_out_internal.h"
46 #include "fastmemcpy.h"
50 #include "subopt-helper.h"
54 #define min(x,y) (((x)<(y))?(x):(y))
57 #if DIRECTFBVERSION > DFB_VERSION(0,9,17)
62 static const vo_info_t info
= {
63 "Direct Framebuffer Device",
65 "Jiri Svoboda Jiri.Svoboda@seznam.cz",
66 "v 2.0 (for DirectFB version >=0.9.13)"
69 const LIBVO_EXTERN(directfb
)
71 /******************************
72 * vo_directfb globals *
73 ******************************/
75 #define DFBCHECK(x...) \
81 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
82 DirectFBErrorFatal( #x, err ); \
90 // main DirectFB handle
91 static IDirectFB
*dfb
= NULL
;
93 static IDirectFBInputDevice
*keyboard
= NULL
;
94 // A buffer for input events.
95 static IDirectFBEventBuffer
*buffer
= NULL
;
98 * filled during config
101 // handle of used layer
102 static IDirectFBDisplayLayer
*layer
= NULL
;
103 // surface of used layer
104 static IDirectFBSurface
*primary
= NULL
;
105 static int primarylocked
= 0;
106 // handle of temporary surface (if used)
107 static IDirectFBSurface
*frame
= NULL
;
108 static int framelocked
= 0;
109 // flipping mode flag (layer/surface)
110 static int flipping
= 0;
112 static int stretch
= 0;
114 static int xoffset
=0,yoffset
=0;
116 static int out_width
=0,out_height
=0;
117 // frame/primary size
118 static int width
=0,height
=0;
119 // frame primary format
120 DFBSurfacePixelFormat pixel_format
;
122 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
123 unsigned char *srca, int stride, unsigned char *dst,
127 /******************************
128 * cmd line parameteres *
129 ******************************/
131 /* command line/config file options */
132 static int layer_id
= -1;
133 static int buffer_mode
= 1;
134 static int use_input
= 1;
135 static int field_parity
= -1;
137 /******************************
139 ******************************/
141 static void unlock(void)
143 if (frame
&& framelocked
) frame
->Unlock(frame
);
144 if (primary
&& primarylocked
) primary
->Unlock(primary
);
147 static int get_parity(strarg_t
*arg
) {
148 if (strargcmp(arg
, "top") == 0)
150 if (strargcmp(arg
, "bottom") == 0)
155 static int check_parity(void *arg
) {
156 return get_parity(arg
) != -1;
159 static int get_mode(strarg_t
*arg
) {
160 if (strargcmp(arg
, "single") == 0)
162 if (strargcmp(arg
, "double") == 0)
164 if (strargcmp(arg
, "triple") == 0)
169 static int check_mode(void *arg
) {
170 return get_mode(arg
) != 0;
173 static int preinit(const char *arg
)
176 strarg_t mode_str
= {0, NULL
};
177 strarg_t par_str
= {0, NULL
};
178 strarg_t dfb_params
= {0, NULL
};
179 const opt_t subopts
[] = {
180 {"input", OPT_ARG_BOOL
, &use_input
, NULL
},
181 {"buffermode", OPT_ARG_STR
, &mode_str
, check_mode
},
182 {"fieldparity", OPT_ARG_STR
, &par_str
, check_parity
},
183 {"layer", OPT_ARG_INT
, &layer_id
, NULL
},
184 {"dfbopts", OPT_ARG_STR
, &dfb_params
, NULL
},
188 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
190 if (dfb
) return 0; // we are already initialized!
193 buffer_mode
= 1 + vo_doublebuffering
; // honor -double switch
197 if (subopt_parse(arg
, subopts
) != 0) {
198 mp_msg( MSGT_VO
, MSGL_ERR
,
199 "\n-vo directfb command line help:\n"
200 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
201 "\nOptions (use 'no' prefix to disable):\n"
202 " input Use DirectFB for keyboard input\n"
205 " n=0..xx Use layer with id n for output (0=primary)\n"
206 " buffermode=(single|double|triple)\n"
207 " single Use single buffering\n"
208 " double Use double buffering\n"
209 " triple Use triple buffering\n"
210 " fieldparity=(top|bottom)\n"
211 " top Top field first\n"
212 " bottom Bottom field first\n"
214 " Specify a parameter list for DirectFB\n"
219 buffer_mode
= get_mode(&mode_str
);
221 field_parity
= get_parity(&par_str
);
224 if (dfb_params
.len
> 0)
227 char arg0
[10] = "mplayer";
228 char *arg1
= malloc(dfb_params
.len
+ 7);
234 strcpy(arg1
, "--dfb:");
235 strncat(arg1
, dfb_params
.str
, dfb_params
.len
);
241 DFBCHECK (DirectFBInit (&argc
,&a
));
246 DFBCHECK (DirectFBInit (NULL
,NULL
));
249 if (((directfb_major_version
<= 0) &&
250 (directfb_minor_version
<= 9) &&
251 (directfb_micro_version
< 13)))
253 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Unsupported DirectFB version\n");
261 // uncomment this if you do not wish to create a new VT for DirectFB
262 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
264 // uncomment this if you want to allow VT switching
265 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
267 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
268 DFBCHECK (DirectFBSetOption ("no-cursor",""));
271 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
277 DFBCHECK (DirectFBCreate (&dfb
));
279 #if DIRECTFBVERSION < DFB_VERSION(0,9,17)
280 if (DFB_OK
!= dfb
->SetCooperativeLevel (dfb
, DFSCL_FULLSCREEN
)) {
281 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - cannot switch to fullscreen mode");
290 ret
= dfb
->GetInputDevice (dfb
, DIDID_KEYBOARD
, &keyboard
);
292 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Keyboard init OK\n");
295 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Keyboard init FAILED\n");
301 * Create an input buffer for the keyboard.
303 if (keyboard
) DFBCHECK (keyboard
->CreateEventBuffer (keyboard
, &buffer
));
305 // just to start clean ...
306 if (buffer
) buffer
->Reset(buffer
);
308 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit OK\n");
314 static DFBSurfacePixelFormat
convformat(uint32_t format
)
316 // add more formats !!!
318 case IMGFMT_RGB32
: return DSPF_RGB32
; break;
319 case IMGFMT_BGR32
: return DSPF_RGB32
; break;
320 case IMGFMT_RGB24
: return DSPF_RGB24
; break;
321 case IMGFMT_BGR24
: return DSPF_RGB24
; break;
322 case IMGFMT_RGB16
: return DSPF_RGB16
; break;
323 case IMGFMT_BGR16
: return DSPF_RGB16
; break;
324 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
325 case IMGFMT_RGB15
: return DSPF_ARGB1555
; break;
326 case IMGFMT_BGR15
: return DSPF_ARGB1555
; break;
328 case IMGFMT_RGB15
: return DSPF_RGB15
; break;
329 case IMGFMT_BGR15
: return DSPF_RGB15
; break;
331 case IMGFMT_YUY2
: return DSPF_YUY2
; break;
332 case IMGFMT_UYVY
: return DSPF_UYVY
; break;
333 case IMGFMT_YV12
: return DSPF_YV12
; break;
334 case IMGFMT_I420
: return DSPF_I420
; break;
335 // case IMGFMT_IYUV: return DSPF_IYUV; break;
336 case IMGFMT_RGB8
: return DSPF_RGB332
; break;
337 case IMGFMT_BGR8
: return DSPF_RGB332
; break;
344 typedef struct enum1_s
{
354 static DFBEnumerationResult
test_format_callback(unsigned int id
,
355 DFBDisplayLayerDescription desc
,
358 enum1_t
*params
=(enum1_t
*)data
;
359 IDirectFBDisplayLayer
*layer
;
362 if ((layer_id
== -1 )||(layer_id
== id
)) {
364 ret
= dfb
->GetDisplayLayer( dfb
, id
, &layer
);
366 DirectFBError( "dfb->GetDisplayLayer failed", ret
);
369 DFBDisplayLayerConfig dlc
;
371 if (params
->setsize
) {
372 dlc
.flags
= DLCONF_WIDTH
|DLCONF_HEIGHT
;
373 dlc
.width
= params
->width
;
374 dlc
.height
= params
->height
;
375 layer
->SetConfiguration(layer
,&dlc
);
379 dlc
.flags
= DLCONF_PIXELFORMAT
;
380 dlc
.pixelformat
= convformat(params
->format
);
382 layer
->SetOpacity(layer
,0);
384 ret
= layer
->TestConfiguration(layer
,&dlc
,NULL
);
386 layer
->Release(layer
);
388 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
391 // printf("Test OK\n");
392 if (params
->result
) {
393 if ((!params
->scale
) && (desc
.caps
& DLCAPS_SCREEN_LOCATION
)) {
396 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
401 if (desc
.caps
& DLCAPS_SCREEN_LOCATION
) params
->scale
=1;
402 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
412 static int query_format(uint32_t format
)
414 int ret
= VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_OSD
; // osd should be removed the in future -> will be handled outside...
418 if (!convformat(format
)) return 0;
419 // temporarily disable YV12
420 // if (format == IMGFMT_YV12) return 0;
421 // if (format == IMGFMT_I420) return 0;
422 if (format
== IMGFMT_IYUV
) return 0;
424 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Format query: %s\n",vo_format_name(format
));
426 params
.format
=format
;
431 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
434 if (params
.scale
) ret
|=VFCAP_HWSCALE_UP
|VFCAP_HWSCALE_DOWN
;
441 typedef struct videomode_s
{
452 static DFBEnumerationResult
video_modes_callback(int width
, int height
,
455 videomode_t
*params
=(videomode_t
*)data
;
457 int overx
=0,overy
=0,closer
=0,over
=0;
460 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Validator entered %i %i %i\n",width,height,bpp);
462 overx
=width
-params
->out_width
;
463 overy
=height
-params
->out_height
;
465 if (!params
->width
) {
467 params
->height
=height
;
470 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Mode added %i %i %i\n",width
,height
,bpp
);
473 if ((params
->overy
<0)||(params
->overx
<0)) we_are_under
=1; // stored mode is smaller than req mode
474 if (abs(overx
*overy
)<abs(params
->overx
* params
->overy
)) closer
=1; // current mode is closer to desired res
475 if ((overx
>=0)&&(overy
>=0)) over
=1; // current mode is bigger or equaul to desired res
476 if ((closer
&& (over
|| we_are_under
)) || (we_are_under
&& over
)) {
478 params
->height
=height
;
481 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Better mode added %i %i %i\n",width
,height
,bpp
);
487 #define CONFIG_ERROR -1
489 static int config(uint32_t s_width
, uint32_t s_height
, uint32_t d_width
,
490 uint32_t d_height
, uint32_t flags
, char *title
,
499 int fs
= flags
& VOFLAG_FULLSCREEN
;
500 int vm
= flags
& VOFLAG_MODESWITCHING
;
502 DFBSurfaceDescription dsc
;
504 DFBDisplayLayerConfig dlc
;
505 DFBSurfaceCapabilities caps
;
509 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config entered [%ix%i]\n",s_width
,s_height
);
510 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: With requested format: %s\n",vo_format_name(format
));
514 frame
->Release(frame
);
519 primary
->Release(primary
);
524 layer
->Release(layer
);
533 params
.out_width
=d_width
;
534 params
.out_height
=d_height
;
552 default: params
.bpp
=0;
555 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - trying to change videomode\n");
556 DFBCHECK (dfb
->EnumVideoModes(dfb
,video_modes_callback
,¶ms
));
557 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,params
.bpp
);
559 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,24);
561 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,32);
563 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,16);
565 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,8);
572 // just to be sure clear primary layer
573 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
574 ret
= dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
);
576 ret
= layer
->GetSurface(layer
,&primary
);
578 primary
->Clear(primary
,0,0,0,0xff);
579 ret
= primary
->Flip(primary
,NULL
,0);
581 primary
->Clear(primary
,0,0,0,0xff);
583 primary
->Release(primary
);
586 layer
->Release(layer
);
593 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - looking for suitable layer\n");
594 params
.format
=format
;
597 params
.width
=s_width
;
598 params
.height
=s_height
;
601 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
603 if (!params
.result
) {
604 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - no suitable layer found\n");
605 params
.id
= DLID_PRIMARY
;
608 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - layer %i\n",params
.id
);
612 DFBCHECK (dfb
->GetDisplayLayer( dfb
, params
.id
, &layer
));
614 #if DIRECTFBVERSION > DFB_VERSION(0,9,16)
615 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - switching layer to exclusive mode\n");
616 ret
= layer
->SetCooperativeLevel (layer
, DLSCL_EXCLUSIVE
);
619 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");
620 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret
);
624 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (size)\n");
625 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
627 dlc
.height
= s_height
;
629 ret
= layer
->SetConfiguration(layer
,&dlc
);
632 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (size)\n");
633 DirectFBError("MPlayer - Layer size change.",ret
);
637 // look if we need to change the pixel format of the layer
638 // and just to be sure also fetch all layer properties
639 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
| DLCONF_OPTIONS
| DLCONF_BUFFERMODE
;
641 ret
= layer
->GetConfiguration(layer
,&dlc
);
643 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
;
646 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - could not get layer properties!\n");
648 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer reports format:%x\n",dlc
.pixelformat
);
651 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
653 dlc
.flags
= DLCONF_PIXELFORMAT
;
654 dlc
.pixelformat
= convformat(params
.format
);
656 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Desired pixelformat: %x\n",dlc
.pixelformat
);
658 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (format)\n");
659 ret
= layer
->SetConfiguration(layer
,&dlc
);
663 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc
.flags
);
664 DirectFBError("MPlayer - layer pixelformat change",ret
);
666 // ugly fbdev workaround - try to switch pixelformat via videomode change
667 switch (dlc
.pixelformat
) {
669 case DSPF_RGB32
: bpp
=32;break;
670 case DSPF_RGB24
: bpp
=24;break;
671 case DSPF_RGB16
: bpp
=16;break;
672 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
673 case DSPF_ARGB1555
: bpp
=15;break;
675 case DSPF_RGB15
: bpp
=15;break;
677 case DSPF_RGB332
: bpp
=8;break;
680 switch (dlc
.pixelformat
) {
685 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
691 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Trying to recover via videomode change (VM).\n");
693 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
694 if (DFB_OK
==layer
->GetConfiguration(layer
,&dlc
)) {
695 // try to set videomode
696 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Videomode %ix%i BPP %i\n",dlc
.width
,dlc
.height
,bpp
);
697 ret
= dfb
->SetVideoMode(dfb
,dlc
.width
,dlc
.height
,bpp
);
698 if (ret
) DirectFBError("MPlayer - VM - pixelformat change",ret
);
702 //get current pixel format
703 dlc
.flags
= DLCONF_PIXELFORMAT
;
704 ret
= layer
->GetConfiguration(layer
,&dlc
);
706 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret
);
708 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer now has pixelformat [%x]\n",dlc
.pixelformat
);
711 // check if we were succesful
712 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
713 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Recovery failed!.\n");
719 default: return CONFIG_ERROR
;
726 // try triple, double... buffering
728 dlc
.flags
= DLCONF_BUFFERMODE
;
730 if (buffer_mode
> 2) {
731 dlc
.buffermode
= DLBM_TRIPLE
;
732 ret
= layer
->SetConfiguration( layer
, &dlc
);
739 if (buffer_mode
> 1) {
740 dlc
.buffermode
= DLBM_BACKVIDEO
;
741 ret
= layer
->SetConfiguration( layer
, &dlc
);
743 dlc
.buffermode
= DLBM_BACKSYSTEM
;
744 ret
= layer
->SetConfiguration( layer
, &dlc
);
748 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Double buffering is active\n");
752 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Triple buffering is active\n");
756 #if DIRECTFBVERSION > DFB_VERSION(0,9,16)
757 if (field_parity
!= -1) {
758 dlc
.flags
= DLCONF_OPTIONS
;
759 ret
= layer
->GetConfiguration( layer
, &dlc
);
761 dlc
.options
|= DLOP_FIELD_PARITY
;
762 ret
= layer
->SetConfiguration( layer
, &dlc
);
764 layer
->SetFieldParity( layer
, field_parity
);
768 mp_msg( MSGT_VO
, MSGL_DBG2
, "DirectFB: Requested field parity: ");
769 switch (field_parity
) {
771 mp_msg( MSGT_VO
, MSGL_DBG2
, "Don't care\n");
774 mp_msg( MSGT_VO
, MSGL_DBG2
, "Top field first\n");
777 mp_msg( MSGT_VO
, MSGL_DBG2
, "Bottom field first\n");
786 ret
= layer
->GetSurface(layer
,&primary
);
789 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - could not get surface\n");
790 return CONFIG_ERROR
; // what shall we report on failure?
793 // test surface for flipping
794 DFBCHECK(primary
->GetCapabilities(primary
,&caps
));
795 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
796 primary
->Clear(primary
,0,0,0,0xff);
799 if (caps
& (DSCAPS_FLIPPING
804 ret
= primary
->Flip(primary
,NULL
,0);
807 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
808 primary
->Clear(primary
,0,0,0,0xff);
810 // if we have 3 buffers clean once more
811 if (caps
& DSCAPS_TRIPLE
) {
812 primary
->Flip(primary
,NULL
,0);
813 primary
->Clear(primary
,0,0,0,0xff);
821 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - flipping = %i\n",flipping
);
823 // is scale needed ? Aspect ratio and layer pos/size
827 DFBCHECK(primary
->GetSize(primary
,&width
,&height
));
829 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - surface size = %ix%i\n",width
,height
);
831 aspect_save_orig(s_width
,s_height
);
832 aspect_save_prescale(d_width
,d_height
);
834 aspect_save_screenres(10000,10000);
835 aspect(&out_width
,&out_height
,A_ZOOM
);
837 ret
= layer
->SetScreenLocation(layer
,(1-(float)out_width
/10000)/2,(1-(float)out_height
/10000)/2,((float)out_width
/10000),((float)out_height
/10000));
839 if (ret
) mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (position)\n");
846 aspect_save_screenres(width
,height
);
849 aspect(&out_width
,&out_height
,A_ZOOM
);
851 aspect(&out_width
,&out_height
,A_NOZOOM
);
854 xoffset
= (width
- out_width
) / 2;
855 yoffset
= (height
- out_height
) / 2;
858 if (((s_width
==out_width
)&&(s_height
==out_height
)) || (params
.scale
)) {
865 // temporary buffer in case of not flipping or scaling
866 if ((!flipping
) || stretch
) {
868 DFBCHECK (primary
->GetPixelFormat (primary
, &dsc
.pixelformat
));
870 dsc
.flags
= DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
| DSDESC_WIDTH
;
873 dsc
.height
= s_height
;
875 DFBCHECK (dfb
->CreateSurface( dfb
, &dsc
, &frame
));
876 DFBCHECK(frame
->GetSize(frame
,&width
,&height
));
877 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Frame is active.\n");
880 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
882 DFBCHECK (frame
->GetPixelFormat(frame
,&pixel_format
));
884 DFBCHECK (primary
->GetPixelFormat(primary
,&pixel_format
));
887 // finally turn on layer
888 layer
->SetOpacity(layer
,255);
890 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height);
895 #include "osdep/keycodes.h"
897 static void check_events(void)
904 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events entered\n");
905 if (buffer
->GetEvent(buffer
, DFB_EVENT (&event
)) == DFB_OK
) {
907 if (event
.type
== DIET_KEYPRESS
) {
908 switch (event
.key_symbol
) {
910 mplayer_put_key(KEY_ESC
);
912 case DIKS_PAGE_UP
: mplayer_put_key(KEY_PAGE_UP
);break;
913 case DIKS_PAGE_DOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
914 case DIKS_CURSOR_UP
: mplayer_put_key(KEY_UP
);break;
915 case DIKS_CURSOR_DOWN
: mplayer_put_key(KEY_DOWN
);break;
916 case DIKS_CURSOR_LEFT
: mplayer_put_key(KEY_LEFT
);break;
917 case DIKS_CURSOR_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
918 case DIKS_INSERT
: mplayer_put_key(KEY_INSERT
);break;
919 case DIKS_DELETE
: mplayer_put_key(KEY_DELETE
);break;
920 case DIKS_HOME
: mplayer_put_key(KEY_HOME
);break;
921 case DIKS_END
: mplayer_put_key(KEY_END
);break;
923 default:mplayer_put_key(event
.key_symbol
);
927 // empty buffer, because of repeating (keyboard repeat is faster than key handling
928 // and this causes problems during seek)
929 // temporary workaround should be solved in the future
930 buffer
->Reset(buffer
);
933 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events finished\n");
936 static void flip_page(void)
938 DFBSurfaceBlittingFlags flags
=DSBLIT_NOFX
;
940 unlock(); // unlock frame & primary
942 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Flip page entered");
944 DFBCHECK (primary
->SetBlittingFlags(primary
,flags
));
954 DFBCHECK (primary
->StretchBlit(primary
,frame
,NULL
,&rect
));
958 DFBCHECK (primary
->Blit(primary
,frame
,NULL
,xoffset
,yoffset
));
966 case 1: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAIT
));
968 case 2: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_ONSYNC
));
970 default:; // should never be reached
974 DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAITFORSYNC
));
982 static void uninit(void)
985 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit entered\n");
993 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing buffer\n");
994 if (buffer) buffer->Release (buffer);
995 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing keyboard\n");
996 if (keyboard) keyboard->Release (keyboard);
999 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing frame\n");
1000 frame
->Release (frame
);
1005 // if (layer) layer->SetOpacity(layer,0);
1008 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing layer\n");
1009 layer
->Release(layer
);
1014 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing primary\n");
1015 primary
->Release (primary
);
1020 /* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n");
1024 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");
1028 static uint32_t directfb_set_video_eq(char *data
, int value
) //data==name
1031 DFBColorAdjustment ca
;
1032 float factor
= (float)0xffff / 200.0;
1034 DFBDisplayLayerDescription desc
;
1040 layer
->GetDescription(layer
,&desc
);
1044 if (! strcmp( data
,"brightness" )) {
1045 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1046 ca
.brightness
= value
* factor
+0x8000;
1047 ca
.flags
|= DCAF_BRIGHTNESS
;
1048 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Brightness 0x%X %i\n",ca
.brightness
,value
);
1049 } else return VO_FALSE
;
1052 if (! strcmp( data
,"contrast" )) {
1053 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1054 ca
.contrast
= value
* factor
+ 0x8000;
1055 ca
.flags
|= DCAF_CONTRAST
;
1056 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Contrast 0x%X %i\n",ca
.contrast
,value
);
1057 } else return VO_FALSE
;
1060 if (! strcmp( data
,"hue" )) {
1061 if ((desc
.caps
& DLCAPS_HUE
)) {
1062 ca
.hue
= value
* factor
+ 0x8000;
1063 ca
.flags
|= DCAF_HUE
;
1064 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Hue 0x%X %i\n",ca
.hue
,value
);
1065 } else return VO_FALSE
;
1068 if (! strcmp( data
,"saturation" )) {
1069 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1070 ca
.saturation
= value
* factor
+ 0x8000;
1071 ca
.flags
|= DCAF_SATURATION
;
1072 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Saturation 0x%X %i\n",ca
.saturation
,value
);
1073 } else return VO_FALSE
;
1076 if (ca
.flags
!= DCAF_NONE
) {
1077 layer
->SetColorAdjustment(layer
,&ca
);
1086 static uint32_t directfb_get_video_eq(char *data
, int *value
) // data==name
1089 DFBColorAdjustment ca
;
1090 float factor
= 200.0 / (float)0xffff;
1092 DFBDisplayLayerDescription desc
;
1098 layer
->GetDescription(layer
,&desc
);
1100 layer
->GetColorAdjustment(layer
,&ca
);
1102 if (! strcmp( data
,"brightness" )) {
1103 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1104 *value
= (int) ((ca
.brightness
-0x8000) * factor
);
1105 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Brightness 0x%X %i\n",ca
.brightness
,*value
);
1107 } else return VO_FALSE
;
1110 if (! strcmp( data
,"contrast" )) {
1111 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1112 *value
= (int) ((ca
.contrast
-0x8000) * factor
);
1113 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Contrast 0x%X %i\n",ca
.contrast
,*value
);
1115 } else return VO_FALSE
;
1118 if (! strcmp( data
,"hue" )) {
1119 if ((desc
.caps
& DLCAPS_HUE
)) {
1120 *value
= (int) ((ca
.hue
-0x8000) * factor
);
1121 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Hue 0x%X %i\n",ca
.hue
,*value
);
1123 } else return VO_FALSE
;
1126 if (! strcmp( data
,"saturation" )) {
1127 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1128 *value
= (int) ((ca
.saturation
-0x8000) * factor
);
1129 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Saturation 0x%X %i\n",ca
.saturation
,*value
);
1131 } else return VO_FALSE
;
1137 static uint32_t get_image(mp_image_t
*mpi
)
1144 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n");
1145 if(mpi
->flags
&MP_IMGFLAG_READABLE
) return VO_FALSE
; // slow video ram
1146 if(mpi
->type
==MP_IMGTYPE_STATIC
) return VO_FALSE
; // it is not static
1148 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1150 if(mpi
->flags
&(MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_ACCEPT_WIDTH
)){
1151 // we're lucky or codec accepts stride => ok, let's go!
1154 err
= frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
);
1157 err
= primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
);
1162 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: DR lock failed!");
1166 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1169 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
1170 mpi
->planes
[1]=dst
+ pitch
*height
;
1171 mpi
->planes
[2]=mpi
->planes
[1] + pitch
*height
/4;
1173 mpi
->planes
[2]=dst
+ pitch
*height
;
1174 mpi
->planes
[1]=mpi
->planes
[2] + pitch
*height
/4;
1177 mpi
->stride
[0]=pitch
;
1178 mpi
->stride
[1]=mpi
->stride
[2]=pitch
/2;
1180 //YUY2 and RGB formats
1183 mpi
->stride
[0]=pitch
;
1189 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1190 mpi
->planes
[0]= dst
+ yoffset
* pitch
+ xoffset
;
1191 mpi
->planes
[1]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1192 mpi
->planes
[2]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1194 mpi
->planes
[0]=dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3);
1198 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1199 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1206 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1215 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1220 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1223 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1230 dst2
= dst
+ pitch
*height
- y
*pitch
+ y
*pitch
/4 - x
/2;
1234 fast_memcpy(dst
,srcp
,p
);
1239 if (pixel_format
== DSPF_YV12
) {
1245 for (i
=0;i
<h
/2;i
++) {
1246 fast_memcpy(dst
,srcp
,p
);
1251 dst
= dst2
+ pitch
*height
/4;
1254 for (i
=0;i
<h
/2;i
++) {
1255 fast_memcpy(dst
,srcp
,p
);
1266 for (i
=0;i
<h
/2;i
++) {
1267 fast_memcpy(dst
,srcp
,p
);
1272 dst
= dst2
+ pitch
*height
/4;
1275 for (i
=0;i
<h
/2;i
++) {
1276 fast_memcpy(dst
,srcp
,p
);
1289 static uint32_t put_image(mp_image_t
*mpi
){
1292 // static IDirectFBSurface *tmp = NULL;
1293 // DFBSurfaceDescription dsc;
1294 // DFBRectangle rect;
1296 // 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);
1301 if((mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))) {
1302 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing to do\n");
1306 if (mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1307 // memcpy all planes - sad but necessary
1314 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1316 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,(void *)&dst
,&pitch
));
1319 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1323 p
=min(mpi
->w
,pitch
);
1325 src
= mpi
->planes
[0]+mpi
->y
*mpi
->stride
[0]+mpi
->x
;
1327 for (i
=0;i
<mpi
->h
;i
++) {
1328 fast_memcpy(dst
+i
*pitch
,src
+i
*mpi
->stride
[0],p
);
1332 if (pixel_format
== DSPF_YV12
) {
1334 dst
+= pitch
*height
;
1336 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1338 for (i
=0;i
<mpi
->h
/2;i
++) {
1339 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1342 dst
+= pitch
*height
/4;
1343 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1345 for (i
=0;i
<mpi
->h
/2;i
++) {
1346 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1351 dst
+= pitch
*height
;
1353 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1355 for (i
=0;i
<mpi
->h
/2;i
++) {
1356 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1359 dst
+= pitch
*height
/4;
1360 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1362 for (i
=0;i
<mpi
->h
/2;i
++) {
1363 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1370 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1373 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1374 dsc.preallocated[0].data = mpi->planes[0];
1375 dsc.preallocated[0].pitch = mpi->stride[0];
1376 dsc.width = mpi->width;
1377 dsc.height = mpi->height;
1378 dsc.pixelformat = convformat(mpi->imgfmt);
1380 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1388 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1390 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1398 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non-planar branch\n");
1400 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1402 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]);
1404 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,(void *)&dst
,&pitch
));
1406 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]);
1416 static int control(uint32_t request
, void *data
, ...)
1419 case VOCTRL_QUERY_FORMAT
:
1420 return query_format(*((uint32_t*)data
));
1421 case VOCTRL_GET_IMAGE
:
1422 return get_image(data
);
1423 case VOCTRL_DRAW_IMAGE
:
1424 return put_image(data
);
1425 case VOCTRL_SET_EQUALIZER
:
1431 value
= va_arg(ap
, int);
1434 return directfb_set_video_eq(data
, value
);
1436 case VOCTRL_GET_EQUALIZER
:
1442 value
= va_arg(ap
, int*);
1445 return directfb_get_video_eq(data
, value
);
1453 static int draw_frame(uint8_t *src
[])
1458 // hopefully will be removed soon
1460 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
1461 unsigned char *srca
, int stride
)
1466 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1469 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1472 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1476 switch(pixel_format
) {
1479 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 4*x0
,pitch
);
1483 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 3*x0
,pitch
);
1487 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1489 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
1494 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1498 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
,pitch
);
1502 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
+ 1,pitch
);
1507 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 1*x0
,pitch
);
1514 static void draw_osd(void)
1516 vo_draw_text(width
,height
,draw_alpha
);