FFmpeg
bink.c
Go to the documentation of this file.
1 /*
2  * Bink video decoder
3  * Copyright (c) 2009 Konstantin Shishkov
4  * Copyright (C) 2011 Peter Ross <pross@xvid.org>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg 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.
12  *
13  * FFmpeg 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.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/attributes.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/internal.h"
26 
27 #define BITSTREAM_READER_LE
28 #include "avcodec.h"
29 #include "binkdata.h"
30 #include "binkdsp.h"
31 #include "blockdsp.h"
32 #include "get_bits.h"
33 #include "hpeldsp.h"
34 #include "internal.h"
35 #include "mathops.h"
36 
37 #define BINK_FLAG_ALPHA 0x00100000
38 #define BINK_FLAG_GRAY 0x00020000
39 
40 static VLC bink_trees[16];
41 
42 /**
43  * IDs for different data types used in old version of Bink video codec
44  */
45 enum OldSources {
46  BINKB_SRC_BLOCK_TYPES = 0, ///< 8x8 block types
47  BINKB_SRC_COLORS, ///< pixel values used for different block types
48  BINKB_SRC_PATTERN, ///< 8-bit values for 2-colour pattern fill
49  BINKB_SRC_X_OFF, ///< X components of motion value
50  BINKB_SRC_Y_OFF, ///< Y components of motion value
51  BINKB_SRC_INTRA_DC, ///< DC values for intrablocks with DCT
52  BINKB_SRC_INTER_DC, ///< DC values for interblocks with DCT
53  BINKB_SRC_INTRA_Q, ///< quantizer values for intrablocks with DCT
54  BINKB_SRC_INTER_Q, ///< quantizer values for interblocks with DCT
55  BINKB_SRC_INTER_COEFS, ///< number of coefficients for residue blocks
56 
58 };
59 
60 static const int binkb_bundle_sizes[BINKB_NB_SRC] = {
61  4, 8, 8, 5, 5, 11, 11, 4, 4, 7
62 };
63 
64 static const int binkb_bundle_signed[BINKB_NB_SRC] = {
65  0, 0, 0, 1, 1, 0, 1, 0, 0, 0
66 };
67 
68 static int32_t binkb_intra_quant[16][64];
69 static int32_t binkb_inter_quant[16][64];
70 
71 /**
72  * IDs for different data types used in Bink video codec
73  */
74 enum Sources {
75  BINK_SRC_BLOCK_TYPES = 0, ///< 8x8 block types
76  BINK_SRC_SUB_BLOCK_TYPES, ///< 16x16 block types (a subset of 8x8 block types)
77  BINK_SRC_COLORS, ///< pixel values used for different block types
78  BINK_SRC_PATTERN, ///< 8-bit values for 2-colour pattern fill
79  BINK_SRC_X_OFF, ///< X components of motion value
80  BINK_SRC_Y_OFF, ///< Y components of motion value
81  BINK_SRC_INTRA_DC, ///< DC values for intrablocks with DCT
82  BINK_SRC_INTER_DC, ///< DC values for interblocks with DCT
83  BINK_SRC_RUN, ///< run lengths for special fill block
84 
86 };
87 
88 /**
89  * data needed to decode 4-bit Huffman-coded value
90  */
91 typedef struct Tree {
92  int vlc_num; ///< tree number (in bink_trees[])
93  uint8_t syms[16]; ///< leaf value to symbol mapping
94 } Tree;
95 
96 #define GET_HUFF(gb, tree) (tree).syms[get_vlc2(gb, bink_trees[(tree).vlc_num].table,\
97  bink_trees[(tree).vlc_num].bits, 1)]
98 
99 /**
100  * data structure used for decoding single Bink data type
101  */
102 typedef struct Bundle {
103  int len; ///< length of number of entries to decode (in bits)
104  Tree tree; ///< Huffman tree-related data
105  uint8_t *data; ///< buffer for decoded symbols
106  uint8_t *data_end; ///< buffer end
107  uint8_t *cur_dec; ///< pointer to the not yet decoded part of the buffer
108  uint8_t *cur_ptr; ///< pointer to the data that is not read from buffer yet
109 } Bundle;
110 
111 /*
112  * Decoder context
113  */
114 typedef struct BinkContext {
120  int version; ///< internal Bink file version
123  unsigned frame_num;
124 
125  Bundle bundle[BINKB_NB_SRC]; ///< bundles for decoding all data types
126  Tree col_high[16]; ///< trees for decoding high nibble in "colours" data type
127  int col_lastval; ///< value of last decoded high nibble in "colours" data type
128 } BinkContext;
129 
130 /**
131  * Bink video block types
132  */
134  SKIP_BLOCK = 0, ///< skipped block
135  SCALED_BLOCK, ///< block has size 16x16
136  MOTION_BLOCK, ///< block is copied from previous frame with some offset
137  RUN_BLOCK, ///< block is composed from runs of colours with custom scan order
138  RESIDUE_BLOCK, ///< motion block with some difference added
139  INTRA_BLOCK, ///< intra DCT block
140  FILL_BLOCK, ///< block is filled with single colour
141  INTER_BLOCK, ///< motion block with DCT applied to the difference
142  PATTERN_BLOCK, ///< block is filled with two colours following custom pattern
143  RAW_BLOCK, ///< uncoded 8x8 block
144 };
145 
146 /**
147  * Initialize length in all bundles.
148  *
149  * @param c decoder context
150  * @param width plane width
151  * @param bw plane width in 8x8 blocks
152  */
153 static void init_lengths(BinkContext *c, int width, int bw)
154 {
155  width = FFALIGN(width, 8);
156 
157  c->bundle[BINK_SRC_BLOCK_TYPES].len = av_log2((width >> 3) + 511) + 1;
158 
159  c->bundle[BINK_SRC_SUB_BLOCK_TYPES].len = av_log2((width >> 4) + 511) + 1;
160 
161  c->bundle[BINK_SRC_COLORS].len = av_log2(bw*64 + 511) + 1;
162 
166  c->bundle[BINK_SRC_Y_OFF].len = av_log2((width >> 3) + 511) + 1;
167 
168  c->bundle[BINK_SRC_PATTERN].len = av_log2((bw << 3) + 511) + 1;
169 
170  c->bundle[BINK_SRC_RUN].len = av_log2(bw*48 + 511) + 1;
171 }
172 
173 /**
174  * Allocate memory for bundles.
175  *
176  * @param c decoder context
177  */
179 {
180  int bw, bh, blocks;
181  uint8_t *tmp;
182  int i;
183 
184  bw = (c->avctx->width + 7) >> 3;
185  bh = (c->avctx->height + 7) >> 3;
186  blocks = bw * bh;
187 
188  tmp = av_calloc(blocks, 64 * BINKB_NB_SRC);
189  if (!tmp)
190  return AVERROR(ENOMEM);
191  for (i = 0; i < BINKB_NB_SRC; i++) {
192  c->bundle[i].data = tmp;
193  tmp += blocks * 64;
194  c->bundle[i].data_end = tmp;
195  }
196 
197  return 0;
198 }
199 
200 /**
201  * Free memory used by bundles.
202  *
203  * @param c decoder context
204  */
206 {
207  av_freep(&c->bundle[0].data);
208 }
209 
210 /**
211  * Merge two consequent lists of equal size depending on bits read.
212  *
213  * @param gb context for reading bits
214  * @param dst buffer where merged list will be written to
215  * @param src pointer to the head of the first list (the second lists starts at src+size)
216  * @param size input lists size
217  */
218 static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
219 {
220  uint8_t *src2 = src + size;
221  int size2 = size;
222 
223  do {
224  if (!get_bits1(gb)) {
225  *dst++ = *src++;
226  size--;
227  } else {
228  *dst++ = *src2++;
229  size2--;
230  }
231  } while (size && size2);
232 
233  while (size--)
234  *dst++ = *src++;
235  while (size2--)
236  *dst++ = *src2++;
237 }
238 
239 /**
240  * Read information about Huffman tree used to decode data.
241  *
242  * @param gb context for reading bits
243  * @param tree pointer for storing tree data
244  */
245 static int read_tree(GetBitContext *gb, Tree *tree)
246 {
247  uint8_t tmp1[16] = { 0 }, tmp2[16], *in = tmp1, *out = tmp2;
248  int i, t, len;
249 
250  if (get_bits_left(gb) < 4)
251  return AVERROR_INVALIDDATA;
252 
253  tree->vlc_num = get_bits(gb, 4);
254  if (!tree->vlc_num) {
255  for (i = 0; i < 16; i++)
256  tree->syms[i] = i;
257  return 0;
258  }
259  if (get_bits1(gb)) {
260  len = get_bits(gb, 3);
261  for (i = 0; i <= len; i++) {
262  tree->syms[i] = get_bits(gb, 4);
263  tmp1[tree->syms[i]] = 1;
264  }
265  for (i = 0; i < 16 && len < 16 - 1; i++)
266  if (!tmp1[i])
267  tree->syms[++len] = i;
268  } else {
269  len = get_bits(gb, 2);
270  for (i = 0; i < 16; i++)
271  in[i] = i;
272  for (i = 0; i <= len; i++) {
273  int size = 1 << i;
274  for (t = 0; t < 16; t += size << 1)
275  merge(gb, out + t, in + t, size);
276  FFSWAP(uint8_t*, in, out);
277  }
278  memcpy(tree->syms, in, 16);
279  }
280  return 0;
281 }
282 
283 /**
284  * Prepare bundle for decoding data.
285  *
286  * @param gb context for reading bits
287  * @param c decoder context
288  * @param bundle_num number of the bundle to initialize
289  */
290 static int read_bundle(GetBitContext *gb, BinkContext *c, int bundle_num)
291 {
292  int i;
293 
294  if (bundle_num == BINK_SRC_COLORS) {
295  for (i = 0; i < 16; i++) {
296  int ret = read_tree(gb, &c->col_high[i]);
297  if (ret < 0)
298  return ret;
299  }
300  c->col_lastval = 0;
301  }
302  if (bundle_num != BINK_SRC_INTRA_DC && bundle_num != BINK_SRC_INTER_DC) {
303  int ret = read_tree(gb, &c->bundle[bundle_num].tree);
304  if (ret < 0)
305  return ret;
306  }
307  c->bundle[bundle_num].cur_dec =
308  c->bundle[bundle_num].cur_ptr = c->bundle[bundle_num].data;
309 
310  return 0;
311 }
312 
313 /**
314  * common check before starting decoding bundle data
315  *
316  * @param gb context for reading bits
317  * @param b bundle
318  * @param t variable where number of elements to decode will be stored
319  */
320 #define CHECK_READ_VAL(gb, b, t) \
321  if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
322  return 0; \
323  t = get_bits(gb, b->len); \
324  if (!t) { \
325  b->cur_dec = NULL; \
326  return 0; \
327  } \
328 
329 static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
330 {
331  int t, v;
332  const uint8_t *dec_end;
333 
334  CHECK_READ_VAL(gb, b, t);
335  dec_end = b->cur_dec + t;
336  if (dec_end > b->data_end) {
337  av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n");
338  return AVERROR_INVALIDDATA;
339  }
340  if (get_bits_left(gb) < 1)
341  return AVERROR_INVALIDDATA;
342  if (get_bits1(gb)) {
343  v = get_bits(gb, 4);
344  memset(b->cur_dec, v, t);
345  b->cur_dec += t;
346  } else {
347  while (b->cur_dec < dec_end)
348  *b->cur_dec++ = GET_HUFF(gb, b->tree);
349  }
350  return 0;
351 }
352 
354 {
355  int t, sign, v;
356  const uint8_t *dec_end;
357 
358  CHECK_READ_VAL(gb, b, t);
359  dec_end = b->cur_dec + t;
360  if (dec_end > b->data_end) {
361  av_log(avctx, AV_LOG_ERROR, "Too many motion values\n");
362  return AVERROR_INVALIDDATA;
363  }
364  if (get_bits_left(gb) < 1)
365  return AVERROR_INVALIDDATA;
366  if (get_bits1(gb)) {
367  v = get_bits(gb, 4);
368  if (v) {
369  sign = -get_bits1(gb);
370  v = (v ^ sign) - sign;
371  }
372  memset(b->cur_dec, v, t);
373  b->cur_dec += t;
374  } else {
375  while (b->cur_dec < dec_end) {
376  v = GET_HUFF(gb, b->tree);
377  if (v) {
378  sign = -get_bits1(gb);
379  v = (v ^ sign) - sign;
380  }
381  *b->cur_dec++ = v;
382  }
383  }
384  return 0;
385 }
386 
387 static const uint8_t bink_rlelens[4] = { 4, 8, 12, 32 };
388 
390 {
391  BinkContext * const c = avctx->priv_data;
392  int t, v;
393  int last = 0;
394  const uint8_t *dec_end;
395 
396  CHECK_READ_VAL(gb, b, t);
397  if (c->version == 'k') {
398  t ^= 0xBBu;
399  if (t == 0) {
400  b->cur_dec = NULL;
401  return 0;
402  }
403  }
404  dec_end = b->cur_dec + t;
405  if (dec_end > b->data_end) {
406  av_log(avctx, AV_LOG_ERROR, "Too many block type values\n");
407  return AVERROR_INVALIDDATA;
408  }
409  if (get_bits_left(gb) < 1)
410  return AVERROR_INVALIDDATA;
411  if (get_bits1(gb)) {
412  v = get_bits(gb, 4);
413  memset(b->cur_dec, v, t);
414  b->cur_dec += t;
415  } else {
416  while (b->cur_dec < dec_end) {
417  v = GET_HUFF(gb, b->tree);
418  if (v < 12) {
419  last = v;
420  *b->cur_dec++ = v;
421  } else {
422  int run = bink_rlelens[v - 12];
423 
424  if (dec_end - b->cur_dec < run)
425  return AVERROR_INVALIDDATA;
426  memset(b->cur_dec, last, run);
427  b->cur_dec += run;
428  }
429  }
430  }
431  return 0;
432 }
433 
435 {
436  int t, v;
437  const uint8_t *dec_end;
438 
439  CHECK_READ_VAL(gb, b, t);
440  dec_end = b->cur_dec + t;
441  if (dec_end > b->data_end) {
442  av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n");
443  return AVERROR_INVALIDDATA;
444  }
445  while (b->cur_dec < dec_end) {
446  if (get_bits_left(gb) < 2)
447  return AVERROR_INVALIDDATA;
448  v = GET_HUFF(gb, b->tree);
449  v |= GET_HUFF(gb, b->tree) << 4;
450  *b->cur_dec++ = v;
451  }
452 
453  return 0;
454 }
455 
457 {
458  int t, sign, v;
459  const uint8_t *dec_end;
460 
461  CHECK_READ_VAL(gb, b, t);
462  dec_end = b->cur_dec + t;
463  if (dec_end > b->data_end) {
464  av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n");
465  return AVERROR_INVALIDDATA;
466  }
467  if (get_bits_left(gb) < 1)
468  return AVERROR_INVALIDDATA;
469  if (get_bits1(gb)) {
470  c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]);
471  v = GET_HUFF(gb, b->tree);
472  v = (c->col_lastval << 4) | v;
473  if (c->version < 'i') {
474  sign = ((int8_t) v) >> 7;
475  v = ((v & 0x7F) ^ sign) - sign;
476  v += 0x80;
477  }
478  memset(b->cur_dec, v, t);
479  b->cur_dec += t;
480  } else {
481  while (b->cur_dec < dec_end) {
482  if (get_bits_left(gb) < 2)
483  return AVERROR_INVALIDDATA;
484  c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]);
485  v = GET_HUFF(gb, b->tree);
486  v = (c->col_lastval << 4) | v;
487  if (c->version < 'i') {
488  sign = ((int8_t) v) >> 7;
489  v = ((v & 0x7F) ^ sign) - sign;
490  v += 0x80;
491  }
492  *b->cur_dec++ = v;
493  }
494  }
495  return 0;
496 }
497 
498 /** number of bits used to store first DC value in bundle */
499 #define DC_START_BITS 11
500 
501 static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b,
502  int start_bits, int has_sign)
503 {
504  int i, j, len, len2, bsize, sign, v, v2;
505  int16_t *dst = (int16_t*)b->cur_dec;
506  int16_t *dst_end = (int16_t*)b->data_end;
507 
508  CHECK_READ_VAL(gb, b, len);
509  if (get_bits_left(gb) < start_bits - has_sign)
510  return AVERROR_INVALIDDATA;
511  v = get_bits(gb, start_bits - has_sign);
512  if (v && has_sign) {
513  sign = -get_bits1(gb);
514  v = (v ^ sign) - sign;
515  }
516  if (dst_end - dst < 1)
517  return AVERROR_INVALIDDATA;
518  *dst++ = v;
519  len--;
520  for (i = 0; i < len; i += 8) {
521  len2 = FFMIN(len - i, 8);
522  if (dst_end - dst < len2)
523  return AVERROR_INVALIDDATA;
524  bsize = get_bits(gb, 4);
525  if (bsize) {
526  for (j = 0; j < len2; j++) {
527  v2 = get_bits(gb, bsize);
528  if (v2) {
529  sign = -get_bits1(gb);
530  v2 = (v2 ^ sign) - sign;
531  }
532  v += v2;
533  *dst++ = v;
534  if (v < -32768 || v > 32767) {
535  av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v);
536  return AVERROR_INVALIDDATA;
537  }
538  }
539  } else {
540  for (j = 0; j < len2; j++)
541  *dst++ = v;
542  }
543  }
544 
545  b->cur_dec = (uint8_t*)dst;
546  return 0;
547 }
548 
549 /**
550  * Retrieve next value from bundle.
551  *
552  * @param c decoder context
553  * @param bundle bundle number
554  */
555 static inline int get_value(BinkContext *c, int bundle)
556 {
557  int ret;
558 
559  if (bundle < BINK_SRC_X_OFF || bundle == BINK_SRC_RUN)
560  return *c->bundle[bundle].cur_ptr++;
561  if (bundle == BINK_SRC_X_OFF || bundle == BINK_SRC_Y_OFF)
562  return (int8_t)*c->bundle[bundle].cur_ptr++;
563  ret = *(int16_t*)c->bundle[bundle].cur_ptr;
564  c->bundle[bundle].cur_ptr += 2;
565  return ret;
566 }
567 
568 static av_cold void binkb_init_bundle(BinkContext *c, int bundle_num)
569 {
570  c->bundle[bundle_num].cur_dec =
571  c->bundle[bundle_num].cur_ptr = c->bundle[bundle_num].data;
572  c->bundle[bundle_num].len = 13;
573 }
574 
576 {
577  int i;
578  for (i = 0; i < BINKB_NB_SRC; i++)
579  binkb_init_bundle(c, i);
580 }
581 
582 static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num)
583 {
584  const int bits = binkb_bundle_sizes[bundle_num];
585  const int mask = 1 << (bits - 1);
586  const int issigned = binkb_bundle_signed[bundle_num];
587  Bundle *b = &c->bundle[bundle_num];
588  int i, len;
589 
590  CHECK_READ_VAL(gb, b, len);
591  if (b->data_end - b->cur_dec < len * (1 + (bits > 8)))
592  return AVERROR_INVALIDDATA;
593  if (bits <= 8) {
594  if (!issigned) {
595  for (i = 0; i < len; i++)
596  *b->cur_dec++ = get_bits(gb, bits);
597  } else {
598  for (i = 0; i < len; i++)
599  *b->cur_dec++ = get_bits(gb, bits) - mask;
600  }
601  } else {
602  int16_t *dst = (int16_t*)b->cur_dec;
603 
604  if (!issigned) {
605  for (i = 0; i < len; i++)
606  *dst++ = get_bits(gb, bits);
607  } else {
608  for (i = 0; i < len; i++)
609  *dst++ = get_bits(gb, bits) - mask;
610  }
611  b->cur_dec = (uint8_t*)dst;
612  }
613  return 0;
614 }
615 
616 static inline int binkb_get_value(BinkContext *c, int bundle_num)
617 {
618  int16_t ret;
619  const int bits = binkb_bundle_sizes[bundle_num];
620 
621  if (bits <= 8) {
622  int val = *c->bundle[bundle_num].cur_ptr++;
623  return binkb_bundle_signed[bundle_num] ? (int8_t)val : val;
624  }
625  ret = *(int16_t*)c->bundle[bundle_num].cur_ptr;
626  c->bundle[bundle_num].cur_ptr += 2;
627  return ret;
628 }
629 
630 /**
631  * Read 8x8 block of DCT coefficients.
632  *
633  * @param gb context for reading bits
634  * @param block place for storing coefficients
635  * @param scan scan order table
636  * @param quant_matrices quantization matrices
637  * @return 0 for success, negative value in other cases
638  */
640  const uint8_t *scan, int *coef_count_,
641  int coef_idx[64], int q)
642 {
643  int coef_list[128];
644  int mode_list[128];
645  int i, t, bits, ccoef, mode, sign;
646  int list_start = 64, list_end = 64, list_pos;
647  int coef_count = 0;
648  int quant_idx;
649 
650  if (get_bits_left(gb) < 4)
651  return AVERROR_INVALIDDATA;
652 
653  coef_list[list_end] = 4; mode_list[list_end++] = 0;
654  coef_list[list_end] = 24; mode_list[list_end++] = 0;
655  coef_list[list_end] = 44; mode_list[list_end++] = 0;
656  coef_list[list_end] = 1; mode_list[list_end++] = 3;
657  coef_list[list_end] = 2; mode_list[list_end++] = 3;
658  coef_list[list_end] = 3; mode_list[list_end++] = 3;
659 
660  for (bits = get_bits(gb, 4) - 1; bits >= 0; bits--) {
661  list_pos = list_start;
662  while (list_pos < list_end) {
663  if (!(mode_list[list_pos] | coef_list[list_pos]) || !get_bits1(gb)) {
664  list_pos++;
665  continue;
666  }
667  ccoef = coef_list[list_pos];
668  mode = mode_list[list_pos];
669  switch (mode) {
670  case 0:
671  coef_list[list_pos] = ccoef + 4;
672  mode_list[list_pos] = 1;
673  case 2:
674  if (mode == 2) {
675  coef_list[list_pos] = 0;
676  mode_list[list_pos++] = 0;
677  }
678  for (i = 0; i < 4; i++, ccoef++) {
679  if (get_bits1(gb)) {
680  coef_list[--list_start] = ccoef;
681  mode_list[ list_start] = 3;
682  } else {
683  if (!bits) {
684  t = 1 - (get_bits1(gb) << 1);
685  } else {
686  t = get_bits(gb, bits) | 1 << bits;
687  sign = -get_bits1(gb);
688  t = (t ^ sign) - sign;
689  }
690  block[scan[ccoef]] = t;
691  coef_idx[coef_count++] = ccoef;
692  }
693  }
694  break;
695  case 1:
696  mode_list[list_pos] = 2;
697  for (i = 0; i < 3; i++) {
698  ccoef += 4;
699  coef_list[list_end] = ccoef;
700  mode_list[list_end++] = 2;
701  }
702  break;
703  case 3:
704  if (!bits) {
705  t = 1 - (get_bits1(gb) << 1);
706  } else {
707  t = get_bits(gb, bits) | 1 << bits;
708  sign = -get_bits1(gb);
709  t = (t ^ sign) - sign;
710  }
711  block[scan[ccoef]] = t;
712  coef_idx[coef_count++] = ccoef;
713  coef_list[list_pos] = 0;
714  mode_list[list_pos++] = 0;
715  break;
716  }
717  }
718  }
719 
720  if (q == -1) {
721  quant_idx = get_bits(gb, 4);
722  } else {
723  quant_idx = q;
724  if (quant_idx > 15U) {
725  av_log(c->avctx, AV_LOG_ERROR, "quant_index %d out of range\n", quant_idx);
726  return AVERROR_INVALIDDATA;
727  }
728  }
729 
730  *coef_count_ = coef_count;
731 
732  return quant_idx;
733 }
734 
735 static void unquantize_dct_coeffs(int32_t block[64], const uint32_t quant[64],
736  int coef_count, int coef_idx[64],
737  const uint8_t *scan)
738 {
739  int i;
740  block[0] = (int)(block[0] * quant[0]) >> 11;
741  for (i = 0; i < coef_count; i++) {
742  int idx = coef_idx[i];
743  block[scan[idx]] = (int)(block[scan[idx]] * quant[idx]) >> 11;
744  }
745 }
746 
747 /**
748  * Read 8x8 block with residue after motion compensation.
749  *
750  * @param gb context for reading bits
751  * @param block place to store read data
752  * @param masks_count number of masks to decode
753  * @return 0 on success, negative value in other cases
754  */
755 static int read_residue(GetBitContext *gb, int16_t block[64], int masks_count)
756 {
757  int coef_list[128];
758  int mode_list[128];
759  int i, sign, mask, ccoef, mode;
760  int list_start = 64, list_end = 64, list_pos;
761  int nz_coeff[64];
762  int nz_coeff_count = 0;
763 
764  coef_list[list_end] = 4; mode_list[list_end++] = 0;
765  coef_list[list_end] = 24; mode_list[list_end++] = 0;
766  coef_list[list_end] = 44; mode_list[list_end++] = 0;
767  coef_list[list_end] = 0; mode_list[list_end++] = 2;
768 
769  for (mask = 1 << get_bits(gb, 3); mask; mask >>= 1) {
770  for (i = 0; i < nz_coeff_count; i++) {
771  if (!get_bits1(gb))
772  continue;
773  if (block[nz_coeff[i]] < 0)
774  block[nz_coeff[i]] -= mask;
775  else
776  block[nz_coeff[i]] += mask;
777  masks_count--;
778  if (masks_count < 0)
779  return 0;
780  }
781  list_pos = list_start;
782  while (list_pos < list_end) {
783  if (!(coef_list[list_pos] | mode_list[list_pos]) || !get_bits1(gb)) {
784  list_pos++;
785  continue;
786  }
787  ccoef = coef_list[list_pos];
788  mode = mode_list[list_pos];
789  switch (mode) {
790  case 0:
791  coef_list[list_pos] = ccoef + 4;
792  mode_list[list_pos] = 1;
793  case 2:
794  if (mode == 2) {
795  coef_list[list_pos] = 0;
796  mode_list[list_pos++] = 0;
797  }
798  for (i = 0; i < 4; i++, ccoef++) {
799  if (get_bits1(gb)) {
800  coef_list[--list_start] = ccoef;
801  mode_list[ list_start] = 3;
802  } else {
803  nz_coeff[nz_coeff_count++] = bink_scan[ccoef];
804  sign = -get_bits1(gb);
805  block[bink_scan[ccoef]] = (mask ^ sign) - sign;
806  masks_count--;
807  if (masks_count < 0)
808  return 0;
809  }
810  }
811  break;
812  case 1:
813  mode_list[list_pos] = 2;
814  for (i = 0; i < 3; i++) {
815  ccoef += 4;
816  coef_list[list_end] = ccoef;
817  mode_list[list_end++] = 2;
818  }
819  break;
820  case 3:
821  nz_coeff[nz_coeff_count++] = bink_scan[ccoef];
822  sign = -get_bits1(gb);
823  block[bink_scan[ccoef]] = (mask ^ sign) - sign;
824  coef_list[list_pos] = 0;
825  mode_list[list_pos++] = 0;
826  masks_count--;
827  if (masks_count < 0)
828  return 0;
829  break;
830  }
831  }
832  }
833 
834  return 0;
835 }
836 
837 /**
838  * Copy 8x8 block from source to destination, where src and dst may be overlapped
839  */
840 static inline void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stride)
841 {
842  uint8_t tmp[64];
843  int i;
844  for (i = 0; i < 8; i++)
845  memcpy(tmp + i*8, src + i*stride, 8);
846  for (i = 0; i < 8; i++)
847  memcpy(dst + i*stride, tmp + i*8, 8);
848 }
849 
851  int plane_idx, int is_key, int is_chroma)
852 {
853  int blk, ret;
854  int i, j, bx, by;
855  uint8_t *dst, *ref, *ref_start, *ref_end;
856  int v, col[2];
857  const uint8_t *scan;
858  int xoff, yoff;
859  LOCAL_ALIGNED_32(int16_t, block, [64]);
860  LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
861  int coordmap[64];
862  int ybias = is_key ? -15 : 0;
863  int qp, quant_idx, coef_count, coef_idx[64];
864 
865  const int stride = frame->linesize[plane_idx];
866  int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3;
867  int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;
868 
870  ref_start = frame->data[plane_idx];
871  ref_end = frame->data[plane_idx] + (bh * frame->linesize[plane_idx] + bw) * 8;
872 
873  for (i = 0; i < 64; i++)
874  coordmap[i] = (i & 7) + (i >> 3) * stride;
875 
876  for (by = 0; by < bh; by++) {
877  for (i = 0; i < BINKB_NB_SRC; i++) {
878  if ((ret = binkb_read_bundle(c, gb, i)) < 0)
879  return ret;
880  }
881 
882  dst = frame->data[plane_idx] + 8*by*stride;
883  for (bx = 0; bx < bw; bx++, dst += 8) {
885  switch (blk) {
886  case 0:
887  break;
888  case 1:
889  scan = bink_patterns[get_bits(gb, 4)];
890  i = 0;
891  do {
892  int mode, run;
893 
894  mode = get_bits1(gb);
895  run = get_bits(gb, binkb_runbits[i]) + 1;
896 
897  i += run;
898  if (i > 64) {
899  av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
900  return AVERROR_INVALIDDATA;
901  }
902  if (mode) {
904  for (j = 0; j < run; j++)
905  dst[coordmap[*scan++]] = v;
906  } else {
907  for (j = 0; j < run; j++)
908  dst[coordmap[*scan++]] = binkb_get_value(c, BINKB_SRC_COLORS);
909  }
910  } while (i < 63);
911  if (i == 63)
912  dst[coordmap[*scan++]] = binkb_get_value(c, BINKB_SRC_COLORS);
913  break;
914  case 2:
915  memset(dctblock, 0, sizeof(*dctblock) * 64);
916  dctblock[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC);
918  if ((quant_idx = read_dct_coeffs(c, gb, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
919  return quant_idx;
920  unquantize_dct_coeffs(dctblock, binkb_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
921  c->binkdsp.idct_put(dst, stride, dctblock);
922  break;
923  case 3:
924  xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
925  yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias;
926  ref = dst + xoff + yoff * stride;
927  if (ref < ref_start || ref + 8*stride > ref_end) {
928  av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
929  } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
930  c->put_pixels_tab(dst, ref, stride, 8);
931  } else {
932  put_pixels8x8_overlapped(dst, ref, stride);
933  }
934  c->bdsp.clear_block(block);
936  read_residue(gb, block, v);
937  c->binkdsp.add_pixels8(dst, block, stride);
938  break;
939  case 4:
940  xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
941  yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias;
942  ref = dst + xoff + yoff * stride;
943  if (ref < ref_start || ref + 8 * stride > ref_end) {
944  av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
945  } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
946  c->put_pixels_tab(dst, ref, stride, 8);
947  } else {
948  put_pixels8x8_overlapped(dst, ref, stride);
949  }
950  memset(dctblock, 0, sizeof(*dctblock) * 64);
951  dctblock[0] = binkb_get_value(c, BINKB_SRC_INTER_DC);
953  if ((quant_idx = read_dct_coeffs(c, gb, dctblock, bink_scan, &coef_count, coef_idx, qp)) < 0)
954  return quant_idx;
955  unquantize_dct_coeffs(dctblock, binkb_inter_quant[quant_idx], coef_count, coef_idx, bink_scan);
956  c->binkdsp.idct_add(dst, stride, dctblock);
957  break;
958  case 5:
960  c->bdsp.fill_block_tab[1](dst, v, stride, 8);
961  break;
962  case 6:
963  for (i = 0; i < 2; i++)
964  col[i] = binkb_get_value(c, BINKB_SRC_COLORS);
965  for (i = 0; i < 8; i++) {
967  for (j = 0; j < 8; j++, v >>= 1)
968  dst[i*stride + j] = col[v & 1];
969  }
970  break;
971  case 7:
972  xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
973  yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias;
974  ref = dst + xoff + yoff * stride;
975  if (ref < ref_start || ref + 8 * stride > ref_end) {
976  av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
977  } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
978  c->put_pixels_tab(dst, ref, stride, 8);
979  } else {
980  put_pixels8x8_overlapped(dst, ref, stride);
981  }
982  break;
983  case 8:
984  for (i = 0; i < 8; i++)
985  memcpy(dst + i*stride, c->bundle[BINKB_SRC_COLORS].cur_ptr + i*8, 8);
986  c->bundle[BINKB_SRC_COLORS].cur_ptr += 64;
987  break;
988  default:
989  av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk);
990  return AVERROR_INVALIDDATA;
991  }
992  }
993  }
994  if (get_bits_count(gb) & 0x1F) //next plane data starts at 32-bit boundary
995  skip_bits_long(gb, 32 - (get_bits_count(gb) & 0x1F));
996 
997  return 0;
998 }
999 
1001  uint8_t *dst, uint8_t *prev, int stride,
1002  uint8_t *ref_start,
1003  uint8_t *ref_end)
1004 {
1005  int xoff = get_value(c, BINK_SRC_X_OFF);
1006  int yoff = get_value(c, BINK_SRC_Y_OFF);
1007  uint8_t *ref = prev + xoff + yoff * stride;
1008  if (ref < ref_start || ref > ref_end) {
1009  av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
1010  xoff, yoff);
1011  return AVERROR_INVALIDDATA;
1012  }
1013  c->put_pixels_tab(dst, ref, stride, 8);
1014 
1015  return 0;
1016 }
1017 
1019  int plane_idx, int is_chroma)
1020 {
1021  int blk, ret;
1022  int i, j, bx, by;
1023  uint8_t *dst, *prev, *ref_start, *ref_end;
1024  int v, col[2];
1025  const uint8_t *scan;
1026  LOCAL_ALIGNED_32(int16_t, block, [64]);
1027  LOCAL_ALIGNED_16(uint8_t, ublock, [64]);
1028  LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
1029  int coordmap[64], quant_idx, coef_count, coef_idx[64];
1030 
1031  const int stride = frame->linesize[plane_idx];
1032  int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3;
1033  int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;
1034  int width = c->avctx->width >> is_chroma;
1035  int height = c->avctx->height >> is_chroma;
1036 
1037  if (c->version == 'k' && get_bits1(gb)) {
1038  int fill = get_bits(gb, 8);
1039 
1040  dst = frame->data[plane_idx];
1041 
1042  for (i = 0; i < height; i++)
1043  memset(dst + i * stride, fill, width);
1044  goto end;
1045  }
1046 
1047  init_lengths(c, FFMAX(width, 8), bw);
1048  for (i = 0; i < BINK_NB_SRC; i++) {
1049  ret = read_bundle(gb, c, i);
1050  if (ret < 0)
1051  return ret;
1052  }
1053 
1054  ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx]
1055  : frame->data[plane_idx];
1056  ref_end = ref_start
1057  + (bw - 1 + c->last->linesize[plane_idx] * (bh - 1)) * 8;
1058 
1059  for (i = 0; i < 64; i++)
1060  coordmap[i] = (i & 7) + (i >> 3) * stride;
1061 
1062  for (by = 0; by < bh; by++) {
1063  if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES])) < 0)
1064  return ret;
1065  if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES])) < 0)
1066  return ret;
1067  if ((ret = read_colors(gb, &c->bundle[BINK_SRC_COLORS], c)) < 0)
1068  return ret;
1069  if ((ret = read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN])) < 0)
1070  return ret;
1071  if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF])) < 0)
1072  return ret;
1073  if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF])) < 0)
1074  return ret;
1075  if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0)) < 0)
1076  return ret;
1077  if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1)) < 0)
1078  return ret;
1079  if ((ret = read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN])) < 0)
1080  return ret;
1081 
1082  dst = frame->data[plane_idx] + 8*by*stride;
1083  prev = (c->last->data[plane_idx] ? c->last->data[plane_idx]
1084  : frame->data[plane_idx]) + 8*by*stride;
1085  for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
1086  blk = get_value(c, BINK_SRC_BLOCK_TYPES);
1087  // 16x16 block type on odd line means part of the already decoded block, so skip it
1088  if ((by & 1) && blk == SCALED_BLOCK) {
1089  bx++;
1090  dst += 8;
1091  prev += 8;
1092  continue;
1093  }
1094  switch (blk) {
1095  case SKIP_BLOCK:
1096  c->put_pixels_tab(dst, prev, stride, 8);
1097  break;
1098  case SCALED_BLOCK:
1100  switch (blk) {
1101  case RUN_BLOCK:
1102  if (get_bits_left(gb) < 4)
1103  return AVERROR_INVALIDDATA;
1104  scan = bink_patterns[get_bits(gb, 4)];
1105  i = 0;
1106  do {
1107  int run = get_value(c, BINK_SRC_RUN) + 1;
1108 
1109  i += run;
1110  if (i > 64) {
1111  av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
1112  return AVERROR_INVALIDDATA;
1113  }
1114  if (get_bits1(gb)) {
1115  v = get_value(c, BINK_SRC_COLORS);
1116  for (j = 0; j < run; j++)
1117  ublock[*scan++] = v;
1118  } else {
1119  for (j = 0; j < run; j++)
1120  ublock[*scan++] = get_value(c, BINK_SRC_COLORS);
1121  }
1122  } while (i < 63);
1123  if (i == 63)
1124  ublock[*scan++] = get_value(c, BINK_SRC_COLORS);
1125  break;
1126  case INTRA_BLOCK:
1127  memset(dctblock, 0, sizeof(*dctblock) * 64);
1128  dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
1129  if ((quant_idx = read_dct_coeffs(c, gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
1130  return quant_idx;
1131  unquantize_dct_coeffs(dctblock, bink_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
1132  c->binkdsp.idct_put(ublock, 8, dctblock);
1133  break;
1134  case FILL_BLOCK:
1135  v = get_value(c, BINK_SRC_COLORS);
1136  c->bdsp.fill_block_tab[0](dst, v, stride, 16);
1137  break;
1138  case PATTERN_BLOCK:
1139  for (i = 0; i < 2; i++)
1140  col[i] = get_value(c, BINK_SRC_COLORS);
1141  for (j = 0; j < 8; j++) {
1142  v = get_value(c, BINK_SRC_PATTERN);
1143  for (i = 0; i < 8; i++, v >>= 1)
1144  ublock[i + j*8] = col[v & 1];
1145  }
1146  break;
1147  case RAW_BLOCK:
1148  for (j = 0; j < 8; j++)
1149  for (i = 0; i < 8; i++)
1150  ublock[i + j*8] = get_value(c, BINK_SRC_COLORS);
1151  break;
1152  default:
1153  av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk);
1154  return AVERROR_INVALIDDATA;
1155  }
1156  if (blk != FILL_BLOCK)
1157  c->binkdsp.scale_block(ublock, dst, stride);
1158  bx++;
1159  dst += 8;
1160  prev += 8;
1161  break;
1162  case MOTION_BLOCK:
1163  ret = bink_put_pixels(c, dst, prev, stride,
1164  ref_start, ref_end);
1165  if (ret < 0)
1166  return ret;
1167  break;
1168  case RUN_BLOCK:
1169  scan = bink_patterns[get_bits(gb, 4)];
1170  i = 0;
1171  do {
1172  int run = get_value(c, BINK_SRC_RUN) + 1;
1173 
1174  i += run;
1175  if (i > 64) {
1176  av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
1177  return AVERROR_INVALIDDATA;
1178  }
1179  if (get_bits1(gb)) {
1180  v = get_value(c, BINK_SRC_COLORS);
1181  for (j = 0; j < run; j++)
1182  dst[coordmap[*scan++]] = v;
1183  } else {
1184  for (j = 0; j < run; j++)
1185  dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS);
1186  }
1187  } while (i < 63);
1188  if (i == 63)
1189  dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS);
1190  break;
1191  case RESIDUE_BLOCK:
1192  ret = bink_put_pixels(c, dst, prev, stride,
1193  ref_start, ref_end);
1194  if (ret < 0)
1195  return ret;
1196  c->bdsp.clear_block(block);
1197  v = get_bits(gb, 7);
1198  read_residue(gb, block, v);
1199  c->binkdsp.add_pixels8(dst, block, stride);
1200  break;
1201  case INTRA_BLOCK:
1202  memset(dctblock, 0, sizeof(*dctblock) * 64);
1203  dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
1204  if ((quant_idx = read_dct_coeffs(c, gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
1205  return quant_idx;
1206  unquantize_dct_coeffs(dctblock, bink_intra_quant[quant_idx], coef_count, coef_idx, bink_scan);
1207  c->binkdsp.idct_put(dst, stride, dctblock);
1208  break;
1209  case FILL_BLOCK:
1210  v = get_value(c, BINK_SRC_COLORS);
1211  c->bdsp.fill_block_tab[1](dst, v, stride, 8);
1212  break;
1213  case INTER_BLOCK:
1214  ret = bink_put_pixels(c, dst, prev, stride,
1215  ref_start, ref_end);
1216  if (ret < 0)
1217  return ret;
1218  memset(dctblock, 0, sizeof(*dctblock) * 64);
1219  dctblock[0] = get_value(c, BINK_SRC_INTER_DC);
1220  if ((quant_idx = read_dct_coeffs(c, gb, dctblock, bink_scan, &coef_count, coef_idx, -1)) < 0)
1221  return quant_idx;
1222  unquantize_dct_coeffs(dctblock, bink_inter_quant[quant_idx], coef_count, coef_idx, bink_scan);
1223  c->binkdsp.idct_add(dst, stride, dctblock);
1224  break;
1225  case PATTERN_BLOCK:
1226  for (i = 0; i < 2; i++)
1227  col[i] = get_value(c, BINK_SRC_COLORS);
1228  for (i = 0; i < 8; i++) {
1229  v = get_value(c, BINK_SRC_PATTERN);
1230  for (j = 0; j < 8; j++, v >>= 1)
1231  dst[i*stride + j] = col[v & 1];
1232  }
1233  break;
1234  case RAW_BLOCK:
1235  for (i = 0; i < 8; i++)
1236  memcpy(dst + i*stride, c->bundle[BINK_SRC_COLORS].cur_ptr + i*8, 8);
1237  c->bundle[BINK_SRC_COLORS].cur_ptr += 64;
1238  break;
1239  default:
1240  av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk);
1241  return AVERROR_INVALIDDATA;
1242  }
1243  }
1244  }
1245 
1246 end:
1247  if (get_bits_count(gb) & 0x1F) //next plane data starts at 32-bit boundary
1248  skip_bits_long(gb, 32 - (get_bits_count(gb) & 0x1F));
1249 
1250  return 0;
1251 }
1252 
1253 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
1254 {
1255  BinkContext * const c = avctx->priv_data;
1256  AVFrame *frame = data;
1257  GetBitContext gb;
1258  int plane, plane_idx, ret;
1259  int bits_count = pkt->size << 3;
1260 
1261  if (c->version > 'b') {
1262  if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
1263  return ret;
1264  } else {
1265  if ((ret = ff_reget_buffer(avctx, c->last, 0)) < 0)
1266  return ret;
1267  if ((ret = av_frame_ref(frame, c->last)) < 0)
1268  return ret;
1269  }
1270 
1271  init_get_bits(&gb, pkt->data, bits_count);
1272  if (c->has_alpha) {
1273  if (c->version >= 'i')
1274  skip_bits_long(&gb, 32);
1275  if ((ret = bink_decode_plane(c, frame, &gb, 3, 0)) < 0)
1276  return ret;
1277  }
1278  if (c->version >= 'i')
1279  skip_bits_long(&gb, 32);
1280 
1281  c->frame_num++;
1282 
1283  for (plane = 0; plane < 3; plane++) {
1284  plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3);
1285 
1286  if (c->version > 'b') {
1287  if ((ret = bink_decode_plane(c, frame, &gb, plane_idx, !!plane)) < 0)
1288  return ret;
1289  } else {
1290  if ((ret = binkb_decode_plane(c, frame, &gb, plane_idx,
1291  c->frame_num == 1, !!plane)) < 0)
1292  return ret;
1293  }
1294  if (get_bits_count(&gb) >= bits_count)
1295  break;
1296  }
1297  emms_c();
1298 
1299  if (c->version > 'b') {
1300  av_frame_unref(c->last);
1301  if ((ret = av_frame_ref(c->last, frame)) < 0)
1302  return ret;
1303  }
1304 
1305  *got_frame = 1;
1306 
1307  /* always report that the buffer was completely consumed */
1308  return pkt->size;
1309 }
1310 
1311 /**
1312  * Calculate quantization tables for version b
1313  */
1314 static av_cold void binkb_calc_quant(void)
1315 {
1316  uint8_t inv_bink_scan[64];
1317  static const int s[64]={
1318  1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1319  1489322693,2065749918,1945893874,1751258219,1489322693,1170153332, 806015634, 410903207,
1320  1402911301,1945893874,1832991949,1649649171,1402911301,1102260336, 759250125, 387062357,
1321  1262586814,1751258219,1649649171,1484645031,1262586814, 992008094, 683307060, 348346918,
1322  1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1323  843633538,1170153332,1102260336, 992008094, 843633538, 662838617, 456571181, 232757969,
1324  581104888, 806015634, 759250125, 683307060, 581104888, 456571181, 314491699, 160326478,
1325  296244703, 410903207, 387062357, 348346918, 296244703, 232757969, 160326478, 81733730,
1326  };
1327  int i, j;
1328 #define C (1LL<<30)
1329  for (i = 0; i < 64; i++)
1330  inv_bink_scan[bink_scan[i]] = i;
1331 
1332  for (j = 0; j < 16; j++) {
1333  for (i = 0; i < 64; i++) {
1334  int k = inv_bink_scan[i];
1335  binkb_intra_quant[j][k] = binkb_intra_seed[i] * (int64_t)s[i] *
1336  binkb_num[j]/(binkb_den[j] * (C>>12));
1337  binkb_inter_quant[j][k] = binkb_inter_seed[i] * (int64_t)s[i] *
1338  binkb_num[j]/(binkb_den[j] * (C>>12));
1339  }
1340  }
1341 }
1342 
1344 {
1345  BinkContext * const c = avctx->priv_data;
1346  static VLC_TYPE table[16 * 128][2];
1347  static int binkb_initialised = 0;
1348  HpelDSPContext hdsp;
1349  int i, ret;
1350  int flags;
1351 
1352  c->version = avctx->codec_tag >> 24;
1353  if (avctx->extradata_size < 4) {
1354  av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n");
1355  return AVERROR_INVALIDDATA;
1356  }
1357  flags = AV_RL32(avctx->extradata);
1358  c->has_alpha = flags & BINK_FLAG_ALPHA;
1359  c->swap_planes = c->version >= 'h';
1360  if (!bink_trees[15].table) {
1361  for (i = 0; i < 16; i++) {
1362  const int maxbits = bink_tree_lens[i][15];
1363  bink_trees[i].table = table + i*128;
1364  bink_trees[i].table_allocated = 1 << maxbits;
1365  init_vlc(&bink_trees[i], maxbits, 16,
1366  bink_tree_lens[i], 1, 1,
1368  }
1369  }
1370  c->avctx = avctx;
1371 
1372  if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
1373  return ret;
1374 
1375  c->last = av_frame_alloc();
1376  if (!c->last)
1377  return AVERROR(ENOMEM);
1378 
1380  avctx->color_range = c->version == 'k' ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
1381 
1382  ff_blockdsp_init(&c->bdsp, avctx);
1383  ff_hpeldsp_init(&hdsp, avctx->flags);
1384  c->put_pixels_tab = hdsp.put_pixels_tab[1][0];
1385  ff_binkdsp_init(&c->binkdsp);
1386 
1387  if ((ret = init_bundles(c)) < 0)
1388  return ret;
1389 
1390  if (c->version == 'b') {
1391  if (!binkb_initialised) {
1392  binkb_calc_quant();
1393  binkb_initialised = 1;
1394  }
1395  }
1396 
1397  return 0;
1398 }
1399 
1401 {
1402  BinkContext * const c = avctx->priv_data;
1403 
1404  av_frame_free(&c->last);
1405 
1406  free_bundles(c);
1407  return 0;
1408 }
1409 
1410 static void flush(AVCodecContext *avctx)
1411 {
1412  BinkContext * const c = avctx->priv_data;
1413 
1414  c->frame_num = 0;
1415 }
1416 
1418  .name = "binkvideo",
1419  .long_name = NULL_IF_CONFIG_SMALL("Bink video"),
1420  .type = AVMEDIA_TYPE_VIDEO,
1421  .id = AV_CODEC_ID_BINKVIDEO,
1422  .priv_data_size = sizeof(BinkContext),
1423  .init = decode_init,
1424  .close = decode_end,
1425  .decode = decode_frame,
1426  .flush = flush,
1427  .capabilities = AV_CODEC_CAP_DR1,
1428  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1429 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define NULL
Definition: coverity.c:32
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static const uint8_t bink_tree_lens[16][16]
Definition: binkdata.h:106
8-bit values for 2-colour pattern fill
Definition: bink.c:48
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
av_cold void ff_binkdsp_init(BinkDSPContext *c)
Definition: binkdsp.c:153
static const uint8_t bink_tree_bits[16][16]
Definition: binkdata.h:39
#define C
#define CHECK_READ_VAL(gb, b, t)
common check before starting decoding bundle data
Definition: bink.c:320
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
void(* clear_block)(int16_t *block)
Definition: blockdsp.h:36
void(* scale_block)(const uint8_t src[64], uint8_t *dst, int linesize)
Definition: binkdsp.h:37
static const uint8_t binkb_den[16]
Definition: binkdata.h:651
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1161
static int read_residue(GetBitContext *gb, int16_t block[64], int masks_count)
Read 8x8 block with residue after motion compensation.
Definition: bink.c:755
int size
Definition: packet.h:364
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
Definition: blockdsp.c:60
int av_log2(unsigned v)
Definition: intmath.c:26
static void unquantize_dct_coeffs(int32_t block[64], const uint32_t quant[64], int coef_count, int coef_idx[64], const uint8_t *scan)
Definition: bink.c:735
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
8-bit values for 2-colour pattern fill
Definition: bink.c:78
static const uint8_t bink_scan[64]
Bink DCT and residue 8x8 block scan order.
Definition: binkdata.h:28
uint8_t run
Definition: svq3.c:204
static AVPacket pkt
#define blk(i)
Definition: sha.c:185
8x8 block types
Definition: bink.c:75
Tree col_high[16]
trees for decoding high nibble in "colours" data type
Definition: bink.c:126
AVCodec.
Definition: codec.h:190
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
16x16 block types (a subset of 8x8 block types)
Definition: bink.c:76
int len
length of number of entries to decode (in bits)
Definition: bink.c:103
Macro definitions for various function/variable attributes.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
static int32_t binkb_inter_quant[16][64]
Definition: bink.c:69
void(* idct_put)(uint8_t *dest, int line_size, int32_t *block)
Definition: binkdsp.h:35
quantizer values for interblocks with DCT
Definition: bink.c:54
static av_cold void binkb_init_bundle(BinkContext *c, int bundle_num)
Definition: bink.c:568
static int read_patterns(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
Definition: bink.c:434
X components of motion value.
Definition: bink.c:49
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
motion block with DCT applied to the difference
Definition: bink.c:141
The exact code depends on how similar the blocks are and how related they are to the block
uint8_t
#define av_cold
Definition: attributes.h:88
intra DCT block
Definition: bink.c:139
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
static int binkb_get_value(BinkContext *c, int bundle_num)
Definition: bink.c:616
static void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stride)
Copy 8x8 block from source to destination, where src and dst may be overlapped.
Definition: bink.c:840
Tree tree
Huffman tree-related data.
Definition: bink.c:104
BlockTypes
Bink video block types.
Definition: bink.c:133
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:456
uncoded 8x8 block
Definition: bink.c:143
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:627
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
#define height
uint8_t * data
Definition: packet.h:363
static const int32_t bink_inter_quant[16][64]
Definition: binkdata.h:451
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
int vlc_num
tree number (in bink_trees[])
Definition: bink.c:92
skipped block
Definition: bink.c:134
bitstream reader API header.
static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
Definition: bink.c:329
ptrdiff_t size
Definition: opengl_enc.c:100
data structure used for decoding single Bink data type
Definition: bink.c:102
#define FFALIGN(x, a)
Definition: macros.h:48
static const uint8_t bink_patterns[16][64]
Definition: binkdata.h:125
#define av_log(a,...)
static const uint16_t table[]
Definition: prosumer.c:206
uint8_t * data
buffer for decoded symbols
Definition: bink.c:105
Bink DSP routines.
#define U(x)
Definition: vp56_arith.h:37
#define src
Definition: vp8dsp.c:254
block is copied from previous frame with some offset
Definition: bink.c:136
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
uint8_t * data_end
buffer end
Definition: bink.c:106
static const uint16_t mask[17]
Definition: lzw.c:38
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: vlc.h:38
unsigned frame_num
Definition: bink.c:123
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available...
Definition: decode.c:1978
AVCodecContext * avctx
Definition: bink.c:115
static av_cold void free_bundles(BinkContext *c)
Free memory used by bundles.
Definition: bink.c:205
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:606
AVCodec ff_bink_decoder
Definition: bink.c:1417
const char * name
Name of the codec implementation.
Definition: codec.h:197
uint8_t bits
Definition: vp3data.h:202
int col_lastval
value of last decoded high nibble in "colours" data type
Definition: bink.c:127
#define FFMAX(a, b)
Definition: common.h:94
BinkDSPContext binkdsp
Definition: bink.c:118
DC values for interblocks with DCT.
Definition: bink.c:82
Definition: vlc.h:26
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
Definition: hpeldsp.c:338
block is composed from runs of colours with custom scan order
Definition: bink.c:137
common internal API header
block is filled with single colour
Definition: bink.c:140
static av_cold void binkb_calc_quant(void)
Calculate quantization tables for version b.
Definition: bink.c:1314
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:317
Half-pel DSP context.
Definition: hpeldsp.h:45
#define b
Definition: input.c:41
#define FFMIN(a, b)
Definition: common.h:96
#define width
int width
picture width / height.
Definition: avcodec.h:699
static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb, int plane_idx, int is_key, int is_chroma)
Definition: bink.c:850
Y components of motion value.
Definition: bink.c:50
void(* idct_add)(uint8_t *dest, int line_size, int32_t *block)
Definition: binkdsp.h:36
number of coefficients for residue blocks
Definition: bink.c:55
int32_t
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define s(width, name)
Definition: cbs_vp9.c:257
int has_alpha
Definition: bink.c:121
block has size 16x16
Definition: bink.c:135
static const uint8_t binkb_inter_seed[64]
Definition: binkdata.h:636
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:538
#define INIT_VLC_LE
Definition: vlc.h:54
int swap_planes
Definition: bink.c:122
if(ret)
static const uint8_t binkb_runbits[64]
Definition: binkdata.h:614
static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb, int plane_idx, int is_chroma)
Definition: bink.c:1018
int table_allocated
Definition: vlc.h:29
data needed to decode 4-bit Huffman-coded value
Definition: bink.c:91
uint8_t * cur_dec
pointer to the not yet decoded part of the buffer
Definition: bink.c:107
Half-pel DSP functions.
Libavcodec external API header.
quantizer values for intrablocks with DCT
Definition: bink.c:53
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:339
void(* add_pixels8)(uint8_t *av_restrict pixels, int16_t *block, int line_size)
Definition: binkdsp.h:38
#define DC_START_BITS
number of bits used to store first DC value in bundle
Definition: bink.c:499
main external API structure.
Definition: avcodec.h:526
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Definition: hpeldsp.h:38
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
Definition: avcodec.h:551
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1872
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
Definition: hpeldsp.h:56
static av_cold int decode_init(AVCodecContext *avctx)
Definition: bink.c:1343
int extradata_size
Definition: avcodec.h:628
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static const int32_t bink_intra_quant[16][64]
Definition: binkdata.h:288
DC values for interblocks with DCT.
Definition: bink.c:52
Sources
IDs for different data types used in Bink video codec.
Definition: bink.c:74
block is filled with two colours following custom pattern
Definition: bink.c:142
static av_cold void binkb_init_bundles(BinkContext *c)
Definition: bink.c:575
static int32_t binkb_intra_quant[16][64]
Definition: bink.c:68
static int read_dct_coeffs(BinkContext *c, GetBitContext *gb, int32_t block[64], const uint8_t *scan, int *coef_count_, int coef_idx[64], int q)
Read 8x8 block of DCT coefficients.
Definition: bink.c:639
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
8x8 block types
Definition: bink.c:46
static const uint8_t binkb_num[16]
Definition: binkdata.h:647
#define GET_HUFF(gb, tree)
Definition: bink.c:96
run lengths for special fill block
Definition: bink.c:83
Y components of motion value.
Definition: bink.c:80
static VLC bink_trees[16]
Definition: bink.c:40
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
Definition: bink.c:218
static int read_bundle(GetBitContext *gb, BinkContext *c, int bundle_num)
Prepare bundle for decoding data.
Definition: bink.c:290
const uint8_t * quant
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:566
Bundle bundle[BINKB_NB_SRC]
bundles for decoding all data types
Definition: bink.c:125
#define flags(name, subs,...)
Definition: cbs_av1.c:560
static void flush(AVCodecContext *avctx)
Definition: bink.c:1410
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:322
pixel values used for different block types
Definition: bink.c:77
AVFrame * last
Definition: bink.c:119
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:537
X components of motion value.
Definition: bink.c:79
#define LOCAL_ALIGNED_32(t, v,...)
Definition: internal.h:137
uint8_t * cur_ptr
pointer to the data that is not read from buffer yet
Definition: bink.c:108
#define BINK_FLAG_ALPHA
Definition: bink.c:37
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
int
static const uint8_t binkb_intra_seed[64]
Definition: binkdata.h:625
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num)
Definition: bink.c:582
common internal api header.
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
static void init_lengths(BinkContext *c, int width, int bw)
Initialize length in all bundles.
Definition: bink.c:153
static av_cold int init_bundles(BinkContext *c)
Allocate memory for bundles.
Definition: bink.c:178
#define INIT_VLC_USE_NEW_STATIC
Definition: vlc.h:55
static int read_colors(GetBitContext *gb, Bundle *b, BinkContext *c)
Definition: bink.c:456
static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
Definition: bink.c:389
uint8_t syms[16]
leaf value to symbol mapping
Definition: bink.c:93
static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, int start_bits, int has_sign)
Definition: bink.c:501
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
Definition: bink.c:1253
DC values for intrablocks with DCT.
Definition: bink.c:51
void * priv_data
Definition: avcodec.h:553
static int read_tree(GetBitContext *gb, Tree *tree)
Read information about Huffman tree used to decode data.
Definition: bink.c:245
static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
Definition: bink.c:353
motion block with some difference added
Definition: bink.c:138
int len
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
static int bink_put_pixels(BinkContext *c, uint8_t *dst, uint8_t *prev, int stride, uint8_t *ref_start, uint8_t *ref_end)
Definition: bink.c:1000
static const int binkb_bundle_sizes[BINKB_NB_SRC]
Definition: bink.c:60
int version
internal Bink file version
Definition: bink.c:120
static const int binkb_bundle_signed[BINKB_NB_SRC]
Definition: bink.c:64
static av_cold int decode_end(AVCodecContext *avctx)
Definition: bink.c:1400
FILE * out
Definition: movenc.c:54
BlockDSPContext bdsp
Definition: bink.c:116
#define LOCAL_ALIGNED_16(t, v,...)
Definition: internal.h:131
#define av_freep(p)
op_pixels_func put_pixels_tab
Definition: bink.c:117
#define VLC_TYPE
Definition: vlc.h:24
#define FFSWAP(type, a, b)
Definition: common.h:99
static const uint8_t bink_rlelens[4]
Definition: bink.c:387
#define stride
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
pixel values used for different block types
Definition: bink.c:47
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
static int get_value(BinkContext *c, int bundle)
Retrieve next value from bundle.
Definition: bink.c:555
static double val(void *priv, double ch)
Definition: aeval.c:76
This structure stores compressed data.
Definition: packet.h:340
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:509
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
DC values for intrablocks with DCT.
Definition: bink.c:81
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
OldSources
IDs for different data types used in old version of Bink video codec.
Definition: bink.c:45
int i
Definition: input.c:407
op_fill_func fill_block_tab[2]
Definition: blockdsp.h:39
static uint8_t tmp[11]
Definition: aes_ctr.c:26