Chromium Code Reviews| Index: media/filters/vp9_bool_decoder.h |
| diff --git a/media/filters/vp9_bool_decoder.h b/media/filters/vp9_bool_decoder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..02729105650f1128411ccafedc481858f1e31568 |
| --- /dev/null |
| +++ b/media/filters/vp9_bool_decoder.h |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_FILTERS_VP9_BOOL_DECODER_H_ |
| +#define MEDIA_FILTERS_VP9_BOOL_DECODER_H_ |
| + |
| +#include <stddef.h> |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +class BitReader; |
| + |
| +class MEDIA_EXPORT Vp9BoolDecoder { |
| + public: |
| + Vp9BoolDecoder(); |
| + ~Vp9BoolDecoder(); |
| + |
| + // |data| is the input buffer with |size| bytes. |
| + // Returns true if read first marker bit successfully. |
| + bool Initialize(const uint8_t* data, size_t size); |
| + |
| + // Returns true if none of the reads since the last Initialize() call has |
| + // gone beyond the end of available data. |
| + bool IsValid() const { return valid_; } |
| + |
| + // Reads one bit. B(p). |
| + // If the read goes beyond the end of buffer, the return value is undefined. |
| + bool ReadBool(int prob); |
| + |
| + // Reads a literal. L(n). |
| + // If the read goes beyond the end of buffer, the return value is undefined. |
| + int ReadLiteral(int bits); |
| + |
| + // Consumes padding bits up to end of data. Returns true if no |
| + // padding bits or they are all zero. |
| + bool ConsumePaddingBits(); |
| + |
| + private: |
| + // The highest 8 bits of BigBool is actual "bool value". The remain bits |
| + // are optimization of prefill buffer. |
| + using BigBool = size_t; |
|
Pawel Osciak
2016/08/04 10:20:18
Is this assuming size_t is 64bit? This may not alw
kcwu
2016/08/05 11:38:47
Not necessary. Any integer type >= 8bits is enough
|
| + const int kBoolSize = 8; |
|
Pawel Osciak
2016/08/04 10:20:18
Could you please document what these are?
We shou
kcwu
2016/08/05 11:38:47
Done.
|
| + const int kBigBoolSize = sizeof(BigBool) * 8; |
|
Pawel Osciak
2016/08/04 10:20:18
Should this be called kBigBoolBitSize or something
kcwu
2016/08/05 11:38:47
Done.
|
| + |
| + void Fill(); |
| + |
| + std::unique_ptr<BitReader> reader_; |
| + |
| + // Indicates if none of the reads since the last Initialize() call has gone |
| + // beyond the end of available data. |
| + bool valid_; |
| + |
| + BigBool bool_value_; |
| + |
| + // Need to fill at least |count_to_fill_| bits. |
| + int count_to_fill_; |
|
Pawel Osciak
2016/08/04 10:20:18
Should this be a size_t?
kcwu
2016/08/05 11:38:47
No, it may be negative. Comment updated.
|
| + unsigned int bool_range_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Vp9BoolDecoder); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_FILTERS_VP9_BOOL_DECODER_H_ |