dd7d8d14195c4fe6a299071204d77056aa10584e
[libav.git] / libavcodec / dnxhdenc.c
1 /*
2 * VC3/DNxHD encoder
3 * Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
4 * Copyright (c) 2011 MirriAd Ltd
5 *
6 * VC-3 encoder funded by the British Broadcasting Corporation
7 * 10 bit support added by MirriAd Ltd, Joseph Artsimovich <joseph@mirriad.com>
8 *
9 * This file is part of Libav.
10 *
11 * Libav is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * Libav is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Libav; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #include "libavutil/attributes.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/timer.h"
30
31 #include "avcodec.h"
32 #include "blockdsp.h"
33 #include "fdctdsp.h"
34 #include "internal.h"
35 #include "mpegvideo.h"
36 #include "pixblockdsp.h"
37 #include "dnxhdenc.h"
38
39 // The largest value that will not lead to overflow for 10bit samples.
40 #define DNX10BIT_QMAT_SHIFT 18
41 #define RC_VARIANCE 1 // use variance or ssd for fast rc
42 #define LAMBDA_FRAC_BITS 10
43
44 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
45 static const AVOption options[] = {
46 { "nitris_compat", "encode with Avid Nitris compatibility",
47 offsetof(DNXHDEncContext, nitris_compat), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
48 { NULL }
49 };
50
51 static const AVClass class = {
52 "dnxhd",
53 av_default_item_name,
54 options,
55 LIBAVUTIL_VERSION_INT
56 };
57
58 static void dnxhd_8bit_get_pixels_8x4_sym(int16_t *restrict block,
59 const uint8_t *pixels,
60 ptrdiff_t line_size)
61 {
62 int i;
63 for (i = 0; i < 4; i++) {
64 block[0] = pixels[0];
65 block[1] = pixels[1];
66 block[2] = pixels[2];
67 block[3] = pixels[3];
68 block[4] = pixels[4];
69 block[5] = pixels[5];
70 block[6] = pixels[6];
71 block[7] = pixels[7];
72 pixels += line_size;
73 block += 8;
74 }
75 memcpy(block, block - 8, sizeof(*block) * 8);
76 memcpy(block + 8, block - 16, sizeof(*block) * 8);
77 memcpy(block + 16, block - 24, sizeof(*block) * 8);
78 memcpy(block + 24, block - 32, sizeof(*block) * 8);
79 }
80
81 static av_always_inline
82 void dnxhd_10bit_get_pixels_8x4_sym(int16_t *restrict block,
83 const uint8_t *pixels,
84 ptrdiff_t line_size)
85 {
86 int i;
87
88 block += 32;
89
90 for (i = 0; i < 4; i++) {
91 memcpy(block + i * 8, pixels + i * line_size, 8 * sizeof(*block));
92 memcpy(block - (i + 1) * 8, pixels + i * line_size, 8 * sizeof(*block));
93 }
94 }
95
96 static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block,
97 int n, int qscale, int *overflow)
98 {
99 const uint8_t *scantable= ctx->intra_scantable.scantable;
100 const int *qmat = ctx->q_intra_matrix[qscale];
101 int last_non_zero = 0;
102 int i;
103
104 ctx->fdsp.fdct(block);
105
106 // Divide by 4 with rounding, to compensate scaling of DCT coefficients
107 block[0] = (block[0] + 2) >> 2;
108
109 for (i = 1; i < 64; ++i) {
110 int j = scantable[i];
111 int sign = FF_SIGNBIT(block[j]);
112 int level = (block[j] ^ sign) - sign;
113 level = level * qmat[j] >> DNX10BIT_QMAT_SHIFT;
114 block[j] = (level ^ sign) - sign;
115 if (level)
116 last_non_zero = i;
117 }
118
119 return last_non_zero;
120 }
121
122 static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx)
123 {
124 int i, j, level, run;
125 int max_level = 1 << (ctx->cid_table->bit_depth + 2);
126
127 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes,
128 max_level * 4 * sizeof(*ctx->vlc_codes), fail);
129 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits,
130 max_level * 4 * sizeof(*ctx->vlc_bits), fail);
131 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes,
132 63 * 2, fail);
133 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits,
134 63, fail);
135
136 ctx->vlc_codes += max_level * 2;
137 ctx->vlc_bits += max_level * 2;
138 for (level = -max_level; level < max_level; level++) {
139 for (run = 0; run < 2; run++) {
140 int index = (level << 1) | run;
141 int sign, offset = 0, alevel = level;
142
143 MASK_ABS(sign, alevel);
144 if (alevel > 64) {
145 offset = (alevel - 1) >> 6;
146 alevel -= offset << 6;
147 }
148 for (j = 0; j < 257; j++) {
149 if (ctx->cid_table->ac_level[j] == alevel &&
150 (!offset || (ctx->cid_table->ac_index_flag[j] && offset)) &&
151 (!run || (ctx->cid_table->ac_run_flag [j] && run))) {
152 assert(!ctx->vlc_codes[index]);
153 if (alevel) {
154 ctx->vlc_codes[index] =
155 (ctx->cid_table->ac_codes[j] << 1) | (sign & 1);
156 ctx->vlc_bits[index] = ctx->cid_table->ac_bits[j] + 1;
157 } else {
158 ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];
159 ctx->vlc_bits[index] = ctx->cid_table->ac_bits[j];
160 }
161 break;
162 }
163 }
164 assert(!alevel || j < 257);
165 if (offset) {
166 ctx->vlc_codes[index] =
167 (ctx->vlc_codes[index] << ctx->cid_table->index_bits) | offset;
168 ctx->vlc_bits[index] += ctx->cid_table->index_bits;
169 }
170 }
171 }
172 for (i = 0; i < 62; i++) {
173 int run = ctx->cid_table->run[i];
174 assert(run < 63);
175 ctx->run_codes[run] = ctx->cid_table->run_codes[i];
176 ctx->run_bits[run] = ctx->cid_table->run_bits[i];
177 }
178 return 0;
179 fail:
180 return AVERROR(ENOMEM);
181 }
182
183 static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
184 {
185 // init first elem to 1 to avoid div by 0 in convert_matrix
186 uint16_t weight_matrix[64] = { 1, }; // convert_matrix needs uint16_t*
187 int qscale, i;
188 const uint8_t *luma_weight_table = ctx->cid_table->luma_weight;
189 const uint8_t *chroma_weight_table = ctx->cid_table->chroma_weight;
190
191 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l,
192 (ctx->m.avctx->qmax + 1) * 64 * sizeof(int), fail);
193 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c,
194 (ctx->m.avctx->qmax + 1) * 64 * sizeof(int), fail);
195 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16,
196 (ctx->m.avctx->qmax + 1) * 64 * 2 * sizeof(uint16_t),
197 fail);
198 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16,
199 (ctx->m.avctx->qmax + 1) * 64 * 2 * sizeof(uint16_t),
200 fail);
201
202 if (ctx->cid_table->bit_depth == 8) {
203 for (i = 1; i < 64; i++) {
204 int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
205 weight_matrix[j] = ctx->cid_table->luma_weight[i];
206 }
207 ff_convert_matrix(&ctx->m, ctx->qmatrix_l, ctx->qmatrix_l16,
208 weight_matrix, ctx->m.intra_quant_bias, 1,
209 ctx->m.avctx->qmax, 1);
210 for (i = 1; i < 64; i++) {
211 int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
212 weight_matrix[j] = ctx->cid_table->chroma_weight[i];
213 }
214 ff_convert_matrix(&ctx->m, ctx->qmatrix_c, ctx->qmatrix_c16,
215 weight_matrix, ctx->m.intra_quant_bias, 1,
216 ctx->m.avctx->qmax, 1);
217
218 for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
219 for (i = 0; i < 64; i++) {
220 ctx->qmatrix_l[qscale][i] <<= 2;
221 ctx->qmatrix_c[qscale][i] <<= 2;
222 ctx->qmatrix_l16[qscale][0][i] <<= 2;
223 ctx->qmatrix_l16[qscale][1][i] <<= 2;
224 ctx->qmatrix_c16[qscale][0][i] <<= 2;
225 ctx->qmatrix_c16[qscale][1][i] <<= 2;
226 }
227 }
228 } else {
229 // 10-bit
230 for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
231 for (i = 1; i < 64; i++) {
232 int j = ctx->m.idsp.idct_permutation[ff_zigzag_direct[i]];
233
234 /* The quantization formula from the VC-3 standard is:
235 * quantized = sign(block[i]) * floor(abs(block[i]/s) * p /
236 * (qscale * weight_table[i]))
237 * Where p is 32 for 8-bit samples and 8 for 10-bit ones.
238 * The s factor compensates scaling of DCT coefficients done by
239 * the DCT routines, and therefore is not present in standard.
240 * It's 8 for 8-bit samples and 4 for 10-bit ones.
241 * We want values of ctx->qtmatrix_l and ctx->qtmatrix_r to be:
242 * ((1 << DNX10BIT_QMAT_SHIFT) * (p / s)) /
243 * (qscale * weight_table[i])
244 * For 10-bit samples, p / s == 2 */
245 ctx->qmatrix_l[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) /
246 (qscale * luma_weight_table[i]);
247 ctx->qmatrix_c[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) /
248 (qscale * chroma_weight_table[i]);
249 }
250 }
251 }
252
253 return 0;
254 fail:
255 return AVERROR(ENOMEM);
256 }
257
258 static av_cold int dnxhd_init_rc(DNXHDEncContext *ctx)
259 {
260 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_rc,
261 8160 * ctx->m.avctx->qmax * sizeof(RCEntry), fail);
262 if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD)
263 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_cmp,
264 ctx->m.mb_num * sizeof(RCCMPEntry), fail);
265
266 ctx->frame_bits = (ctx->cid_table->coding_unit_size -
267 640 - 4 - ctx->min_padding) * 8;
268 ctx->qscale = 1;
269 ctx->lambda = 2 << LAMBDA_FRAC_BITS; // qscale 2
270 return 0;
271 fail:
272 return AVERROR(ENOMEM);
273 }
274
275 static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
276 {
277 DNXHDEncContext *ctx = avctx->priv_data;
278 int i, index, bit_depth, ret;
279
280 switch (avctx->pix_fmt) {
281 case AV_PIX_FMT_YUV422P:
282 bit_depth = 8;
283 break;
284 case AV_PIX_FMT_YUV422P10:
285 bit_depth = 10;
286 break;
287 default:
288 av_log(avctx, AV_LOG_ERROR,
289 "pixel format is incompatible with DNxHD\n");
290 return AVERROR(EINVAL);
291 }
292
293 ctx->cid = ff_dnxhd_find_cid(avctx, bit_depth);
294 if (!ctx->cid) {
295 av_log(avctx, AV_LOG_ERROR,
296 "video parameters incompatible with DNxHD\n");
297 return AVERROR(EINVAL);
298 }
299 av_log(avctx, AV_LOG_DEBUG, "cid %d\n", ctx->cid);
300
301 index = ff_dnxhd_get_cid_table(ctx->cid);
302 if (index < 0)
303 return index;
304 ctx->cid_table = &ff_dnxhd_cid_table[index];
305
306 ctx->m.avctx = avctx;
307 ctx->m.mb_intra = 1;
308 ctx->m.h263_aic = 1;
309
310 avctx->bits_per_raw_sample = ctx->cid_table->bit_depth;
311
312 ff_blockdsp_init(&ctx->bdsp, avctx);
313 ff_fdctdsp_init(&ctx->m.fdsp, avctx);
314 ff_mpv_idct_init(&ctx->m);
315 ff_mpegvideoencdsp_init(&ctx->m.mpvencdsp, avctx);
316 ff_pixblockdsp_init(&ctx->m.pdsp, avctx);
317 if (!ctx->m.dct_quantize)
318 ctx->m.dct_quantize = ff_dct_quantize_c;
319
320 if (ctx->cid_table->bit_depth == 10) {
321 ctx->m.dct_quantize = dnxhd_10bit_dct_quantize;
322 ctx->get_pixels_8x4_sym = dnxhd_10bit_get_pixels_8x4_sym;
323 ctx->block_width_l2 = 4;
324 } else {
325 ctx->get_pixels_8x4_sym = dnxhd_8bit_get_pixels_8x4_sym;
326 ctx->block_width_l2 = 3;
327 }
328
329 if (ARCH_X86)
330 ff_dnxhdenc_init_x86(ctx);
331
332 ctx->m.mb_height = (avctx->height + 15) / 16;
333 ctx->m.mb_width = (avctx->width + 15) / 16;
334
335 if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
336 ctx->interlaced = 1;
337 ctx->m.mb_height /= 2;
338 }
339
340 ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width;
341
342 if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
343 ctx->m.intra_quant_bias = avctx->intra_quant_bias;
344 // XXX tune lbias/cbias
345 if ((ret = dnxhd_init_qmat(ctx, ctx->m.intra_quant_bias, 0)) < 0)
346 return ret;
347
348 /* Avid Nitris hardware decoder requires a minimum amount of padding
349 * in the coding unit payload */
350 if (ctx->nitris_compat)
351 ctx->min_padding = 1600;
352
353 if ((ret = dnxhd_init_vlc(ctx)) < 0)
354 return ret;
355 if ((ret = dnxhd_init_rc(ctx)) < 0)
356 return ret;
357
358 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size,
359 ctx->m.mb_height * sizeof(uint32_t), fail);
360 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_offs,
361 ctx->m.mb_height * sizeof(uint32_t), fail);
362 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits,
363 ctx->m.mb_num * sizeof(uint16_t), fail);
364 FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale,
365 ctx->m.mb_num * sizeof(uint8_t), fail);
366
367 avctx->coded_frame = av_frame_alloc();
368 if (!avctx->coded_frame)
369 return AVERROR(ENOMEM);
370
371 avctx->coded_frame->key_frame = 1;
372 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
373
374 if (avctx->thread_count > MAX_THREADS) {
375 av_log(avctx, AV_LOG_ERROR, "too many threads\n");
376 return AVERROR(EINVAL);
377 }
378
379 ctx->thread[0] = ctx;
380 for (i = 1; i < avctx->thread_count; i++) {
381 ctx->thread[i] = av_malloc(sizeof(DNXHDEncContext));
382 memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext));
383 }
384
385 return 0;
386 fail: // for FF_ALLOCZ_OR_GOTO
387 return AVERROR(ENOMEM);
388 }
389
390 static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf)
391 {
392 DNXHDEncContext *ctx = avctx->priv_data;
393 const uint8_t header_prefix[5] = { 0x00, 0x00, 0x02, 0x80, 0x01 };
394
395 memset(buf, 0, 640);
396
397 memcpy(buf, header_prefix, 5);
398 buf[5] = ctx->interlaced ? ctx->cur_field + 2 : 0x01;
399 buf[6] = 0x80; // crc flag off
400 buf[7] = 0xa0; // reserved
401 AV_WB16(buf + 0x18, avctx->height >> ctx->interlaced); // ALPF
402 AV_WB16(buf + 0x1a, avctx->width); // SPL
403 AV_WB16(buf + 0x1d, avctx->height >> ctx->interlaced); // NAL
404
405 buf[0x21] = ctx->cid_table->bit_depth == 10 ? 0x58 : 0x38;
406 buf[0x22] = 0x88 + (ctx->interlaced << 2);
407 AV_WB32(buf + 0x28, ctx->cid); // CID
408 buf[0x2c] = ctx->interlaced ? 0 : 0x80;
409
410 buf[0x5f] = 0x01; // UDL
411
412 buf[0x167] = 0x02; // reserved
413 AV_WB16(buf + 0x16a, ctx->m.mb_height * 4 + 4); // MSIPS
414 buf[0x16d] = ctx->m.mb_height; // Ns
415 buf[0x16f] = 0x10; // reserved
416
417 ctx->msip = buf + 0x170;
418 return 0;
419 }
420
421 static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
422 {
423 int nbits;
424 if (diff < 0) {
425 nbits = av_log2_16bit(-2 * diff);
426 diff--;
427 } else {
428 nbits = av_log2_16bit(2 * diff);
429 }
430 put_bits(&ctx->m.pb, ctx->cid_table->dc_bits[nbits] + nbits,
431 (ctx->cid_table->dc_codes[nbits] << nbits) +
432 (diff & ((1 << nbits) - 1)));
433 }
434
435 static av_always_inline
436 void dnxhd_encode_block(DNXHDEncContext *ctx, int16_t *block,
437 int last_index, int n)
438 {
439 int last_non_zero = 0;
440 int slevel, i, j;
441
442 dnxhd_encode_dc(ctx, block[0] - ctx->m.last_dc[n]);
443 ctx->m.last_dc[n] = block[0];
444
445 for (i = 1; i <= last_index; i++) {
446 j = ctx->m.intra_scantable.permutated[i];
447 slevel = block[j];
448 if (slevel) {
449 int run_level = i - last_non_zero - 1;
450 int rlevel = (slevel << 1) | !!run_level;
451 put_bits(&ctx->m.pb, ctx->vlc_bits[rlevel], ctx->vlc_codes[rlevel]);
452 if (run_level)
453 put_bits(&ctx->m.pb, ctx->run_bits[run_level],
454 ctx->run_codes[run_level]);
455 last_non_zero = i;
456 }
457 }
458 put_bits(&ctx->m.pb, ctx->vlc_bits[0], ctx->vlc_codes[0]); // EOB
459 }
460
461 static av_always_inline
462 void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *block, int n,
463 int qscale, int last_index)
464 {
465 const uint8_t *weight_matrix;
466 int level;
467 int i;
468
469 weight_matrix = (n & 2) ? ctx->cid_table->chroma_weight
470 : ctx->cid_table->luma_weight;
471
472 for (i = 1; i <= last_index; i++) {
473 int j = ctx->m.intra_scantable.permutated[i];
474 level = block[j];
475 if (level) {
476 if (level < 0) {
477 level = (1 - 2 * level) * qscale * weight_matrix[i];
478 if (ctx->cid_table->bit_depth == 10) {
479 if (weight_matrix[i] != 8)
480 level += 8;
481 level >>= 4;
482 } else {
483 if (weight_matrix[i] != 32)
484 level += 32;
485 level >>= 6;
486 }
487 level = -level;
488 } else {
489 level = (2 * level + 1) * qscale * weight_matrix[i];
490 if (ctx->cid_table->bit_depth == 10) {
491 if (weight_matrix[i] != 8)
492 level += 8;
493 level >>= 4;
494 } else {
495 if (weight_matrix[i] != 32)
496 level += 32;
497 level >>= 6;
498 }
499 }
500 block[j] = level;
501 }
502 }
503 }
504
505 static av_always_inline int dnxhd_ssd_block(int16_t *qblock, int16_t *block)
506 {
507 int score = 0;
508 int i;
509 for (i = 0; i < 64; i++)
510 score += (block[i] - qblock[i]) * (block[i] - qblock[i]);
511 return score;
512 }
513
514 static av_always_inline
515 int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, int16_t *block, int last_index)
516 {
517 int last_non_zero = 0;
518 int bits = 0;
519 int i, j, level;
520 for (i = 1; i <= last_index; i++) {
521 j = ctx->m.intra_scantable.permutated[i];
522 level = block[j];
523 if (level) {
524 int run_level = i - last_non_zero - 1;
525 bits += ctx->vlc_bits[(level << 1) |
526 !!run_level] + ctx->run_bits[run_level];
527 last_non_zero = i;
528 }
529 }
530 return bits;
531 }
532
533 static av_always_inline
534 void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y)
535 {
536 const int bs = ctx->block_width_l2;
537 const int bw = 1 << bs;
538 const uint8_t *ptr_y = ctx->thread[0]->src[0] +
539 ((mb_y << 4) * ctx->m.linesize) + (mb_x << bs + 1);
540 const uint8_t *ptr_u = ctx->thread[0]->src[1] +
541 ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs);
542 const uint8_t *ptr_v = ctx->thread[0]->src[2] +
543 ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs);
544 PixblockDSPContext *pdsp = &ctx->m.pdsp;
545
546 pdsp->get_pixels(ctx->blocks[0], ptr_y, ctx->m.linesize);
547 pdsp->get_pixels(ctx->blocks[1], ptr_y + bw, ctx->m.linesize);
548 pdsp->get_pixels(ctx->blocks[2], ptr_u, ctx->m.uvlinesize);
549 pdsp->get_pixels(ctx->blocks[3], ptr_v, ctx->m.uvlinesize);
550
551 if (mb_y + 1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) {
552 if (ctx->interlaced) {
553 ctx->get_pixels_8x4_sym(ctx->blocks[4],
554 ptr_y + ctx->dct_y_offset,
555 ctx->m.linesize);
556 ctx->get_pixels_8x4_sym(ctx->blocks[5],
557 ptr_y + ctx->dct_y_offset + bw,
558 ctx->m.linesize);
559 ctx->get_pixels_8x4_sym(ctx->blocks[6],
560 ptr_u + ctx->dct_uv_offset,
561 ctx->m.uvlinesize);
562 ctx->get_pixels_8x4_sym(ctx->blocks[7],
563 ptr_v + ctx->dct_uv_offset,
564 ctx->m.uvlinesize);
565 } else {
566 ctx->bdsp.clear_block(ctx->blocks[4]);
567 ctx->bdsp.clear_block(ctx->blocks[5]);
568 ctx->bdsp.clear_block(ctx->blocks[6]);
569 ctx->bdsp.clear_block(ctx->blocks[7]);
570 }
571 } else {
572 pdsp->get_pixels(ctx->blocks[4],
573 ptr_y + ctx->dct_y_offset, ctx->m.linesize);
574 pdsp->get_pixels(ctx->blocks[5],
575 ptr_y + ctx->dct_y_offset + bw, ctx->m.linesize);
576 pdsp->get_pixels(ctx->blocks[6],
577 ptr_u + ctx->dct_uv_offset, ctx->m.uvlinesize);
578 pdsp->get_pixels(ctx->blocks[7],
579 ptr_v + ctx->dct_uv_offset, ctx->m.uvlinesize);
580 }
581 }
582
583 static av_always_inline
584 int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i)
585 {
586 if (i & 2) {
587 ctx->m.q_intra_matrix16 = ctx->qmatrix_c16;
588 ctx->m.q_intra_matrix = ctx->qmatrix_c;
589 return 1 + (i & 1);
590 } else {
591 ctx->m.q_intra_matrix16 = ctx->qmatrix_l16;
592 ctx->m.q_intra_matrix = ctx->qmatrix_l;
593 return 0;
594 }
595 }
596
597 static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg,
598 int jobnr, int threadnr)
599 {
600 DNXHDEncContext *ctx = avctx->priv_data;
601 int mb_y = jobnr, mb_x;
602 int qscale = ctx->qscale;
603 LOCAL_ALIGNED_16(int16_t, block, [64]);
604 ctx = ctx->thread[threadnr];
605
606 ctx->m.last_dc[0] =
607 ctx->m.last_dc[1] =
608 ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2);
609
610 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
611 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
612 int ssd = 0;
613 int ac_bits = 0;
614 int dc_bits = 0;
615 int i;
616
617 dnxhd_get_blocks(ctx, mb_x, mb_y);
618
619 for (i = 0; i < 8; i++) {
620 int16_t *src_block = ctx->blocks[i];
621 int overflow, nbits, diff, last_index;
622 int n = dnxhd_switch_matrix(ctx, i);
623
624 memcpy(block, src_block, 64 * sizeof(*block));
625 last_index = ctx->m.dct_quantize(&ctx->m, block, i,
626 qscale, &overflow);
627 ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index);
628
629 diff = block[0] - ctx->m.last_dc[n];
630 if (diff < 0)
631 nbits = av_log2_16bit(-2 * diff);
632 else
633 nbits = av_log2_16bit(2 * diff);
634
635 assert(nbits < ctx->cid_table->bit_depth + 4);
636 dc_bits += ctx->cid_table->dc_bits[nbits] + nbits;
637
638 ctx->m.last_dc[n] = block[0];
639
640 if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) {
641 dnxhd_unquantize_c(ctx, block, i, qscale, last_index);
642 ctx->m.idsp.idct(block);
643 ssd += dnxhd_ssd_block(block, src_block);
644 }
645 }
646 ctx->mb_rc[qscale][mb].ssd = ssd;
647 ctx->mb_rc[qscale][mb].bits = ac_bits + dc_bits + 12 +
648 8 * ctx->vlc_bits[0];
649 }
650 return 0;
651 }
652
653 static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg,
654 int jobnr, int threadnr)
655 {
656 DNXHDEncContext *ctx = avctx->priv_data;
657 int mb_y = jobnr, mb_x;
658 ctx = ctx->thread[threadnr];
659 init_put_bits(&ctx->m.pb, (uint8_t *)arg + 640 + ctx->slice_offs[jobnr],
660 ctx->slice_size[jobnr]);
661
662 ctx->m.last_dc[0] =
663 ctx->m.last_dc[1] =
664 ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2);
665 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
666 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
667 int qscale = ctx->mb_qscale[mb];
668 int i;
669
670 put_bits(&ctx->m.pb, 12, qscale << 1);
671
672 dnxhd_get_blocks(ctx, mb_x, mb_y);
673
674 for (i = 0; i < 8; i++) {
675 int16_t *block = ctx->blocks[i];
676 int overflow, n = dnxhd_switch_matrix(ctx, i);
677 int last_index = ctx->m.dct_quantize(&ctx->m, block, i,
678 qscale, &overflow);
679 // START_TIMER;
680 dnxhd_encode_block(ctx, block, last_index, n);
681 // STOP_TIMER("encode_block");
682 }
683 }
684 if (put_bits_count(&ctx->m.pb) & 31)
685 put_bits(&ctx->m.pb, 32 - (put_bits_count(&ctx->m.pb) & 31), 0);
686 flush_put_bits(&ctx->m.pb);
687 return 0;
688 }
689
690 static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx)
691 {
692 int mb_y, mb_x;
693 int offset = 0;
694 for (mb_y = 0; mb_y < ctx->m.mb_height; mb_y++) {
695 int thread_size;
696 ctx->slice_offs[mb_y] = offset;
697 ctx->slice_size[mb_y] = 0;
698 for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
699 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
700 ctx->slice_size[mb_y] += ctx->mb_bits[mb];
701 }
702 ctx->slice_size[mb_y] = (ctx->slice_size[mb_y] + 31) & ~31;
703 ctx->slice_size[mb_y] >>= 3;
704 thread_size = ctx->slice_size[mb_y];
705 offset += thread_size;
706 }
707 }
708
709 static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg,
710 int jobnr, int threadnr)
711 {
712 DNXHDEncContext *ctx = avctx->priv_data;
713 int mb_y = jobnr, mb_x, x, y;
714 int partial_last_row = (mb_y == ctx->m.mb_height - 1) &&
715 ((avctx->height >> ctx->interlaced) & 0xF);
716
717 ctx = ctx->thread[threadnr];
718 if (ctx->cid_table->bit_depth == 8) {
719 uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize);
720 for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x, pix += 16) {
721 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
722 int sum;
723 int varc;
724
725 if (!partial_last_row && mb_x * 16 <= avctx->width - 16) {
726 sum = ctx->m.mpvencdsp.pix_sum(pix, ctx->m.linesize);
727 varc = ctx->m.mpvencdsp.pix_norm1(pix, ctx->m.linesize);
728 } else {
729 int bw = FFMIN(avctx->width - 16 * mb_x, 16);
730 int bh = FFMIN((avctx->height >> ctx->interlaced) - 16 * mb_y, 16);
731 sum = varc = 0;
732 for (y = 0; y < bh; y++) {
733 for (x = 0; x < bw; x++) {
734 uint8_t val = pix[x + y * ctx->m.linesize];
735 sum += val;
736 varc += val * val;
737 }
738 }
739 }
740 varc = (varc - (((unsigned) sum * sum) >> 8) + 128) >> 8;
741
742 ctx->mb_cmp[mb].value = varc;
743 ctx->mb_cmp[mb].mb = mb;
744 }
745 } else { // 10-bit
746 int const linesize = ctx->m.linesize >> 1;
747 for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x) {
748 uint16_t *pix = (uint16_t *)ctx->thread[0]->src[0] +
749 ((mb_y << 4) * linesize) + (mb_x << 4);
750 unsigned mb = mb_y * ctx->m.mb_width + mb_x;
751 int sum = 0;
752 int sqsum = 0;
753 int mean, sqmean;
754 int i, j;
755 // Macroblocks are 16x16 pixels, unlike DCT blocks which are 8x8.
756 for (i = 0; i < 16; ++i) {
757 for (j = 0; j < 16; ++j) {
758 // Turn 16-bit pixels into 10-bit ones.
759 int const sample = (unsigned) pix[j] >> 6;
760 sum += sample;
761 sqsum += sample * sample;
762 // 2^10 * 2^10 * 16 * 16 = 2^28, which is less than INT_MAX
763 }
764 pix += linesize;
765 }
766 mean = sum >> 8; // 16*16 == 2^8
767 sqmean = sqsum >> 8;
768 ctx->mb_cmp[mb].value = sqmean - mean * mean;
769 ctx->mb_cmp[mb].mb = mb;
770 }
771 }
772 return 0;
773 }
774
775 static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
776 {
777 int lambda, up_step, down_step;
778 int last_lower = INT_MAX, last_higher = 0;
779 int x, y, q;
780
781 for (q = 1; q < avctx->qmax; q++) {
782 ctx->qscale = q;
783 avctx->execute2(avctx, dnxhd_calc_bits_thread,
784 NULL, NULL, ctx->m.mb_height);
785 }
786 up_step = down_step = 2 << LAMBDA_FRAC_BITS;
787 lambda = ctx->lambda;
788
789 for (;;) {
790 int bits = 0;
791 int end = 0;
792 if (lambda == last_higher) {
793 lambda++;
794 end = 1; // need to set final qscales/bits
795 }
796 for (y = 0; y < ctx->m.mb_height; y++) {
797 for (x = 0; x < ctx->m.mb_width; x++) {
798 unsigned min = UINT_MAX;
799 int qscale = 1;
800 int mb = y * ctx->m.mb_width + x;
801 for (q = 1; q < avctx->qmax; q++) {
802 unsigned score = ctx->mb_rc[q][mb].bits * lambda +
803 ((unsigned) ctx->mb_rc[q][mb].ssd << LAMBDA_FRAC_BITS);
804 if (score < min) {
805 min = score;
806 qscale = q;
807 }
808 }
809 bits += ctx->mb_rc[qscale][mb].bits;
810 ctx->mb_qscale[mb] = qscale;
811 ctx->mb_bits[mb] = ctx->mb_rc[qscale][mb].bits;
812 }
813 bits = (bits + 31) & ~31; // padding
814 if (bits > ctx->frame_bits)
815 break;
816 }
817 // ff_dlog(ctx->m.avctx,
818 // "lambda %d, up %u, down %u, bits %d, frame %d\n",
819 // lambda, last_higher, last_lower, bits, ctx->frame_bits);
820 if (end) {
821 if (bits > ctx->frame_bits)
822 return AVERROR(EINVAL);
823 break;
824 }
825 if (bits < ctx->frame_bits) {
826 last_lower = FFMIN(lambda, last_lower);
827 if (last_higher != 0)
828 lambda = (lambda+last_higher)>>1;
829 else
830 lambda -= down_step;
831 down_step = FFMIN((int64_t)down_step*5, INT_MAX);
832 up_step = 1<<LAMBDA_FRAC_BITS;
833 lambda = FFMAX(1, lambda);
834 if (lambda == last_lower)
835 break;
836 } else {
837 last_higher = FFMAX(lambda, last_higher);
838 if (last_lower != INT_MAX)
839 lambda = (lambda+last_lower)>>1;
840 else if ((int64_t)lambda + up_step > INT_MAX)
841 return AVERROR(EINVAL);
842 else
843 lambda += up_step;
844 up_step = FFMIN((int64_t)up_step*5, INT_MAX);
845 down_step = 1<<LAMBDA_FRAC_BITS;
846 }
847 }
848 //ff_dlog(ctx->m.avctx, "out lambda %d\n", lambda);
849 ctx->lambda = lambda;
850 return 0;
851 }
852
853 static int dnxhd_find_qscale(DNXHDEncContext *ctx)
854 {
855 int bits = 0;
856 int up_step = 1;
857 int down_step = 1;
858 int last_higher = 0;
859 int last_lower = INT_MAX;
860 int qscale;
861 int x, y;
862
863 qscale = ctx->qscale;
864 for (;;) {
865 bits = 0;
866 ctx->qscale = qscale;
867 // XXX avoid recalculating bits
868 ctx->m.avctx->execute2(ctx->m.avctx, dnxhd_calc_bits_thread,
869 NULL, NULL, ctx->m.mb_height);
870 for (y = 0; y < ctx->m.mb_height; y++) {
871 for (x = 0; x < ctx->m.mb_width; x++)
872 bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits;
873 bits = (bits+31)&~31; // padding
874 if (bits > ctx->frame_bits)
875 break;
876 }
877 // ff_dlog(ctx->m.avctx,
878 // "%d, qscale %d, bits %d, frame %d, higher %d, lower %d\n",
879 // ctx->m.avctx->frame_number, qscale, bits, ctx->frame_bits,
880 // last_higher, last_lower);
881 if (bits < ctx->frame_bits) {
882 if (qscale == 1)
883 return 1;
884 if (last_higher == qscale - 1) {
885 qscale = last_higher;
886 break;
887 }
888 last_lower = FFMIN(qscale, last_lower);
889 if (last_higher != 0)
890 qscale = (qscale + last_higher) >> 1;
891 else
892 qscale -= down_step++;
893 if (qscale < 1)
894 qscale = 1;
895 up_step = 1;
896 } else {
897 if (last_lower == qscale + 1)
898 break;
899 last_higher = FFMAX(qscale, last_higher);
900 if (last_lower != INT_MAX)
901 qscale = (qscale + last_lower) >> 1;
902 else
903 qscale += up_step++;
904 down_step = 1;
905 if (qscale >= ctx->m.avctx->qmax)
906 return AVERROR(EINVAL);
907 }
908 }
909 //ff_dlog(ctx->m.avctx, "out qscale %d\n", qscale);
910 ctx->qscale = qscale;
911 return 0;
912 }
913
914 #define BUCKET_BITS 8
915 #define RADIX_PASSES 4
916 #define NBUCKETS (1 << BUCKET_BITS)
917
918 static inline int get_bucket(int value, int shift)
919 {
920 value >>= shift;
921 value &= NBUCKETS - 1;
922 return NBUCKETS - 1 - value;
923 }
924
925 static void radix_count(const RCCMPEntry *data, int size,
926 int buckets[RADIX_PASSES][NBUCKETS])
927 {
928 int i, j;
929 memset(buckets, 0, sizeof(buckets[0][0]) * RADIX_PASSES * NBUCKETS);
930 for (i = 0; i < size; i++) {
931 int v = data[i].value;
932 for (j = 0; j < RADIX_PASSES; j++) {
933 buckets[j][get_bucket(v, 0)]++;
934 v >>= BUCKET_BITS;
935 }
936 assert(!v);
937 }
938 for (j = 0; j < RADIX_PASSES; j++) {
939 int offset = size;
940 for (i = NBUCKETS - 1; i >= 0; i--)
941 buckets[j][i] = offset -= buckets[j][i];
942 assert(!buckets[j][0]);
943 }
944 }
945
946 static void radix_sort_pass(RCCMPEntry *dst, const RCCMPEntry *data,
947 int size, int buckets[NBUCKETS], int pass)
948 {
949 int shift = pass * BUCKET_BITS;
950 int i;
951 for (i = 0; i < size; i++) {
952 int v = get_bucket(data[i].value, shift);
953 int pos = buckets[v]++;
954 dst[pos] = data[i];
955 }
956 }
957
958 static void radix_sort(RCCMPEntry *data, int size)
959 {
960 int buckets[RADIX_PASSES][NBUCKETS];
961 RCCMPEntry *tmp = av_malloc(sizeof(*tmp) * size);
962 radix_count(data, size, buckets);
963 radix_sort_pass(tmp, data, size, buckets[0], 0);
964 radix_sort_pass(data, tmp, size, buckets[1], 1);
965 if (buckets[2][NBUCKETS - 1] || buckets[3][NBUCKETS - 1]) {
966 radix_sort_pass(tmp, data, size, buckets[2], 2);
967 radix_sort_pass(data, tmp, size, buckets[3], 3);
968 }
969 av_free(tmp);
970 }
971
972 static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx)
973 {
974 int max_bits = 0;
975 int ret, x, y;
976 if ((ret = dnxhd_find_qscale(ctx)) < 0)
977 return ret;
978 for (y = 0; y < ctx->m.mb_height; y++) {
979 for (x = 0; x < ctx->m.mb_width; x++) {
980 int mb = y * ctx->m.mb_width + x;
981 int delta_bits;
982 ctx->mb_qscale[mb] = ctx->qscale;
983 ctx->mb_bits[mb] = ctx->mb_rc[ctx->qscale][mb].bits;
984 max_bits += ctx->mb_rc[ctx->qscale][mb].bits;
985 if (!RC_VARIANCE) {
986 delta_bits = ctx->mb_rc[ctx->qscale][mb].bits -
987 ctx->mb_rc[ctx->qscale + 1][mb].bits;
988 ctx->mb_cmp[mb].mb = mb;
989 ctx->mb_cmp[mb].value =
990 delta_bits ? ((ctx->mb_rc[ctx->qscale][mb].ssd -
991 ctx->mb_rc[ctx->qscale + 1][mb].ssd) * 100) /
992 delta_bits
993 : INT_MIN; // avoid increasing qscale
994 }
995 }
996 max_bits += 31; // worst padding
997 }
998 if (!ret) {
999 if (RC_VARIANCE)
1000 avctx->execute2(avctx, dnxhd_mb_var_thread,
1001 NULL, NULL, ctx->m.mb_height);
1002 radix_sort(ctx->mb_cmp, ctx->m.mb_num);
1003 for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) {
1004 int mb = ctx->mb_cmp[x].mb;
1005 max_bits -= ctx->mb_rc[ctx->qscale][mb].bits -
1006 ctx->mb_rc[ctx->qscale + 1][mb].bits;
1007 ctx->mb_qscale[mb] = ctx->qscale + 1;
1008 ctx->mb_bits[mb] = ctx->mb_rc[ctx->qscale + 1][mb].bits;
1009 }
1010 }
1011 return 0;
1012 }
1013
1014 static void dnxhd_load_picture(DNXHDEncContext *ctx, const AVFrame *frame)
1015 {
1016 int i;
1017
1018 for (i = 0; i < ctx->m.avctx->thread_count; i++) {
1019 ctx->thread[i]->m.linesize = frame->linesize[0] << ctx->interlaced;
1020 ctx->thread[i]->m.uvlinesize = frame->linesize[1] << ctx->interlaced;
1021 ctx->thread[i]->dct_y_offset = ctx->m.linesize *8;
1022 ctx->thread[i]->dct_uv_offset = ctx->m.uvlinesize*8;
1023 }
1024
1025 ctx->m.avctx->coded_frame->interlaced_frame = frame->interlaced_frame;
1026 ctx->cur_field = frame->interlaced_frame && !frame->top_field_first;
1027 }
1028
1029 static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
1030 const AVFrame *frame, int *got_packet)
1031 {
1032 DNXHDEncContext *ctx = avctx->priv_data;
1033 int first_field = 1;
1034 int offset, i, ret;
1035 uint8_t *buf;
1036
1037 if ((ret = ff_alloc_packet(pkt, ctx->cid_table->frame_size)) < 0) {
1038 av_log(avctx, AV_LOG_ERROR,
1039 "output buffer is too small to compress picture\n");
1040 return ret;
1041 }
1042 buf = pkt->data;
1043
1044 dnxhd_load_picture(ctx, frame);
1045
1046 encode_coding_unit:
1047 for (i = 0; i < 3; i++) {
1048 ctx->src[i] = frame->data[i];
1049 if (ctx->interlaced && ctx->cur_field)
1050 ctx->src[i] += frame->linesize[i];
1051 }
1052
1053 dnxhd_write_header(avctx, buf);
1054
1055 if (avctx->mb_decision == FF_MB_DECISION_RD)
1056 ret = dnxhd_encode_rdo(avctx, ctx);
1057 else
1058 ret = dnxhd_encode_fast(avctx, ctx);
1059 if (ret < 0) {
1060 av_log(avctx, AV_LOG_ERROR,
1061 "picture could not fit ratecontrol constraints, increase qmax\n");
1062 return ret;
1063 }
1064
1065 dnxhd_setup_threads_slices(ctx);
1066
1067 offset = 0;
1068 for (i = 0; i < ctx->m.mb_height; i++) {
1069 AV_WB32(ctx->msip + i * 4, offset);
1070 offset += ctx->slice_size[i];
1071 assert(!(ctx->slice_size[i] & 3));
1072 }
1073
1074 avctx->execute2(avctx, dnxhd_encode_thread, buf, NULL, ctx->m.mb_height);
1075
1076 assert(640 + offset + 4 <= ctx->cid_table->coding_unit_size);
1077 memset(buf + 640 + offset, 0,
1078 ctx->cid_table->coding_unit_size - 4 - offset - 640);
1079
1080 AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF
1081
1082 if (ctx->interlaced && first_field) {
1083 first_field = 0;
1084 ctx->cur_field ^= 1;
1085 buf += ctx->cid_table->coding_unit_size;
1086 goto encode_coding_unit;
1087 }
1088
1089 avctx->coded_frame->quality = ctx->qscale * FF_QP2LAMBDA;
1090
1091 pkt->flags |= AV_PKT_FLAG_KEY;
1092 *got_packet = 1;
1093 return 0;
1094 }
1095
1096 static av_cold int dnxhd_encode_end(AVCodecContext *avctx)
1097 {
1098 DNXHDEncContext *ctx = avctx->priv_data;
1099 int max_level = 1 << (ctx->cid_table->bit_depth + 2);
1100 int i;
1101
1102 av_free(ctx->vlc_codes - max_level * 2);
1103 av_free(ctx->vlc_bits - max_level * 2);
1104 av_freep(&ctx->run_codes);
1105 av_freep(&ctx->run_bits);
1106
1107 av_freep(&ctx->mb_bits);
1108 av_freep(&ctx->mb_qscale);
1109 av_freep(&ctx->mb_rc);
1110 av_freep(&ctx->mb_cmp);
1111 av_freep(&ctx->slice_size);
1112 av_freep(&ctx->slice_offs);
1113
1114 av_freep(&ctx->qmatrix_c);
1115 av_freep(&ctx->qmatrix_l);
1116 av_freep(&ctx->qmatrix_c16);
1117 av_freep(&ctx->qmatrix_l16);
1118
1119 for (i = 1; i < avctx->thread_count; i++)
1120 av_freep(&ctx->thread[i]);
1121
1122 av_frame_free(&avctx->coded_frame);
1123
1124 return 0;
1125 }
1126
1127 AVCodec ff_dnxhd_encoder = {
1128 .name = "dnxhd",
1129 .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"),
1130 .type = AVMEDIA_TYPE_VIDEO,
1131 .id = AV_CODEC_ID_DNXHD,
1132 .priv_data_size = sizeof(DNXHDEncContext),
1133 .init = dnxhd_encode_init,
1134 .encode2 = dnxhd_encode_picture,
1135 .close = dnxhd_encode_end,
1136 .capabilities = CODEC_CAP_SLICE_THREADS,
1137 .pix_fmts = (const enum AVPixelFormat[]) {
1138 AV_PIX_FMT_YUV422P,
1139 AV_PIX_FMT_YUV422P10,
1140 AV_PIX_FMT_NONE
1141 },
1142 .priv_class = &class,
1143 };