1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 15:52:25 +00:00

Sync with GomGom's patch-12 version.

updated copyright
  two new postprocessing options
  display aspect ratio support


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13653 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
iive 2004-10-16 14:10:57 +00:00
parent 8d5af4018f
commit 4a1200b8ea

View File

@ -1,9 +1,9 @@
/***************************************************************************** /*****************************************************************************
* *
* - XviD 1.0 decoder module for mplayer/mencoder - * - XviD 1.x decoder module for mplayer/mencoder -
* *
* Copyright(C) 2003 Marco Belli <elcabesa@inwind.it> * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it>
* 2003 Edouard Gomez <ed.gomez@free.fr> * 2003-2004 Edouard Gomez <ed.gomez@free.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -46,6 +46,8 @@ static int do_dr2 = 1;
static int filmeffect = 0; static int filmeffect = 0;
static int lumadeblock = 0; static int lumadeblock = 0;
static int chromadeblock = 0; static int chromadeblock = 0;
static int lumadering = 0;
static int chromadering = 0;
m_option_t xvid_dec_opts[] = { m_option_t xvid_dec_opts[] = {
{ "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "dr2", &do_dr2, CONF_TYPE_FLAG, 0, 0, 1, NULL},
@ -53,6 +55,8 @@ m_option_t xvid_dec_opts[] = {
{ "filmeffect", &filmeffect, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "filmeffect", &filmeffect, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{ "deblock-luma", &lumadeblock, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "deblock-luma", &lumadeblock, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{ "deblock-chroma", &chromadeblock, CONF_TYPE_FLAG, 0, 0, 1, NULL}, { "deblock-chroma", &chromadeblock, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{ "dering-luma", &lumadering, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{ "dering-chroma", &chromadering, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL} {NULL, NULL, 0, 0, 0, 0, NULL}
}; };
@ -65,8 +69,15 @@ typedef struct {
unsigned char img_type; unsigned char img_type;
void* hdl; void* hdl;
mp_image_t* mpi; mp_image_t* mpi;
int vo_initialized;
} priv_t; } priv_t;
/*****************************************************************************
* Module function helpers
****************************************************************************/
static float stats2aspect(xvid_dec_stats_t *stats);
/***************************************************************************** /*****************************************************************************
* Video decoder API function definitions * Video decoder API function definitions
****************************************************************************/ ****************************************************************************/
@ -86,18 +97,21 @@ static int control(sh_video_t *sh,int cmd,void* arg,...)
static int init(sh_video_t *sh) static int init(sh_video_t *sh)
{ {
xvid_gbl_info_t xvid_gbl_info;
xvid_gbl_init_t xvid_ini; xvid_gbl_init_t xvid_ini;
xvid_dec_create_t dec_p; xvid_dec_create_t dec_p;
priv_t* p; priv_t* p;
int cs; int cs;
memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t));
xvid_gbl_info.version = XVID_VERSION;
memset(&xvid_ini, 0, sizeof(xvid_gbl_init_t)); memset(&xvid_ini, 0, sizeof(xvid_gbl_init_t));
xvid_ini.version = XVID_VERSION; xvid_ini.version = XVID_VERSION;
memset(&dec_p, 0, sizeof(xvid_dec_create_t)); memset(&dec_p, 0, sizeof(xvid_dec_create_t));
dec_p.version = XVID_VERSION; dec_p.version = XVID_VERSION;
if(!mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_YV12))
return(0);
switch(sh->codec->outfmt[sh->outfmtidx]){ switch(sh->codec->outfmt[sh->outfmtidx]){
case IMGFMT_YV12: case IMGFMT_YV12:
@ -135,12 +149,28 @@ static int init(sh_video_t *sh)
return(0); return(0);
} }
/* Gather some information about the host library */
if(xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) {
mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: could not get information about the library\n");
} else {
mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n",
XVID_VERSION_MAJOR(xvid_gbl_info.actual_version),
XVID_VERSION_MINOR(xvid_gbl_info.actual_version),
XVID_VERSION_PATCH(xvid_gbl_info.actual_version),
xvid_gbl_info.build);
}
/* Initialize the xvidcore library */
if(xvid_global(NULL, XVID_GBL_INIT, &xvid_ini, NULL)) if(xvid_global(NULL, XVID_GBL_INIT, &xvid_ini, NULL))
return(0); return(0);
dec_p.width = sh->disp_w; /* We use 0 width and height so xvidcore will resize its buffers
dec_p.height = sh->disp_h; * if required. That allows this vd plugin to do resize on first
* VOL encountered (don't trust containers' width and height) */
dec_p.width = 0;
dec_p.height = 0;
/* Get a decoder instance */
if(xvid_decore(0, XVID_DEC_CREATE, &dec_p, NULL)<0) { if(xvid_decore(0, XVID_DEC_CREATE, &dec_p, NULL)<0) {
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "XviD init failed\n"); mp_msg(MSGT_DECVIDEO, MSGL_ERR, "XviD init failed\n");
return(0); return(0);
@ -149,6 +179,7 @@ static int init(sh_video_t *sh)
p = (priv_t*)malloc(sizeof(priv_t)); p = (priv_t*)malloc(sizeof(priv_t));
p->cs = cs; p->cs = cs;
p->hdl = dec_p.handle; p->hdl = dec_p.handle;
p->vo_initialized = 0;
sh->context = p; sh->context = p;
switch(cs) { switch(cs) {
@ -185,44 +216,90 @@ static void uninit(sh_video_t *sh){
static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags)
{ {
xvid_dec_frame_t dec; xvid_dec_frame_t dec;
xvid_dec_stats_t stats;
mp_image_t* mpi = NULL;
priv_t* p = sh->context; priv_t* p = sh->context;
mp_image_t* mpi = mpcodecs_get_image(sh, p->img_type,
MP_IMGFLAG_ACCEPT_STRIDE,
sh->disp_w,sh->disp_h);
if(!data || !mpi || len <= 0) if(!data || len <= 0)
return(NULL); return(NULL);
memset(&dec,0,sizeof(xvid_dec_frame_t)); memset(&dec,0,sizeof(xvid_dec_frame_t));
memset(&stats, 0, sizeof(xvid_dec_stats_t));
dec.version = XVID_VERSION; dec.version = XVID_VERSION;
stats.version = XVID_VERSION;
dec.bitstream = data; dec.bitstream = data;
dec.length = len; dec.length = len;
dec.general |= XVID_LOWDELAY dec.general |= XVID_LOWDELAY
/* XXX: if lowdelay is unset, and xvidcore internal buffers are
* used => crash. MUST FIX */
| (filmeffect ? XVID_FILMEFFECT : 0 ) | (filmeffect ? XVID_FILMEFFECT : 0 )
| (lumadeblock ? XVID_DEBLOCKY : 0 ) | (lumadeblock ? XVID_DEBLOCKY : 0 )
| (chromadeblock ? XVID_DEBLOCKUV : 0 ); | (chromadeblock ? XVID_DEBLOCKUV : 0 );
#if XVID_API >= XVID_MAKE_API(4,1)
dec.general |= (lumadering ? XVID_DEBLOCKY|XVID_DERINGY : 0 );
dec.general |= (chromadering ? XVID_DEBLOCKUV|XVID_DERINGUV : 0 );
#endif
dec.output.csp = p->cs; dec.output.csp = p->cs;
if(p->cs != XVID_CSP_INTERNAL) { /* Decoding loop because xvidcore may return VOL information for
dec.output.plane[0] = mpi->planes[0]; * on the fly buffer resizing. In that case we must decode VOL,
dec.output.plane[1] = mpi->planes[1]; * init VO, then decode the frame */
dec.output.plane[2] = mpi->planes[2]; do {
int consumed;
dec.output.stride[0] = mpi->stride[0]; /* If we don't know frame size yet, don't even try to request
dec.output.stride[1] = mpi->stride[1]; * a buffer, we must loop until we find a VOL, so VO plugin
dec.output.stride[2] = mpi->stride[2]; * is initialized and we can obviously output something */
} if (p->vo_initialized) {
mpi = mpcodecs_get_image(sh, p->img_type,
MP_IMGFLAG_ACCEPT_STRIDE,
sh->disp_w, sh->disp_h);
if(p->cs != XVID_CSP_INTERNAL) {
dec.output.plane[0] = mpi->planes[0];
dec.output.plane[1] = mpi->planes[1];
dec.output.plane[2] = mpi->planes[2];
if(xvid_decore(p->hdl, XVID_DEC_DECODE, &dec, NULL) < 0) { dec.output.stride[0] = mpi->stride[0];
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Decoding error\n"); dec.output.stride[1] = mpi->stride[1];
return(NULL); dec.output.stride[2] = mpi->stride[2];
} }
}
/* Decode data */
consumed = xvid_decore(p->hdl, XVID_DEC_DECODE, &dec, &stats);
if (consumed < 0) {
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Decoding error\n");
return(NULL);
}
if(p->cs == XVID_CSP_INTERNAL) { /* Found a VOL information stats, if VO plugin is not initialized
* yet then do it now */
if (stats.type == XVID_TYPE_VOL && !p->vo_initialized) {
sh->aspect = stats2aspect(&stats);
if(!mpcodecs_config_vo(sh, stats.data.vol.width, stats.data.vol.height, IMGFMT_YV12))
return(NULL);
/* Don't take this path twice */
p->vo_initialized = !p->vo_initialized;
}
/* Don't forget to update buffer position and buffer length */
dec.bitstream += consumed;
dec.length -= consumed;
} while ((stats.type == XVID_TYPE_VOL || stats.type == XVID_TYPE_NOTHING) && dec.length > 0);
/* There are two ways to get out of the decoding loop:
* - a frame has been returned
* - no more data in buffer and no frames returned */
/* If mpi is NULL, it proves nothing has been returned by the decoder
* so don't try to display internal buffers. */
if (mpi != NULL && p->cs == XVID_CSP_INTERNAL) {
mpi->planes[0] = dec.output.plane[0]; mpi->planes[0] = dec.output.plane[0];
mpi->planes[1] = dec.output.plane[1]; mpi->planes[1] = dec.output.plane[1];
mpi->planes[2] = dec.output.plane[2]; mpi->planes[2] = dec.output.plane[2];
@ -232,7 +309,71 @@ static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags)
mpi->stride[2] = dec.output.stride[2]; mpi->stride[2] = dec.output.stride[2];
} }
return(mpi); /* If we got out the decoding loop because the buffer was empty and there was nothing
* to output yet, then just return NULL */
return((stats.type == XVID_TYPE_NOTHING)? NULL: mpi);
}
/*****************************************************************************
* Helper functions
****************************************************************************/
/* Returns DAR value according to VOL's informations contained in stats
* param */
static float stats2aspect(xvid_dec_stats_t *stats)
{
if (stats->type == XVID_TYPE_VOL) {
float wpar;
float hpar;
float dar;
/* MPEG4 strem stores PAR (Pixel Aspect Ratio), mplayer uses
* DAR (Display Aspect Ratio)
*
* Both are related thanks to the equation:
* width
* DAR = ----- x PAR
* height
*
* As MPEG4 is so well designed (*cough*), VOL header carries
* both informations together -- lucky eh ? */
switch (stats->data.vol.par) {
case XVID_PAR_11_VGA: /* 1:1 vga (square), default if supplied PAR is not a valid value */
wpar = hpar = 1.0f;
break;
case XVID_PAR_43_PAL: /* 4:3 pal (12:11 625-line) */
wpar = 12;
hpar = 11;
break;
case XVID_PAR_43_NTSC: /* 4:3 ntsc (10:11 525-line) */
wpar = 10;
hpar = 11;
break;
case XVID_PAR_169_PAL: /* 16:9 pal (16:11 625-line) */
wpar = 16;
hpar = 11;
break;
case XVID_PAR_169_NTSC: /* 16:9 ntsc (40:33 525-line) */
wpar = 40;
hpar = 33;
break;
case XVID_PAR_EXT: /* extended par; use par_width, par_height */
wpar = stats->data.vol.par_width;
hpar = stats->data.vol.par_height;
break;
default:
wpar = hpar = 1.0f;
break;
}
dar = ((float)stats->data.vol.width*wpar);
dar /= ((float)stats->data.vol.height*hpar);
return(dar);
}
return(0.0f);
} }
/***************************************************************************** /*****************************************************************************