FFmpeg
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 <stdint.h>
23 #include <stdatomic.h>
24 
25 #include "apv.h"
26 #include "apv_dsp.h"
27 #include "cbs_apv.h"
28 
29 #include "cbs.h"
30 #include "get_bits.h"
31 #include "libavutil/frame.h"
32 
33 // Number of bits in the entropy look-up tables.
34 // It may be desirable to tune this per-architecture, as a larger LUT
35 // trades greater memory use for fewer instructions.
36 // (N bits -> 24*2^N bytes of tables; 9 -> 12KB of tables.)
37 #define APV_VLC_LUT_BITS 9
38 #define APV_VLC_LUT_SIZE (1 << APV_VLC_LUT_BITS)
39 
40 typedef struct APVSingleVLCLUTEntry {
41  uint16_t result; // Return value if not reading more.
42  uint8_t consume; // Number of bits to consume.
43  uint8_t more; // Whether to read additional bits.
45 
46 typedef struct APVMultiVLCLUTEntry {
47  // Number of symbols this bit stream resolves to.
48  uint8_t count;
49  // k_run after decoding all symbols.
50  uint8_t k_run : 2;
51  // k_level after decoding the first level symbol.
52  uint8_t k_level_0 : 3;
53  // k_level after decoding all symbols.
54  uint8_t k_level_1 : 3;
55  // Run output values.
56  uint8_t run[2];
57  // Level output values.
58  int16_t level[2];
59  // Bit index of the end of each code.
60  uint8_t offset[4];
62 
63 typedef struct APVVLCLUT {
64  // Single-symbol LUT for VLCs.
65  // Applies to all coefficients, but used only for DC coefficients
66  // in the decoder.
68  // Multi-symbol LUT for run/level combinations, decoding up to four
69  // symbols per step. Comes in two versions, which to use depends on
70  // whether the next symbol is a run or a level.
73 } APVVLCLUT;
74 
75 typedef struct APVEntropyState {
76  void *log_ctx;
77 
79 
80  // Previous DC level value.
81  int16_t prev_dc;
82  // k parameter implied by the previous DC level value.
83  uint8_t prev_k_dc;
84  // k parameter implied by the previous first AC level value.
85  uint8_t prev_k_level;
87 
88 typedef struct APVDerivedTileInfo {
89  uint8_t tile_cols;
90  uint8_t tile_rows;
91  uint16_t num_tiles;
92  // The spec uses an extra element on the end of these arrays
93  // not corresponding to any tile.
97 
98 typedef struct APVDecodeContext {
101 
105 
110 
112  int nb_unit;
113 
117 
119 
120 /**
121  * Build the decoder VLC look-up tables.
122  */
124 
125 /**
126  * Entropy decode a single 8x8 block to coefficients.
127  *
128  * Outputs nonzero coefficients only to the block row-major order
129  * (dezigzag is applied within the function). The output block
130  * must have been filled with zeroes before calling this function.
131  */
132 int ff_apv_entropy_decode_block(int16_t *restrict coeff,
133  GetBitContext *restrict gbc,
134  APVEntropyState *restrict state);
135 
136 #endif /* AVCODEC_APV_DECODE_H */
APV_MAX_TILE_COLS
@ APV_MAX_TILE_COLS
Definition: apv.h:75
cbs.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
APVDecodeContext::dsp
APVDSPContext dsp
Definition: apv_decode.h:100
APVDerivedTileInfo::tile_cols
uint8_t tile_cols
Definition: apv_decode.h:89
APVDecodeContext::output_frame
AVFrame * output_frame
Definition: apv_decode.h:107
APVSingleVLCLUTEntry::result
uint16_t result
Definition: apv_decode.h:41
APVDecodeContext
Definition: apv_decode.h:98
APVMultiVLCLUTEntry::run
uint8_t run[2]
Definition: apv_decode.h:56
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:459
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
atomic_int
intptr_t atomic_int
Definition: stdatomic.h:55
APVVLCLUT::level_first_lut
APVMultiVLCLUTEntry level_first_lut[3][5][APV_VLC_LUT_SIZE]
Definition: apv_decode.h:72
ff_apv_decode_lut
APVVLCLUT ff_apv_decode_lut
Definition: apv_decode.c:48
APVDecodeContext::tile_info
APVDerivedTileInfo tile_info
Definition: apv_decode.h:103
APVDecodeContext::tile_errors
atomic_int tile_errors
Definition: apv_decode.h:109
GetBitContext
Definition: get_bits.h:109
APVDecodeContext::nb_unit
int nb_unit
Definition: apv_decode.h:112
APVDSPContext
Definition: apv_dsp.h:26
apv_dsp.h
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
APV_VLC_LUT_SIZE
#define APV_VLC_LUT_SIZE
Definition: apv_decode.h:38
APVDecodeContext::au
CodedBitstreamFragment au
Definition: apv_decode.h:102
get_bits.h
APVDecodeContext::cur_raw_frame
APVRawFrame * cur_raw_frame
Definition: apv_decode.h:104
apv.h
ff_apv_entropy_build_decode_lut
void ff_apv_entropy_build_decode_lut(APVVLCLUT *decode_lut)
Build the decoder VLC look-up tables.
Definition: apv_entropy.c:62
APVRawFrame
Definition: cbs_apv.h:101
APVSingleVLCLUTEntry
Definition: apv_decode.h:40
APVEntropyState
Definition: apv_decode.h:75
APVEntropyState::log_ctx
void * log_ctx
Definition: apv_decode.h:76
APVEntropyState::prev_k_level
uint8_t prev_k_level
Definition: apv_decode.h:85
frame.h
APVMultiVLCLUTEntry
Definition: apv_decode.h:46
APVVLCLUT::run_first_lut
APVMultiVLCLUTEntry run_first_lut[3][5][APV_VLC_LUT_SIZE]
Definition: apv_decode.h:71
state
static struct @583 state
APVDecodeContext::warned_unknown_pbu_types
uint8_t warned_unknown_pbu_types
Definition: apv_decode.h:115
APVMultiVLCLUTEntry::k_run
uint8_t k_run
Definition: apv_decode.h:50
APVMultiVLCLUTEntry::level
int16_t level[2]
Definition: apv_decode.h:58
APVDerivedTileInfo::row_starts
uint16_t row_starts[APV_MAX_TILE_ROWS+1]
Definition: apv_decode.h:95
APVEntropyState::prev_k_dc
uint8_t prev_k_dc
Definition: apv_decode.h:83
APVVLCLUT::single_lut
APVSingleVLCLUTEntry single_lut[6][APV_VLC_LUT_SIZE]
Definition: apv_decode.h:67
APVMultiVLCLUTEntry::offset
uint8_t offset[4]
Definition: apv_decode.h:60
APVSingleVLCLUTEntry::more
uint8_t more
Definition: apv_decode.h:43
APVDecodeContext::pix_fmt
enum AVPixelFormat pix_fmt
Definition: apv_decode.h:111
APVDerivedTileInfo
Definition: apv_decode.h:88
APVDecodeContext::pkt
AVPacket * pkt
Definition: apv_decode.h:106
APVVLCLUT
Definition: apv_decode.h:63
APVDerivedTileInfo::tile_rows
uint8_t tile_rows
Definition: apv_decode.h:90
APVDerivedTileInfo::col_starts
uint16_t col_starts[APV_MAX_TILE_COLS+1]
Definition: apv_decode.h:94
APV_MAX_TILE_ROWS
@ APV_MAX_TILE_ROWS
Definition: apv.h:76
APVDecodeContext::warned_additional_frames
uint8_t warned_additional_frames
Definition: apv_decode.h:114
APVMultiVLCLUTEntry::count
uint8_t count
Definition: apv_decode.h:48
APVMultiVLCLUTEntry::k_level_0
uint8_t k_level_0
Definition: apv_decode.h:52
APVDecodeContext::cbc
CodedBitstreamContext * cbc
Definition: apv_decode.h:99
AVPacket
This structure stores compressed data.
Definition: packet.h:572
APVDecodeContext::hwaccel_picture_private
void * hwaccel_picture_private
Definition: apv_decode.h:108
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:80
ff_apv_entropy_decode_block
int ff_apv_entropy_decode_block(int16_t *restrict coeff, GetBitContext *restrict gbc, APVEntropyState *restrict state)
Entropy decode a single 8x8 block to coefficients.
Definition: apv_entropy.c:208
APVSingleVLCLUTEntry::consume
uint8_t consume
Definition: apv_decode.h:42
APVDerivedTileInfo::num_tiles
uint16_t num_tiles
Definition: apv_decode.h:91
cbs_apv.h
APVEntropyState::prev_dc
int16_t prev_dc
Definition: apv_decode.h:81
APVEntropyState::decode_lut
const APVVLCLUT * decode_lut
Definition: apv_decode.h:78
APVMultiVLCLUTEntry::k_level_1
uint8_t k_level_1
Definition: apv_decode.h:54