History

dnxhd: Support DNx444

Kostya Shishkov committed 12 years ago

Commit e95018b1 parent 2f6eec63 files · +94 −22Browse files

Unified · Split

3 files
  1. Changelog +1 −0
  2. libavcodec/dnxhddata.c +18 −0
  3. libavcodec/dnxhddec.c +75 −22
Changelog+1−0
@@ -56,6 +56,7 @@ version 10: · 55 unmodified lines
5656 - ATRAC3+ decoder
5757 - framepack filter
5858 - Mirillis FIC video decoder
59+- Support DNx444
5960
6061
6162 version 9:
libavcodec/dnxhddata.c+18−0
@@ -220,6 +220,17 @@ static const uint8_t dnxhd_1252_chroma_weight[] = { · 219 unmodified lines
220220 114, 128, 125, 129, 134, 125, 116, 116,
221221 };
222222
223+static const uint8_t dnxhd_1256_chroma_weight[] = {
224+ 0, 32, 32, 32, 32, 32, 32, 33,
225+ 32, 32, 32, 32, 32, 32, 32, 34,
226+ 32, 32, 32, 32, 32, 32, 33, 37,
227+ 32, 32, 32, 32, 32, 32, 36, 39,
228+ 32, 32, 32, 32, 32, 34, 39, 44,
229+ 32, 37, 32, 32, 35, 40, 43, 49,
230+ 32, 33, 36, 36, 40, 43, 50, 60,
231+ 34, 37, 39, 44, 51, 56, 61, 70,
232+};
233+
223234 static const uint8_t dnxhd_1237_dc_codes[12] = {
224235 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63,
225236 };
@@ -1133,6 +1144,13 @@ const CIDEntry ff_dnxhd_cid_table[] = { · 907 unmodified lines
11331144 dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag,
11341145 dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run,
11351146 { 36, 45, 75, 90 } },
1147+ { 1256, 1920, 1080, 0, 1835008, 1835008, 6, 10,
1148+ dnxhd_1235_luma_weight, dnxhd_1256_chroma_weight,
1149+ dnxhd_1235_1241_dc_codes, dnxhd_1235_1241_dc_bits,
1150+ dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level,
1151+ dnxhd_1235_1241_ac_run_flag, dnxhd_1235_1241_ac_index_flag,
1152+ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run,
1153+ { 350, 390, 440, 730, 880 } },
11361154 };
11371155
11381156 int ff_dnxhd_get_cid_table(int cid)
libavcodec/dnxhddec.c+75−22
@@ -41,10 +41,11 @@ typedef struct DNXHDContext { · 40 unmodified lines
4141 VLC ac_vlc, dc_vlc, run_vlc;
4242 int last_dc[3];
4343 DSPContext dsp;
44− DECLARE_ALIGNED(16, int16_t, blocks)[8][64];
44+ DECLARE_ALIGNED(16, int16_t, blocks)[12][64];
4545 ScanTable scantable;
4646 const CIDEntry *cid_table;
4747 int bit_depth; // 8, 10 or 0 if not initialized at all.
48+ int is_444;
4849 void (*decode_dct_block)(struct DNXHDContext *ctx, int16_t *block,
4950 int n, int qscale);
5051 } DNXHDContext;
@@ -54,6 +55,7 @@ typedef struct DNXHDContext { · 3 unmodified lines
5455
5556 static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, int16_t *block, int n, int qscale);
5657 static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, int16_t *block, int n, int qscale);
58+static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block, int n, int qscale);
5759
5860 static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
5961 {
@@ -97,13 +99,14 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid) · 37 unmodified lines
9799 static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
98100 const uint8_t *buf, int buf_size, int first_field)
99101 {
100− static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
102+ static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
103+ static const uint8_t header_prefix444[] = { 0x00, 0x00, 0x02, 0x80, 0x02 };
101104 int i, cid, ret;
102105
103106 if (buf_size < 0x280)
104107 return AVERROR_INVALIDDATA;
105108
106− if (memcmp(buf, header_prefix, 5)) {
109+ if (memcmp(buf, header_prefix, 5) && memcmp(buf, header_prefix444, 5)) {
107110 av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n");
108111 return AVERROR_INVALIDDATA;
109112 }
@@ -119,7 +122,17 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, · 9 unmodified lines
119122
120123 av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height);
121124
122− if (buf[0x21] & 0x40) {
125+ ctx->is_444 = 0;
126+ if (buf[0x4] == 0x2) {
127+ ctx->avctx->pix_fmt = AV_PIX_FMT_YUV444P10;
128+ ctx->avctx->bits_per_raw_sample = 10;
129+ if (ctx->bit_depth != 10) {
130+ ff_dsputil_init(&ctx->dsp, ctx->avctx);
131+ ctx->bit_depth = 10;
132+ ctx->decode_dct_block = dnxhd_decode_dct_block_10_444;
133+ }
134+ ctx->is_444 = 1;
135+ } else if (buf[0x21] & 0x40) {
123136 ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
124137 ctx->avctx->bits_per_raw_sample = 10;
125138 if (ctx->bit_depth != 10) {
@@ -186,12 +199,21 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, · 60 unmodified lines
186199 const uint8_t *weight_matrix;
187200 OPEN_READER(bs, &ctx->gb);
188201
189− if (n&2) {
190− component = 1 + (n&1);
191− weight_matrix = ctx->cid_table->chroma_weight;
202+ if (!ctx->is_444) {
203+ if (n&2) {
204+ component = 1 + (n&1);
205+ weight_matrix = ctx->cid_table->chroma_weight;
206+ } else {
207+ component = 0;
208+ weight_matrix = ctx->cid_table->luma_weight;
209+ }
192210 } else {
193− component = 0;
194− weight_matrix = ctx->cid_table->luma_weight;
211+ component = (n >> 1) % 3;
212+ if (component) {
213+ weight_matrix = ctx->cid_table->chroma_weight;
214+ } else {
215+ weight_matrix = ctx->cid_table->luma_weight;
216+ }
195217 }
196218
197219 UPDATE_CACHE(bs, &ctx->gb);
@@ -257,6 +279,12 @@ static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, int16_t *block, · 59 unmodified lines
257279 dnxhd_decode_dct_block(ctx, block, n, qscale, 6, 8, 4);
258280 }
259281
282+static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block,
283+ int n, int qscale)
284+{
285+ dnxhd_decode_dct_block(ctx, block, n, qscale, 6, 32, 6);
286+}
287+
260288 static int dnxhd_decode_macroblock(DNXHDContext *ctx, AVFrame *frame, int x, int y)
261289 {
262290 int shift1 = ctx->bit_depth == 10;
@@ -273,6 +301,12 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, AVFrame *frame, int x, int · 10 unmodified lines
273301 ctx->dsp.clear_block(ctx->blocks[i]);
274302 ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale);
275303 }
304+ if (ctx->is_444) {
305+ for (; i < 12; i++) {
306+ ctx->dsp.clear_block(ctx->blocks[i]);
307+ ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale);
308+ }
309+ }
276310
277311 if (frame->interlaced_frame) {
278312 dct_linesize_luma <<= 1;
@@ -280,8 +314,8 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, AVFrame *frame, int x, int · 1 unmodified line
280314 }
281315
282316 dest_y = frame->data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 + shift1));
283− dest_u = frame->data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1));
284− dest_v = frame->data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1));
317+ dest_u = frame->data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->is_444));
318+ dest_v = frame->data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1 + ctx->is_444));
285319
286320 if (ctx->cur_field) {
287321 dest_y += frame->linesize[0];
@@ -291,17 +325,36 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, AVFrame *frame, int x, int · 3 unmodified lines
291325
292326 dct_y_offset = dct_linesize_luma << 3;
293327 dct_x_offset = 8 << shift1;
294− ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]);
295− ctx->dsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, ctx->blocks[1]);
296− ctx->dsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, ctx->blocks[4]);
297− ctx->dsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->blocks[5]);
298−
299− if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) {
300− dct_y_offset = dct_linesize_chroma << 3;
301− ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]);
302− ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]);
303− ctx->dsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, ctx->blocks[6]);
304− ctx->dsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, ctx->blocks[7]);
328+ if (!ctx->is_444) {
329+ ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]);
330+ ctx->dsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, ctx->blocks[1]);
331+ ctx->dsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, ctx->blocks[4]);
332+ ctx->dsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->blocks[5]);
333+
334+ if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) {
335+ dct_y_offset = dct_linesize_chroma << 3;
336+ ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]);
337+ ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]);
338+ ctx->dsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, ctx->blocks[6]);
339+ ctx->dsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, ctx->blocks[7]);
340+ }
341+ } else {
342+ ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]);
343+ ctx->dsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, ctx->blocks[1]);
344+ ctx->dsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, ctx->blocks[6]);
345+ ctx->dsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->blocks[7]);
346+
347+ if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) {
348+ dct_y_offset = dct_linesize_chroma << 3;
349+ ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]);
350+ ctx->dsp.idct_put(dest_u + dct_x_offset, dct_linesize_chroma, ctx->blocks[3]);
351+ ctx->dsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, ctx->blocks[8]);
352+ ctx->dsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_chroma, ctx->blocks[9]);
353+ ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[4]);
354+ ctx->dsp.idct_put(dest_v + dct_x_offset, dct_linesize_chroma, ctx->blocks[5]);
355+ ctx->dsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, ctx->blocks[10]);
356+ ctx->dsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, ctx->blocks[11]);
357+ }
305358 }
306359
307360 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t