Chromium Code Reviews| 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 int kVp9NumFrameContext = 4; | |
|
Pawel Osciak
2016/08/04 10:20:19
size_t ?
s/Context/Contexts/ ?
kcwu
2016/08/05 11:38:47
Done.
| |
| 34 | |
| 35 typedef uint8_t Vp9Prob; | |
|
Pawel Osciak
2016/08/04 10:20:19
Nit: perhaps "using" syntax?
Perhaps move to into
kcwu
2016/08/05 11:38:47
It's not only used in context class.
| |
| 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 Vp9FrameType { |
|
Pawel Osciak
2016/08/04 10:20:19
Perhaps RefType? We already have FrameType in head
kcwu
2016/08/05 11:38:48
Done.
| |
| 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 Vp9TxMode { | |
|
Pawel Osciak
2016/08/04 10:20:19
Perhaps move to Vp9Compressed header?
kcwu
2016/08/05 11:38:48
Done.
| |
| 65 ONLY_4X4 = 0, | |
| 66 ALLOW_8X8 = 1, | |
| 67 ALLOW_16X16 = 2, | |
| 68 ALLOW_32X32 = 3, | |
| 69 TX_MODE_SELECT = 4, | |
| 70 TX_MODES = 5, | |
| 71 }; | |
| 72 | |
| 73 enum Vp9TxSize { | |
|
Pawel Osciak
2016/08/04 10:20:19
Perhaps we should move this to ReadCoefProbs()?
kcwu
2016/08/05 11:38:47
Done.
| |
| 74 TX_4X4 = 0, | |
| 75 TX_8X8 = 1, | |
| 76 TX_16X16 = 2, | |
| 77 TX_32X32 = 3, | |
| 78 TX_SIZES = 4, | |
| 79 }; | |
| 80 | |
| 81 enum Vp9ReferenceMode { | |
| 82 SINGLE_REFERENCE = 0, | |
| 83 COMPOUND_REFERENCE = 1, | |
| 84 REFERENCE_MODE_SELECT = 2, | |
| 85 }; | |
| 86 | |
| 87 struct MEDIA_EXPORT Vp9SegmentationParams { | |
| 53 static const size_t kNumSegments = 8; | 88 static const size_t kNumSegments = 8; |
| 54 static const size_t kNumTreeProbs = kNumSegments - 1; | 89 static const size_t kNumTreeProbs = kNumSegments - 1; |
| 55 static const size_t kNumPredictionProbs = 3; | 90 static const size_t kNumPredictionProbs = 3; |
| 56 enum SegmentLevelFeature { | 91 enum SegmentLevelFeature { |
| 57 SEG_LVL_ALT_Q = 0, | 92 SEG_LVL_ALT_Q = 0, |
| 58 SEG_LVL_ALT_LF = 1, | 93 SEG_LVL_ALT_LF = 1, |
| 59 SEG_LVL_REF_FRAME = 2, | 94 SEG_LVL_REF_FRAME = 2, |
| 60 SEG_LVL_SKIP = 3, | 95 SEG_LVL_SKIP = 3, |
| 61 SEG_LVL_MAX | 96 SEG_LVL_MAX |
| 62 }; | 97 }; |
| 63 | 98 |
| 64 bool enabled; | 99 bool enabled; |
| 65 | 100 |
| 66 bool update_map; | 101 bool update_map; |
| 67 uint8_t tree_probs[kNumTreeProbs]; | 102 uint8_t tree_probs[kNumTreeProbs]; |
| 68 bool temporal_update; | 103 bool temporal_update; |
| 69 uint8_t pred_probs[kNumPredictionProbs]; | 104 uint8_t pred_probs[kNumPredictionProbs]; |
| 70 | 105 |
| 71 bool update_data; | 106 bool update_data; |
| 72 bool abs_delta; | 107 bool abs_or_delta_update; |
| 73 bool feature_enabled[kNumSegments][SEG_LVL_MAX]; | 108 bool feature_enabled[kNumSegments][SEG_LVL_MAX]; |
| 74 int16_t feature_data[kNumSegments][SEG_LVL_MAX]; | 109 int16_t feature_data[kNumSegments][SEG_LVL_MAX]; |
| 75 | 110 |
| 76 int16_t y_dequant[kNumSegments][2]; | 111 int16_t y_dequant[kNumSegments][2]; |
| 77 int16_t uv_dequant[kNumSegments][2]; | 112 int16_t uv_dequant[kNumSegments][2]; |
| 78 | 113 |
| 79 bool FeatureEnabled(size_t seg_id, SegmentLevelFeature feature) const { | 114 bool FeatureEnabled(size_t seg_id, SegmentLevelFeature feature) const { |
| 80 return feature_enabled[seg_id][feature]; | 115 return feature_enabled[seg_id][feature]; |
| 81 } | 116 } |
| 82 | 117 |
| 83 int16_t FeatureData(size_t seg_id, SegmentLevelFeature feature) const { | 118 int16_t FeatureData(size_t seg_id, SegmentLevelFeature feature) const { |
| 84 return feature_data[seg_id][feature]; | 119 return feature_data[seg_id][feature]; |
| 85 } | 120 } |
| 86 }; | 121 }; |
| 87 | 122 |
| 88 struct MEDIA_EXPORT Vp9LoopFilter { | 123 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; | 124 static const size_t kNumModeDeltas = 2; |
| 98 | 125 |
| 99 uint8_t filter_level; | 126 uint8_t level; |
| 100 uint8_t sharpness_level; | 127 uint8_t sharpness; |
| 101 | 128 |
| 102 bool mode_ref_delta_enabled; | 129 bool delta_enabled; |
| 103 bool mode_ref_delta_update; | 130 bool delta_update; |
| 104 bool update_ref_deltas[VP9_FRAME_MAX]; | 131 bool update_ref_deltas[VP9_FRAME_MAX]; |
| 105 int8_t ref_deltas[VP9_FRAME_MAX]; | 132 int8_t ref_deltas[VP9_FRAME_MAX]; |
| 106 bool update_mode_deltas[kNumModeDeltas]; | 133 bool update_mode_deltas[kNumModeDeltas]; |
| 107 int8_t mode_deltas[kNumModeDeltas]; | 134 int8_t mode_deltas[kNumModeDeltas]; |
| 108 | 135 |
| 109 uint8_t lvl[Vp9Segmentation::kNumSegments][VP9_FRAME_MAX][kNumModeDeltas]; | 136 // calculated from above fields |
|
Pawel Osciak
2016/08/04 10:20:19
Nit: to match the style, please capitalize first l
kcwu
2016/08/05 11:38:48
Done.
| |
| 137 uint8_t lvl[Vp9SegmentationParams::kNumSegments][VP9_FRAME_MAX] | |
| 138 [kNumModeDeltas]; | |
| 110 }; | 139 }; |
| 111 | 140 |
| 112 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseNextFrame. | 141 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseNextFrame. |
| 113 struct MEDIA_EXPORT Vp9QuantizationParams { | 142 struct MEDIA_EXPORT Vp9QuantizationParams { |
| 114 bool IsLossless() const { | 143 bool IsLossless() const { |
| 115 return base_qindex == 0 && y_dc_delta == 0 && uv_dc_delta == 0 && | 144 return base_q_idx == 0 && delta_q_y_dc == 0 && delta_q_uv_dc == 0 && |
| 116 uv_ac_delta == 0; | 145 delta_q_uv_ac == 0; |
| 117 } | 146 } |
| 118 | 147 |
| 119 uint8_t base_qindex; | 148 uint8_t base_q_idx; |
| 120 int8_t y_dc_delta; | 149 int8_t delta_q_y_dc; |
| 121 int8_t uv_dc_delta; | 150 int8_t delta_q_uv_dc; |
| 122 int8_t uv_ac_delta; | 151 int8_t delta_q_uv_ac; |
| 152 }; | |
| 153 | |
| 154 // Entropy context for frame parsing | |
| 155 struct MEDIA_EXPORT Vp9FrameContext { | |
| 156 Vp9Prob tx_probs_8x8[2][1]; | |
| 157 Vp9Prob tx_probs_16x16[2][2]; | |
| 158 Vp9Prob tx_probs_32x32[2][3]; | |
| 159 | |
| 160 Vp9Prob coef_probs[4][2][2][6][6][3]; | |
| 161 Vp9Prob skip_prob[3]; | |
| 162 Vp9Prob inter_mode_probs[7][3]; | |
| 163 Vp9Prob interp_filter_probs[4][2]; | |
| 164 Vp9Prob is_inter_prob[4]; | |
| 165 | |
| 166 Vp9Prob comp_mode_prob[5]; | |
| 167 Vp9Prob single_ref_prob[5][2]; | |
| 168 Vp9Prob comp_ref_prob[5]; | |
| 169 | |
| 170 Vp9Prob y_mode_probs[4][9]; | |
| 171 Vp9Prob uv_mode_probs[10][9]; | |
| 172 Vp9Prob partition_probs[16][3]; | |
| 173 | |
| 174 Vp9Prob mv_joint_probs[3]; | |
| 175 Vp9Prob mv_sign_prob[2]; | |
| 176 Vp9Prob mv_class_probs[2][10]; | |
| 177 Vp9Prob mv_class0_bit_prob[2]; | |
| 178 Vp9Prob mv_bits_prob[2][10]; | |
| 179 Vp9Prob mv_class0_fr_probs[2][2][3]; | |
| 180 Vp9Prob mv_fr_probs[2][3]; | |
| 181 Vp9Prob mv_class0_hp_prob[2]; | |
| 182 Vp9Prob mv_hp_prob[2]; | |
| 183 }; | |
| 184 | |
| 185 struct MEDIA_EXPORT Vp9CompressedHeader { | |
| 186 Vp9TxMode tx_mode; | |
| 187 Vp9ReferenceMode reference_mode; | |
| 123 }; | 188 }; |
| 124 | 189 |
| 125 // VP9 frame header. | 190 // VP9 frame header. |
| 126 struct MEDIA_EXPORT Vp9FrameHeader { | 191 struct MEDIA_EXPORT Vp9FrameHeader { |
| 127 enum FrameType { | 192 enum FrameType { |
| 128 KEYFRAME = 0, | 193 KEYFRAME = 0, |
| 129 INTERFRAME = 1, | 194 INTERFRAME = 1, |
| 130 }; | 195 }; |
| 131 | 196 |
| 132 bool IsKeyframe() const; | 197 bool IsKeyframe() const; |
| 133 bool RefreshFlag(size_t i) const { return !!(refresh_flags & (1u << i)); } | 198 bool IsIntra() const; |
| 199 bool RefreshFlag(size_t i) const { | |
| 200 return !!(refresh_frame_flags & (1u << i)); | |
| 201 } | |
| 134 | 202 |
| 135 uint8_t profile; | 203 uint8_t profile; |
| 136 | 204 |
| 137 bool show_existing_frame; | 205 bool show_existing_frame; |
| 138 uint8_t frame_to_show; | 206 uint8_t frame_to_show_map_idx; |
| 139 | 207 |
| 140 FrameType frame_type; | 208 FrameType frame_type; |
| 141 | 209 |
| 142 bool show_frame; | 210 bool show_frame; |
| 143 bool error_resilient_mode; | 211 bool error_resilient_mode; |
| 144 | 212 |
| 145 uint8_t bit_depth; | 213 uint8_t bit_depth; |
| 146 Vp9ColorSpace color_space; | 214 Vp9ColorSpace color_space; |
| 147 bool yuv_range; | 215 bool color_range; |
| 148 uint8_t subsampling_x; | 216 uint8_t subsampling_x; |
| 149 uint8_t subsampling_y; | 217 uint8_t subsampling_y; |
| 150 | 218 |
| 151 // The range of width and height is 1..2^16. | 219 // The range of frame_width and frame_height is 1..2^16. |
| 152 uint32_t width; | 220 uint32_t frame_width; |
| 153 uint32_t height; | 221 uint32_t frame_height; |
| 154 uint32_t display_width; | 222 uint32_t render_width; |
| 155 uint32_t display_height; | 223 uint32_t render_height; |
| 156 | 224 |
| 157 bool intra_only; | 225 bool intra_only; |
| 158 uint8_t reset_context; | 226 uint8_t reset_frame_context; |
| 159 uint8_t refresh_flags; | 227 uint8_t refresh_frame_flags; |
| 160 uint8_t frame_refs[kVp9NumRefsPerFrame]; | 228 uint8_t ref_frame_idx[kVp9NumRefsPerFrame]; |
| 161 bool ref_sign_biases[kVp9NumRefsPerFrame]; | 229 bool ref_frame_sign_bias[Vp9FrameType::VP9_FRAME_MAX]; |
| 162 bool allow_high_precision_mv; | 230 bool allow_high_precision_mv; |
| 163 Vp9InterpFilter interp_filter; | 231 Vp9InterpolationFilter interpolation_filter; |
| 164 | 232 |
| 165 bool refresh_frame_context; | 233 bool refresh_frame_context; |
| 166 bool frame_parallel_decoding_mode; | 234 bool frame_parallel_decoding_mode; |
| 167 uint8_t frame_context_idx; | 235 uint8_t frame_context_idx; |
| 236 // |frame_context_idx| may change later, backup the original value parsed | |
| 237 // from the stream. | |
| 238 uint8_t frame_context_idx_backup; | |
|
Pawel Osciak
2016/08/04 10:20:19
Perhaps frame_context_idx and frame_context_idx_to
kcwu
2016/08/05 11:38:48
Done.
However, it seem look odd for vaapi_vda.
| |
| 168 | 239 |
| 169 Vp9QuantizationParams quant_params; | 240 Vp9QuantizationParams quant_params; |
| 170 | 241 |
| 171 uint8_t log2_tile_cols; | 242 uint8_t tile_cols_log2; |
| 172 uint8_t log2_tile_rows; | 243 uint8_t tile_rows_log2; |
| 173 | 244 |
| 174 // Pointer to the beginning of frame data. It is a responsibility of the | 245 // 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 | 246 // client of the Vp9Parser to maintain validity of this data while it is |
| 176 // being used outside of that class. | 247 // being used outside of that class. |
| 177 const uint8_t* data; | 248 const uint8_t* data; |
| 178 | 249 |
| 179 // Size of |data| in bytes. | 250 // Size of |data| in bytes. |
| 180 size_t frame_size; | 251 size_t frame_size; |
| 181 | 252 |
| 182 // Size of compressed header in bytes. | 253 // Size of compressed header in bytes. |
| 183 size_t first_partition_size; | 254 size_t header_size_in_bytes; |
| 184 | 255 |
| 185 // Size of uncompressed header in bytes. | 256 // Size of uncompressed header in bytes. |
| 186 size_t uncompressed_header_size; | 257 size_t uncompressed_header_size; |
| 258 | |
| 259 Vp9CompressedHeader compressed_header; | |
| 260 // Initial frame entropy context after load_probs2(frame_context_idx). | |
| 261 Vp9FrameContext initial_frame_context; | |
| 262 // Current frame entropy context after header parsing. | |
| 263 Vp9FrameContext frame_context; | |
| 264 }; | |
| 265 | |
| 266 class Vp9FrameContextManager { | |
| 267 public: | |
| 268 using ContextRefreshCallback = base::Callback<void(const Vp9FrameContext&)>; | |
|
Pawel Osciak
2016/08/04 10:20:19
Please document.
kcwu
2016/08/05 11:38:48
Done.
| |
| 269 | |
| 270 static bool IsValidFrameContext(const Vp9FrameContext& context); | |
| 271 | |
| 272 Vp9FrameContextManager(); | |
| 273 ~Vp9FrameContextManager(); | |
| 274 bool initialized() const { return initialized_; } | |
| 275 bool need_update() const { return need_update_; } | |
|
Pawel Osciak
2016/08/04 10:20:19
s/need/needs/
kcwu
2016/08/05 11:38:48
Done.
| |
| 276 const Vp9FrameContext& frame_context() const; | |
| 277 | |
| 278 void Reset(); | |
|
Pawel Osciak
2016/08/04 10:20:19
Please document methods.
kcwu
2016/08/05 11:38:48
Done.
| |
| 279 ContextRefreshCallback SetNeedUpdate(); | |
| 280 void Update(const Vp9FrameContext& frame_context); | |
| 281 | |
| 282 private: | |
| 283 bool initialized_; | |
| 284 bool need_update_; | |
| 285 Vp9FrameContext frame_context_; | |
| 286 | |
| 287 base::WeakPtrFactory<Vp9FrameContextManager> weak_ptr_factory_; | |
| 187 }; | 288 }; |
| 188 | 289 |
| 189 // A parser for VP9 bitstream. | 290 // A parser for VP9 bitstream. |
| 190 class MEDIA_EXPORT Vp9Parser { | 291 class MEDIA_EXPORT Vp9Parser { |
| 191 public: | 292 public: |
| 192 // ParseNextFrame() return values. See documentation for ParseNextFrame(). | 293 // ParseNextFrame() return values. See documentation for ParseNextFrame(). |
| 193 enum Result { | 294 enum Result { |
| 194 kOk, | 295 kOk, |
| 195 kInvalidStream, | 296 kInvalidStream, |
| 196 kEOStream, | 297 kEOStream, |
| 298 kAwaitingRefresh, | |
| 197 }; | 299 }; |
| 198 | 300 |
| 199 Vp9Parser(); | 301 // The parsing context to keep track of references. |
| 302 struct ReferenceSlot { | |
| 303 bool initialized; | |
| 304 uint32_t frame_width; | |
| 305 uint32_t frame_height; | |
| 306 uint8_t subsampling_x; | |
| 307 uint8_t subsampling_y; | |
| 308 uint8_t bit_depth; | |
| 309 | |
| 310 // More fields for consistency checking. | |
|
Pawel Osciak
2016/08/04 10:20:19
I think color_space we also use to copy to frame_h
kcwu
2016/08/05 11:38:48
Yes, but it is not mentioned in spec 8.10. I list
Pawel Osciak
2016/08/08 08:13:36
Acknowledged.
| |
| 311 uint8_t profile; | |
| 312 Vp9ColorSpace color_space; | |
| 313 }; | |
| 314 | |
| 315 // The parsing context that persists across frames. | |
| 316 struct Context { | |
| 317 void Reset(); | |
| 318 | |
| 319 // Segmentation and loop filter state. | |
| 320 Vp9SegmentationParams segmentation; | |
| 321 Vp9LoopFilterParams loop_filter; | |
| 322 | |
| 323 // Frame references. | |
| 324 ReferenceSlot ref_slots[kVp9NumRefFrames]; | |
| 325 | |
| 326 Vp9FrameContextManager frame_context_managers[kVp9NumFrameContext]; | |
| 327 }; | |
| 328 | |
| 329 explicit Vp9Parser(bool parsing_compressed_header); | |
|
Pawel Osciak
2016/08/04 10:20:19
Please document, maybe referring to ParseNextFrame
kcwu
2016/08/05 11:38:47
Done.
| |
| 200 ~Vp9Parser(); | 330 ~Vp9Parser(); |
| 201 | 331 |
| 202 // Set a new stream buffer to read from, starting at |stream| and of size | 332 // 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 | 333 // |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 | 334 // frame or a single superframe, is owned by caller and must remain valid |
| 205 // until the next call to SetStream(). | 335 // until the next call to SetStream(). |
| 206 void SetStream(const uint8_t* stream, off_t stream_size); | 336 void SetStream(const uint8_t* stream, off_t stream_size); |
| 207 | 337 |
| 208 // Parse the next frame in the current stream buffer, filling |fhdr| with | 338 // Parse the next frame in the current stream buffer, filling |fhdr| with |
| 209 // the parsed frame header and updating current segmentation and loop filter | 339 // the parsed frame header and updating current segmentation and loop filter |
| 210 // state. Return kOk if a frame has successfully been parsed, kEOStream if | 340 // state. If |parsing_compressed_header|, this function also fills |
|
Pawel Osciak
2016/08/04 10:20:19
s/parsing_compressed_header/parsing_compressed_hea
kcwu
2016/08/05 11:38:47
Done.
| |
| 211 // there is no more data in the current stream buffer, or kInvalidStream | 341 // |context_refresh_cb|, which is used to update frame context. If |
| 212 // on error. | 342 // |*context_refresh_cb| is null, no callback is necessary. |
| 213 Result ParseNextFrame(Vp9FrameHeader* fhdr); | 343 // Return kOk if a frame has successfully been parsed, |
| 344 // kEOStream if there is no more data in the current stream buffer, | |
| 345 // kAwaitingRefresh if this frame awaiting frame context update, or | |
| 346 // kInvalidStream on error. | |
| 347 Result ParseNextFrame( | |
| 348 Vp9FrameHeader* fhdr, | |
| 349 base::Callback<void(const Vp9FrameContext&)>* context_refresh_cb); | |
| 214 | 350 |
| 215 // Return current segmentation state. | 351 // Return current segmentation state. |
| 216 const Vp9Segmentation& GetSegmentation() const { return segmentation_; } | 352 const Vp9SegmentationParams& GetSegmentation() const { |
| 353 return context_.segmentation; | |
| 354 } | |
| 217 | 355 |
| 218 // Return current loop filter state. | 356 // Return current loop filter state. |
| 219 const Vp9LoopFilter& GetLoopFilter() const { return loop_filter_; } | 357 const Vp9LoopFilterParams& GetLoopFilter() const { |
| 358 return context_.loop_filter; | |
| 359 } | |
| 220 | 360 |
| 221 // Clear parser state and return to an initialized state. | 361 // Clear parser state and return to an initialized state. |
| 222 void Reset(); | 362 void Reset(); |
| 223 | 363 |
| 224 private: | 364 private: |
| 225 // The parsing context to keep track of references. | 365 class UncompressedHeaderParser; |
| 226 struct ReferenceSlot { | 366 class CompressedHeaderParser; |
| 227 uint32_t width; | |
| 228 uint32_t height; | |
| 229 }; | |
| 230 | 367 |
| 231 bool ParseSuperframe(); | 368 bool ParseSuperframe(); |
| 232 uint8_t ReadProfile(); | 369 |
| 233 bool VerifySyncCode(); | 370 size_t GetQIndex(const Vp9QuantizationParams& quant, size_t segid) const; |
| 234 bool ReadBitDepthColorSpaceSampling(Vp9FrameHeader* fhdr); | 371 void SetupSegmentationDequant(const Vp9FrameHeader* fhdr); |
| 235 void ReadFrameSize(Vp9FrameHeader* fhdr); | 372 void SetupLoopFilter(); |
| 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); | 373 void UpdateSlots(const Vp9FrameHeader* fhdr); |
| 249 | 374 |
| 250 void ResetLoopfilter(); | |
| 251 void SetupPastIndependence(); | |
| 252 size_t GetQIndex(const Vp9QuantizationParams& quant, size_t segid) const; | |
| 253 void SetupSegmentationDequant(const Vp9QuantizationParams& quant); | |
| 254 void SetupLoopFilter(); | |
| 255 | |
| 256 // Current address in the bitstream buffer. | 375 // Current address in the bitstream buffer. |
| 257 const uint8_t* stream_; | 376 const uint8_t* stream_; |
| 258 | 377 |
| 259 // Remaining bytes in stream_. | 378 // Remaining bytes in stream_. |
| 260 off_t bytes_left_; | 379 off_t bytes_left_; |
| 261 | 380 |
| 262 // Stores start pointer and size of each frame within the current superframe. | 381 // Stores start pointer and size of each frame within the current superframe. |
| 263 struct FrameInfo { | 382 struct FrameInfo { |
| 264 FrameInfo(const uint8_t* ptr, off_t size); | 383 FrameInfo(const uint8_t* ptr, off_t size); |
| 265 | 384 |
| 266 // Starting address of the frame. | 385 // Starting address of the frame. |
| 267 const uint8_t* ptr; | 386 const uint8_t* ptr; |
| 268 | 387 |
| 269 // Size of the frame in bytes. | 388 // Size of the frame in bytes. |
| 270 off_t size; | 389 off_t size; |
| 271 }; | 390 }; |
| 272 | 391 |
| 392 bool parsing_compressed_header_; | |
| 393 | |
| 273 // FrameInfo for the remaining frames in the current superframe to be parsed. | 394 // FrameInfo for the remaining frames in the current superframe to be parsed. |
| 274 std::deque<FrameInfo> frames_; | 395 std::deque<FrameInfo> frames_; |
| 275 | 396 |
| 276 // Raw bits decoder for uncompressed frame header. | 397 Context context_; |
| 277 Vp9RawBitsReader reader_; | |
| 278 | |
| 279 // Segmentation and loop filter state that persists across frames. | |
| 280 Vp9Segmentation segmentation_; | |
| 281 Vp9LoopFilter loop_filter_; | |
| 282 | |
| 283 // The parsing context to keep track of references. | |
| 284 ReferenceSlot ref_slots_[kVp9NumRefFrames]; | |
| 285 | 398 |
| 286 DISALLOW_COPY_AND_ASSIGN(Vp9Parser); | 399 DISALLOW_COPY_AND_ASSIGN(Vp9Parser); |
| 287 }; | 400 }; |
| 288 | 401 |
| 289 } // namespace media | 402 } // namespace media |
| 290 | 403 |
| 291 #endif // MEDIA_FILTERS_VP9_PARSER_H_ | 404 #endif // MEDIA_FILTERS_VP9_PARSER_H_ |
| OLD | NEW |