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"
|
|
|
|
|
2002-10-29 16:50:34 +00:00
|
|
|
#ifdef USE_LIBLZO
|
2002-10-13 21:40:10 +00:00
|
|
|
#include <lzo1x.h>
|
2002-10-19 18:56:48 +00:00
|
|
|
#else
|
|
|
|
#include "native/minilzo.h"
|
|
|
|
#define lzo_malloc malloc
|
|
|
|
#define lzo_free free
|
|
|
|
#endif
|
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 {
|
|
|
|
lzo_byte *wrkmem;
|
|
|
|
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
|
|
|
|
|
|
|
if (lzo_init() != LZO_E_OK) {
|
2002-10-19 19:06:45 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] lzo_init() failed\n", MOD_NAME);
|
2002-10-13 21:40:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
priv->codec = -1;
|
|
|
|
sh->context = priv;
|
|
|
|
|
|
|
|
priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS);
|
2002-10-13 21:40:10 +00:00
|
|
|
|
2002-10-19 19:06:45 +00:00
|
|
|
if (priv->wrkmem == NULL) {
|
2002-10-13 21:40:10 +00:00
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (priv)
|
|
|
|
{
|
|
|
|
if (priv->wrkmem)
|
|
|
|
lzo_free(priv->wrkmem);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
static int init_done = 0;
|
|
|
|
int r;
|
|
|
|
mp_image_t* mpi;
|
2002-11-06 23:54:29 +00:00
|
|
|
int w;
|
2002-10-19 19:06:45 +00:00
|
|
|
lzo_context_t *priv = sh->context;
|
2002-10-13 21:40:10 +00:00
|
|
|
|
|
|
|
if (len <= 0) {
|
|
|
|
return NULL; // skipped frame
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!init_done) {
|
2007-01-30 18:53:53 +00:00
|
|
|
lzo_byte *tmp = lzo_malloc(sh->bih->biSizeImage);
|
2002-10-13 21:40:10 +00:00
|
|
|
|
|
|
|
// decompress one frame to see if its
|
|
|
|
// either YV12 or RGB24
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
/* decompress the frame */
|
2006-04-09 18:25:35 +00:00
|
|
|
w = sh->bih->biSizeImage;
|
|
|
|
r = lzo1x_decompress_safe (data, len, tmp, &w, priv->wrkmem);
|
2006-03-08 10:50:16 +00:00
|
|
|
free(tmp);
|
2002-10-13 21:40:10 +00:00
|
|
|
|
|
|
|
if (r != LZO_E_OK) {
|
|
|
|
/* this should NEVER happen */
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR,
|
|
|
|
"[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w == (sh->bih->biSizeImage)) {
|
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;
|
|
|
|
}
|
|
|
|
|
2002-10-28 00:42:39 +00:00
|
|
|
if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) return NULL;
|
2002-10-13 21:40:10 +00:00
|
|
|
init_done++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0,
|
|
|
|
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-30 18:51:23 +00:00
|
|
|
w = (mpi->w * mpi->h * mpi->bpp) / 8;
|
2006-04-09 18:25:35 +00:00
|
|
|
r = lzo1x_decompress_safe (data, len, mpi->planes[0], &w, priv->wrkmem);
|
2002-10-13 21:40:10 +00:00
|
|
|
if (r != LZO_E_OK) {
|
|
|
|
/* this should NEVER happen */
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_ERR,
|
|
|
|
"[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
|
|
|
|
"[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
|
|
|
|
(long) len, (long)w);
|
|
|
|
|
|
|
|
return mpi;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: sw=4
|
|
|
|
*/
|