OLD | NEW |
1 /* | 1 /* |
2 * VC3/DNxHD decoder. | 2 * VC3/DNxHD decoder. |
3 * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier
at smartjog dot com> | 3 * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier
at smartjog dot com> |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 21 matching lines...) Expand all Loading... |
32 AVFrame picture; | 32 AVFrame picture; |
33 GetBitContext gb; | 33 GetBitContext gb; |
34 int cid; ///< compression id | 34 int cid; ///< compression id |
35 unsigned int width, height; | 35 unsigned int width, height; |
36 unsigned int mb_width, mb_height; | 36 unsigned int mb_width, mb_height; |
37 uint32_t mb_scan_index[68]; /* max for 1080p */ | 37 uint32_t mb_scan_index[68]; /* max for 1080p */ |
38 int cur_field; ///< current interlaced field | 38 int cur_field; ///< current interlaced field |
39 VLC ac_vlc, dc_vlc, run_vlc; | 39 VLC ac_vlc, dc_vlc, run_vlc; |
40 int last_dc[3]; | 40 int last_dc[3]; |
41 DSPContext dsp; | 41 DSPContext dsp; |
42 DECLARE_ALIGNED_16(DCTELEM, blocks)[8][64]; | 42 DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; |
43 ScanTable scantable; | 43 ScanTable scantable; |
44 const CIDEntry *cid_table; | 44 const CIDEntry *cid_table; |
45 } DNXHDContext; | 45 } DNXHDContext; |
46 | 46 |
47 #define DNXHD_VLC_BITS 9 | 47 #define DNXHD_VLC_BITS 9 |
48 #define DNXHD_DC_VLC_BITS 7 | 48 #define DNXHD_DC_VLC_BITS 7 |
49 | 49 |
50 static av_cold int dnxhd_decode_init(AVCodecContext *avctx) | 50 static av_cold int dnxhd_decode_init(AVCodecContext *avctx) |
51 { | 51 { |
52 DNXHDContext *ctx = avctx->priv_data; | 52 DNXHDContext *ctx = avctx->priv_data; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return -1; | 119 return -1; |
120 | 120 |
121 if (buf_size < ctx->cid_table->coding_unit_size) { | 121 if (buf_size < ctx->cid_table->coding_unit_size) { |
122 av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n"); | 122 av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n"); |
123 return -1; | 123 return -1; |
124 } | 124 } |
125 | 125 |
126 ctx->mb_width = ctx->width>>4; | 126 ctx->mb_width = ctx->width>>4; |
127 ctx->mb_height = buf[0x16d]; | 127 ctx->mb_height = buf[0x16d]; |
128 | 128 |
129 if (ctx->mb_height > 68) { | 129 dprintf(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_he
ight); |
130 av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big\n"); | 130 |
| 131 if ((ctx->height+15)>>4 == ctx->mb_height && ctx->picture.interlaced_frame) |
| 132 ctx->height <<= 1; |
| 133 |
| 134 if (ctx->mb_height > 68 || |
| 135 (ctx->mb_height<<ctx->picture.interlaced_frame) > (ctx->height+15)>>4) { |
| 136 av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_heig
ht); |
131 return -1; | 137 return -1; |
132 } | 138 } |
133 | 139 |
134 dprintf(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_he
ight); | |
135 for (i = 0; i < ctx->mb_height; i++) { | 140 for (i = 0; i < ctx->mb_height; i++) { |
136 ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2)); | 141 ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2)); |
137 dprintf(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]); | 142 dprintf(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]); |
138 if (buf_size < ctx->mb_scan_index[i] + 0x280) { | 143 if (buf_size < ctx->mb_scan_index[i] + 0x280) { |
139 av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n"); | 144 av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n"); |
140 return -1; | 145 return -1; |
141 } | 146 } |
142 } | 147 } |
143 | 148 |
144 return 0; | 149 return 0; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 DNXHDContext *ctx = avctx->priv_data; | 290 DNXHDContext *ctx = avctx->priv_data; |
286 AVFrame *picture = data; | 291 AVFrame *picture = data; |
287 int first_field = 1; | 292 int first_field = 1; |
288 | 293 |
289 dprintf(avctx, "frame size %d\n", buf_size); | 294 dprintf(avctx, "frame size %d\n", buf_size); |
290 | 295 |
291 decode_coding_unit: | 296 decode_coding_unit: |
292 if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0) | 297 if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0) |
293 return -1; | 298 return -1; |
294 | 299 |
| 300 if ((avctx->width || avctx->height) && |
| 301 (ctx->width != avctx->width || ctx->height != avctx->height)) { |
| 302 av_log(avctx, AV_LOG_WARNING, "frame size changed: %dx%d -> %dx%d\n", |
| 303 avctx->width, avctx->height, ctx->width, ctx->height); |
| 304 first_field = 1; |
| 305 } |
| 306 |
295 avctx->pix_fmt = PIX_FMT_YUV422P; | 307 avctx->pix_fmt = PIX_FMT_YUV422P; |
296 if (avcodec_check_dimensions(avctx, ctx->width, ctx->height)) | 308 if (avcodec_check_dimensions(avctx, ctx->width, ctx->height)) |
297 return -1; | 309 return -1; |
298 avcodec_set_dimensions(avctx, ctx->width, ctx->height); | 310 avcodec_set_dimensions(avctx, ctx->width, ctx->height); |
299 | 311 |
300 if (first_field) { | 312 if (first_field) { |
301 if (ctx->picture.data[0]) | 313 if (ctx->picture.data[0]) |
302 avctx->release_buffer(avctx, &ctx->picture); | 314 avctx->release_buffer(avctx, &ctx->picture); |
303 if (avctx->get_buffer(avctx, &ctx->picture) < 0) { | 315 if (avctx->get_buffer(avctx, &ctx->picture) < 0) { |
304 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | 316 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 CODEC_TYPE_VIDEO, | 349 CODEC_TYPE_VIDEO, |
338 CODEC_ID_DNXHD, | 350 CODEC_ID_DNXHD, |
339 sizeof(DNXHDContext), | 351 sizeof(DNXHDContext), |
340 dnxhd_decode_init, | 352 dnxhd_decode_init, |
341 NULL, | 353 NULL, |
342 dnxhd_decode_close, | 354 dnxhd_decode_close, |
343 dnxhd_decode_frame, | 355 dnxhd_decode_frame, |
344 CODEC_CAP_DR1, | 356 CODEC_CAP_DR1, |
345 .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"), | 357 .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"), |
346 }; | 358 }; |
OLD | NEW |