vp9_raw_bits_reader.h 2.0 KB

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