/src/mozilla-central/dom/media/BitReader.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #ifndef BIT_READER_H_ |
6 | | #define BIT_READER_H_ |
7 | | |
8 | | #include "MediaData.h" |
9 | | |
10 | | namespace mozilla |
11 | | { |
12 | | |
13 | | class BitReader |
14 | | { |
15 | | public: |
16 | | explicit BitReader(const MediaByteBuffer* aBuffer); |
17 | | BitReader(const MediaByteBuffer* aBuffer, size_t aBits); |
18 | | BitReader(const uint8_t* aBuffer, size_t aBits); |
19 | | ~BitReader(); |
20 | | uint32_t ReadBits(size_t aNum); |
21 | 0 | bool ReadBit() { return ReadBits(1) != 0; } |
22 | 0 | uint32_t ReadU32() { return ReadBits(32); } |
23 | | uint64_t ReadU64(); |
24 | | |
25 | | // Read the UTF-8 sequence and convert it to its 64-bit UCS-4 encoded form. |
26 | | // Return 0xfffffffffffffff if sequence was invalid. |
27 | | uint64_t ReadUTF8(); |
28 | | // Read unsigned integer Exp-Golomb-coded. |
29 | | uint32_t ReadUE(); |
30 | | // Read signed integer Exp-Golomb-coded. |
31 | | int32_t ReadSE(); |
32 | | |
33 | | // Return the number of bits parsed so far; |
34 | | size_t BitCount() const; |
35 | | // Return the number of bits left. |
36 | | size_t BitsLeft() const; |
37 | | |
38 | | // Return RBSP bit length. |
39 | | static uint32_t GetBitLength(const MediaByteBuffer* aNAL); |
40 | | |
41 | | private: |
42 | | void FillReservoir(); |
43 | | const uint8_t* mData; |
44 | | const size_t mOriginalBitSize; |
45 | | size_t mTotalBitsLeft; |
46 | | size_t mSize; // Size left in bytes |
47 | | uint32_t mReservoir; // Left-aligned bits |
48 | | size_t mNumBitsLeft; // Number of bits left in reservoir. |
49 | | }; |
50 | | |
51 | | } // namespace mozilla |
52 | | |
53 | | #endif // BIT_READER_H_ |