Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 22063:34bc7e626d2b
cosmetics: remove useless commented-out stuff.
author | reimar |
---|---|
date | Tue, 30 Jan 2007 19:01:42 +0000 |
parents | 56adbcf864de |
children | 40135eba142f |
rev | line source |
---|---|
7729 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
5 #include "mp_msg.h" | |
6 | |
7 #include "vd_internal.h" | |
8 | |
7959 | 9 #ifdef USE_LIBLZO |
7729 | 10 #include <lzo1x.h> |
7799 | 11 #else |
12 #include "native/minilzo.h" | |
13 #define lzo_malloc malloc | |
14 #define lzo_free free | |
15 #endif | |
7729 | 16 |
17 #define MOD_NAME "DecLZO" | |
18 | |
19 static vd_info_t info = { | |
20 "LZO compressed Video", | |
21 "lzo", | |
22 "Tilmann Bitterberg", | |
23 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>", | |
24 "based on liblzo: http://www.oberhumer.com/opensource/lzo/" | |
25 }; | |
26 | |
27 LIBVD_EXTERN(lzo) | |
28 | |
7800 | 29 typedef struct { |
30 lzo_byte *wrkmem; | |
31 int codec; | |
32 } lzo_context_t; | |
7729 | 33 |
34 // to set/get/query special features/parameters | |
35 static int control (sh_video_t *sh, int cmd, void* arg, ...) | |
36 { | |
7800 | 37 lzo_context_t *priv = sh->context; |
7729 | 38 switch(cmd){ |
39 case VDCTRL_QUERY_FORMAT: | |
22062 | 40 if (*(int *)arg == priv->codec) return CONTROL_TRUE; |
7729 | 41 return CONTROL_FALSE; |
42 } | |
43 return CONTROL_UNKNOWN; | |
44 } | |
45 | |
46 | |
47 // init driver | |
48 static int init(sh_video_t *sh) | |
49 { | |
7800 | 50 lzo_context_t *priv; |
7729 | 51 |
52 if (lzo_init() != LZO_E_OK) { | |
7800 | 53 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] lzo_init() failed\n", MOD_NAME); |
7729 | 54 return 0; |
55 } | |
56 | |
7800 | 57 priv = malloc(sizeof(lzo_context_t)); |
58 if (!priv) | |
59 { | |
60 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
61 return 0; | |
62 } | |
63 priv->codec = -1; | |
64 sh->context = priv; | |
7729 | 65 |
7800 | 66 priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); |
67 | |
68 if (priv->wrkmem == NULL) { | |
7729 | 69 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME); |
70 return 0; | |
71 } | |
72 | |
73 return 1; | |
74 } | |
75 | |
76 // uninit driver | |
77 static void uninit(sh_video_t *sh) | |
78 { | |
7800 | 79 lzo_context_t *priv = sh->context; |
80 | |
81 if (priv) | |
82 { | |
83 if (priv->wrkmem) | |
84 lzo_free(priv->wrkmem); | |
85 free(priv); | |
86 } | |
87 | |
88 sh->context = NULL; | |
7729 | 89 } |
90 | |
91 // decode a frame | |
92 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
93 { | |
94 static int init_done = 0; | |
95 int r; | |
96 mp_image_t* mpi; | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7959
diff
changeset
|
97 int w; |
7800 | 98 lzo_context_t *priv = sh->context; |
7729 | 99 |
100 if (len <= 0) { | |
101 return NULL; // skipped frame | |
102 } | |
103 | |
104 | |
105 if (!init_done) { | |
22061 | 106 lzo_byte *tmp = lzo_malloc(sh->bih->biSizeImage); |
7729 | 107 |
108 // decompress one frame to see if its | |
109 // either YV12 or RGB24 | |
110 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", | |
111 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
112 ); | |
113 | |
114 /* decompress the frame */ | |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
115 w = sh->bih->biSizeImage; |
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
116 r = lzo1x_decompress_safe (data, len, tmp, &w, priv->wrkmem); |
17768
c7b1b78f14bd
free tmp earlier, it is not needed below and might leak on errors otherwise
reimar
parents:
8123
diff
changeset
|
117 free(tmp); |
7729 | 118 |
119 if (r != LZO_E_OK) { | |
120 /* this should NEVER happen */ | |
121 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
122 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
123 return NULL; | |
124 } | |
125 | |
126 if (w == (sh->bih->biSizeImage)) { | |
7800 | 127 priv->codec = IMGFMT_BGR24; |
7729 | 128 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME); |
129 } else if (w == (sh->bih->biSizeImage)/2) { | |
7800 | 130 priv->codec = IMGFMT_YV12; |
7729 | 131 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME); |
132 } else { | |
7800 | 133 priv->codec = -1; |
7729 | 134 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
135 return NULL; | |
136 } | |
137 | |
7941 | 138 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) return NULL; |
7729 | 139 init_done++; |
140 } | |
141 | |
142 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, | |
143 sh->disp_w, sh->disp_h); | |
144 | |
145 | |
146 if (!mpi) { | |
147 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
148 return NULL; | |
149 } | |
150 | |
22060 | 151 w = (mpi->w * mpi->h * mpi->bpp) / 8; |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
152 r = lzo1x_decompress_safe (data, len, mpi->planes[0], &w, priv->wrkmem); |
7729 | 153 if (r != LZO_E_OK) { |
154 /* this should NEVER happen */ | |
155 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
156 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
157 return NULL; | |
158 } | |
159 | |
160 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, | |
161 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, | |
162 (long) len, (long)w); | |
163 | |
164 return mpi; | |
165 } | |
166 | |
167 /* vim: sw=4 | |
168 */ |