/*
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"
#include "subopt-helper.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;
// tvnorm
static int tvnorm = -1;
// 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 */
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 int get_parity(strarg_t *arg) {
if (strargcmp(arg, "top") == 0)
return 0;
if (strargcmp(arg, "bottom") == 0)
return 1;
return -1;
}
static int check_parity(void *arg) {
return get_parity(arg) != -1;
}
static int get_mode(strarg_t *arg) {
if (strargcmp(arg, "single") == 0)
return 1;
if (strargcmp(arg, "double") == 0)
return 2;
if (strargcmp(arg, "triple") == 0)
return 3;
return 0;
}
static int check_mode(void *arg) {
return get_mode(arg) != 0;
}
static uint32_t preinit(const char *arg)
{
DFBResult ret;
strarg_t mode_str = {0, NULL};
strarg_t par_str = {0, NULL};
strarg_t dfb_params = {0, NULL};
opt_t subopts[] = {
{"input", OPT_ARG_BOOL, &use_input, NULL},
{"buffermode", OPT_ARG_STR, &mode_str, check_mode},
{"fieldparity", OPT_ARG_STR, &par_str, check_parity},
{"layer", OPT_ARG_INT, &layer_id, NULL},
{"dfbopts", OPT_ARG_STR, &dfb_params, NULL},
{NULL}
};
mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
if (dfb) return 0; // we are already inited!
// set defaults
buffer_mode = 1 + vo_doublebuffering; // honor -double switch
layer_id = -1;
use_input = 1;
field_parity = -1;
if (subopt_parse(arg, subopts) != 0) {
mp_msg( MSGT_VO, MSGL_ERR,
"\n-vo directfb 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"
" dfbopts=<str>\n"
" Specify a parameter list for DirectFB\n"
"\n" );
return -1;
}
if (mode_str.len)
buffer_mode = get_mode(&mode_str);
if (par_str.len)
field_parity = get_parity(&par_str);
if (dfb_params.len > 0)
{
int argc = 2;
char arg0[10] = "mplayer";
char *arg1 = (char *)malloc(dfb_params.len + 7);
char* argv[3];
char ** a;
a = &argv[0];
strcpy(arg1, "--dfb:");
strncat(arg1, dfb_params.str, dfb_params.len);
argv[0]=arg0;
argv[1]=arg1;
argv[2]=NULL;
DFBCHECK (DirectFBInit (&argc,&a));
free(arg1);
} else {
DFBCHECK (DirectFBInit (NULL,NULL));
}
if (((directfb_major_version <= 0) &&
(directfb_minor_version <= 9) &&
(directfb_micro_version < 13)))
{
mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: Unsupported DirectFB version\n");
return 1;
}
/*
* (set options)
*/
// uncomment this if you do not wish to create a new vt for DirectFB
// DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
// uncomment this if you want to allow vt switching
// DFBCHECK (DirectFBSetOption ("vt-switching",""));
// uncomment this if you want to hide gfx cursor (req dfb
|