Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 22062:56adbcf864de
More simplification
author | reimar |
---|---|
date | Tue, 30 Jan 2007 19:00:54 +0000 |
parents | 6b82ba8d011b |
children | 34bc7e626d2b |
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 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_BGR24)?"BGR":"none"); |
39 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_YV12)?"YV12":"none"); | |
40 switch(cmd){ | |
41 case VDCTRL_QUERY_FORMAT: | |
22062 | 42 if (*(int *)arg == priv->codec) return CONTROL_TRUE; |
7729 | 43 return CONTROL_FALSE; |
44 } | |
45 return CONTROL_UNKNOWN; | |
46 } | |
47 | |
48 | |
49 // init driver | |
50 static int init(sh_video_t *sh) | |
51 { | |
7800 | 52 lzo_context_t *priv; |
7729 | 53 |
54 if (lzo_init() != LZO_E_OK) { | |
7800 | 55 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] lzo_init() failed\n", MOD_NAME); |
7729 | 56 return 0; |
57 } | |
58 | |
7800 | 59 priv = malloc(sizeof(lzo_context_t)); |
60 if (!priv) | |
61 { | |
62 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
63 return 0; | |
64 } | |
65 priv->codec = -1; | |
66 sh->context = priv; | |
7729 | 67 |
7800 | 68 priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); |
69 | |
70 if (priv->wrkmem == NULL) { | |
7729 | 71 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME); |
72 return 0; | |
73 } | |
74 | |
75 return 1; | |
76 } | |
77 | |
78 // uninit driver | |
79 static void uninit(sh_video_t *sh) | |
80 { | |
7800 | 81 lzo_context_t *priv = sh->context; |
82 | |
83 if (priv) | |
84 { | |
85 if (priv->wrkmem) | |
86 lzo_free(priv->wrkmem); | |
87 free(priv); | |
88 } | |
89 | |
90 sh->context = NULL; | |
7729 | 91 } |
92 | |
93 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
94 | |
95 // decode a frame | |
96 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
97 { | |
98 static int init_done = 0; | |
99 int r; | |
100 mp_image_t* mpi; | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7959
diff
changeset
|
101 int w; |
7800 | 102 lzo_context_t *priv = sh->context; |
7729 | 103 |
104 if (len <= 0) { | |
105 return NULL; // skipped frame | |
106 } | |
107 | |
108 | |
109 if (!init_done) { | |
22061 | 110 lzo_byte *tmp = lzo_malloc(sh->bih->biSizeImage); |
7729 | 111 |
112 // decompress one frame to see if its | |
113 // either YV12 or RGB24 | |
114 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", | |
115 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
116 ); | |
117 | |
118 /* decompress the frame */ | |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
119 w = sh->bih->biSizeImage; |
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
120 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
|
121 free(tmp); |
7729 | 122 |
123 if (r != LZO_E_OK) { | |
124 /* this should NEVER happen */ | |
125 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
126 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
127 return NULL; | |
128 } | |
129 | |
130 if (w == (sh->bih->biSizeImage)) { | |
7800 | 131 priv->codec = IMGFMT_BGR24; |
7729 | 132 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME); |
133 } else if (w == (sh->bih->biSizeImage)/2) { | |
7800 | 134 priv->codec = IMGFMT_YV12; |
7729 | 135 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME); |
136 } else { | |
7800 | 137 priv->codec = -1; |
7729 | 138 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
139 return NULL; | |
140 } | |
141 | |
7941 | 142 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) return NULL; |
7729 | 143 init_done++; |
144 } | |
145 | |
146 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, | |
147 sh->disp_w, sh->disp_h); | |
148 | |
149 | |
150 if (!mpi) { | |
151 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
152 return NULL; | |
153 } | |
154 | |
22060 | 155 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
|
156 r = lzo1x_decompress_safe (data, len, mpi->planes[0], &w, priv->wrkmem); |
7729 | 157 if (r != LZO_E_OK) { |
158 /* this should NEVER happen */ | |
159 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
160 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
161 return NULL; | |
162 } | |
163 | |
164 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, | |
165 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, | |
166 (long) len, (long)w); | |
167 | |
168 return mpi; | |
169 } | |
170 | |
171 /* vim: sw=4 | |
172 */ |