Signed-off-by: Paul B Mahol <onemda@gmail.com>
Paul B Mahol authored on 2015/10/31 02:15:22... | ... |
@@ -989,6 +989,7 @@ following image formats are supported: |
989 | 989 |
@item iLBC (Internet Low Bitrate Codec) @tab E @tab E |
990 | 990 |
@tab encoding and decoding supported through external library libilbc |
991 | 991 |
@item IMC (Intel Music Coder) @tab @tab X |
992 |
+@item Interplay ACM @tab @tab X |
|
992 | 993 |
@item MACE (Macintosh Audio Compression/Expansion) 3:1 @tab @tab X |
993 | 994 |
@item MACE (Macintosh Audio Compression/Expansion) 6:1 @tab @tab X |
994 | 995 |
@item MLP (Meridian Lossless Packing) @tab @tab X |
... | ... |
@@ -320,6 +320,7 @@ OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o |
320 | 320 |
OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o |
321 | 321 |
OBJS-$(CONFIG_INDEO4_DECODER) += indeo4.o ivi.o |
322 | 322 |
OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi.o |
323 |
+OBJS-$(CONFIG_INTERPLAY_ACM_DECODER) += interplayacm.o |
|
323 | 324 |
OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o |
324 | 325 |
OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o |
325 | 326 |
OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o |
... | ... |
@@ -399,6 +399,7 @@ void avcodec_register_all(void) |
399 | 399 |
REGISTER_DECODER(GSM_MS, gsm_ms); |
400 | 400 |
REGISTER_DECODER(IAC, iac); |
401 | 401 |
REGISTER_DECODER(IMC, imc); |
402 |
+ REGISTER_DECODER(INTERPLAY_ACM, interplay_acm); |
|
402 | 403 |
REGISTER_DECODER(MACE3, mace3); |
403 | 404 |
REGISTER_DECODER(MACE6, mace6); |
404 | 405 |
REGISTER_DECODER(METASOUND, metasound); |
... | ... |
@@ -496,6 +496,7 @@ enum AVCodecID { |
496 | 496 |
AV_CODEC_ID_DSD_LSBF_PLANAR, |
497 | 497 |
AV_CODEC_ID_DSD_MSBF_PLANAR, |
498 | 498 |
AV_CODEC_ID_4GV, |
499 |
+ AV_CODEC_ID_INTERPLAY_ACM, |
|
499 | 500 |
|
500 | 501 |
/* subtitle codecs */ |
501 | 502 |
AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. |
... | ... |
@@ -2622,6 +2622,13 @@ static const AVCodecDescriptor codec_descriptors[] = { |
2622 | 2622 |
.long_name = NULL_IF_CONFIG_SMALL("DSD (Direct Stream Digital), most significant bit first, planar"), |
2623 | 2623 |
.props = AV_CODEC_PROP_LOSSY, |
2624 | 2624 |
}, |
2625 |
+ { |
|
2626 |
+ .id = AV_CODEC_ID_INTERPLAY_ACM, |
|
2627 |
+ .type = AVMEDIA_TYPE_AUDIO, |
|
2628 |
+ .name = "interplayacm", |
|
2629 |
+ .long_name = NULL_IF_CONFIG_SMALL("Interplay ACM"), |
|
2630 |
+ .props = AV_CODEC_PROP_LOSSY, |
|
2631 |
+ }, |
|
2625 | 2632 |
|
2626 | 2633 |
/* subtitle codecs */ |
2627 | 2634 |
{ |
2628 | 2635 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,615 @@ |
0 |
+/* |
|
1 |
+ * Interplay ACM decoder |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2004-2008 Marko Kreen |
|
4 |
+ * Copyright (c) 2008 Adam Gashlin |
|
5 |
+ * Copyright (c) 2015 Paul B Mahol |
|
6 |
+ * |
|
7 |
+ * Permission to use, copy, modify, and distribute this software for any |
|
8 |
+ * purpose with or without fee is hereby granted, provided that the above |
|
9 |
+ * copyright notice and this permission notice appear in all copies. |
|
10 |
+ * |
|
11 |
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
12 |
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
13 |
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
14 |
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
15 |
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
16 |
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
17 |
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+#include "libavutil/intreadwrite.h" |
|
21 |
+#include "avcodec.h" |
|
22 |
+#define BITSTREAM_READER_LE |
|
23 |
+#include "get_bits.h" |
|
24 |
+#include "internal.h" |
|
25 |
+ |
|
26 |
+static const int8_t map_1bit[] = { -1, +1 }; |
|
27 |
+static const int8_t map_2bit_near[] = { -2, -1, +1, +2 }; |
|
28 |
+static const int8_t map_2bit_far[] = { -3, -2, +2, +3 }; |
|
29 |
+static const int8_t map_3bit[] = { -4, -3, -2, -1, +1, +2, +3, +4 }; |
|
30 |
+ |
|
31 |
+static int mul_3x3 [3 * 3 * 3]; |
|
32 |
+static int mul_3x5 [5 * 5 * 5]; |
|
33 |
+static int mul_2x11[11 * 11]; |
|
34 |
+ |
|
35 |
+typedef struct InterplayACMContext { |
|
36 |
+ GetBitContext gb; |
|
37 |
+ uint8_t *bitstream; |
|
38 |
+ int max_framesize; |
|
39 |
+ int bitstream_size; |
|
40 |
+ int bitstream_index; |
|
41 |
+ |
|
42 |
+ int level; |
|
43 |
+ int rows; |
|
44 |
+ int cols; |
|
45 |
+ int wrapbuf_len; |
|
46 |
+ int block_len; |
|
47 |
+ int skip; |
|
48 |
+ |
|
49 |
+ int *block; |
|
50 |
+ int *wrapbuf; |
|
51 |
+ int *ampbuf; |
|
52 |
+ int *midbuf; |
|
53 |
+} InterplayACMContext; |
|
54 |
+ |
|
55 |
+static av_cold int decode_init(AVCodecContext *avctx) |
|
56 |
+{ |
|
57 |
+ InterplayACMContext *s = avctx->priv_data; |
|
58 |
+ int x1, x2, x3; |
|
59 |
+ |
|
60 |
+ if (avctx->extradata_size < 14) |
|
61 |
+ return AVERROR_INVALIDDATA; |
|
62 |
+ |
|
63 |
+ s->level = AV_RL16(avctx->extradata + 12) & 0xf; |
|
64 |
+ s->rows = AV_RL16(avctx->extradata + 12) >> 4; |
|
65 |
+ s->cols = 1 << s->level; |
|
66 |
+ s->wrapbuf_len = 2 * s->cols - 2; |
|
67 |
+ s->block_len = s->rows * s->cols; |
|
68 |
+ s->max_framesize = s->block_len; |
|
69 |
+ |
|
70 |
+ s->block = av_calloc(s->block_len, sizeof(int)); |
|
71 |
+ s->wrapbuf = av_calloc(s->wrapbuf_len, sizeof(int)); |
|
72 |
+ s->ampbuf = av_calloc(0x10000, sizeof(int)); |
|
73 |
+ s->bitstream = av_calloc(s->max_framesize, sizeof(*s->bitstream)); |
|
74 |
+ if (!s->block || !s->wrapbuf || !s->ampbuf || !s->bitstream) |
|
75 |
+ return AVERROR(ENOMEM); |
|
76 |
+ |
|
77 |
+ s->midbuf = s->ampbuf + 0x8000; |
|
78 |
+ avctx->sample_fmt = AV_SAMPLE_FMT_S16; |
|
79 |
+ |
|
80 |
+ for (x3 = 0; x3 < 3; x3++) |
|
81 |
+ for (x2 = 0; x2 < 3; x2++) |
|
82 |
+ for (x1 = 0; x1 < 3; x1++) |
|
83 |
+ mul_3x3[x1 + x2 * 3 + x3* 3 * 3] = x1 + (x2 << 4) + (x3 << 8); |
|
84 |
+ for (x3 = 0; x3 < 5; x3++) |
|
85 |
+ for (x2 = 0; x2 < 5; x2++) |
|
86 |
+ for (x1 = 0; x1 < 5; x1++) |
|
87 |
+ mul_3x5[x1 + x2 * 5 + x3 * 5 * 5] = x1 + (x2 << 4) + (x3 << 8); |
|
88 |
+ for (x2 = 0; x2 < 11; x2++) |
|
89 |
+ for (x1 = 0; x1 < 11; x1++) |
|
90 |
+ mul_2x11[x1 + x2 * 11] = x1 + (x2 << 4); |
|
91 |
+ |
|
92 |
+ return 0; |
|
93 |
+} |
|
94 |
+ |
|
95 |
+#define set_pos(s, r, c, idx) do { \ |
|
96 |
+ unsigned pos = ((r) << s->level) + (c); \ |
|
97 |
+ s->block[pos] = s->midbuf[(idx)]; \ |
|
98 |
+ } while (0) |
|
99 |
+ |
|
100 |
+static int zero(InterplayACMContext *s, unsigned ind, unsigned col) |
|
101 |
+{ |
|
102 |
+ unsigned i; |
|
103 |
+ |
|
104 |
+ for (i = 0; i < s->rows; i++) |
|
105 |
+ set_pos(s, i, col, 0); |
|
106 |
+ return 0; |
|
107 |
+} |
|
108 |
+ |
|
109 |
+static int bad(InterplayACMContext *s, unsigned ind, unsigned col) |
|
110 |
+{ |
|
111 |
+ return AVERROR_INVALIDDATA; |
|
112 |
+} |
|
113 |
+ |
|
114 |
+static int linear(InterplayACMContext *s, unsigned ind, unsigned col) |
|
115 |
+{ |
|
116 |
+ GetBitContext *gb = &s->gb; |
|
117 |
+ unsigned int i; |
|
118 |
+ int b, middle = 1 << (ind - 1); |
|
119 |
+ |
|
120 |
+ for (i = 0; i < s->rows; i++) { |
|
121 |
+ b = get_bits(gb, ind); |
|
122 |
+ set_pos(s, i, col, b - middle); |
|
123 |
+ } |
|
124 |
+ return 0; |
|
125 |
+} |
|
126 |
+ |
|
127 |
+static int k13(InterplayACMContext *s, unsigned ind, unsigned col) |
|
128 |
+{ |
|
129 |
+ GetBitContext *gb = &s->gb; |
|
130 |
+ unsigned i, b; |
|
131 |
+ |
|
132 |
+ for (i = 0; i < s->rows; i++) { |
|
133 |
+ b = get_bits1(gb); |
|
134 |
+ if (b == 0) { |
|
135 |
+ set_pos(s, i++, col, 0); |
|
136 |
+ if (i >= s->rows) |
|
137 |
+ break; |
|
138 |
+ set_pos(s, i, col, 0); |
|
139 |
+ continue; |
|
140 |
+ } |
|
141 |
+ b = get_bits1(gb); |
|
142 |
+ if (b == 0) { |
|
143 |
+ set_pos(s, i, col, 0); |
|
144 |
+ continue; |
|
145 |
+ } |
|
146 |
+ b = get_bits1(gb); |
|
147 |
+ set_pos(s, i, col, map_1bit[b]); |
|
148 |
+ } |
|
149 |
+ return 0; |
|
150 |
+} |
|
151 |
+ |
|
152 |
+static int k12(InterplayACMContext *s, unsigned ind, unsigned col) |
|
153 |
+{ |
|
154 |
+ GetBitContext *gb = &s->gb; |
|
155 |
+ unsigned i, b; |
|
156 |
+ |
|
157 |
+ for (i = 0; i < s->rows; i++) { |
|
158 |
+ b = get_bits1(gb); |
|
159 |
+ if (b == 0) { |
|
160 |
+ set_pos(s, i, col, 0); |
|
161 |
+ continue; |
|
162 |
+ } |
|
163 |
+ |
|
164 |
+ b = get_bits1(gb); |
|
165 |
+ set_pos(s, i, col, map_1bit[b]); |
|
166 |
+ } |
|
167 |
+ return 0; |
|
168 |
+} |
|
169 |
+ |
|
170 |
+static int k24(InterplayACMContext *s, unsigned ind, unsigned col) |
|
171 |
+{ |
|
172 |
+ GetBitContext *gb = &s->gb; |
|
173 |
+ unsigned i, b; |
|
174 |
+ |
|
175 |
+ for (i = 0; i < s->rows; i++) { |
|
176 |
+ b = get_bits1(gb); |
|
177 |
+ if (b == 0) { |
|
178 |
+ set_pos(s, i++, col, 0); |
|
179 |
+ if (i >= s->rows) break; |
|
180 |
+ set_pos(s, i, col, 0); |
|
181 |
+ continue; |
|
182 |
+ } |
|
183 |
+ |
|
184 |
+ b = get_bits1(gb); |
|
185 |
+ if (b == 0) { |
|
186 |
+ set_pos(s, i, col, 0); |
|
187 |
+ continue; |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ b = get_bits(gb, 2); |
|
191 |
+ set_pos(s, i, col, map_2bit_near[b]); |
|
192 |
+ } |
|
193 |
+ return 0; |
|
194 |
+} |
|
195 |
+ |
|
196 |
+static int k23(InterplayACMContext *s, unsigned ind, unsigned col) |
|
197 |
+{ |
|
198 |
+ GetBitContext *gb = &s->gb; |
|
199 |
+ unsigned i, b; |
|
200 |
+ |
|
201 |
+ for (i = 0; i < s->rows; i++) { |
|
202 |
+ b = get_bits1(gb); |
|
203 |
+ if (b == 0) { |
|
204 |
+ set_pos(s, i, col, 0); |
|
205 |
+ continue; |
|
206 |
+ } |
|
207 |
+ |
|
208 |
+ b = get_bits(gb, 2); |
|
209 |
+ set_pos(s, i, col, map_2bit_near[b]); |
|
210 |
+ } |
|
211 |
+ return 0; |
|
212 |
+} |
|
213 |
+ |
|
214 |
+static int k35(InterplayACMContext *s, unsigned ind, unsigned col) |
|
215 |
+{ |
|
216 |
+ GetBitContext *gb = &s->gb; |
|
217 |
+ unsigned i, b; |
|
218 |
+ |
|
219 |
+ for (i = 0; i < s->rows; i++) { |
|
220 |
+ b = get_bits1(gb); |
|
221 |
+ if (b == 0) { |
|
222 |
+ set_pos(s, i++, col, 0); |
|
223 |
+ if (i >= s->rows) |
|
224 |
+ break; |
|
225 |
+ set_pos(s, i, col, 0); |
|
226 |
+ continue; |
|
227 |
+ } |
|
228 |
+ |
|
229 |
+ b = get_bits1(gb); |
|
230 |
+ if (b == 0) { |
|
231 |
+ set_pos(s, i, col, 0); |
|
232 |
+ continue; |
|
233 |
+ } |
|
234 |
+ |
|
235 |
+ b = get_bits1(gb); |
|
236 |
+ if (b == 0) { |
|
237 |
+ b = get_bits1(gb); |
|
238 |
+ set_pos(s, i, col, map_1bit[b]); |
|
239 |
+ continue; |
|
240 |
+ } |
|
241 |
+ |
|
242 |
+ b = get_bits(gb, 2); |
|
243 |
+ set_pos(s, i, col, map_2bit_far[b]); |
|
244 |
+ } |
|
245 |
+ return 0; |
|
246 |
+} |
|
247 |
+ |
|
248 |
+static int k34(InterplayACMContext *s, unsigned ind, unsigned col) |
|
249 |
+{ |
|
250 |
+ GetBitContext *gb = &s->gb; |
|
251 |
+ unsigned i, b; |
|
252 |
+ |
|
253 |
+ for (i = 0; i < s->rows; i++) { |
|
254 |
+ b = get_bits1(gb); |
|
255 |
+ if (b == 0) { |
|
256 |
+ set_pos(s, i, col, 0); |
|
257 |
+ continue; |
|
258 |
+ } |
|
259 |
+ |
|
260 |
+ b = get_bits1(gb); |
|
261 |
+ if (b == 0) { |
|
262 |
+ b = get_bits1(gb); |
|
263 |
+ set_pos(s, i, col, map_1bit[b]); |
|
264 |
+ continue; |
|
265 |
+ } |
|
266 |
+ |
|
267 |
+ b = get_bits(gb, 2); |
|
268 |
+ set_pos(s, i, col, map_2bit_far[b]); |
|
269 |
+ } |
|
270 |
+ return 0; |
|
271 |
+} |
|
272 |
+ |
|
273 |
+static int k45(InterplayACMContext *s, unsigned ind, unsigned col) |
|
274 |
+{ |
|
275 |
+ GetBitContext *gb = &s->gb; |
|
276 |
+ unsigned i, b; |
|
277 |
+ |
|
278 |
+ for (i = 0; i < s->rows; i++) { |
|
279 |
+ b = get_bits1(gb); |
|
280 |
+ if (b == 0) { |
|
281 |
+ set_pos(s, i, col, 0); i++; |
|
282 |
+ if (i >= s->rows) |
|
283 |
+ break; |
|
284 |
+ set_pos(s, i, col, 0); |
|
285 |
+ continue; |
|
286 |
+ } |
|
287 |
+ |
|
288 |
+ b = get_bits1(gb); |
|
289 |
+ if (b == 0) { |
|
290 |
+ set_pos(s, i, col, 0); |
|
291 |
+ continue; |
|
292 |
+ } |
|
293 |
+ |
|
294 |
+ b = get_bits(gb, 3); |
|
295 |
+ set_pos(s, i, col, map_3bit[b]); |
|
296 |
+ } |
|
297 |
+ return 0; |
|
298 |
+} |
|
299 |
+ |
|
300 |
+static int k44(InterplayACMContext *s, unsigned ind, unsigned col) |
|
301 |
+{ |
|
302 |
+ GetBitContext *gb = &s->gb; |
|
303 |
+ unsigned i, b; |
|
304 |
+ |
|
305 |
+ for (i = 0; i < s->rows; i++) { |
|
306 |
+ b = get_bits1(gb); |
|
307 |
+ if (b == 0) { |
|
308 |
+ set_pos(s, i, col, 0); |
|
309 |
+ continue; |
|
310 |
+ } |
|
311 |
+ |
|
312 |
+ b = get_bits(gb, 3); |
|
313 |
+ set_pos(s, i, col, map_3bit[b]); |
|
314 |
+ } |
|
315 |
+ return 0; |
|
316 |
+} |
|
317 |
+ |
|
318 |
+static int t15(InterplayACMContext *s, unsigned ind, unsigned col) |
|
319 |
+{ |
|
320 |
+ GetBitContext *gb = &s->gb; |
|
321 |
+ unsigned i, b; |
|
322 |
+ int n1, n2, n3; |
|
323 |
+ |
|
324 |
+ for (i = 0; i < s->rows; i++) { |
|
325 |
+ /* b = (x1) + (x2 * 3) + (x3 * 9) */ |
|
326 |
+ b = get_bits(gb, 5); |
|
327 |
+ |
|
328 |
+ n1 = (mul_3x3[b] & 0x0F) - 1; |
|
329 |
+ n2 = ((mul_3x3[b] >> 4) & 0x0F) - 1; |
|
330 |
+ n3 = ((mul_3x3[b] >> 8) & 0x0F) - 1; |
|
331 |
+ |
|
332 |
+ set_pos(s, i++, col, n1); |
|
333 |
+ if (i >= s->rows) |
|
334 |
+ break; |
|
335 |
+ set_pos(s, i++, col, n2); |
|
336 |
+ if (i >= s->rows) |
|
337 |
+ break; |
|
338 |
+ set_pos(s, i, col, n3); |
|
339 |
+ } |
|
340 |
+ return 0; |
|
341 |
+} |
|
342 |
+ |
|
343 |
+static int t27(InterplayACMContext *s, unsigned ind, unsigned col) |
|
344 |
+{ |
|
345 |
+ GetBitContext *gb = &s->gb; |
|
346 |
+ unsigned i, b; |
|
347 |
+ int n1, n2, n3; |
|
348 |
+ |
|
349 |
+ for (i = 0; i < s->rows; i++) { |
|
350 |
+ /* b = (x1) + (x2 * 5) + (x3 * 25) */ |
|
351 |
+ b = get_bits(gb, 7); |
|
352 |
+ |
|
353 |
+ n1 = (mul_3x5[b] & 0x0F) - 2; |
|
354 |
+ n2 = ((mul_3x5[b] >> 4) & 0x0F) - 2; |
|
355 |
+ n3 = ((mul_3x5[b] >> 8) & 0x0F) - 2; |
|
356 |
+ |
|
357 |
+ set_pos(s, i++, col, n1); |
|
358 |
+ if (i >= s->rows) |
|
359 |
+ break; |
|
360 |
+ set_pos(s, i++, col, n2); |
|
361 |
+ if (i >= s->rows) |
|
362 |
+ break; |
|
363 |
+ set_pos(s, i, col, n3); |
|
364 |
+ } |
|
365 |
+ return 0; |
|
366 |
+} |
|
367 |
+ |
|
368 |
+static int t37(InterplayACMContext *s, unsigned ind, unsigned col) |
|
369 |
+{ |
|
370 |
+ GetBitContext *gb = &s->gb; |
|
371 |
+ unsigned i, b; |
|
372 |
+ int n1, n2; |
|
373 |
+ for (i = 0; i < s->rows; i++) { |
|
374 |
+ /* b = (x1) + (x2 * 11) */ |
|
375 |
+ b = get_bits(gb, 7); |
|
376 |
+ |
|
377 |
+ n1 = (mul_2x11[b] & 0x0F) - 5; |
|
378 |
+ n2 = ((mul_2x11[b] >> 4) & 0x0F) - 5; |
|
379 |
+ |
|
380 |
+ set_pos(s, i++, col, n1); |
|
381 |
+ if (i >= s->rows) |
|
382 |
+ break; |
|
383 |
+ set_pos(s, i, col, n2); |
|
384 |
+ } |
|
385 |
+ return 0; |
|
386 |
+} |
|
387 |
+ |
|
388 |
+typedef int (*filler)(InterplayACMContext *s, unsigned ind, unsigned col); |
|
389 |
+ |
|
390 |
+static const filler filler_list[] = { |
|
391 |
+ zero, bad, bad, linear, |
|
392 |
+ linear, linear, linear, linear, |
|
393 |
+ linear, linear, linear, linear, |
|
394 |
+ linear, linear, linear, linear, |
|
395 |
+ linear, k13, k12, t15, |
|
396 |
+ k24, k23, t27, k35, |
|
397 |
+ k34, bad, k45, k44, |
|
398 |
+ bad, t37, bad, bad, |
|
399 |
+}; |
|
400 |
+ |
|
401 |
+static int fill_block(InterplayACMContext *s) |
|
402 |
+{ |
|
403 |
+ GetBitContext *gb = &s->gb; |
|
404 |
+ unsigned i, ind; |
|
405 |
+ int ret; |
|
406 |
+ |
|
407 |
+ for (i = 0; i < s->cols; i++) { |
|
408 |
+ ind = get_bits(gb, 5); |
|
409 |
+ ret = filler_list[ind](s, ind, i); |
|
410 |
+ if (ret < 0) |
|
411 |
+ return ret; |
|
412 |
+ } |
|
413 |
+ return 0; |
|
414 |
+} |
|
415 |
+ |
|
416 |
+static void juggle(int *wrap_p, int *block_p, unsigned sub_len, unsigned sub_count) |
|
417 |
+{ |
|
418 |
+ unsigned i, j; |
|
419 |
+ int *p, r0, r1, r2, r3; |
|
420 |
+ |
|
421 |
+ for (i = 0; i < sub_len; i++) { |
|
422 |
+ p = block_p; |
|
423 |
+ r0 = wrap_p[0]; |
|
424 |
+ r1 = wrap_p[1]; |
|
425 |
+ for (j = 0; j < sub_count/2; j++) { |
|
426 |
+ r2 = *p; |
|
427 |
+ *p = r1 * 2 + (r0 + r2); |
|
428 |
+ p += sub_len; |
|
429 |
+ r3 = *p; |
|
430 |
+ *p = r2 * 2 - (r1 + r3); |
|
431 |
+ p += sub_len; |
|
432 |
+ r0 = r2; |
|
433 |
+ r1 = r3; |
|
434 |
+ } |
|
435 |
+ |
|
436 |
+ *wrap_p++ = r0; |
|
437 |
+ *wrap_p++ = r1; |
|
438 |
+ block_p++; |
|
439 |
+ } |
|
440 |
+} |
|
441 |
+ |
|
442 |
+static void juggle_block(InterplayACMContext *s) |
|
443 |
+{ |
|
444 |
+ unsigned sub_count, sub_len, todo_count, step_subcount, i; |
|
445 |
+ int *wrap_p, *block_p, *p; |
|
446 |
+ |
|
447 |
+ /* juggle only if subblock_len > 1 */ |
|
448 |
+ if (s->level == 0) |
|
449 |
+ return; |
|
450 |
+ |
|
451 |
+ /* 2048 / subblock_len */ |
|
452 |
+ if (s->level > 9) |
|
453 |
+ step_subcount = 1; |
|
454 |
+ else |
|
455 |
+ step_subcount = (2048 >> s->level) - 2; |
|
456 |
+ |
|
457 |
+ /* Apply juggle() (rows)x(cols) |
|
458 |
+ * from (step_subcount * 2) x (subblock_len/2) |
|
459 |
+ * to (step_subcount * subblock_len) x (1) |
|
460 |
+ */ |
|
461 |
+ todo_count = s->rows; |
|
462 |
+ block_p = s->block; |
|
463 |
+ while (1) { |
|
464 |
+ wrap_p = s->wrapbuf; |
|
465 |
+ sub_count = step_subcount; |
|
466 |
+ if (sub_count > todo_count) |
|
467 |
+ sub_count = todo_count; |
|
468 |
+ |
|
469 |
+ sub_len = s->cols / 2; |
|
470 |
+ sub_count *= 2; |
|
471 |
+ |
|
472 |
+ juggle(wrap_p, block_p, sub_len, sub_count); |
|
473 |
+ wrap_p += sub_len * 2; |
|
474 |
+ |
|
475 |
+ for (i = 0, p = block_p; i < sub_count; i++) { |
|
476 |
+ p[0]++; |
|
477 |
+ p += sub_len; |
|
478 |
+ } |
|
479 |
+ |
|
480 |
+ while (sub_len > 1) { |
|
481 |
+ sub_len /= 2; |
|
482 |
+ sub_count *= 2; |
|
483 |
+ juggle(wrap_p, block_p, sub_len, sub_count); |
|
484 |
+ wrap_p += sub_len * 2; |
|
485 |
+ } |
|
486 |
+ |
|
487 |
+ if (todo_count <= step_subcount) |
|
488 |
+ break; |
|
489 |
+ |
|
490 |
+ todo_count -= step_subcount; |
|
491 |
+ block_p += step_subcount << s->level; |
|
492 |
+ } |
|
493 |
+} |
|
494 |
+ |
|
495 |
+static int decode_block(InterplayACMContext *s) |
|
496 |
+{ |
|
497 |
+ GetBitContext *gb = &s->gb; |
|
498 |
+ int pwr, count, val, i, x, ret; |
|
499 |
+ |
|
500 |
+ pwr = get_bits(gb, 4); |
|
501 |
+ val = get_bits(gb, 16); |
|
502 |
+ |
|
503 |
+ count = 1 << pwr; |
|
504 |
+ |
|
505 |
+ for (i = 0, x = 0; i < count; i++) { |
|
506 |
+ s->midbuf[i] = x; |
|
507 |
+ x += val; |
|
508 |
+ } |
|
509 |
+ |
|
510 |
+ for (i = 1, x = -val; i <= count; i++) { |
|
511 |
+ s->midbuf[-i] = x; |
|
512 |
+ x -= val; |
|
513 |
+ } |
|
514 |
+ |
|
515 |
+ ret = fill_block(s); |
|
516 |
+ if (ret < 0) |
|
517 |
+ return ret; |
|
518 |
+ |
|
519 |
+ juggle_block(s); |
|
520 |
+ |
|
521 |
+ return 0; |
|
522 |
+} |
|
523 |
+ |
|
524 |
+static int decode_frame(AVCodecContext *avctx, void *data, |
|
525 |
+ int *got_frame_ptr, AVPacket *pkt) |
|
526 |
+{ |
|
527 |
+ InterplayACMContext *s = avctx->priv_data; |
|
528 |
+ GetBitContext *gb = &s->gb; |
|
529 |
+ AVFrame *frame = data; |
|
530 |
+ const uint8_t *buf; |
|
531 |
+ int16_t *samples; |
|
532 |
+ int ret, n, buf_size, input_buf_size; |
|
533 |
+ |
|
534 |
+ if (!pkt->size && !s->bitstream_size) { |
|
535 |
+ *got_frame_ptr = 0; |
|
536 |
+ return 0; |
|
537 |
+ } |
|
538 |
+ |
|
539 |
+ buf_size = FFMIN(pkt->size, s->max_framesize - s->bitstream_size); |
|
540 |
+ input_buf_size = buf_size; |
|
541 |
+ if (s->bitstream_index + s->bitstream_size + buf_size > s->max_framesize) { |
|
542 |
+ memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); |
|
543 |
+ s->bitstream_index = 0; |
|
544 |
+ } |
|
545 |
+ if (pkt->data) |
|
546 |
+ memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], pkt->data, buf_size); |
|
547 |
+ buf = &s->bitstream[s->bitstream_index]; |
|
548 |
+ buf_size += s->bitstream_size; |
|
549 |
+ s->bitstream_size = buf_size; |
|
550 |
+ if (buf_size < s->max_framesize && pkt->data) { |
|
551 |
+ *got_frame_ptr = 0; |
|
552 |
+ return input_buf_size; |
|
553 |
+ } |
|
554 |
+ |
|
555 |
+ if ((ret = init_get_bits8(gb, buf, buf_size)) < 0) |
|
556 |
+ return ret; |
|
557 |
+ |
|
558 |
+ frame->nb_samples = s->block_len / avctx->channels; |
|
559 |
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) |
|
560 |
+ return ret; |
|
561 |
+ |
|
562 |
+ skip_bits(gb, s->skip); |
|
563 |
+ ret = decode_block(s); |
|
564 |
+ if (ret < 0) |
|
565 |
+ return ret; |
|
566 |
+ |
|
567 |
+ samples = (int16_t *)frame->data[0]; |
|
568 |
+ for (n = 0; n < frame->nb_samples * avctx->channels; n++) { |
|
569 |
+ int val = s->block[n] >> s->level; |
|
570 |
+ *samples++ = val; |
|
571 |
+ } |
|
572 |
+ |
|
573 |
+ *got_frame_ptr = 1; |
|
574 |
+ s->skip = get_bits_count(gb) - 8 * (get_bits_count(gb) / 8); |
|
575 |
+ n = get_bits_count(gb) / 8; |
|
576 |
+ |
|
577 |
+ if (n > buf_size && pkt->data) { |
|
578 |
+ s->bitstream_size = 0; |
|
579 |
+ s->bitstream_index = 0; |
|
580 |
+ return AVERROR_INVALIDDATA; |
|
581 |
+ } |
|
582 |
+ |
|
583 |
+ if (s->bitstream_size) { |
|
584 |
+ s->bitstream_index += n; |
|
585 |
+ s->bitstream_size -= n; |
|
586 |
+ return input_buf_size; |
|
587 |
+ } |
|
588 |
+ return n; |
|
589 |
+} |
|
590 |
+ |
|
591 |
+static av_cold int decode_close(AVCodecContext *avctx) |
|
592 |
+{ |
|
593 |
+ InterplayACMContext *s = avctx->priv_data; |
|
594 |
+ |
|
595 |
+ av_freep(&s->block); |
|
596 |
+ av_freep(&s->wrapbuf); |
|
597 |
+ av_freep(&s->ampbuf); |
|
598 |
+ av_freep(&s->bitstream); |
|
599 |
+ s->bitstream_size = 0; |
|
600 |
+ |
|
601 |
+ return 0; |
|
602 |
+} |
|
603 |
+ |
|
604 |
+AVCodec ff_interplay_acm_decoder = { |
|
605 |
+ .name = "interplayacm", |
|
606 |
+ .long_name = NULL_IF_CONFIG_SMALL("Interplay ACM"), |
|
607 |
+ .type = AVMEDIA_TYPE_AUDIO, |
|
608 |
+ .id = AV_CODEC_ID_INTERPLAY_ACM, |
|
609 |
+ .init = decode_init, |
|
610 |
+ .close = decode_close, |
|
611 |
+ .decode = decode_frame, |
|
612 |
+ .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1, |
|
613 |
+ .priv_data_size = sizeof(InterplayACMContext), |
|
614 |
+}; |
... | ... |
@@ -29,8 +29,8 @@ |
29 | 29 |
#include "libavutil/version.h" |
30 | 30 |
|
31 | 31 |
#define LIBAVCODEC_VERSION_MAJOR 57 |
32 |
-#define LIBAVCODEC_VERSION_MINOR 13 |
|
33 |
-#define LIBAVCODEC_VERSION_MICRO 102 |
|
32 |
+#define LIBAVCODEC_VERSION_MINOR 14 |
|
33 |
+#define LIBAVCODEC_VERSION_MICRO 100 |
|
34 | 34 |
|
35 | 35 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
36 | 36 |
LIBAVCODEC_VERSION_MINOR, \ |