1 // Copyright 2016 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_BOOL_DECODER_H_
6 #define MEDIA_FILTERS_VP9_BOOL_DECODER_H_
13 #include "media/base/media_export.h"
19 class MEDIA_EXPORT Vp9BoolDecoder {
23 Vp9BoolDecoder(const Vp9BoolDecoder&) = delete;
24 Vp9BoolDecoder& operator=(const Vp9BoolDecoder&) = delete;
28 // |data| is the input buffer with |size| bytes.
29 // Returns true if read first marker bit successfully.
30 bool Initialize(const uint8_t* data, size_t size);
32 // Returns true if none of the reads since the last Initialize() call has
33 // gone beyond the end of available data.
34 bool IsValid() const { return valid_; }
36 // Reads one bit. B(p).
37 // If the read goes beyond the end of buffer, the return value is undefined.
38 bool ReadBool(int prob);
40 // Reads a literal. L(n).
41 // If the read goes beyond the end of buffer, the return value is undefined.
42 uint8_t ReadLiteral(int bits);
44 // Consumes padding bits up to end of data. Returns true if no
45 // padding bits or they are all zero.
46 bool ConsumePaddingBits();
49 // The highest 8 bits of BigBool is actual "bool value". The remain bits
50 // are optimization of prefill buffer.
51 using BigBool = size_t;
52 // The size of "bool value" used for boolean decoding defined in spec.
53 const int kBoolSize = 8;
54 const int kBigBoolBitSize = sizeof(BigBool) * 8;
58 std::unique_ptr<BitReader> reader_;
60 // Indicates if none of the reads since the last Initialize() call has gone
61 // beyond the end of available data.
64 BigBool bool_value_ = 0;
66 // Need to fill at least |count_to_fill_| bits. Negative value means extra
68 int count_to_fill_ = 0;
69 unsigned int bool_range_ = 0;
74 #endif // MEDIA_FILTERS_VP9_BOOL_DECODER_H_