OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 MEDIA_FILTERS_VP9_BOOL_DECODER_H_ | |
6 #define MEDIA_FILTERS_VP9_BOOL_DECODER_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <memory> | |
12 | |
13 #include "base/macros.h" | |
14 #include "media/base/media_export.h" | |
15 | |
16 namespace media { | |
17 | |
18 class BitReader; | |
19 | |
20 class MEDIA_EXPORT Vp9BoolDecoder { | |
21 public: | |
22 Vp9BoolDecoder(); | |
23 ~Vp9BoolDecoder(); | |
24 | |
25 // |data| is the input buffer with |size| bytes. | |
26 // Returns true if read first marker bit successfully. | |
27 bool 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 // Reads one bit. B(p). | |
34 // If the read goes beyond the end of buffer, the return value is undefined. | |
35 bool ReadBool(int prob); | |
36 | |
37 // Reads a literal. L(n). | |
38 // If the read goes beyond the end of buffer, the return value is undefined. | |
39 int ReadLiteral(int bits); | |
40 | |
41 // Consumes padding bits up to end of data. Returns true if no | |
42 // padding bits or they are all zero. | |
43 bool ConsumePaddingBits(); | |
44 | |
45 private: | |
46 // The highest 8 bits of BigBool is actual "bool value". The remain bits | |
47 // are optimization of prefill buffer. | |
48 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
| |
49 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.
| |
50 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.
| |
51 | |
52 void Fill(); | |
53 | |
54 std::unique_ptr<BitReader> reader_; | |
55 | |
56 // Indicates if none of the reads since the last Initialize() call has gone | |
57 // beyond the end of available data. | |
58 bool valid_; | |
59 | |
60 BigBool bool_value_; | |
61 | |
62 // Need to fill at least |count_to_fill_| bits. | |
63 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.
| |
64 unsigned int bool_range_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(Vp9BoolDecoder); | |
67 }; | |
68 | |
69 } // namespace media | |
70 | |
71 #endif // MEDIA_FILTERS_VP9_BOOL_DECODER_H_ | |
OLD | NEW |