/*
MPlayer video driver for DirectFramebuffer device
(C) 2002
Written by Jiri Svoboda <Jiri.Svoboda@seznam.cz>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
// directfb includes
#include <directfb.h>
// other things
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __linux__
#include <sys/kd.h>
#else
#include <linux/kd.h>
#endif
#include "config.h"
#include "video_out.h"
#include "video_out_internal.h"
#include "fastmemcpy.h"
#include "sub.h"
#include "mp_msg.h"
#include "aspect.h"
#ifndef min
#define min(x,y) (((x)<(y))?(x):(y))
#endif
#if DIRECTFBVERSION > 917
// triple buffering
#define TRIPLE 1
#endif
static vo_info_t info = {
"Direct Framebuffer Device",
"directfb",
"Jiri Svoboda Jiri.Svoboda@seznam.cz",
"v 2.0 (for DirectFB version >=0.9.13)"
};
LIBVO_EXTERN(directfb)
extern int verbose;
/******************************
* vo_directfb globals *
******************************/
#define DFBCHECK(x...) \
{ \
DFBResult err = x; \
\
if (err != DFB_OK) \
{ \
fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
DirectFBErrorFatal( #x, err ); \
} \
}
/*
* filled by preinit
*/
// main DirectFB handle
static IDirectFB *dfb = NULL;
// keyboard handle
static IDirectFBInputDevice *keyboard = NULL;
// A buffer for input events.
static IDirectFBEventBuffer *buffer = NULL;
/*
* filled during config
*/
// handle of used layer
static IDirectFBDisplayLayer *layer = NULL;
// surface of used layer
static IDirectFBSurface *primary = NULL;
static int primarylocked = 0;
// handle of temporary surface (if used)
static IDirectFBSurface *frame = NULL;
static int framelocked = 0;
// flipping mode flag (layer/surface)
static int flipping = 0;
// scaling flag
static int stretch = 0;
// pictrure position
static int xoffset=0,yoffset=0;
// picture size
static int out_width=0,out_height=0;
// frame/primary size
static int width=0,height=0;
// frame primary format
DFBSurfacePixelFormat pixel_format;
/*
static void (*draw_alpha_p)(int w, int h, unsigned char *src,
unsigned char *srca, int stride, unsigned char *dst,
int dstride);
*/
/******************************
* cmd line parameteres *
******************************/
/* command line/config file options */
#ifdef HAVE_FBDEV
extern char *fb_dev_name;
#else
char *fb_dev_name;
#endif
char *dfb_params;
static int layer_id = -1;
static int buffer_mode = 1;
static int use_input = 1;
static int field_parity = -1;
/******************************
* implementation *
******************************/
void unlock() {
if (frame && framelocked) frame->Unlock(frame);
if (primary && primarylocked) primary->Unlock(primary);
}
static uint32_t preinit(const char *arg)
{
DFBResult ret;
mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
if (dfb) return 0; // we are already inited!
buffer_mode = 1 + vo_doublebuffering; // honor -double switch
// config stuff - borrowed from dfbmga (to be as compatible as it could be :-)
if (vo_subdevice) {
int show_help = 0;
int opt_no = 0;
while (*vo_subdevice != '\0') {
if (!strncmp(vo_subdevice, "input", 5)) {
use_input = !opt_no;
vo_subdevice += 5;
opt_no = 0;
} else if (!strncmp(vo_subdevice, "buffermode=", 11)) {
if (opt_no) {
show_help = 1;
break;
}
vo_subdevice += 11;
if (!strncmp(vo_subdevice, "single", 6)) {
buffer_mode = 1;
vo_subdevice += 6;
} else if (!strncmp(vo_subdevice, "double", 6)) {
buffer_mode = 2;
vo_subdevice += 6;
} else if (!strncmp(vo_subdevice, "triple", 6)) {
buffer_mode = 3;
vo_subdevice += 6;
} else {
show_help = 1;
break;
}
opt_no = 0;
} else if (!strncmp(vo_subdevice, "fieldparity=", 12)) {
if (opt_no) {
show_help = 1;
break;
}
vo_subdevice += 12;
if (!strncmp(vo_subdevice, "top", 3)) {
field_parity = 0;
vo_subdevice += 3;
} else if (!strncmp(vo_subdevice, "bottom", 6)) {
field_parity = 1;
vo_subdevice += 6;
} else {
show_help = 1;
break;
}
opt_no = 0;
} else if (!strncmp(vo_subdevice, "layer=", 6)) {
int tmp=-1;
if (opt_no) {
show_help = 1;
break;
}
vo_subdevice += 6;
if (sscanf(vo_subdevice,"%i",&tmp)) {
layer_id=tmp;
mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Layer id is forced to %i\n",layer_id);
} else {
show_help = 1;
break;
}
opt_no = 0;
} else if (!strncmp(vo_subdevice, "no", 2)) {
if (opt_no) {
show_help = 1;
break;
}
vo_subdevice += 2;
opt_no = 1;
} else if (*vo_subdevice == ':') {
if (opt_no) {
show_help = 1;
break;
}
vo_subdevice++;
opt_no = 0;
} else if (!strncmp(vo_subdevice, "help", 4)) {
show_help = 1;
vo_subdevice += 4;
break;
}
}
if (show_help) {
mp_msg( MSGT_VO, MSGL_ERR,
"\nvo_dfbmga command line help:\n"
"Example: mplayer -vo directfb:layer=1:buffermode=single\n"
"\nOptions (use 'no' prefix to disable):\n"
" input Use DirectFB for keyboard input\n"
"\nOther options:\n"
" layer=n\n"
" n=0..xx Use layer with id n for output (0=primary)\n"
" buffermode=(single|double|triple)\n"
" single Use single buffering\n"
" double Use double buffering\n"
" triple Use triple buffering\n"
" fieldparity=(top|bottom)\n"
" top Top field first\n"
" bottom Bottom field first\n"
"\n" );
return -1;
}
}
if (dfb_params)
{
int argc = 2;
char arg0[10] = "mplayer";
char arg1[256] = "--dfb:";
char* argv[3];
char ** a;
a = &argv[0];
strncat(arg1,dfb_params,249);
argv[0]=arg0;
argv[1]=arg1;
argv[2]=NULL;
DFBCHECK (DirectFBInit (&argc,&a));
} else {
DFBCHECK (DirectFBInit (NULL,NULL));
}
if (((directfb_major_version <= 0) &&
(dir
|