Signed-off-by: Elvis Presley <elvis@e.p>
Elvis Presley authored on 2011/09/15 12:50:44... | ... |
@@ -476,6 +476,8 @@ following image formats are supported: |
476 | 476 |
@tab fourcc: VP80, encoding supported through external library libvpx |
477 | 477 |
@item planar RGB @tab @tab X |
478 | 478 |
@tab fourcc: 8BPS |
479 |
+@item Prores @tab @tab X |
|
480 |
+ @tab fourcc: apch,apcn,apcs,apco |
|
479 | 481 |
@item Q-team QPEG @tab @tab X |
480 | 482 |
@tab fourccs: QPEG, Q1.0, Q1.1 |
481 | 483 |
@item QuickTime 8BPS video @tab @tab X |
... | ... |
@@ -307,6 +307,7 @@ OBJS-$(CONFIG_PNG_DECODER) += png.o pngdec.o |
307 | 307 |
OBJS-$(CONFIG_PNG_ENCODER) += png.o pngenc.o |
308 | 308 |
OBJS-$(CONFIG_PPM_DECODER) += pnmdec.o pnm.o |
309 | 309 |
OBJS-$(CONFIG_PPM_ENCODER) += pnmenc.o pnm.o |
310 |
+OBJS-$(CONFIG_PRORES_DECODER) += proresdec.o |
|
310 | 311 |
OBJS-$(CONFIG_PTX_DECODER) += ptx.o |
311 | 312 |
OBJS-$(CONFIG_QCELP_DECODER) += qcelpdec.o celp_math.o \ |
312 | 313 |
celp_filters.o acelp_vectors.o \ |
... | ... |
@@ -172,6 +172,7 @@ void avcodec_register_all(void) |
172 | 172 |
REGISTER_DECODER (PICTOR, pictor); |
173 | 173 |
REGISTER_ENCDEC (PNG, png); |
174 | 174 |
REGISTER_ENCDEC (PPM, ppm); |
175 |
+ REGISTER_DECODER (PRORES, prores); |
|
175 | 176 |
REGISTER_DECODER (PTX, ptx); |
176 | 177 |
REGISTER_DECODER (QDRAW, qdraw); |
177 | 178 |
REGISTER_DECODER (QPEG, qpeg); |
178 | 179 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,614 @@ |
0 |
+/* |
|
1 |
+ * This file is part of FFmpeg. |
|
2 |
+ * |
|
3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
4 |
+ * modify it under the terms of the GNU General Public |
|
5 |
+ * License as published by the Free Software Foundation; |
|
6 |
+ * version 2 of the License. |
|
7 |
+ * |
|
8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 |
+ * General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU General Public |
|
14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 |
+ */ |
|
17 |
+ |
|
18 |
+/** |
|
19 |
+ * @file libavcodec/proresdec.c |
|
20 |
+ * Known FOURCCs: 'apch' (HQ), 'apcn' (SD), 'apcs' (LT), 'acpo' (Proxy), 'ap4c' (4444) |
|
21 |
+ */ |
|
22 |
+ |
|
23 |
+//#define DEBUG |
|
24 |
+ |
|
25 |
+#define A32_BITSTREAM_READER |
|
26 |
+ |
|
27 |
+#include "avcodec.h" |
|
28 |
+#include "get_bits.h" |
|
29 |
+#include "dsputil.h" |
|
30 |
+#include "simple_idct.h" |
|
31 |
+ |
|
32 |
+typedef struct { |
|
33 |
+ const uint8_t *data; |
|
34 |
+ unsigned mb_x; |
|
35 |
+ unsigned mb_y; |
|
36 |
+ unsigned mb_count; |
|
37 |
+ unsigned data_size; |
|
38 |
+} SliceContext; |
|
39 |
+ |
|
40 |
+typedef struct { |
|
41 |
+ AVFrame frame; |
|
42 |
+ DSPContext dsp; |
|
43 |
+ int frame_type; ///< 0 = progressive, 1 = tff, 2 = bff |
|
44 |
+ uint8_t qmat_luma[64]; |
|
45 |
+ uint8_t qmat_chroma[64]; |
|
46 |
+ SliceContext *slices; |
|
47 |
+ int slice_count; ///< number of slices in the current picture |
|
48 |
+ unsigned mb_width; ///< width of the current picture in mb |
|
49 |
+ unsigned mb_height; ///< height of the current picture in mb |
|
50 |
+ uint8_t progressive_scan[64]; |
|
51 |
+ uint8_t interlaced_scan[64]; |
|
52 |
+ const uint8_t *scan; |
|
53 |
+ int first_field; |
|
54 |
+ void (*idct_put)(DCTELEM *, uint8_t *restrict, int); |
|
55 |
+} ProresContext; |
|
56 |
+ |
|
57 |
+static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[64]) |
|
58 |
+{ |
|
59 |
+ int i; |
|
60 |
+ for (i = 0; i < 64; i++) |
|
61 |
+ dst[i] = permutation[src[i]]; |
|
62 |
+} |
|
63 |
+ |
|
64 |
+static av_always_inline void put_pixels(const DCTELEM *block, uint8_t *restrict pixels, int stride) |
|
65 |
+{ |
|
66 |
+ int16_t *p = (int16_t*)pixels; |
|
67 |
+ int i, j; |
|
68 |
+ |
|
69 |
+ stride >>= 1; |
|
70 |
+ for(i = 0; i < 8; i++) { |
|
71 |
+ for (j = 0; j < 8; j++) { |
|
72 |
+ p[j] = av_clip(block[j], 4, 1019); |
|
73 |
+ } |
|
74 |
+ p += stride; |
|
75 |
+ block += 8; |
|
76 |
+ } |
|
77 |
+} |
|
78 |
+ |
|
79 |
+static void idct_put(DCTELEM *block, uint8_t *restrict pixels, int stride) |
|
80 |
+{ |
|
81 |
+ ff_simple_idct_10(block); |
|
82 |
+ put_pixels(block, pixels, stride); |
|
83 |
+} |
|
84 |
+ |
|
85 |
+static const uint8_t progressive_scan[64] = { |
|
86 |
+ 0, 1, 8, 9, 2, 3, 10, 11, |
|
87 |
+ 16, 17, 24, 25, 18, 19, 26, 27, |
|
88 |
+ 4, 5, 12, 20, 13, 6, 7, 14, |
|
89 |
+ 21, 28, 29, 22, 15, 23, 30, 31, |
|
90 |
+ 32, 33, 40, 48, 41, 34, 35, 42, |
|
91 |
+ 49, 56, 57, 50, 43, 36, 37, 44, |
|
92 |
+ 51, 58, 59, 52, 45, 38, 39, 46, |
|
93 |
+ 53, 60, 61, 54, 47, 55, 62, 63 |
|
94 |
+}; |
|
95 |
+ |
|
96 |
+static const uint8_t interlaced_scan[64] = { |
|
97 |
+ 0, 8, 1, 9, 16, 24, 17, 25, |
|
98 |
+ 2, 10, 3, 11, 18, 26, 19, 27, |
|
99 |
+ 32, 40, 33, 34, 41, 48, 56, 49, |
|
100 |
+ 42, 35, 43, 50, 57, 58, 51, 59, |
|
101 |
+ 4, 12, 5, 6, 13, 20, 28, 21, |
|
102 |
+ 14, 7, 15, 22, 29, 36, 44, 37, |
|
103 |
+ 30, 23, 31, 38, 45, 52, 60, 53, |
|
104 |
+ 46, 39, 47, 54, 61, 62, 55, 63, |
|
105 |
+}; |
|
106 |
+ |
|
107 |
+static av_cold int decode_init(AVCodecContext *avctx) |
|
108 |
+{ |
|
109 |
+ ProresContext *ctx = avctx->priv_data; |
|
110 |
+ |
|
111 |
+ avctx->bits_per_raw_sample = 10; |
|
112 |
+ |
|
113 |
+ dsputil_init(&ctx->dsp, avctx); |
|
114 |
+ |
|
115 |
+ avctx->coded_frame = &ctx->frame; |
|
116 |
+ ctx->frame.type = FF_I_TYPE; |
|
117 |
+ ctx->frame.key_frame = 1; |
|
118 |
+ |
|
119 |
+ ctx->idct_put = idct_put; |
|
120 |
+ memcpy(ctx->progressive_scan, progressive_scan, sizeof(progressive_scan)); |
|
121 |
+ memcpy(ctx->interlaced_scan, interlaced_scan, sizeof(interlaced_scan)); |
|
122 |
+ |
|
123 |
+ return 0; |
|
124 |
+} |
|
125 |
+ |
|
126 |
+static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, |
|
127 |
+ const int data_size, AVCodecContext *avctx) |
|
128 |
+{ |
|
129 |
+ int hdr_size, width, height, flags; |
|
130 |
+ int version; |
|
131 |
+ const uint8_t *ptr; |
|
132 |
+ const uint8_t *scan; |
|
133 |
+ |
|
134 |
+ hdr_size = AV_RB16(buf); |
|
135 |
+ av_dlog(avctx, "header size %d\n", hdr_size); |
|
136 |
+ if (hdr_size > data_size) { |
|
137 |
+ av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n"); |
|
138 |
+ return -1; |
|
139 |
+ } |
|
140 |
+ |
|
141 |
+ version = AV_RB16(buf + 2); |
|
142 |
+ av_dlog(avctx, "%.4s version %d\n", buf+4, version); |
|
143 |
+ if (version != 0) { |
|
144 |
+ av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version); |
|
145 |
+ return -1; |
|
146 |
+ } |
|
147 |
+ |
|
148 |
+ width = AV_RB16(buf + 8); |
|
149 |
+ height = AV_RB16(buf + 10); |
|
150 |
+ if (width != avctx->width || height != avctx->height) { |
|
151 |
+ av_log(avctx, AV_LOG_ERROR, "picture resolution change: %dx%d -> %dx%d\n", |
|
152 |
+ avctx->width, avctx->height, width, height); |
|
153 |
+ return -1; |
|
154 |
+ } |
|
155 |
+ |
|
156 |
+ ctx->frame_type = (buf[12] >> 2) & 3; |
|
157 |
+ |
|
158 |
+ av_dlog(avctx, "frame type %d\n", ctx->frame_type); |
|
159 |
+ |
|
160 |
+ if (ctx->frame_type == 0) { |
|
161 |
+ scan = progressive_scan; |
|
162 |
+ ctx->scan = ctx->progressive_scan; // permuted |
|
163 |
+ } else { |
|
164 |
+ scan = interlaced_scan; |
|
165 |
+ ctx->scan = ctx->interlaced_scan; // permuted |
|
166 |
+ ctx->frame.interlaced_frame = 1; |
|
167 |
+ ctx->frame.top_field_first = ctx->frame_type == 1; |
|
168 |
+ } |
|
169 |
+ |
|
170 |
+ avctx->pix_fmt = PIX_FMT_YUV422P10; |
|
171 |
+ |
|
172 |
+ ptr = buf + 20; |
|
173 |
+ flags = buf[19]; |
|
174 |
+ av_dlog(avctx, "flags %x\n", flags); |
|
175 |
+ |
|
176 |
+ if (flags & 2) { |
|
177 |
+ permute(ctx->qmat_luma, scan, ptr); |
|
178 |
+ ptr += 64; |
|
179 |
+ } else { |
|
180 |
+ memset(ctx->qmat_luma, 4, 64); |
|
181 |
+ } |
|
182 |
+ |
|
183 |
+ if (flags & 1) { |
|
184 |
+ permute(ctx->qmat_chroma, scan, ptr); |
|
185 |
+ } else { |
|
186 |
+ memset(ctx->qmat_chroma, 4, 64); |
|
187 |
+ } |
|
188 |
+ |
|
189 |
+ return hdr_size; |
|
190 |
+} |
|
191 |
+ |
|
192 |
+static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size) |
|
193 |
+{ |
|
194 |
+ ProresContext *ctx = avctx->priv_data; |
|
195 |
+ int i, hdr_size, slice_count; |
|
196 |
+ unsigned pic_data_size; |
|
197 |
+ int log2_slice_mb_width, log2_slice_mb_height; |
|
198 |
+ int slice_mb_count, mb_x, mb_y; |
|
199 |
+ const uint8_t *data_ptr, *index_ptr; |
|
200 |
+ |
|
201 |
+ hdr_size = buf[0] >> 3; |
|
202 |
+ if (hdr_size < 8 || hdr_size > buf_size) { |
|
203 |
+ av_log(avctx, AV_LOG_ERROR, "error, wrong picture header size\n"); |
|
204 |
+ return -1; |
|
205 |
+ } |
|
206 |
+ |
|
207 |
+ pic_data_size = AV_RB32(buf + 1); |
|
208 |
+ if (pic_data_size > buf_size) { |
|
209 |
+ av_log(avctx, AV_LOG_ERROR, "error, wrong picture data size\n"); |
|
210 |
+ return -1; |
|
211 |
+ } |
|
212 |
+ |
|
213 |
+ log2_slice_mb_width = buf[7] >> 4; |
|
214 |
+ log2_slice_mb_height = buf[7] & 0xF; |
|
215 |
+ if (log2_slice_mb_width > 3 || log2_slice_mb_height) { |
|
216 |
+ av_log(avctx, AV_LOG_ERROR, "unsupported slice resolution: %dx%d\n", |
|
217 |
+ 1 << log2_slice_mb_width, 1 << log2_slice_mb_height); |
|
218 |
+ return -1; |
|
219 |
+ } |
|
220 |
+ |
|
221 |
+ ctx->mb_width = (avctx->width + 15) >> 4; |
|
222 |
+ ctx->mb_height = (avctx->height + 15) >> 4; |
|
223 |
+ |
|
224 |
+ slice_count = AV_RB16(buf + 5); |
|
225 |
+ |
|
226 |
+ if (ctx->slice_count != slice_count || !ctx->slices) { |
|
227 |
+ av_freep(&ctx->slices); |
|
228 |
+ ctx->slices = av_mallocz(slice_count * sizeof(*ctx->slices)); |
|
229 |
+ if (!ctx->slices) |
|
230 |
+ return AVERROR(ENOMEM); |
|
231 |
+ ctx->slice_count = slice_count; |
|
232 |
+ } |
|
233 |
+ |
|
234 |
+ if (!slice_count) |
|
235 |
+ return AVERROR(EINVAL); |
|
236 |
+ |
|
237 |
+ if (hdr_size + slice_count*2 > buf_size) { |
|
238 |
+ av_log(avctx, AV_LOG_ERROR, "error, wrong slice count\n"); |
|
239 |
+ return -1; |
|
240 |
+ } |
|
241 |
+ |
|
242 |
+ // parse slice information |
|
243 |
+ index_ptr = buf + hdr_size; |
|
244 |
+ data_ptr = index_ptr + slice_count*2; |
|
245 |
+ |
|
246 |
+ slice_mb_count = 1 << log2_slice_mb_width; |
|
247 |
+ mb_x = 0; |
|
248 |
+ mb_y = 0; |
|
249 |
+ |
|
250 |
+ for (i = 0; i < slice_count; i++) { |
|
251 |
+ SliceContext *slice = &ctx->slices[i]; |
|
252 |
+ |
|
253 |
+ slice->data = data_ptr; |
|
254 |
+ data_ptr += AV_RB16(index_ptr + i*2); |
|
255 |
+ |
|
256 |
+ while (ctx->mb_width - mb_x < slice_mb_count) |
|
257 |
+ slice_mb_count >>= 1; |
|
258 |
+ |
|
259 |
+ slice->mb_x = mb_x; |
|
260 |
+ slice->mb_y = mb_y; |
|
261 |
+ slice->mb_count = slice_mb_count; |
|
262 |
+ slice->data_size = data_ptr - slice->data; |
|
263 |
+ |
|
264 |
+ if (slice->data_size < 6) { |
|
265 |
+ av_log(avctx, AV_LOG_ERROR, "error, wrong slice data size\n"); |
|
266 |
+ return -1; |
|
267 |
+ } |
|
268 |
+ |
|
269 |
+ mb_x += slice_mb_count; |
|
270 |
+ if (mb_x == ctx->mb_width) { |
|
271 |
+ slice_mb_count = 1 << log2_slice_mb_width; |
|
272 |
+ mb_x = 0; |
|
273 |
+ mb_y++; |
|
274 |
+ } |
|
275 |
+ if (data_ptr > buf + buf_size) { |
|
276 |
+ av_log(avctx, AV_LOG_ERROR, "error, slice out of bounds\n"); |
|
277 |
+ return -1; |
|
278 |
+ } |
|
279 |
+ } |
|
280 |
+ |
|
281 |
+ return pic_data_size; |
|
282 |
+} |
|
283 |
+ |
|
284 |
+#define DECODE_CODEWORD(val, codebook) \ |
|
285 |
+ do { \ |
|
286 |
+ unsigned int rice_order, exp_order, switch_bits; \ |
|
287 |
+ unsigned int q, buf, bits; \ |
|
288 |
+ \ |
|
289 |
+ UPDATE_CACHE(re, gb); \ |
|
290 |
+ buf = GET_CACHE(re, gb); \ |
|
291 |
+ \ |
|
292 |
+ /* number of bits to switch between rice and exp golomb */ \ |
|
293 |
+ switch_bits = codebook & 3; \ |
|
294 |
+ rice_order = codebook >> 5; \ |
|
295 |
+ exp_order = (codebook >> 2) & 7; \ |
|
296 |
+ \ |
|
297 |
+ q = 31-av_log2(buf); \ |
|
298 |
+ \ |
|
299 |
+ if (q > switch_bits) { /* exp golomb */ \ |
|
300 |
+ bits = exp_order - switch_bits + (q<<1); \ |
|
301 |
+ val = SHOW_UBITS(re, gb, bits) - (1 << exp_order) + \ |
|
302 |
+ ((switch_bits + 1) << rice_order); \ |
|
303 |
+ SKIP_BITS(re, gb, bits); \ |
|
304 |
+ } else if (rice_order) { \ |
|
305 |
+ SKIP_BITS(re, gb, q+1); \ |
|
306 |
+ val = (q << rice_order) + SHOW_UBITS(re, gb, rice_order); \ |
|
307 |
+ SKIP_BITS(re, gb, rice_order); \ |
|
308 |
+ } else { \ |
|
309 |
+ val = q; \ |
|
310 |
+ SKIP_BITS(re, gb, q+1); \ |
|
311 |
+ } \ |
|
312 |
+ } while (0); \ |
|
313 |
+ |
|
314 |
+#define TOSIGNED(x) (((x) >> 1) ^ (-((x) & 1))) |
|
315 |
+ |
|
316 |
+#define FIRST_DC_CB 0xB8 |
|
317 |
+ |
|
318 |
+static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}; |
|
319 |
+ |
|
320 |
+static av_always_inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, |
|
321 |
+ int blocks_per_slice, const int *qmat) |
|
322 |
+{ |
|
323 |
+ DCTELEM prev_dc; |
|
324 |
+ int code, code2, i, sign; |
|
325 |
+ |
|
326 |
+ OPEN_READER(re, gb); |
|
327 |
+ |
|
328 |
+ DECODE_CODEWORD(code, FIRST_DC_CB); |
|
329 |
+ prev_dc = TOSIGNED(code); |
|
330 |
+ out[0] = 4096 + ((prev_dc * qmat[0]) >> 2); |
|
331 |
+ |
|
332 |
+ out += 64; // dc coeff for the next block |
|
333 |
+ |
|
334 |
+ code = 5; |
|
335 |
+ sign = 0; |
|
336 |
+ for (i = 1; i < blocks_per_slice; i++, out += 64) { |
|
337 |
+ DECODE_CODEWORD(code, dc_codebook[FFMIN(code, 6)]); |
|
338 |
+ if(code) sign ^= -(code & 1); |
|
339 |
+ else sign = 0; |
|
340 |
+ prev_dc += (((code + 1) >> 1) ^ sign) - sign; |
|
341 |
+ out[0] = 4096 + ((prev_dc * qmat[0]) >> 2); |
|
342 |
+ } |
|
343 |
+ CLOSE_READER(re, gb); |
|
344 |
+} |
|
345 |
+ |
|
346 |
+// adaptive codebook switching lut according to previous run/level values |
|
347 |
+static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C }; |
|
348 |
+static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C }; |
|
349 |
+ |
|
350 |
+static av_always_inline void decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb, |
|
351 |
+ DCTELEM *out, int blocks_per_slice, |
|
352 |
+ const int *qmat) |
|
353 |
+{ |
|
354 |
+ ProresContext *ctx = avctx->priv_data; |
|
355 |
+ int block_mask, sign; |
|
356 |
+ unsigned pos, run, level; |
|
357 |
+ int max_coeffs, i, bits_left; |
|
358 |
+ int log2_block_count = av_log2(blocks_per_slice); |
|
359 |
+ |
|
360 |
+ OPEN_READER(re, gb); |
|
361 |
+ |
|
362 |
+ run = 4; |
|
363 |
+ level = 2; |
|
364 |
+ |
|
365 |
+ max_coeffs = 64 << log2_block_count; |
|
366 |
+ block_mask = blocks_per_slice - 1; |
|
367 |
+ |
|
368 |
+ for (pos = block_mask;;) { |
|
369 |
+ bits_left = gb->size_in_bits - (((uint8_t*)re_buffer_ptr - gb->buffer)*8 - 32 + re_bit_count); |
|
370 |
+ if (!bits_left || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left))) |
|
371 |
+ break; |
|
372 |
+ |
|
373 |
+ DECODE_CODEWORD(run, run_to_cb[FFMIN(run, 15)]); |
|
374 |
+ pos += run + 1; |
|
375 |
+ if (pos >= max_coeffs) { |
|
376 |
+ av_log(avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", pos, max_coeffs); |
|
377 |
+ return; |
|
378 |
+ } |
|
379 |
+ |
|
380 |
+ DECODE_CODEWORD(level, lev_to_cb[FFMIN(level, 9)]); |
|
381 |
+ level += 1; |
|
382 |
+ |
|
383 |
+ i = pos >> log2_block_count; |
|
384 |
+ |
|
385 |
+ sign = SHOW_SBITS(re, gb, 1); |
|
386 |
+ SKIP_BITS(re, gb, 1); |
|
387 |
+ out[((pos & block_mask) << 6) + ctx->scan[i]] = (((level ^ sign) - sign) * qmat[i]) >> 2; |
|
388 |
+ } |
|
389 |
+ |
|
390 |
+ CLOSE_READER(re, gb); |
|
391 |
+} |
|
392 |
+ |
|
393 |
+static void decode_slice_luma(AVCodecContext *avctx, SliceContext *slice, |
|
394 |
+ uint8_t *dst, int dst_stride, |
|
395 |
+ const uint8_t *buf, unsigned buf_size, |
|
396 |
+ const int *qmat) |
|
397 |
+{ |
|
398 |
+ ProresContext *ctx = avctx->priv_data; |
|
399 |
+ DECLARE_ALIGNED(16, DCTELEM, blocks)[8*4*64], *block; |
|
400 |
+ GetBitContext gb; |
|
401 |
+ int i, blocks_per_slice = slice->mb_count<<2; |
|
402 |
+ |
|
403 |
+ for (i = 0; i < blocks_per_slice; i++) |
|
404 |
+ ctx->dsp.clear_block(blocks+(i<<6)); |
|
405 |
+ |
|
406 |
+ init_get_bits(&gb, buf, buf_size << 3); |
|
407 |
+ |
|
408 |
+ decode_dc_coeffs(&gb, blocks, blocks_per_slice, qmat); |
|
409 |
+ decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice, qmat); |
|
410 |
+ |
|
411 |
+ block = blocks; |
|
412 |
+ for (i = 0; i < slice->mb_count; i++) { |
|
413 |
+ ctx->idct_put(block+(0<<6), dst, dst_stride); |
|
414 |
+ ctx->idct_put(block+(1<<6), dst+16, dst_stride); |
|
415 |
+ ctx->idct_put(block+(2<<6), dst+8*dst_stride, dst_stride); |
|
416 |
+ ctx->idct_put(block+(3<<6), dst+8*dst_stride+16, dst_stride); |
|
417 |
+ block += 4*64; |
|
418 |
+ dst += 32; |
|
419 |
+ } |
|
420 |
+} |
|
421 |
+ |
|
422 |
+static void decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice, |
|
423 |
+ uint8_t *dst, int dst_stride, |
|
424 |
+ const uint8_t *buf, unsigned buf_size, |
|
425 |
+ const int *qmat) |
|
426 |
+{ |
|
427 |
+ ProresContext *ctx = avctx->priv_data; |
|
428 |
+ DECLARE_ALIGNED(16, DCTELEM, blocks)[8*4*64], *block; |
|
429 |
+ GetBitContext gb; |
|
430 |
+ int i, blocks_per_slice = slice->mb_count*2; |
|
431 |
+ |
|
432 |
+ for (i = 0; i < blocks_per_slice; i++) |
|
433 |
+ ctx->dsp.clear_block(blocks+(i<<6)); |
|
434 |
+ |
|
435 |
+ init_get_bits(&gb, buf, buf_size << 3); |
|
436 |
+ |
|
437 |
+ decode_dc_coeffs(&gb, blocks, blocks_per_slice, qmat); |
|
438 |
+ decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice, qmat); |
|
439 |
+ |
|
440 |
+ block = blocks; |
|
441 |
+ for (i = 0; i < slice->mb_count; i++) { |
|
442 |
+ ctx->idct_put(block+(0<<6), dst, dst_stride); |
|
443 |
+ ctx->idct_put(block+(1<<6), dst+8*dst_stride, dst_stride); |
|
444 |
+ block += 2*64; |
|
445 |
+ dst += 16; |
|
446 |
+ } |
|
447 |
+} |
|
448 |
+ |
|
449 |
+static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) |
|
450 |
+{ |
|
451 |
+ ProresContext *ctx = avctx->priv_data; |
|
452 |
+ SliceContext *slice = &ctx->slices[jobnr]; |
|
453 |
+ const uint8_t *buf = slice->data; |
|
454 |
+ AVFrame *pic = avctx->coded_frame; |
|
455 |
+ int i, hdr_size, qscale; |
|
456 |
+ int luma_stride, chroma_stride; |
|
457 |
+ int y_data_size, u_data_size, v_data_size; |
|
458 |
+ uint8_t *dest_y, *dest_u, *dest_v; |
|
459 |
+ int qmat_luma_scaled[64]; |
|
460 |
+ int qmat_chroma_scaled[64]; |
|
461 |
+ |
|
462 |
+ //av_log(avctx, AV_LOG_INFO, "slice %d mb width %d mb x %d y %d\n", |
|
463 |
+ // jobnr, slice->mb_count, slice->mb_x, slice->mb_y); |
|
464 |
+ |
|
465 |
+ // slice header |
|
466 |
+ hdr_size = buf[0] >> 3; |
|
467 |
+ qscale = av_clip(buf[1], 1, 224); |
|
468 |
+ qscale = qscale > 128 ? qscale - 96 << 2: qscale; |
|
469 |
+ y_data_size = AV_RB16(buf + 2); |
|
470 |
+ u_data_size = AV_RB16(buf + 4); |
|
471 |
+ v_data_size = slice->data_size - y_data_size - u_data_size - hdr_size; |
|
472 |
+ |
|
473 |
+ if (y_data_size < 0 || u_data_size < 0 || v_data_size < 0) { |
|
474 |
+ av_log(avctx, AV_LOG_ERROR, "invalid plane data size\n"); |
|
475 |
+ return -1; |
|
476 |
+ } |
|
477 |
+ |
|
478 |
+ buf += hdr_size; |
|
479 |
+ |
|
480 |
+ for (i = 0; i < 64; i++) { |
|
481 |
+ qmat_luma_scaled[i] = ctx->qmat_luma[i] * qscale; |
|
482 |
+ qmat_chroma_scaled[i] = ctx->qmat_chroma[i] * qscale; |
|
483 |
+ } |
|
484 |
+ |
|
485 |
+ if (ctx->frame_type == 0) { |
|
486 |
+ luma_stride = pic->linesize[0]; |
|
487 |
+ chroma_stride = pic->linesize[1]; |
|
488 |
+ } else { |
|
489 |
+ luma_stride = pic->linesize[0] << 1; |
|
490 |
+ chroma_stride = pic->linesize[1] << 1; |
|
491 |
+ } |
|
492 |
+ |
|
493 |
+ dest_y = pic->data[0] + (slice->mb_y << 4) * luma_stride + (slice->mb_x << 5); |
|
494 |
+ dest_u = pic->data[1] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << 4); |
|
495 |
+ dest_v = pic->data[2] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << 4); |
|
496 |
+ |
|
497 |
+ if (ctx->frame_type && ctx->first_field ^ ctx->frame.top_field_first) { |
|
498 |
+ dest_y += pic->linesize[0]; |
|
499 |
+ dest_u += pic->linesize[1]; |
|
500 |
+ dest_v += pic->linesize[2]; |
|
501 |
+ } |
|
502 |
+ |
|
503 |
+ decode_slice_luma(avctx, slice, dest_y, luma_stride, |
|
504 |
+ buf, y_data_size, qmat_luma_scaled); |
|
505 |
+ |
|
506 |
+ if (!(avctx->flags & CODEC_FLAG_GRAY)) { |
|
507 |
+ decode_slice_chroma(avctx, slice, dest_u, chroma_stride, |
|
508 |
+ buf + y_data_size, u_data_size, |
|
509 |
+ qmat_chroma_scaled); |
|
510 |
+ decode_slice_chroma(avctx, slice, dest_v, chroma_stride, |
|
511 |
+ buf + y_data_size + u_data_size, v_data_size, |
|
512 |
+ qmat_chroma_scaled); |
|
513 |
+ } |
|
514 |
+ |
|
515 |
+ return 0; |
|
516 |
+} |
|
517 |
+ |
|
518 |
+static int decode_picture(AVCodecContext *avctx) |
|
519 |
+{ |
|
520 |
+ ProresContext *ctx = avctx->priv_data; |
|
521 |
+ int i, threads_ret[ctx->slice_count]; |
|
522 |
+ |
|
523 |
+ avctx->execute2(avctx, decode_slice_thread, NULL, threads_ret, ctx->slice_count); |
|
524 |
+ |
|
525 |
+ for (i = 0; i < ctx->slice_count; i++) |
|
526 |
+ if (threads_ret[i] < 0) |
|
527 |
+ return threads_ret[i]; |
|
528 |
+ |
|
529 |
+ return 0; |
|
530 |
+} |
|
531 |
+ |
|
532 |
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, |
|
533 |
+ AVPacket *avpkt) |
|
534 |
+{ |
|
535 |
+ ProresContext *ctx = avctx->priv_data; |
|
536 |
+ AVFrame *frame = avctx->coded_frame; |
|
537 |
+ const uint8_t *buf = avpkt->data; |
|
538 |
+ int buf_size = avpkt->size; |
|
539 |
+ int frame_hdr_size, pic_size; |
|
540 |
+ |
|
541 |
+ if (buf_size < 28 || buf_size != AV_RB32(buf) || |
|
542 |
+ AV_RL32(buf + 4) != AV_RL32("icpf")) { |
|
543 |
+ av_log(avctx, AV_LOG_ERROR, "invalid frame header\n"); |
|
544 |
+ return -1; |
|
545 |
+ } |
|
546 |
+ |
|
547 |
+ ctx->first_field = 1; |
|
548 |
+ |
|
549 |
+ buf += 8; |
|
550 |
+ buf_size -= 8; |
|
551 |
+ |
|
552 |
+ frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx); |
|
553 |
+ if (frame_hdr_size < 0) |
|
554 |
+ return -1; |
|
555 |
+ |
|
556 |
+ buf += frame_hdr_size; |
|
557 |
+ buf_size -= frame_hdr_size; |
|
558 |
+ |
|
559 |
+ decode_picture: |
|
560 |
+ pic_size = decode_picture_header(avctx, buf, buf_size); |
|
561 |
+ if (pic_size < 0) { |
|
562 |
+ av_log(avctx, AV_LOG_ERROR, "error decoding picture header\n"); |
|
563 |
+ return -1; |
|
564 |
+ } |
|
565 |
+ |
|
566 |
+ if (frame->data[0]) |
|
567 |
+ avctx->release_buffer(avctx, frame); |
|
568 |
+ |
|
569 |
+ if (avctx->get_buffer(avctx, frame) < 0) |
|
570 |
+ return -1; |
|
571 |
+ |
|
572 |
+ if (decode_picture(avctx)) { |
|
573 |
+ av_log(avctx, AV_LOG_ERROR, "error decoding picture\n"); |
|
574 |
+ return -1; |
|
575 |
+ } |
|
576 |
+ |
|
577 |
+ buf += pic_size; |
|
578 |
+ buf_size -= pic_size; |
|
579 |
+ |
|
580 |
+ if (ctx->frame_type && buf_size > 0 && ctx->first_field) { |
|
581 |
+ ctx->first_field = 0; |
|
582 |
+ goto decode_picture; |
|
583 |
+ } |
|
584 |
+ |
|
585 |
+ *data_size = sizeof(AVFrame); |
|
586 |
+ *(AVFrame*)data = *frame; |
|
587 |
+ |
|
588 |
+ return avpkt->size; |
|
589 |
+} |
|
590 |
+ |
|
591 |
+static av_cold int decode_close(AVCodecContext *avctx) |
|
592 |
+{ |
|
593 |
+ ProresContext *ctx = avctx->priv_data; |
|
594 |
+ |
|
595 |
+ AVFrame *frame = avctx->coded_frame; |
|
596 |
+ if (frame->data[0]) |
|
597 |
+ avctx->release_buffer(avctx, frame); |
|
598 |
+ av_freep(&ctx->slices); |
|
599 |
+ |
|
600 |
+ return 0; |
|
601 |
+} |
|
602 |
+ |
|
603 |
+AVCodec ff_prores_decoder = { |
|
604 |
+ .name = "prores", |
|
605 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
606 |
+ .id = CODEC_ID_PRORES, |
|
607 |
+ .priv_data_size = sizeof(ProresContext), |
|
608 |
+ .init = decode_init, |
|
609 |
+ .close = decode_close, |
|
610 |
+ .decode = decode_frame, |
|
611 |
+ .long_name = NULL_IF_CONFIG_SMALL("ProRes"), |
|
612 |
+ .capabilities = CODEC_CAP_SLICE_THREADS, |
|
613 |
+}; |
... | ... |
@@ -149,7 +149,7 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int l |
149 | 149 |
case PIX_FMT_YUV444P10BE: |
150 | 150 |
w_align= 16; //FIXME check for non mpeg style codecs and use less alignment |
151 | 151 |
h_align= 16; |
152 |
- if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264) |
|
152 |
+ if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264 || s->codec_id == CODEC_ID_PRORES) |
|
153 | 153 |
h_align= 32; // interlaced is rounded up to 2 MBs |
154 | 154 |
break; |
155 | 155 |
case PIX_FMT_YUV411P: |
... | ... |
@@ -21,7 +21,7 @@ |
21 | 21 |
#define AVCODEC_VERSION_H |
22 | 22 |
|
23 | 23 |
#define LIBAVCODEC_VERSION_MAJOR 53 |
24 |
-#define LIBAVCODEC_VERSION_MINOR 14 |
|
24 |
+#define LIBAVCODEC_VERSION_MINOR 15 |
|
25 | 25 |
#define LIBAVCODEC_VERSION_MICRO 0 |
26 | 26 |
|
27 | 27 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |