2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVCODEC_CBS_VP9_H
20 #define AVCODEC_CBS_VP9_H
28 // Miscellaneous constants (section 3).
30 VP9_REFS_PER_FRAME = 3,
32 VP9_MIN_TILE_WIDTH_B64 = 4,
33 VP9_MAX_TILE_WIDTH_B64 = 64,
35 VP9_NUM_REF_FRAMES = 8,
36 VP9_MAX_REF_FRAMES = 4,
42 // Frame types (section 7.2).
45 VP9_NON_KEY_FRAME = 1,
48 // Frame sync bytes (section 7.2.1).
50 VP9_FRAME_SYNC_0 = 0x49,
51 VP9_FRAME_SYNC_1 = 0x83,
52 VP9_FRAME_SYNC_2 = 0x42,
55 // Color space values (section 7.2.2).
67 // Reference frame types (section 7.4.12).
75 // Superframe properties (section B.3).
77 VP9_MAX_FRAMES_IN_SUPERFRAME = 8,
79 VP9_SUPERFRAME_MARKER = 6,
83 typedef struct VP9RawFrameHeader {
85 uint8_t profile_low_bit;
86 uint8_t profile_high_bit;
88 uint8_t show_existing_frame;
89 uint8_t frame_to_show_map_idx;
93 uint8_t error_resilient_mode;
96 uint8_t ten_or_twelve_bit;
99 uint8_t subsampling_x;
100 uint8_t subsampling_y;
102 uint8_t refresh_frame_flags;
105 uint8_t reset_frame_context;
107 uint8_t ref_frame_idx[VP9_REFS_PER_FRAME];
108 uint8_t ref_frame_sign_bias[VP9_MAX_REF_FRAMES];
110 uint8_t allow_high_precision_mv;
112 uint8_t refresh_frame_context;
113 uint8_t frame_parallel_decoding_mode;
115 uint8_t frame_context_idx;
117 // Frame/render size.
118 uint8_t found_ref[VP9_REFS_PER_FRAME];
119 uint16_t frame_width_minus_1;
120 uint16_t frame_height_minus_1;
121 uint8_t render_and_frame_size_different;
122 uint16_t render_width_minus_1;
123 uint16_t render_height_minus_1;
125 // Interpolation filter.
126 uint8_t is_filter_switchable;
127 uint8_t raw_interpolation_filter_type;
129 // Loop filter params.
130 uint8_t loop_filter_level;
131 uint8_t loop_filter_sharpness;
132 uint8_t loop_filter_delta_enabled;
133 uint8_t loop_filter_delta_update;
134 uint8_t update_ref_delta[VP9_MAX_REF_FRAMES];
135 int8_t loop_filter_ref_deltas[VP9_MAX_REF_FRAMES];
136 uint8_t update_mode_delta[2];
137 int8_t loop_filter_mode_deltas[2];
139 // Quantization params.
142 int8_t delta_q_uv_dc;
143 int8_t delta_q_uv_ac;
145 // Segmentation params.
146 uint8_t segmentation_enabled;
147 uint8_t segmentation_update_map;
148 uint8_t segmentation_tree_probs[7];
149 uint8_t segmentation_temporal_update;
150 uint8_t segmentation_pred_prob[3];
151 uint8_t segmentation_update_data;
152 uint8_t segmentation_abs_or_delta_update;
153 uint8_t feature_enabled[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
154 uint8_t feature_value[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
155 uint8_t feature_sign[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
158 uint8_t tile_cols_log2;
159 uint8_t tile_rows_log2;
161 uint16_t header_size_in_bytes;
164 typedef struct VP9RawFrame {
165 VP9RawFrameHeader header;
169 AVBufferRef *data_ref;
172 typedef struct VP9RawSuperframeIndex {
173 uint8_t superframe_marker;
174 uint8_t bytes_per_framesize_minus_1;
175 uint8_t frames_in_superframe_minus_1;
176 uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME];
177 } VP9RawSuperframeIndex;
179 typedef struct VP9RawSuperframe {
180 VP9RawFrame frames[VP9_MAX_FRAMES_IN_SUPERFRAME];
181 VP9RawSuperframeIndex index;
184 typedef struct VP9ReferenceFrameState {
185 int frame_width; // RefFrameWidth
186 int frame_height; // RefFrameHeight
187 int subsampling_x; // RefSubsamplingX
188 int subsampling_y; // RefSubsamplingY
189 int bit_depth; // RefBitDepth
190 } VP9ReferenceFrameState;
192 typedef struct CodedBitstreamVP9Context {
195 // Frame dimensions in 8x8 mode info blocks.
198 // Frame dimensions in 64x64 superblocks.
205 uint8_t subsampling_x;
206 uint8_t subsampling_y;
209 VP9ReferenceFrameState ref[VP9_NUM_REF_FRAMES];
212 uint8_t *write_buffer;
213 size_t write_buffer_size;
214 } CodedBitstreamVP9Context;
217 #endif /* AVCODEC_CBS_VP9_H */