2002-07-10 20:56:57 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_XVID
|
|
|
|
|
|
|
|
#include "vd_internal.h"
|
2003-08-13 16:29:32 +00:00
|
|
|
#include "m_option.h"
|
2002-07-10 20:56:57 +00:00
|
|
|
|
|
|
|
#include <xvid.h>
|
|
|
|
|
2002-12-18 08:10:24 +00:00
|
|
|
#ifdef XVID_API_UNSTABLE
|
|
|
|
#warning *******************************************************************
|
|
|
|
#warning ** **
|
|
|
|
#warning ** Y O U '' R E U S I N G U N S T A B L E S O F T W A R E **
|
|
|
|
#warning ** **
|
|
|
|
#warning ** There are bugs, this code could crash, could blow up your PC **
|
|
|
|
#warning ** or the whole building and do many other nasty things ! **
|
|
|
|
#warning ** **
|
|
|
|
#warning ** If you want stable code use stable XViD releases (0.9.x). **
|
|
|
|
#warning ** **
|
|
|
|
#warning *******************************************************************
|
2002-12-15 18:35:11 +00:00
|
|
|
#endif
|
|
|
|
|
2003-04-02 20:31:47 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *y;
|
|
|
|
void *u;
|
|
|
|
void *v;
|
|
|
|
int stride_y;
|
|
|
|
int stride_uv;
|
|
|
|
}
|
|
|
|
DIVX4_DEC_PICTURE;
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-07-10 20:56:57 +00:00
|
|
|
static vd_info_t info =
|
|
|
|
{
|
|
|
|
"xvid decoder",
|
|
|
|
"xvid",
|
|
|
|
"Albeu",
|
|
|
|
"Albeu",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBVD_EXTERN(xvid)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int cs;
|
2002-07-20 13:53:53 +00:00
|
|
|
unsigned char img_type;
|
2002-07-10 20:56:57 +00:00
|
|
|
void* hdl;
|
|
|
|
mp_image_t* mpi;
|
|
|
|
} priv_t;
|
|
|
|
|
2002-07-20 13:53:53 +00:00
|
|
|
static int do_dr2 = 0;
|
|
|
|
|
2003-08-13 16:29:32 +00:00
|
|
|
m_option_t xvid_dec_opts[] = {
|
2002-07-20 13:53:53 +00:00
|
|
|
{ "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL},
|
|
|
|
{ "nodr2", &do_dr2, CONF_TYPE_FLAG, 0, 1, 0, NULL},
|
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2002-07-10 20:56:57 +00:00
|
|
|
// to set/get/query special features/parameters
|
|
|
|
static int control(sh_video_t *sh,int cmd,void* arg,...){
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// init driver
|
|
|
|
static int init(sh_video_t *sh){
|
|
|
|
XVID_INIT_PARAM ini;
|
|
|
|
XVID_DEC_PARAM dec_p;
|
|
|
|
priv_t* p;
|
|
|
|
int cs;
|
|
|
|
|
2002-12-18 08:10:24 +00:00
|
|
|
#ifdef XVID_API_UNSTABLE
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_WARN,
|
|
|
|
"\n"
|
|
|
|
"*******************************************************************\n"
|
|
|
|
"** **\n"
|
|
|
|
"** Y O U ' R E U S I N G U N S T A B L E S O F T W A R E **\n"
|
|
|
|
"** **\n"
|
|
|
|
"** There are bugs, this code could crash, could blow up your PC **\n"
|
|
|
|
"** or the whole building and do many other nasty things ! **\n"
|
|
|
|
"** **\n"
|
|
|
|
"** If you want stable code use stable XViD releases (0.9.x). **\n"
|
|
|
|
"** **\n"
|
|
|
|
"*******************************************************************\n"
|
|
|
|
"\n");
|
|
|
|
#endif
|
|
|
|
|
2002-07-10 20:56:57 +00:00
|
|
|
memset(&ini,0,sizeof(XVID_INIT_PARAM));
|
|
|
|
memset(&dec_p,0,sizeof(XVID_DEC_PARAM));
|
|
|
|
|
|
|
|
if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(sh->codec->outfmt[sh->outfmtidx]){
|
|
|
|
case IMGFMT_YV12:
|
2002-07-22 14:54:34 +00:00
|
|
|
#ifdef XVID_CSP_EXTERN
|
2002-07-20 13:53:53 +00:00
|
|
|
cs= do_dr2 ? XVID_CSP_EXTERN : XVID_CSP_USER;
|
2002-07-22 14:54:34 +00:00
|
|
|
#else
|
|
|
|
cs= XVID_CSP_USER;
|
|
|
|
#endif
|
2002-07-10 20:56:57 +00:00
|
|
|
break;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
cs=XVID_CSP_YUY2;
|
|
|
|
break;
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
cs=XVID_CSP_UYVY;
|
|
|
|
break;
|
|
|
|
case IMGFMT_I420:
|
2002-07-22 14:54:34 +00:00
|
|
|
case IMGFMT_IYUV:
|
2002-07-10 20:56:57 +00:00
|
|
|
cs=XVID_CSP_I420;
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR15:
|
|
|
|
cs=XVID_CSP_RGB555;
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR16:
|
|
|
|
cs=XVID_CSP_RGB565;
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
cs=XVID_CSP_RGB24;
|
|
|
|
break;
|
|
|
|
case IMGFMT_BGR32:
|
|
|
|
cs=XVID_CSP_RGB32;
|
|
|
|
break;
|
|
|
|
case IMGFMT_YVYU:
|
|
|
|
cs=XVID_CSP_YVYU;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",sh->codec->outfmt[sh->outfmtidx]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xvid_init(NULL, 0, &ini, NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(ini.api_version != API_VERSION) {
|
|
|
|
if(ini.api_version < API_VERSION) {
|
2003-02-01 12:27:51 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Too old version of xvid (min. %d)\n",API_VERSION);
|
2002-07-10 20:56:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Bad xvid version %d was compiled with %d\n",
|
|
|
|
ini.api_version,API_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
dec_p.width = sh->disp_w;
|
|
|
|
dec_p.height = sh->disp_h;
|
|
|
|
|
|
|
|
if(xvid_decore(NULL, XVID_DEC_CREATE, &dec_p, NULL)) {
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"xvid init failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (priv_t*)malloc(sizeof(priv_t));
|
|
|
|
p->cs = cs;
|
|
|
|
p->hdl = dec_p.handle;
|
|
|
|
sh->context = p;
|
|
|
|
|
2002-07-20 13:53:53 +00:00
|
|
|
switch(cs) {
|
2002-07-22 14:54:34 +00:00
|
|
|
#ifdef XVID_CSP_EXTERN
|
2002-07-20 13:53:53 +00:00
|
|
|
case XVID_CSP_EXTERN:
|
|
|
|
p->img_type = MP_IMGTYPE_STATIC;
|
|
|
|
break;
|
2002-07-22 14:54:34 +00:00
|
|
|
#endif
|
2002-07-20 13:53:53 +00:00
|
|
|
case XVID_CSP_USER:
|
|
|
|
p->img_type = MP_IMGTYPE_EXPORT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
p->img_type = MP_IMGTYPE_TEMP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-10 20:56:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// uninit driver
|
|
|
|
static void uninit(sh_video_t *sh){
|
|
|
|
priv_t* p = sh->context;
|
|
|
|
if(!p)
|
|
|
|
return;
|
|
|
|
xvid_decore(p->hdl,XVID_DEC_DESTROY, NULL, NULL);
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// decode a frame
|
|
|
|
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
|
|
|
XVID_DEC_FRAME dec;
|
2003-02-06 20:24:14 +00:00
|
|
|
DIVX4_DEC_PICTURE d4_pic;
|
2002-08-05 01:53:17 +00:00
|
|
|
#ifdef XVID_CSP_EXTERN
|
2002-07-20 13:53:53 +00:00
|
|
|
XVID_DEC_PICTURE pic;
|
2002-08-05 01:53:17 +00:00
|
|
|
#endif
|
2002-07-10 20:56:57 +00:00
|
|
|
priv_t* p = sh->context;
|
|
|
|
|
2002-07-20 13:53:53 +00:00
|
|
|
mp_image_t* mpi = mpcodecs_get_image(sh, p->img_type,
|
2002-07-10 20:56:57 +00:00
|
|
|
MP_IMGFLAG_ACCEPT_STRIDE,
|
|
|
|
sh->disp_w,sh->disp_h);
|
|
|
|
|
|
|
|
if(!data || !mpi || len <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(&dec,0,sizeof(XVID_DEC_FRAME));
|
|
|
|
|
|
|
|
dec.bitstream = data;
|
|
|
|
dec.length = len;
|
2002-12-18 08:10:24 +00:00
|
|
|
#ifdef XVID_API_UNSTABLE
|
2002-12-15 18:35:11 +00:00
|
|
|
dec.general |= XVID_DEC_LOWDELAY;
|
|
|
|
#endif
|
2002-07-10 20:56:57 +00:00
|
|
|
switch(p->cs) {
|
|
|
|
case XVID_CSP_USER:
|
|
|
|
dec.image = &d4_pic;
|
|
|
|
break;
|
2002-07-22 14:54:34 +00:00
|
|
|
#ifdef XVID_CSP_EXTERN
|
2002-07-20 13:53:53 +00:00
|
|
|
case XVID_CSP_EXTERN:
|
|
|
|
pic.y = mpi->planes[0];
|
|
|
|
pic.u = mpi->planes[1];
|
|
|
|
pic.v = mpi->planes[2];
|
|
|
|
pic.stride_y = mpi->stride[0];
|
|
|
|
pic.stride_u = mpi->stride[1];
|
|
|
|
pic.stride_v = mpi->stride[2];
|
|
|
|
dec.image = &pic;
|
|
|
|
break;
|
2002-07-22 14:54:34 +00:00
|
|
|
#endif
|
2002-07-10 20:56:57 +00:00
|
|
|
default:
|
|
|
|
dec.image = mpi->planes[0];
|
|
|
|
if(IMGFMT_IS_BGR(mpi->imgfmt) || IMGFMT_IS_RGB(mpi->imgfmt))
|
|
|
|
dec.stride = mpi->width;
|
|
|
|
else
|
|
|
|
dec.stride = mpi->stride[0];
|
|
|
|
}
|
|
|
|
dec.colorspace = p->cs;
|
|
|
|
|
|
|
|
if(xvid_decore(p->hdl,XVID_DEC_DECODE,&dec,NULL)) {
|
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"decoding error\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(p->cs == XVID_CSP_USER) {
|
|
|
|
mpi->planes[0] = d4_pic.y;
|
|
|
|
mpi->planes[1] = d4_pic.u;
|
|
|
|
mpi->planes[2] = d4_pic.v;
|
|
|
|
mpi->stride[0] = d4_pic.stride_y;
|
|
|
|
mpi->stride[1] = mpi->stride[2] = d4_pic.stride_uv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mpi;
|
|
|
|
}
|
2003-04-02 20:31:47 +00:00
|
|
|
#endif //have_xvid
|