/libavcodec/vp3.c
http://github.com/FFmpeg/FFmpeg · C · 3260 lines · 2458 code · 454 blank · 348 comment · 614 complexity · 503483eb2da5ccc94c391a2e91805d76 MD5 · raw file
Large files are truncated click here to view the full file
- /*
- * Copyright (C) 2003-2004 The FFmpeg project
- * Copyright (C) 2019 Peter Ross
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
- /**
- * @file
- * On2 VP3/VP4 Video Decoder
- *
- * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx)
- * For more information about the VP3 coding process, visit:
- * http://wiki.multimedia.cx/index.php?title=On2_VP3
- *
- * Theora decoder by Alex Beregszaszi
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "libavutil/imgutils.h"
- #include "avcodec.h"
- #include "get_bits.h"
- #include "hpeldsp.h"
- #include "internal.h"
- #include "mathops.h"
- #include "thread.h"
- #include "videodsp.h"
- #include "vp3data.h"
- #include "vp4data.h"
- #include "vp3dsp.h"
- #include "xiph.h"
- #define FRAGMENT_PIXELS 8
- // FIXME split things out into their own arrays
- typedef struct Vp3Fragment {
- int16_t dc;
- uint8_t coding_method;
- uint8_t qpi;
- } Vp3Fragment;
- #define SB_NOT_CODED 0
- #define SB_PARTIALLY_CODED 1
- #define SB_FULLY_CODED 2
- // This is the maximum length of a single long bit run that can be encoded
- // for superblock coding or block qps. Theora special-cases this to read a
- // bit instead of flipping the current bit to allow for runs longer than 4129.
- #define MAXIMUM_LONG_BIT_RUN 4129
- #define MODE_INTER_NO_MV 0
- #define MODE_INTRA 1
- #define MODE_INTER_PLUS_MV 2
- #define MODE_INTER_LAST_MV 3
- #define MODE_INTER_PRIOR_LAST 4
- #define MODE_USING_GOLDEN 5
- #define MODE_GOLDEN_MV 6
- #define MODE_INTER_FOURMV 7
- #define CODING_MODE_COUNT 8
- /* special internal mode */
- #define MODE_COPY 8
- static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb);
- static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb);
- /* There are 6 preset schemes, plus a free-form scheme */
- static const int ModeAlphabet[6][CODING_MODE_COUNT] = {
- /* scheme 1: Last motion vector dominates */
- { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_PLUS_MV, MODE_INTER_NO_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
- /* scheme 2 */
- { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_NO_MV, MODE_INTER_PLUS_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
- /* scheme 3 */
- { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
- MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
- /* scheme 4 */
- { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
- MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
- /* scheme 5: No motion vector dominates */
- { MODE_INTER_NO_MV, MODE_INTER_LAST_MV,
- MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
- /* scheme 6 */
- { MODE_INTER_NO_MV, MODE_USING_GOLDEN,
- MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_PLUS_MV, MODE_INTRA,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
- };
- static const uint8_t hilbert_offset[16][2] = {
- { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 },
- { 0, 2 }, { 0, 3 }, { 1, 3 }, { 1, 2 },
- { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 2 },
- { 3, 1 }, { 2, 1 }, { 2, 0 }, { 3, 0 }
- };
- enum {
- VP4_DC_INTRA = 0,
- VP4_DC_INTER = 1,
- VP4_DC_GOLDEN = 2,
- NB_VP4_DC_TYPES,
- VP4_DC_UNDEFINED = NB_VP4_DC_TYPES
- };
- static const uint8_t vp4_pred_block_type_map[8] = {
- [MODE_INTER_NO_MV] = VP4_DC_INTER,
- [MODE_INTRA] = VP4_DC_INTRA,
- [MODE_INTER_PLUS_MV] = VP4_DC_INTER,
- [MODE_INTER_LAST_MV] = VP4_DC_INTER,
- [MODE_INTER_PRIOR_LAST] = VP4_DC_INTER,
- [MODE_USING_GOLDEN] = VP4_DC_GOLDEN,
- [MODE_GOLDEN_MV] = VP4_DC_GOLDEN,
- [MODE_INTER_FOURMV] = VP4_DC_INTER,
- };
- typedef struct {
- int dc;
- int type;
- } VP4Predictor;
- #define MIN_DEQUANT_VAL 2
- typedef struct Vp3DecodeContext {
- AVCodecContext *avctx;
- int theora, theora_tables, theora_header;
- int version;
- int width, height;
- int chroma_x_shift, chroma_y_shift;
- ThreadFrame golden_frame;
- ThreadFrame last_frame;
- ThreadFrame current_frame;
- int keyframe;
- uint8_t idct_permutation[64];
- uint8_t idct_scantable[64];
- HpelDSPContext hdsp;
- VideoDSPContext vdsp;
- VP3DSPContext vp3dsp;
- DECLARE_ALIGNED(16, int16_t, block)[64];
- int flipped_image;
- int last_slice_end;
- int skip_loop_filter;
- int qps[3];
- int nqps;
- int last_qps[3];
- int superblock_count;
- int y_superblock_width;
- int y_superblock_height;
- int y_superblock_count;
- int c_superblock_width;
- int c_superblock_height;
- int c_superblock_count;
- int u_superblock_start;
- int v_superblock_start;
- unsigned char *superblock_coding;
- int macroblock_count; /* y macroblock count */
- int macroblock_width;
- int macroblock_height;
- int c_macroblock_count;
- int c_macroblock_width;
- int c_macroblock_height;
- int yuv_macroblock_count; /* y+u+v macroblock count */
- int fragment_count;
- int fragment_width[2];
- int fragment_height[2];
- Vp3Fragment *all_fragments;
- int fragment_start[3];
- int data_offset[3];
- uint8_t offset_x;
- uint8_t offset_y;
- int offset_x_warned;
- int8_t (*motion_val[2])[2];
- /* tables */
- uint16_t coded_dc_scale_factor[2][64];
- uint32_t coded_ac_scale_factor[64];
- uint8_t base_matrix[384][64];
- uint8_t qr_count[2][3];
- uint8_t qr_size[2][3][64];
- uint16_t qr_base[2][3][64];
- /**
- * This is a list of all tokens in bitstream order. Reordering takes place
- * by pulling from each level during IDCT. As a consequence, IDCT must be
- * in Hilbert order, making the minimum slice height 64 for 4:2:0 and 32
- * otherwise. The 32 different tokens with up to 12 bits of extradata are
- * collapsed into 3 types, packed as follows:
- * (from the low to high bits)
- *
- * 2 bits: type (0,1,2)
- * 0: EOB run, 14 bits for run length (12 needed)
- * 1: zero run, 7 bits for run length
- * 7 bits for the next coefficient (3 needed)
- * 2: coefficient, 14 bits (11 needed)
- *
- * Coefficients are signed, so are packed in the highest bits for automatic
- * sign extension.
- */
- int16_t *dct_tokens[3][64];
- int16_t *dct_tokens_base;
- #define TOKEN_EOB(eob_run) ((eob_run) << 2)
- #define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) * 512) + ((zero_run) << 2) + 1)
- #define TOKEN_COEFF(coeff) (((coeff) * 4) + 2)
- /**
- * number of blocks that contain DCT coefficients at
- * the given level or higher
- */
- int num_coded_frags[3][64];
- int total_num_coded_frags;
- /* this is a list of indexes into the all_fragments array indicating
- * which of the fragments are coded */
- int *coded_fragment_list[3];
- int *kf_coded_fragment_list;
- int *nkf_coded_fragment_list;
- int num_kf_coded_fragment[3];
- VLC dc_vlc[16];
- VLC ac_vlc_1[16];
- VLC ac_vlc_2[16];
- VLC ac_vlc_3[16];
- VLC ac_vlc_4[16];
- VLC superblock_run_length_vlc; /* version < 2 */
- VLC fragment_run_length_vlc; /* version < 2 */
- VLC block_pattern_vlc[2]; /* version >= 2*/
- VLC mode_code_vlc;
- VLC motion_vector_vlc; /* version < 2 */
- VLC vp4_mv_vlc[2][7]; /* version >=2 */
- /* these arrays need to be on 16-byte boundaries since SSE2 operations
- * index into them */
- DECLARE_ALIGNED(16, int16_t, qmat)[3][2][3][64]; ///< qmat[qpi][is_inter][plane]
- /* This table contains superblock_count * 16 entries. Each set of 16
- * numbers corresponds to the fragment indexes 0..15 of the superblock.
- * An entry will be -1 to indicate that no entry corresponds to that
- * index. */
- int *superblock_fragments;
- /* This is an array that indicates how a particular macroblock
- * is coded. */
- unsigned char *macroblock_coding;
- uint8_t *edge_emu_buffer;
- /* Huffman decode */
- int hti;
- unsigned int hbits;
- int entries;
- int huff_code_size;
- uint32_t huffman_table[80][32][2];
- uint8_t filter_limit_values[64];
- DECLARE_ALIGNED(8, int, bounding_values_array)[256 + 2];
- VP4Predictor * dc_pred_row; /* dc_pred_row[y_superblock_width * 4] */
- } Vp3DecodeContext;
- /************************************************************************
- * VP3 specific functions
- ************************************************************************/
- static av_cold void free_tables(AVCodecContext *avctx)
- {
- Vp3DecodeContext *s = avctx->priv_data;
- av_freep(&s->superblock_coding);
- av_freep(&s->all_fragments);
- av_freep(&s->nkf_coded_fragment_list);
- av_freep(&s->kf_coded_fragment_list);
- av_freep(&s->dct_tokens_base);
- av_freep(&s->superblock_fragments);
- av_freep(&s->macroblock_coding);
- av_freep(&s->dc_pred_row);
- av_freep(&s->motion_val[0]);
- av_freep(&s->motion_val[1]);
- }
- static void vp3_decode_flush(AVCodecContext *avctx)
- {
- Vp3DecodeContext *s = avctx->priv_data;
- if (s->golden_frame.f)
- ff_thread_release_buffer(avctx, &s->golden_frame);
- if (s->last_frame.f)
- ff_thread_release_buffer(avctx, &s->last_frame);
- if (s->current_frame.f)
- ff_thread_release_buffer(avctx, &s->current_frame);
- }
- static av_cold int vp3_decode_end(AVCodecContext *avctx)
- {
- Vp3DecodeContext *s = avctx->priv_data;
- int i, j;
- free_tables(avctx);
- av_freep(&s->edge_emu_buffer);
- s->theora_tables = 0;
- /* release all frames */
- vp3_decode_flush(avctx);
- av_frame_free(&s->current_frame.f);
- av_frame_free(&s->last_frame.f);
- av_frame_free(&s->golden_frame.f);
- for (i = 0; i < 16; i++) {
- ff_free_vlc(&s->dc_vlc[i]);
- ff_free_vlc(&s->ac_vlc_1[i]);
- ff_free_vlc(&s->ac_vlc_2[i]);
- ff_free_vlc(&s->ac_vlc_3[i]);
- ff_free_vlc(&s->ac_vlc_4[i]);
- }
- ff_free_vlc(&s->superblock_run_length_vlc);
- ff_free_vlc(&s->fragment_run_length_vlc);
- ff_free_vlc(&s->mode_code_vlc);
- ff_free_vlc(&s->motion_vector_vlc);
- for (j = 0; j < 2; j++)
- for (i = 0; i < 7; i++)
- ff_free_vlc(&s->vp4_mv_vlc[j][i]);
- for (i = 0; i < 2; i++)
- ff_free_vlc(&s->block_pattern_vlc[i]);
- return 0;
- }
- /**
- * This function sets up all of the various blocks mappings:
- * superblocks <-> fragments, macroblocks <-> fragments,
- * superblocks <-> macroblocks
- *
- * @return 0 is successful; returns 1 if *anything* went wrong.
- */
- static int init_block_mapping(Vp3DecodeContext *s)
- {
- int sb_x, sb_y, plane;
- int x, y, i, j = 0;
- for (plane = 0; plane < 3; plane++) {
- int sb_width = plane ? s->c_superblock_width
- : s->y_superblock_width;
- int sb_height = plane ? s->c_superblock_height
- : s->y_superblock_height;
- int frag_width = s->fragment_width[!!plane];
- int frag_height = s->fragment_height[!!plane];
- for (sb_y = 0; sb_y < sb_height; sb_y++)
- for (sb_x = 0; sb_x < sb_width; sb_x++)
- for (i = 0; i < 16; i++) {
- x = 4 * sb_x + hilbert_offset[i][0];
- y = 4 * sb_y + hilbert_offset[i][1];
- if (x < frag_width && y < frag_height)
- s->superblock_fragments[j++] = s->fragment_start[plane] +
- y * frag_width + x;
- else
- s->superblock_fragments[j++] = -1;
- }
- }
- return 0; /* successful path out */
- }
- /*
- * This function sets up the dequantization tables used for a particular
- * frame.
- */
- static void init_dequantizer(Vp3DecodeContext *s, int qpi)
- {
- int ac_scale_factor = s->coded_ac_scale_factor[s->qps[qpi]];
- int i, plane, inter, qri, bmi, bmj, qistart;
- for (inter = 0; inter < 2; inter++) {
- for (plane = 0; plane < 3; plane++) {
- int dc_scale_factor = s->coded_dc_scale_factor[!!plane][s->qps[qpi]];
- int sum = 0;
- for (qri = 0; qri < s->qr_count[inter][plane]; qri++) {
- sum += s->qr_size[inter][plane][qri];
- if (s->qps[qpi] <= sum)
- break;
- }
- qistart = sum - s->qr_size[inter][plane][qri];
- bmi = s->qr_base[inter][plane][qri];
- bmj = s->qr_base[inter][plane][qri + 1];
- for (i = 0; i < 64; i++) {
- int coeff = (2 * (sum - s->qps[qpi]) * s->base_matrix[bmi][i] -
- 2 * (qistart - s->qps[qpi]) * s->base_matrix[bmj][i] +
- s->qr_size[inter][plane][qri]) /
- (2 * s->qr_size[inter][plane][qri]);
- int qmin = 8 << (inter + !i);
- int qscale = i ? ac_scale_factor : dc_scale_factor;
- int qbias = (1 + inter) * 3;
- s->qmat[qpi][inter][plane][s->idct_permutation[i]] =
- (i == 0 || s->version < 2) ? av_clip((qscale * coeff) / 100 * 4, qmin, 4096)
- : (qscale * (coeff - qbias) / 100 + qbias) * 4;
- }
- /* all DC coefficients use the same quant so as not to interfere
- * with DC prediction */
- s->qmat[qpi][inter][plane][0] = s->qmat[0][inter][plane][0];
- }
- }
- }
- /*
- * This function initializes the loop filter boundary limits if the frame's
- * quality index is different from the previous frame's.
- *
- * The filter_limit_values may not be larger than 127.
- */
- static void init_loop_filter(Vp3DecodeContext *s)
- {
- ff_vp3dsp_set_bounding_values(s->bounding_values_array, s->filter_limit_values[s->qps[0]]);
- }
- /*
- * This function unpacks all of the superblock/macroblock/fragment coding
- * information from the bitstream.
- */
- static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int superblock_starts[3] = {
- 0, s->u_superblock_start, s->v_superblock_start
- };
- int bit = 0;
- int current_superblock = 0;
- int current_run = 0;
- int num_partial_superblocks = 0;
- int i, j;
- int current_fragment;
- int plane;
- int plane0_num_coded_frags = 0;
- if (s->keyframe) {
- memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count);
- } else {
- /* unpack the list of partially-coded superblocks */
- bit = get_bits1(gb) ^ 1;
- current_run = 0;
- while (current_superblock < s->superblock_count && get_bits_left(gb) > 0) {
- if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN)
- bit = get_bits1(gb);
- else
- bit ^= 1;
- current_run = get_vlc2(gb, s->superblock_run_length_vlc.table,
- 6, 2) + 1;
- if (current_run == 34)
- current_run += get_bits(gb, 12);
- if (current_run > s->superblock_count - current_superblock) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Invalid partially coded superblock run length\n");
- return -1;
- }
- memset(s->superblock_coding + current_superblock, bit, current_run);
- current_superblock += current_run;
- if (bit)
- num_partial_superblocks += current_run;
- }
- /* unpack the list of fully coded superblocks if any of the blocks were
- * not marked as partially coded in the previous step */
- if (num_partial_superblocks < s->superblock_count) {
- int superblocks_decoded = 0;
- current_superblock = 0;
- bit = get_bits1(gb) ^ 1;
- current_run = 0;
- while (superblocks_decoded < s->superblock_count - num_partial_superblocks &&
- get_bits_left(gb) > 0) {
- if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN)
- bit = get_bits1(gb);
- else
- bit ^= 1;
- current_run = get_vlc2(gb, s->superblock_run_length_vlc.table,
- 6, 2) + 1;
- if (current_run == 34)
- current_run += get_bits(gb, 12);
- for (j = 0; j < current_run; current_superblock++) {
- if (current_superblock >= s->superblock_count) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Invalid fully coded superblock run length\n");
- return -1;
- }
- /* skip any superblocks already marked as partially coded */
- if (s->superblock_coding[current_superblock] == SB_NOT_CODED) {
- s->superblock_coding[current_superblock] = 2 * bit;
- j++;
- }
- }
- superblocks_decoded += current_run;
- }
- }
- /* if there were partial blocks, initialize bitstream for
- * unpacking fragment codings */
- if (num_partial_superblocks) {
- current_run = 0;
- bit = get_bits1(gb);
- /* toggle the bit because as soon as the first run length is
- * fetched the bit will be toggled again */
- bit ^= 1;
- }
- }
- /* figure out which fragments are coded; iterate through each
- * superblock (all planes) */
- s->total_num_coded_frags = 0;
- memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
- s->coded_fragment_list[0] = s->keyframe ? s->kf_coded_fragment_list
- : s->nkf_coded_fragment_list;
- for (plane = 0; plane < 3; plane++) {
- int sb_start = superblock_starts[plane];
- int sb_end = sb_start + (plane ? s->c_superblock_count
- : s->y_superblock_count);
- int num_coded_frags = 0;
- if (s->keyframe) {
- if (s->num_kf_coded_fragment[plane] == -1) {
- for (i = sb_start; i < sb_end; i++) {
- /* iterate through all 16 fragments in a superblock */
- for (j = 0; j < 16; j++) {
- /* if the fragment is in bounds, check its coding status */
- current_fragment = s->superblock_fragments[i * 16 + j];
- if (current_fragment != -1) {
- s->coded_fragment_list[plane][num_coded_frags++] =
- current_fragment;
- }
- }
- }
- s->num_kf_coded_fragment[plane] = num_coded_frags;
- } else
- num_coded_frags = s->num_kf_coded_fragment[plane];
- } else {
- for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
- if (get_bits_left(gb) < plane0_num_coded_frags >> 2) {
- return AVERROR_INVALIDDATA;
- }
- /* iterate through all 16 fragments in a superblock */
- for (j = 0; j < 16; j++) {
- /* if the fragment is in bounds, check its coding status */
- current_fragment = s->superblock_fragments[i * 16 + j];
- if (current_fragment != -1) {
- int coded = s->superblock_coding[i];
- if (coded == SB_PARTIALLY_CODED) {
- /* fragment may or may not be coded; this is the case
- * that cares about the fragment coding runs */
- if (current_run-- == 0) {
- bit ^= 1;
- current_run = get_vlc2(gb, s->fragment_run_length_vlc.table, 5, 2);
- }
- coded = bit;
- }
- if (coded) {
- /* default mode; actual mode will be decoded in
- * the next phase */
- s->all_fragments[current_fragment].coding_method =
- MODE_INTER_NO_MV;
- s->coded_fragment_list[plane][num_coded_frags++] =
- current_fragment;
- } else {
- /* not coded; copy this fragment from the prior frame */
- s->all_fragments[current_fragment].coding_method =
- MODE_COPY;
- }
- }
- }
- }
- }
- if (!plane)
- plane0_num_coded_frags = num_coded_frags;
- s->total_num_coded_frags += num_coded_frags;
- for (i = 0; i < 64; i++)
- s->num_coded_frags[plane][i] = num_coded_frags;
- if (plane < 2)
- s->coded_fragment_list[plane + 1] = s->coded_fragment_list[plane] +
- num_coded_frags;
- }
- return 0;
- }
- #define BLOCK_X (2 * mb_x + (k & 1))
- #define BLOCK_Y (2 * mb_y + (k >> 1))
- #if CONFIG_VP4_DECODER
- /**
- * @return number of blocks, or > yuv_macroblock_count on error.
- * return value is always >= 1.
- */
- static int vp4_get_mb_count(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int v = 1;
- int bits;
- while ((bits = show_bits(gb, 9)) == 0x1ff) {
- skip_bits(gb, 9);
- v += 256;
- if (v > s->yuv_macroblock_count) {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid run length\n");
- return v;
- }
- }
- #define body(n) { \
- skip_bits(gb, 2 + n); \
- v += (1 << n) + get_bits(gb, n); }
- #define thresh(n) (0x200 - (0x80 >> n))
- #define else_if(n) else if (bits < thresh(n)) body(n)
- if (bits < 0x100) {
- skip_bits(gb, 1);
- } else if (bits < thresh(0)) {
- skip_bits(gb, 2);
- v += 1;
- }
- else_if(1)
- else_if(2)
- else_if(3)
- else_if(4)
- else_if(5)
- else_if(6)
- else body(7)
- #undef body
- #undef thresh
- #undef else_if
- return v;
- }
- static int vp4_get_block_pattern(Vp3DecodeContext *s, GetBitContext *gb, int *next_block_pattern_table)
- {
- int v = get_vlc2(gb, s->block_pattern_vlc[*next_block_pattern_table].table, 3, 2);
- if (v == -1) {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid block pattern\n");
- *next_block_pattern_table = 0;
- return 0;
- }
- *next_block_pattern_table = vp4_block_pattern_table_selector[v];
- return v + 1;
- }
- static int vp4_unpack_macroblocks(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int plane, i, j, k, fragment;
- int next_block_pattern_table;
- int bit, current_run, has_partial;
- memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
- if (s->keyframe)
- return 0;
- has_partial = 0;
- bit = get_bits1(gb);
- for (i = 0; i < s->yuv_macroblock_count; i += current_run) {
- if (get_bits_left(gb) <= 0)
- return AVERROR_INVALIDDATA;
- current_run = vp4_get_mb_count(s, gb);
- if (current_run > s->yuv_macroblock_count - i)
- return -1;
- memset(s->superblock_coding + i, 2 * bit, current_run);
- bit ^= 1;
- has_partial |= bit;
- }
- if (has_partial) {
- if (get_bits_left(gb) <= 0)
- return AVERROR_INVALIDDATA;
- bit = get_bits1(gb);
- current_run = vp4_get_mb_count(s, gb);
- for (i = 0; i < s->yuv_macroblock_count; i++) {
- if (!s->superblock_coding[i]) {
- if (!current_run) {
- bit ^= 1;
- current_run = vp4_get_mb_count(s, gb);
- }
- s->superblock_coding[i] = bit;
- current_run--;
- }
- }
- if (current_run) /* handle situation when vp4_get_mb_count() fails */
- return -1;
- }
- next_block_pattern_table = 0;
- i = 0;
- for (plane = 0; plane < 3; plane++) {
- int sb_x, sb_y;
- int sb_width = plane ? s->c_superblock_width : s->y_superblock_width;
- int sb_height = plane ? s->c_superblock_height : s->y_superblock_height;
- int mb_width = plane ? s->c_macroblock_width : s->macroblock_width;
- int mb_height = plane ? s->c_macroblock_height : s->macroblock_height;
- int fragment_width = s->fragment_width[!!plane];
- int fragment_height = s->fragment_height[!!plane];
- for (sb_y = 0; sb_y < sb_height; sb_y++) {
- for (sb_x = 0; sb_x < sb_width; sb_x++) {
- for (j = 0; j < 4; j++) {
- int mb_x = 2 * sb_x + (j >> 1);
- int mb_y = 2 * sb_y + (j >> 1) ^ (j & 1);
- int mb_coded, pattern, coded;
- if (mb_x >= mb_width || mb_y >= mb_height)
- continue;
- mb_coded = s->superblock_coding[i++];
- if (mb_coded == SB_FULLY_CODED)
- pattern = 0xF;
- else if (mb_coded == SB_PARTIALLY_CODED)
- pattern = vp4_get_block_pattern(s, gb, &next_block_pattern_table);
- else
- pattern = 0;
- for (k = 0; k < 4; k++) {
- if (BLOCK_X >= fragment_width || BLOCK_Y >= fragment_height)
- continue;
- fragment = s->fragment_start[plane] + BLOCK_Y * fragment_width + BLOCK_X;
- coded = pattern & (8 >> k);
- /* MODE_INTER_NO_MV is the default for coded fragments.
- the actual method is decoded in the next phase. */
- s->all_fragments[fragment].coding_method = coded ? MODE_INTER_NO_MV : MODE_COPY;
- }
- }
- }
- }
- }
- return 0;
- }
- #endif
- /*
- * This function unpacks all the coding mode data for individual macroblocks
- * from the bitstream.
- */
- static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int i, j, k, sb_x, sb_y;
- int scheme;
- int current_macroblock;
- int current_fragment;
- int coding_mode;
- int custom_mode_alphabet[CODING_MODE_COUNT];
- const int *alphabet;
- Vp3Fragment *frag;
- if (s->keyframe) {
- for (i = 0; i < s->fragment_count; i++)
- s->all_fragments[i].coding_method = MODE_INTRA;
- } else {
- /* fetch the mode coding scheme for this frame */
- scheme = get_bits(gb, 3);
- /* is it a custom coding scheme? */
- if (scheme == 0) {
- for (i = 0; i < 8; i++)
- custom_mode_alphabet[i] = MODE_INTER_NO_MV;
- for (i = 0; i < 8; i++)
- custom_mode_alphabet[get_bits(gb, 3)] = i;
- alphabet = custom_mode_alphabet;
- } else
- alphabet = ModeAlphabet[scheme - 1];
- /* iterate through all of the macroblocks that contain 1 or more
- * coded fragments */
- for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {
- for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {
- if (get_bits_left(gb) <= 0)
- return -1;
- for (j = 0; j < 4; j++) {
- int mb_x = 2 * sb_x + (j >> 1);
- int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
- current_macroblock = mb_y * s->macroblock_width + mb_x;
- if (mb_x >= s->macroblock_width ||
- mb_y >= s->macroblock_height)
- continue;
- /* coding modes are only stored if the macroblock has
- * at least one luma block coded, otherwise it must be
- * INTER_NO_MV */
- for (k = 0; k < 4; k++) {
- current_fragment = BLOCK_Y *
- s->fragment_width[0] + BLOCK_X;
- if (s->all_fragments[current_fragment].coding_method != MODE_COPY)
- break;
- }
- if (k == 4) {
- s->macroblock_coding[current_macroblock] = MODE_INTER_NO_MV;
- continue;
- }
- /* mode 7 means get 3 bits for each coding mode */
- if (scheme == 7)
- coding_mode = get_bits(gb, 3);
- else
- coding_mode = alphabet[get_vlc2(gb, s->mode_code_vlc.table, 3, 3)];
- s->macroblock_coding[current_macroblock] = coding_mode;
- for (k = 0; k < 4; k++) {
- frag = s->all_fragments + BLOCK_Y * s->fragment_width[0] + BLOCK_X;
- if (frag->coding_method != MODE_COPY)
- frag->coding_method = coding_mode;
- }
- #define SET_CHROMA_MODES \
- if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \
- frag[s->fragment_start[1]].coding_method = coding_mode; \
- if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \
- frag[s->fragment_start[2]].coding_method = coding_mode;
- if (s->chroma_y_shift) {
- frag = s->all_fragments + mb_y *
- s->fragment_width[1] + mb_x;
- SET_CHROMA_MODES
- } else if (s->chroma_x_shift) {
- frag = s->all_fragments +
- 2 * mb_y * s->fragment_width[1] + mb_x;
- for (k = 0; k < 2; k++) {
- SET_CHROMA_MODES
- frag += s->fragment_width[1];
- }
- } else {
- for (k = 0; k < 4; k++) {
- frag = s->all_fragments +
- BLOCK_Y * s->fragment_width[1] + BLOCK_X;
- SET_CHROMA_MODES
- }
- }
- }
- }
- }
- }
- return 0;
- }
- static int vp4_get_mv(Vp3DecodeContext *s, GetBitContext *gb, int axis, int last_motion)
- {
- int v = get_vlc2(gb, s->vp4_mv_vlc[axis][vp4_mv_table_selector[FFABS(last_motion)]].table, 6, 2) - 31;
- return last_motion < 0 ? -v : v;
- }
- /*
- * This function unpacks all the motion vectors for the individual
- * macroblocks from the bitstream.
- */
- static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int j, k, sb_x, sb_y;
- int coding_mode;
- int motion_x[4];
- int motion_y[4];
- int last_motion_x = 0;
- int last_motion_y = 0;
- int prior_last_motion_x = 0;
- int prior_last_motion_y = 0;
- int last_gold_motion_x = 0;
- int last_gold_motion_y = 0;
- int current_macroblock;
- int current_fragment;
- int frag;
- if (s->keyframe)
- return 0;
- /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme; 2 is VP4 code scheme */
- coding_mode = s->version < 2 ? get_bits1(gb) : 2;
- /* iterate through all of the macroblocks that contain 1 or more
- * coded fragments */
- for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {
- for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {
- if (get_bits_left(gb) <= 0)
- return -1;
- for (j = 0; j < 4; j++) {
- int mb_x = 2 * sb_x + (j >> 1);
- int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);
- current_macroblock = mb_y * s->macroblock_width + mb_x;
- if (mb_x >= s->macroblock_width ||
- mb_y >= s->macroblock_height ||
- s->macroblock_coding[current_macroblock] == MODE_COPY)
- continue;
- switch (s->macroblock_coding[current_macroblock]) {
- case MODE_GOLDEN_MV:
- if (coding_mode == 2) { /* VP4 */
- last_gold_motion_x = motion_x[0] = vp4_get_mv(s, gb, 0, last_gold_motion_x);
- last_gold_motion_y = motion_y[0] = vp4_get_mv(s, gb, 1, last_gold_motion_y);
- break;
- } /* otherwise fall through */
- case MODE_INTER_PLUS_MV:
- /* all 6 fragments use the same motion vector */
- if (coding_mode == 0) {
- motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- } else if (coding_mode == 1) {
- motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];
- motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)];
- } else { /* VP4 */
- motion_x[0] = vp4_get_mv(s, gb, 0, last_motion_x);
- motion_y[0] = vp4_get_mv(s, gb, 1, last_motion_y);
- }
- /* vector maintenance, only on MODE_INTER_PLUS_MV */
- if (s->macroblock_coding[current_macroblock] == MODE_INTER_PLUS_MV) {
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[0];
- last_motion_y = motion_y[0];
- }
- break;
- case MODE_INTER_FOURMV:
- /* vector maintenance */
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- /* fetch 4 vectors from the bitstream, one for each
- * Y fragment, then average for the C fragment vectors */
- for (k = 0; k < 4; k++) {
- current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X;
- if (s->all_fragments[current_fragment].coding_method != MODE_COPY) {
- if (coding_mode == 0) {
- motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];
- } else if (coding_mode == 1) {
- motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];
- motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];
- } else { /* VP4 */
- motion_x[k] = vp4_get_mv(s, gb, 0, prior_last_motion_x);
- motion_y[k] = vp4_get_mv(s, gb, 1, prior_last_motion_y);
- }
- last_motion_x = motion_x[k];
- last_motion_y = motion_y[k];
- } else {
- motion_x[k] = 0;
- motion_y[k] = 0;
- }
- }
- break;
- case MODE_INTER_LAST_MV:
- /* all 6 fragments use the last motion vector */
- motion_x[0] = last_motion_x;
- motion_y[0] = last_motion_y;
- /* no vector maintenance (last vector remains the
- * last vector) */
- break;
- case MODE_INTER_PRIOR_LAST:
- /* all 6 fragments use the motion vector prior to the
- * last motion vector */
- motion_x[0] = prior_last_motion_x;
- motion_y[0] = prior_last_motion_y;
- /* vector maintenance */
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[0];
- last_motion_y = motion_y[0];
- break;
- default:
- /* covers intra, inter without MV, golden without MV */
- motion_x[0] = 0;
- motion_y[0] = 0;
- /* no vector maintenance */
- break;
- }
- /* assign the motion vectors to the correct fragments */
- for (k = 0; k < 4; k++) {
- current_fragment =
- BLOCK_Y * s->fragment_width[0] + BLOCK_X;
- if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
- s->motion_val[0][current_fragment][0] = motion_x[k];
- s->motion_val[0][current_fragment][1] = motion_y[k];
- } else {
- s->motion_val[0][current_fragment][0] = motion_x[0];
- s->motion_val[0][current_fragment][1] = motion_y[0];
- }
- }
- if (s->chroma_y_shift) {
- if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
- motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] +
- motion_x[2] + motion_x[3], 2);
- motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] +
- motion_y[2] + motion_y[3], 2);
- }
- if (s->version <= 2) {
- motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
- motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);
- }
- frag = mb_y * s->fragment_width[1] + mb_x;
- s->motion_val[1][frag][0] = motion_x[0];
- s->motion_val[1][frag][1] = motion_y[0];
- } else if (s->chroma_x_shift) {
- if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
- motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1);
- motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1);
- motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1);
- motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1);
- } else {
- motion_x[1] = motion_x[0];
- motion_y[1] = motion_y[0];
- }
- if (s->version <= 2) {
- motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);
- motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);
- }
- frag = 2 * mb_y * s->fragment_width[1] + mb_x;
- for (k = 0; k < 2; k++) {
- s->motion_val[1][frag][0] = motion_x[k];
- s->motion_val[1][frag][1] = motion_y[k];
- frag += s->fragment_width[1];
- }
- } else {
- for (k = 0; k < 4; k++) {
- frag = BLOCK_Y * s->fragment_width[1] + BLOCK_X;
- if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {
- s->motion_val[1][frag][0] = motion_x[k];
- s->motion_val[1][frag][1] = motion_y[k];
- } else {
- s->motion_val[1][frag][0] = motion_x[0];
- s->motion_val[1][frag][1] = motion_y[0];
- }
- }
- }
- }
- }
- }
- return 0;
- }
- static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int qpi, i, j, bit, run_length, blocks_decoded, num_blocks_at_qpi;
- int num_blocks = s->total_num_coded_frags;
- for (qpi = 0; qpi < s->nqps - 1 && num_blocks > 0; qpi++) {
- i = blocks_decoded = num_blocks_at_qpi = 0;
- bit = get_bits1(gb) ^ 1;
- run_length = 0;
- do {
- if (run_length == MAXIMUM_LONG_BIT_RUN)
- bit = get_bits1(gb);
- else
- bit ^= 1;
- run_length = get_vlc2(gb, s->superblock_run_length_vlc.table, 6, 2) + 1;
- if (run_length == 34)
- run_length += get_bits(gb, 12);
- blocks_decoded += run_length;
- if (!bit)
- num_blocks_at_qpi += run_length;
- for (j = 0; j < run_length; i++) {
- if (i >= s->total_num_coded_frags)
- return -1;
- if (s->all_fragments[s->coded_fragment_list[0][i]].qpi == qpi) {
- s->all_fragments[s->coded_fragment_list[0][i]].qpi += bit;
- j++;
- }
- }
- } while (blocks_decoded < num_blocks && get_bits_left(gb) > 0);
- num_blocks -= num_blocks_at_qpi;
- }
- return 0;
- }
- static inline int get_eob_run(GetBitContext *gb, int token)
- {
- int v = eob_run_table[token].base;
- if (eob_run_table[token].bits)
- v += get_bits(gb, eob_run_table[token].bits);
- return v;
- }
- static inline int get_coeff(GetBitContext *gb, int token, int16_t *coeff)
- {
- int bits_to_get, zero_run;
- bits_to_get = coeff_get_bits[token];
- if (bits_to_get)
- bits_to_get = get_bits(gb, bits_to_get);
- *coeff = coeff_tables[token][bits_to_get];
- zero_run = zero_run_base[token];
- if (zero_run_get_bits[token])
- zero_run += get_bits(gb, zero_run_get_bits[token]);
- return zero_run;
- }
- /*
- * This function is called by unpack_dct_coeffs() to extract the VLCs from
- * the bitstream. The VLCs encode tokens which are used to unpack DCT
- * data. This function unpacks all the VLCs for either the Y plane or both
- * C planes, and is called for DC coefficients or different AC coefficient
- * levels (since different coefficient types require different VLC tables.
- *
- * This function returns a residual eob run. E.g, if a particular token gave
- * instructions to EOB the next 5 fragments and there were only 2 fragments
- * left in the current fragment range, 3 would be returned so that it could
- * be passed into the next call to this same function.
- */
- static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
- VLC *table, int coeff_index,
- int plane,
- int eob_run)
- {
- int i, j = 0;
- int token;
- int zero_run = 0;
- int16_t coeff = 0;
- int blocks_ended;
- int coeff_i = 0;
- int num_coeffs = s->num_coded_frags[plane][coeff_index];
- int16_t *dct_tokens = s->dct_tokens[plane][coeff_index];
- /* local references to structure members to avoid repeated dereferences */
- int *coded_fragment_list = s->coded_fragment_list[plane];
- Vp3Fragment *all_fragments = s->all_fragments;
- VLC_TYPE(*vlc_table)[2] = table->table;
- if (num_coeffs < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Invalid number of coefficients at level %d\n", coeff_index);
- return AVERROR_INVALIDDATA;
- }
- if (eob_run > num_coeffs) {
- coeff_i =
- blocks_ended = num_coeffs;
- eob_run -= num_coeffs;
- } else {
- coeff_i =
- blocks_ended = eob_run;
- eob_run = 0;
- }
- // insert fake EOB token to cover the split between planes or zzi
- if (blocks_ended)
- dct_tokens[j++] = blocks_ended << 2;
- while (coeff_i < num_coeffs && get_bits_left(gb) > 0) {
- /* decode a VLC into a token */
- token = get_vlc2(gb, vlc_table, 11, 3);
- /* use the token to get a zero run, a coefficient, and an eob run */
- if ((unsigned) token <= 6U) {
- eob_run = get_eob_run(gb, token);
- if (!eob_run)
- eob_run = INT_MAX;
- // record only the number of blocks ended in this plane,
- // any spill will be recorded in the next plane.
- if (eob_run > num_coeffs - coeff_i) {
- dct_tokens[j++] = TOKEN_EOB(num_coeffs - coeff_i);
- blocks_ended += num_coeffs - coeff_i;
- eob_run -= num_coeffs - coeff_i;
- coeff_i = num_coeffs;
- } else {
- dct_tokens[j++] = TOKEN_EOB(eob_run);
- blocks_ended += eob_run;
- coeff_i += eob_run;
- eob_run = 0;
- }
- } else if (token >= 0) {
- zero_run = get_coeff(gb, token, &coeff);
- if (zero_run) {
- dct_tokens[j++] = TOKEN_ZERO_RUN(coeff, zero_run);
- } else {
- // Save DC into the fragment structure. DC prediction is
- // done in raster order, so the actual DC can't be in with
- // other tokens. We still need the token in dct_tokens[]
- // however, or else the structure collapses on itself.
- if (!coeff_index)
- all_fragments[coded_fragment_list[coeff_i]].dc = coeff;
- dct_tokens[j++] = TOKEN_COEFF(coeff);
- }
- if (coeff_index + zero_run > 64) {
- av_log(s->avctx, AV_LOG_DEBUG,
- "Invalid zero run of %d with %d coeffs left\n",
- zero_run, 64 - coeff_index);
- zero_run = 64 - coeff_index;
- }
- // zero runs code multiple coefficients,
- // so don't try to decode coeffs for those higher levels
- for (i = coeff_index + 1; i <= coeff_index + zero_run; i++)
- s->num_coded_frags[plane][i]--;
- coeff_i++;
- } else {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid token %d\n", token);
- return -1;
- }
- }
- if (blocks_ended > s->num_coded_frags[plane][coeff_index])
- av_log(s->avctx, AV_LOG_ERROR, "More blocks ended than coded!\n");
- // decrement the number of blocks that have higher coefficients for each
- // EOB run at this level
- if (blocks_ended)
- for (i = coeff_index + 1; i < 64; i++)
- s->num_coded_frags[plane][i] -= blocks_ended;
- // setup the next buffer
- if (plane < 2)
- s->dct_tokens[plane + 1][coeff_index] = dct_tokens + j;
- else if (coeff_index < 63)
- s->dct_tokens[0][coeff_index + 1] = dct_tokens + j;
- return eob_run;
- }
- static void reverse_dc_prediction(Vp3DecodeContext *s,
- int first_fragment,
- int fragment_width,
- int fragment_height);
- /*
- * This function unpacks all of the DCT coefficient data from the
- * bitstream.
- */
- static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
- {
- int i;
- int dc_y_table;
- int dc_c_table;
- int ac_y_table;
- int ac_c_table;
- int residual_eob_run = 0;
- VLC *y_tables[64];
- VLC *c_tables[64];
- s->dct_tokens[0][0] = s->dct_tokens_base;
- if (get_bits_left(gb) < 16)
- return AVERROR_INVALIDDATA;
- /* fetch the DC table indexes */
- dc_y_table = get_bits(gb, 4);
- dc_c_table = get_bits(gb, 4);
- /* unpack the Y plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0,
- 0, residual_eob_run);
- if (residual_eob_run < 0)
- return residual_eob_run;
- if (get_bits_left(gb) < 8)
- return AVERROR_INVALIDDATA;
- /* reverse prediction of the Y-plane DC coefficients */
- reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]);
- /* unpack the C plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0,
- 1, residual_eob_run);
- if (residual_eob_run < 0)
- return residual_eob_run;
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0,
- 2, residual_eob_run);
- if (residual_eob_run < 0)
- return residual_eob_run;
- /* reverse prediction of the C-plane DC coefficients */
- if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
- reverse_dc_prediction(s, s->fragment_start[1],
- s->fragment_width[1], s->fragment_height[1]);
- reverse_dc_prediction(s, s->fragment_start[2],
- s->fragment_width[1], s->fragment_height[1]);
- }
- if (get_bits_left(gb) < 8)
- return AVERROR_INVALIDDATA;
- /* fetch the AC table indexes */
- ac_y_table = get_bits(gb, 4);
- ac_c_table = get_bits(gb, 4);
- /* build tables of AC VLC tables */
- for (i = 1; i <= 5; i++) {
- y_tables[i] = &s->ac_vlc_1[ac_y_table];
- c_tables[i] = &s->ac_vlc_1[ac_c_table];
- }
- for (i = 6; i <= 14; i++) {
- y_tables[i] = &s->ac_vlc_2[ac_y_table];
- c_tables[i] = &s->ac_vlc_2[ac_c_table];
- }
- for (i = 15; i <= 27; i++) {
- y_tables[…