1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_VP9_RAW_BITS_READER_H_
6 #define MEDIA_FILTERS_VP9_RAW_BITS_READER_H_
13 #include "media/base/media_export.h"
19 // A class to read raw bits stream. See VP9 spec, "RAW-BITS DECODING" section
21 class MEDIA_EXPORT Vp9RawBitsReader {
25 Vp9RawBitsReader(const Vp9RawBitsReader&) = delete;
26 Vp9RawBitsReader& operator=(const Vp9RawBitsReader&) = delete;
30 // |data| is the input buffer with |size| bytes.
31 void Initialize(const uint8_t* data, size_t size);
33 // Returns true if none of the reads since the last Initialize() call has
34 // gone beyond the end of available data.
35 bool IsValid() const { return valid_; }
37 // Returns how many bytes were read since the last Initialize() call.
38 // Partial bytes will be counted as one byte. For example, it will return 1
39 // if 3 bits were read.
40 size_t GetBytesRead() const;
43 // If the read goes beyond the end of buffer, the return value is undefined.
46 // Reads a literal with |bits| bits.
47 // If the read goes beyond the end of buffer, the return value is undefined.
48 int ReadLiteral(int bits);
50 // Reads a signed literal with |bits| bits (not including the sign bit).
51 // If the read goes beyond the end of buffer, the return value is undefined.
52 int ReadSignedLiteral(int bits);
54 // Consumes trailing bits up to next byte boundary. Returns true if no
55 // trailing bits or they are all zero.
56 bool ConsumeTrailingBits();
59 std::unique_ptr<BitReader> reader_;
61 // Indicates if none of the reads since the last Initialize() call has gone
62 // beyond the end of available data.
68 #endif // MEDIA_FILTERS_VP9_RAW_BITS_READER_H_