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 VP9_RAW_BITS_READER_H_ 6 #define VP9_RAW_BITS_READER_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include <memory> 12 13 #include "base/macros.h" 14 15 namespace media { 16 17 class BitReader; 18 19 // A class to read raw bits stream. See VP9 spec, "RAW-BITS DECODING" section 20 // for detail. 21 class Vp9RawBitsReader { 22 public: 23 Vp9RawBitsReader(); 24 ~Vp9RawBitsReader(); 25 26 // |data| is the input buffer with |size| bytes. 27 void Initialize(const uint8_t* data, size_t size); 28 29 // Returns true if none of the reads since the last Initialize() call has 30 // gone beyond the end of available data. 31 bool IsValid() const { return valid_; } 32 33 // Returns how many bytes were read since the last Initialize() call. 34 // Partial bytes will be counted as one byte. For example, it will return 1 35 // if 3 bits were read. 36 size_t GetBytesRead() const; 37 38 // Reads one bit. 39 // If the read goes beyond the end of buffer, the return value is undefined. 40 bool ReadBool(); 41 42 // Reads a literal with |bits| bits. 43 // If the read goes beyond the end of buffer, the return value is undefined. 44 int ReadLiteral(int bits); 45 46 // Reads a signed literal with |bits| bits (not including the sign bit). 47 // If the read goes beyond the end of buffer, the return value is undefined. 48 int ReadSignedLiteral(int bits); 49 50 // Consumes trailing bits up to next byte boundary. Returns true if no 51 // trailing bits or they are all zero. 52 bool ConsumeTrailingBits(); 53 54 private: 55 std::unique_ptr<BitReader> reader_; 56 57 // Indicates if none of the reads since the last Initialize() call has gone 58 // beyond the end of available data. 59 bool valid_; 60 61 DISALLOW_COPY_AND_ASSIGN(Vp9RawBitsReader); 62 }; 63 64 } // namespace media 65 66 #endif // VP9_RAW_BITS_READER_H_ 67