OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This file contains an implementation of a VP9 bitstream parser. The main | 5 // This file contains an implementation of a VP9 bitstream parser. The main |
6 // purpose of this parser is to support hardware decode acceleration. Some | 6 // purpose of this parser is to support hardware decode acceleration. Some |
7 // accelerators, e.g. libva which implements VA-API, require the caller | 7 // accelerators, e.g. libva which implements VA-API, require the caller |
8 // (chrome) to feed them parsed VP9 frame header. | 8 // (chrome) to feed them parsed VP9 frame header. |
9 // | 9 // |
10 // See media::VP9Decoder for example usage. | 10 // See media::VP9Decoder for example usage. |
11 // | 11 // |
12 #ifndef MEDIA_FILTERS_VP9_PARSER_H_ | 12 #ifndef MEDIA_FILTERS_VP9_PARSER_H_ |
13 #define MEDIA_FILTERS_VP9_PARSER_H_ | 13 #define MEDIA_FILTERS_VP9_PARSER_H_ |
14 | 14 |
15 #include <stddef.h> | 15 #include <stddef.h> |
16 #include <stdint.h> | 16 #include <stdint.h> |
17 #include <sys/types.h> | 17 #include <sys/types.h> |
18 | 18 |
19 #include <deque> | 19 #include <deque> |
20 | 20 |
| 21 #include "base/callback.h" |
21 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/memory/weak_ptr.h" |
22 #include "media/base/media_export.h" | 24 #include "media/base/media_export.h" |
23 #include "media/filters/vp9_raw_bits_reader.h" | |
24 | 25 |
25 namespace media { | 26 namespace media { |
26 | 27 |
27 const int kVp9MaxProfile = 4; | 28 const int kVp9MaxProfile = 4; |
28 const int kVp9NumRefFramesLog2 = 3; | 29 const int kVp9NumRefFramesLog2 = 3; |
29 const size_t kVp9NumRefFrames = 1 << kVp9NumRefFramesLog2; | 30 const size_t kVp9NumRefFrames = 1 << kVp9NumRefFramesLog2; |
30 const uint8_t kVp9MaxProb = 255; | 31 const uint8_t kVp9MaxProb = 255; |
31 const size_t kVp9NumRefsPerFrame = 3; | 32 const size_t kVp9NumRefsPerFrame = 3; |
| 33 const size_t kVp9NumFrameContexts = 4; |
| 34 |
| 35 using Vp9Prob = uint8_t; |
32 | 36 |
33 enum class Vp9ColorSpace { | 37 enum class Vp9ColorSpace { |
34 UNKNOWN = 0, | 38 UNKNOWN = 0, |
35 BT_601 = 1, | 39 BT_601 = 1, |
36 BT_709 = 2, | 40 BT_709 = 2, |
37 SMPTE_170 = 3, | 41 SMPTE_170 = 3, |
38 SMPTE_240 = 4, | 42 SMPTE_240 = 4, |
39 BT_2020 = 5, | 43 BT_2020 = 5, |
40 RESERVED = 6, | 44 RESERVED = 6, |
41 SRGB = 7, | 45 SRGB = 7, |
42 }; | 46 }; |
43 | 47 |
44 enum Vp9InterpFilter { | 48 enum Vp9InterpolationFilter { |
45 EIGHTTAP = 0, | 49 EIGHTTAP = 0, |
46 EIGHTTAP_SMOOTH = 1, | 50 EIGHTTAP_SMOOTH = 1, |
47 EIGHTTAP_SHARP = 2, | 51 EIGHTTAP_SHARP = 2, |
48 BILINEAR = 3, | 52 BILINEAR = 3, |
49 SWICHABLE = 4, | 53 SWITCHABLE = 4, |
50 }; | 54 }; |
51 | 55 |
52 struct MEDIA_EXPORT Vp9Segmentation { | 56 enum Vp9RefType { |
| 57 VP9_FRAME_INTRA = 0, |
| 58 VP9_FRAME_LAST = 1, |
| 59 VP9_FRAME_GOLDEN = 2, |
| 60 VP9_FRAME_ALTREF = 3, |
| 61 VP9_FRAME_MAX = 4, |
| 62 }; |
| 63 |
| 64 enum Vp9ReferenceMode { |
| 65 SINGLE_REFERENCE = 0, |
| 66 COMPOUND_REFERENCE = 1, |
| 67 REFERENCE_MODE_SELECT = 2, |
| 68 }; |
| 69 |
| 70 struct MEDIA_EXPORT Vp9SegmentationParams { |
53 static const size_t kNumSegments = 8; | 71 static const size_t kNumSegments = 8; |
54 static const size_t kNumTreeProbs = kNumSegments - 1; | 72 static const size_t kNumTreeProbs = kNumSegments - 1; |
55 static const size_t kNumPredictionProbs = 3; | 73 static const size_t kNumPredictionProbs = 3; |
56 enum SegmentLevelFeature { | 74 enum SegmentLevelFeature { |
57 SEG_LVL_ALT_Q = 0, | 75 SEG_LVL_ALT_Q = 0, |
58 SEG_LVL_ALT_LF = 1, | 76 SEG_LVL_ALT_LF = 1, |
59 SEG_LVL_REF_FRAME = 2, | 77 SEG_LVL_REF_FRAME = 2, |
60 SEG_LVL_SKIP = 3, | 78 SEG_LVL_SKIP = 3, |
61 SEG_LVL_MAX | 79 SEG_LVL_MAX |
62 }; | 80 }; |
63 | 81 |
64 bool enabled; | 82 bool enabled; |
65 | 83 |
66 bool update_map; | 84 bool update_map; |
67 uint8_t tree_probs[kNumTreeProbs]; | 85 uint8_t tree_probs[kNumTreeProbs]; |
68 bool temporal_update; | 86 bool temporal_update; |
69 uint8_t pred_probs[kNumPredictionProbs]; | 87 uint8_t pred_probs[kNumPredictionProbs]; |
70 | 88 |
71 bool update_data; | 89 bool update_data; |
72 bool abs_delta; | 90 bool abs_or_delta_update; |
73 bool feature_enabled[kNumSegments][SEG_LVL_MAX]; | 91 bool feature_enabled[kNumSegments][SEG_LVL_MAX]; |
74 int16_t feature_data[kNumSegments][SEG_LVL_MAX]; | 92 int16_t feature_data[kNumSegments][SEG_LVL_MAX]; |
75 | 93 |
76 int16_t y_dequant[kNumSegments][2]; | 94 int16_t y_dequant[kNumSegments][2]; |
77 int16_t uv_dequant[kNumSegments][2]; | 95 int16_t uv_dequant[kNumSegments][2]; |
78 | 96 |
79 bool FeatureEnabled(size_t seg_id, SegmentLevelFeature feature) const { | 97 bool FeatureEnabled(size_t seg_id, SegmentLevelFeature feature) const { |
80 return feature_enabled[seg_id][feature]; | 98 return feature_enabled[seg_id][feature]; |
81 } | 99 } |
82 | 100 |
83 int16_t FeatureData(size_t seg_id, SegmentLevelFeature feature) const { | 101 int16_t FeatureData(size_t seg_id, SegmentLevelFeature feature) const { |
84 return feature_data[seg_id][feature]; | 102 return feature_data[seg_id][feature]; |
85 } | 103 } |
86 }; | 104 }; |
87 | 105 |
88 struct MEDIA_EXPORT Vp9LoopFilter { | 106 struct MEDIA_EXPORT Vp9LoopFilterParams { |
89 enum Vp9FrameType { | |
90 VP9_FRAME_INTRA = 0, | |
91 VP9_FRAME_LAST = 1, | |
92 VP9_FRAME_GOLDEN = 2, | |
93 VP9_FRAME_ALTREF = 3, | |
94 VP9_FRAME_MAX = 4, | |
95 }; | |
96 | |
97 static const size_t kNumModeDeltas = 2; | 107 static const size_t kNumModeDeltas = 2; |
98 | 108 |
99 uint8_t filter_level; | 109 uint8_t level; |
100 uint8_t sharpness_level; | 110 uint8_t sharpness; |
101 | 111 |
102 bool mode_ref_delta_enabled; | 112 bool delta_enabled; |
103 bool mode_ref_delta_update; | 113 bool delta_update; |
104 bool update_ref_deltas[VP9_FRAME_MAX]; | 114 bool update_ref_deltas[VP9_FRAME_MAX]; |
105 int8_t ref_deltas[VP9_FRAME_MAX]; | 115 int8_t ref_deltas[VP9_FRAME_MAX]; |
106 bool update_mode_deltas[kNumModeDeltas]; | 116 bool update_mode_deltas[kNumModeDeltas]; |
107 int8_t mode_deltas[kNumModeDeltas]; | 117 int8_t mode_deltas[kNumModeDeltas]; |
108 | 118 |
109 uint8_t lvl[Vp9Segmentation::kNumSegments][VP9_FRAME_MAX][kNumModeDeltas]; | 119 // Calculated from above fields. |
| 120 uint8_t lvl[Vp9SegmentationParams::kNumSegments][VP9_FRAME_MAX] |
| 121 [kNumModeDeltas]; |
110 }; | 122 }; |
111 | 123 |
112 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseNextFrame. | 124 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseNextFrame. |
113 struct MEDIA_EXPORT Vp9QuantizationParams { | 125 struct MEDIA_EXPORT Vp9QuantizationParams { |
114 bool IsLossless() const { | 126 bool IsLossless() const { |
115 return base_qindex == 0 && y_dc_delta == 0 && uv_dc_delta == 0 && | 127 return base_q_idx == 0 && delta_q_y_dc == 0 && delta_q_uv_dc == 0 && |
116 uv_ac_delta == 0; | 128 delta_q_uv_ac == 0; |
117 } | 129 } |
118 | 130 |
119 uint8_t base_qindex; | 131 uint8_t base_q_idx; |
120 int8_t y_dc_delta; | 132 int8_t delta_q_y_dc; |
121 int8_t uv_dc_delta; | 133 int8_t delta_q_uv_dc; |
122 int8_t uv_ac_delta; | 134 int8_t delta_q_uv_ac; |
| 135 }; |
| 136 |
| 137 // Entropy context for frame parsing |
| 138 struct MEDIA_EXPORT Vp9FrameContext { |
| 139 Vp9Prob tx_probs_8x8[2][1]; |
| 140 Vp9Prob tx_probs_16x16[2][2]; |
| 141 Vp9Prob tx_probs_32x32[2][3]; |
| 142 |
| 143 Vp9Prob coef_probs[4][2][2][6][6][3]; |
| 144 Vp9Prob skip_prob[3]; |
| 145 Vp9Prob inter_mode_probs[7][3]; |
| 146 Vp9Prob interp_filter_probs[4][2]; |
| 147 Vp9Prob is_inter_prob[4]; |
| 148 |
| 149 Vp9Prob comp_mode_prob[5]; |
| 150 Vp9Prob single_ref_prob[5][2]; |
| 151 Vp9Prob comp_ref_prob[5]; |
| 152 |
| 153 Vp9Prob y_mode_probs[4][9]; |
| 154 Vp9Prob uv_mode_probs[10][9]; |
| 155 Vp9Prob partition_probs[16][3]; |
| 156 |
| 157 Vp9Prob mv_joint_probs[3]; |
| 158 Vp9Prob mv_sign_prob[2]; |
| 159 Vp9Prob mv_class_probs[2][10]; |
| 160 Vp9Prob mv_class0_bit_prob[2]; |
| 161 Vp9Prob mv_bits_prob[2][10]; |
| 162 Vp9Prob mv_class0_fr_probs[2][2][3]; |
| 163 Vp9Prob mv_fr_probs[2][3]; |
| 164 Vp9Prob mv_class0_hp_prob[2]; |
| 165 Vp9Prob mv_hp_prob[2]; |
| 166 }; |
| 167 |
| 168 struct MEDIA_EXPORT Vp9CompressedHeader { |
| 169 enum Vp9TxMode { |
| 170 ONLY_4X4 = 0, |
| 171 ALLOW_8X8 = 1, |
| 172 ALLOW_16X16 = 2, |
| 173 ALLOW_32X32 = 3, |
| 174 TX_MODE_SELECT = 4, |
| 175 TX_MODES = 5, |
| 176 }; |
| 177 |
| 178 Vp9TxMode tx_mode; |
| 179 Vp9ReferenceMode reference_mode; |
123 }; | 180 }; |
124 | 181 |
125 // VP9 frame header. | 182 // VP9 frame header. |
126 struct MEDIA_EXPORT Vp9FrameHeader { | 183 struct MEDIA_EXPORT Vp9FrameHeader { |
127 enum FrameType { | 184 enum FrameType { |
128 KEYFRAME = 0, | 185 KEYFRAME = 0, |
129 INTERFRAME = 1, | 186 INTERFRAME = 1, |
130 }; | 187 }; |
131 | 188 |
132 bool IsKeyframe() const; | 189 bool IsKeyframe() const; |
133 bool RefreshFlag(size_t i) const { return !!(refresh_flags & (1u << i)); } | 190 bool IsIntra() const; |
| 191 bool RefreshFlag(size_t i) const { |
| 192 return !!(refresh_frame_flags & (1u << i)); |
| 193 } |
134 | 194 |
135 uint8_t profile; | 195 uint8_t profile; |
136 | 196 |
137 bool show_existing_frame; | 197 bool show_existing_frame; |
138 uint8_t frame_to_show; | 198 uint8_t frame_to_show_map_idx; |
139 | 199 |
140 FrameType frame_type; | 200 FrameType frame_type; |
141 | 201 |
142 bool show_frame; | 202 bool show_frame; |
143 bool error_resilient_mode; | 203 bool error_resilient_mode; |
144 | 204 |
145 uint8_t bit_depth; | 205 uint8_t bit_depth; |
146 Vp9ColorSpace color_space; | 206 Vp9ColorSpace color_space; |
147 bool yuv_range; | 207 bool color_range; |
148 uint8_t subsampling_x; | 208 uint8_t subsampling_x; |
149 uint8_t subsampling_y; | 209 uint8_t subsampling_y; |
150 | 210 |
151 // The range of width and height is 1..2^16. | 211 // The range of frame_width and frame_height is 1..2^16. |
152 uint32_t width; | 212 uint32_t frame_width; |
153 uint32_t height; | 213 uint32_t frame_height; |
154 uint32_t display_width; | 214 uint32_t render_width; |
155 uint32_t display_height; | 215 uint32_t render_height; |
156 | 216 |
157 bool intra_only; | 217 bool intra_only; |
158 uint8_t reset_context; | 218 uint8_t reset_frame_context; |
159 uint8_t refresh_flags; | 219 uint8_t refresh_frame_flags; |
160 uint8_t frame_refs[kVp9NumRefsPerFrame]; | 220 uint8_t ref_frame_idx[kVp9NumRefsPerFrame]; |
161 bool ref_sign_biases[kVp9NumRefsPerFrame]; | 221 bool ref_frame_sign_bias[Vp9RefType::VP9_FRAME_MAX]; |
162 bool allow_high_precision_mv; | 222 bool allow_high_precision_mv; |
163 Vp9InterpFilter interp_filter; | 223 Vp9InterpolationFilter interpolation_filter; |
164 | 224 |
165 bool refresh_frame_context; | 225 bool refresh_frame_context; |
166 bool frame_parallel_decoding_mode; | 226 bool frame_parallel_decoding_mode; |
167 uint8_t frame_context_idx; | 227 uint8_t frame_context_idx; |
| 228 // |frame_context_idx_to_save_probs| is to be used by save_probs() only, and |
| 229 // |frame_context_idx| otherwise. |
| 230 uint8_t frame_context_idx_to_save_probs; |
168 | 231 |
169 Vp9QuantizationParams quant_params; | 232 Vp9QuantizationParams quant_params; |
170 | 233 |
171 uint8_t log2_tile_cols; | 234 uint8_t tile_cols_log2; |
172 uint8_t log2_tile_rows; | 235 uint8_t tile_rows_log2; |
173 | 236 |
174 // Pointer to the beginning of frame data. It is a responsibility of the | 237 // Pointer to the beginning of frame data. It is a responsibility of the |
175 // client of the Vp9Parser to maintain validity of this data while it is | 238 // client of the Vp9Parser to maintain validity of this data while it is |
176 // being used outside of that class. | 239 // being used outside of that class. |
177 const uint8_t* data; | 240 const uint8_t* data; |
178 | 241 |
179 // Size of |data| in bytes. | 242 // Size of |data| in bytes. |
180 size_t frame_size; | 243 size_t frame_size; |
181 | 244 |
182 // Size of compressed header in bytes. | 245 // Size of compressed header in bytes. |
183 size_t first_partition_size; | 246 size_t header_size_in_bytes; |
184 | 247 |
185 // Size of uncompressed header in bytes. | 248 // Size of uncompressed header in bytes. |
186 size_t uncompressed_header_size; | 249 size_t uncompressed_header_size; |
| 250 |
| 251 Vp9CompressedHeader compressed_header; |
| 252 // Initial frame entropy context after load_probs2(frame_context_idx). |
| 253 Vp9FrameContext initial_frame_context; |
| 254 // Current frame entropy context after header parsing. |
| 255 Vp9FrameContext frame_context; |
| 256 }; |
| 257 |
| 258 class Vp9FrameContextManager { |
| 259 public: |
| 260 // If context update is needed after decoding a frame, the client must |
| 261 // execute this callback, passing the updated context state. |
| 262 using ContextRefreshCallback = base::Callback<void(const Vp9FrameContext&)>; |
| 263 |
| 264 static bool IsValidFrameContext(const Vp9FrameContext& context); |
| 265 |
| 266 Vp9FrameContextManager(); |
| 267 ~Vp9FrameContextManager(); |
| 268 bool initialized() const { return initialized_; } |
| 269 bool needs_client_update() const { return needs_client_update_; } |
| 270 const Vp9FrameContext& frame_context() const; |
| 271 |
| 272 // Resets to uninitialized state. |
| 273 void Reset(); |
| 274 |
| 275 // Sets this context need update from parser's client. Returns a callback for |
| 276 // update. |
| 277 ContextRefreshCallback SetNeedsClientUpdate(); |
| 278 |
| 279 // Updates frame context. |
| 280 void Update(const Vp9FrameContext& frame_context); |
| 281 |
| 282 private: |
| 283 // Updates frame context from parser's client. |
| 284 void UpdateFromClient(const Vp9FrameContext& frame_context); |
| 285 |
| 286 bool initialized_ = false; |
| 287 bool needs_client_update_ = false; |
| 288 Vp9FrameContext frame_context_; |
| 289 |
| 290 base::WeakPtrFactory<Vp9FrameContextManager> weak_ptr_factory_; |
187 }; | 291 }; |
188 | 292 |
189 // A parser for VP9 bitstream. | 293 // A parser for VP9 bitstream. |
190 class MEDIA_EXPORT Vp9Parser { | 294 class MEDIA_EXPORT Vp9Parser { |
191 public: | 295 public: |
192 // ParseNextFrame() return values. See documentation for ParseNextFrame(). | 296 // ParseNextFrame() return values. See documentation for ParseNextFrame(). |
193 enum Result { | 297 enum Result { |
194 kOk, | 298 kOk, |
195 kInvalidStream, | 299 kInvalidStream, |
196 kEOStream, | 300 kEOStream, |
| 301 kAwaitingRefresh, |
197 }; | 302 }; |
198 | 303 |
199 Vp9Parser(); | 304 // The parsing context to keep track of references. |
| 305 struct ReferenceSlot { |
| 306 bool initialized; |
| 307 uint32_t frame_width; |
| 308 uint32_t frame_height; |
| 309 uint8_t subsampling_x; |
| 310 uint8_t subsampling_y; |
| 311 uint8_t bit_depth; |
| 312 |
| 313 // More fields for consistency checking. |
| 314 uint8_t profile; |
| 315 Vp9ColorSpace color_space; |
| 316 }; |
| 317 |
| 318 // The parsing context that persists across frames. |
| 319 struct Context { |
| 320 void Reset(); |
| 321 |
| 322 // Segmentation and loop filter state. |
| 323 Vp9SegmentationParams segmentation; |
| 324 Vp9LoopFilterParams loop_filter; |
| 325 |
| 326 // Frame references. |
| 327 ReferenceSlot ref_slots[kVp9NumRefFrames]; |
| 328 |
| 329 Vp9FrameContextManager frame_context_managers[kVp9NumFrameContexts]; |
| 330 }; |
| 331 |
| 332 // The constructor. See ParseNextFrame() for comments for |
| 333 // |parsing_compressed_header|. |
| 334 explicit Vp9Parser(bool parsing_compressed_header); |
200 ~Vp9Parser(); | 335 ~Vp9Parser(); |
201 | 336 |
202 // Set a new stream buffer to read from, starting at |stream| and of size | 337 // Set a new stream buffer to read from, starting at |stream| and of size |
203 // |stream_size| in bytes. |stream| must point to the beginning of a single | 338 // |stream_size| in bytes. |stream| must point to the beginning of a single |
204 // frame or a single superframe, is owned by caller and must remain valid | 339 // frame or a single superframe, is owned by caller and must remain valid |
205 // until the next call to SetStream(). | 340 // until the next call to SetStream(). |
206 void SetStream(const uint8_t* stream, off_t stream_size); | 341 void SetStream(const uint8_t* stream, off_t stream_size); |
207 | 342 |
208 // Parse the next frame in the current stream buffer, filling |fhdr| with | 343 // Parse the next frame in the current stream buffer, filling |fhdr| with |
209 // the parsed frame header and updating current segmentation and loop filter | 344 // the parsed frame header and updating current segmentation and loop filter |
210 // state. Return kOk if a frame has successfully been parsed, kEOStream if | 345 // state. If |parsing_compressed_header_|, this function also fills |
211 // there is no more data in the current stream buffer, or kInvalidStream | 346 // |context_refresh_cb|, which is used to update frame context. If |
212 // on error. | 347 // |*context_refresh_cb| is null, no callback is necessary. |
213 Result ParseNextFrame(Vp9FrameHeader* fhdr); | 348 // Return kOk if a frame has successfully been parsed, |
| 349 // kEOStream if there is no more data in the current stream buffer, |
| 350 // kAwaitingRefresh if this frame awaiting frame context update, or |
| 351 // kInvalidStream on error. |
| 352 Result ParseNextFrame( |
| 353 Vp9FrameHeader* fhdr, |
| 354 Vp9FrameContextManager::ContextRefreshCallback* context_refresh_cb); |
214 | 355 |
215 // Return current segmentation state. | 356 // Return current segmentation state. |
216 const Vp9Segmentation& GetSegmentation() const { return segmentation_; } | 357 const Vp9SegmentationParams& GetSegmentation() const { |
| 358 return context_.segmentation; |
| 359 } |
217 | 360 |
218 // Return current loop filter state. | 361 // Return current loop filter state. |
219 const Vp9LoopFilter& GetLoopFilter() const { return loop_filter_; } | 362 const Vp9LoopFilterParams& GetLoopFilter() const { |
| 363 return context_.loop_filter; |
| 364 } |
220 | 365 |
221 // Clear parser state and return to an initialized state. | 366 // Clear parser state and return to an initialized state. |
222 void Reset(); | 367 void Reset(); |
223 | 368 |
224 private: | 369 private: |
225 // The parsing context to keep track of references. | 370 class UncompressedHeaderParser; |
226 struct ReferenceSlot { | 371 class CompressedHeaderParser; |
227 uint32_t width; | 372 |
228 uint32_t height; | 373 // Stores start pointer and size of each frame within the current superframe. |
| 374 struct FrameInfo { |
| 375 FrameInfo() = default; |
| 376 FrameInfo(const uint8_t* ptr, off_t size); |
| 377 bool IsValid() const { return ptr != nullptr; } |
| 378 void Reset() { ptr = nullptr; } |
| 379 |
| 380 // Starting address of the frame. |
| 381 const uint8_t* ptr = nullptr; |
| 382 |
| 383 // Size of the frame in bytes. |
| 384 off_t size = 0; |
229 }; | 385 }; |
230 | 386 |
231 bool ParseSuperframe(); | 387 std::deque<FrameInfo> ParseSuperframe(); |
232 uint8_t ReadProfile(); | |
233 bool VerifySyncCode(); | |
234 bool ReadBitDepthColorSpaceSampling(Vp9FrameHeader* fhdr); | |
235 void ReadFrameSize(Vp9FrameHeader* fhdr); | |
236 bool ReadFrameSizeFromRefs(Vp9FrameHeader* fhdr); | |
237 void ReadDisplayFrameSize(Vp9FrameHeader* fhdr); | |
238 Vp9InterpFilter ReadInterpFilter(); | |
239 void ReadLoopFilter(); | |
240 void ReadQuantization(Vp9QuantizationParams* quants); | |
241 void ReadSegmentationMap(); | |
242 void ReadSegmentationData(); | |
243 void ReadSegmentation(); | |
244 void ReadTiles(Vp9FrameHeader* fhdr); | |
245 bool ParseUncompressedHeader(const uint8_t* stream, | |
246 off_t frame_size, | |
247 Vp9FrameHeader* fhdr); | |
248 void UpdateSlots(const Vp9FrameHeader* fhdr); | |
249 | 388 |
250 void ResetLoopfilter(); | |
251 void SetupPastIndependence(); | |
252 size_t GetQIndex(const Vp9QuantizationParams& quant, size_t segid) const; | 389 size_t GetQIndex(const Vp9QuantizationParams& quant, size_t segid) const; |
253 void SetupSegmentationDequant(const Vp9QuantizationParams& quant); | 390 void SetupSegmentationDequant(); |
254 void SetupLoopFilter(); | 391 void SetupLoopFilter(); |
| 392 void UpdateSlots(); |
255 | 393 |
256 // Current address in the bitstream buffer. | 394 // Current address in the bitstream buffer. |
257 const uint8_t* stream_; | 395 const uint8_t* stream_; |
258 | 396 |
259 // Remaining bytes in stream_. | 397 // Remaining bytes in stream_. |
260 off_t bytes_left_; | 398 off_t bytes_left_; |
261 | 399 |
262 // Stores start pointer and size of each frame within the current superframe. | 400 bool parsing_compressed_header_; |
263 struct FrameInfo { | |
264 FrameInfo(const uint8_t* ptr, off_t size); | |
265 | |
266 // Starting address of the frame. | |
267 const uint8_t* ptr; | |
268 | |
269 // Size of the frame in bytes. | |
270 off_t size; | |
271 }; | |
272 | 401 |
273 // FrameInfo for the remaining frames in the current superframe to be parsed. | 402 // FrameInfo for the remaining frames in the current superframe to be parsed. |
274 std::deque<FrameInfo> frames_; | 403 std::deque<FrameInfo> frames_; |
275 | 404 |
276 // Raw bits decoder for uncompressed frame header. | 405 Context context_; |
277 Vp9RawBitsReader reader_; | |
278 | 406 |
279 // Segmentation and loop filter state that persists across frames. | 407 FrameInfo curr_frame_info_; |
280 Vp9Segmentation segmentation_; | 408 Vp9FrameHeader curr_frame_header_; |
281 Vp9LoopFilter loop_filter_; | |
282 | |
283 // The parsing context to keep track of references. | |
284 ReferenceSlot ref_slots_[kVp9NumRefFrames]; | |
285 | 409 |
286 DISALLOW_COPY_AND_ASSIGN(Vp9Parser); | 410 DISALLOW_COPY_AND_ASSIGN(Vp9Parser); |
287 }; | 411 }; |
288 | 412 |
289 } // namespace media | 413 } // namespace media |
290 | 414 |
291 #endif // MEDIA_FILTERS_VP9_PARSER_H_ | 415 #endif // MEDIA_FILTERS_VP9_PARSER_H_ |
OLD | NEW |