2 MPlayer video driver for DirectFramebuffer device
6 Written by Jiri Svoboda <Jiri.Svoboda@seznam.cz>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301 USA.
28 #define DFB_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
43 #include "video_out.h"
44 #include "video_out_internal.h"
45 #include "fastmemcpy.h"
49 #include "subopt-helper.h"
53 #define min(x,y) (((x)<(y))?(x):(y))
56 #if DIRECTFBVERSION > DFB_VERSION(0,9,17)
61 static const vo_info_t info
= {
62 "Direct Framebuffer Device",
64 "Jiri Svoboda Jiri.Svoboda@seznam.cz",
65 "v 2.0 (for DirectFB version >=0.9.13)"
68 const LIBVO_EXTERN(directfb
)
70 /******************************
71 * vo_directfb globals *
72 ******************************/
74 #define DFBCHECK(x...) \
80 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
81 DirectFBErrorFatal( #x, err ); \
89 // main DirectFB handle
90 static IDirectFB
*dfb
= NULL
;
92 static IDirectFBInputDevice
*keyboard
= NULL
;
93 // A buffer for input events.
94 static IDirectFBEventBuffer
*buffer
= NULL
;
97 * filled during config
100 // handle of used layer
101 static IDirectFBDisplayLayer
*layer
= NULL
;
102 // surface of used layer
103 static IDirectFBSurface
*primary
= NULL
;
104 static int primarylocked
= 0;
105 // handle of temporary surface (if used)
106 static IDirectFBSurface
*frame
= NULL
;
107 static int framelocked
= 0;
108 // flipping mode flag (layer/surface)
109 static int flipping
= 0;
111 static int stretch
= 0;
113 static int xoffset
=0,yoffset
=0;
115 static int out_width
=0,out_height
=0;
116 // frame/primary size
117 static int width
=0,height
=0;
118 // frame primary format
119 DFBSurfacePixelFormat pixel_format
;
121 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
122 unsigned char *srca, int stride, unsigned char *dst,
126 /******************************
127 * cmd line parameteres *
128 ******************************/
130 /* command line/config file options */
131 static int layer_id
= -1;
132 static int buffer_mode
= 1;
133 static int use_input
= 1;
134 static int field_parity
= -1;
136 /******************************
138 ******************************/
141 if (frame
&& framelocked
) frame
->Unlock(frame
);
142 if (primary
&& primarylocked
) primary
->Unlock(primary
);
145 static int get_parity(strarg_t
*arg
) {
146 if (strargcmp(arg
, "top") == 0)
148 if (strargcmp(arg
, "bottom") == 0)
153 static int check_parity(void *arg
) {
154 return get_parity(arg
) != -1;
157 static int get_mode(strarg_t
*arg
) {
158 if (strargcmp(arg
, "single") == 0)
160 if (strargcmp(arg
, "double") == 0)
162 if (strargcmp(arg
, "triple") == 0)
167 static int check_mode(void *arg
) {
168 return get_mode(arg
) != 0;
171 static int preinit(const char *arg
)
174 strarg_t mode_str
= {0, NULL
};
175 strarg_t par_str
= {0, NULL
};
176 strarg_t dfb_params
= {0, NULL
};
178 {"input", OPT_ARG_BOOL
, &use_input
, NULL
},
179 {"buffermode", OPT_ARG_STR
, &mode_str
, check_mode
},
180 {"fieldparity", OPT_ARG_STR
, &par_str
, check_parity
},
181 {"layer", OPT_ARG_INT
, &layer_id
, NULL
},
182 {"dfbopts", OPT_ARG_STR
, &dfb_params
, NULL
},
186 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
188 if (dfb
) return 0; // we are already initialized!
191 buffer_mode
= 1 + vo_doublebuffering
; // honor -double switch
195 if (subopt_parse(arg
, subopts
) != 0) {
196 mp_msg( MSGT_VO
, MSGL_ERR
,
197 "\n-vo directfb command line help:\n"
198 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
199 "\nOptions (use 'no' prefix to disable):\n"
200 " input Use DirectFB for keyboard input\n"
203 " n=0..xx Use layer with id n for output (0=primary)\n"
204 " buffermode=(single|double|triple)\n"
205 " single Use single buffering\n"
206 " double Use double buffering\n"
207 " triple Use triple buffering\n"
208 " fieldparity=(top|bottom)\n"
209 " top Top field first\n"
210 " bottom Bottom field first\n"
212 " Specify a parameter list for DirectFB\n"
217 buffer_mode
= get_mode(&mode_str
);
219 field_parity
= get_parity(&par_str
);
222 if (dfb_params
.len
> 0)
225 char arg0
[10] = "mplayer";
226 char *arg1
= malloc(dfb_params
.len
+ 7);
232 strcpy(arg1
, "--dfb:");
233 strncat(arg1
, dfb_params
.str
, dfb_params
.len
);
239 DFBCHECK (DirectFBInit (&argc
,&a
));
244 DFBCHECK (DirectFBInit (NULL
,NULL
));
247 if (((directfb_major_version
<= 0) &&
248 (directfb_minor_version
<= 9) &&
249 (directfb_micro_version
< 13)))
251 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Unsupported DirectFB version\n");
259 // uncomment this if you do not wish to create a new VT for DirectFB
260 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
262 // uncomment this if you want to allow VT switching
263 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
265 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
266 DFBCHECK (DirectFBSetOption ("no-cursor",""));
269 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
275 DFBCHECK (DirectFBCreate (&dfb
));
277 #if DIRECTFBVERSION < DFB_VERSION(0,9,17)
278 if (DFB_OK
!= dfb
->SetCooperativeLevel (dfb
, DFSCL_FULLSCREEN
)) {
279 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - cannot switch to fullscreen mode");
288 ret
= dfb
->GetInputDevice (dfb
, DIDID_KEYBOARD
, &keyboard
);
290 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Keyboard init OK\n");
293 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Keyboard init FAILED\n");
299 * Create an input buffer for the keyboard.
301 if (keyboard
) DFBCHECK (keyboard
->CreateEventBuffer (keyboard
, &buffer
));
303 // just to start clean ...
304 if (buffer
) buffer
->Reset(buffer
);
306 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit OK\n");
312 DFBSurfacePixelFormat
convformat(uint32_t format
)
314 // add more formats !!!
316 case IMGFMT_RGB32
: return DSPF_RGB32
; break;
317 case IMGFMT_BGR32
: return DSPF_RGB32
; break;
318 case IMGFMT_RGB24
: return DSPF_RGB24
; break;
319 case IMGFMT_BGR24
: return DSPF_RGB24
; break;
320 case IMGFMT_RGB16
: return DSPF_RGB16
; break;
321 case IMGFMT_BGR16
: return DSPF_RGB16
; break;
322 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
323 case IMGFMT_RGB15
: return DSPF_ARGB1555
; break;
324 case IMGFMT_BGR15
: return DSPF_ARGB1555
; break;
326 case IMGFMT_RGB15
: return DSPF_RGB15
; break;
327 case IMGFMT_BGR15
: return DSPF_RGB15
; break;
329 case IMGFMT_YUY2
: return DSPF_YUY2
; break;
330 case IMGFMT_UYVY
: return DSPF_UYVY
; break;
331 case IMGFMT_YV12
: return DSPF_YV12
; break;
332 case IMGFMT_I420
: return DSPF_I420
; break;
333 // case IMGFMT_IYUV: return DSPF_IYUV; break;
334 case IMGFMT_RGB8
: return DSPF_RGB332
; break;
335 case IMGFMT_BGR8
: return DSPF_RGB332
; break;
342 typedef struct enum1_s
{
352 DFBEnumerationResult
test_format_callback( unsigned int id
,
353 DFBDisplayLayerDescription desc
,
356 enum1_t
*params
=(enum1_t
*)data
;
357 IDirectFBDisplayLayer
*layer
;
360 if ((layer_id
== -1 )||(layer_id
== id
)) {
362 ret
= dfb
->GetDisplayLayer( dfb
, id
, &layer
);
364 DirectFBError( "dfb->GetDisplayLayer failed", ret
);
367 DFBDisplayLayerConfig dlc
;
369 if (params
->setsize
) {
370 dlc
.flags
= DLCONF_WIDTH
|DLCONF_HEIGHT
;
371 dlc
.width
= params
->width
;
372 dlc
.height
= params
->height
;
373 layer
->SetConfiguration(layer
,&dlc
);
377 dlc
.flags
= DLCONF_PIXELFORMAT
;
378 dlc
.pixelformat
= convformat(params
->format
);
380 layer
->SetOpacity(layer
,0);
382 ret
= layer
->TestConfiguration(layer
,&dlc
,NULL
);
384 layer
->Release(layer
);
386 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
389 // printf("Test OK\n");
390 if (params
->result
) {
391 if ((!params
->scale
) && (desc
.caps
& DLCAPS_SCREEN_LOCATION
)) {
394 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
399 if (desc
.caps
& DLCAPS_SCREEN_LOCATION
) params
->scale
=1;
400 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
410 static int query_format(uint32_t format
)
412 int ret
= VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_OSD
; // osd should be removed the in future -> will be handled outside...
416 if (!convformat(format
)) return 0;
417 // temporarily disable YV12
418 // if (format == IMGFMT_YV12) return 0;
419 // if (format == IMGFMT_I420) return 0;
420 if (format
== IMGFMT_IYUV
) return 0;
422 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Format query: %s\n",vo_format_name(format
));
424 params
.format
=format
;
429 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
432 if (params
.scale
) ret
|=VFCAP_HWSCALE_UP
|VFCAP_HWSCALE_DOWN
;
439 typedef struct videomode_s
{
450 DFBEnumerationResult
video_modes_callback( unsigned int width
,unsigned int height
,unsigned int bpp
, void *data
)
452 videomode_t
*params
=(videomode_t
*)data
;
454 int overx
=0,overy
=0,closer
=0,over
=0;
457 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Validator entered %i %i %i\n",width,height,bpp);
459 overx
=width
-params
->out_width
;
460 overy
=height
-params
->out_height
;
462 if (!params
->width
) {
464 params
->height
=height
;
467 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Mode added %i %i %i\n",width
,height
,bpp
);
470 if ((params
->overy
<0)||(params
->overx
<0)) we_are_under
=1; // stored mode is smaller than req mode
471 if (abs(overx
*overy
)<abs(params
->overx
* params
->overy
)) closer
=1; // current mode is closer to desired res
472 if ((overx
>=0)&&(overy
>=0)) over
=1; // current mode is bigger or equaul to desired res
473 if ((closer
&& (over
|| we_are_under
)) || (we_are_under
&& over
)) {
475 params
->height
=height
;
478 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Better mode added %i %i %i\n",width
,height
,bpp
);
484 #define CONFIG_ERROR -1
486 static int config(uint32_t s_width
, uint32_t s_height
, uint32_t d_width
,
487 uint32_t d_height
, uint32_t flags
, char *title
,
496 int fs
= flags
& VOFLAG_FULLSCREEN
;
497 int vm
= flags
& VOFLAG_MODESWITCHING
;
499 DFBSurfaceDescription dsc
;
501 DFBDisplayLayerConfig dlc
;
502 DFBSurfaceCapabilities caps
;
506 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config entered [%ix%i]\n",s_width
,s_height
);
507 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: With requested format: %s\n",vo_format_name(format
));
511 frame
->Release(frame
);
516 primary
->Release(primary
);
521 layer
->Release(layer
);
530 params
.out_width
=d_width
;
531 params
.out_height
=d_height
;
549 default: params
.bpp
=0;
552 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - trying to change videomode\n");
553 DFBCHECK (dfb
->EnumVideoModes(dfb
,video_modes_callback
,¶ms
));
554 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,params
.bpp
);
556 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,24);
558 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,32);
560 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,16);
562 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,8);
569 // just to be sure clear primary layer
570 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
571 ret
= dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
);
573 ret
= layer
->GetSurface(layer
,&primary
);
575 primary
->Clear(primary
,0,0,0,0xff);
576 ret
= primary
->Flip(primary
,NULL
,0);
578 primary
->Clear(primary
,0,0,0,0xff);
580 primary
->Release(primary
);
583 layer
->Release(layer
);
590 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - looking for suitable layer\n");
591 params
.format
=format
;
594 params
.width
=s_width
;
595 params
.height
=s_height
;
598 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
600 if (!params
.result
) {
601 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - no suitable layer found\n");
602 params
.id
= DLID_PRIMARY
;
605 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - layer %i\n",params
.id
);
609 DFBCHECK (dfb
->GetDisplayLayer( dfb
, params
.id
, &layer
));
611 #if DIRECTFBVERSION > DFB_VERSION(0,9,16)
612 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - switching layer to exclusive mode\n");
613 ret
= layer
->SetCooperativeLevel (layer
, DLSCL_EXCLUSIVE
);
616 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");
617 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret
);
621 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (size)\n");
622 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
624 dlc
.height
= s_height
;
626 ret
= layer
->SetConfiguration(layer
,&dlc
);
629 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (size)\n");
630 DirectFBError("MPlayer - Layer size change.",ret
);
634 // look if we need to change the pixel format of the layer
635 // and just to be sure also fetch all layer properties
636 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
| DLCONF_OPTIONS
| DLCONF_BUFFERMODE
;
638 ret
= layer
->GetConfiguration(layer
,&dlc
);
640 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
;
643 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - could not get layer properties!\n");
645 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer reports format:%x\n",dlc
.pixelformat
);
648 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
650 dlc
.flags
= DLCONF_PIXELFORMAT
;
651 dlc
.pixelformat
= convformat(params
.format
);
653 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Desired pixelformat: %x\n",dlc
.pixelformat
);
655 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - changing layer configuration (format)\n");
656 ret
= layer
->SetConfiguration(layer
,&dlc
);
660 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc
.flags
);
661 DirectFBError("MPlayer - layer pixelformat change",ret
);
663 // ugly fbdev workaround - try to switch pixelformat via videomode change
664 switch (dlc
.pixelformat
) {
666 case DSPF_RGB32
: bpp
=32;break;
667 case DSPF_RGB24
: bpp
=24;break;
668 case DSPF_RGB16
: bpp
=16;break;
669 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
670 case DSPF_ARGB1555
: bpp
=15;break;
672 case DSPF_RGB15
: bpp
=15;break;
674 case DSPF_RGB332
: bpp
=8;break;
677 switch (dlc
.pixelformat
) {
682 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
688 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Trying to recover via videomode change (VM).\n");
690 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
691 if (DFB_OK
==layer
->GetConfiguration(layer
,&dlc
)) {
692 // try to set videomode
693 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Videomode %ix%i BPP %i\n",dlc
.width
,dlc
.height
,bpp
);
694 ret
= dfb
->SetVideoMode(dfb
,dlc
.width
,dlc
.height
,bpp
);
695 if (ret
) DirectFBError("MPlayer - VM - pixelformat change",ret
);
699 //get current pixel format
700 dlc
.flags
= DLCONF_PIXELFORMAT
;
701 ret
= layer
->GetConfiguration(layer
,&dlc
);
703 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret
);
705 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Layer now has pixelformat [%x]\n",dlc
.pixelformat
);
708 // check if we were succesful
709 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
710 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Recovery failed!.\n");
716 default: return CONFIG_ERROR
;
723 // try triple, double... buffering
725 dlc
.flags
= DLCONF_BUFFERMODE
;
727 if (buffer_mode
> 2) {
728 dlc
.buffermode
= DLBM_TRIPLE
;
729 ret
= layer
->SetConfiguration( layer
, &dlc
);
736 if (buffer_mode
> 1) {
737 dlc
.buffermode
= DLBM_BACKVIDEO
;
738 ret
= layer
->SetConfiguration( layer
, &dlc
);
740 dlc
.buffermode
= DLBM_BACKSYSTEM
;
741 ret
= layer
->SetConfiguration( layer
, &dlc
);
745 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Double buffering is active\n");
749 mp_msg(MSGT_VO
, MSGL_V
,"DirectFB: Triple buffering is active\n");
753 #if DIRECTFBVERSION > DFB_VERSION(0,9,16)
754 if (field_parity
!= -1) {
755 dlc
.flags
= DLCONF_OPTIONS
;
756 ret
= layer
->GetConfiguration( layer
, &dlc
);
758 dlc
.options
|= DLOP_FIELD_PARITY
;
759 ret
= layer
->SetConfiguration( layer
, &dlc
);
761 layer
->SetFieldParity( layer
, field_parity
);
765 mp_msg( MSGT_VO
, MSGL_DBG2
, "DirectFB: Requested field parity: ");
766 switch (field_parity
) {
768 mp_msg( MSGT_VO
, MSGL_DBG2
, "Don't care\n");
771 mp_msg( MSGT_VO
, MSGL_DBG2
, "Top field first\n");
774 mp_msg( MSGT_VO
, MSGL_DBG2
, "Bottom field first\n");
783 ret
= layer
->GetSurface(layer
,&primary
);
786 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - could not get surface\n");
787 return CONFIG_ERROR
; // what shall we report on failure?
790 // test surface for flipping
791 DFBCHECK(primary
->GetCapabilities(primary
,&caps
));
792 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
793 primary
->Clear(primary
,0,0,0,0xff);
796 if (caps
& (DSCAPS_FLIPPING
801 ret
= primary
->Flip(primary
,NULL
,0);
804 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
805 primary
->Clear(primary
,0,0,0,0xff);
807 // if we have 3 buffers clean once more
808 if (caps
& DSCAPS_TRIPLE
) {
809 primary
->Flip(primary
,NULL
,0);
810 primary
->Clear(primary
,0,0,0,0xff);
818 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - flipping = %i\n",flipping
);
820 // is scale needed ? Aspect ratio and layer pos/size
824 DFBCHECK(primary
->GetSize(primary
,&width
,&height
));
826 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Config - surface size = %ix%i\n",width
,height
);
828 aspect_save_orig(s_width
,s_height
);
829 aspect_save_prescale(d_width
,d_height
);
831 aspect_save_screenres(10000,10000);
832 aspect(&out_width
,&out_height
,A_ZOOM
);
834 ret
= layer
->SetScreenLocation(layer
,(1-(float)out_width
/10000)/2,(1-(float)out_height
/10000)/2,((float)out_width
/10000),((float)out_height
/10000));
836 if (ret
) mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (position)\n");
843 aspect_save_screenres(width
,height
);
846 aspect(&out_width
,&out_height
,A_ZOOM
);
848 aspect(&out_width
,&out_height
,A_NOZOOM
);
851 xoffset
= (width
- out_width
) / 2;
852 yoffset
= (height
- out_height
) / 2;
855 if (((s_width
==out_width
)&&(s_height
==out_height
)) || (params
.scale
)) {
862 // temporary buffer in case of not flipping or scaling
863 if ((!flipping
) || stretch
) {
865 DFBCHECK (primary
->GetPixelFormat (primary
, &dsc
.pixelformat
));
867 dsc
.flags
= DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
| DSDESC_WIDTH
;
870 dsc
.height
= s_height
;
872 DFBCHECK (dfb
->CreateSurface( dfb
, &dsc
, &frame
));
873 DFBCHECK(frame
->GetSize(frame
,&width
,&height
));
874 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Frame is active.\n");
877 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
879 DFBCHECK (frame
->GetPixelFormat(frame
,&pixel_format
));
881 DFBCHECK (primary
->GetPixelFormat(primary
,&pixel_format
));
884 // finally turn on layer
885 layer
->SetOpacity(layer
,255);
887 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height);
892 #include "osdep/keycodes.h"
894 static void check_events(void)
901 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events entered\n");
902 if (buffer
->GetEvent(buffer
, DFB_EVENT (&event
)) == DFB_OK
) {
904 if (event
.type
== DIET_KEYPRESS
) {
905 switch (event
.key_symbol
) {
907 mplayer_put_key(KEY_ESC
);
909 case DIKS_PAGE_UP
: mplayer_put_key(KEY_PAGE_UP
);break;
910 case DIKS_PAGE_DOWN
: mplayer_put_key(KEY_PAGE_DOWN
);break;
911 case DIKS_CURSOR_UP
: mplayer_put_key(KEY_UP
);break;
912 case DIKS_CURSOR_DOWN
: mplayer_put_key(KEY_DOWN
);break;
913 case DIKS_CURSOR_LEFT
: mplayer_put_key(KEY_LEFT
);break;
914 case DIKS_CURSOR_RIGHT
: mplayer_put_key(KEY_RIGHT
);break;
915 case DIKS_INSERT
: mplayer_put_key(KEY_INSERT
);break;
916 case DIKS_DELETE
: mplayer_put_key(KEY_DELETE
);break;
917 case DIKS_HOME
: mplayer_put_key(KEY_HOME
);break;
918 case DIKS_END
: mplayer_put_key(KEY_END
);break;
920 default:mplayer_put_key(event
.key_symbol
);
924 // empty buffer, because of repeating (keyboard repeat is faster than key handling
925 // and this causes problems during seek)
926 // temporary workaround should be solved in the future
927 buffer
->Reset(buffer
);
930 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events finished\n");
933 static void flip_page(void)
935 DFBSurfaceBlittingFlags flags
=DSBLIT_NOFX
;
937 unlock(); // unlock frame & primary
939 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Flip page entered");
941 DFBCHECK (primary
->SetBlittingFlags(primary
,flags
));
951 DFBCHECK (primary
->StretchBlit(primary
,frame
,NULL
,&rect
));
955 DFBCHECK (primary
->Blit(primary
,frame
,NULL
,xoffset
,yoffset
));
963 case 1: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAIT
));
965 case 2: DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_ONSYNC
));
967 default:; // should never be reached
971 DFBCHECK (primary
->Flip (primary
, NULL
, DSFLIP_WAITFORSYNC
));
979 static void uninit(void)
982 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit entered\n");
990 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing buffer\n");
991 if (buffer) buffer->Release (buffer);
992 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing keyboard\n");
993 if (keyboard) keyboard->Release (keyboard);
996 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing frame\n");
997 frame
->Release (frame
);
1002 // if (layer) layer->SetOpacity(layer,0);
1005 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing layer\n");
1006 layer
->Release(layer
);
1011 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: Releasing primary\n");
1012 primary
->Release (primary
);
1017 /* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n");
1021 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");
1025 static uint32_t directfb_set_video_eq(char *data
, int value
) //data==name
1028 DFBColorAdjustment ca
;
1029 float factor
= (float)0xffff / 200.0;
1031 DFBDisplayLayerDescription desc
;
1037 layer
->GetDescription(layer
,&desc
);
1041 if (! strcmp( data
,"brightness" )) {
1042 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1043 ca
.brightness
= value
* factor
+0x8000;
1044 ca
.flags
|= DCAF_BRIGHTNESS
;
1045 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Brightness 0x%X %i\n",ca
.brightness
,value
);
1046 } else return VO_FALSE
;
1049 if (! strcmp( data
,"contrast" )) {
1050 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1051 ca
.contrast
= value
* factor
+ 0x8000;
1052 ca
.flags
|= DCAF_CONTRAST
;
1053 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Contrast 0x%X %i\n",ca
.contrast
,value
);
1054 } else return VO_FALSE
;
1057 if (! strcmp( data
,"hue" )) {
1058 if ((desc
.caps
& DLCAPS_HUE
)) {
1059 ca
.hue
= value
* factor
+ 0x8000;
1060 ca
.flags
|= DCAF_HUE
;
1061 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Hue 0x%X %i\n",ca
.hue
,value
);
1062 } else return VO_FALSE
;
1065 if (! strcmp( data
,"saturation" )) {
1066 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1067 ca
.saturation
= value
* factor
+ 0x8000;
1068 ca
.flags
|= DCAF_SATURATION
;
1069 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: SetVEq Saturation 0x%X %i\n",ca
.saturation
,value
);
1070 } else return VO_FALSE
;
1073 if (ca
.flags
!= DCAF_NONE
) {
1074 layer
->SetColorAdjustment(layer
,&ca
);
1083 static uint32_t directfb_get_video_eq(char *data
, int *value
) // data==name
1086 DFBColorAdjustment ca
;
1087 float factor
= 200.0 / (float)0xffff;
1089 DFBDisplayLayerDescription desc
;
1095 layer
->GetDescription(layer
,&desc
);
1097 layer
->GetColorAdjustment(layer
,&ca
);
1099 if (! strcmp( data
,"brightness" )) {
1100 if (desc
.caps
& DLCAPS_BRIGHTNESS
) {
1101 *value
= (int) ((ca
.brightness
-0x8000) * factor
);
1102 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Brightness 0x%X %i\n",ca
.brightness
,*value
);
1104 } else return VO_FALSE
;
1107 if (! strcmp( data
,"contrast" )) {
1108 if ((desc
.caps
& DLCAPS_CONTRAST
)) {
1109 *value
= (int) ((ca
.contrast
-0x8000) * factor
);
1110 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Contrast 0x%X %i\n",ca
.contrast
,*value
);
1112 } else return VO_FALSE
;
1115 if (! strcmp( data
,"hue" )) {
1116 if ((desc
.caps
& DLCAPS_HUE
)) {
1117 *value
= (int) ((ca
.hue
-0x8000) * factor
);
1118 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Hue 0x%X %i\n",ca
.hue
,*value
);
1120 } else return VO_FALSE
;
1123 if (! strcmp( data
,"saturation" )) {
1124 if ((desc
.caps
& DLCAPS_SATURATION
)) {
1125 *value
= (int) ((ca
.saturation
-0x8000) * factor
);
1126 mp_msg(MSGT_VO
, MSGL_DBG2
,"DirectFB: GetVEq Saturation 0x%X %i\n",ca
.saturation
,*value
);
1128 } else return VO_FALSE
;
1134 static uint32_t get_image(mp_image_t
*mpi
)
1141 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n");
1142 if(mpi
->flags
&MP_IMGFLAG_READABLE
) return VO_FALSE
; // slow video ram
1143 if(mpi
->type
==MP_IMGTYPE_STATIC
) return VO_FALSE
; // it is not static
1145 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1147 if((mpi
->width
==pitch
) ||
1148 (mpi
->flags
&(MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_ACCEPT_WIDTH
))){
1149 // we're lucky or codec accepts stride => ok, let's go!
1152 err
= frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
);
1155 err
= primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
);
1160 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: DR lock failed!");
1164 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1167 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
1168 mpi
->planes
[1]=dst
+ pitch
*height
;
1169 mpi
->planes
[2]=mpi
->planes
[1] + pitch
*height
/4;
1171 mpi
->planes
[2]=dst
+ pitch
*height
;
1172 mpi
->planes
[1]=mpi
->planes
[2] + pitch
*height
/4;
1175 mpi
->stride
[0]=pitch
;
1176 mpi
->stride
[1]=mpi
->stride
[2]=pitch
/2;
1178 //YUY2 and RGB formats
1181 mpi
->stride
[0]=pitch
;
1187 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1188 mpi
->planes
[0]= dst
+ yoffset
* pitch
+ xoffset
;
1189 mpi
->planes
[1]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1190 mpi
->planes
[2]+= ((yoffset
* pitch
) >> 2) + (xoffset
>> 1);
1192 mpi
->planes
[0]=dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3);
1196 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1197 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1204 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1213 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1218 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1221 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1228 dst2
= dst
+ pitch
*height
- y
*pitch
+ y
*pitch
/4 - x
/2;
1232 fast_memcpy(dst
,srcp
,p
);
1237 if (pixel_format
== DSPF_YV12
) {
1243 for (i
=0;i
<h
/2;i
++) {
1244 fast_memcpy(dst
,srcp
,p
);
1249 dst
= dst2
+ pitch
*height
/4;
1252 for (i
=0;i
<h
/2;i
++) {
1253 fast_memcpy(dst
,srcp
,p
);
1264 for (i
=0;i
<h
/2;i
++) {
1265 fast_memcpy(dst
,srcp
,p
);
1270 dst
= dst2
+ pitch
*height
/4;
1273 for (i
=0;i
<h
/2;i
++) {
1274 fast_memcpy(dst
,srcp
,p
);
1287 static uint32_t put_image(mp_image_t
*mpi
){
1290 // static IDirectFBSurface *tmp = NULL;
1291 // DFBSurfaceDescription dsc;
1292 // DFBRectangle rect;
1294 // 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);
1299 if((mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))) {
1300 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing to do\n");
1304 if (mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1305 // memcpy all planes - sad but necessary
1312 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1314 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1317 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1321 p
=min(mpi
->w
,pitch
);
1323 src
= mpi
->planes
[0]+mpi
->y
*mpi
->stride
[0]+mpi
->x
;
1325 for (i
=0;i
<mpi
->h
;i
++) {
1326 fast_memcpy(dst
+i
*pitch
,src
+i
*mpi
->stride
[0],p
);
1330 if (pixel_format
== DSPF_YV12
) {
1332 dst
+= pitch
*height
;
1334 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1336 for (i
=0;i
<mpi
->h
/2;i
++) {
1337 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1340 dst
+= pitch
*height
/4;
1341 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1343 for (i
=0;i
<mpi
->h
/2;i
++) {
1344 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1349 dst
+= pitch
*height
;
1351 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1353 for (i
=0;i
<mpi
->h
/2;i
++) {
1354 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1357 dst
+= pitch
*height
/4;
1358 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1360 for (i
=0;i
<mpi
->h
/2;i
++) {
1361 fast_memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1368 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1371 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1372 dsc.preallocated[0].data = mpi->planes[0];
1373 dsc.preallocated[0].pitch = mpi->stride[0];
1374 dsc.width = mpi->width;
1375 dsc.height = mpi->height;
1376 dsc.pixelformat = convformat(mpi->imgfmt);
1378 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1386 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1388 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1396 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non-planar branch\n");
1398 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
,&dst
,&pitch
));
1400 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]);
1402 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1404 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]);
1414 static int control(uint32_t request
, void *data
, ...)
1417 case VOCTRL_QUERY_FORMAT
:
1418 return query_format(*((uint32_t*)data
));
1419 case VOCTRL_GET_IMAGE
:
1420 return get_image(data
);
1421 case VOCTRL_DRAW_IMAGE
:
1422 return put_image(data
);
1423 case VOCTRL_SET_EQUALIZER
:
1429 value
= va_arg(ap
, int);
1432 return(directfb_set_video_eq(data
, value
));
1434 case VOCTRL_GET_EQUALIZER
:
1440 value
= va_arg(ap
, int*);
1443 return(directfb_get_video_eq(data
, value
));
1451 static int draw_frame(uint8_t *src
[])
1456 // hopefully will be removed soon
1458 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
1459 unsigned char *srca
, int stride
)
1464 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1467 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1470 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1474 switch(pixel_format
) {
1477 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 4*x0
,pitch
);
1481 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 3*x0
,pitch
);
1485 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1487 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
1492 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1496 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
,pitch
);
1500 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
+ 1,pitch
);
1505 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 1*x0
,pitch
);
1512 static void draw_osd(void)
1514 vo_draw_text(width
,height
,draw_alpha
);