Add missing multiple inclusion guards.
[mplayer/glamo.git] / libmpcodecs / vd_lzo.c
bloba2e92a5301adb214711b84e784752de051d2f8c6
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "config.h"
5 #include "mp_msg.h"
7 #include "vd_internal.h"
8 #include "libavutil/lzo.h"
10 #define MOD_NAME "DecLZO"
12 static vd_info_t info = {
13 "LZO compressed Video",
14 "lzo",
15 "Tilmann Bitterberg",
16 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
17 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
20 LIBVD_EXTERN(lzo)
22 typedef struct {
23 uint8_t *buffer;
24 int bufsz;
25 int codec;
26 } lzo_context_t;
28 // to set/get/query special features/parameters
29 static int control (sh_video_t *sh, int cmd, void* arg, ...)
31 lzo_context_t *priv = sh->context;
32 switch(cmd){
33 case VDCTRL_QUERY_FORMAT:
34 if (*(int *)arg == priv->codec) return CONTROL_TRUE;
35 return CONTROL_FALSE;
37 return CONTROL_UNKNOWN;
41 // init driver
42 static int init(sh_video_t *sh)
44 lzo_context_t *priv;
46 if (sh->bih->biSizeImage <= 0) {
47 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Invalid frame size\n", MOD_NAME);
48 return 0;
51 priv = malloc(sizeof(lzo_context_t));
52 if (!priv)
54 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME);
55 return 0;
57 priv->bufsz = sh->bih->biSizeImage;
58 priv->buffer = malloc(priv->bufsz + LZO_OUTPUT_PADDING);
59 priv->codec = -1;
60 sh->context = priv;
62 return 1;
65 // uninit driver
66 static void uninit(sh_video_t *sh)
68 lzo_context_t *priv = sh->context;
70 if (priv)
72 free(priv->buffer);
73 free(priv);
76 sh->context = NULL;
79 // decode a frame
80 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
82 int r;
83 mp_image_t* mpi;
84 lzo_context_t *priv = sh->context;
85 int w = priv->bufsz;
87 if (len <= 0) {
88 return NULL; // skipped frame
91 r = lzo1x_decode(priv->buffer, &w, data, &len);
92 if (r) {
93 /* this should NEVER happen */
94 mp_msg (MSGT_DECVIDEO, MSGL_ERR,
95 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
96 return NULL;
99 if (priv->codec == -1) {
100 // detect RGB24 vs. YV12 via decoded size
101 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n",
102 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
105 if (w == 0) {
106 priv->codec = IMGFMT_BGR24;
107 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME);
108 } else if (w == (sh->bih->biSizeImage)/2) {
109 priv->codec = IMGFMT_YV12;
110 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME);
111 } else {
112 priv->codec = -1;
113 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME);
114 return NULL;
117 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) {
118 priv->codec = -1;
119 return NULL;
123 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
124 sh->disp_w, sh->disp_h);
127 if (!mpi) {
128 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME);
129 return NULL;
132 mpi->planes[0] = priv->buffer;
133 if (priv->codec == IMGFMT_BGR24)
134 mpi->stride[0] = 3 * sh->disp_w;
135 else {
136 mpi->stride[0] = sh->disp_w;
137 mpi->planes[2] = priv->buffer + sh->disp_w*sh->disp_h;
138 mpi->stride[2] = sh->disp_w / 2;
139 mpi->planes[1] = priv->buffer + sh->disp_w*sh->disp_h*5/4;
140 mpi->stride[1] = sh->disp_w / 2;
143 mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
144 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
145 (long) len, (long)w);
147 return mpi;
150 /* vim: sw=4