... | ... |
@@ -1526,6 +1526,7 @@ aac_latm_decoder_select="aac_decoder aac_latm_parser" |
1526 | 1526 |
ac3_decoder_select="mdct ac3dsp ac3_parser dsputil" |
1527 | 1527 |
ac3_encoder_select="mdct ac3dsp dsputil" |
1528 | 1528 |
ac3_fixed_encoder_select="mdct ac3dsp dsputil" |
1529 |
+aic_decoder_select="dsputil golomb" |
|
1529 | 1530 |
alac_encoder_select="lpc" |
1530 | 1531 |
als_decoder_select="dsputil" |
1531 | 1532 |
amrnb_decoder_select="lsp" |
... | ... |
@@ -430,6 +430,7 @@ following image formats are supported: |
430 | 430 |
@item AMV Video @tab @tab X |
431 | 431 |
@tab Used in Chinese MP3 players. |
432 | 432 |
@item ANSI/ASCII art @tab @tab X |
433 |
+@item Apple Intermediate Codec @tab @tab X |
|
433 | 434 |
@item Apple MJPEG-B @tab @tab X |
434 | 435 |
@item Apple ProRes @tab X @tab X |
435 | 436 |
@item Apple QuickDraw @tab @tab X |
... | ... |
@@ -83,6 +83,7 @@ OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3dec_data.o ac3.o kbdwin.o |
83 | 83 |
OBJS-$(CONFIG_AC3_ENCODER) += ac3enc_float.o ac3enc.o ac3tab.o \ |
84 | 84 |
ac3.o kbdwin.o |
85 | 85 |
OBJS-$(CONFIG_AC3_FIXED_ENCODER) += ac3enc_fixed.o ac3enc.o ac3tab.o ac3.o |
86 |
+OBJS-$(CONFIG_AIC_DECODER) += aic.o |
|
86 | 87 |
OBJS-$(CONFIG_ALAC_DECODER) += alac.o alac_data.o |
87 | 88 |
OBJS-$(CONFIG_ALAC_ENCODER) += alacenc.o alac_data.o |
88 | 89 |
OBJS-$(CONFIG_ALS_DECODER) += alsdec.o bgmc.o mpeg4audio.o |
89 | 90 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,477 @@ |
0 |
+/* |
|
1 |
+ * Apple Intermediate Codec decoder |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2013 Konstantin Shishkov |
|
4 |
+ * |
|
5 |
+ * This file is part of Libav. |
|
6 |
+ * |
|
7 |
+ * Libav is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * Libav is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with Libav; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+#include "avcodec.h" |
|
23 |
+#include "bytestream.h" |
|
24 |
+#include "dsputil.h" |
|
25 |
+#include "internal.h" |
|
26 |
+#include "get_bits.h" |
|
27 |
+#include "golomb.h" |
|
28 |
+#include "unary.h" |
|
29 |
+ |
|
30 |
+#define AIC_HDR_SIZE 24 |
|
31 |
+#define AIC_BAND_COEFFS (64 + 32 + 192 + 96) |
|
32 |
+ |
|
33 |
+enum AICBands { |
|
34 |
+ COEFF_LUMA = 0, |
|
35 |
+ COEFF_CHROMA, |
|
36 |
+ COEFF_LUMA_EXT, |
|
37 |
+ COEFF_CHROMA_EXT, |
|
38 |
+ NUM_BANDS |
|
39 |
+}; |
|
40 |
+ |
|
41 |
+static const int aic_num_band_coeffs[NUM_BANDS] = { 64, 32, 192, 96 }; |
|
42 |
+ |
|
43 |
+static const int aic_band_off[NUM_BANDS] = { 0, 64, 96, 288 }; |
|
44 |
+ |
|
45 |
+static const uint8_t aic_quant_matrix[64] = { |
|
46 |
+ 8, 16, 19, 22, 22, 26, 26, 27, |
|
47 |
+ 16, 16, 22, 22, 26, 27, 27, 29, |
|
48 |
+ 19, 22, 26, 26, 27, 29, 29, 35, |
|
49 |
+ 22, 24, 27, 27, 29, 32, 34, 38, |
|
50 |
+ 26, 27, 29, 29, 32, 35, 38, 46, |
|
51 |
+ 27, 29, 34, 34, 35, 40, 46, 56, |
|
52 |
+ 29, 34, 34, 37, 40, 48, 56, 69, |
|
53 |
+ 34, 37, 38, 40, 48, 58, 69, 83, |
|
54 |
+}; |
|
55 |
+ |
|
56 |
+static const uint8_t aic_y_scan[64] = { |
|
57 |
+ 0, 4, 1, 2, 5, 8, 12, 9, |
|
58 |
+ 6, 3, 7, 10, 13, 14, 11, 15, |
|
59 |
+ 47, 43, 46, 45, 42, 39, 35, 38, |
|
60 |
+ 41, 44, 40, 37, 34, 33, 36, 32, |
|
61 |
+ 16, 20, 17, 18, 21, 24, 28, 25, |
|
62 |
+ 22, 19, 23, 26, 29, 30, 27, 31, |
|
63 |
+ 63, 59, 62, 61, 58, 55, 51, 54, |
|
64 |
+ 57, 60, 56, 53, 50, 49, 52, 48, |
|
65 |
+}; |
|
66 |
+ |
|
67 |
+static const uint8_t aic_y_ext_scan[192] = { |
|
68 |
+ 64, 72, 65, 66, 73, 80, 88, 81, |
|
69 |
+ 74, 67, 75, 82, 89, 90, 83, 91, |
|
70 |
+ 0, 4, 1, 2, 5, 8, 12, 9, |
|
71 |
+ 6, 3, 7, 10, 13, 14, 11, 15, |
|
72 |
+ 16, 20, 17, 18, 21, 24, 28, 25, |
|
73 |
+ 22, 19, 23, 26, 29, 30, 27, 31, |
|
74 |
+ 155, 147, 154, 153, 146, 139, 131, 138, |
|
75 |
+ 145, 152, 144, 137, 130, 129, 136, 128, |
|
76 |
+ 47, 43, 46, 45, 42, 39, 35, 38, |
|
77 |
+ 41, 44, 40, 37, 34, 33, 36, 32, |
|
78 |
+ 63, 59, 62, 61, 58, 55, 51, 54, |
|
79 |
+ 57, 60, 56, 53, 50, 49, 52, 48, |
|
80 |
+ 96, 104, 97, 98, 105, 112, 120, 113, |
|
81 |
+ 106, 99, 107, 114, 121, 122, 115, 123, |
|
82 |
+ 68, 76, 69, 70, 77, 84, 92, 85, |
|
83 |
+ 78, 71, 79, 86, 93, 94, 87, 95, |
|
84 |
+ 100, 108, 101, 102, 109, 116, 124, 117, |
|
85 |
+ 110, 103, 111, 118, 125, 126, 119, 127, |
|
86 |
+ 187, 179, 186, 185, 178, 171, 163, 170, |
|
87 |
+ 177, 184, 176, 169, 162, 161, 168, 160, |
|
88 |
+ 159, 151, 158, 157, 150, 143, 135, 142, |
|
89 |
+ 149, 156, 148, 141, 134, 133, 140, 132, |
|
90 |
+ 191, 183, 190, 189, 182, 175, 167, 174, |
|
91 |
+ 181, 188, 180, 173, 166, 165, 172, 164, |
|
92 |
+}; |
|
93 |
+ |
|
94 |
+static const uint8_t aic_c_scan[64] = { |
|
95 |
+ 0, 4, 1, 2, 5, 8, 12, 9, |
|
96 |
+ 6, 3, 7, 10, 13, 14, 11, 15, |
|
97 |
+ 31, 27, 30, 29, 26, 23, 19, 22, |
|
98 |
+ 25, 28, 24, 21, 18, 17, 20, 16, |
|
99 |
+ 32, 36, 33, 34, 37, 40, 44, 41, |
|
100 |
+ 38, 35, 39, 42, 45, 46, 43, 47, |
|
101 |
+ 63, 59, 62, 61, 58, 55, 51, 54, |
|
102 |
+ 57, 60, 56, 53, 50, 49, 52, 48, |
|
103 |
+}; |
|
104 |
+ |
|
105 |
+static const uint8_t aic_c_ext_scan[192] = { |
|
106 |
+ 16, 24, 17, 18, 25, 32, 40, 33, |
|
107 |
+ 26, 19, 27, 34, 41, 42, 35, 43, |
|
108 |
+ 0, 4, 1, 2, 5, 8, 12, 9, |
|
109 |
+ 6, 3, 7, 10, 13, 14, 11, 15, |
|
110 |
+ 20, 28, 21, 22, 29, 36, 44, 37, |
|
111 |
+ 30, 23, 31, 38, 45, 46, 39, 47, |
|
112 |
+ 95, 87, 94, 93, 86, 79, 71, 78, |
|
113 |
+ 85, 92, 84, 77, 70, 69, 76, 68, |
|
114 |
+ 63, 59, 62, 61, 58, 55, 51, 54, |
|
115 |
+ 57, 60, 56, 53, 50, 49, 52, 48, |
|
116 |
+ 91, 83, 90, 89, 82, 75, 67, 74, |
|
117 |
+ 81, 88, 80, 73, 66, 65, 72, 64, |
|
118 |
+ 112, 120, 113, 114, 121, 128, 136, 129, |
|
119 |
+ 122, 115, 123, 130, 137, 138, 131, 139, |
|
120 |
+ 96, 100, 97, 98, 101, 104, 108, 105, |
|
121 |
+ 102, 99, 103, 106, 109, 110, 107, 111, |
|
122 |
+ 116, 124, 117, 118, 125, 132, 140, 133, |
|
123 |
+ 126, 119, 127, 134, 141, 142, 135, 143, |
|
124 |
+ 191, 183, 190, 189, 182, 175, 167, 174, |
|
125 |
+ 181, 188, 180, 173, 166, 165, 172, 164, |
|
126 |
+ 159, 155, 158, 157, 154, 151, 147, 150, |
|
127 |
+ 153, 156, 152, 149, 146, 145, 148, 144, |
|
128 |
+ 187, 179, 186, 185, 178, 171, 163, 170, |
|
129 |
+ 177, 184, 176, 169, 162, 161, 168, 160, |
|
130 |
+}; |
|
131 |
+ |
|
132 |
+static const uint8_t *aic_scan[NUM_BANDS] = { |
|
133 |
+ aic_y_scan, aic_c_scan, aic_y_ext_scan, aic_c_ext_scan |
|
134 |
+}; |
|
135 |
+ |
|
136 |
+typedef struct AICContext { |
|
137 |
+ AVCodecContext *avctx; |
|
138 |
+ AVFrame *frame; |
|
139 |
+ DSPContext dsp; |
|
140 |
+ ScanTable scantable; |
|
141 |
+ |
|
142 |
+ int num_x_slices; |
|
143 |
+ int slice_width; |
|
144 |
+ int mb_width, mb_height; |
|
145 |
+ int quant; |
|
146 |
+ int interlaced; |
|
147 |
+ |
|
148 |
+ int16_t *slice_data; |
|
149 |
+ int16_t *data_ptr[NUM_BANDS]; |
|
150 |
+ |
|
151 |
+ DECLARE_ALIGNED(16, int16_t, block)[64]; |
|
152 |
+} AICContext; |
|
153 |
+ |
|
154 |
+static int aic_decode_header(AICContext *ctx, const uint8_t *src, int size) |
|
155 |
+{ |
|
156 |
+ uint32_t frame_size; |
|
157 |
+ int width, height; |
|
158 |
+ |
|
159 |
+ if (src[0] != 1) { |
|
160 |
+ av_log(ctx->avctx, AV_LOG_ERROR, "Invalid version %d\n", src[0]); |
|
161 |
+ return AVERROR_INVALIDDATA; |
|
162 |
+ } |
|
163 |
+ if (src[1] != AIC_HDR_SIZE - 2) { |
|
164 |
+ av_log(ctx->avctx, AV_LOG_ERROR, "Invalid header size %d\n", src[1]); |
|
165 |
+ return AVERROR_INVALIDDATA; |
|
166 |
+ } |
|
167 |
+ frame_size = AV_RB32(src + 2); |
|
168 |
+ width = AV_RB16(src + 6); |
|
169 |
+ height = AV_RB16(src + 8); |
|
170 |
+ if (frame_size > size) { |
|
171 |
+ av_log(ctx->avctx, AV_LOG_ERROR, "Frame size should be %d got %d\n", |
|
172 |
+ frame_size, size); |
|
173 |
+ return AVERROR_INVALIDDATA; |
|
174 |
+ } |
|
175 |
+ if (width != ctx->avctx->width || height != ctx->avctx->height) { |
|
176 |
+ av_log(ctx->avctx, AV_LOG_ERROR, |
|
177 |
+ "Picture dimension changed: old: %d x %d, new: %d x %d\n", |
|
178 |
+ ctx->avctx->width, ctx->avctx->height, width, height); |
|
179 |
+ return AVERROR_INVALIDDATA; |
|
180 |
+ } |
|
181 |
+ ctx->quant = src[15]; |
|
182 |
+ ctx->interlaced = ((src[16] >> 4) == 3); |
|
183 |
+ |
|
184 |
+ return 0; |
|
185 |
+} |
|
186 |
+ |
|
187 |
+#define GET_CODE(val, type, add_bits) \ |
|
188 |
+ do { \ |
|
189 |
+ if (type) \ |
|
190 |
+ val = get_ue_golomb(gb); \ |
|
191 |
+ else \ |
|
192 |
+ val = get_unary(gb, 1, 31); \ |
|
193 |
+ if (add_bits) \ |
|
194 |
+ val = (val << add_bits) + get_bits(gb, add_bits); \ |
|
195 |
+ } while (0) |
|
196 |
+ |
|
197 |
+static int aic_decode_coeffs(GetBitContext *gb, int16_t *dst, |
|
198 |
+ int band, int slice_width) |
|
199 |
+{ |
|
200 |
+ int has_skips, coeff_type, coeff_bits, skip_type, skip_bits; |
|
201 |
+ const int num_coeffs = aic_num_band_coeffs[band]; |
|
202 |
+ const uint8_t *scan = aic_scan[band]; |
|
203 |
+ int mb, idx, val; |
|
204 |
+ |
|
205 |
+ has_skips = get_bits1(gb); |
|
206 |
+ coeff_type = get_bits1(gb); |
|
207 |
+ coeff_bits = get_bits(gb, 3); |
|
208 |
+ |
|
209 |
+ if (has_skips) { |
|
210 |
+ skip_type = get_bits1(gb); |
|
211 |
+ skip_bits = get_bits(gb, 3); |
|
212 |
+ |
|
213 |
+ for (mb = 0; mb < slice_width; mb++) { |
|
214 |
+ idx = -1; |
|
215 |
+ do { |
|
216 |
+ GET_CODE(val, skip_type, skip_bits); |
|
217 |
+ idx += val + 1; |
|
218 |
+ if (idx >= num_coeffs) |
|
219 |
+ break; |
|
220 |
+ GET_CODE(val, coeff_type, coeff_bits); |
|
221 |
+ val++; |
|
222 |
+ if (val >= 0x10000) |
|
223 |
+ return AVERROR_INVALIDDATA; |
|
224 |
+ dst[scan[idx]] = val; |
|
225 |
+ } while (idx < num_coeffs - 1); |
|
226 |
+ dst += num_coeffs; |
|
227 |
+ } |
|
228 |
+ } else { |
|
229 |
+ for (mb = 0; mb < slice_width; mb++) { |
|
230 |
+ for (idx = 0; idx < num_coeffs; idx++) { |
|
231 |
+ GET_CODE(val, coeff_type, coeff_bits); |
|
232 |
+ if (val >= 0x10000) |
|
233 |
+ return AVERROR_INVALIDDATA; |
|
234 |
+ dst[scan[idx]] = val; |
|
235 |
+ } |
|
236 |
+ dst += num_coeffs; |
|
237 |
+ } |
|
238 |
+ } |
|
239 |
+ return 0; |
|
240 |
+} |
|
241 |
+ |
|
242 |
+static void recombine_block(int16_t *dst, const uint8_t *scan, |
|
243 |
+ int16_t **base, int16_t **ext) |
|
244 |
+{ |
|
245 |
+ int i, j; |
|
246 |
+ |
|
247 |
+ for (i = 0; i < 4; i++) { |
|
248 |
+ for (j = 0; j < 4; j++) |
|
249 |
+ dst[scan[i * 8 + j]] = (*base)[j]; |
|
250 |
+ for (j = 0; j < 4; j++) |
|
251 |
+ dst[scan[i * 8 + j + 4]] = (*ext)[j]; |
|
252 |
+ *base += 4; |
|
253 |
+ *ext += 4; |
|
254 |
+ } |
|
255 |
+ for (; i < 8; i++) { |
|
256 |
+ for (j = 0; j < 8; j++) |
|
257 |
+ dst[scan[i * 8 + j]] = (*ext)[j]; |
|
258 |
+ *ext += 8; |
|
259 |
+ } |
|
260 |
+} |
|
261 |
+ |
|
262 |
+static void recombine_block_il(int16_t *dst, const uint8_t *scan, |
|
263 |
+ int16_t **base, int16_t **ext, |
|
264 |
+ int block_no) |
|
265 |
+{ |
|
266 |
+ int i, j; |
|
267 |
+ |
|
268 |
+ if (block_no < 2) { |
|
269 |
+ for (i = 0; i < 8; i++) { |
|
270 |
+ for (j = 0; j < 4; j++) |
|
271 |
+ dst[scan[i * 8 + j]] = (*base)[j]; |
|
272 |
+ for (j = 0; j < 4; j++) |
|
273 |
+ dst[scan[i * 8 + j + 4]] = (*ext)[j]; |
|
274 |
+ *base += 4; |
|
275 |
+ *ext += 4; |
|
276 |
+ } |
|
277 |
+ } else { |
|
278 |
+ for (i = 0; i < 64; i++) |
|
279 |
+ dst[scan[i]] = (*ext)[i]; |
|
280 |
+ *ext += 64; |
|
281 |
+ } |
|
282 |
+} |
|
283 |
+ |
|
284 |
+static void unquant_block(int16_t *block, int q) |
|
285 |
+{ |
|
286 |
+ int i; |
|
287 |
+ |
|
288 |
+ for (i = 0; i < 64; i++) { |
|
289 |
+ int val = (uint16_t)block[i]; |
|
290 |
+ int sign = val & 1; |
|
291 |
+ |
|
292 |
+ block[i] = (((val >> 1) ^ -sign) * q * aic_quant_matrix[i] >> 4) |
|
293 |
+ + sign; |
|
294 |
+ } |
|
295 |
+} |
|
296 |
+ |
|
297 |
+static int aic_decode_slice(AICContext *ctx, int mb_x, int mb_y, |
|
298 |
+ const uint8_t *src, int src_size) |
|
299 |
+{ |
|
300 |
+ GetBitContext gb; |
|
301 |
+ int ret, i, mb, blk; |
|
302 |
+ int slice_width = FFMIN(ctx->slice_width, ctx->mb_width - mb_x); |
|
303 |
+ uint8_t *Y, *C[2]; |
|
304 |
+ uint8_t *dst; |
|
305 |
+ int16_t *base_y = ctx->data_ptr[COEFF_LUMA]; |
|
306 |
+ int16_t *base_c = ctx->data_ptr[COEFF_CHROMA]; |
|
307 |
+ int16_t *ext_y = ctx->data_ptr[COEFF_LUMA_EXT]; |
|
308 |
+ int16_t *ext_c = ctx->data_ptr[COEFF_CHROMA_EXT]; |
|
309 |
+ const int ystride = ctx->frame->linesize[0]; |
|
310 |
+ |
|
311 |
+ Y = ctx->frame->data[0] + mb_x * 16 + mb_y * 16 * ystride; |
|
312 |
+ for (i = 0; i < 2; i++) |
|
313 |
+ C[i] = ctx->frame->data[i + 1] + mb_x * 8 |
|
314 |
+ + mb_y * 8 * ctx->frame->linesize[i + 1]; |
|
315 |
+ init_get_bits(&gb, src, src_size * 8); |
|
316 |
+ |
|
317 |
+ memset(ctx->slice_data, 0, |
|
318 |
+ sizeof(*ctx->slice_data) * slice_width * AIC_BAND_COEFFS); |
|
319 |
+ for (i = 0; i < NUM_BANDS; i++) |
|
320 |
+ if ((ret = aic_decode_coeffs(&gb, ctx->data_ptr[i], |
|
321 |
+ i, slice_width)) < 0) |
|
322 |
+ return ret; |
|
323 |
+ |
|
324 |
+ for (mb = 0; mb < slice_width; mb++) { |
|
325 |
+ for (blk = 0; blk < 4; blk++) { |
|
326 |
+ if (!ctx->interlaced) |
|
327 |
+ recombine_block(ctx->block, ctx->scantable.permutated, |
|
328 |
+ &base_y, &ext_y); |
|
329 |
+ else |
|
330 |
+ recombine_block_il(ctx->block, ctx->scantable.permutated, |
|
331 |
+ &base_y, &ext_y, blk); |
|
332 |
+ unquant_block(ctx->block, ctx->quant); |
|
333 |
+ ctx->dsp.idct(ctx->block); |
|
334 |
+ |
|
335 |
+ if (!ctx->interlaced) { |
|
336 |
+ dst = Y + (blk & 1) * 8 * ystride + (blk >> 1) * 8; |
|
337 |
+ ctx->dsp.put_signed_pixels_clamped(ctx->block, dst, |
|
338 |
+ ystride); |
|
339 |
+ } else { |
|
340 |
+ dst = Y + (blk & 1) * 8 + (blk >> 1) * ystride; |
|
341 |
+ ctx->dsp.put_signed_pixels_clamped(ctx->block, dst, |
|
342 |
+ ystride * 2); |
|
343 |
+ } |
|
344 |
+ } |
|
345 |
+ Y += 16; |
|
346 |
+ |
|
347 |
+ for (blk = 0; blk < 2; blk++) { |
|
348 |
+ recombine_block(ctx->block, ctx->scantable.permutated, |
|
349 |
+ &base_c, &ext_c); |
|
350 |
+ unquant_block(ctx->block, ctx->quant); |
|
351 |
+ ctx->dsp.idct(ctx->block); |
|
352 |
+ ctx->dsp.put_signed_pixels_clamped(ctx->block, C[blk], |
|
353 |
+ ctx->frame->linesize[blk + 1]); |
|
354 |
+ C[blk] += 8; |
|
355 |
+ } |
|
356 |
+ } |
|
357 |
+ |
|
358 |
+ return 0; |
|
359 |
+} |
|
360 |
+ |
|
361 |
+static int aic_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, |
|
362 |
+ AVPacket *avpkt) |
|
363 |
+{ |
|
364 |
+ AICContext *ctx = avctx->priv_data; |
|
365 |
+ const uint8_t *buf = avpkt->data; |
|
366 |
+ int buf_size = avpkt->size; |
|
367 |
+ GetByteContext gb; |
|
368 |
+ uint32_t off; |
|
369 |
+ int x, y, ret; |
|
370 |
+ int slice_size; |
|
371 |
+ |
|
372 |
+ ctx->frame = data; |
|
373 |
+ ctx->frame->pict_type = AV_PICTURE_TYPE_I; |
|
374 |
+ ctx->frame->key_frame = 1; |
|
375 |
+ |
|
376 |
+ off = FFALIGN(AIC_HDR_SIZE + ctx->num_x_slices * ctx->mb_height * 2, 4); |
|
377 |
+ |
|
378 |
+ if (buf_size < off) { |
|
379 |
+ av_log(avctx, AV_LOG_ERROR, "Too small frame\n"); |
|
380 |
+ return AVERROR_INVALIDDATA; |
|
381 |
+ } |
|
382 |
+ |
|
383 |
+ if ((ret = aic_decode_header(ctx, buf, buf_size)) < 0) |
|
384 |
+ return ret; |
|
385 |
+ |
|
386 |
+ if ((ret = ff_get_buffer(avctx, ctx->frame, 0)) < 0) |
|
387 |
+ return ret; |
|
388 |
+ |
|
389 |
+ bytestream2_init(&gb, buf + AIC_HDR_SIZE, |
|
390 |
+ ctx->num_x_slices * ctx->mb_height * 2); |
|
391 |
+ |
|
392 |
+ for (y = 0; y < ctx->mb_height; y++) { |
|
393 |
+ for (x = 0; x < ctx->mb_width; x += ctx->slice_width) { |
|
394 |
+ slice_size = bytestream2_get_le16(&gb) * 4; |
|
395 |
+ if (slice_size + off > buf_size || !slice_size) { |
|
396 |
+ av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n"); |
|
397 |
+ return AVERROR_INVALIDDATA; |
|
398 |
+ } |
|
399 |
+ |
|
400 |
+ if ((ret = aic_decode_slice(ctx, x, y, |
|
401 |
+ buf + off, slice_size)) < 0) |
|
402 |
+ return ret; |
|
403 |
+ |
|
404 |
+ off += slice_size; |
|
405 |
+ } |
|
406 |
+ } |
|
407 |
+ |
|
408 |
+ *got_frame = 1; |
|
409 |
+ |
|
410 |
+ return avpkt->size; |
|
411 |
+} |
|
412 |
+ |
|
413 |
+static av_cold int aic_decode_init(AVCodecContext *avctx) |
|
414 |
+{ |
|
415 |
+ AICContext *ctx = avctx->priv_data; |
|
416 |
+ int i; |
|
417 |
+ uint8_t scan[64]; |
|
418 |
+ |
|
419 |
+ ctx->avctx = avctx; |
|
420 |
+ |
|
421 |
+ avctx->pix_fmt = AV_PIX_FMT_YUV420P; |
|
422 |
+ |
|
423 |
+ ff_dsputil_init(&ctx->dsp, avctx); |
|
424 |
+ |
|
425 |
+ for (i = 0; i < 64; i++) |
|
426 |
+ scan[i] = i; |
|
427 |
+ ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, scan); |
|
428 |
+ |
|
429 |
+ ctx->mb_width = FFALIGN(avctx->width, 16) >> 4; |
|
430 |
+ ctx->mb_height = FFALIGN(avctx->height, 16) >> 4; |
|
431 |
+ |
|
432 |
+ ctx->num_x_slices = 16; |
|
433 |
+ ctx->slice_width = ctx->mb_width / 16; |
|
434 |
+ for (i = 1; i < 32; i++) { |
|
435 |
+ if (!(ctx->mb_width % i) && (ctx->mb_width / i < 32)) { |
|
436 |
+ ctx->slice_width = ctx->mb_width / i; |
|
437 |
+ ctx->num_x_slices = i; |
|
438 |
+ break; |
|
439 |
+ } |
|
440 |
+ } |
|
441 |
+ |
|
442 |
+ ctx->slice_data = av_malloc(ctx->slice_width * AIC_BAND_COEFFS |
|
443 |
+ * sizeof(*ctx->slice_data)); |
|
444 |
+ if (!ctx->slice_data) { |
|
445 |
+ av_log(avctx, AV_LOG_ERROR, "Error allocating slice buffer\n"); |
|
446 |
+ |
|
447 |
+ return AVERROR(ENOMEM); |
|
448 |
+ } |
|
449 |
+ |
|
450 |
+ for (i = 0; i < NUM_BANDS; i++) |
|
451 |
+ ctx->data_ptr[i] = ctx->slice_data + ctx->slice_width |
|
452 |
+ * aic_band_off[i]; |
|
453 |
+ |
|
454 |
+ return 0; |
|
455 |
+} |
|
456 |
+ |
|
457 |
+static av_cold int aic_decode_close(AVCodecContext *avctx) |
|
458 |
+{ |
|
459 |
+ AICContext *ctx = avctx->priv_data; |
|
460 |
+ |
|
461 |
+ av_freep(&ctx->slice_data); |
|
462 |
+ |
|
463 |
+ return 0; |
|
464 |
+} |
|
465 |
+ |
|
466 |
+AVCodec ff_aic_decoder = { |
|
467 |
+ .name = "aic", |
|
468 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
469 |
+ .id = AV_CODEC_ID_AIC, |
|
470 |
+ .priv_data_size = sizeof(AICContext), |
|
471 |
+ .init = aic_decode_init, |
|
472 |
+ .close = aic_decode_close, |
|
473 |
+ .decode = aic_decode_frame, |
|
474 |
+ .capabilities = CODEC_CAP_DR1, |
|
475 |
+ .long_name = NULL_IF_CONFIG_SMALL("Apple Intermediate Codec") |
|
476 |
+}; |
... | ... |
@@ -96,6 +96,7 @@ void avcodec_register_all(void) |
96 | 96 |
REGISTER_ENCODER(A64MULTI, a64multi); |
97 | 97 |
REGISTER_ENCODER(A64MULTI5, a64multi5); |
98 | 98 |
REGISTER_DECODER(AASC, aasc); |
99 |
+ REGISTER_DECODER(AIC, aic); |
|
99 | 100 |
REGISTER_DECODER(AMV, amv); |
100 | 101 |
REGISTER_DECODER(ANM, anm); |
101 | 102 |
REGISTER_DECODER(ANSI, ansi); |
... | ... |
@@ -1207,6 +1207,13 @@ static const AVCodecDescriptor codec_descriptors[] = { |
1207 | 1207 |
.long_name = NULL_IF_CONFIG_SMALL("MS Windows Media Video V9 Screen"), |
1208 | 1208 |
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, |
1209 | 1209 |
}, |
1210 |
+ { |
|
1211 |
+ .id = AV_CODEC_ID_AIC, |
|
1212 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
1213 |
+ .name = "aic", |
|
1214 |
+ .long_name = NULL_IF_CONFIG_SMALL("Apple Intermediate Codec"), |
|
1215 |
+ .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, |
|
1216 |
+ }, |
|
1210 | 1217 |
|
1211 | 1218 |
/* various PCM "codecs" */ |
1212 | 1219 |
{ |
... | ... |
@@ -222,6 +222,8 @@ const AVCodecTag ff_codec_movvideo_tags[] = { |
222 | 222 |
{ AV_CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'o') }, /* Apple ProRes 422 Proxy */ |
223 | 223 |
{ AV_CODEC_ID_PRORES, MKTAG('a', 'p', '4', 'h') }, /* Apple ProRes 4444 */ |
224 | 224 |
|
225 |
+ { AV_CODEC_ID_AIC, MKTAG('i', 'c', 'o', 'd') }, |
|
226 |
+ |
|
225 | 227 |
{ AV_CODEC_ID_NONE, 0 }, |
226 | 228 |
}; |
227 | 229 |
|