1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 #ifndef LIBWEBM_COMMON_VP9_HEADER_PARSER_H_ 9 #define LIBWEBM_COMMON_VP9_HEADER_PARSER_H_ 10 11 #include <stddef.h> 12 #include <stdint.h> 13 14 namespace vp9_parser { 15 16 const int kVp9FrameMarker = 2; 17 const int kMinTileWidthB64 = 4; 18 const int kMaxTileWidthB64 = 64; 19 const int kRefFrames = 8; 20 const int kRefsPerFrame = 3; 21 const int kRefFrames_LOG2 = 3; 22 const int kVpxCsBt601 = 1; 23 const int kVpxCsSrgb = 7; 24 const int kVpxCrStudioRange = 0; 25 const int kVpxCrFullRange = 1; 26 const int kMiSizeLog2 = 3; 27 28 // Class to parse the header of a VP9 frame. 29 class Vp9HeaderParser { 30 public: Vp9HeaderParser()31 Vp9HeaderParser() 32 : frame_(NULL), 33 frame_size_(0), 34 bit_offset_(0), 35 profile_(-1), 36 show_existing_frame_(0), 37 key_(0), 38 altref_(0), 39 error_resilient_mode_(0), 40 intra_only_(0), 41 reset_frame_context_(0), 42 bit_depth_(0), 43 color_space_(0), 44 color_range_(0), 45 subsampling_x_(0), 46 subsampling_y_(0), 47 refresh_frame_flags_(0), 48 width_(0), 49 height_(0), 50 row_tiles_(0), 51 column_tiles_(0), 52 frame_parallel_mode_(0) {} 53 54 // Parse the VP9 uncompressed header. The return values of the remaining 55 // functions are only valid on success. 56 bool ParseUncompressedHeader(const uint8_t* frame, size_t length); 57 frame_size()58 size_t frame_size() const { return frame_size_; } profile()59 int profile() const { return profile_; } key()60 int key() const { return key_; } altref()61 int altref() const { return altref_; } error_resilient_mode()62 int error_resilient_mode() const { return error_resilient_mode_; } bit_depth()63 int bit_depth() const { return bit_depth_; } color_space()64 int color_space() const { return color_space_; } width()65 int width() const { return width_; } height()66 int height() const { return height_; } refresh_frame_flags()67 int refresh_frame_flags() const { return refresh_frame_flags_; } row_tiles()68 int row_tiles() const { return row_tiles_; } column_tiles()69 int column_tiles() const { return column_tiles_; } frame_parallel_mode()70 int frame_parallel_mode() const { return frame_parallel_mode_; } 71 72 private: 73 // Set the compressed VP9 frame. 74 bool SetFrame(const uint8_t* frame, size_t length); 75 76 // Returns the next bit of the frame. 77 int ReadBit(); 78 79 // Returns the next |bits| of the frame. 80 int VpxReadLiteral(int bits); 81 82 // Returns true if the vp9 sync code is valid. 83 bool ValidateVp9SyncCode(); 84 85 // Parses bit_depth_, color_space_, subsampling_x_, subsampling_y_, and 86 // color_range_. 87 void ParseColorSpace(); 88 89 // Parses width and height of the frame. 90 void ParseFrameResolution(); 91 92 // Parses frame_parallel_mode_. This function skips over some features. 93 void ParseFrameParallelMode(); 94 95 // Parses row and column tiles. This function skips over some features. 96 void ParseTileInfo(); 97 void SkipDeltaQ(); 98 int AlignPowerOfTwo(int value, int n); 99 100 const uint8_t* frame_; 101 size_t frame_size_; 102 size_t bit_offset_; 103 int profile_; 104 int show_existing_frame_; 105 int key_; 106 int altref_; 107 int error_resilient_mode_; 108 int intra_only_; 109 int reset_frame_context_; 110 int bit_depth_; 111 int color_space_; 112 int color_range_; 113 int subsampling_x_; 114 int subsampling_y_; 115 int refresh_frame_flags_; 116 int width_; 117 int height_; 118 int row_tiles_; 119 int column_tiles_; 120 int frame_parallel_mode_; 121 }; 122 123 } // namespace vp9_parser 124 125 #endif // LIBWEBM_COMMON_VP9_HEADER_PARSER_H_ 126