FFmpeg
Loading...
Searching...
No Matches
apv_decode.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_APV_DECODE_H
20#define AVCODEC_APV_DECODE_H
21
22#include <assert.h>
23#include <stdint.h>
24#include <stdatomic.h>
25
26#include "apv.h"
27#include "apv_dsp.h"
28#include "cbs_apv.h"
29
30#include "cbs.h"
31#include "get_bits.h"
32#include "libavutil/frame.h"
33
34// Number of bits in the entropy look-up tables.
35// It may be desirable to tune this per-architecture, as a larger LUT
36// trades greater memory use for fewer instructions.
37// (N bits -> 384*2^N bytes of tables; 9 -> 192KB of tables.)
38#define APV_VLC_LUT_BITS 9
39#define APV_VLC_LUT_SIZE (1 << APV_VLC_LUT_BITS)
40
41// The single-symbol LUT must be able to resolve a symbol with a single
42// leading zero for the largest k (5) without reading more bits, which
43// takes 2 + 1 + 5 = 8 bits.
44static_assert(APV_VLC_LUT_BITS >= 8, "APV VLC LUT too small");
45
46typedef struct APVSingleVLCLUTEntry {
47 uint16_t result; // Return value if not reading more.
48 uint8_t consume; // Number of bits to consume.
49 uint8_t more; // Whether to read additional bits.
51
52typedef struct APVMultiVLCLUTEntry {
53 // Number of symbols this bit stream resolves to.
54 uint8_t count;
55 // k_run after decoding all symbols.
56 uint8_t k_run : 2;
57 // k_level after decoding the first level symbol.
58 uint8_t k_level_0 : 3;
59 // k_level after decoding all symbols.
60 uint8_t k_level_1 : 3;
61 // Level output values. If fewer than two levels are decoded the
62 // remaining ones are zero.
63 int8_t level[2];
64 // Scan position of each level relative to the scan position before
65 // this entry. Missing levels are placed at the end of the entry,
66 // where writing the level zero is harmless.
67 uint8_t level_pos[2];
68 // Total scan position advance if all symbols are consumed. If not
69 // all symbols are consumed this can be recalculated from level_pos.
70 uint8_t scan_advance;
71 // Bits consumed at the end of each of the four possible symbols.
72 // Entry 3 always contains the bits from all symbols, even if fewer
73 // than four symbols are consumed.
74 uint8_t offset[4];
75 // Index of the table to use for the next lookup, combining the
76 // type of the next symbol with k_run and k_level after this entry.
77 uint8_t next;
79
80// Types of entry in the entropy table.
81enum {
82 // Entries are run/level/run/level.
84 // Entries are level/run/level/run.
86};
87// Index of the base point in the multi-symbol table for the given
88// type, k_run and k_level.
89#define APV_TABLE_INDEX(type, k_run, k_level) \
90 (((type) * 3 + (k_run)) * 5 + (k_level))
91
92typedef struct APVVLCLUT {
93 // Single-symbol LUT for VLCs.
94 // Applies to all coefficients, but used only for DC coefficients
95 // in the decoder.
97 // Multi-symbol LUT for run/level combinations, decoding up to four
98 // symbols per step.
99 // Indexed by [run first or level first][k_run][k_level][bits].
101 // Zigzag scan extended past the end of the block, where every
102 // position maps to a dummy coefficient after the block.
103 uint8_t zigzag[128];
104} APVVLCLUT;
105
106
107// Number of coefficients in the block buffer used by entropy decode:
108// the block itself and a dummy coefficient slot at the end which is
109// used to avoid branching.
110#define APV_ENTROPY_COEFF_SIZE 65
111
112typedef struct APVEntropyState {
113 void *log_ctx;
114
116
117 // Previous DC level value.
118 int16_t prev_dc;
119 // k parameter implied by the previous DC level value.
120 uint8_t prev_k_dc;
121 // k parameter implied by the previous first AC level value.
124
125typedef struct APVDerivedTileInfo {
126 uint8_t tile_cols;
127 uint8_t tile_rows;
128 uint16_t num_tiles;
129 // The spec uses an extra element on the end of these arrays
130 // not corresponding to any tile.
134
154
156
157/**
158 * Build the decoder VLC look-up tables.
159 */
161
162/**
163 * Entropy decode a single 8x8 block to coefficients.
164 *
165 * Outputs nonzero coefficients only to the block row-major order
166 * (dezigzag is applied within the function). The first 64 elements
167 * of the output block must have been filled with zeroes before
168 * calling this function, and there must be space for
169 * APV_ENTROPY_COEFF_SIZE elements in total.
170 */
171int ff_apv_entropy_decode_block(int16_t *restrict coeff,
172 GetBitContext *restrict gbc,
173 APVEntropyState *restrict state);
174
175#endif /* AVCODEC_APV_DECODE_H */
APVVLCLUT ff_apv_decode_lut
Definition apv_decode.c:48
#define APV_VLC_LUT_SIZE
Definition apv_decode.h:39
#define APV_VLC_LUT_BITS
Definition apv_decode.h:38
int ff_apv_entropy_decode_block(int16_t *restrict coeff, GetBitContext *restrict gbc, APVEntropyState *restrict state)
Entropy decode a single 8x8 block to coefficients.
void ff_apv_entropy_build_decode_lut(APVVLCLUT *decode_lut)
Build the decoder VLC look-up tables.
Definition apv_entropy.c:62
@ APV_ENTROPY_LEVEL_FIRST
Definition apv_decode.h:85
@ APV_ENTROPY_RUN_FIRST
Definition apv_decode.h:83
reference-counted frame API
bitstream reader API header.
@ APV_MAX_TILE_COLS
Definition apv.h:75
@ APV_MAX_TILE_ROWS
Definition apv.h:76
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
int atomic_int
Definition stdatomic.h:63
atomic_int tile_errors
Definition apv_decode.h:146
APVRawFrame * cur_raw_frame
Definition apv_decode.h:141
uint8_t warned_unknown_pbu_types
Definition apv_decode.h:152
CodedBitstreamFragment au
Definition apv_decode.h:139
uint8_t warned_additional_frames
Definition apv_decode.h:151
APVDSPContext dsp
Definition apv_decode.h:137
enum AVPixelFormat pix_fmt
Definition apv_decode.h:148
CodedBitstreamContext * cbc
Definition apv_decode.h:136
AVPacket * pkt
Definition apv_decode.h:143
APVDerivedTileInfo tile_info
Definition apv_decode.h:140
void * hwaccel_picture_private
Definition apv_decode.h:145
AVFrame * output_frame
Definition apv_decode.h:144
uint16_t col_starts[APV_MAX_TILE_COLS+1]
Definition apv_decode.h:131
uint16_t row_starts[APV_MAX_TILE_ROWS+1]
Definition apv_decode.h:132
const APVVLCLUT * decode_lut
Definition apv_decode.h:115
uint8_t prev_k_level
Definition apv_decode.h:122
uint8_t prev_k_dc
Definition apv_decode.h:120
uint8_t level_pos[2]
Definition apv_decode.h:67
uint8_t offset[4]
Definition apv_decode.h:74
APVMultiVLCLUTEntry multi_lut[2][3][5][APV_VLC_LUT_SIZE]
Definition apv_decode.h:100
uint8_t zigzag[128]
Definition apv_decode.h:103
APVSingleVLCLUTEntry single_lut[6][APV_VLC_LUT_SIZE]
Definition apv_decode.h:96
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This structure stores compressed data.
Definition packet.h:587
Context structure for coded bitstream operations.
Definition cbs.h:226
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
static struct @232240247175332074307271266321204261331170211232 state