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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
41 #include "video_out.h"
42 #include "video_out_internal.h"
43 #include "fastmemcpy.h"
47 #include "subopt-helper.h"
50 #define min(x,y) (((x)<(y))?(x):(y))
53 #if DIRECTFBVERSION > 917
58 static vo_info_t info
= {
59 "Direct Framebuffer Device",
61 "Jiri Svoboda Jiri.Svoboda@seznam.cz",
62 "v 2.0 (for DirectFB version >=0.9.13)"
65 LIBVO_EXTERN(directfb
)
67 /******************************
68 * vo_directfb globals *
69 ******************************/
71 #define DFBCHECK(x...) \
77 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
78 DirectFBErrorFatal( #x, err ); \
86 // main DirectFB handle
87 static IDirectFB
*dfb
= NULL
;
89 static IDirectFBInputDevice
*keyboard
= NULL
;
90 // A buffer for input events.
91 static IDirectFBEventBuffer
*buffer
= NULL
;
94 * filled during config
97 // handle of used layer
98 static IDirectFBDisplayLayer
*layer
= NULL
;
99 // surface of used layer
100 static IDirectFBSurface
*primary
= NULL
;
101 static int primarylocked
= 0;
102 // handle of temporary surface (if used)
103 static IDirectFBSurface
*frame
= NULL
;
104 static int framelocked
= 0;
105 // flipping mode flag (layer/surface)
106 static int flipping
= 0;
108 static int tvnorm
= -1;
110 static int stretch
= 0;
112 static int xoffset
=0,yoffset
=0;
114 static int out_width
=0,out_height
=0;
115 // frame/primary size
116 static int width
=0,height
=0;
117 // frame primary format
118 DFBSurfacePixelFormat pixel_format
;
120 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
121 unsigned char *srca, int stride, unsigned char *dst,
125 /******************************
126 * cmd line parameteres *
127 ******************************/
129 /* command line/config file options */
130 static int layer_id
= -1;
131 static int buffer_mode
= 1;
132 static int use_input
= 1;
133 static int field_parity
= -1;
135 /******************************
137 ******************************/
140 if (frame
&& framelocked
) frame
->Unlock(frame
);
141 if (primary
&& primarylocked
) primary
->Unlock(primary
);
144 static int get_parity(strarg_t
*arg
) {
145 if (strargcmp(arg
, "top") == 0)
147 if (strargcmp(arg
, "bottom") == 0)
152 static int check_parity(void *arg
) {
153 return get_parity(arg
) != -1;
156 static int get_mode(strarg_t
*arg
) {
157 if (strargcmp(arg
, "single") == 0)
159 if (strargcmp(arg
, "double") == 0)
161 if (strargcmp(arg
, "triple") == 0)
166 static int check_mode(void *arg
) {
167 return get_mode(arg
) != 0;
170 static int preinit(const char *arg
)
173 strarg_t mode_str
= {0, NULL
};
174 strarg_t par_str
= {0, NULL
};
175 strarg_t dfb_params
= {0, NULL
};
177 {"input", OPT_ARG_BOOL
, &use_input
, NULL
},
178 {"buffermode", OPT_ARG_STR
, &mode_str
, check_mode
},
179 {"fieldparity", OPT_ARG_STR
, &par_str
, check_parity
},
180 {"layer", OPT_ARG_INT
, &layer_id
, NULL
},
181 {"dfbopts", OPT_ARG_STR
, &dfb_params
, NULL
},
185 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Preinit entered\n");
187 if (dfb
) return 0; // we are already inited!
190 buffer_mode
= 1 + vo_doublebuffering
; // honor -double switch
194 if (subopt_parse(arg
, subopts
) != 0) {
195 mp_msg( MSGT_VO
, MSGL_ERR
,
196 "\n-vo directfb command line help:\n"
197 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
198 "\nOptions (use 'no' prefix to disable):\n"
199 " input Use DirectFB for keyboard input\n"
202 " n=0..xx Use layer with id n for output (0=primary)\n"
203 " buffermode=(single|double|triple)\n"
204 " single Use single buffering\n"
205 " double Use double buffering\n"
206 " triple Use triple buffering\n"
207 " fieldparity=(top|bottom)\n"
208 " top Top field first\n"
209 " bottom Bottom field first\n"
211 " Specify a parameter list for DirectFB\n"
216 buffer_mode
= get_mode(&mode_str
);
218 field_parity
= get_parity(&par_str
);
221 if (dfb_params
.len
> 0)
224 char arg0
[10] = "mplayer";
225 char *arg1
= (char *)malloc(dfb_params
.len
+ 7);
231 strcpy(arg1
, "--dfb:");
232 strncat(arg1
, dfb_params
.str
, dfb_params
.len
);
238 DFBCHECK (DirectFBInit (&argc
,&a
));
243 DFBCHECK (DirectFBInit (NULL
,NULL
));
246 if (((directfb_major_version
<= 0) &&
247 (directfb_minor_version
<= 9) &&
248 (directfb_micro_version
< 13)))
250 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Unsupported DirectFB version\n");
258 // uncomment this if you do not wish to create a new vt for DirectFB
259 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
261 // uncomment this if you want to allow vt switching
262 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
264 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
265 DFBCHECK (DirectFBSetOption ("no-cursor",""));
268 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
274 DFBCHECK (DirectFBCreate (&dfb
));
276 #if DIRECTFBVERSION < 917
277 if (DFB_OK
!= dfb
->SetCooperativeLevel (dfb
, DFSCL_FULLSCREEN
)) {
278 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - cannot swith to fullscreen mode");
287 ret
= dfb
->GetInputDevice (dfb
, DIDID_KEYBOARD
, &keyboard
);
289 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Keyboard init OK\n");
292 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: Keyboard init FAILED\n");
298 * Create an input buffer for the keyboard.
300 if (keyboard
) DFBCHECK (keyboard
->CreateEventBuffer (keyboard
, &buffer
));
302 // just to start with clean ...
303 if (buffer
) buffer
->Reset(buffer
);
305 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Preinit OK\n");
311 DFBSurfacePixelFormat
convformat(uint32_t format
)
313 // add more formats !!!
315 case IMGFMT_RGB32
: return DSPF_RGB32
; break;
316 case IMGFMT_BGR32
: return DSPF_RGB32
; break;
317 case IMGFMT_RGB24
: return DSPF_RGB24
; break;
318 case IMGFMT_BGR24
: return DSPF_RGB24
; break;
319 case IMGFMT_RGB16
: return DSPF_RGB16
; break;
320 case IMGFMT_BGR16
: return DSPF_RGB16
; break;
321 #if DIRECTFBVERSION > 915
322 case IMGFMT_RGB15
: return DSPF_ARGB1555
; break;
323 case IMGFMT_BGR15
: return DSPF_ARGB1555
; break;
325 case IMGFMT_RGB15
: return DSPF_RGB15
; break;
326 case IMGFMT_BGR15
: return DSPF_RGB15
; break;
328 case IMGFMT_YUY2
: return DSPF_YUY2
; break;
329 case IMGFMT_UYVY
: return DSPF_UYVY
; break;
330 case IMGFMT_YV12
: return DSPF_YV12
; break;
331 case IMGFMT_I420
: return DSPF_I420
; break;
332 // case IMGFMT_IYUV: return DSPF_IYUV; break;
333 case IMGFMT_RGB8
: return DSPF_RGB332
; break;
334 case IMGFMT_BGR8
: return DSPF_RGB332
; break;
341 typedef struct enum1_s
{
351 DFBEnumerationResult
test_format_callback( unsigned int id
,
352 DFBDisplayLayerDescription desc
,
355 enum1_t
*params
=(enum1_t
*)data
;
356 IDirectFBDisplayLayer
*layer
;
359 if ((layer_id
== -1 )||(layer_id
== id
)) {
361 ret
= dfb
->GetDisplayLayer( dfb
, id
, &layer
);
363 DirectFBError( "dfb->GetDisplayLayer failed", ret
);
366 DFBDisplayLayerConfig dlc
;
368 if (params
->setsize
) {
369 dlc
.flags
= DLCONF_WIDTH
|DLCONF_HEIGHT
;
370 dlc
.width
= params
->width
;
371 dlc
.height
= params
->height
;
372 layer
->SetConfiguration(layer
,&dlc
);
376 dlc
.flags
= DLCONF_PIXELFORMAT
;
377 dlc
.pixelformat
= convformat(params
->format
);
379 layer
->SetOpacity(layer
,0);
381 ret
= layer
->TestConfiguration(layer
,&dlc
,NULL
);
383 layer
->Release(layer
);
385 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Test format - layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
388 // printf("Test OK\n");
389 if (params
->result
) {
390 if ((!params
->scale
) && (desc
.caps
& DLCAPS_SCREEN_LOCATION
)) {
393 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
398 if (desc
.caps
& DLCAPS_SCREEN_LOCATION
) params
->scale
=1;
399 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Test format - added layer %i scale/pos %i\n",id
,(desc
.caps
& DLCAPS_SCREEN_LOCATION
));
409 static int query_format(uint32_t format
)
411 int ret
= VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
|VFCAP_OSD
; // osd should be removed in future -> will be handled outside...
415 if (!convformat(format
)) return 0;
416 // temporary disable YV12
417 // if (format == IMGFMT_YV12) return 0;
418 // if (format == IMGFMT_I420) return 0;
419 if (format
== IMGFMT_IYUV
) return 0;
421 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Format query: %s\n",vo_format_name(format
));
423 params
.format
=format
;
428 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
431 if (params
.scale
) ret
|=VFCAP_HWSCALE_UP
|VFCAP_HWSCALE_DOWN
;
438 typedef struct videomode_s
{
449 DFBEnumerationResult
video_modes_callback( unsigned int width
,unsigned int height
,unsigned int bpp
, void *data
)
451 videomode_t
*params
=(videomode_t
*)data
;
453 int overx
=0,overy
=0,closer
=0,over
=0;
456 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Validator entered %i %i %i\n",width
,height
,bpp
);
458 overx
=width
-params
->out_width
;
459 overy
=height
-params
->out_height
;
461 if (!params
->width
) {
463 params
->height
=height
;
466 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Mode added %i %i %i\n",width
,height
,bpp
);
469 if ((params
->overy
<0)||(params
->overx
<0)) we_are_under
=1; // stored mode is smaller than req mode
470 if (abs(overx
*overy
)<abs(params
->overx
* params
->overy
)) closer
=1; // current mode is closer to desired res
471 if ((overx
>=0)&&(overy
>=0)) over
=1; // current mode is bigger or equaul to desired res
472 if ((closer
&& (over
|| we_are_under
)) || (we_are_under
&& over
)) {
474 params
->height
=height
;
477 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Better mode added %i %i %i\n",width
,height
,bpp
);
483 #define CONFIG_ERROR -1
485 static int config(uint32_t s_width
, uint32_t s_height
, uint32_t d_width
,
486 uint32_t d_height
, uint32_t flags
, char *title
,
495 int fs
= flags
& VOFLAG_FULLSCREEN
;
496 int vm
= flags
& VOFLAG_MODESWITCHING
;
497 int zoom
= flags
& VOFLAG_SWSCALE
;
498 int flip
= flags
& VOFLAG_FLIPPING
;
500 DFBSurfaceDescription dsc
;
502 DFBDisplayLayerConfig dlc
;
503 DFBSurfaceCapabilities caps
;
507 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config entered [%ix%i]\n",s_width
,s_height
);
508 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: With requested format: %s\n",vo_format_name(format
));
512 frame
->Release(frame
);
517 primary
->Release(primary
);
522 layer
->Release(layer
);
531 params
.out_width
=d_width
;
532 params
.out_height
=d_height
;
550 default: params
.bpp
=0;
553 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - trying to change videomode\n");
554 DFBCHECK (dfb
->EnumVideoModes(dfb
,video_modes_callback
,¶ms
));
555 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,params
.bpp
);
557 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,24);
559 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,32);
561 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,16);
563 ret
=dfb
->SetVideoMode(dfb
,params
.width
,params
.height
,8);
570 // just for sure clear primary layer
571 #if DIRECTFBVERSION > 913
572 ret
= dfb
->GetDisplayLayer( dfb
, DLID_PRIMARY
, &layer
);
574 ret
= layer
->GetSurface(layer
,&primary
);
576 primary
->Clear(primary
,0,0,0,0xff);
577 ret
= primary
->Flip(primary
,NULL
,0);
579 primary
->Clear(primary
,0,0,0,0xff);
581 primary
->Release(primary
);
584 layer
->Release(layer
);
591 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - looking for suitable layer\n");
592 params
.format
=format
;
595 params
.width
=s_width
;
596 params
.height
=s_height
;
599 DFBCHECK (dfb
->EnumDisplayLayers(dfb
,test_format_callback
,¶ms
));
601 if (!params
.result
) {
602 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - no suitable layer found\n");
603 params
.id
= DLID_PRIMARY
;
606 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - layer %i\n",params
.id
);
610 DFBCHECK (dfb
->GetDisplayLayer( dfb
, params
.id
, &layer
));
612 #if DIRECTFBVERSION > 916
613 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - switching layer to exclusive mode\n");
614 ret
= layer
->SetCooperativeLevel (layer
, DLSCL_EXCLUSIVE
);
617 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - cannot swith layer to exclusive mode. This could cause\nproblems. You may need to select correct pixel format manually!\n");
618 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret
);
622 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - changing layer configuration (size)\n");
623 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
625 dlc
.height
= s_height
;
627 ret
= layer
->SetConfiguration(layer
,&dlc
);
630 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (size)\n");
631 DirectFBError("MPlayer - Layer size change.",ret
);
635 // look if we need to change pixel fromat of layer
636 // and just for sure fetch also all layer propreties
637 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
| DLCONF_OPTIONS
| DLCONF_BUFFERMODE
;
639 ret
= layer
->GetConfiguration(layer
,&dlc
);
641 dlc
.flags
= DLCONF_PIXELFORMAT
| DLCONF_WIDTH
| DLCONF_HEIGHT
;
644 mp_msg(MSGT_VO
, MSGL_WARN
,"DirectFB: Warning - could not get layer properties!\n");
646 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Layer reports format:%x\n",dlc
.pixelformat
);
649 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
651 dlc
.flags
= DLCONF_PIXELFORMAT
;
652 dlc
.pixelformat
= convformat(params
.format
);
654 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Desired pixelformat: %x\n",dlc
.pixelformat
);
656 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - changing layer configuration (format)\n");
657 ret
= layer
->SetConfiguration(layer
,&dlc
);
661 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc
.flags
);
662 DirectFBError("MPlayer - layer pixelformat change",ret
);
664 // ugly fbdev workabout - try to switch pixelformat via videomode change
665 switch (dlc
.pixelformat
) {
667 case DSPF_RGB32
: bpp
=32;break;
668 case DSPF_RGB24
: bpp
=24;break;
669 case DSPF_RGB16
: bpp
=16;break;
670 #if DIRECTFBVERSION > 915
671 case DSPF_ARGB1555
: bpp
=15;break;
673 case DSPF_RGB15
: bpp
=15;break;
675 case DSPF_RGB332
: bpp
=8;break;
678 switch (dlc
.pixelformat
) {
683 #if DIRECTFBVERSION > 915
689 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Trying to recover via videomode change (VM).\n");
691 dlc
.flags
= DLCONF_WIDTH
| DLCONF_HEIGHT
;
692 if (DFB_OK
==layer
->GetConfiguration(layer
,&dlc
)) {
693 // try to set videomode
694 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Videomode %ix%i BPP %i\n",dlc
.width
,dlc
.height
,bpp
);
695 ret
= dfb
->SetVideoMode(dfb
,dlc
.width
,dlc
.height
,bpp
);
696 if (ret
) DirectFBError("MPlayer - VM - pixelformat change",ret
);
700 //get current pixel format
701 dlc
.flags
= DLCONF_PIXELFORMAT
;
702 ret
= layer
->GetConfiguration(layer
,&dlc
);
704 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret
);
706 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Layer has now pixelformat [%x]\n",dlc
.pixelformat
);
709 // check if we were succesfull
710 if ((dlc
.pixelformat
!= convformat(params
.format
)) || (ret
!= DFB_OK
)) {
711 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Recovery failed!.\n");
717 default: return CONFIG_ERROR
;
724 // try triple, \double... buffering
726 dlc
.flags
= DLCONF_BUFFERMODE
;
728 if (buffer_mode
> 2) {
729 dlc
.buffermode
= DLBM_TRIPLE
;
730 ret
= layer
->SetConfiguration( layer
, &dlc
);
737 if (buffer_mode
> 1) {
738 dlc
.buffermode
= DLBM_BACKVIDEO
;
739 ret
= layer
->SetConfiguration( layer
, &dlc
);
741 dlc
.buffermode
= DLBM_BACKSYSTEM
;
742 ret
= layer
->SetConfiguration( layer
, &dlc
);
746 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Double buffering is active\n");
750 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Triple buffering is active\n");
754 #if DIRECTFBVERSION > 916
755 if (field_parity
!= -1) {
756 dlc
.flags
= DLCONF_OPTIONS
;
757 ret
= layer
->GetConfiguration( layer
, &dlc
);
759 dlc
.options
|= DLOP_FIELD_PARITY
;
760 ret
= layer
->SetConfiguration( layer
, &dlc
);
762 layer
->SetFieldParity( layer
, field_parity
);
766 mp_msg( MSGT_VO
, MSGL_INFO
, "DirectFB: Requested field parity: ");
767 switch (field_parity
) {
769 mp_msg( MSGT_VO
, MSGL_INFO
, "Don't care\n");
772 mp_msg( MSGT_VO
, MSGL_INFO
, "Top field first\n");
775 mp_msg( MSGT_VO
, MSGL_INFO
, "Bottom field first\n");
784 ret
= layer
->GetSurface(layer
,&primary
);
787 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError - could not get surface\n");
788 return CONFIG_ERROR
; // what shall we report on fail?
791 // test surface for flipping
792 DFBCHECK(primary
->GetCapabilities(primary
,&caps
));
793 #if DIRECTFBVERSION > 913
794 primary
->Clear(primary
,0,0,0,0xff);
797 if (caps
& (DSCAPS_FLIPPING
802 ret
= primary
->Flip(primary
,NULL
,0);
805 #if DIRECTFBVERSION > 913
806 primary
->Clear(primary
,0,0,0,0xff);
808 // if we have 3 buffers clean once more
809 if (caps
& DSCAPS_TRIPLE
) {
810 primary
->Flip(primary
,NULL
,0);
811 primary
->Clear(primary
,0,0,0,0xff);
819 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - flipping = %i\n",flipping
);
821 // is scale needed ? Aspect ratio and layer pos/size
825 DFBCHECK(primary
->GetSize(primary
,&width
,&height
));
827 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config - surface size = %ix%i\n",width
,height
);
829 aspect_save_orig(s_width
,s_height
);
830 aspect_save_prescale(d_width
,d_height
);
832 aspect_save_screenres(10000,10000);
833 aspect(&out_width
,&out_height
,A_ZOOM
);
835 ret
= layer
->SetScreenLocation(layer
,(1-(float)out_width
/10000)/2,(1-(float)out_height
/10000)/2,((float)out_width
/10000),((float)out_height
/10000));
837 if (ret
) mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: ConfigError in layer configuration (position)\n");
844 aspect_save_screenres(width
,height
);
847 aspect(&out_width
,&out_height
,A_ZOOM
);
849 aspect(&out_width
,&out_height
,A_NOZOOM
);
852 xoffset
= (width
- out_width
) / 2;
853 yoffset
= (height
- out_height
) / 2;
856 if (((s_width
==out_width
)&&(s_height
==out_height
)) || (params
.scale
)) {
863 // temporary buffer in case of not flipping or scaling
864 if ((!flipping
) || stretch
) {
866 DFBCHECK (primary
->GetPixelFormat (primary
, &dsc
.pixelformat
));
868 dsc
.flags
= DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
| DSDESC_WIDTH
;
871 dsc
.height
= s_height
;
873 DFBCHECK (dfb
->CreateSurface( dfb
, &dsc
, &frame
));
874 DFBCHECK(frame
->GetSize(frame
,&width
,&height
));
875 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Frame is active.\n");
878 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
880 DFBCHECK (frame
->GetPixelFormat(frame
,&pixel_format
));
882 DFBCHECK (primary
->GetPixelFormat(primary
,&pixel_format
));
885 // finally turn on layer
886 layer
->SetOpacity(layer
,255);
888 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width
,out_height
,width
,height
);
893 extern void mplayer_put_key(int code
);
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 workabout 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 reach here
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_INFO
,"DirectFB: Releasing frame\n");
1000 frame
->Release (frame
);
1005 // if (layer) layer->SetOpacity(layer,0);
1008 mp_msg(MSGT_VO
, MSGL_INFO
,"DirectFB: Releasing layer\n");
1009 layer
->Release(layer
);
1014 mp_msg(MSGT_VO
, MSGL_INFO
,"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_INFO
,"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_INFO
,"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_INFO
,"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_INFO
,"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_INFO
,"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_INFO
,"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_INFO
,"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_INFO
,"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
->width
==pitch
) ||
1151 (mpi
->flags
&(MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_ACCEPT_WIDTH
))){
1152 // we're lucky or codec accepts stride => ok, let's go!
1155 err
= frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
);
1158 err
= primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
);
1163 mp_msg(MSGT_VO
, MSGL_ERR
,"DirectFB: DR lock failed!");
1167 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1170 if(mpi
->flags
&MP_IMGFLAG_SWAPPED
){
1171 mpi
->planes
[1]=dst
+ pitch
*height
;
1172 mpi
->planes
[2]=mpi
->planes
[1] + pitch
*height
/4;
1174 mpi
->planes
[2]=dst
+ pitch
*height
;
1175 mpi
->planes
[1]=mpi
->planes
[2] + pitch
*height
/4;
1178 mpi
->stride
[0]=pitch
;
1179 mpi
->stride
[1]=mpi
->stride
[2]=pitch
/2;
1181 //YUY2 and RGB formats
1184 mpi
->stride
[0]=pitch
;
1190 if(mpi
->flags
&MP_IMGFLAG_PLANAR
){
1191 mpi
->planes
[0]= dst
+ yoffset
* pitch
+ xoffset
;
1192 mpi
->planes
[1]+= (yoffset
* pitch
) >> 2 + xoffset
>> 1;
1193 mpi
->planes
[2]+= (yoffset
* pitch
) >> 2 + xoffset
>> 1;
1195 mpi
->planes
[0]=dst
+ yoffset
* pitch
+ xoffset
* (mpi
->bpp
>> 3);
1199 mpi
->flags
|=MP_IMGFLAG_DIRECT
;
1200 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1207 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1216 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1221 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1224 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1231 dst2
= dst
+ pitch
*height
- y
*pitch
+ y
*pitch
/4 - x
/2;
1240 if (pixel_format
== DSPF_YV12
) {
1246 for (i
=0;i
<h
/2;i
++) {
1252 dst
= dst2
+ pitch
*height
/4;
1255 for (i
=0;i
<h
/2;i
++) {
1267 for (i
=0;i
<h
/2;i
++) {
1273 dst
= dst2
+ pitch
*height
/4;
1276 for (i
=0;i
<h
/2;i
++) {
1290 static uint32_t put_image(mp_image_t
*mpi
){
1293 static IDirectFBSurface
*tmp
= NULL
;
1294 DFBSurfaceDescription dsc
;
1297 // 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);
1302 if((mpi
->flags
&(MP_IMGFLAG_DIRECT
|MP_IMGFLAG_DRAW_CALLBACK
))) {
1303 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing todo\n");
1307 if (mpi
->flags
&MP_IMGFLAG_PLANAR
) {
1308 // memcpy all planes - sad but necessary
1315 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1317 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1320 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1324 p
=min(mpi
->w
,pitch
);
1326 src
= mpi
->planes
[0]+mpi
->y
*mpi
->stride
[0]+mpi
->x
;
1328 for (i
=0;i
<mpi
->h
;i
++) {
1329 memcpy(dst
+i
*pitch
,src
+i
*mpi
->stride
[0],p
);
1333 if (pixel_format
== DSPF_YV12
) {
1335 dst
+= pitch
*height
;
1337 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1339 for (i
=0;i
<mpi
->h
/2;i
++) {
1340 memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1343 dst
+= pitch
*height
/4;
1344 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1346 for (i
=0;i
<mpi
->h
/2;i
++) {
1347 memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1352 dst
+= pitch
*height
;
1354 src
= mpi
->planes
[1]+mpi
->y
*mpi
->stride
[1]+mpi
->x
/2;
1356 for (i
=0;i
<mpi
->h
/2;i
++) {
1357 memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[1],p
);
1360 dst
+= pitch
*height
/4;
1361 src
= mpi
->planes
[2]+mpi
->y
*mpi
->stride
[2]+mpi
->x
/2;
1363 for (i
=0;i
<mpi
->h
/2;i
++) {
1364 memcpy(dst
+i
*pitch
/2,src
+i
*mpi
->stride
[2],p
);
1371 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1374 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1375 dsc.preallocated[0].data = mpi->planes[0];
1376 dsc.preallocated[0].pitch = mpi->stride[0];
1377 dsc.width = mpi->width;
1378 dsc.height = mpi->height;
1379 dsc.pixelformat = convformat(mpi->imgfmt);
1381 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1389 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1391 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1399 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non planar branch\n");
1401 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
,&dst
,&pitch
));
1403 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]);
1405 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1407 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]);
1417 static int control(uint32_t request
, void *data
, ...)
1420 case VOCTRL_QUERY_FORMAT
:
1421 return query_format(*((uint32_t*)data
));
1422 case VOCTRL_GET_IMAGE
:
1423 return get_image(data
);
1424 case VOCTRL_DRAW_IMAGE
:
1425 return put_image(data
);
1426 case VOCTRL_SET_EQUALIZER
:
1432 value
= va_arg(ap
, int);
1435 return(directfb_set_video_eq(data
, value
));
1437 case VOCTRL_GET_EQUALIZER
:
1443 value
= va_arg(ap
, int*);
1446 return(directfb_get_video_eq(data
, value
));
1454 static int draw_frame(uint8_t *src
[])
1459 // hopefully will be removed soon
1461 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
1462 unsigned char *srca
, int stride
)
1467 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1470 DFBCHECK (frame
->Lock(frame
,DSLF_WRITE
|DSLF_READ
,&dst
,&pitch
));
1473 DFBCHECK (primary
->Lock(primary
,DSLF_WRITE
,&dst
,&pitch
));
1477 switch(pixel_format
) {
1480 vo_draw_alpha_rgb32(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 4*x0
,pitch
);
1484 vo_draw_alpha_rgb24(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 3*x0
,pitch
);
1488 vo_draw_alpha_rgb16(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1490 #if DIRECTFBVERSION > 915
1495 vo_draw_alpha_rgb15(w
,h
,src
,srca
,stride
,((uint8_t *) dst
)+pitch
*y0
+ 2*x0
,pitch
);
1499 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
,pitch
);
1503 vo_draw_alpha_yuy2(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 2*x0
+ 1,pitch
);
1508 vo_draw_alpha_yv12(w
,h
,src
,srca
,stride
,((uint8_t *) dst
) + pitch
*y0
+ 1*x0
,pitch
);
1515 static void draw_osd(void)
1517 vo_draw_text(width
,height
,draw_alpha
);