3 * Copyright (c) 2009 Konstantin Shishkov
4 * Copyright (C) 2011 Peter Ross <pross@xvid.org>
6 * This file is part of Libav.
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/attributes.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/internal.h"
27 #define BITSTREAM_READER_LE
31 #include "bitstream.h"
38 #define BINK_FLAG_ALPHA 0x00100000
39 #define BINK_FLAG_GRAY 0x00020000
41 static VLC bink_trees
[16];
44 * IDs for different data types used in old version of Bink video codec
47 BINKB_SRC_BLOCK_TYPES
= 0, ///< 8x8 block types
48 BINKB_SRC_COLORS
, ///< pixel values used for different block types
49 BINKB_SRC_PATTERN
, ///< 8-bit values for 2-colour pattern fill
50 BINKB_SRC_X_OFF
, ///< X components of motion value
51 BINKB_SRC_Y_OFF
, ///< Y components of motion value
52 BINKB_SRC_INTRA_DC
, ///< DC values for intrablocks with DCT
53 BINKB_SRC_INTER_DC
, ///< DC values for interblocks with DCT
54 BINKB_SRC_INTRA_Q
, ///< quantizer values for intrablocks with DCT
55 BINKB_SRC_INTER_Q
, ///< quantizer values for interblocks with DCT
56 BINKB_SRC_INTER_COEFS
, ///< number of coefficients for residue blocks
61 static const int binkb_bundle_sizes
[BINKB_NB_SRC
] = {
62 4, 8, 8, 5, 5, 11, 11, 4, 4, 7
65 static const int binkb_bundle_signed
[BINKB_NB_SRC
] = {
66 0, 0, 0, 1, 1, 0, 1, 0, 0, 0
69 static int32_t binkb_intra_quant
[16][64];
70 static int32_t binkb_inter_quant
[16][64];
73 * IDs for different data types used in Bink video codec
76 BINK_SRC_BLOCK_TYPES
= 0, ///< 8x8 block types
77 BINK_SRC_SUB_BLOCK_TYPES
, ///< 16x16 block types (a subset of 8x8 block types)
78 BINK_SRC_COLORS
, ///< pixel values used for different block types
79 BINK_SRC_PATTERN
, ///< 8-bit values for 2-colour pattern fill
80 BINK_SRC_X_OFF
, ///< X components of motion value
81 BINK_SRC_Y_OFF
, ///< Y components of motion value
82 BINK_SRC_INTRA_DC
, ///< DC values for intrablocks with DCT
83 BINK_SRC_INTER_DC
, ///< DC values for interblocks with DCT
84 BINK_SRC_RUN
, ///< run lengths for special fill block
90 * data needed to decode 4-bit Huffman-coded value
93 int vlc_num
; ///< tree number (in bink_trees[])
94 uint8_t syms
[16]; ///< leaf value to symbol mapping
97 #define GET_HUFF(bc, tree) \
98 (tree).syms[bitstream_read_vlc(bc, bink_trees[(tree).vlc_num].table, \
99 bink_trees[(tree).vlc_num].bits, 1)]
102 * data structure used for decoding single Bink data type
104 typedef struct Bundle
{
105 int len
; ///< length of number of entries to decode (in bits)
106 Tree tree
; ///< Huffman tree-related data
107 uint8_t *data
; ///< buffer for decoded symbols
108 uint8_t *data_end
; ///< buffer end
109 uint8_t *cur_dec
; ///< pointer to the not yet decoded part of the buffer
110 uint8_t *cur_ptr
; ///< pointer to the data that is not read from buffer yet
116 typedef struct BinkContext
{
117 AVCodecContext
*avctx
;
118 BlockDSPContext bdsp
;
120 BinkDSPContext binkdsp
;
122 int version
; ///< internal Bink file version
126 Bundle bundle
[BINKB_NB_SRC
]; ///< bundles for decoding all data types
127 Tree col_high
[16]; ///< trees for decoding high nibble in "colours" data type
128 int col_lastval
; ///< value of last decoded high nibble in "colours" data type
132 * Bink video block types
135 SKIP_BLOCK
= 0, ///< skipped block
136 SCALED_BLOCK
, ///< block has size 16x16
137 MOTION_BLOCK
, ///< block is copied from previous frame with some offset
138 RUN_BLOCK
, ///< block is composed from runs of colours with custom scan order
139 RESIDUE_BLOCK
, ///< motion block with some difference added
140 INTRA_BLOCK
, ///< intra DCT block
141 FILL_BLOCK
, ///< block is filled with single colour
142 INTER_BLOCK
, ///< motion block with DCT applied to the difference
143 PATTERN_BLOCK
, ///< block is filled with two colours following custom pattern
144 RAW_BLOCK
, ///< uncoded 8x8 block
148 * Initialize length length in all bundles.
150 * @param c decoder context
151 * @param width plane width
152 * @param bw plane width in 8x8 blocks
154 static void init_lengths(BinkContext
*c
, int width
, int bw
)
156 width
= FFALIGN(width
, 8);
158 c
->bundle
[BINK_SRC_BLOCK_TYPES
].len
= av_log2((width
>> 3) + 511) + 1;
160 c
->bundle
[BINK_SRC_SUB_BLOCK_TYPES
].len
= av_log2((width
>> 4) + 511) + 1;
162 c
->bundle
[BINK_SRC_COLORS
].len
= av_log2(bw
*64 + 511) + 1;
164 c
->bundle
[BINK_SRC_INTRA_DC
].len
=
165 c
->bundle
[BINK_SRC_INTER_DC
].len
=
166 c
->bundle
[BINK_SRC_X_OFF
].len
=
167 c
->bundle
[BINK_SRC_Y_OFF
].len
= av_log2((width
>> 3) + 511) + 1;
169 c
->bundle
[BINK_SRC_PATTERN
].len
= av_log2((bw
<< 3) + 511) + 1;
171 c
->bundle
[BINK_SRC_RUN
].len
= av_log2(bw
*48 + 511) + 1;
175 * Allocate memory for bundles.
177 * @param c decoder context
179 static av_cold
void init_bundles(BinkContext
*c
)
184 bw
= (c
->avctx
->width
+ 7) >> 3;
185 bh
= (c
->avctx
->height
+ 7) >> 3;
188 for (i
= 0; i
< BINKB_NB_SRC
; i
++) {
189 c
->bundle
[i
].data
= av_malloc(blocks
* 64);
190 c
->bundle
[i
].data_end
= c
->bundle
[i
].data
+ blocks
* 64;
195 * Free memory used by bundles.
197 * @param c decoder context
199 static av_cold
void free_bundles(BinkContext
*c
)
202 for (i
= 0; i
< BINKB_NB_SRC
; i
++)
203 av_freep(&c
->bundle
[i
].data
);
207 * Merge two consequent lists of equal size depending on bits read.
209 * @param bc context for reading bits
210 * @param dst buffer where merged list will be written to
211 * @param src pointer to the head of the first list (the second lists starts at src+size)
212 * @param size input lists size
214 static void merge(BitstreamContext
*bc
, uint8_t *dst
, uint8_t *src
, int size
)
216 uint8_t *src2
= src
+ size
;
220 if (!bitstream_read_bit(bc
)) {
227 } while (size
&& size2
);
236 * Read information about Huffman tree used to decode data.
238 * @param bc context for reading bits
239 * @param tree pointer for storing tree data
241 static void read_tree(BitstreamContext
*bc
, Tree
*tree
)
243 uint8_t tmp1
[16] = { 0 }, tmp2
[16], *in
= tmp1
, *out
= tmp2
;
246 tree
->vlc_num
= bitstream_read(bc
, 4);
247 if (!tree
->vlc_num
) {
248 for (i
= 0; i
< 16; i
++)
252 if (bitstream_read_bit(bc
)) {
253 len
= bitstream_read(bc
, 3);
254 for (i
= 0; i
<= len
; i
++) {
255 tree
->syms
[i
] = bitstream_read(bc
, 4);
256 tmp1
[tree
->syms
[i
]] = 1;
258 for (i
= 0; i
< 16 && len
< 16 - 1; i
++)
260 tree
->syms
[++len
] = i
;
262 len
= bitstream_read(bc
, 2);
263 for (i
= 0; i
< 16; i
++)
265 for (i
= 0; i
<= len
; i
++) {
267 for (t
= 0; t
< 16; t
+= size
<< 1)
268 merge(bc
, out
+ t
, in
+ t
, size
);
269 FFSWAP(uint8_t*, in
, out
);
271 memcpy(tree
->syms
, in
, 16);
276 * Prepare bundle for decoding data.
278 * @param bc context for reading bits
279 * @param c decoder context
280 * @param bundle_num number of the bundle to initialize
282 static void read_bundle(BitstreamContext
*bc
, BinkContext
*c
, int bundle_num
)
286 if (bundle_num
== BINK_SRC_COLORS
) {
287 for (i
= 0; i
< 16; i
++)
288 read_tree(bc
, &c
->col_high
[i
]);
291 if (bundle_num
!= BINK_SRC_INTRA_DC
&& bundle_num
!= BINK_SRC_INTER_DC
)
292 read_tree(bc
, &c
->bundle
[bundle_num
].tree
);
293 c
->bundle
[bundle_num
].cur_dec
=
294 c
->bundle
[bundle_num
].cur_ptr
= c
->bundle
[bundle_num
].data
;
298 * common check before starting decoding bundle data
300 * @param bc context for reading bits
302 * @param t variable where number of elements to decode will be stored
304 #define CHECK_READ_VAL(bc, b, t) \
305 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
307 t = bitstream_read(bc, b->len); \
313 static int read_runs(AVCodecContext *avctx, BitstreamContext *bc, Bundle *b)
316 const uint8_t *dec_end
;
318 CHECK_READ_VAL(bc
, b
, t
);
319 dec_end
= b
->cur_dec
+ t
;
320 if (dec_end
> b
->data_end
) {
321 av_log(avctx
, AV_LOG_ERROR
, "Run value went out of bounds\n");
322 return AVERROR_INVALIDDATA
;
324 if (bitstream_read_bit(bc
)) {
325 v
= bitstream_read(bc
, 4);
326 memset(b
->cur_dec
, v
, t
);
329 while (b
->cur_dec
< dec_end
)
330 *b
->cur_dec
++ = GET_HUFF(bc
, b
->tree
);
335 static int read_motion_values(AVCodecContext
*avctx
, BitstreamContext
*bc
, Bundle
*b
)
338 const uint8_t *dec_end
;
340 CHECK_READ_VAL(bc
, b
, t
);
341 dec_end
= b
->cur_dec
+ t
;
342 if (dec_end
> b
->data_end
) {
343 av_log(avctx
, AV_LOG_ERROR
, "Too many motion values\n");
344 return AVERROR_INVALIDDATA
;
346 if (bitstream_read_bit(bc
)) {
347 v
= bitstream_read(bc
, 4);
349 v
= bitstream_apply_sign(bc
, v
);
351 memset(b
->cur_dec
, v
, t
);
354 while (b
->cur_dec
< dec_end
) {
355 v
= GET_HUFF(bc
, b
->tree
);
357 v
= bitstream_apply_sign(bc
, v
);
365 static const uint8_t bink_rlelens
[4] = { 4, 8, 12, 32 };
367 static int read_block_types(AVCodecContext
*avctx
, BitstreamContext
*bc
, Bundle
*b
)
371 const uint8_t *dec_end
;
373 CHECK_READ_VAL(bc
, b
, t
);
374 dec_end
= b
->cur_dec
+ t
;
375 if (dec_end
> b
->data_end
) {
376 av_log(avctx
, AV_LOG_ERROR
, "Too many block type values\n");
377 return AVERROR_INVALIDDATA
;
379 if (bitstream_read_bit(bc
)) {
380 v
= bitstream_read(bc
, 4);
381 memset(b
->cur_dec
, v
, t
);
384 while (b
->cur_dec
< dec_end
) {
385 v
= GET_HUFF(bc
, b
->tree
);
390 int run
= bink_rlelens
[v
- 12];
392 if (dec_end
- b
->cur_dec
< run
)
393 return AVERROR_INVALIDDATA
;
394 memset(b
->cur_dec
, last
, run
);
402 static int read_patterns(AVCodecContext
*avctx
, BitstreamContext
*bc
, Bundle
*b
)
405 const uint8_t *dec_end
;
407 CHECK_READ_VAL(bc
, b
, t
);
408 dec_end
= b
->cur_dec
+ t
;
409 if (dec_end
> b
->data_end
) {
410 av_log(avctx
, AV_LOG_ERROR
, "Too many pattern values\n");
411 return AVERROR_INVALIDDATA
;
413 while (b
->cur_dec
< dec_end
) {
414 v
= GET_HUFF(bc
, b
->tree
);
415 v
|= GET_HUFF(bc
, b
->tree
) << 4;
422 static int read_colors(BitstreamContext
*bc
, Bundle
*b
, BinkContext
*c
)
425 const uint8_t *dec_end
;
427 CHECK_READ_VAL(bc
, b
, t
);
428 dec_end
= b
->cur_dec
+ t
;
429 if (dec_end
> b
->data_end
) {
430 av_log(c
->avctx
, AV_LOG_ERROR
, "Too many color values\n");
431 return AVERROR_INVALIDDATA
;
433 if (bitstream_read_bit(bc
)) {
434 c
->col_lastval
= GET_HUFF(bc
, c
->col_high
[c
->col_lastval
]);
435 v
= GET_HUFF(bc
, b
->tree
);
436 v
= (c
->col_lastval
<< 4) | v
;
437 if (c
->version
< 'i') {
438 sign
= ((int8_t) v
) >> 7;
439 v
= ((v
& 0x7F) ^ sign
) - sign
;
442 memset(b
->cur_dec
, v
, t
);
445 while (b
->cur_dec
< dec_end
) {
446 c
->col_lastval
= GET_HUFF(bc
, c
->col_high
[c
->col_lastval
]);
447 v
= GET_HUFF(bc
, b
->tree
);
448 v
= (c
->col_lastval
<< 4) | v
;
449 if (c
->version
< 'i') {
450 sign
= ((int8_t) v
) >> 7;
451 v
= ((v
& 0x7F) ^ sign
) - sign
;
460 /** number of bits used to store first DC value in bundle */
461 #define DC_START_BITS 11
463 static int read_dcs(AVCodecContext
*avctx
, BitstreamContext
*bc
, Bundle
*b
,
464 int start_bits
, int has_sign
)
466 int i
, j
, len
, len2
, bsize
, v
, v2
;
467 int16_t *dst
= (int16_t*)b
->cur_dec
;
468 int16_t *dst_end
= (int16_t*)b
->data_end
;
470 CHECK_READ_VAL(bc
, b
, len
);
471 v
= bitstream_read(bc
, start_bits
- has_sign
);
473 v
= bitstream_apply_sign(bc
, v
);
475 if (dst_end
- dst
< 1)
476 return AVERROR_INVALIDDATA
;
479 for (i
= 0; i
< len
; i
+= 8) {
480 len2
= FFMIN(len
- i
, 8);
481 if (dst_end
- dst
< len2
)
482 return AVERROR_INVALIDDATA
;
483 bsize
= bitstream_read(bc
, 4);
485 for (j
= 0; j
< len2
; j
++) {
486 v2
= bitstream_read(bc
, bsize
);
488 v2
= bitstream_apply_sign(bc
, v2
);
492 if (v
< -32768 || v
> 32767) {
493 av_log(avctx
, AV_LOG_ERROR
, "DC value went out of bounds: %d\n", v
);
494 return AVERROR_INVALIDDATA
;
498 for (j
= 0; j
< len2
; j
++)
503 b
->cur_dec
= (uint8_t*)dst
;
508 * Retrieve next value from bundle.
510 * @param c decoder context
511 * @param bundle bundle number
513 static inline int get_value(BinkContext
*c
, int bundle
)
517 if (bundle
< BINK_SRC_X_OFF
|| bundle
== BINK_SRC_RUN
)
518 return *c
->bundle
[bundle
].cur_ptr
++;
519 if (bundle
== BINK_SRC_X_OFF
|| bundle
== BINK_SRC_Y_OFF
)
520 return (int8_t)*c
->bundle
[bundle
].cur_ptr
++;
521 ret
= *(int16_t*)c
->bundle
[bundle
].cur_ptr
;
522 c
->bundle
[bundle
].cur_ptr
+= 2;
526 static av_cold
void binkb_init_bundle(BinkContext
*c
, int bundle_num
)
528 c
->bundle
[bundle_num
].cur_dec
=
529 c
->bundle
[bundle_num
].cur_ptr
= c
->bundle
[bundle_num
].data
;
530 c
->bundle
[bundle_num
].len
= 13;
533 static av_cold
void binkb_init_bundles(BinkContext
*c
)
536 for (i
= 0; i
< BINKB_NB_SRC
; i
++)
537 binkb_init_bundle(c
, i
);
540 static int binkb_read_bundle(BinkContext
*c
, BitstreamContext
*bc
, int bundle_num
)
542 const int bits
= binkb_bundle_sizes
[bundle_num
];
543 const int mask
= 1 << (bits
- 1);
544 const int issigned
= binkb_bundle_signed
[bundle_num
];
545 Bundle
*b
= &c
->bundle
[bundle_num
];
548 CHECK_READ_VAL(bc
, b
, len
);
549 if (b
->data_end
- b
->cur_dec
< len
* (1 + (bits
> 8)))
550 return AVERROR_INVALIDDATA
;
553 for (i
= 0; i
< len
; i
++)
554 *b
->cur_dec
++ = bitstream_read(bc
, bits
);
556 for (i
= 0; i
< len
; i
++)
557 *b
->cur_dec
++ = bitstream_read(bc
, bits
) - mask
;
560 int16_t *dst
= (int16_t*)b
->cur_dec
;
563 for (i
= 0; i
< len
; i
++)
564 *dst
++ = bitstream_read(bc
, bits
);
566 for (i
= 0; i
< len
; i
++)
567 *dst
++ = bitstream_read(bc
, bits
) - mask
;
569 b
->cur_dec
= (uint8_t*)dst
;
574 static inline int binkb_get_value(BinkContext
*c
, int bundle_num
)
577 const int bits
= binkb_bundle_sizes
[bundle_num
];
580 int val
= *c
->bundle
[bundle_num
].cur_ptr
++;
581 return binkb_bundle_signed
[bundle_num
] ? (int8_t)val
: val
;
583 ret
= *(int16_t*)c
->bundle
[bundle_num
].cur_ptr
;
584 c
->bundle
[bundle_num
].cur_ptr
+= 2;
589 * Read 8x8 block of DCT coefficients.
591 * @param bc context for reading bits
592 * @param block place for storing coefficients
593 * @param scan scan order table
594 * @param quant_matrices quantization matrices
595 * @return 0 for success, negative value in other cases
597 static int read_dct_coeffs(BitstreamContext
*bc
, int32_t block
[64],
598 const uint8_t *scan
, int *coef_count_
,
599 int coef_idx
[64], int q
)
603 int i
, t
, bits
, ccoef
, mode
;
604 int list_start
= 64, list_end
= 64, list_pos
;
608 coef_list
[list_end
] = 4; mode_list
[list_end
++] = 0;
609 coef_list
[list_end
] = 24; mode_list
[list_end
++] = 0;
610 coef_list
[list_end
] = 44; mode_list
[list_end
++] = 0;
611 coef_list
[list_end
] = 1; mode_list
[list_end
++] = 3;
612 coef_list
[list_end
] = 2; mode_list
[list_end
++] = 3;
613 coef_list
[list_end
] = 3; mode_list
[list_end
++] = 3;
615 for (bits
= bitstream_read(bc
, 4) - 1; bits
>= 0; bits
--) {
616 list_pos
= list_start
;
617 while (list_pos
< list_end
) {
618 if (!(mode_list
[list_pos
] | coef_list
[list_pos
]) || !bitstream_read_bit(bc
)) {
622 ccoef
= coef_list
[list_pos
];
623 mode
= mode_list
[list_pos
];
626 coef_list
[list_pos
] = ccoef
+ 4;
627 mode_list
[list_pos
] = 1;
630 coef_list
[list_pos
] = 0;
631 mode_list
[list_pos
++] = 0;
633 for (i
= 0; i
< 4; i
++, ccoef
++) {
634 if (bitstream_read_bit(bc
)) {
635 coef_list
[--list_start
] = ccoef
;
636 mode_list
[ list_start
] = 3;
639 t
= 1 - (bitstream_read_bit(bc
) << 1);
641 t
= bitstream_read(bc
, bits
) | 1 << bits
;
642 t
= bitstream_apply_sign(bc
, t
);
644 block
[scan
[ccoef
]] = t
;
645 coef_idx
[coef_count
++] = ccoef
;
650 mode_list
[list_pos
] = 2;
651 for (i
= 0; i
< 3; i
++) {
653 coef_list
[list_end
] = ccoef
;
654 mode_list
[list_end
++] = 2;
659 t
= 1 - (bitstream_read_bit(bc
) << 1);
661 t
= bitstream_read(bc
, bits
) | 1 << bits
;
662 t
= bitstream_apply_sign(bc
, t
);
664 block
[scan
[ccoef
]] = t
;
665 coef_idx
[coef_count
++] = ccoef
;
666 coef_list
[list_pos
] = 0;
667 mode_list
[list_pos
++] = 0;
674 quant_idx
= bitstream_read(bc
, 4);
680 return AVERROR_INVALIDDATA
;
682 *coef_count_
= coef_count
;
687 static void unquantize_dct_coeffs(int32_t block
[64], const int32_t quant
[64],
688 int coef_count
, int coef_idx
[64],
692 block
[0] = (block
[0] * quant
[0]) >> 11;
693 for (i
= 0; i
< coef_count
; i
++) {
694 int idx
= coef_idx
[i
];
695 block
[scan
[idx
]] = (block
[scan
[idx
]] * quant
[idx
]) >> 11;
700 * Read 8x8 block with residue after motion compensation.
702 * @param bc context for reading bits
703 * @param block place to store read data
704 * @param masks_count number of masks to decode
705 * @return 0 on success, negative value in other cases
707 static int read_residue(BitstreamContext
*bc
, int16_t block
[64], int masks_count
)
711 int i
, mask
, ccoef
, mode
;
712 int list_start
= 64, list_end
= 64, list_pos
;
714 int nz_coeff_count
= 0;
716 coef_list
[list_end
] = 4; mode_list
[list_end
++] = 0;
717 coef_list
[list_end
] = 24; mode_list
[list_end
++] = 0;
718 coef_list
[list_end
] = 44; mode_list
[list_end
++] = 0;
719 coef_list
[list_end
] = 0; mode_list
[list_end
++] = 2;
721 for (mask
= 1 << bitstream_read(bc
, 3); mask
; mask
>>= 1) {
722 for (i
= 0; i
< nz_coeff_count
; i
++) {
723 if (!bitstream_read_bit(bc
))
725 if (block
[nz_coeff
[i
]] < 0)
726 block
[nz_coeff
[i
]] -= mask
;
728 block
[nz_coeff
[i
]] += mask
;
733 list_pos
= list_start
;
734 while (list_pos
< list_end
) {
735 if (!(coef_list
[list_pos
] | mode_list
[list_pos
]) || !bitstream_read_bit(bc
)) {
739 ccoef
= coef_list
[list_pos
];
740 mode
= mode_list
[list_pos
];
743 coef_list
[list_pos
] = ccoef
+ 4;
744 mode_list
[list_pos
] = 1;
747 coef_list
[list_pos
] = 0;
748 mode_list
[list_pos
++] = 0;
750 for (i
= 0; i
< 4; i
++, ccoef
++) {
751 if (bitstream_read_bit(bc
)) {
752 coef_list
[--list_start
] = ccoef
;
753 mode_list
[ list_start
] = 3;
755 nz_coeff
[nz_coeff_count
++] = bink_scan
[ccoef
];
756 block
[bink_scan
[ccoef
]] = bitstream_apply_sign(bc
, mask
);
764 mode_list
[list_pos
] = 2;
765 for (i
= 0; i
< 3; i
++) {
767 coef_list
[list_end
] = ccoef
;
768 mode_list
[list_end
++] = 2;
772 nz_coeff
[nz_coeff_count
++] = bink_scan
[ccoef
];
773 block
[bink_scan
[ccoef
]] = bitstream_apply_sign(bc
, mask
);
774 coef_list
[list_pos
] = 0;
775 mode_list
[list_pos
++] = 0;
788 * Copy 8x8 block from source to destination, where src and dst may be overlapped
790 static inline void put_pixels8x8_overlapped(uint8_t *dst
, uint8_t *src
, int stride
)
794 for (i
= 0; i
< 8; i
++)
795 memcpy(tmp
+ i
*8, src
+ i
*stride
, 8);
796 for (i
= 0; i
< 8; i
++)
797 memcpy(dst
+ i
*stride
, tmp
+ i
*8, 8);
800 static int binkb_decode_plane(BinkContext
*c
, AVFrame
*frame
, BitstreamContext
*bc
,
801 int plane_idx
, int is_key
, int is_chroma
)
805 uint8_t *dst
, *ref
, *ref_start
, *ref_end
;
809 LOCAL_ALIGNED_16(int16_t, block
, [64]);
810 LOCAL_ALIGNED_16(int32_t, dctblock
, [64]);
812 int ybias
= is_key
? -15 : 0;
813 int qp
, quant_idx
, coef_count
, coef_idx
[64];
815 const int stride
= frame
->linesize
[plane_idx
];
816 int bw
= is_chroma
? (c
->avctx
->width
+ 15) >> 4 : (c
->avctx
->width
+ 7) >> 3;
817 int bh
= is_chroma
? (c
->avctx
->height
+ 15) >> 4 : (c
->avctx
->height
+ 7) >> 3;
819 binkb_init_bundles(c
);
820 ref_start
= frame
->data
[plane_idx
];
821 ref_end
= frame
->data
[plane_idx
] + (bh
* frame
->linesize
[plane_idx
] + bw
) * 8;
823 for (i
= 0; i
< 64; i
++)
824 coordmap
[i
] = (i
& 7) + (i
>> 3) * stride
;
826 for (by
= 0; by
< bh
; by
++) {
827 for (i
= 0; i
< BINKB_NB_SRC
; i
++) {
828 if ((ret
= binkb_read_bundle(c
, bc
, i
)) < 0)
832 dst
= frame
->data
[plane_idx
] + 8*by
*stride
;
833 for (bx
= 0; bx
< bw
; bx
++, dst
+= 8) {
834 blk
= binkb_get_value(c
, BINKB_SRC_BLOCK_TYPES
);
839 scan
= bink_patterns
[bitstream_read(bc
, 4)];
842 int mode
= bitstream_read_bit(bc
);
843 int run
= bitstream_read(bc
, binkb_runbits
[i
]) + 1;
847 av_log(c
->avctx
, AV_LOG_ERROR
, "Run went out of bounds\n");
848 return AVERROR_INVALIDDATA
;
851 v
= binkb_get_value(c
, BINKB_SRC_COLORS
);
852 for (j
= 0; j
< run
; j
++)
853 dst
[coordmap
[*scan
++]] = v
;
855 for (j
= 0; j
< run
; j
++)
856 dst
[coordmap
[*scan
++]] = binkb_get_value(c
, BINKB_SRC_COLORS
);
860 dst
[coordmap
[*scan
++]] = binkb_get_value(c
, BINKB_SRC_COLORS
);
863 memset(dctblock
, 0, sizeof(*dctblock
) * 64);
864 dctblock
[0] = binkb_get_value(c
, BINKB_SRC_INTRA_DC
);
865 qp
= binkb_get_value(c
, BINKB_SRC_INTRA_Q
);
866 if ((quant_idx
= read_dct_coeffs(bc
, dctblock
, bink_scan
, &coef_count
, coef_idx
, qp
)) < 0)
868 unquantize_dct_coeffs(dctblock
, binkb_intra_quant
[quant_idx
], coef_count
, coef_idx
, bink_scan
);
869 c
->binkdsp
.idct_put(dst
, stride
, dctblock
);
872 xoff
= binkb_get_value(c
, BINKB_SRC_X_OFF
);
873 yoff
= binkb_get_value(c
, BINKB_SRC_Y_OFF
) + ybias
;
874 ref
= dst
+ xoff
+ yoff
* stride
;
875 if (ref
< ref_start
|| ref
+ 8*stride
> ref_end
) {
876 av_log(c
->avctx
, AV_LOG_WARNING
, "Reference block is out of bounds\n");
877 } else if (ref
+ 8*stride
< dst
|| ref
>= dst
+ 8*stride
) {
878 c
->hdsp
.put_pixels_tab
[1][0](dst
, ref
, stride
, 8);
880 put_pixels8x8_overlapped(dst
, ref
, stride
);
882 c
->bdsp
.clear_block(block
);
883 v
= binkb_get_value(c
, BINKB_SRC_INTER_COEFS
);
884 read_residue(bc
, block
, v
);
885 c
->binkdsp
.add_pixels8(dst
, block
, stride
);
888 xoff
= binkb_get_value(c
, BINKB_SRC_X_OFF
);
889 yoff
= binkb_get_value(c
, BINKB_SRC_Y_OFF
) + ybias
;
890 ref
= dst
+ xoff
+ yoff
* stride
;
891 if (ref
< ref_start
|| ref
+ 8 * stride
> ref_end
) {
892 av_log(c
->avctx
, AV_LOG_WARNING
, "Reference block is out of bounds\n");
893 } else if (ref
+ 8*stride
< dst
|| ref
>= dst
+ 8*stride
) {
894 c
->hdsp
.put_pixels_tab
[1][0](dst
, ref
, stride
, 8);
896 put_pixels8x8_overlapped(dst
, ref
, stride
);
898 memset(dctblock
, 0, sizeof(*dctblock
) * 64);
899 dctblock
[0] = binkb_get_value(c
, BINKB_SRC_INTER_DC
);
900 qp
= binkb_get_value(c
, BINKB_SRC_INTER_Q
);
901 if ((quant_idx
= read_dct_coeffs(bc
, dctblock
, bink_scan
, &coef_count
, coef_idx
, qp
)) < 0)
903 unquantize_dct_coeffs(dctblock
, binkb_inter_quant
[quant_idx
], coef_count
, coef_idx
, bink_scan
);
904 c
->binkdsp
.idct_add(dst
, stride
, dctblock
);
907 v
= binkb_get_value(c
, BINKB_SRC_COLORS
);
908 c
->bdsp
.fill_block_tab
[1](dst
, v
, stride
, 8);
911 for (i
= 0; i
< 2; i
++)
912 col
[i
] = binkb_get_value(c
, BINKB_SRC_COLORS
);
913 for (i
= 0; i
< 8; i
++) {
914 v
= binkb_get_value(c
, BINKB_SRC_PATTERN
);
915 for (j
= 0; j
< 8; j
++, v
>>= 1)
916 dst
[i
*stride
+ j
] = col
[v
& 1];
920 xoff
= binkb_get_value(c
, BINKB_SRC_X_OFF
);
921 yoff
= binkb_get_value(c
, BINKB_SRC_Y_OFF
) + ybias
;
922 ref
= dst
+ xoff
+ yoff
* stride
;
923 if (ref
< ref_start
|| ref
+ 8 * stride
> ref_end
) {
924 av_log(c
->avctx
, AV_LOG_WARNING
, "Reference block is out of bounds\n");
925 } else if (ref
+ 8*stride
< dst
|| ref
>= dst
+ 8*stride
) {
926 c
->hdsp
.put_pixels_tab
[1][0](dst
, ref
, stride
, 8);
928 put_pixels8x8_overlapped(dst
, ref
, stride
);
932 for (i
= 0; i
< 8; i
++)
933 memcpy(dst
+ i
*stride
, c
->bundle
[BINKB_SRC_COLORS
].cur_ptr
+ i
*8, 8);
934 c
->bundle
[BINKB_SRC_COLORS
].cur_ptr
+= 64;
937 av_log(c
->avctx
, AV_LOG_ERROR
, "Unknown block type %d\n", blk
);
938 return AVERROR_INVALIDDATA
;
942 if (bitstream_tell(bc
) & 0x1F) // next plane data starts at 32-bit boundary
943 bitstream_skip(bc
, 32 - (bitstream_tell(bc
) & 0x1F));
948 static int bink_put_pixels(BinkContext
*c
,
949 uint8_t *dst
, uint8_t *prev
, int stride
,
953 int xoff
= get_value(c
, BINK_SRC_X_OFF
);
954 int yoff
= get_value(c
, BINK_SRC_Y_OFF
);
955 uint8_t *ref
= prev
+ xoff
+ yoff
* stride
;
956 if (ref
< ref_start
|| ref
> ref_end
) {
957 av_log(c
->avctx
, AV_LOG_ERROR
, "Copy out of bounds @%d, %d\n",
959 return AVERROR_INVALIDDATA
;
961 c
->hdsp
.put_pixels_tab
[1][0](dst
, ref
, stride
, 8);
966 static int bink_decode_plane(BinkContext
*c
, AVFrame
*frame
, BitstreamContext
*bc
,
967 int plane_idx
, int is_chroma
)
971 uint8_t *dst
, *prev
, *ref_start
, *ref_end
;
974 LOCAL_ALIGNED_16(int16_t, block
, [64]);
975 LOCAL_ALIGNED_16(uint8_t, ublock
, [64]);
976 LOCAL_ALIGNED_16(int32_t, dctblock
, [64]);
977 int coordmap
[64], quant_idx
, coef_count
, coef_idx
[64];
979 const int stride
= frame
->linesize
[plane_idx
];
980 int bw
= is_chroma
? (c
->avctx
->width
+ 15) >> 4 : (c
->avctx
->width
+ 7) >> 3;
981 int bh
= is_chroma
? (c
->avctx
->height
+ 15) >> 4 : (c
->avctx
->height
+ 7) >> 3;
982 int width
= c
->avctx
->width
>> is_chroma
;
984 init_lengths(c
, FFMAX(width
, 8), bw
);
985 for (i
= 0; i
< BINK_NB_SRC
; i
++)
986 read_bundle(bc
, c
, i
);
988 ref_start
= c
->last
->data
[plane_idx
] ? c
->last
->data
[plane_idx
]
989 : frame
->data
[plane_idx
];
991 + (bw
- 1 + c
->last
->linesize
[plane_idx
] * (bh
- 1)) * 8;
993 for (i
= 0; i
< 64; i
++)
994 coordmap
[i
] = (i
& 7) + (i
>> 3) * stride
;
996 for (by
= 0; by
< bh
; by
++) {
997 if ((ret
= read_block_types(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_BLOCK_TYPES
])) < 0)
999 if ((ret
= read_block_types(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_SUB_BLOCK_TYPES
])) < 0)
1001 if ((ret
= read_colors(bc
, &c
->bundle
[BINK_SRC_COLORS
], c
)) < 0)
1003 if ((ret
= read_patterns(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_PATTERN
])) < 0)
1005 if ((ret
= read_motion_values(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_X_OFF
])) < 0)
1007 if ((ret
= read_motion_values(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_Y_OFF
])) < 0)
1009 if ((ret
= read_dcs(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_INTRA_DC
], DC_START_BITS
, 0)) < 0)
1011 if ((ret
= read_dcs(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_INTER_DC
], DC_START_BITS
, 1)) < 0)
1013 if ((ret
= read_runs(c
->avctx
, bc
, &c
->bundle
[BINK_SRC_RUN
])) < 0)
1018 dst
= frame
->data
[plane_idx
] + 8*by
*stride
;
1019 prev
= (c
->last
->data
[plane_idx
] ? c
->last
->data
[plane_idx
]
1020 : frame
->data
[plane_idx
]) + 8*by
*stride
;
1021 for (bx
= 0; bx
< bw
; bx
++, dst
+= 8, prev
+= 8) {
1022 blk
= get_value(c
, BINK_SRC_BLOCK_TYPES
);
1023 // 16x16 block type on odd line means part of the already decoded block, so skip it
1024 if ((by
& 1) && blk
== SCALED_BLOCK
) {
1032 c
->hdsp
.put_pixels_tab
[1][0](dst
, prev
, stride
, 8);
1035 blk
= get_value(c
, BINK_SRC_SUB_BLOCK_TYPES
);
1038 scan
= bink_patterns
[bitstream_read(bc
, 4)];
1041 int run
= get_value(c
, BINK_SRC_RUN
) + 1;
1045 av_log(c
->avctx
, AV_LOG_ERROR
, "Run went out of bounds\n");
1046 return AVERROR_INVALIDDATA
;
1048 if (bitstream_read_bit(bc
)) {
1049 v
= get_value(c
, BINK_SRC_COLORS
);
1050 for (j
= 0; j
< run
; j
++)
1051 ublock
[*scan
++] = v
;
1053 for (j
= 0; j
< run
; j
++)
1054 ublock
[*scan
++] = get_value(c
, BINK_SRC_COLORS
);
1058 ublock
[*scan
++] = get_value(c
, BINK_SRC_COLORS
);
1061 memset(dctblock
, 0, sizeof(*dctblock
) * 64);
1062 dctblock
[0] = get_value(c
, BINK_SRC_INTRA_DC
);
1063 if ((quant_idx
= read_dct_coeffs(bc
, dctblock
, bink_scan
, &coef_count
, coef_idx
, -1)) < 0)
1065 unquantize_dct_coeffs(dctblock
, bink_intra_quant
[quant_idx
], coef_count
, coef_idx
, bink_scan
);
1066 c
->binkdsp
.idct_put(ublock
, 8, dctblock
);
1069 v
= get_value(c
, BINK_SRC_COLORS
);
1070 c
->bdsp
.fill_block_tab
[0](dst
, v
, stride
, 16);
1073 for (i
= 0; i
< 2; i
++)
1074 col
[i
] = get_value(c
, BINK_SRC_COLORS
);
1075 for (j
= 0; j
< 8; j
++) {
1076 v
= get_value(c
, BINK_SRC_PATTERN
);
1077 for (i
= 0; i
< 8; i
++, v
>>= 1)
1078 ublock
[i
+ j
*8] = col
[v
& 1];
1082 for (j
= 0; j
< 8; j
++)
1083 for (i
= 0; i
< 8; i
++)
1084 ublock
[i
+ j
*8] = get_value(c
, BINK_SRC_COLORS
);
1087 av_log(c
->avctx
, AV_LOG_ERROR
, "Incorrect 16x16 block type %d\n", blk
);
1088 return AVERROR_INVALIDDATA
;
1090 if (blk
!= FILL_BLOCK
)
1091 c
->binkdsp
.scale_block(ublock
, dst
, stride
);
1097 ret
= bink_put_pixels(c
, dst
, prev
, stride
,
1098 ref_start
, ref_end
);
1103 scan
= bink_patterns
[bitstream_read(bc
, 4)];
1106 int run
= get_value(c
, BINK_SRC_RUN
) + 1;
1110 av_log(c
->avctx
, AV_LOG_ERROR
, "Run went out of bounds\n");
1111 return AVERROR_INVALIDDATA
;
1113 if (bitstream_read_bit(bc
)) {
1114 v
= get_value(c
, BINK_SRC_COLORS
);
1115 for (j
= 0; j
< run
; j
++)
1116 dst
[coordmap
[*scan
++]] = v
;
1118 for (j
= 0; j
< run
; j
++)
1119 dst
[coordmap
[*scan
++]] = get_value(c
, BINK_SRC_COLORS
);
1123 dst
[coordmap
[*scan
++]] = get_value(c
, BINK_SRC_COLORS
);
1126 ret
= bink_put_pixels(c
, dst
, prev
, stride
,
1127 ref_start
, ref_end
);
1130 c
->bdsp
.clear_block(block
);
1131 v
= bitstream_read(bc
, 7);
1132 read_residue(bc
, block
, v
);
1133 c
->binkdsp
.add_pixels8(dst
, block
, stride
);
1136 memset(dctblock
, 0, sizeof(*dctblock
) * 64);
1137 dctblock
[0] = get_value(c
, BINK_SRC_INTRA_DC
);
1138 if ((quant_idx
= read_dct_coeffs(bc
, dctblock
, bink_scan
, &coef_count
, coef_idx
, -1)) < 0)
1140 unquantize_dct_coeffs(dctblock
, bink_intra_quant
[quant_idx
], coef_count
, coef_idx
, bink_scan
);
1141 c
->binkdsp
.idct_put(dst
, stride
, dctblock
);
1144 v
= get_value(c
, BINK_SRC_COLORS
);
1145 c
->bdsp
.fill_block_tab
[1](dst
, v
, stride
, 8);
1148 ret
= bink_put_pixels(c
, dst
, prev
, stride
,
1149 ref_start
, ref_end
);
1152 memset(dctblock
, 0, sizeof(*dctblock
) * 64);
1153 dctblock
[0] = get_value(c
, BINK_SRC_INTER_DC
);
1154 if ((quant_idx
= read_dct_coeffs(bc
, dctblock
, bink_scan
, &coef_count
, coef_idx
, -1)) < 0)
1156 unquantize_dct_coeffs(dctblock
, bink_inter_quant
[quant_idx
], coef_count
, coef_idx
, bink_scan
);
1157 c
->binkdsp
.idct_add(dst
, stride
, dctblock
);
1160 for (i
= 0; i
< 2; i
++)
1161 col
[i
] = get_value(c
, BINK_SRC_COLORS
);
1162 for (i
= 0; i
< 8; i
++) {
1163 v
= get_value(c
, BINK_SRC_PATTERN
);
1164 for (j
= 0; j
< 8; j
++, v
>>= 1)
1165 dst
[i
*stride
+ j
] = col
[v
& 1];
1169 for (i
= 0; i
< 8; i
++)
1170 memcpy(dst
+ i
*stride
, c
->bundle
[BINK_SRC_COLORS
].cur_ptr
+ i
*8, 8);
1171 c
->bundle
[BINK_SRC_COLORS
].cur_ptr
+= 64;
1174 av_log(c
->avctx
, AV_LOG_ERROR
, "Unknown block type %d\n", blk
);
1175 return AVERROR_INVALIDDATA
;
1179 if (bitstream_tell(bc
) & 0x1F) // next plane data starts at 32-bit boundary
1180 bitstream_skip(bc
, 32 - (bitstream_tell(bc
) & 0x1F));
1185 static int decode_frame(AVCodecContext
*avctx
, void *data
, int *got_frame
, AVPacket
*pkt
)
1187 BinkContext
* const c
= avctx
->priv_data
;
1188 AVFrame
*frame
= data
;
1189 BitstreamContext bc
;
1190 int plane
, plane_idx
, ret
;
1191 int bits_count
= pkt
->size
<< 3;
1193 if (c
->version
> 'b') {
1194 if ((ret
= ff_get_buffer(avctx
, frame
, AV_GET_BUFFER_FLAG_REF
)) < 0) {
1195 av_log(avctx
, AV_LOG_ERROR
, "get_buffer() failed\n");
1199 if ((ret
= ff_reget_buffer(avctx
, c
->last
)) < 0) {
1200 av_log(avctx
, AV_LOG_ERROR
, "reget_buffer() failed\n");
1203 if ((ret
= av_frame_ref(frame
, c
->last
)) < 0)
1207 bitstream_init(&bc
, pkt
->data
, bits_count
);
1209 if (c
->version
>= 'i')
1210 bitstream_skip(&bc
, 32);
1211 if ((ret
= bink_decode_plane(c
, frame
, &bc
, 3, 0)) < 0)
1214 if (c
->version
>= 'i')
1215 bitstream_skip(&bc
, 32);
1217 for (plane
= 0; plane
< 3; plane
++) {
1218 plane_idx
= (!plane
|| !c
->swap_planes
) ? plane
: (plane
^ 3);
1220 if (c
->version
> 'b') {
1221 if ((ret
= bink_decode_plane(c
, frame
, &bc
, plane_idx
, !!plane
)) < 0)
1224 if ((ret
= binkb_decode_plane(c
, frame
, &bc
, plane_idx
,
1225 !avctx
->frame_number
, !!plane
)) < 0)
1228 if (bitstream_tell(&bc
) >= bits_count
)
1233 if (c
->version
> 'b') {
1234 av_frame_unref(c
->last
);
1235 if ((ret
= av_frame_ref(c
->last
, frame
)) < 0)
1241 /* always report that the buffer was completely consumed */
1246 * Calculate quantization tables for version b
1248 static av_cold
void binkb_calc_quant(void)
1250 uint8_t inv_bink_scan
[64];
1254 for (j
= 0; j
< 8; j
++) {
1255 for (i
= 0; i
< 8; i
++) {
1258 s
[j
*8 + i
] = cos(j
* M_PI
/16.0) * cos(i
* M_PI
/16.0) * 2.0;
1260 s
[j
*8 + i
] = cos(j
* M_PI
/16.0) * sqrt(2.0);
1263 s
[j
*8 + i
] = cos(i
* M_PI
/16.0) * sqrt(2.0);
1269 for (i
= 0; i
< 64; i
++)
1270 inv_bink_scan
[bink_scan
[i
]] = i
;
1272 for (j
= 0; j
< 16; j
++) {
1273 for (i
= 0; i
< 64; i
++) {
1274 int k
= inv_bink_scan
[i
];
1276 binkb_intra_quant
[j
][k
] = (1L << 12) * binkb_intra_seed
[i
] *
1277 binkb_num
[j
]/binkb_den
[j
];
1278 binkb_inter_quant
[j
][k
] = (1L << 12) * binkb_inter_seed
[i
] *
1279 binkb_num
[j
]/binkb_den
[j
];
1281 binkb_intra_quant
[j
][k
] = (1L << 12) * binkb_intra_seed
[i
] * s
[i
] *
1282 binkb_num
[j
]/(double)binkb_den
[j
];
1283 binkb_inter_quant
[j
][k
] = (1L << 12) * binkb_inter_seed
[i
] * s
[i
] *
1284 binkb_num
[j
]/(double)binkb_den
[j
];
1290 static av_cold
int decode_init(AVCodecContext
*avctx
)
1292 BinkContext
* const c
= avctx
->priv_data
;
1293 static VLC_TYPE table
[16 * 128][2];
1294 static int binkb_initialised
= 0;
1298 c
->version
= avctx
->codec_tag
>> 24;
1299 if (avctx
->extradata_size
< 4) {
1300 av_log(avctx
, AV_LOG_ERROR
, "Extradata missing or too short\n");
1301 return AVERROR_INVALIDDATA
;
1303 flags
= AV_RL32(avctx
->extradata
);
1304 c
->has_alpha
= flags
& BINK_FLAG_ALPHA
;
1305 c
->swap_planes
= c
->version
>= 'h';
1306 if (!bink_trees
[15].table
) {
1307 for (i
= 0; i
< 16; i
++) {
1308 const int maxbits
= bink_tree_lens
[i
][15];
1309 bink_trees
[i
].table
= table
+ i
*128;
1310 bink_trees
[i
].table_allocated
= 1 << maxbits
;
1311 init_vlc(&bink_trees
[i
], maxbits
, 16,
1312 bink_tree_lens
[i
], 1, 1,
1313 bink_tree_bits
[i
], 1, 1, INIT_VLC_USE_NEW_STATIC
| INIT_VLC_LE
);
1318 c
->last
= av_frame_alloc();
1320 return AVERROR(ENOMEM
);
1322 if ((ret
= av_image_check_size(avctx
->width
, avctx
->height
, 0, avctx
)) < 0)
1325 avctx
->pix_fmt
= c
->has_alpha
? AV_PIX_FMT_YUVA420P
: AV_PIX_FMT_YUV420P
;
1327 ff_blockdsp_init(&c
->bdsp
);
1328 ff_hpeldsp_init(&c
->hdsp
, avctx
->flags
);
1329 ff_binkdsp_init(&c
->binkdsp
);
1333 if (c
->version
== 'b') {
1334 if (!binkb_initialised
) {
1336 binkb_initialised
= 1;
1343 static av_cold
int decode_end(AVCodecContext
*avctx
)
1345 BinkContext
* const c
= avctx
->priv_data
;
1347 av_frame_free(&c
->last
);
1353 AVCodec ff_bink_decoder
= {
1354 .name
= "binkvideo",
1355 .long_name
= NULL_IF_CONFIG_SMALL("Bink video"),
1356 .type
= AVMEDIA_TYPE_VIDEO
,
1357 .id
= AV_CODEC_ID_BINKVIDEO
,
1358 .priv_data_size
= sizeof(BinkContext
),
1359 .init
= decode_init
,
1360 .close
= decode_end
,
1361 .decode
= decode_frame
,
1362 .capabilities
= AV_CODEC_CAP_DR1
,