]> git.sesse.net Git - ffmpeg/blob - libavcodec/cbs_vp9.h
Merge commit '76eef04f30a768fa80366d679f3de7e9447b67d5'
[ffmpeg] / libavcodec / cbs_vp9.h
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_CBS_VP9_H
20 #define AVCODEC_CBS_VP9_H
21
22 #include <stddef.h>
23 #include <stdint.h>
24
25 #include "cbs.h"
26
27
28 // Miscellaneous constants (section 3).
29 enum {
30     VP9_REFS_PER_FRAME = 3,
31
32     VP9_MIN_TILE_WIDTH_B64 = 4,
33     VP9_MAX_TILE_WIDTH_B64 = 64,
34
35     VP9_NUM_REF_FRAMES = 8,
36     VP9_MAX_REF_FRAMES = 4,
37
38     VP9_MAX_SEGMENTS = 8,
39     VP9_SEG_LVL_MAX  = 4,
40 };
41
42 // Frame types (section 7.2).
43 enum {
44     VP9_KEY_FRAME     = 0,
45     VP9_NON_KEY_FRAME = 1,
46 };
47
48 // Frame sync bytes (section 7.2.1).
49 enum {
50     VP9_FRAME_SYNC_0 = 0x49,
51     VP9_FRAME_SYNC_1 = 0x83,
52     VP9_FRAME_SYNC_2 = 0x42,
53 };
54
55 // Color space values (section 7.2.2).
56 enum {
57     VP9_CS_UNKNOWN   = 0,
58     VP9_CS_BT_601    = 1,
59     VP9_CS_BT_709    = 2,
60     VP9_CS_SMPTE_170 = 3,
61     VP9_CS_SMPTE_240 = 4,
62     VP9_CS_BT_2020   = 5,
63     VP9_CS_RESERVED  = 6,
64     VP9_CS_RGB       = 7,
65 };
66
67 // Reference frame types (section 7.4.12).
68 enum {
69     VP9_INTRA_FRAME  = 0,
70     VP9_LAST_FRAME   = 1,
71     VP9_GOLDEN_FRAME = 2,
72     VP9_ALTREF_FRAME = 3,
73 };
74
75 // Superframe properties (section B.3).
76 enum {
77     VP9_MAX_FRAMES_IN_SUPERFRAME = 8,
78
79     VP9_SUPERFRAME_MARKER = 6,
80 };
81
82
83 typedef struct VP9RawFrameHeader {
84     uint8_t frame_marker;
85     uint8_t profile_low_bit;
86     uint8_t profile_high_bit;
87     uint8_t profile_reserved_zero;
88
89     uint8_t show_existing_frame;
90     uint8_t frame_to_show_map_idx;
91
92     uint8_t frame_type;
93     uint8_t show_frame;
94     uint8_t error_resilient_mode;
95
96     // Color config.
97     uint8_t ten_or_twelve_bit;
98     uint8_t color_space;
99     uint8_t color_range;
100     uint8_t subsampling_x;
101     uint8_t subsampling_y;
102     uint8_t color_config_reserved_zero;
103
104     uint8_t refresh_frame_flags;
105
106     uint8_t intra_only;
107     uint8_t reset_frame_context;
108
109     uint8_t ref_frame_idx[VP9_REFS_PER_FRAME];
110     uint8_t ref_frame_sign_bias[VP9_MAX_REF_FRAMES];
111
112     uint8_t allow_high_precision_mv;
113
114     uint8_t refresh_frame_context;
115     uint8_t frame_parallel_decoding_mode;
116
117     uint8_t frame_context_idx;
118
119     // Frame/render size.
120     uint8_t found_ref[VP9_REFS_PER_FRAME];
121     uint16_t frame_width_minus_1;
122     uint16_t frame_height_minus_1;
123     uint8_t render_and_frame_size_different;
124     uint16_t render_width_minus_1;
125     uint16_t render_height_minus_1;
126
127     // Interpolation filter.
128     uint8_t is_filter_switchable;
129     uint8_t raw_interpolation_filter_type;
130
131     // Loop filter params.
132     uint8_t loop_filter_level;
133     uint8_t loop_filter_sharpness;
134     uint8_t loop_filter_delta_enabled;
135     uint8_t loop_filter_delta_update;
136     uint8_t update_ref_delta[VP9_MAX_REF_FRAMES];
137     int8_t loop_filter_ref_deltas[VP9_MAX_REF_FRAMES];
138     uint8_t update_mode_delta[2];
139     int8_t loop_filter_mode_deltas[2];
140
141     // Quantization params.
142     uint8_t base_q_idx;
143     int8_t delta_q_y_dc;
144     int8_t delta_q_uv_dc;
145     int8_t delta_q_uv_ac;
146
147     // Segmentation params.
148     uint8_t segmentation_enabled;
149     uint8_t segmentation_update_map;
150     uint8_t segmentation_tree_probs[7];
151     uint8_t segmentation_temporal_update;
152     uint8_t segmentation_pred_prob[3];
153     uint8_t segmentation_update_data;
154     uint8_t segmentation_abs_or_delta_update;
155     uint8_t feature_enabled[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
156     uint8_t feature_value[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
157     uint8_t feature_sign[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
158
159     // Tile info.
160     uint8_t tile_cols_log2;
161     uint8_t tile_rows_log2;
162
163     uint16_t header_size_in_bytes;
164 } VP9RawFrameHeader;
165
166 typedef struct VP9RawFrame {
167     VP9RawFrameHeader header;
168
169     uint8_t     *data;
170     size_t       data_size;
171     AVBufferRef *data_ref;
172 } VP9RawFrame;
173
174 typedef struct VP9RawSuperframeIndex {
175     uint8_t superframe_marker;
176     uint8_t bytes_per_framesize_minus_1;
177     uint8_t frames_in_superframe_minus_1;
178     uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME];
179 } VP9RawSuperframeIndex;
180
181 typedef struct VP9RawSuperframe {
182     VP9RawFrame frames[VP9_MAX_FRAMES_IN_SUPERFRAME];
183     VP9RawSuperframeIndex index;
184 } VP9RawSuperframe;
185
186
187 typedef struct CodedBitstreamVP9Context {
188     // Frame dimensions in 8x8 mode info blocks.
189     uint16_t mi_cols;
190     uint16_t mi_rows;
191     // Frame dimensions in 64x64 superblocks.
192     uint16_t sb64_cols;
193     uint16_t sb64_rows;
194
195     // Write buffer.
196     uint8_t *write_buffer;
197     size_t write_buffer_size;
198 } CodedBitstreamVP9Context;
199
200
201 #endif /* AVCODEC_CBS_VP9_H */