FFmpeg
Loading...
Searching...
No Matches
vp3.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2003-2004 The FFmpeg project
3 * Copyright (C) 2019 Peter Ross
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * On2 VP3/VP4 Video Decoder
25 *
26 * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
27 * For more information about the VP3 coding process, visit:
28 * http://wiki.multimedia.cx/index.php?title=On2_VP3
29 *
30 * Theora decoder by Alex Beregszaszi
31 */
32
33#include "config_components.h"
34
35#include <stddef.h>
36#include <string.h>
37
39#include "libavutil/imgutils.h"
40#include "libavutil/mem.h"
42#include "libavutil/thread.h"
43
44#include "avcodec.h"
45#include "codec_internal.h"
46#include "decode.h"
47#include "get_bits.h"
48#include "hpeldsp.h"
49#include "jpegquanttables.h"
50#include "mathops.h"
51#include "progressframe.h"
52#include "libavutil/refstruct.h"
53#include "thread.h"
54#include "videodsp.h"
55#include "vp3data.h"
56#include "vp4data.h"
57#include "vp3dsp.h"
58#include "xiph.h"
59
60#define VP3_MV_VLC_BITS 6
61#define VP4_MV_VLC_BITS 6
62#define SUPERBLOCK_VLC_BITS 6
63
64#define FRAGMENT_PIXELS 8
65
66// FIXME split things out into their own arrays
67typedef struct Vp3Fragment {
68 int16_t dc;
70 uint8_t qpi;
72
73#define SB_NOT_CODED 0
74#define SB_PARTIALLY_CODED 1
75#define SB_FULLY_CODED 2
76
77// This is the maximum length of a single long bit run that can be encoded
78// for superblock coding or block qps. Theora special-cases this to read a
79// bit instead of flipping the current bit to allow for runs longer than 4129.
80#define MAXIMUM_LONG_BIT_RUN 4129
81
82#define MODE_INTER_NO_MV 0
83#define MODE_INTRA 1
84#define MODE_INTER_PLUS_MV 2
85#define MODE_INTER_LAST_MV 3
86#define MODE_INTER_PRIOR_LAST 4
87#define MODE_USING_GOLDEN 5
88#define MODE_GOLDEN_MV 6
89#define MODE_INTER_FOURMV 7
90#define CODING_MODE_COUNT 8
91
92/* special internal mode */
93#define MODE_COPY 8
94
97
98
99/* There are 6 preset schemes, plus a free-form scheme */
137
138static const uint8_t hilbert_offset[16][2] = {
139 { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
140 { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
141 { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
142 { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
143};
144
145enum {
151};
152
163
164static VLCElem superblock_run_length_vlc[88]; /* version < 2 */
165static VLCElem fragment_run_length_vlc[56]; /* version < 2 */
166static VLCElem motion_vector_vlc[112]; /* version < 2 */
167
168// The VP4 tables reuse this vlc.
169static VLCElem mode_code_vlc[24 + 2108 * CONFIG_VP4_DECODER];
170
171#if CONFIG_VP4_DECODER
172static const VLCElem *vp4_mv_vlc_table[2][7]; /* version >= 2 */
173static const VLCElem *block_pattern_vlc[2]; /* version >= 2 */
174#endif
175
176typedef struct {
177 int dc;
178 int type;
180
181#define MIN_DEQUANT_VAL 2
182
183typedef struct HuffEntry {
184 uint8_t len, sym;
185} HuffEntry;
186
187typedef struct HuffTable {
189 uint8_t nb_entries;
190} HuffTable;
191
192typedef struct CoeffVLCs {
193 const VLCElem *vlc_tabs[80];
195} CoeffVLCs;
196
197typedef struct Vp3DecodeContext {
207 uint8_t idct_permutation[64];
208 uint8_t idct_scantable[64];
212 DECLARE_ALIGNED(16, int16_t, block)[64];
216
217 int qps[3];
218 int nqps;
219
229 unsigned char *superblock_coding;
230
231 int macroblock_count; /* y macroblock count */
237 int yuv_macroblock_count; /* y+u+v macroblock count */
238
242
246 uint8_t offset_x;
247 uint8_t offset_y;
249
250 int8_t (*motion_val[2])[2];
251
252 /* tables */
253 uint16_t coded_dc_scale_factor[2][64];
255 uint8_t base_matrix[384][64];
256 uint8_t qr_count[2][3];
257 uint8_t qr_size[2][3][64];
258 uint16_t qr_base[2][3][64];
259
260 /**
261 * This is a list of all tokens in bitstream order. Reordering takes place
262 * by pulling from each level during IDCT. As a consequence, IDCT must be
263 * in Hilbert order, making the minimum slice height 64 for 4:2:0 and 32
264 * otherwise. The 32 different tokens with up to 12 bits of extradata are
265 * collapsed into 3 types, packed as follows:
266 * (from the low to high bits)
267 *
268 * 2 bits: type (0,1,2)
269 * 0: EOB run, 14 bits for run length (12 needed)
270 * 1: zero run, 7 bits for run length
271 * 7 bits for the next coefficient (3 needed)
272 * 2: coefficient, 14 bits (11 needed)
273 *
274 * Coefficients are signed, so are packed in the highest bits for automatic
275 * sign extension.
276 */
277 int16_t *dct_tokens[3][64];
279#define TOKEN_EOB(eob_run) ((eob_run) << 2)
280#define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
281#define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
282
283 /**
284 * number of blocks that contain DCT coefficients at
285 * the given level or higher
286 */
287 int num_coded_frags[3][64];
289
290 /* this is a list of indexes into the all_fragments array indicating
291 * which of the fragments are coded */
293
297
298 /**
299 * The first 16 of the following VLCs are for the dc coefficients;
300 * the others are four groups of 16 VLCs each for ac coefficients.
301 * This is a RefStruct reference to share these VLCs between threads.
302 */
304
305 /* these arrays need to be on 16-byte boundaries since SSE2 operations
306 * index into them */
307 DECLARE_ALIGNED(16, int16_t, qmat)[3][2][3][64]; ///< qmat[qpi][is_inter][plane]
308
309 /* This table contains superblock_count * 16 entries. Each set of 16
310 * numbers corresponds to the fragment indexes 0..15 of the superblock.
311 * An entry will be -1 to indicate that no entry corresponds to that
312 * index. */
314
315 /* This is an array that indicates how a particular macroblock
316 * is coded. */
317 unsigned char *macroblock_coding;
318
320
321 /* Huffman decode */
323
326
327 VP4Predictor * dc_pred_row; /* dc_pred_row[y_superblock_width * 4] */
329
330/************************************************************************
331 * VP3 specific functions
332 ************************************************************************/
333
335{
336 Vp3DecodeContext *s = avctx->priv_data;
337
338 av_freep(&s->superblock_coding);
339 av_freep(&s->all_fragments);
340 av_freep(&s->nkf_coded_fragment_list);
341 av_freep(&s->kf_coded_fragment_list);
342 av_freep(&s->dct_tokens_base);
343 av_freep(&s->superblock_fragments);
344 av_freep(&s->macroblock_coding);
345 av_freep(&s->dc_pred_row);
346 av_freep(&s->motion_val[0]);
347 av_freep(&s->motion_val[1]);
348}
349
351{
352 Vp3DecodeContext *s = avctx->priv_data;
353
354 ff_progress_frame_unref(&s->golden_frame);
355 ff_progress_frame_unref(&s->last_frame);
356 ff_progress_frame_unref(&s->current_frame);
357}
358
360{
361 Vp3DecodeContext *s = avctx->priv_data;
362
363 free_tables(avctx);
364 av_freep(&s->edge_emu_buffer);
365
366 s->theora_tables = 0;
367
368 /* release all frames */
369 vp3_decode_flush(avctx);
370
371 av_refstruct_unref(&s->coeff_vlc);
372
373 return 0;
374}
375
376/**
377 * This function sets up all of the various blocks mappings:
378 * superblocks <-> fragments, macroblocks <-> fragments,
379 * superblocks <-> macroblocks
380 *
381 * @return 0 is successful; returns 1 if *anything* went wrong.
382 */
384{
385 int j = 0;
386
387 for (int plane = 0; plane < 3; plane++) {
388 int sb_width = plane ? s->c_superblock_width
389 : s->y_superblock_width;
390 int sb_height = plane ? s->c_superblock_height
391 : s->y_superblock_height;
392 int frag_width = s->fragment_width[!!plane];
393 int frag_height = s->fragment_height[!!plane];
394
395 for (int sb_y = 0; sb_y < sb_height; sb_y++)
396 for (int sb_x = 0; sb_x < sb_width; sb_x++)
397 for (int i = 0; i < 16; i++) {
398 int x = 4 * sb_x + hilbert_offset[i][0];
399 int y = 4 * sb_y + hilbert_offset[i][1];
400
401 if (x < frag_width && y < frag_height)
402 s->superblock_fragments[j++] = s->fragment_start[plane] +
403 y * frag_width + x;
404 else
405 s->superblock_fragments[j++] = -1;
406 }
407 }
408
409 return 0; /* successful path out */
410}
411
412/*
413 * This function sets up the dequantization tables used for a particular
414 * frame.
415 */
416static void init_dequantizer(Vp3DecodeContext *s, int qpi)
417{
418 int ac_scale_factor = s->coded_ac_scale_factor[s->qps[qpi]];
419
420 for (int inter = 0; inter < 2; inter++) {
421 for (int plane = 0; plane < 3; plane++) {
422 int dc_scale_factor = s->coded_dc_scale_factor[!!plane][s->qps[qpi]];
423 int sum = 0, bmi, bmj, qistart, qri;
424 for (qri = 0; qri < s->qr_count[inter][plane]; qri++) {
425 sum += s->qr_size[inter][plane][qri];
426 if (s->qps[qpi] <= sum)
427 break;
428 }
429 qistart = sum - s->qr_size[inter][plane][qri];
430 bmi = s->qr_base[inter][plane][qri];
431 bmj = s->qr_base[inter][plane][qri + 1];
432 for (int i = 0; i < 64; i++) {
433 int coeff = (2 * (sum - s->qps[qpi]) * s->base_matrix[bmi][i] -
434 2 * (qistart - s->qps[qpi]) * s->base_matrix[bmj][i] +
435 s->qr_size[inter][plane][qri]) /
436 (2 * s->qr_size[inter][plane][qri]);
437
438 int qmin = 8 << (inter + !i);
439 int qscale = i ? ac_scale_factor : dc_scale_factor;
440 int qbias = (1 + inter) * 3;
441 s->qmat[qpi][inter][plane][s->idct_permutation[i]] =
442 (i == 0 || s->version < 2) ? av_clip((qscale * coeff) / 100 * 4, qmin, 4096)
443 : (qscale * (coeff - qbias) / 100 + qbias) * 4;
444 }
445 /* all DC coefficients use the same quant so as not to interfere
446 * with DC prediction */
447 s->qmat[qpi][inter][plane][0] = s->qmat[0][inter][plane][0];
448 }
449 }
450}
451
452/*
453 * This function initializes the loop filter boundary limits if the frame's
454 * quality index is different from the previous frame's.
455 *
456 * The filter_limit_values may not be larger than 127.
457 */
459{
460 ff_vp3dsp_set_bounding_values(s->bounding_values_array, s->filter_limit_values[s->qps[0]]);
461}
462
463/*
464 * This function unpacks all of the superblock/macroblock/fragment coding
465 * information from the bitstream.
466 */
468{
469 const int superblock_starts[3] = {
470 0, s->u_superblock_start, s->v_superblock_start
471 };
472 int bit = 0;
473 int current_superblock = 0;
474 int current_run = 0;
475 int num_partial_superblocks = 0;
476
477 int current_fragment;
478 int plane0_num_coded_frags = 0;
479
480 if (s->keyframe) {
481 memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count);
482 } else {
483 /* unpack the list of partially-coded superblocks */
484 bit = get_bits1(gb) ^ 1;
485 current_run = 0;
486
487 while (current_superblock < s->superblock_count && get_bits_left(gb) > 0) {
488 if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN)
489 bit = get_bits1(gb);
490 else
491 bit ^= 1;
492
493 current_run = get_vlc2(gb, superblock_run_length_vlc,
495 if (current_run == 34)
496 current_run += get_bits(gb, 12);
497
498 if (current_run > s->superblock_count - current_superblock) {
499 av_log(s->avctx, AV_LOG_ERROR,
500 "Invalid partially coded superblock run length\n");
501 return -1;
502 }
503
504 memset(s->superblock_coding + current_superblock, bit, current_run);
505
506 current_superblock += current_run;
507 if (bit)
508 num_partial_superblocks += current_run;
509 }
510
511 /* unpack the list of fully coded superblocks if any of the blocks were
512 * not marked as partially coded in the previous step */
513 if (num_partial_superblocks < s->superblock_count) {
514 int superblocks_decoded = 0;
515
516 current_superblock = 0;
517 bit = get_bits1(gb) ^ 1;
518 current_run = 0;
519
520 while (superblocks_decoded < s->superblock_count - num_partial_superblocks &&
521 get_bits_left(gb) > 0) {
522 if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN)
523 bit = get_bits1(gb);
524 else
525 bit ^= 1;
526
527 current_run = get_vlc2(gb, superblock_run_length_vlc,
529 if (current_run == 34)
530 current_run += get_bits(gb, 12);
531
532 for (int j = 0; j < current_run; current_superblock++) {
533 if (current_superblock >= s->superblock_count) {
534 av_log(s->avctx, AV_LOG_ERROR,
535 "Invalid fully coded superblock run length\n");
536 return -1;
537 }
538
539 /* skip any superblocks already marked as partially coded */
540 if (s->superblock_coding[current_superblock] == SB_NOT_CODED) {
541 s->superblock_coding[current_superblock] = 2 * bit;
542 j++;
543 }
544 }
545 superblocks_decoded += current_run;
546 }
547 }
548
549 /* if there were partial blocks, initialize bitstream for
550 * unpacking fragment codings */
551 if (num_partial_superblocks) {
552 current_run = 0;
553 bit = get_bits1(gb);
554 /* toggle the bit because as soon as the first run length is
555 * fetched the bit will be toggled again */
556 bit ^= 1;
557 }
558 }
559
560 /* figure out which fragments are coded; iterate through each
561 * superblock (all planes) */
562 s->total_num_coded_frags = 0;
563 memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
564
565 s->coded_fragment_list[0] = s->keyframe ? s->kf_coded_fragment_list
566 : s->nkf_coded_fragment_list;
567
568 for (int plane = 0; plane < 3; plane++) {
569 int sb_start = superblock_starts[plane];
570 int sb_end = sb_start + (plane ? s->c_superblock_count
571 : s->y_superblock_count);
572 int num_coded_frags = 0;
573
574 if (s->keyframe) {
575 if (s->num_kf_coded_fragment[plane] == -1) {
576 for (int i = sb_start; i < sb_end; i++) {
577 /* iterate through all 16 fragments in a superblock */
578 for (int j = 0; j < 16; j++) {
579 /* if the fragment is in bounds, check its coding status */
580 current_fragment = s->superblock_fragments[i * 16 + j];
581 if (current_fragment != -1) {
582 s->coded_fragment_list[plane][num_coded_frags++] =
583 current_fragment;
584 }
585 }
586 }
587 s->num_kf_coded_fragment[plane] = num_coded_frags;
588 } else
589 num_coded_frags = s->num_kf_coded_fragment[plane];
590 } else {
591 for (int i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
592 if (get_bits_left(gb) < plane0_num_coded_frags >> 2) {
593 return AVERROR_INVALIDDATA;
594 }
595 /* iterate through all 16 fragments in a superblock */
596 for (int j = 0; j < 16; j++) {
597 /* if the fragment is in bounds, check its coding status */
598 current_fragment = s->superblock_fragments[i * 16 + j];
599 if (current_fragment != -1) {
600 int coded = s->superblock_coding[i];
601
602 if (coded == SB_PARTIALLY_CODED) {
603 /* fragment may or may not be coded; this is the case
604 * that cares about the fragment coding runs */
605 if (current_run-- == 0) {
606 bit ^= 1;
607 current_run = get_vlc2(gb, fragment_run_length_vlc, 5, 2);
608 }
609 coded = bit;
610 }
611
612 if (coded) {
613 /* default mode; actual mode will be decoded in
614 * the next phase */
615 s->all_fragments[current_fragment].coding_method =
617 s->coded_fragment_list[plane][num_coded_frags++] =
618 current_fragment;
619 } else {
620 /* not coded; copy this fragment from the prior frame */
621 s->all_fragments[current_fragment].coding_method =
622 MODE_COPY;
623 }
624 }
625 }
626 }
627 }
628 if (!plane)
629 plane0_num_coded_frags = num_coded_frags;
630 s->total_num_coded_frags += num_coded_frags;
631 for (int i = 0; i < 64; i++)
632 s->num_coded_frags[plane][i] = num_coded_frags;
633 if (plane < 2)
634 s->coded_fragment_list[plane + 1] = s->coded_fragment_list[plane] +
635 num_coded_frags;
636 }
637 return 0;
638}
639
640#define BLOCK_X (2 * mb_x + (k & 1))
641#define BLOCK_Y (2 * mb_y + (k >> 1))
642
643#if CONFIG_VP4_DECODER
644/**
645 * @return number of blocks, or > yuv_macroblock_count on error.
646 * return value is always >= 1.
647 */
648static int vp4_get_mb_count(Vp3DecodeContext *s, GetBitContext *gb)
649{
650 int v = 1;
651 int bits;
652 while ((bits = show_bits(gb, 9)) == 0x1ff) {
653 skip_bits(gb, 9);
654 v += 256;
655 if (v > s->yuv_macroblock_count) {
656 av_log(s->avctx, AV_LOG_ERROR, "Invalid run length\n");
657 return v;
658 }
659 }
660#define body(n) { \
661 skip_bits(gb, 2 + n); \
662 v += (1 << n) + get_bits(gb, n); }
663#define thresh(n) (0x200 - (0x80 >> n))
664#define else_if(n) else if (bits < thresh(n)) body(n)
665 if (bits < 0x100) {
666 skip_bits(gb, 1);
667 } else if (bits < thresh(0)) {
668 skip_bits(gb, 2);
669 v += 1;
670 }
671 else_if(1)
672 else_if(2)
673 else_if(3)
674 else_if(4)
675 else_if(5)
676 else_if(6)
677 else body(7)
678#undef body
679#undef thresh
680#undef else_if
681 return v;
682}
683
684static int vp4_get_block_pattern(GetBitContext *gb, int *next_block_pattern_table)
685{
686 int v = get_vlc2(gb, block_pattern_vlc[*next_block_pattern_table], 5, 1);
687 *next_block_pattern_table = vp4_block_pattern_table_selector[v];
688 return v + 1;
689}
690
691static int vp4_unpack_macroblocks(Vp3DecodeContext *s, GetBitContext *gb)
692{
693 int fragment;
694 int next_block_pattern_table;
695 int bit, current_run, has_partial;
696
697 memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
698
699 if (s->keyframe)
700 return 0;
701
702 has_partial = 0;
703 bit = get_bits1(gb);
704 for (int i = 0; i < s->yuv_macroblock_count; i += current_run) {
705 if (get_bits_left(gb) <= 0)
706 return AVERROR_INVALIDDATA;
707 current_run = vp4_get_mb_count(s, gb);
708 if (current_run > s->yuv_macroblock_count - i)
709 return -1;
710 memset(s->superblock_coding + i, 2 * bit, current_run);
711 bit ^= 1;
712 has_partial |= bit;
713 }
714
715 if (has_partial) {
716 if (get_bits_left(gb) <= 0)
717 return AVERROR_INVALIDDATA;
718 bit = get_bits1(gb);
719 current_run = vp4_get_mb_count(s, gb);
720 for (int i = 0; i < s->yuv_macroblock_count; i++) {
721 if (!s->superblock_coding[i]) {
722 if (!current_run) {
723 bit ^= 1;
724 current_run = vp4_get_mb_count(s, gb);
725 }
726 s->superblock_coding[i] = bit;
727 current_run--;
728 }
729 }
730 if (current_run) /* handle situation when vp4_get_mb_count() fails */
731 return -1;
732 }
733
734 next_block_pattern_table = 0;
735 for (int plane = 0, i = 0; plane < 3; plane++) {
736 int sb_width = plane ? s->c_superblock_width : s->y_superblock_width;
737 int sb_height = plane ? s->c_superblock_height : s->y_superblock_height;
738 int mb_width = plane ? s->c_macroblock_width : s->macroblock_width;
739 int mb_height = plane ? s->c_macroblock_height : s->macroblock_height;
740 int fragment_width = s->fragment_width[!!plane];
741 int fragment_height = s->fragment_height[!!plane];
742
743 for (int sb_y = 0; sb_y < sb_height; sb_y++) {
744 for (int sb_x = 0; sb_x < sb_width; sb_x++) {
745 for (int j = 0; j < 4; j++) {
746 int mb_x = 2 * sb_x + (j >> 1);
747 int mb_y = 2 * sb_y + (j >> 1) ^ (j & 1);
748 int mb_coded, pattern, coded;
749
750 if (mb_x >= mb_width || mb_y >= mb_height)
751 continue;
752
753 mb_coded = s->superblock_coding[i++];
754
755 if (mb_coded == SB_FULLY_CODED)
756 pattern = 0xF;
757 else if (mb_coded == SB_PARTIALLY_CODED)
758 pattern = vp4_get_block_pattern(gb, &next_block_pattern_table);
759 else
760 pattern = 0;
761
762 for (int k = 0; k < 4; k++) {
763 if (BLOCK_X >= fragment_width || BLOCK_Y >= fragment_height)
764 continue;
765 fragment = s->fragment_start[plane] + BLOCK_Y * fragment_width + BLOCK_X;
766 coded = pattern & (8 >> k);
767 /* MODE_INTER_NO_MV is the default for coded fragments.
768 the actual method is decoded in the next phase. */
769 s->all_fragments[fragment].coding_method = coded ? MODE_INTER_NO_MV : MODE_COPY;
770 }
771 }
772 }
773 }
774 }
775 return 0;
776}
777#endif
778
779/*
780 * This function unpacks all the coding mode data for individual macroblocks
781 * from the bitstream.
782 */
784{
785 int scheme;
786 int current_macroblock;
787 int current_fragment;
788 int coding_mode;
789 int custom_mode_alphabet[CODING_MODE_COUNT];
790 const int *alphabet;
791 Vp3Fragment *frag;
792
793 if (s->keyframe) {
794 for (int i = 0; i < s->fragment_count; i++)
795 s->all_fragments[i].coding_method = MODE_INTRA;
796 } else {
797 /* fetch the mode coding scheme for this frame */
798 scheme = get_bits(gb, 3);
799
800 /* is it a custom coding scheme? */
801 if (scheme == 0) {
802 for (int i = 0; i < 8; i++)
803 custom_mode_alphabet[i] = MODE_INTER_NO_MV;
804 for (int i = 0; i < 8; i++)
805 custom_mode_alphabet[get_bits(gb, 3)] = i;
806 alphabet = custom_mode_alphabet;
807 } else
808 alphabet = ModeAlphabet[scheme - 1];
809
810 /* iterate through all of the macroblocks that contain 1 or more
811 * coded fragments */
812 for (int sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {
813 for (int sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {
814 if (get_bits_left(gb) <= 0)
815 return -1;
816
817 for (int j = 0; j < 4; j++) {
818 int k;
819 int mb_x = 2 * sb_x + (j >> 1);
820 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
821 current_macroblock = mb_y * s->macroblock_width + mb_x;
822
823 if (mb_x >= s->macroblock_width ||
824 mb_y >= s->macroblock_height)
825 continue;
826
827 /* coding modes are only stored if the macroblock has
828 * at least one luma block coded, otherwise it must be
829 * INTER_NO_MV */
830 for (k = 0; k < 4; k++) {
831 current_fragment = BLOCK_Y *
832 s->fragment_width[0] + BLOCK_X;
833 if (s->all_fragments[current_fragment].coding_method != MODE_COPY)
834 break;
835 }
836 if (k == 4) {
837 s->macroblock_coding[current_macroblock] = MODE_INTER_NO_MV;
838 continue;
839 }
840
841 /* mode 7 means get 3 bits for each coding mode */
842 if (scheme == 7)
843 coding_mode = get_bits(gb, 3);
844 else
845 coding_mode = alphabet[get_vlc2(gb, mode_code_vlc, 4, 2)];
846
847 s->macroblock_coding[current_macroblock] = coding_mode;
848 for (k = 0; k < 4; k++) {
849 frag = s->all_fragments + BLOCK_Y * s->fragment_width[0] + BLOCK_X;
850 if (frag->coding_method != MODE_COPY)
851 frag->coding_method = coding_mode;
852 }
853
854#define SET_CHROMA_MODES \
855 if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
856 frag[s->fragment_start[1]].coding_method = coding_mode; \
857 if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
858 frag[s->fragment_start[2]].coding_method = coding_mode;
859
860 if (s->chroma_y_shift) {
861 frag = s->all_fragments + mb_y *
862 s->fragment_width[1] + mb_x;
864 } else if (s->chroma_x_shift) {
865 frag = s->all_fragments +
866 2 * mb_y * s->fragment_width[1] + mb_x;
867 for (k = 0; k < 2; k++) {
869 frag += s->fragment_width[1];
870 }
871 } else {
872 for (k = 0; k < 4; k++) {
873 frag = s->all_fragments +
874 BLOCK_Y * s->fragment_width[1] + BLOCK_X;
876 }
877 }
878 }
879 }
880 }
881 }
882
883 return 0;
884}
885
886static int vp4_get_mv(GetBitContext *gb, int axis, int last_motion)
887{
888#if CONFIG_VP4_DECODER
889 int v = get_vlc2(gb, vp4_mv_vlc_table[axis][vp4_mv_table_selector[FFABS(last_motion)]],
890 VP4_MV_VLC_BITS, 2);
891 return last_motion < 0 ? -v : v;
892#else
893 return 0;
894#endif
895}
896
897/*
898 * This function unpacks all the motion vectors for the individual
899 * macroblocks from the bitstream.
900 */
902{
903 int coding_mode;
904 int motion_x[4];
905 int motion_y[4];
906 int last_motion_x = 0;
907 int last_motion_y = 0;
908 int prior_last_motion_x = 0;
909 int prior_last_motion_y = 0;
910 int last_gold_motion_x = 0;
911 int last_gold_motion_y = 0;
912 int current_macroblock;
913 int current_fragment;
914 int frag;
915
916 if (s->keyframe)
917 return 0;
918
919 /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme; 2 is VP4 code scheme */
920 coding_mode = s->version < 2 ? get_bits1(gb) : 2;
921
922 /* iterate through all of the macroblocks that contain 1 or more
923 * coded fragments */
924 for (int sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {
925 for (int sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {
926 if (get_bits_left(gb) <= 0)
927 return -1;
928
929 for (int j = 0; j < 4; j++) {
930 int mb_x = 2 * sb_x + (j >> 1);
931 int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
932 current_macroblock = mb_y * s->macroblock_width + mb_x;
933
934 if (mb_x >= s->macroblock_width ||
935 mb_y >= s->macroblock_height ||
936 s->macroblock_coding[current_macroblock] == MODE_COPY)
937 continue;
938
939 switch (s->macroblock_coding[current_macroblock]) {
940 case MODE_GOLDEN_MV:
941 if (coding_mode == 2) { /* VP4 */
942 last_gold_motion_x = motion_x[0] = vp4_get_mv(gb, 0, last_gold_motion_x);
943 last_gold_motion_y = motion_y[0] = vp4_get_mv(gb, 1, last_gold_motion_y);
944 break;
945 }
948 /* all 6 fragments use the same motion vector */
949 if (coding_mode == 0) {
950 motion_x[0] = get_vlc2(gb, motion_vector_vlc,
951 VP3_MV_VLC_BITS, 2);
952 motion_y[0] = get_vlc2(gb, motion_vector_vlc,
953 VP3_MV_VLC_BITS, 2);
954 } else if (coding_mode == 1) {
955 motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];
956 motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)];
957 } else { /* VP4 */
958 motion_x[0] = vp4_get_mv(gb, 0, last_motion_x);
959 motion_y[0] = vp4_get_mv(gb, 1, last_motion_y);
960 }
961
962 /* vector maintenance, only on MODE_INTER_PLUS_MV */
963 if (s->macroblock_coding[current_macroblock] == MODE_INTER_PLUS_MV) {
964 prior_last_motion_x = last_motion_x;
965 prior_last_motion_y = last_motion_y;
966 last_motion_x = motion_x[0];
967 last_motion_y = motion_y[0];
968 }
969 break;
970
972 /* vector maintenance */
973 prior_last_motion_x = last_motion_x;
974 prior_last_motion_y = last_motion_y;
975
976 /* fetch 4 vectors from the bitstream, one for each
977 * Y fragment, then average for the C fragment vectors */
978 for (int k = 0; k < 4; k++) {
979 current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X;
980 if (s->all_fragments[current_fragment].coding_method != MODE_COPY) {
981 if (coding_mode == 0) {
982 motion_x[k] = get_vlc2(gb, motion_vector_vlc,
983 VP3_MV_VLC_BITS, 2);
984 motion_y[k] = get_vlc2(gb, motion_vector_vlc,
985 VP3_MV_VLC_BITS, 2);
986 } else if (coding_mode == 1) {
987 motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];
988 motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];
989 } else { /* VP4 */
990 motion_x[k] = vp4_get_mv(gb, 0, prior_last_motion_x);
991 motion_y[k] = vp4_get_mv(gb, 1, prior_last_motion_y);
992 }
993 last_motion_x = motion_x[k];
994 last_motion_y = motion_y[k];
995 } else {
996 motion_x[k] = 0;
997 motion_y[k] = 0;
998 }
999 }
1000 break;
1001
1002 case MODE_INTER_LAST_MV:
1003 /* all 6 fragments use the last motion vector */
1004 motion_x[0] = last_motion_x;
1005 motion_y[0] = last_motion_y;
1006
1007 /* no vector maintenance (last vector remains the
1008 * last vector) */
1009 break;
1010
1012 /* all 6 fragments use the motion vector prior to the
1013 * last motion vector */
1014 motion_x[0] = prior_last_motion_x;
1015 motion_y[0] = prior_last_motion_y;
1016
1017 /* vector maintenance */
1018 prior_last_motion_x = last_motion_x;
1019 prior_last_motion_y = last_motion_y;
1020 last_motion_x = motion_x[0];
1021 last_motion_y = motion_y[0];
1022 break;
1023
1024 default:
1025 /* covers intra, inter without MV, golden without MV */
1026 motion_x[0] = 0;
1027 motion_y[0] = 0;
1028
1029 /* no vector maintenance */
1030 break;
1031 }
1032
1033 /* assign the motion vectors to the correct fragments */
1034 for (int k = 0; k < 4; k++) {
1035 current_fragment =
1036 BLOCK_Y * s->fragment_width[0] + BLOCK_X;
1037 if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
1038 s->motion_val[0][current_fragment][0] = motion_x[k];
1039 s->motion_val[0][current_fragment][1] = motion_y[k];
1040 } else {
1041 s->motion_val[0][current_fragment][0] = motion_x[0];
1042 s->motion_val[0][current_fragment][1] = motion_y[0];
1043 }
1044 }
1045
1046 if (s->chroma_y_shift) {
1047 if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
1048 motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] +
1049 motion_x[2] + motion_x[3], 2);
1050 motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] +
1051 motion_y[2] + motion_y[3], 2);
1052 }
1053 if (s->version <= 2) {
1054 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1055 motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
1056 }
1057 frag = mb_y * s->fragment_width[1] + mb_x;
1058 s->motion_val[1][frag][0] = motion_x[0];
1059 s->motion_val[1][frag][1] = motion_y[0];
1060 } else if (s->chroma_x_shift) {
1061 if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
1062 motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1);
1063 motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1);
1064 motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1);
1065 motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1);
1066 } else {
1067 motion_x[1] = motion_x[0];
1068 motion_y[1] = motion_y[0];
1069 }
1070 if (s->version <= 2) {
1071 motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
1072 motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
1073 }
1074 frag = 2 * mb_y * s->fragment_width[1] + mb_x;
1075 for (int k = 0; k < 2; k++) {
1076 s->motion_val[1][frag][0] = motion_x[k];
1077 s->motion_val[1][frag][1] = motion_y[k];
1078 frag += s->fragment_width[1];
1079 }
1080 } else {
1081 for (int k = 0; k < 4; k++) {
1082 frag = BLOCK_Y * s->fragment_width[1] + BLOCK_X;
1083 if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
1084 s->motion_val[1][frag][0] = motion_x[k];
1085 s->motion_val[1][frag][1] = motion_y[k];
1086 } else {
1087 s->motion_val[1][frag][0] = motion_x[0];
1088 s->motion_val[1][frag][1] = motion_y[0];
1089 }
1090 }
1091 }
1092 }
1093 }
1094 }
1095
1096 return 0;
1097}
1098
1100{
1101 int num_blocks = s->total_num_coded_frags;
1102
1103 for (int qpi = 0; qpi < s->nqps - 1 && num_blocks > 0; qpi++) {
1104 int i = 0, blocks_decoded = 0, num_blocks_at_qpi = 0;
1105 int bit, run_length;
1106
1107 bit = get_bits1(gb) ^ 1;
1108 run_length = 0;
1109
1110 do {
1111 if (run_length == MAXIMUM_LONG_BIT_RUN)
1112 bit = get_bits1(gb);
1113 else
1114 bit ^= 1;
1115
1116 run_length = get_vlc2(gb, superblock_run_length_vlc,
1118 if (run_length == 34)
1119 run_length += get_bits(gb, 12);
1120 blocks_decoded += run_length;
1121
1122 if (!bit)
1123 num_blocks_at_qpi += run_length;
1124
1125 for (int j = 0; j < run_length; i++) {
1126 if (i >= s->total_num_coded_frags)
1127 return -1;
1128
1129 if (s->all_fragments[s->coded_fragment_list[0][i]].qpi == qpi) {
1130 s->all_fragments[s->coded_fragment_list[0][i]].qpi += bit;
1131 j++;
1132 }
1133 }
1134 } while (blocks_decoded < num_blocks && get_bits_left(gb) > 0);
1135
1136 num_blocks -= num_blocks_at_qpi;
1137 }
1138
1139 return 0;
1140}
1141
1142static inline int get_eob_run(GetBitContext *gb, int token)
1143{
1144 int v = eob_run_table[token].base;
1145 if (eob_run_table[token].bits)
1146 v += get_bits(gb, eob_run_table[token].bits);
1147 return v;
1148}
1149
1150static inline int get_coeff(GetBitContext *gb, int token, int16_t *coeff)
1151{
1152 int bits_to_get, zero_run;
1153
1154 bits_to_get = coeff_get_bits[token];
1155 if (bits_to_get)
1156 bits_to_get = get_bits(gb, bits_to_get);
1157 *coeff = coeff_tables[token][bits_to_get];
1158
1159 zero_run = zero_run_base[token];
1160 if (zero_run_get_bits[token])
1161 zero_run += get_bits(gb, zero_run_get_bits[token]);
1162
1163 return zero_run;
1164}
1165
1166/*
1167 * This function is called by unpack_dct_coeffs() to extract the VLCs from
1168 * the bitstream. The VLCs encode tokens which are used to unpack DCT
1169 * data. This function unpacks all the VLCs for either the Y plane or both
1170 * C planes, and is called for DC coefficients or different AC coefficient
1171 * levels (since different coefficient types require different VLC tables.
1172 *
1173 * This function returns a residual eob run. E.g, if a particular token gave
1174 * instructions to EOB the next 5 fragments and there were only 2 fragments
1175 * left in the current fragment range, 3 would be returned so that it could
1176 * be passed into the next call to this same function.
1177 */
1179 const VLCElem *vlc_table, int coeff_index,
1180 int plane,
1181 int eob_run)
1182{
1183 int j = 0;
1184 int token;
1185 int zero_run = 0;
1186 int16_t coeff = 0;
1187 int blocks_ended;
1188 int coeff_i = 0;
1189 int num_coeffs = s->num_coded_frags[plane][coeff_index];
1190 int16_t *dct_tokens = s->dct_tokens[plane][coeff_index];
1191
1192 /* local references to structure members to avoid repeated dereferences */
1193 const int *coded_fragment_list = s->coded_fragment_list[plane];
1194 Vp3Fragment *all_fragments = s->all_fragments;
1195
1196 if (num_coeffs < 0) {
1197 av_log(s->avctx, AV_LOG_ERROR,
1198 "Invalid number of coefficients at level %d\n", coeff_index);
1199 return AVERROR_INVALIDDATA;
1200 }
1201
1202 if (eob_run > num_coeffs) {
1203 coeff_i =
1204 blocks_ended = num_coeffs;
1205 eob_run -= num_coeffs;
1206 } else {
1207 coeff_i =
1208 blocks_ended = eob_run;
1209 eob_run = 0;
1210 }
1211
1212 // insert fake EOB token to cover the split between planes or zzi
1213 if (blocks_ended)
1214 dct_tokens[j++] = blocks_ended << 2;
1215
1216 while (coeff_i < num_coeffs && get_bits_left(gb) > 0) {
1217 /* decode a VLC into a token */
1218 token = get_vlc2(gb, vlc_table, 11, 3);
1219 /* use the token to get a zero run, a coefficient, and an eob run */
1220 if ((unsigned) token <= 6U) {
1221 eob_run = get_eob_run(gb, token);
1222 if (!eob_run)
1223 eob_run = INT_MAX;
1224
1225 // record only the number of blocks ended in this plane,
1226 // any spill will be recorded in the next plane.
1227 if (eob_run > num_coeffs - coeff_i) {
1228 dct_tokens[j++] = TOKEN_EOB(num_coeffs - coeff_i);
1229 blocks_ended += num_coeffs - coeff_i;
1230 eob_run -= num_coeffs - coeff_i;
1231 coeff_i = num_coeffs;
1232 } else {
1233 dct_tokens[j++] = TOKEN_EOB(eob_run);
1234 blocks_ended += eob_run;
1235 coeff_i += eob_run;
1236 eob_run = 0;
1237 }
1238 } else if (token >= 0) {
1239 zero_run = get_coeff(gb, token, &coeff);
1240
1241 if (zero_run) {
1242 dct_tokens[j++] = TOKEN_ZERO_RUN(coeff, zero_run);
1243 } else {
1244 // Save DC into the fragment structure. DC prediction is
1245 // done in raster order, so the actual DC can't be in with
1246 // other tokens. We still need the token in dct_tokens[]
1247 // however, or else the structure collapses on itself.
1248 if (!coeff_index)
1249 all_fragments[coded_fragment_list[coeff_i]].dc = coeff;
1250
1251 dct_tokens[j++] = TOKEN_COEFF(coeff);
1252 }
1253
1254 if (coeff_index + zero_run > 64) {
1255 av_log(s->avctx, AV_LOG_DEBUG,
1256 "Invalid zero run of %d with %d coeffs left\n",
1257 zero_run, 64 - coeff_index);
1258 zero_run = 64 - coeff_index;
1259 }
1260
1261 // zero runs code multiple coefficients,
1262 // so don't try to decode coeffs for those higher levels
1263 for (int i = coeff_index + 1; i <= coeff_index + zero_run; i++)
1264 s->num_coded_frags[plane][i]--;
1265 coeff_i++;
1266 } else {
1267 av_log(s->avctx, AV_LOG_ERROR, "Invalid token %d\n", token);
1268 return -1;
1269 }
1270 }
1271
1272 if (blocks_ended > s->num_coded_frags[plane][coeff_index])
1273 av_log(s->avctx, AV_LOG_ERROR, "More blocks ended than coded!\n");
1274
1275 // decrement the number of blocks that have higher coefficients for each
1276 // EOB run at this level
1277 if (blocks_ended)
1278 for (int i = coeff_index + 1; i < 64; i++)
1279 s->num_coded_frags[plane][i] -= blocks_ended;
1280
1281 // setup the next buffer
1282 if (plane < 2)
1283 s->dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
1284 else if (coeff_index < 63)
1285 s->dct_tokens[0][coeff_index + 1] = dct_tokens + j;
1286
1287 return eob_run;
1288}
1289
1291 int first_fragment,
1292 int fragment_width,
1293 int fragment_height);
1294/*
1295 * This function unpacks all of the DCT coefficient data from the
1296 * bitstream.
1297 */
1299{
1300 const VLCElem *const *coeff_vlc = s->coeff_vlc->vlc_tabs;
1301 int dc_y_table;
1302 int dc_c_table;
1303 int ac_y_table;
1304 int ac_c_table;
1305 int residual_eob_run = 0;
1306 const VLCElem *y_tables[64], *c_tables[64];
1307
1308 s->dct_tokens[0][0] = s->dct_tokens_base;
1309
1310 if (get_bits_left(gb) < 16)
1311 return AVERROR_INVALIDDATA;
1312
1313 /* fetch the DC table indexes */
1314 dc_y_table = get_bits(gb, 4);
1315 dc_c_table = get_bits(gb, 4);
1316
1317 /* unpack the Y plane DC coefficients */
1318 residual_eob_run = unpack_vlcs(s, gb, coeff_vlc[dc_y_table], 0,
1319 0, residual_eob_run);
1320 if (residual_eob_run < 0)
1321 return residual_eob_run;
1322 if (get_bits_left(gb) < 8)
1323 return AVERROR_INVALIDDATA;
1324
1325 /* reverse prediction of the Y-plane DC coefficients */
1326 reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]);
1327
1328 /* unpack the C plane DC coefficients */
1329 residual_eob_run = unpack_vlcs(s, gb, coeff_vlc[dc_c_table], 0,
1330 1, residual_eob_run);
1331 if (residual_eob_run < 0)
1332 return residual_eob_run;
1333 residual_eob_run = unpack_vlcs(s, gb, coeff_vlc[dc_c_table], 0,
1334 2, residual_eob_run);
1335 if (residual_eob_run < 0)
1336 return residual_eob_run;
1337
1338 /* reverse prediction of the C-plane DC coefficients */
1339 if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1340 reverse_dc_prediction(s, s->fragment_start[1],
1341 s->fragment_width[1], s->fragment_height[1]);
1342 reverse_dc_prediction(s, s->fragment_start[2],
1343 s->fragment_width[1], s->fragment_height[1]);
1344 }
1345
1346 if (get_bits_left(gb) < 8)
1347 return AVERROR_INVALIDDATA;
1348 /* fetch the AC table indexes */
1349 ac_y_table = get_bits(gb, 4);
1350 ac_c_table = get_bits(gb, 4);
1351
1352 /* build tables of AC VLC tables */
1353 for (int i = 1; i <= 5; i++) {
1354 /* AC VLC table group 1 */
1355 y_tables[i] = coeff_vlc[ac_y_table + 16];
1356 c_tables[i] = coeff_vlc[ac_c_table + 16];
1357 }
1358 for (int i = 6; i <= 14; i++) {
1359 /* AC VLC table group 2 */
1360 y_tables[i] = coeff_vlc[ac_y_table + 32];
1361 c_tables[i] = coeff_vlc[ac_c_table + 32];
1362 }
1363 for (int i = 15; i <= 27; i++) {
1364 /* AC VLC table group 3 */
1365 y_tables[i] = coeff_vlc[ac_y_table + 48];
1366 c_tables[i] = coeff_vlc[ac_c_table + 48];
1367 }
1368 for (int i = 28; i <= 63; i++) {
1369 /* AC VLC table group 4 */
1370 y_tables[i] = coeff_vlc[ac_y_table + 64];
1371 c_tables[i] = coeff_vlc[ac_c_table + 64];
1372 }
1373
1374 /* decode all AC coefficients */
1375 for (int i = 1; i <= 63; i++) {
1376 residual_eob_run = unpack_vlcs(s, gb, y_tables[i], i,
1377 0, residual_eob_run);
1378 if (residual_eob_run < 0)
1379 return residual_eob_run;
1380
1381 residual_eob_run = unpack_vlcs(s, gb, c_tables[i], i,
1382 1, residual_eob_run);
1383 if (residual_eob_run < 0)
1384 return residual_eob_run;
1385 residual_eob_run = unpack_vlcs(s, gb, c_tables[i], i,
1386 2, residual_eob_run);
1387 if (residual_eob_run < 0)
1388 return residual_eob_run;
1389 }
1390
1391 return 0;
1392}
1393
1394#if CONFIG_VP4_DECODER
1395/**
1396 * eob_tracker[] is instead of TOKEN_EOB(value)
1397 * a dummy TOKEN_EOB(0) value is used to make vp3_dequant work
1398 *
1399 * @return < 0 on error
1400 */
1401static int vp4_unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
1402 const VLCElem *const vlc_tables[64],
1403 int plane, int eob_tracker[64], int fragment)
1404{
1405 int token;
1406 int zero_run = 0;
1407 int16_t coeff = 0;
1408 int coeff_i = 0;
1409 int eob_run;
1410
1411 while (!eob_tracker[coeff_i]) {
1412 if (get_bits_left(gb) < 1)
1413 return AVERROR_INVALIDDATA;
1414
1415 token = get_vlc2(gb, vlc_tables[coeff_i], 11, 3);
1416
1417 /* use the token to get a zero run, a coefficient, and an eob run */
1418 if ((unsigned) token <= 6U) {
1419 eob_run = get_eob_run(gb, token);
1420 *s->dct_tokens[plane][coeff_i]++ = TOKEN_EOB(0);
1421 eob_tracker[coeff_i] = eob_run - 1;
1422 return 0;
1423 } else if (token >= 0) {
1424 zero_run = get_coeff(gb, token, &coeff);
1425
1426 if (zero_run) {
1427 if (coeff_i + zero_run > 64) {
1428 av_log(s->avctx, AV_LOG_DEBUG,
1429 "Invalid zero run of %d with %d coeffs left\n",
1430 zero_run, 64 - coeff_i);
1431 zero_run = 64 - coeff_i;
1432 }
1433 *s->dct_tokens[plane][coeff_i]++ = TOKEN_ZERO_RUN(coeff, zero_run);
1434 coeff_i += zero_run;
1435 } else {
1436 if (!coeff_i)
1437 s->all_fragments[fragment].dc = coeff;
1438
1439 *s->dct_tokens[plane][coeff_i]++ = TOKEN_COEFF(coeff);
1440 }
1441 coeff_i++;
1442 if (coeff_i >= 64) /* > 64 occurs when there is a zero_run overflow */
1443 return 0; /* stop */
1444 } else {
1445 av_log(s->avctx, AV_LOG_ERROR, "Invalid token %d\n", token);
1446 return -1;
1447 }
1448 }
1449 *s->dct_tokens[plane][coeff_i]++ = TOKEN_EOB(0);
1450 eob_tracker[coeff_i]--;
1451 return 0;
1452}
1453
1454static void vp4_dc_predictor_reset(VP4Predictor *p)
1455{
1456 p->dc = 0;
1457 p->type = VP4_DC_UNDEFINED;
1458}
1459
1460static void vp4_dc_pred_before(const Vp3DecodeContext *s, VP4Predictor dc_pred[6][6], int sb_x)
1461{
1462 for (int i = 0; i < 4; i++)
1463 dc_pred[0][i + 1] = s->dc_pred_row[sb_x * 4 + i];
1464
1465 for (int j = 1; j < 5; j++)
1466 for (int i = 0; i < 4; i++)
1467 vp4_dc_predictor_reset(&dc_pred[j][i + 1]);
1468}
1469
1470static void vp4_dc_pred_after(Vp3DecodeContext *s, VP4Predictor dc_pred[6][6], int sb_x)
1471{
1472 for (int i = 0; i < 4; i++)
1473 s->dc_pred_row[sb_x * 4 + i] = dc_pred[4][i + 1];
1474
1475 for (int i = 1; i < 5; i++)
1476 dc_pred[i][0] = dc_pred[i][4];
1477}
1478
1479/* note: dc_pred points to the current block */
1480static int vp4_dc_pred(const Vp3DecodeContext *s, const VP4Predictor * dc_pred, const int * last_dc, int type, int plane)
1481{
1482 int count = 0;
1483 int dc = 0;
1484
1485 if (dc_pred[-6].type == type) {
1486 dc += dc_pred[-6].dc;
1487 count++;
1488 }
1489
1490 if (dc_pred[6].type == type) {
1491 dc += dc_pred[6].dc;
1492 count++;
1493 }
1494
1495 if (count != 2 && dc_pred[-1].type == type) {
1496 dc += dc_pred[-1].dc;
1497 count++;
1498 }
1499
1500 if (count != 2 && dc_pred[1].type == type) {
1501 dc += dc_pred[1].dc;
1502 count++;
1503 }
1504
1505 /* using division instead of shift to correctly handle negative values */
1506 return count == 2 ? dc / 2 : last_dc[type];
1507}
1508
1509static void vp4_set_tokens_base(Vp3DecodeContext *s)
1510{
1511 int16_t *base = s->dct_tokens_base;
1512 for (int plane = 0; plane < 3; plane++) {
1513 for (int i = 0; i < 64; i++) {
1514 s->dct_tokens[plane][i] = base;
1515 base += s->fragment_width[!!plane] * s->fragment_height[!!plane];
1516 }
1517 }
1518}
1519
1520static int vp4_unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
1521{
1522 const VLCElem *const *coeff_vlc = s->coeff_vlc->vlc_tabs;
1523 int dc_y_table;
1524 int dc_c_table;
1525 int ac_y_table;
1526 int ac_c_table;
1527 const VLCElem *tables[2][64];
1528 int eob_tracker[64];
1529 VP4Predictor dc_pred[6][6];
1530 int last_dc[NB_VP4_DC_TYPES];
1531
1532 if (get_bits_left(gb) < 16)
1533 return AVERROR_INVALIDDATA;
1534
1535 /* fetch the DC table indexes */
1536 dc_y_table = get_bits(gb, 4);
1537 dc_c_table = get_bits(gb, 4);
1538
1539 ac_y_table = get_bits(gb, 4);
1540 ac_c_table = get_bits(gb, 4);
1541
1542 /* build tables of DC/AC VLC tables */
1543
1544 /* DC table group */
1545 tables[0][0] = coeff_vlc[dc_y_table];
1546 tables[1][0] = coeff_vlc[dc_c_table];
1547 for (int i = 1; i <= 5; i++) {
1548 /* AC VLC table group 1 */
1549 tables[0][i] = coeff_vlc[ac_y_table + 16];
1550 tables[1][i] = coeff_vlc[ac_c_table + 16];
1551 }
1552 for (int i = 6; i <= 14; i++) {
1553 /* AC VLC table group 2 */
1554 tables[0][i] = coeff_vlc[ac_y_table + 32];
1555 tables[1][i] = coeff_vlc[ac_c_table + 32];
1556 }
1557 for (int i = 15; i <= 27; i++) {
1558 /* AC VLC table group 3 */
1559 tables[0][i] = coeff_vlc[ac_y_table + 48];
1560 tables[1][i] = coeff_vlc[ac_c_table + 48];
1561 }
1562 for (int i = 28; i <= 63; i++) {
1563 /* AC VLC table group 4 */
1564 tables[0][i] = coeff_vlc[ac_y_table + 64];
1565 tables[1][i] = coeff_vlc[ac_c_table + 64];
1566 }
1567
1568 vp4_set_tokens_base(s);
1569
1570 memset(last_dc, 0, sizeof(last_dc));
1571
1572 for (int plane = 0; plane < ((s->avctx->flags & AV_CODEC_FLAG_GRAY) ? 1 : 3); plane++) {
1573 memset(eob_tracker, 0, sizeof(eob_tracker));
1574
1575 /* initialise dc prediction */
1576 for (int i = 0; i < s->fragment_width[!!plane]; i++)
1577 vp4_dc_predictor_reset(&s->dc_pred_row[i]);
1578
1579 for (int j = 0; j < 6; j++)
1580 for (int i = 0; i < 6; i++)
1581 vp4_dc_predictor_reset(&dc_pred[j][i]);
1582
1583 for (int sb_y = 0; sb_y * 4 < s->fragment_height[!!plane]; sb_y++) {
1584 for (int sb_x = 0; sb_x *4 < s->fragment_width[!!plane]; sb_x++) {
1585 vp4_dc_pred_before(s, dc_pred, sb_x);
1586 for (int j = 0; j < 16; j++) {
1587 int hx = hilbert_offset[j][0];
1588 int hy = hilbert_offset[j][1];
1589 int x = 4 * sb_x + hx;
1590 int y = 4 * sb_y + hy;
1591 VP4Predictor *this_dc_pred = &dc_pred[hy + 1][hx + 1];
1592 int fragment, dc_block_type;
1593
1594 if (x >= s->fragment_width[!!plane] || y >= s->fragment_height[!!plane])
1595 continue;
1596
1597 fragment = s->fragment_start[plane] + y * s->fragment_width[!!plane] + x;
1598
1599 if (s->all_fragments[fragment].coding_method == MODE_COPY)
1600 continue;
1601
1602 if (vp4_unpack_vlcs(s, gb, tables[!!plane], plane, eob_tracker, fragment) < 0)
1603 return -1;
1604
1605 dc_block_type = vp4_pred_block_type_map[s->all_fragments[fragment].coding_method];
1606
1607 s->all_fragments[fragment].dc +=
1608 vp4_dc_pred(s, this_dc_pred, last_dc, dc_block_type, plane);
1609
1610 this_dc_pred->type = dc_block_type,
1611 this_dc_pred->dc = last_dc[dc_block_type] = s->all_fragments[fragment].dc;
1612 }
1613 vp4_dc_pred_after(s, dc_pred, sb_x);
1614 }
1615 }
1616 }
1617
1618 vp4_set_tokens_base(s);
1619
1620 return 0;
1621}
1622#endif
1623
1624/*
1625 * This function reverses the DC prediction for each coded fragment in
1626 * the frame. Much of this function is adapted directly from the original
1627 * VP3 source code.
1628 */
1629#define COMPATIBLE_FRAME(x) \
1630 (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
1631#define DC_COEFF(u) s->all_fragments[u].dc
1632
1634 int first_fragment,
1635 int fragment_width,
1636 int fragment_height)
1637{
1638#define PUL 8
1639#define PU 4
1640#define PUR 2
1641#define PL 1
1642
1643 int i = first_fragment;
1644
1645 int predicted_dc;
1646
1647 /* DC values for the left, up-left, up, and up-right fragments */
1648 int vl, vul, vu, vur;
1649
1650 /* indexes for the left, up-left, up, and up-right fragments */
1651 int l, ul, u, ur;
1652
1653 /*
1654 * The 6 fields mean:
1655 * 0: up-left multiplier
1656 * 1: up multiplier
1657 * 2: up-right multiplier
1658 * 3: left multiplier
1659 */
1660 static const int predictor_transform[16][4] = {
1661 { 0, 0, 0, 0 },
1662 { 0, 0, 0, 128 }, // PL
1663 { 0, 0, 128, 0 }, // PUR
1664 { 0, 0, 53, 75 }, // PUR|PL
1665 { 0, 128, 0, 0 }, // PU
1666 { 0, 64, 0, 64 }, // PU |PL
1667 { 0, 128, 0, 0 }, // PU |PUR
1668 { 0, 0, 53, 75 }, // PU |PUR|PL
1669 { 128, 0, 0, 0 }, // PUL
1670 { 0, 0, 0, 128 }, // PUL|PL
1671 { 64, 0, 64, 0 }, // PUL|PUR
1672 { 0, 0, 53, 75 }, // PUL|PUR|PL
1673 { 0, 128, 0, 0 }, // PUL|PU
1674 { -104, 116, 0, 116 }, // PUL|PU |PL
1675 { 24, 80, 24, 0 }, // PUL|PU |PUR
1676 { -104, 116, 0, 116 } // PUL|PU |PUR|PL
1677 };
1678
1679 /* This table shows which types of blocks can use other blocks for
1680 * prediction. For example, INTRA is the only mode in this table to
1681 * have a frame number of 0. That means INTRA blocks can only predict
1682 * from other INTRA blocks. There are 2 golden frame coding types;
1683 * blocks encoding in these modes can only predict from other blocks
1684 * that were encoded with these 1 of these 2 modes. */
1685 static const unsigned char compatible_frame[9] = {
1686 1, /* MODE_INTER_NO_MV */
1687 0, /* MODE_INTRA */
1688 1, /* MODE_INTER_PLUS_MV */
1689 1, /* MODE_INTER_LAST_MV */
1690 1, /* MODE_INTER_PRIOR_MV */
1691 2, /* MODE_USING_GOLDEN */
1692 2, /* MODE_GOLDEN_MV */
1693 1, /* MODE_INTER_FOUR_MV */
1694 3 /* MODE_COPY */
1695 };
1696 int current_frame_type;
1697
1698 /* there is a last DC predictor for each of the 3 frame types */
1699 short last_dc[3];
1700
1701 int transform = 0;
1702
1703 vul =
1704 vu =
1705 vur =
1706 vl = 0;
1707 last_dc[0] =
1708 last_dc[1] =
1709 last_dc[2] = 0;
1710
1711 /* for each fragment row... */
1712 for (int y = 0; y < fragment_height; y++) {
1713 /* for each fragment in a row... */
1714 for (int x = 0; x < fragment_width; x++, i++) {
1715
1716 /* reverse prediction if this block was coded */
1717 if (s->all_fragments[i].coding_method != MODE_COPY) {
1718 current_frame_type =
1719 compatible_frame[s->all_fragments[i].coding_method];
1720
1721 transform = 0;
1722 if (x) {
1723 l = i - 1;
1724 vl = DC_COEFF(l);
1725 if (COMPATIBLE_FRAME(l))
1726 transform |= PL;
1727 }
1728 if (y) {
1729 u = i - fragment_width;
1730 vu = DC_COEFF(u);
1731 if (COMPATIBLE_FRAME(u))
1732 transform |= PU;
1733 if (x) {
1734 ul = i - fragment_width - 1;
1735 vul = DC_COEFF(ul);
1736 if (COMPATIBLE_FRAME(ul))
1737 transform |= PUL;
1738 }
1739 if (x + 1 < fragment_width) {
1740 ur = i - fragment_width + 1;
1741 vur = DC_COEFF(ur);
1742 if (COMPATIBLE_FRAME(ur))
1743 transform |= PUR;
1744 }
1745 }
1746
1747 if (transform == 0) {
1748 /* if there were no fragments to predict from, use last
1749 * DC saved */
1750 predicted_dc = last_dc[current_frame_type];
1751 } else {
1752 /* apply the appropriate predictor transform */
1753 predicted_dc =
1754 (predictor_transform[transform][0] * vul) +
1755 (predictor_transform[transform][1] * vu) +
1756 (predictor_transform[transform][2] * vur) +
1757 (predictor_transform[transform][3] * vl);
1758
1759 predicted_dc /= 128;
1760
1761 /* check for outranging on the [ul u l] and
1762 * [ul u ur l] predictors */
1763 if ((transform == 15) || (transform == 13)) {
1764 if (FFABS(predicted_dc - vu) > 128)
1765 predicted_dc = vu;
1766 else if (FFABS(predicted_dc - vl) > 128)
1767 predicted_dc = vl;
1768 else if (FFABS(predicted_dc - vul) > 128)
1769 predicted_dc = vul;
1770 }
1771 }
1772
1773 /* at long last, apply the predictor */
1774 DC_COEFF(i) += predicted_dc;
1775 /* save the DC */
1776 last_dc[current_frame_type] = DC_COEFF(i);
1777 }
1778 }
1779 }
1780}
1781
1782static void apply_loop_filter(Vp3DecodeContext *s, int plane,
1783 int ystart, int yend)
1784{
1785 int *bounding_values = s->bounding_values_array + 127;
1786
1787 int width = s->fragment_width[!!plane];
1788 int height = s->fragment_height[!!plane];
1789 int fragment = s->fragment_start[plane] + ystart * width;
1790 ptrdiff_t stride = s->current_frame.f->linesize[plane];
1791 uint8_t *plane_data = s->current_frame.f->data[plane];
1792 if (!s->flipped_image)
1793 stride = -stride;
1794 plane_data += s->data_offset[plane] + 8 * ystart * stride;
1795
1796 for (int y = ystart; y < yend; y++) {
1797 for (int x = 0; x < width; x++) {
1798 /* This code basically just deblocks on the edges of coded blocks.
1799 * However, it has to be much more complicated because of the
1800 * brain damaged deblock ordering used in VP3/Theora. Order matters
1801 * because some pixels get filtered twice. */
1802 if (s->all_fragments[fragment].coding_method != MODE_COPY) {
1803 /* do not perform left edge filter for left columns frags */
1804 if (x > 0) {
1805 s->vp3dsp.h_loop_filter(
1806 plane_data + 8 * x,
1807 stride, bounding_values);
1808 }
1809
1810 /* do not perform top edge filter for top row fragments */
1811 if (y > 0) {
1812 s->vp3dsp.v_loop_filter(
1813 plane_data + 8 * x,
1814 stride, bounding_values);
1815 }
1816
1817 /* do not perform right edge filter for right column
1818 * fragments or if right fragment neighbor is also coded
1819 * in this frame (it will be filtered in next iteration) */
1820 if ((x < width - 1) &&
1821 (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) {
1822 s->vp3dsp.h_loop_filter(
1823 plane_data + 8 * x + 8,
1824 stride, bounding_values);
1825 }
1826
1827 /* do not perform bottom edge filter for bottom row
1828 * fragments or if bottom fragment neighbor is also coded
1829 * in this frame (it will be filtered in the next row) */
1830 if ((y < height - 1) &&
1831 (s->all_fragments[fragment + width].coding_method == MODE_COPY)) {
1832 s->vp3dsp.v_loop_filter(
1833 plane_data + 8 * x + 8 * stride,
1834 stride, bounding_values);
1835 }
1836 }
1837
1838 fragment++;
1839 }
1840 plane_data += 8 * stride;
1841 }
1842}
1843
1844/**
1845 * Pull DCT tokens from the 64 levels to decode and dequant the coefficients
1846 * for the next block in coding order
1847 */
1848static inline int vp3_dequant(Vp3DecodeContext *s, const Vp3Fragment *frag,
1849 int plane, int inter, int16_t block[64])
1850{
1851 const int16_t *dequantizer = s->qmat[frag->qpi][inter][plane];
1852 const uint8_t *perm = s->idct_scantable;
1853 int i = 0;
1854
1855 do {
1856 int token = *s->dct_tokens[plane][i];
1857 switch (token & 3) {
1858 case 0: // EOB
1859 if (--token < 4) // 0-3 are token types so the EOB run must now be 0
1860 s->dct_tokens[plane][i]++;
1861 else
1862 *s->dct_tokens[plane][i] = token & ~3;
1863 goto end;
1864 case 1: // zero run
1865 s->dct_tokens[plane][i]++;
1866 i += (token >> 2) & 0x7f;
1867 if (i > 63) {
1868 av_log(s->avctx, AV_LOG_ERROR, "Coefficient index overflow\n");
1869 return i;
1870 }
1871 block[perm[i]] = (token >> 9) * dequantizer[perm[i]];
1872 i++;
1873 break;
1874 case 2: // coeff
1875 block[perm[i]] = (token >> 2) * dequantizer[perm[i]];
1876 s->dct_tokens[plane][i++]++;
1877 break;
1878 default: // shouldn't happen
1879 return i;
1880 }
1881 } while (i < 64);
1882 // return value is expected to be a valid level
1883 i--;
1884end:
1885 // the actual DC+prediction is in the fragment structure
1886 block[0] = frag->dc * s->qmat[0][inter][plane][0];
1887 return i;
1888}
1889
1890/**
1891 * called when all pixels up to row y are complete
1892 */
1894{
1895 int h, cy;
1897
1898 if (HAVE_THREADS && s->avctx->active_thread_type & FF_THREAD_FRAME) {
1899 /* At the end of the frame, report INT_MAX instead of the height of
1900 * the frame. This makes the other threads' ff_thread_await_progress()
1901 * calls cheaper, because they don't have to clip their values. */
1902 ff_progress_frame_report(&s->current_frame,
1903 y == s->height ? INT_MAX : y - 1);
1904 }
1905
1906 if (!s->avctx->draw_horiz_band)
1907 return;
1908
1909 h = y - s->last_slice_end;
1910 s->last_slice_end = y;
1911 y -= h;
1912
1913 if (!s->flipped_image)
1914 y = s->height - y - h;
1915
1916 cy = y >> s->chroma_y_shift;
1917 offset[0] = s->current_frame.f->linesize[0] * y;
1918 offset[1] = s->current_frame.f->linesize[1] * cy;
1919 offset[2] = s->current_frame.f->linesize[2] * cy;
1920 for (int i = 3; i < AV_NUM_DATA_POINTERS; i++)
1921 offset[i] = 0;
1922
1923 s->avctx->draw_horiz_band(s->avctx, s->current_frame.f, offset, y, 3, h);
1924}
1925
1926/**
1927 * Wait for the reference frame of the current fragment.
1928 * The progress value is in luma pixel rows.
1929 */
1931 int motion_y, int y)
1932{
1933 const ProgressFrame *ref_frame;
1934 int ref_row;
1935 int border = motion_y & 1;
1936
1937 if (fragment->coding_method == MODE_USING_GOLDEN ||
1938 fragment->coding_method == MODE_GOLDEN_MV)
1939 ref_frame = &s->golden_frame;
1940 else
1941 ref_frame = &s->last_frame;
1942
1943 ref_row = y + (motion_y >> 1);
1944 ref_row = FFMAX(FFABS(ref_row), ref_row + 8 + border);
1945
1947}
1948
1949#if CONFIG_VP4_DECODER
1950/**
1951 * @return non-zero if temp (edge_emu_buffer) was populated
1952 */
1953static int vp4_mc_loop_filter(Vp3DecodeContext *s, int plane, int motion_x, int motion_y, int bx, int by,
1954 const uint8_t *motion_source, ptrdiff_t stride,
1955 int src_x, int src_y, uint8_t *temp)
1956{
1957 int motion_shift = plane ? 4 : 2;
1958 int subpel_mask = plane ? 3 : 1;
1959 int *bounding_values = s->bounding_values_array + 127;
1960
1961 int x, y;
1962 int x2, y2;
1963 int x_subpel, y_subpel;
1964 int x_offset, y_offset;
1965
1966 int block_width = plane ? 8 : 16;
1967 int plane_width = s->width >> (plane && s->chroma_x_shift);
1968 int plane_height = s->height >> (plane && s->chroma_y_shift);
1969
1970#define loop_stride 12
1971 uint8_t loop[12 * loop_stride];
1972
1973 /* using division instead of shift to correctly handle negative values */
1974 x = 8 * bx + motion_x / motion_shift;
1975 y = 8 * by + motion_y / motion_shift;
1976
1977 x_subpel = motion_x & subpel_mask;
1978 y_subpel = motion_y & subpel_mask;
1979
1980 if (x_subpel || y_subpel) {
1981 x--;
1982 y--;
1983
1984 if (x_subpel)
1985 x = FFMIN(x, x + FFSIGN(motion_x));
1986
1987 if (y_subpel)
1988 y = FFMIN(y, y + FFSIGN(motion_y));
1989
1990 x2 = x + block_width;
1991 y2 = y + block_width;
1992
1993 if (x2 < 0 || x2 >= plane_width || y2 < 0 || y2 >= plane_height)
1994 return 0;
1995
1996 x_offset = (-(x + 2) & 7) + 2;
1997 y_offset = (-(y + 2) & 7) + 2;
1998
1999 av_assert1(!(x_offset > 8 + x_subpel && y_offset > 8 + y_subpel));
2000
2001 s->vdsp.emulated_edge_mc(loop, motion_source - stride - 1,
2002 loop_stride, stride,
2003 12, 12, src_x - 1, src_y - 1,
2004 plane_width,
2005 plane_height);
2006
2007 if (x_offset <= 8 + x_subpel)
2008 ff_vp3dsp_h_loop_filter_12(loop + x_offset, loop_stride, bounding_values);
2009
2010 if (y_offset <= 8 + y_subpel)
2011 ff_vp3dsp_v_loop_filter_12(loop + y_offset*loop_stride, loop_stride, bounding_values);
2012
2013 } else {
2014
2015 x_offset = -x & 7;
2016 y_offset = -y & 7;
2017
2018 if (!x_offset && !y_offset)
2019 return 0;
2020
2021 s->vdsp.emulated_edge_mc(loop, motion_source - stride - 1,
2022 loop_stride, stride,
2023 12, 12, src_x - 1, src_y - 1,
2024 plane_width,
2025 plane_height);
2026
2027#define safe_loop_filter(name, ptr, stride, bounding_values) \
2028 if (VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT && (uintptr_t)(ptr) & 7) \
2029 s->vp3dsp.name##_unaligned(ptr, stride, bounding_values); \
2030 else \
2031 s->vp3dsp.name(ptr, stride, bounding_values);
2032
2033 if (x_offset)
2034 safe_loop_filter(h_loop_filter, loop + loop_stride + x_offset + 1, loop_stride, bounding_values);
2035
2036 if (y_offset)
2037 safe_loop_filter(v_loop_filter, loop + (y_offset + 1)*loop_stride + 1, loop_stride, bounding_values);
2038 }
2039
2040 for (int i = 0; i < 9; i++)
2041 memcpy(temp + i*stride, loop + (i + 1) * loop_stride + 1, 9);
2042
2043 return 1;
2044}
2045#endif
2046
2047/*
2048 * Perform the final rendering for a particular slice of data.
2049 * The slice number ranges from 0..(c_superblock_height - 1).
2050 */
2051static void render_slice(Vp3DecodeContext *s, int slice)
2052{
2053 int16_t *block = s->block;
2054 int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef;
2055 /* When decoding keyframes, the earlier frames may not be available,
2056 * so we just use the current frame in this case instead;
2057 * it also avoid using undefined pointer arithmetic. Nothing is
2058 * ever read from these frames in case of a keyframe. */
2059 const AVFrame *last_frame = s->last_frame.f ?
2060 s->last_frame.f : s->current_frame.f;
2061 const AVFrame *golden_frame = s->golden_frame.f ?
2062 s->golden_frame.f : s->current_frame.f;
2063 int motion_halfpel_index;
2064 int first_pixel;
2065
2066 if (slice >= s->c_superblock_height)
2067 return;
2068
2069 for (int plane = 0; plane < 3; plane++) {
2070 uint8_t *output_plane = s->current_frame.f->data[plane] +
2071 s->data_offset[plane];
2072 const uint8_t *last_plane = last_frame->data[plane] +
2073 s->data_offset[plane];
2074 const uint8_t *golden_plane = golden_frame->data[plane] +
2075 s->data_offset[plane];
2076 ptrdiff_t stride = s->current_frame.f->linesize[plane];
2077 int plane_width = s->width >> (plane && s->chroma_x_shift);
2078 int plane_height = s->height >> (plane && s->chroma_y_shift);
2079 const int8_t (*motion_val)[2] = s->motion_val[!!plane];
2080
2081 int sb_y = slice << (!plane && s->chroma_y_shift);
2082 int slice_height = sb_y + 1 + (!plane && s->chroma_y_shift);
2083 int slice_width = plane ? s->c_superblock_width
2084 : s->y_superblock_width;
2085
2086 int fragment_width = s->fragment_width[!!plane];
2087 int fragment_height = s->fragment_height[!!plane];
2088 int fragment_start = s->fragment_start[plane];
2089
2090 int do_await = !plane && HAVE_THREADS &&
2091 (s->avctx->active_thread_type & FF_THREAD_FRAME);
2092
2093 if (!s->flipped_image)
2094 stride = -stride;
2095 if (CONFIG_GRAY && plane && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
2096 continue;
2097
2098 /* for each superblock row in the slice (both of them)... */
2099 for (; sb_y < slice_height; sb_y++) {
2100 /* for each superblock in a row... */
2101 for (int sb_x = 0; sb_x < slice_width; sb_x++) {
2102 /* for each block in a superblock... */
2103 for (int j = 0; j < 16; j++) {
2104 int x = 4 * sb_x + hilbert_offset[j][0];
2105 int y = 4 * sb_y + hilbert_offset[j][1];
2106 int fragment = y * fragment_width + x;
2107
2108 int i = fragment_start + fragment;
2109
2110 // bounds check
2111 if (x >= fragment_width || y >= fragment_height)
2112 continue;
2113
2114 first_pixel = 8 * y * stride + 8 * x;
2115
2116 if (do_await &&
2117 s->all_fragments[i].coding_method != MODE_INTRA)
2118 await_reference_row(s, &s->all_fragments[i],
2119 motion_val[fragment][1],
2120 (16 * y) >> s->chroma_y_shift);
2121
2122 /* transform if this block was coded */
2123 if (s->all_fragments[i].coding_method != MODE_COPY) {
2124 const uint8_t *motion_source;
2125 if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) ||
2126 (s->all_fragments[i].coding_method == MODE_GOLDEN_MV))
2127 motion_source = golden_plane;
2128 else
2129 motion_source = last_plane;
2130
2131 motion_source += first_pixel;
2132 motion_halfpel_index = 0;
2133
2134 /* sort out the motion vector if this fragment is coded
2135 * using a motion vector method */
2136 if ((s->all_fragments[i].coding_method > MODE_INTRA) &&
2137 (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) {
2138 int src_x, src_y;
2139 int standard_mc = 1;
2140 motion_x = motion_val[fragment][0];
2141 motion_y = motion_val[fragment][1];
2142#if CONFIG_VP4_DECODER
2143 if (plane && s->version >= 2) {
2144 motion_x = (motion_x >> 1) | (motion_x & 1);
2145 motion_y = (motion_y >> 1) | (motion_y & 1);
2146 }
2147#endif
2148
2149 src_x = (motion_x >> 1) + 8 * x;
2150 src_y = (motion_y >> 1) + 8 * y;
2151
2152 motion_halfpel_index = motion_x & 0x01;
2153 motion_source += (motion_x >> 1);
2154
2155 motion_halfpel_index |= (motion_y & 0x01) << 1;
2156 motion_source += ((motion_y >> 1) * stride);
2157
2158#if CONFIG_VP4_DECODER
2159 if (s->version >= 2) {
2160 uint8_t *temp = s->edge_emu_buffer;
2161 if (stride < 0)
2162 temp -= 8 * stride;
2163 if (vp4_mc_loop_filter(s, plane, motion_val[fragment][0], motion_val[fragment][1], x, y, motion_source, stride, src_x, src_y, temp)) {
2164 motion_source = temp;
2165 standard_mc = 0;
2166 }
2167 }
2168#endif
2169
2170 if (standard_mc && (
2171 src_x < 0 || src_y < 0 ||
2172 src_x + 9 >= plane_width ||
2173 src_y + 9 >= plane_height)) {
2174 uint8_t *temp = s->edge_emu_buffer;
2175 if (stride < 0)
2176 temp -= 8 * stride;
2177
2178 s->vdsp.emulated_edge_mc(temp, motion_source,
2179 stride, stride,
2180 9, 9, src_x, src_y,
2181 plane_width,
2182 plane_height);
2183 motion_source = temp;
2184 }
2185 }
2186
2187 /* first, take care of copying a block from either the
2188 * previous or the golden frame */
2189 if (s->all_fragments[i].coding_method != MODE_INTRA) {
2190 /* Note, it is possible to implement all MC cases
2191 * with put_no_rnd_pixels_l2 which would look more
2192 * like the VP3 source but this would be slower as
2193 * put_no_rnd_pixels_tab is better optimized */
2194 if (motion_halfpel_index != 3) {
2195 s->hdsp.put_no_rnd_pixels_tab[1][motion_halfpel_index](
2196 output_plane + first_pixel,
2197 motion_source, stride, 8);
2198 } else {
2199 /* d is 0 if motion_x and _y have the same sign,
2200 * else -1 */
2201 int d = (motion_x ^ motion_y) >> 31;
2202 s->vp3dsp.put_no_rnd_pixels_l2(output_plane + first_pixel,
2203 motion_source - d,
2204 motion_source + stride + 1 + d,
2205 stride, 8);
2206 }
2207 }
2208
2209 /* invert DCT and place (or add) in final output */
2210
2211 if (s->all_fragments[i].coding_method == MODE_INTRA) {
2212 vp3_dequant(s, s->all_fragments + i,
2213 plane, 0, block);
2214 s->vp3dsp.idct_put(output_plane + first_pixel,
2215 stride,
2216 block);
2217 } else {
2218 if (vp3_dequant(s, s->all_fragments + i,
2219 plane, 1, block)) {
2220 s->vp3dsp.idct_add(output_plane + first_pixel,
2221 stride,
2222 block);
2223 } else {
2224 s->vp3dsp.idct_dc_add(output_plane + first_pixel,
2225 stride, block);
2226 }
2227 }
2228 } else {
2229 /* copy directly from the previous frame */
2230 s->hdsp.put_pixels_tab[1][0](
2231 output_plane + first_pixel,
2232 last_plane + first_pixel,
2233 stride, 8);
2234 }
2235 }
2236 }
2237
2238 // Filter up to the last row in the superblock row
2239 if (s->version < 2 && !s->skip_loop_filter)
2240 apply_loop_filter(s, plane, 4 * sb_y - !!sb_y,
2241 FFMIN(4 * sb_y + 3, fragment_height - 1));
2242 }
2243 }
2244
2245 /* this looks like a good place for slice dispatch... */
2246 /* algorithm:
2247 * if (slice == s->macroblock_height - 1)
2248 * dispatch (both last slice & 2nd-to-last slice);
2249 * else if (slice > 0)
2250 * dispatch (slice - 1);
2251 */
2252
2253 vp3_draw_horiz_band(s, FFMIN((32 << s->chroma_y_shift) * (slice + 1) - 16,
2254 s->height - 16));
2255}
2256
2257static av_cold void init_tables_once(void)
2258{
2260
2264 NULL, 0, 0, 1, 0);
2265
2268 NULL, 0, 0, 0, 0);
2269
2271 &motion_vector_vlc_table[0][1], 2,
2272 &motion_vector_vlc_table[0][0], 2, 1,
2273 -31, 0);
2274
2277 NULL, 0, 0, 0, 0);
2278
2279#if CONFIG_VP4_DECODER
2280 for (int j = 0; j < 2; j++)
2281 for (int i = 0; i < 7; i++) {
2282 vp4_mv_vlc_table[j][i] =
2284 &vp4_mv_vlc[j][i][0][1], 2,
2285 &vp4_mv_vlc[j][i][0][0], 2, 1,
2286 -31, 0);
2287 }
2288
2289 /* version >= 2 */
2290 for (int i = 0; i < 2; i++) {
2291 block_pattern_vlc[i] =
2292 ff_vlc_init_tables(&state, 5, 14,
2293 &vp4_block_pattern_vlc[i][0][1], 2, 1,
2294 &vp4_block_pattern_vlc[i][0][0], 2, 1, 0);
2295 }
2296#endif
2297}
2298
2299/// Allocate tables for per-frame data in Vp3DecodeContext
2301{
2302 Vp3DecodeContext *s = avctx->priv_data;
2303 int y_fragment_count, c_fragment_count;
2304
2305 free_tables(avctx);
2306
2307 y_fragment_count = s->fragment_width[0] * s->fragment_height[0];
2308 c_fragment_count = s->fragment_width[1] * s->fragment_height[1];
2309
2310 /* superblock_coding is used by unpack_superblocks (VP3/Theora) and vp4_unpack_macroblocks (VP4) */
2311 s->superblock_coding = av_mallocz(FFMAX(s->superblock_count, s->yuv_macroblock_count));
2312 s->all_fragments = av_calloc(s->fragment_count, sizeof(*s->all_fragments));
2313
2314 s-> kf_coded_fragment_list = av_calloc(s->fragment_count, sizeof(int));
2315 s->nkf_coded_fragment_list = av_calloc(s->fragment_count, sizeof(int));
2316 memset(s-> num_kf_coded_fragment, -1, sizeof(s-> num_kf_coded_fragment));
2317
2318 s->dct_tokens_base = av_calloc(s->fragment_count,
2319 64 * sizeof(*s->dct_tokens_base));
2320 s->motion_val[0] = av_calloc(y_fragment_count, sizeof(*s->motion_val[0]));
2321 s->motion_val[1] = av_calloc(c_fragment_count, sizeof(*s->motion_val[1]));
2322
2323 /* work out the block mapping tables */
2324 s->superblock_fragments = av_calloc(s->superblock_count, 16 * sizeof(int));
2325 s->macroblock_coding = av_mallocz(s->macroblock_count + 1);
2326
2327 s->dc_pred_row = av_malloc_array(s->y_superblock_width * 4, sizeof(*s->dc_pred_row));
2328
2329 if (!s->superblock_coding || !s->all_fragments ||
2330 !s->dct_tokens_base || !s->kf_coded_fragment_list ||
2331 !s->nkf_coded_fragment_list ||
2332 !s->superblock_fragments || !s->macroblock_coding ||
2333 !s->dc_pred_row ||
2334 !s->motion_val[0] || !s->motion_val[1]) {
2335 return -1;
2336 }
2337
2339
2340 return 0;
2341}
2342
2343
2345{
2346 CoeffVLCs *vlcs = obj;
2347
2348 for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++)
2349 ff_vlc_free(&vlcs->vlcs[i]);
2350}
2351
2353{
2354 static AVOnce init_static_once = AV_ONCE_INIT;
2355 Vp3DecodeContext *s = avctx->priv_data;
2356 int ret;
2357 int c_width;
2358 int c_height;
2359 int y_fragment_count, c_fragment_count;
2360
2361 if (avctx->codec_tag == MKTAG('V', 'P', '4', '0')) {
2362 s->version = 3;
2363#if !CONFIG_VP4_DECODER
2364 av_log(avctx, AV_LOG_ERROR, "This build does not support decoding VP4.\n");
2366#endif
2367 } else if (avctx->codec_tag == MKTAG('V', 'P', '3', '0'))
2368 s->version = 0;
2369 else
2370 s->version = 1;
2371
2372 s->avctx = avctx;
2373 s->width = FFALIGN(avctx->coded_width, 16);
2374 s->height = FFALIGN(avctx->coded_height, 16);
2375 if (s->width < 18)
2376 return AVERROR_PATCHWELCOME;
2377 if (avctx->codec_id != AV_CODEC_ID_THEORA)
2378 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
2381 ff_videodsp_init(&s->vdsp, 8);
2382 ff_vp3dsp_init(&s->vp3dsp);
2383
2384 for (int i = 0; i < 64; i++) {
2385#define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
2386 s->idct_permutation[i] = TRANSPOSE(i);
2387 s->idct_scantable[i] = TRANSPOSE(ff_zigzag_direct[i]);
2388#undef TRANSPOSE
2389 }
2390
2391 /* initialize to an impossible value which will force a recalculation
2392 * in the first frame decode */
2393 for (int i = 0; i < 3; i++)
2394 s->qps[i] = -1;
2395
2396 ret = av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift);
2397 if (ret)
2398 return ret;
2399
2400 s->y_superblock_width = (s->width + 31) / 32;
2401 s->y_superblock_height = (s->height + 31) / 32;
2402 s->y_superblock_count = s->y_superblock_width * s->y_superblock_height;
2403
2404 /* work out the dimensions for the C planes */
2405 c_width = s->width >> s->chroma_x_shift;
2406 c_height = s->height >> s->chroma_y_shift;
2407 s->c_superblock_width = (c_width + 31) / 32;
2408 s->c_superblock_height = (c_height + 31) / 32;
2409 s->c_superblock_count = s->c_superblock_width * s->c_superblock_height;
2410
2411 s->superblock_count = s->y_superblock_count + (s->c_superblock_count * 2);
2412 s->u_superblock_start = s->y_superblock_count;
2413 s->v_superblock_start = s->u_superblock_start + s->c_superblock_count;
2414
2415 s->macroblock_width = (s->width + 15) / 16;
2416 s->macroblock_height = (s->height + 15) / 16;
2417 s->macroblock_count = s->macroblock_width * s->macroblock_height;
2418 s->c_macroblock_width = (c_width + 15) / 16;
2419 s->c_macroblock_height = (c_height + 15) / 16;
2420 s->c_macroblock_count = s->c_macroblock_width * s->c_macroblock_height;
2421 s->yuv_macroblock_count = s->macroblock_count + 2 * s->c_macroblock_count;
2422
2423 s->fragment_width[0] = s->width / FRAGMENT_PIXELS;
2424 s->fragment_height[0] = s->height / FRAGMENT_PIXELS;
2425 s->fragment_width[1] = s->fragment_width[0] >> s->chroma_x_shift;
2426 s->fragment_height[1] = s->fragment_height[0] >> s->chroma_y_shift;
2427
2428 /* fragment count covers all 8x8 blocks for all 3 planes */
2429 y_fragment_count = s->fragment_width[0] * s->fragment_height[0];
2430 c_fragment_count = s->fragment_width[1] * s->fragment_height[1];
2431 s->fragment_count = y_fragment_count + 2 * c_fragment_count;
2432 s->fragment_start[1] = y_fragment_count;
2433 s->fragment_start[2] = y_fragment_count + c_fragment_count;
2434
2435 if (!s->theora_tables) {
2436 for (int i = 0; i < 64; i++) {
2437 s->coded_dc_scale_factor[0][i] = s->version < 2 ? vp31_dc_scale_factor[i] : vp4_y_dc_scale_factor[i];
2438 s->coded_dc_scale_factor[1][i] = s->version < 2 ? vp31_dc_scale_factor[i] : vp4_uv_dc_scale_factor[i];
2439 s->coded_ac_scale_factor[i] = s->version < 2 ? vp31_ac_scale_factor[i] : vp4_ac_scale_factor[i];
2440 s->base_matrix[0][i] = s->version < 2 ? vp31_intra_y_dequant[i] : vp4_generic_dequant[i];
2441 s->base_matrix[1][i] = s->version < 2 ? ff_mjpeg_std_chrominance_quant_tbl[i] : vp4_generic_dequant[i];
2442 s->base_matrix[2][i] = s->version < 2 ? vp31_inter_dequant[i] : vp4_generic_dequant[i];
2443 s->filter_limit_values[i] = s->version < 2 ? vp31_filter_limit_values[i] : vp4_filter_limit_values[i];
2444 }
2445
2446 for (int inter = 0; inter < 2; inter++) {
2447 for (int plane = 0; plane < 3; plane++) {
2448 s->qr_count[inter][plane] = 1;
2449 s->qr_size[inter][plane][0] = 63;
2450 s->qr_base[inter][plane][0] =
2451 s->qr_base[inter][plane][1] = 2 * inter + (!!plane) * !inter;
2452 }
2453 }
2454 }
2455
2457 CoeffVLCs *vlcs = av_refstruct_alloc_ext(sizeof(*s->coeff_vlc), 0,
2459 if (!vlcs)
2460 return AVERROR(ENOMEM);
2461
2462 s->coeff_vlc = vlcs;
2463
2464 if (!s->theora_tables) {
2465 const uint8_t (*bias_tabs)[32][2];
2466
2467 /* init VLC tables */
2468 bias_tabs = CONFIG_VP4_DECODER && s->version >= 2 ? vp4_bias : vp3_bias;
2469 for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
2470 ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, 32,
2471 &bias_tabs[i][0][1], 2,
2472 &bias_tabs[i][0][0], 2, 1,
2473 0, 0, avctx);
2474 if (ret < 0)
2475 return ret;
2476 vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
2477 }
2478 } else {
2479 for (int i = 0; i < FF_ARRAY_ELEMS(vlcs->vlcs); i++) {
2480 const HuffTable *tab = &s->huffman_table[i];
2481
2482 ret = ff_vlc_init_from_lengths(&vlcs->vlcs[i], 11, tab->nb_entries,
2483 &tab->entries[0].len, sizeof(*tab->entries),
2484 &tab->entries[0].sym, sizeof(*tab->entries), 1,
2485 0, 0, avctx);
2486 if (ret < 0)
2487 return ret;
2488 vlcs->vlc_tabs[i] = vlcs->vlcs[i].table;
2489 }
2490 }
2491 }
2492
2493 ff_thread_once(&init_static_once, init_tables_once);
2494
2495 return allocate_tables(avctx);
2496}
2497
2498#if HAVE_THREADS
2499static void ref_frames(Vp3DecodeContext *dst, const Vp3DecodeContext *src)
2500{
2501 ff_progress_frame_replace(&dst->current_frame, &src->current_frame);
2502 ff_progress_frame_replace(&dst->golden_frame, &src->golden_frame);
2503}
2504
2505static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
2506{
2507 Vp3DecodeContext *s = dst->priv_data;
2508 const Vp3DecodeContext *s1 = src->priv_data;
2509 int qps_changed = 0;
2510
2511 // copy previous frame data
2512 ref_frames(s, s1);
2513
2514 if (s != s1) {
2515 // copy qscale data if necessary
2516 for (int i = 0; i < 3; i++) {
2517 if (s->qps[i] != s1->qps[i]) {
2518 qps_changed = 1;
2519 memcpy(&s->qmat[i], &s1->qmat[i], sizeof(s->qmat[i]));
2520 }
2521 }
2522
2523 if (s->qps[0] != s1->qps[0])
2524 memcpy(&s->bounding_values_array, &s1->bounding_values_array,
2525 sizeof(s->bounding_values_array));
2526
2527 if (qps_changed) {
2528 memcpy(s->qps, s1->qps, sizeof(s->qps));
2529 s->nqps = s1->nqps;
2530 }
2531 }
2532 return 0;
2533}
2534#endif
2535
2537 int *got_frame, AVPacket *avpkt)
2538{
2539 const uint8_t *buf = avpkt->data;
2540 int buf_size = avpkt->size;
2541 Vp3DecodeContext *s = avctx->priv_data;
2542 GetBitContext gb;
2543 int ret;
2544
2545 if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
2546 return ret;
2547
2548#if CONFIG_THEORA_DECODER
2549 if (s->theora && get_bits1(&gb)) {
2550 int type = get_bits(&gb, 7);
2551 skip_bits_long(&gb, 6*8); /* "theora" */
2552
2553 if (s->avctx->active_thread_type&FF_THREAD_FRAME) {
2554 av_log(avctx, AV_LOG_ERROR, "midstream reconfiguration with multithreading is unsupported, try -threads 1\n");
2555 return AVERROR_PATCHWELCOME;
2556 }
2557 if (type == 0) {
2558 vp3_decode_end(avctx);
2559 ret = theora_decode_header(avctx, &gb);
2560
2561 if (ret >= 0)
2562 ret = vp3_decode_init(avctx);
2563 if (ret < 0) {
2564 vp3_decode_end(avctx);
2565 return ret;
2566 }
2567 return buf_size;
2568 } else if (type == 2) {
2569 vp3_decode_end(avctx);
2570 ret = theora_decode_tables(avctx, &gb);
2571 if (ret >= 0)
2572 ret = vp3_decode_init(avctx);
2573 if (ret < 0) {
2574 vp3_decode_end(avctx);
2575 return ret;
2576 }
2577 return buf_size;
2578 }
2579
2580 av_log(avctx, AV_LOG_ERROR,
2581 "Header packet passed to frame decoder, skipping\n");
2582 return -1;
2583 }
2584#endif
2585
2586 s->keyframe = !get_bits1(&gb);
2587 if (!s->all_fragments) {
2588 av_log(avctx, AV_LOG_ERROR, "Data packet without prior valid headers\n");
2589 return -1;
2590 }
2591 if (!s->theora)
2592 skip_bits(&gb, 1);
2593
2594 int last_qps[3];
2595 for (int i = 0; i < 3; i++)
2596 last_qps[i] = s->qps[i];
2597
2598 s->nqps = 0;
2599 do {
2600 s->qps[s->nqps++] = get_bits(&gb, 6);
2601 } while (s->theora >= 0x030200 && s->nqps < 3 && get_bits1(&gb));
2602 for (int i = s->nqps; i < 3; i++)
2603 s->qps[i] = -1;
2604
2605 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
2606 av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%"PRId64": Q index = %d\n",
2607 s->keyframe ? "key" : "", avctx->frame_num + 1, s->qps[0]);
2608
2609 s->skip_loop_filter = !s->filter_limit_values[s->qps[0]] ||
2610 avctx->skip_loop_filter >= (s->keyframe ? AVDISCARD_ALL
2612
2613 if (s->qps[0] != last_qps[0])
2615
2616 for (int i = 0; i < s->nqps; i++)
2617 // reinit all dequantizers if the first one changed, because
2618 // the DC of the first quantizer must be used for all matrices
2619 if (s->qps[i] != last_qps[i] || s->qps[0] != last_qps[0])
2621
2622 if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)
2623 return buf_size;
2624
2625 ret = ff_progress_frame_get_buffer(avctx, &s->last_frame,
2627 if (ret < 0) {
2628 // Don't goto error here, as one can't report progress on or
2629 // unref a non-existent frame.
2630 return ret;
2631 }
2632 FFSWAP(ProgressFrame, s->last_frame, s->current_frame);
2633 s->current_frame.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I
2635 if (s->keyframe)
2636 s->current_frame.f->flags |= AV_FRAME_FLAG_KEY;
2637 else
2638 s->current_frame.f->flags &= ~AV_FRAME_FLAG_KEY;
2639
2640 if (!s->edge_emu_buffer) {
2641 s->edge_emu_buffer = av_malloc(9 * FFABS(s->current_frame.f->linesize[0]));
2642 if (!s->edge_emu_buffer) {
2643 ret = AVERROR(ENOMEM);
2644 goto error;
2645 }
2646 }
2647
2648 if (s->keyframe) {
2649 if (!s->theora) {
2650 skip_bits(&gb, 4); /* width code */
2651 skip_bits(&gb, 4); /* height code */
2652 if (s->version) {
2653 int version = get_bits(&gb, 5);
2654#if !CONFIG_VP4_DECODER
2655 if (version >= 2) {
2656 av_log(avctx, AV_LOG_ERROR, "This build does not support decoding VP4.\n");
2658 goto error;
2659 }
2660#endif
2661 s->version = version;
2662 if (avctx->frame_num == 0)
2663 av_log(s->avctx, AV_LOG_DEBUG,
2664 "VP version: %d\n", s->version);
2665 }
2666 }
2667 if (s->version || s->theora) {
2668 if (get_bits1(&gb))
2669 av_log(s->avctx, AV_LOG_ERROR,
2670 "Warning, unsupported keyframe coding type?!\n");
2671 skip_bits(&gb, 2); /* reserved? */
2672
2673#if CONFIG_VP4_DECODER
2674 if (s->version >= 2) {
2675 int mb_height, mb_width;
2676 int mb_width_mul, mb_width_div, mb_height_mul, mb_height_div;
2677
2678 mb_height = get_bits(&gb, 8);
2679 mb_width = get_bits(&gb, 8);
2680 if (mb_height != s->macroblock_height ||
2681 mb_width != s->macroblock_width)
2682 avpriv_request_sample(s->avctx, "macroblock dimension mismatch");
2683
2684 mb_width_mul = get_bits(&gb, 5);
2685 mb_width_div = get_bits(&gb, 3);
2686 mb_height_mul = get_bits(&gb, 5);
2687 mb_height_div = get_bits(&gb, 3);
2688 if (mb_width_mul != 1 || mb_width_div != 1 || mb_height_mul != 1 || mb_height_div != 1)
2689 avpriv_request_sample(s->avctx, "unexpected macroblock dimension multiplier/divider");
2690
2691 if (get_bits(&gb, 2))
2692 avpriv_request_sample(s->avctx, "unknown bits");
2693 }
2694#endif
2695 }
2696 ff_progress_frame_replace(&s->golden_frame, &s->current_frame);
2697 } else {
2698 if (!s->golden_frame.f) {
2699 av_log(s->avctx, AV_LOG_WARNING,
2700 "vp3: first frame not a keyframe\n");
2701
2702 if ((ret = ff_progress_frame_get_buffer(avctx, &s->golden_frame,
2704 goto error;
2705 s->golden_frame.f->pict_type = AV_PICTURE_TYPE_I;
2706 ff_progress_frame_replace(&s->last_frame, &s->golden_frame);
2707 ff_progress_frame_report(&s->golden_frame, INT_MAX);
2708 }
2709 }
2711
2712 memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment));
2713
2714 if (s->version < 2) {
2715 if ((ret = unpack_superblocks(s, &gb)) < 0) {
2716 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");
2717 goto error;
2718 }
2719#if CONFIG_VP4_DECODER
2720 } else {
2721 if ((ret = vp4_unpack_macroblocks(s, &gb)) < 0) {
2722 av_log(s->avctx, AV_LOG_ERROR, "error in vp4_unpack_macroblocks\n");
2723 goto error;
2724 }
2725#endif
2726 }
2727 if ((ret = unpack_modes(s, &gb)) < 0) {
2728 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");
2729 goto error;
2730 }
2731 if (ret = unpack_vectors(s, &gb)) {
2732 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");
2733 goto error;
2734 }
2735 if ((ret = unpack_block_qpis(s, &gb)) < 0) {
2736 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n");
2737 goto error;
2738 }
2739
2740 if (s->version < 2) {
2741 if ((ret = unpack_dct_coeffs(s, &gb)) < 0) {
2742 av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");
2743 goto error;
2744 }
2745#if CONFIG_VP4_DECODER
2746 } else {
2747 if ((ret = vp4_unpack_dct_coeffs(s, &gb)) < 0) {
2748 av_log(s->avctx, AV_LOG_ERROR, "error in vp4_unpack_dct_coeffs\n");
2749 goto error;
2750 }
2751#endif
2752 }
2753
2754 for (int i = 0; i < 3; i++) {
2755 int height = s->height >> (i && s->chroma_y_shift);
2756 if (s->flipped_image)
2757 s->data_offset[i] = 0;
2758 else
2759 s->data_offset[i] = (height - 1) * s->current_frame.f->linesize[i];
2760 }
2761
2762 s->last_slice_end = 0;
2763 for (int i = 0; i < s->c_superblock_height; i++)
2764 render_slice(s, i);
2765
2766 // filter the last row
2767 if (s->version < 2)
2768 for (int i = 0; i < 3; i++) {
2769 int row = (s->height >> (3 + (i && s->chroma_y_shift))) - 1;
2770 apply_loop_filter(s, i, row, row + 1);
2771 }
2772 vp3_draw_horiz_band(s, s->height);
2773
2774 ff_progress_frame_unref(&s->last_frame);
2775
2776 /* output frame, offset as needed */
2777 if ((ret = av_frame_ref(frame, s->current_frame.f)) < 0)
2778 return ret;
2779
2780 frame->crop_left = s->offset_x;
2781 frame->crop_right = avctx->coded_width - avctx->width - s->offset_x;
2782 frame->crop_top = s->offset_y;
2783 frame->crop_bottom = avctx->coded_height - avctx->height - s->offset_y;
2784
2785 *got_frame = 1;
2786
2787 return buf_size;
2788
2789error:
2790 ff_progress_frame_report(&s->current_frame, INT_MAX);
2791 ff_progress_frame_unref(&s->last_frame);
2792
2793 return ret;
2794}
2795
2796static int read_huffman_tree(HuffTable *huff, GetBitContext *gb, int length,
2797 AVCodecContext *avctx)
2798{
2799 if (get_bits1(gb)) {
2800 int token;
2801 if (huff->nb_entries >= 32) { /* overflow */
2802 av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
2803 return -1;
2804 }
2805 token = get_bits(gb, 5);
2806 ff_dlog(avctx, "code length %d, curr entry %d, token %d\n",
2807 length, huff->nb_entries, token);
2808 huff->entries[huff->nb_entries++] = (HuffEntry){ length, token };
2809 } else {
2810 /* The following bound follows from the fact that nb_entries <= 32. */
2811 if (length >= 31) { /* overflow */
2812 av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n");
2813 return -1;
2814 }
2815 length++;
2816 if (read_huffman_tree(huff, gb, length, avctx))
2817 return -1;
2818 if (read_huffman_tree(huff, gb, length, avctx))
2819 return -1;
2820 }
2821 return 0;
2822}
2823
2824#if CONFIG_THEORA_DECODER
2825static const enum AVPixelFormat theora_pix_fmts[4] = {
2827};
2828
2830{
2831 Vp3DecodeContext *s = avctx->priv_data;
2832 int visible_width, visible_height, colorspace;
2833 uint8_t offset_x = 0, offset_y = 0;
2834 int ret;
2835 AVRational fps, aspect;
2836
2837 if (get_bits_left(gb) < 206)
2838 return AVERROR_INVALIDDATA;
2839
2840 s->theora_header = 0;
2841 s->theora = get_bits(gb, 24);
2842 av_log(avctx, AV_LOG_DEBUG, "Theora bitstream version %X\n", s->theora);
2843 if (!s->theora) {
2844 s->theora = 1;
2845 avpriv_request_sample(s->avctx, "theora 0");
2846 }
2847
2848 /* 3.2.0 aka alpha3 has the same frame orientation as original vp3
2849 * but previous versions have the image flipped relative to vp3 */
2850 if (s->theora < 0x030200) {
2851 s->flipped_image = 1;
2852 av_log(avctx, AV_LOG_DEBUG,
2853 "Old (<alpha3) Theora bitstream, flipped image\n");
2854 }
2855
2856 visible_width =
2857 s->width = get_bits(gb, 16) << 4;
2858 visible_height =
2859 s->height = get_bits(gb, 16) << 4;
2860
2861 if (s->theora >= 0x030200) {
2862 visible_width = get_bits(gb, 24);
2863 visible_height = get_bits(gb, 24);
2864
2865 offset_x = get_bits(gb, 8); /* offset x */
2866 offset_y = get_bits(gb, 8); /* offset y, from bottom */
2867 }
2868
2869 /* sanity check */
2870 if (av_image_check_size(visible_width, visible_height, 0, avctx) < 0 ||
2871 visible_width + offset_x > s->width ||
2872 visible_height + offset_y > s->height ||
2873 visible_width + 512 < s->width ||
2874 visible_height + 512 < s->height ||
2875 visible_width < 18
2876 ) {
2877 av_log(avctx, AV_LOG_ERROR,
2878 "Invalid frame dimensions - w:%d h:%d x:%d y:%d (%dx%d).\n",
2879 visible_width, visible_height, offset_x, offset_y,
2880 s->width, s->height);
2881 return AVERROR_INVALIDDATA;
2882 }
2883
2884 fps.num = get_bits_long(gb, 32);
2885 fps.den = get_bits_long(gb, 32);
2886 if (fps.num && fps.den) {
2887 if (fps.num < 0 || fps.den < 0) {
2888 av_log(avctx, AV_LOG_ERROR, "Invalid framerate\n");
2889 return AVERROR_INVALIDDATA;
2890 }
2891 av_reduce(&avctx->framerate.den, &avctx->framerate.num,
2892 fps.den, fps.num, 1 << 30);
2893 }
2894
2895 aspect.num = get_bits(gb, 24);
2896 aspect.den = get_bits(gb, 24);
2897 if (aspect.num && aspect.den) {
2899 &avctx->sample_aspect_ratio.den,
2900 aspect.num, aspect.den, 1 << 30);
2901 ff_set_sar(avctx, avctx->sample_aspect_ratio);
2902 }
2903
2904 if (s->theora < 0x030200)
2905 skip_bits(gb, 5); /* keyframe frequency force */
2906 colorspace = get_bits(gb, 8);
2907 skip_bits(gb, 24); /* bitrate */
2908
2909 skip_bits(gb, 6); /* quality hint */
2910
2911 if (s->theora >= 0x030200) {
2912 skip_bits(gb, 5); /* keyframe frequency force */
2913 avctx->pix_fmt = theora_pix_fmts[get_bits(gb, 2)];
2914 if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
2915 av_log(avctx, AV_LOG_ERROR, "Invalid pixel format\n");
2916 return AVERROR_INVALIDDATA;
2917 }
2918 skip_bits(gb, 3); /* reserved */
2919 } else
2920 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
2921
2922 if (s->width < 18)
2923 return AVERROR_PATCHWELCOME;
2924 ret = ff_set_dimensions(avctx, s->width, s->height);
2925 if (ret < 0)
2926 return ret;
2927 if (!(avctx->flags2 & AV_CODEC_FLAG2_IGNORE_CROP)) {
2928 avctx->width = visible_width;
2929 avctx->height = visible_height;
2930 // translate offsets from theora axis ([0,0] lower left)
2931 // to normal axis ([0,0] upper left)
2932 s->offset_x = offset_x;
2933 s->offset_y = s->height - visible_height - offset_y;
2934 }
2935
2936 if (colorspace == 1)
2938 else if (colorspace == 2)
2940
2941 if (colorspace == 1 || colorspace == 2) {
2943 avctx->color_trc = AVCOL_TRC_BT709;
2944 }
2945
2946 s->theora_header = 1;
2947 return 0;
2948}
2949
2951{
2952 Vp3DecodeContext *s = avctx->priv_data;
2953 int n, matrices, ret;
2954
2955 if (!s->theora_header)
2956 return AVERROR_INVALIDDATA;
2957
2958 if (s->theora >= 0x030200) {
2959 n = get_bits(gb, 3);
2960 /* loop filter limit values table */
2961 if (n)
2962 for (int i = 0; i < 64; i++)
2963 s->filter_limit_values[i] = get_bits(gb, n);
2964 }
2965
2966 if (s->theora >= 0x030200)
2967 n = get_bits(gb, 4) + 1;
2968 else
2969 n = 16;
2970 /* quality threshold table */
2971 for (int i = 0; i < 64; i++)
2972 s->coded_ac_scale_factor[i] = get_bits(gb, n);
2973
2974 if (s->theora >= 0x030200)
2975 n = get_bits(gb, 4) + 1;
2976 else
2977 n = 16;
2978 /* dc scale factor table */
2979 for (int i = 0; i < 64; i++)
2980 s->coded_dc_scale_factor[0][i] =
2981 s->coded_dc_scale_factor[1][i] = get_bits(gb, n);
2982
2983 if (s->theora >= 0x030200)
2984 matrices = get_bits(gb, 9) + 1;
2985 else
2986 matrices = 3;
2987
2988 if (matrices > 384) {
2989 av_log(avctx, AV_LOG_ERROR, "invalid number of base matrixes\n");
2990 return -1;
2991 }
2992
2993 for (int j = 0; j < matrices; j++)
2994 for (int i = 0; i < 64; i++)
2995 s->base_matrix[j][i] = get_bits(gb, 8);
2996
2997 for (int inter = 0; inter <= 1; inter++) {
2998 for (int plane = 0; plane <= 2; plane++) {
2999 int newqr = 1;
3000 if (inter || plane > 0)
3001 newqr = get_bits1(gb);
3002 if (!newqr) {
3003 int qtj, plj;
3004 if (inter && get_bits1(gb)) {
3005 qtj = 0;
3006 plj = plane;
3007 } else {
3008 qtj = (3 * inter + plane - 1) / 3;
3009 plj = (plane + 2) % 3;
3010 }
3011 s->qr_count[inter][plane] = s->qr_count[qtj][plj];
3012 memcpy(s->qr_size[inter][plane], s->qr_size[qtj][plj],
3013 sizeof(s->qr_size[0][0]));
3014 memcpy(s->qr_base[inter][plane], s->qr_base[qtj][plj],
3015 sizeof(s->qr_base[0][0]));
3016 } else {
3017 int qri = 0;
3018 int qi = 0;
3019
3020 for (;;) {
3021 int i = get_bits(gb, av_log2(matrices - 1) + 1);
3022 if (i >= matrices) {
3023 av_log(avctx, AV_LOG_ERROR,
3024 "invalid base matrix index\n");
3025 return -1;
3026 }
3027 s->qr_base[inter][plane][qri] = i;
3028 if (qi >= 63)
3029 break;
3030 i = get_bits(gb, av_log2(63 - qi) + 1) + 1;
3031 s->qr_size[inter][plane][qri++] = i;
3032 qi += i;
3033 }
3034
3035 if (qi > 63) {
3036 av_log(avctx, AV_LOG_ERROR, "invalid qi %d > 63\n", qi);
3037 return -1;
3038 }
3039 s->qr_count[inter][plane] = qri;
3040 }
3041 }
3042 }
3043
3044 /* Huffman tables */
3045 for (int i = 0; i < FF_ARRAY_ELEMS(s->huffman_table); i++) {
3046 s->huffman_table[i].nb_entries = 0;
3047 if ((ret = read_huffman_tree(&s->huffman_table[i], gb, 0, avctx)) < 0)
3048 return ret;
3049 }
3050
3051 s->theora_tables = 1;
3052
3053 return 0;
3054}
3055
3056static av_cold int theora_decode_init(AVCodecContext *avctx)
3057{
3058 Vp3DecodeContext *s = avctx->priv_data;
3059 GetBitContext gb;
3060 int ptype;
3061 const uint8_t *header_start[3];
3062 int header_len[3];
3063 int ret;
3064
3065 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
3066
3067 s->theora = 1;
3068
3069 if (!avctx->extradata_size) {
3070 av_log(avctx, AV_LOG_ERROR, "Missing extradata!\n");
3071 return -1;
3072 }
3073
3075 42, header_start, header_len) < 0) {
3076 av_log(avctx, AV_LOG_ERROR, "Corrupt extradata\n");
3077 return -1;
3078 }
3079
3080 for (int i = 0; i < 3; i++) {
3081 if (header_len[i] <= 0)
3082 continue;
3083 ret = init_get_bits8(&gb, header_start[i], header_len[i]);
3084 if (ret < 0)
3085 return ret;
3086
3087 ptype = get_bits(&gb, 8);
3088
3089 if (!(ptype & 0x80)) {
3090 av_log(avctx, AV_LOG_ERROR, "Invalid extradata!\n");
3091// return -1;
3092 }
3093
3094 // FIXME: Check for this as well.
3095 skip_bits_long(&gb, 6 * 8); /* "theora" */
3096
3097 switch (ptype) {
3098 case 0x80:
3099 if (theora_decode_header(avctx, &gb) < 0)
3100 return -1;
3101 break;
3102 case 0x81:
3103// FIXME: is this needed? it breaks sometimes
3104// theora_decode_comments(avctx, gb);
3105 break;
3106 case 0x82:
3107 if (theora_decode_tables(avctx, &gb))
3108 return -1;
3109 break;
3110 default:
3111 av_log(avctx, AV_LOG_ERROR,
3112 "Unknown Theora config packet: %d\n", ptype & ~0x80);
3113 break;
3114 }
3115 if (ptype != 0x81 && get_bits_left(&gb) >= 8U)
3116 av_log(avctx, AV_LOG_WARNING,
3117 "%d bits left in packet %X\n",
3118 get_bits_left(&gb), ptype);
3119 if (s->theora < 0x030200)
3120 break;
3121 }
3122
3123 return vp3_decode_init(avctx);
3124}
3125
3126const FFCodec ff_theora_decoder = {
3127 .p.name = "theora",
3128 CODEC_LONG_NAME("Theora"),
3129 .p.type = AVMEDIA_TYPE_VIDEO,
3130 .p.id = AV_CODEC_ID_THEORA,
3131 .priv_data_size = sizeof(Vp3DecodeContext),
3132 .init = theora_decode_init,
3137 .flush = vp3_decode_flush,
3138 UPDATE_THREAD_CONTEXT(vp3_update_thread_context),
3139 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
3142};
3143#endif
3144
3146 .p.name = "vp3",
3147 CODEC_LONG_NAME("On2 VP3"),
3148 .p.type = AVMEDIA_TYPE_VIDEO,
3149 .p.id = AV_CODEC_ID_VP3,
3150 .priv_data_size = sizeof(Vp3DecodeContext),
3156 .flush = vp3_decode_flush,
3157 UPDATE_THREAD_CONTEXT(vp3_update_thread_context),
3158 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
3160};
3161
3162#if CONFIG_VP4_DECODER
3163const FFCodec ff_vp4_decoder = {
3164 .p.name = "vp4",
3165 CODEC_LONG_NAME("On2 VP4"),
3166 .p.type = AVMEDIA_TYPE_VIDEO,
3167 .p.id = AV_CODEC_ID_VP4,
3168 .priv_data_size = sizeof(Vp3DecodeContext),
3174 .flush = vp3_decode_flush,
3175 UPDATE_THREAD_CONTEXT(vp3_update_thread_context),
3176 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
3178};
3179#endif
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
const FFCodec ff_theora_decoder
const FFCodec ff_vp3_decoder
Definition vp3.c:3145
const FFCodec ff_vp4_decoder
static const VLCElem * coeff_vlc[2][8][4]
Definition atrac9dec.c:110
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
Libavcodec external API header.
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition avcodec.h:1600
#define FF_DEBUG_PICT_INFO
Definition avcodec.h:1399
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define bit(string, value)
Definition cbs_mpeg2.c:56
#define s(width, name)
Definition cbs_vp9.c:198
#define UPDATE_THREAD_CONTEXT(func)
#define FF_CODEC_CAP_EXPORTS_CROPPING
The decoder sets the cropping fields in the output frames manually.
#define FF_CODEC_CAP_USES_PROGRESSFRAMES
The decoder might make use of the ProgressFrame API.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define av_clip
Definition common.h:100
#define RSHIFT(a, b)
Definition common.h:56
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define FFSIGN(a)
Definition common.h:75
#define NULL
Definition coverity.c:32
static int16_t block[64]
Definition dct.c:125
void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
Do nothing if dst and src already refer to the same AVFrame; otherwise unreference dst and if src is ...
Definition decode.c:2006
void ff_progress_frame_await(const ProgressFrame *f, int n)
Wait for earlier decoding threads to finish reference frames.
Definition decode.c:2021
void ff_progress_frame_report(ProgressFrame *f, int n)
Notify later decoding threads when part of their reference frame is ready.
Definition decode.c:2016
enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.
Definition decode.c:2027
int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
Definition decode.c:1976
void ff_progress_frame_unref(ProgressFrame *f)
Give up a reference to the underlying frame contained in a ProgressFrame and reset the ProgressFrame,...
Definition decode.c:1999
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition utils.c:106
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
perm
Definition f_perms.c:75
static const uint8_t bits[8]
Definition fastaudio.c:100
int ret
Definition ffplay.c:391
static int loop
Definition ffplay.c:367
#define AV_NUM_DATA_POINTERS
Definition frame.h:480
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition get_bits.h:424
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition get_bits.h:645
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static void skip_bits(GetBitContext *s, int n)
Definition get_bits.h:383
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition get_bits.h:373
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition codec.h:41
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition avcodec.h:322
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition avcodec.h:415
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition avcodec.h:302
#define AV_CODEC_FLAG2_IGNORE_CROP
Discard cropping information from SPS.
Definition avcodec.h:355
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_VP3
Definition codec_id.h:79
@ AV_CODEC_ID_THEORA
Definition codec_id.h:80
@ AV_CODEC_ID_VP4
Definition codec_id.h:291
@ AVDISCARD_ALL
discard all
Definition defs.h:248
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition defs.h:247
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition error.h:54
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:694
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:281
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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:318
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
#define PL(y)
static const int8_t transform[32][32]
Definition dsp.c:27
Half-pel DSP functions.
static VLCElem vlc_tables[VLC_TABLES_SIZE]
Definition imc.c:115
misc image utilities
static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst, ptrdiff_t dst_pitch, int dst_height)
Convert and output the current plane.
Definition indeo3.c:1037
#define av_log2
Definition intmath.h:84
enum MPFType type
Definition jpegmpfenc.c:55
const uint8_t ff_mjpeg_std_chrominance_quant_tbl[64]
unsigned offset
Definition libaomenc.c:763
enum TrimAxis axis
Definition trim.c:49
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
Definition hpeldsp.c:337
Multithreading API for decoders.
@ FF_THREAD_IS_COPY
Definition thread.h:61
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition videodsp.c:39
void ff_vp3dsp_set_bounding_values(int *bounding_values_array, int filter_limit)
Definition vp3dsp.c:477
av_cold void ff_vp3dsp_init(VP3DSPContext *c)
Definition vp3dsp.c:448
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_cold
Definition attributes.h:117
#define AVOnce
Definition thread.h:202
static int ff_thread_once(char *control, void(*routine)(void))
Definition thread.h:205
#define AV_ONCE_INIT
Definition thread.h:203
version
Definition libkvazaar.c:313
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
const uint8_t ff_zigzag_direct[64]
Definition mathtables.c:137
static void body(uint32_t ABCD[4], const uint8_t *src, size_t nblocks)
Definition md5.c:103
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const char * obj
Definition mscl.c:57
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define av_malloc(s)
Definition ops_static.c:52
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition pixdesc.c:3512
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition pixfmt.h:814
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition pixfmt.h:654
@ AVCOL_PRI_BT470M
also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition pixfmt.h:652
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition pixfmt.h:679
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition pixfmt.h:717
#define PU(x)
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
Definition refstruct.h:94
#define FF_ARRAY_ELEMS(a)
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:644
int width
picture width / height.
Definition avcodec.h:605
int flags2
AV_CODEC_FLAG2_*.
Definition avcodec.h:507
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition avcodec.h:468
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:658
int64_t frame_num
Frame counter, set by libavcodec.
Definition avcodec.h:1893
AVRational framerate
Definition avcodec.h:563
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:629
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
Definition avcodec.h:1663
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:672
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:665
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:692
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:620
void * priv_data
Definition avcodec.h:470
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition avcodec.h:1677
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
This structure stores compressed data.
Definition packet.h:587
int size
Definition packet.h:611
uint8_t * data
Definition packet.h:610
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
VLC vlcs[80]
Definition vp3.c:194
const VLCElem * vlc_tabs[80]
Definition vp3.c:193
Half-pel DSP context.
Definition hpeldsp.h:46
uint8_t len
Definition exr.c:96
uint16_t sym
Definition exr.c:97
HuffEntry entries[32]
Definition vp3.c:188
uint8_t nb_entries
Definition vp3.c:189
The ProgressFrame structure.
Definition vlc.h:32
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
Definition vlc.h:220
Definition vlc.h:50
VLCElem * table
Definition vlc.h:52
int dc
Definition vp3.c:177
int type
Definition vp3.c:178
uint16_t coded_dc_scale_factor[2][64]
Definition vp3.c:253
VideoDSPContext vdsp
Definition vp3.c:210
int num_coded_frags[3][64]
number of blocks that contain DCT coefficients at the given level or higher
Definition vp3.c:287
int macroblock_height
Definition vp3.c:233
CoeffVLCs * coeff_vlc
The first 16 of the following VLCs are for the dc coefficients; the others are four groups of 16 VLCs...
Definition vp3.c:303
ProgressFrame golden_frame
Definition vp3.c:203
int flipped_image
Definition vp3.c:213
int8_t(*[2] motion_val)[2]
Definition vp3.c:250
int theora_header
Definition vp3.c:199
uint8_t base_matrix[384][64]
Definition vp3.c:255
int c_superblock_width
Definition vp3.c:224
int theora_tables
Definition vp3.c:199
int c_superblock_count
Definition vp3.c:226
int * kf_coded_fragment_list
Definition vp3.c:294
int last_slice_end
Definition vp3.c:214
int offset_x_warned
Definition vp3.c:248
int chroma_y_shift
Definition vp3.c:202
VP4Predictor * dc_pred_row
Definition vp3.c:327
uint32_t coded_ac_scale_factor[64]
Definition vp3.c:254
int y_superblock_height
Definition vp3.c:222
int yuv_macroblock_count
Definition vp3.c:237
int16_t * dct_tokens_base
Definition vp3.c:278
int fragment_start[3]
Definition vp3.c:244
uint8_t idct_permutation[64]
Definition vp3.c:207
int16_t block[64]
Definition vp3.c:212
AVCodecContext * avctx
Definition vp3.c:198
int chroma_x_shift
Definition vp3.c:202
ProgressFrame current_frame
Definition vp3.c:205
int c_macroblock_height
Definition vp3.c:236
unsigned char * macroblock_coding
Definition vp3.c:317
int c_macroblock_width
Definition vp3.c:235
uint8_t * edge_emu_buffer
Definition vp3.c:319
int c_superblock_height
Definition vp3.c:225
int fragment_width[2]
Definition vp3.c:240
int num_kf_coded_fragment[3]
Definition vp3.c:296
int skip_loop_filter
Definition vp3.c:215
int * coded_fragment_list[3]
Definition vp3.c:292
int bounding_values_array[256+4]
Definition vp3.c:325
int total_num_coded_frags
Definition vp3.c:288
HuffTable huffman_table[5 *16]
Definition vp3.c:322
int macroblock_width
Definition vp3.c:232
uint8_t filter_limit_values[64]
Definition vp3.c:324
int qps[3]
Definition vp3.c:217
int fragment_count
Definition vp3.c:239
int16_t * dct_tokens[3][64]
This is a list of all tokens in bitstream order.
Definition vp3.c:277
ProgressFrame last_frame
Definition vp3.c:204
Vp3Fragment * all_fragments
Definition vp3.c:243
unsigned char * superblock_coding
Definition vp3.c:229
int macroblock_count
Definition vp3.c:231
int * nkf_coded_fragment_list
Definition vp3.c:295
uint8_t qr_count[2][3]
Definition vp3.c:256
uint8_t qr_size[2][3][64]
Definition vp3.c:257
int fragment_height[2]
Definition vp3.c:241
int y_superblock_width
Definition vp3.c:221
int16_t qmat[3][2][3][64]
qmat[qpi][is_inter][plane]
Definition vp3.c:307
uint8_t idct_scantable[64]
Definition vp3.c:208
HpelDSPContext hdsp
Definition vp3.c:209
int y_superblock_count
Definition vp3.c:223
uint8_t offset_y
Definition vp3.c:247
int superblock_count
Definition vp3.c:220
uint16_t qr_base[2][3][64]
Definition vp3.c:258
uint8_t offset_x
Definition vp3.c:246
VP3DSPContext vp3dsp
Definition vp3.c:211
int v_superblock_start
Definition vp3.c:228
int data_offset[3]
Definition vp3.c:245
int * superblock_fragments
Definition vp3.c:313
int c_macroblock_count
Definition vp3.c:234
int u_superblock_start
Definition vp3.c:227
uint8_t qpi
Definition vp3.c:70
int16_t dc
Definition vp3.c:68
uint8_t coding_method
Definition vp3.c:69
#define stride
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define ff_dlog(a,...)
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_log(a,...)
static void error(const char *err)
#define src
Definition vp8dsp.c:248
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99
static struct @232240247175332074307271266321204261331170211232 state
static const uint8_t *const tables[]
static const struct twinvq_data tab
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
else temp
Definition vf_mcdeint.c:275
Core video DSP helper functions.
int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
Definition vlc.c:306
av_cold const VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
Definition vlc.c:366
void ff_vlc_free(VLC *vlc)
Definition vlc.c:580
#define VLC_INIT_STATE(_table)
Definition vlc.h:225
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
Definition vlc.h:288
static const VLCElem * ff_vlc_init_tables(VLCInitState *state, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, int flags)
Definition vlc.h:254
static int vp4_get_mv(GetBitContext *gb, int axis, int last_motion)
Definition vp3.c:886
static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb)
#define SB_FULLY_CODED
Definition vp3.c:75
static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb)
Definition vp3.c:1099
@ VP4_DC_GOLDEN
Definition vp3.c:148
@ VP4_DC_INTER
Definition vp3.c:147
@ VP4_DC_UNDEFINED
Definition vp3.c:150
@ VP4_DC_INTRA
Definition vp3.c:146
@ NB_VP4_DC_TYPES
Definition vp3.c:149
#define CODING_MODE_COUNT
Definition vp3.c:90
#define MODE_INTRA
Definition vp3.c:83
#define DC_COEFF(u)
Definition vp3.c:1631
#define MODE_GOLDEN_MV
Definition vp3.c:88
#define BLOCK_X
Definition vp3.c:640
static av_cold int vp3_decode_init(AVCodecContext *avctx)
Definition vp3.c:2352
#define COMPATIBLE_FRAME(x)
Definition vp3.c:1629
static void init_loop_filter(Vp3DecodeContext *s)
Definition vp3.c:458
#define MODE_INTER_PRIOR_LAST
Definition vp3.c:86
static int get_eob_run(GetBitContext *gb, int token)
Definition vp3.c:1142
static void reverse_dc_prediction(Vp3DecodeContext *s, int first_fragment, int fragment_width, int fragment_height)
Definition vp3.c:1633
#define TOKEN_EOB(eob_run)
Definition vp3.c:279
static void init_dequantizer(Vp3DecodeContext *s, int qpi)
Definition vp3.c:416
static VLCElem motion_vector_vlc[112]
Definition vp3.c:166
static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
Definition vp3.c:901
static av_cold int allocate_tables(AVCodecContext *avctx)
Allocate tables for per-frame data in Vp3DecodeContext.
Definition vp3.c:2300
#define MODE_COPY
Definition vp3.c:93
static av_cold void free_vlc_tables(AVRefStructOpaque unused, void *obj)
Definition vp3.c:2344
static VLCElem mode_code_vlc[24+2108 *CONFIG_VP4_DECODER]
Definition vp3.c:169
static av_cold void free_tables(AVCodecContext *avctx)
Definition vp3.c:334
static int vp3_dequant(Vp3DecodeContext *s, const Vp3Fragment *frag, int plane, int inter, int16_t block[64])
Pull DCT tokens from the 64 levels to decode and dequant the coefficients for the next block in codin...
Definition vp3.c:1848
#define MODE_INTER_LAST_MV
Definition vp3.c:85
#define VP3_MV_VLC_BITS
Definition vp3.c:60
static av_cold void vp3_decode_flush(AVCodecContext *avctx)
Definition vp3.c:350
#define MAXIMUM_LONG_BIT_RUN
Definition vp3.c:80
static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, const VLCElem *vlc_table, int coeff_index, int plane, int eob_run)
Definition vp3.c:1178
static void render_slice(Vp3DecodeContext *s, int slice)
Definition vp3.c:2051
#define MODE_INTER_FOURMV
Definition vp3.c:89
#define VP4_MV_VLC_BITS
Definition vp3.c:61
#define SB_PARTIALLY_CODED
Definition vp3.c:74
#define PUL
static void await_reference_row(Vp3DecodeContext *s, const Vp3Fragment *fragment, int motion_y, int y)
Wait for the reference frame of the current fragment.
Definition vp3.c:1930
static int read_huffman_tree(HuffTable *huff, GetBitContext *gb, int length, AVCodecContext *avctx)
Definition vp3.c:2796
static VLCElem superblock_run_length_vlc[88]
Definition vp3.c:164
static const uint8_t vp4_pred_block_type_map[8]
Definition vp3.c:153
#define SUPERBLOCK_VLC_BITS
Definition vp3.c:62
#define SB_NOT_CODED
Definition vp3.c:73
static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
Definition vp3.c:783
#define BLOCK_Y
Definition vp3.c:641
static av_cold int vp3_decode_end(AVCodecContext *avctx)
Definition vp3.c:359
static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
Definition vp3.c:1298
#define MODE_USING_GOLDEN
Definition vp3.c:87
static int init_block_mapping(Vp3DecodeContext *s)
This function sets up all of the various blocks mappings: superblocks <-> fragments,...
Definition vp3.c:383
#define MODE_INTER_PLUS_MV
Definition vp3.c:84
#define SET_CHROMA_MODES
static const int ModeAlphabet[6][CODING_MODE_COUNT]
Definition vp3.c:100
static av_cold void init_tables_once(void)
Definition vp3.c:2257
#define MODE_INTER_NO_MV
Definition vp3.c:82
#define PUR
static int get_coeff(GetBitContext *gb, int token, int16_t *coeff)
Definition vp3.c:1150
static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int yend)
Definition vp3.c:1782
static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition vp3.c:2536
#define TRANSPOSE(x)
#define TOKEN_COEFF(coeff)
Definition vp3.c:281
static const uint8_t hilbert_offset[16][2]
Definition vp3.c:138
#define TOKEN_ZERO_RUN(coeff, zero_run)
Definition vp3.c:280
static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y)
called when all pixels up to row y are complete
Definition vp3.c:1893
static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
Definition vp3.c:467
#define FRAGMENT_PIXELS
Definition vp3.c:64
static VLCElem fragment_run_length_vlc[56]
Definition vp3.c:165
static const uint8_t zero_run_get_bits[32]
Definition vp3data.h:140
static const uint8_t vp31_filter_limit_values[64]
Definition vp3data.h:74
static const uint16_t vp31_ac_scale_factor[64]
Definition vp3data.h:63
static const uint8_t mode_code_vlc_len[8]
Definition vp3data.h:97
static const uint8_t zero_run_base[32]
Definition vp3data.h:133
static const int8_t fixed_motion_vector_table[64]
Definition vp3data.h:115
static const int16_t *const coeff_tables[32]
Definition vp3data.h:332
static const uint8_t vp31_dc_scale_factor[64]
Definition vp3data.h:52
static const uint8_t vp3_bias[5 *16][32][2]
Definition vp3data.h:370
static const uint8_t fragment_run_length_vlc_len[30]
Definition vp3data.h:92
static const uint8_t vp31_intra_y_dequant[64]
Definition vp3data.h:29
static const struct @370321105316032037314210141206274253244133335364 eob_run_table[7]
static const uint8_t vp31_inter_dequant[64]
Definition vp3data.h:41
uint8_t base
Definition vp3data.h:128
static const uint8_t coeff_get_bits[32]
Definition vp3data.h:148
static const uint8_t motion_vector_vlc_table[63][2]
Definition vp3data.h:101
static const uint8_t superblock_run_length_vlc_lens[34]
Definition vp3data.h:85
void ff_vp3dsp_h_loop_filter_12(uint8_t *first_pixel, ptrdiff_t stride, int *bounding_values)
void ff_vp3dsp_v_loop_filter_12(uint8_t *first_pixel, ptrdiff_t stride, int *bounding_values)
VP4 video decoder.
static const uint8_t vp4_mv_vlc[2][7][63][2]
Definition vp4data.h:112
static const uint8_t vp4_filter_limit_values[64]
Definition vp4data.h:75
static const uint8_t vp4_uv_dc_scale_factor[64]
Definition vp4data.h:53
static const uint8_t vp4_block_pattern_table_selector[14]
Definition vp4data.h:86
static const uint8_t vp4_mv_table_selector[32]
Definition vp4data.h:105
static const uint8_t vp4_block_pattern_vlc[2][14][2]
Definition vp4data.h:90
static const uint16_t vp4_ac_scale_factor[64]
Definition vp4data.h:64
static const uint8_t vp4_bias[5 *16][32][2]
Definition vp4data.h:329
static const uint8_t vp4_generic_dequant[64]
Definition vp4data.h:31
static const uint8_t vp4_y_dc_scale_factor[64]
Definition vp4data.h:42
static int ref_frame(VVCFrame *dst, const VVCFrame *src)
Definition dec.c:619
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.
Definition xiph.c:26