Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: media/filters/vp9_parser.h

Issue 1258083004: Add a Vp9Parser implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ReadBool, fix compile warning Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/BUILD.gn ('k') | media/filters/vp9_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // This file contains an implementation of a VP9 bitstream parser. The main
6 // purpose of this parser is to support hardware decode acceleration. Some
7 // accelerators, e.g. libva which implements VA-API, require the caller
8 // (chrome) to feed them parsed VP9 frame header.
9 //
10 // Example usage:
11 // {
12 // Vp9Parser parser;
13 // uint8_t* frame_stream;
14 // size_t frame_size;
15 //
16 // // Get frames from, say, WebM parser or IVF parser.
17 // while (GetVp9Frame(&frame_stream, &frame_size)) {
18 // Vp9FrameHeader header;
19 // if (!parser.ParseFrame(frame_stream, frame_size, &header)) {
20 // // Parse failed.
21 // return false;
22 // }
23 // // Got a frame parsed successfully.
24 // }
25 // }
26
27 #ifndef MEDIA_FILTERS_VP9_PARSER_H_
28 #define MEDIA_FILTERS_VP9_PARSER_H_
29
30 #include <stddef.h>
31 #include <stdint.h>
32
33 #include "base/macros.h"
34 #include "media/base/media_export.h"
35 #include "media/filters/vp9_raw_bits_reader.h"
36
37 namespace media {
38
39 const int kVp9MaxProfile = 4;
40 const int kVp9NumRefFramesLog2 = 3;
41 const int kVp9NumRefFrames = 1 << kVp9NumRefFramesLog2;
42 const uint8_t kVp9MaxProb = 255;
43 const int kVp9NumRefsPerFrame = 3;
44
45 enum class Vp9ColorSpace {
46 UNKNOWN = 0,
47 BT_601 = 1,
48 BT_709 = 2,
49 SMPTE_170 = 3,
50 SMPTE_240 = 4,
51 BT_2020 = 5,
52 RESERVED = 6,
53 SRGB = 7,
54 };
55
56 enum class Vp9InterpFilter {
57 INTERP_FILTER_SELECT = 0,
58 EIGHTTAP_SMOOTH = 1,
59 EIGHTTAP = 2,
60 EIGHTTAP_SHARP = 3,
61 BILINEAR = 4,
62 };
63
64 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseFrame.
65 struct MEDIA_EXPORT Vp9Segmentation {
66 static const int kNumSegments = 8;
67 static const int kNumTreeProbs = kNumSegments - 1;
68 static const int kNumPredictionProbs = 3;
69 static const int kNumFeatures = 4;
70
71 bool enabled;
72
73 bool update_map;
74 uint8_t tree_probs[kNumTreeProbs];
75 bool temporal_update;
76 uint8_t pred_probs[kNumPredictionProbs];
77
78 bool update_data;
79 bool abs_delta;
80 bool feature_enabled[kNumSegments][kNumFeatures];
81 int8_t feature_data[kNumSegments][kNumFeatures];
82 };
83
84 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseFrame.
85 struct MEDIA_EXPORT Vp9LoopFilter {
86 static const int kNumRefDeltas = 4;
87 static const int kNumModeDeltas = 2;
88
89 uint8_t filter_level;
90 uint8_t sharpness_level;
91
92 bool mode_ref_delta_enabled;
93 bool mode_ref_delta_update;
94 bool update_ref_deltas[kNumRefDeltas];
95 int8_t ref_deltas[kNumRefDeltas];
96 bool update_mode_deltas[kNumModeDeltas];
97 int8_t mode_deltas[kNumModeDeltas];
98 };
99
100 // Members of Vp9FrameHeader will be 0-initialized by Vp9Parser::ParseFrame.
101 struct MEDIA_EXPORT Vp9QuantizationParams {
102 bool IsLossless() const {
103 return base_qindex == 0 && y_dc_delta == 0 && uv_dc_delta == 0 &&
104 uv_ac_delta == 0;
105 }
106
107 uint8_t base_qindex;
108 int8_t y_dc_delta;
109 int8_t uv_dc_delta;
110 int8_t uv_ac_delta;
111 };
112
113 // VP9 frame header.
114 struct MEDIA_EXPORT Vp9FrameHeader {
115 enum FrameType {
116 KEYFRAME = 0,
117 INTERFRAME = 1,
118 };
119
120 bool IsKeyframe() const { return frame_type == KEYFRAME; }
121
122 uint8_t profile;
123
124 bool show_existing_frame;
125 uint8_t frame_to_show;
126
127 FrameType frame_type;
128
129 bool show_frame;
130 bool error_resilient_mode;
131
132 uint8_t bit_depth;
133 Vp9ColorSpace color_space;
134 bool yuv_range;
135 uint8_t subsampling_x;
136 uint8_t subsampling_y;
137
138 // The range of width and height is 1..2^16.
139 uint32_t width;
140 uint32_t height;
141 uint32_t display_width;
142 uint32_t display_height;
143
144 bool intra_only;
145 uint8_t reset_context;
146 bool refresh_flag[kVp9NumRefFrames];
147 uint8_t frame_refs[kVp9NumRefsPerFrame];
148 bool ref_sign_biases[kVp9NumRefsPerFrame];
149 bool allow_high_precision_mv;
150 Vp9InterpFilter interp_filter;
151
152 bool refresh_frame_context;
153 bool frame_parallel_decoding_mode;
154 uint8_t frame_context_idx;
155
156 Vp9LoopFilter loop_filter;
157 Vp9QuantizationParams quant_params;
158 Vp9Segmentation segment;
159
160 uint8_t log2_tile_cols;
161 uint8_t log2_tile_rows;
162
163 // Size of compressed header in bytes.
164 size_t first_partition_size;
165
166 // Size of uncompressed header in bytes.
167 size_t uncompressed_header_size;
168 };
169
170 // A parser for VP9 bitstream.
171 class MEDIA_EXPORT Vp9Parser {
172 public:
173 Vp9Parser();
174
175 // Parses one frame and fills parsing result to |fhdr|. Returns true on
176 // success, false otherwise.
177 // |stream| is the address of VP9 bitstream with |size|.
178 bool ParseFrame(const uint8_t* stream, size_t size, Vp9FrameHeader* fhdr);
179
180 private:
181 // The parsing context to keep track of references.
182 struct ReferenceSlot {
183 uint32_t width;
184 uint32_t height;
185 };
186
187 uint8_t ReadProfile();
188 bool VerifySyncCode();
189 bool ReadBitDepthColorSpaceSampling(Vp9FrameHeader* fhdr);
190 void ReadFrameSize(Vp9FrameHeader* fhdr);
191 bool ReadFrameSizeFromRefs(Vp9FrameHeader* fhdr);
192 void ReadDisplayFrameSize(Vp9FrameHeader* fhdr);
193 Vp9InterpFilter ReadInterpFilter();
194 void ReadLoopFilter(Vp9LoopFilter* loop_filter);
195 void ReadQuantization(Vp9QuantizationParams* quants);
196 void ReadSegmentationMap(Vp9Segmentation* segment);
197 void ReadSegmentationData(Vp9Segmentation* segment);
198 void ReadSegmentation(Vp9Segmentation* segment);
199 void ReadTiles(Vp9FrameHeader* fhdr);
200 bool ParseUncompressedHeader(Vp9FrameHeader* fhdr);
201 void UpdateSlots(const Vp9FrameHeader* fhdr);
202
203 // Start address of VP9 bitstream buffer.
204 const uint8_t* stream_;
205
206 // Size of |stream_| in bytes.
207 size_t size_;
208
209 // Raw bits decoder for uncompressed frame header.
210 Vp9RawBitsReader reader_;
211
212 // The parsing context to keep track of references.
213 ReferenceSlot ref_slots_[kVp9NumRefFrames];
214
215 DISALLOW_COPY_AND_ASSIGN(Vp9Parser);
216 };
217
218 } // namespace media
219
220 #endif // MEDIA_FILTERS_VP9_PARSER_H_
OLDNEW
« no previous file with comments | « media/BUILD.gn ('k') | media/filters/vp9_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698