2002-10-13 21:40:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
#include "vd_internal.h"
|
2007-01-31 23:04:20 +00:00
|
|
|
#include "libavutil/lzo.h"
|
2002-10-13 21:40:10 +00:00
|
|
|
|
|
|
|
#define MOD_NAME "DecLZO"
|
|
|
|
|
|
|
|
static vd_info_t info = {
|
|
|
|
"LZO compressed Video",
|
|
|
|
"lzo",
|
|
|
|
"Tilmann Bitterberg",
|
|
|
|
"Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
|
|
|
|
"based on liblzo: http://www.oberhumer.com/opensource/lzo/"
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBVD_EXTERN(lzo)
|
|
|
|
|
2002-10-19 19:06:45 +00:00
|
|
|
typedef struct {
|
2007-01-31 22:17:52 +00:00
|
|
|
uint8_t *buffer;
|
|
|
|
int bufsz;
|
2002-10-19 19:06:45 +00:00
|
|
|
int codec;
|
|
|
|
} lzo_context_t;
|
2002-10-13 21:40:10 +00:00
|
|
|
|
|
|
|
// to set/get/query special features/parameters
|
|
|
|
static int control (sh_video_t *sh, int cmd, void* arg, ...)
|
|
|
|
{
|
2002-10-19 19:06:45 +00:00
|
|
|
lzo_context_t *priv = sh->context;
|
2002-10-13 21:40:10 +00:00
|
|
|
switch(cmd){
|
|
|
|
case VDCTRL_QUERY_FORMAT:
|
2007-01-30 19:00:54 +00:00
|
|
|
if (*(int *)arg == priv->codec) return CONTROL_TRUE;
|
2002-10-13 21:40:10 +00:00
|
|
|
return CONTROL_FALSE;
|
|
|
|
}
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// init driver
|
|
|
|
static int init(sh_video_t *sh)
|
|
|
|
{
|
2002-10-19 19:06:45 +00:00
|
|
|
lzo_context_t *priv;
|
2002-10-13 21:40:10 +00:00
|
|
|
|
2007-01-31 23:04:20 +00:00
|
|
|
if (sh->bih->biSizeImage <= 0) {
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Invalid frame size\n", MOD_NAME);
|
2009-05-13 02:58:57 +00:00
|
|
|
return 0;
|
2002-10-13 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
2002-10-19 19:06:45 +00:00
|
|
|
priv = malloc(sizeof(lzo_context_t));
|
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-01-31 22:17:52 +00:00
|
|
|
priv->bufsz = sh->bih->biSizeImage;
|
2009-02-02 20:22:36 +00:00
|
|
|
priv->buffer = malloc(priv->bufsz + AV_LZO_OUTPUT_PADDING);
|
2002-10-19 19:06:45 +00:00
|
|
|
priv->codec = -1;
|
|
|
|
sh->context = priv;
|
|
|
|
|
2002-10-13 21:40:10 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// uninit driver
|
|
|
|
static void uninit(sh_video_t *sh)
|
|
|
|
{
|
2002-10-19 19:06:45 +00:00
|
|
|
lzo_context_t *priv = sh->context;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-19 19:06:45 +00:00
|
|
|
if (priv)
|
|
|
|
{
|
2007-01-31 22:17:52 +00:00
|
|
|
free(priv->buffer);
|
2002-10-19 19:06:45 +00:00
|
|
|
free(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
sh->context = NULL;
|
2002-10-13 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// decode a frame
|
|
|
|
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
mp_image_t* mpi;
|
2002-10-19 19:06:45 +00:00
|
|
|
lzo_context_t *priv = sh->context;
|
2007-01-31 22:17:52 +00:00
|
|
|
int w = priv->bufsz;
|
2002-10-13 21:40:10 +00:00
|
|
|
|
|
|
|
if (len <= 0) {
|
|
|
|
return NULL; // skipped frame
|
|
|
|
}
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2009-02-02 20:22:36 +00:00
|
|
|
r = av_lzo1x_decode(priv->buffer, &w, data, &len);
|
2007-01-31 23:04:20 +00:00
|
|
|
if (r) {
|
2007-01-31 22:17:52 +00:00
|
|
|
/* this should NEVER happen */
|
2009-05-13 02:58:57 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR,
|
2007-01-31 22:17:52 +00:00
|
|
|
"[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-10-13 21:40:10 +00:00
|
|
|
|
2007-01-31 22:15:51 +00:00
|
|
|
if (priv->codec == -1) {
|
2007-01-31 22:17:52 +00:00
|
|
|
// detect RGB24 vs. YV12 via decoded size
|
2002-10-13 21:40:10 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n",
|
|
|
|
MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
|
|
|
|
);
|
|
|
|
|
2007-01-31 23:04:20 +00:00
|
|
|
if (w == 0) {
|
2002-10-19 19:06:45 +00:00
|
|
|
priv->codec = IMGFMT_BGR24;
|
2002-10-13 21:40:10 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME);
|
|
|
|
} else if (w == (sh->bih->biSizeImage)/2) {
|
2002-10-19 19:06:45 +00:00
|
|
|
priv->codec = IMGFMT_YV12;
|
2002-10-13 21:40:10 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME);
|
|
|
|
} else {
|
2002-10-19 19:06:45 +00:00
|
|
|
priv->codec = -1;
|
2002-10-13 21:40:10 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-31 22:15:51 +00:00
|
|
|
if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) {
|
|
|
|
priv->codec = -1;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-10-13 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
2007-01-31 22:17:52 +00:00
|
|
|
mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
|
2002-10-13 21:40:10 +00:00
|
|
|
sh->disp_w, sh->disp_h);
|
|
|
|
|
|
|
|
|
|
|
|
if (!mpi) {
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-31 22:17:52 +00:00
|
|
|
mpi->planes[0] = priv->buffer;
|
|
|
|
if (priv->codec == IMGFMT_BGR24)
|
|
|
|
mpi->stride[0] = 3 * sh->disp_w;
|
|
|
|
else {
|
|
|
|
mpi->stride[0] = sh->disp_w;
|
|
|
|
mpi->planes[2] = priv->buffer + sh->disp_w*sh->disp_h;
|
|
|
|
mpi->stride[2] = sh->disp_w / 2;
|
|
|
|
mpi->planes[1] = priv->buffer + sh->disp_w*sh->disp_h*5/4;
|
|
|
|
mpi->stride[1] = sh->disp_w / 2;
|
2002-10-13 21:40:10 +00:00
|
|
|
}
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
|
2002-10-13 21:40:10 +00:00
|
|
|
"[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
|
|
|
|
(long) len, (long)w);
|
|
|
|
|
|
|
|
return mpi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: sw=4
|
|
|
|
*/
|