Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_FILTERS_VP9_PARSER_H_ | |
| 6 #define MEDIA_FILTERS_VP9_PARSER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "media/base/media_export.h" | |
| 13 #include "media/filters/vp9_raw_bits_reader.h" | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 const int kVp9MaxProfile = 4; | |
| 18 const int kVp9RefFramesLog2 = 3; | |
| 19 const int kVp9RefFrames = 1 << kVp9RefFramesLog2; | |
| 20 const uint8_t kVp9MaxProb = 255; | |
| 21 const int kVp9RefsPerFrame = 3; | |
|
Pawel Osciak
2015/07/30 11:52:31
kVp9NumRefFrames
kcwu1
2015/07/31 04:36:02
Ok, I changed the name
kVp9RefFrames -> kVp9NumRef
| |
| 22 | |
| 23 enum class Vp9ColorSpace { | |
| 24 UNKNOWN, | |
| 25 BT_601, | |
|
Pawel Osciak
2015/07/30 08:27:38
We should assign explicit values since this is per
kcwu1
2015/07/31 04:36:02
Done.
| |
| 26 BT_709, | |
| 27 SMPTE_170, | |
| 28 SMPTE_240, | |
| 29 BT_2020, | |
| 30 RESERVED, | |
| 31 SRGB, | |
| 32 }; | |
| 33 | |
| 34 enum class Vp9InterpFilter { | |
| 35 INTERP_FILTER_SELECT, | |
| 36 EIGHTTAP_SMOOTH, | |
| 37 EIGHTTAP, | |
| 38 EIGHTTAP_SHARP, | |
| 39 BILINEAR, | |
| 40 }; | |
| 41 | |
| 42 struct MEDIA_EXPORT Vp9Segmentation { | |
| 43 static const int kNumSegment = 8; | |
|
Pawel Osciak
2015/07/30 08:27:38
kNumSegments
kcwu1
2015/07/31 04:36:02
Done.
| |
| 44 static const int kTreeProbs = kNumSegment - 1; | |
|
Pawel Osciak
2015/07/30 08:27:38
kNumTreeProbs
kcwu1
2015/07/31 04:36:02
Done.
| |
| 45 static const int kPredictionProbs = 3; | |
|
Pawel Osciak
2015/07/30 08:27:38
kNumPredictionProbs
kcwu1
2015/07/31 04:36:02
Done.
| |
| 46 static const int kNumFeature = 4; | |
| 47 | |
| 48 bool enabled; | |
| 49 | |
| 50 bool update_map; | |
| 51 uint8_t tree_probs[kTreeProbs]; | |
| 52 uint8_t pred_probs[kPredictionProbs]; | |
| 53 | |
| 54 bool update_data; | |
| 55 bool abs_delta; | |
| 56 bool feature_enabled[kNumSegment][kNumFeature]; | |
| 57 int8_t feature_data[kNumSegment][kNumFeature]; | |
| 58 }; | |
| 59 | |
| 60 struct MEDIA_EXPORT Vp9LoopFilter { | |
| 61 static const int kNumRefDeltas = 4; | |
| 62 static const int kNumModeDeltas = 2; | |
| 63 | |
| 64 uint8_t filter_level; | |
| 65 uint8_t sharpness_level; | |
| 66 | |
| 67 bool mode_ref_delta_enabled; | |
| 68 bool mode_ref_delta_update; | |
| 69 bool update_ref_deltas[kNumRefDeltas]; | |
| 70 int8_t ref_deltas[kNumRefDeltas]; | |
| 71 bool update_mode_deltas[kNumModeDeltas]; | |
| 72 int8_t mode_deltas[kNumModeDeltas]; | |
| 73 }; | |
| 74 | |
| 75 struct MEDIA_EXPORT Vp9QuantizationParams { | |
| 76 bool IsLossless() const { | |
| 77 return base_qindex == 0 && y_dc_delta == 0 && uv_dc_delta == 0; | |
|
Pawel Osciak
2015/07/30 11:52:31
Do we need && uv_ac_delta_q == 0 here as well?
kcwu1
2015/07/31 04:36:02
Done.
| |
| 78 } | |
| 79 | |
| 80 uint8_t base_qindex; | |
| 81 int8_t y_dc_delta; | |
| 82 int8_t uv_dc_delta; | |
| 83 int8_t uv_ac_delta; | |
| 84 }; | |
| 85 | |
| 86 // VP9 frame header. | |
| 87 struct MEDIA_EXPORT Vp9FrameHeader { | |
| 88 enum FrameType { | |
| 89 KEYFRAME, | |
|
Pawel Osciak
2015/07/30 08:27:38
Explicit values please.
kcwu1
2015/07/31 04:36:02
Done.
| |
| 90 INTERFRAME, | |
| 91 }; | |
| 92 | |
| 93 bool IsKeyframe() const { return frame_type == KEYFRAME; } | |
| 94 | |
| 95 uint8_t profile; | |
| 96 | |
| 97 bool show_existing_frame; | |
| 98 uint8_t frame_to_show; | |
| 99 | |
| 100 enum FrameType frame_type; | |
|
Pawel Osciak
2015/07/30 08:27:38
s/enum//
kcwu1
2015/07/31 04:36:02
Done.
| |
| 101 | |
| 102 bool show_frame; | |
| 103 bool error_resilient_mode; | |
| 104 | |
| 105 uint8_t bit_depth; | |
| 106 enum Vp9ColorSpace color_space; | |
| 107 bool yuv_range; | |
| 108 uint8_t subsampling_x; | |
| 109 uint8_t subsampling_y; | |
| 110 | |
| 111 // The range of width and height is 1..2^16. | |
| 112 uint32_t width; | |
| 113 uint32_t height; | |
| 114 uint32_t display_width; | |
| 115 uint32_t display_height; | |
| 116 | |
| 117 bool intra_only; | |
| 118 uint8_t reset_context; | |
| 119 bool refresh_flag[kVp9RefFrames]; | |
| 120 uint8_t frame_refs[kVp9RefsPerFrame]; | |
| 121 bool ref_sign_biases[kVp9RefsPerFrame]; | |
| 122 bool allow_high_precision_mv; | |
| 123 enum Vp9InterpFilter interp_filter; | |
| 124 | |
| 125 bool refresh_frame_context; | |
| 126 bool frame_parallel_decoding_mode; | |
| 127 uint8_t frame_context_idx; | |
| 128 | |
| 129 Vp9LoopFilter loop_filter; | |
| 130 Vp9QuantizationParams quant_params; | |
| 131 Vp9Segmentation segment; | |
| 132 | |
| 133 uint8_t log2_tile_cols; | |
| 134 uint8_t log2_tile_rows; | |
| 135 | |
| 136 // If parsing out of order and |frame_type| is INTERFRAME, the value of | |
| 137 // |first_partition_size| and |compressed_header| may be invalid. | |
| 138 uint16_t first_partition_size; | |
| 139 const uint8_t* compressed_header; | |
| 140 }; | |
| 141 | |
| 142 class MEDIA_EXPORT Vp9Parser { | |
| 143 public: | |
| 144 Vp9Parser(); | |
| 145 | |
| 146 // Parses one frame. | |
| 147 // If parsing out of order (say, frame skip or seek), it still returns | |
| 148 // true for interframes but |fhdr| fields refering to previous frames | |
| 149 // will be undefined until next keyframe. | |
| 150 // ??? Do we need to support such case? Or should we check sizes strictly? | |
| 151 bool ParseFrame(const uint8_t* ptr, size_t size, Vp9FrameHeader* fhdr); | |
| 152 | |
| 153 private: | |
| 154 struct ReferenceSlot { | |
| 155 bool used; | |
| 156 uint32_t width; | |
| 157 uint32_t height; | |
| 158 }; | |
| 159 | |
| 160 uint8_t ReadProfile(); | |
| 161 bool VerifySyncCode(); | |
| 162 bool ReadBitDepthColorSpaceSampling(Vp9FrameHeader* fhdr); | |
| 163 void ReadFrameSize(Vp9FrameHeader* fhdr); | |
| 164 void ReadFrameSizeFromRefs(Vp9FrameHeader* fhdr); | |
| 165 void ReadDisplayFrameSize(Vp9FrameHeader* fhdr); | |
| 166 Vp9InterpFilter ReadInterpFilter(); | |
| 167 void ReadLoopFilter(Vp9LoopFilter* loop_filter); | |
| 168 void ReadQuantization(Vp9QuantizationParams* quants); | |
| 169 void ReadSegmentationMap(Vp9Segmentation* segment); | |
| 170 void ReadSegmentationData(Vp9Segmentation* segment); | |
| 171 void ReadSegmentation(Vp9Segmentation* segment); | |
| 172 bool ParseUncompressedHeader(Vp9FrameHeader* fhdr); | |
| 173 void ReadTiles(Vp9FrameHeader* fhdr); | |
| 174 void UpdateSlots(Vp9FrameHeader* fhdr); | |
| 175 | |
| 176 const uint8_t* stream_; | |
| 177 size_t size_; | |
| 178 Vp9RawBitsReader reader_; | |
| 179 | |
| 180 // The parsing context to keep track references. | |
| 181 ReferenceSlot ref_slots_[kVp9RefFrames]; | |
| 182 | |
| 183 DISALLOW_COPY_AND_ASSIGN(Vp9Parser); | |
| 184 }; | |
| 185 | |
| 186 } // namespace media | |
| 187 | |
| 188 #endif // MEDIA_FILTERS_VP9_PARSER_H_ | |
| OLD | NEW |