1 /*
2 * VC3/DNxHD decoder.
3 * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
4 * Copyright (c) 2011 MirriAd Ltd
5 *
6 * 10 bit support added by MirriAd Ltd, Joseph Artsimovich <joseph@mirriad.com>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
34
39 int64_t
cid;
///< compression id
51 int bit_depth;
// 8, 10 or 0 if not initialized at all.
59
60 #define DNXHD_VLC_BITS 9
61 #define DNXHD_DC_VLC_BITS 7
62
69
71 {
73
76 return 0;
77 }
78
80 {
81 if (cid != ctx->
cid) {
83
87 }
91 }
93
97
107
111 }
112 return 0;
113 }
114
118 {
119 static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
120 static const uint8_t header_prefix444[] = { 0x00, 0x00, 0x02, 0x80, 0x02 };
122
123 if (buf_size < 0x280) {
125 buf_size);
127 }
128
129 if (memcmp(buf, header_prefix, 5) && memcmp(buf, header_prefix444, 5)) {
132 }
133 if (buf[5] & 2) { /* interlaced */
138 "interlaced %d, cur field %d\n", buf[5] & 3, ctx->
cur_field);
139 }
140
143
145
149 }
150 if (buf[0x21] == 0x58) { /* 10 bit */
152
153 if (buf[0x4] == 0x2) {
157 } else {
160 }
161 } else if (buf[0x21] == 0x38) { /* 8 bit */
163
166 } else {
168 buf[0x21]);
170 }
171
174
177
178 // make sure profile size constraints are respected
179 // DNx100 allows 1920->1440 and 1280->960 subsampling
185 }
186
191 }
192
195
198
201
205 "mb height too big: %d\n", ctx->
mb_height);
207 }
208
214 "invalid mb scan index (%d < %d).\n",
217 }
218 }
219
220 return 0;
221 }
222
225 int qscale,
226 int index_bits,
227 int level_bias,
228 int level_shift)
229 {
230 int i, j, index1, index2,
len,
flags;
231 int level, component, sign;
232 const int *scale;
238
240 if (n & 2) {
241 component = 1 + (n & 1);
244 } else {
245 component = 0;
248 }
249 } else {
250 component = (n >> 1) % 3;
251 if (component) {
254 } else {
257 }
258 }
259
262 if (len) {
265 sign = ~level >> 31;
266 level = (
NEG_USR32(sign ^ level, len) ^ sign) - sign;
268 }
269 block[0] = ctx->
last_dc[component];
270
271 i = 0;
272
276
277 while (index1 != eob_index) {
278 level = ac_level[index1];
279 flags = ac_flags[index1];
280
283
284 if (flags & 1) {
287 }
288
289 if (flags & 2) {
294 }
295
296 if (++i > 63) {
298 break;
299 }
300
302 level *= scale[i];
303 if (level_bias < 32 || weight_matrix[i] != level_bias)
304 level += level_bias;
305 level >>= level_shift;
306
307 block[j] = (level ^ sign) - sign;
308
312 }
313
315 }
316
319 {
321 }
322
325 {
327 }
328
331 {
333 }
334
337 {
339 int dct_linesize_luma = frame->
linesize[0];
340 int dct_linesize_chroma = frame->
linesize[1];
341 uint8_t *dest_y, *dest_u, *dest_v;
342 int dct_y_offset, dct_x_offset;
343 int qscale, i;
344
347
349 for (i = 0; i < 64; i++) {
352 }
354 }
355
356 for (i = 0; i < 8; i++) {
359 }
361 for (; i < 12; i++) {
364 }
365 }
366
368 dct_linesize_luma <<= 1;
369 dct_linesize_chroma <<= 1;
370 }
371
372 dest_y = frame->
data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 +
shift1));
373 dest_u = frame->
data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->
is_444));
374 dest_v = frame->
data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->
is_444));
375
380 }
381
382 dct_y_offset = dct_linesize_luma << 3;
383 dct_x_offset = 8 <<
shift1;
388 ctx->
idsp.
idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->
blocks[5]);
389
391 dct_y_offset = dct_linesize_chroma << 3;
396 }
397 } else {
401 ctx->
idsp.
idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->
blocks[7]);
402
404 dct_y_offset = dct_linesize_chroma << 3;
408 ctx->
idsp.
idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, ctx->
blocks[9]);
412 ctx->
idsp.
idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, ctx->
blocks[11]);
413 }
414 }
415
416 return 0;
417 }
418
421 {
428 for (x = 0; x < ctx->
mb_width; x++) {
429 //START_TIMER;
431 //STOP_TIMER("decode macroblock");
432 }
433 }
434 return 0;
435 }
436
439 {
441 int buf_size = avpkt->
size;
447
448 av_dlog(avctx,
"frame size %d\n", buf_size);
449
450 decode_coding_unit:
453
458 first_field = 1;
459 }
463 first_field = 1;
464 }
465
468 if (ret < 0)
470
471 if (first_field) {
476 }
477
479
483 first_field = 0;
484 goto decode_coding_unit;
485 }
486
487 *got_frame = 1;
489 }
490
492 {
494
498 return 0;
499 }
500
511 };