diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/media/BitReader.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/BitReader.h')
-rw-r--r-- | dom/media/BitReader.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/dom/media/BitReader.h b/dom/media/BitReader.h new file mode 100644 index 0000000000..21c28f2c8c --- /dev/null +++ b/dom/media/BitReader.h @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BIT_READER_H_ +#define BIT_READER_H_ + +#include "MediaData.h" + +namespace mozilla { + +class BitReader { + public: + explicit BitReader(const MediaByteBuffer* aBuffer); + BitReader(const MediaByteBuffer* aBuffer, size_t aBits); + BitReader(const uint8_t* aBuffer, size_t aBits); + ~BitReader(); + uint32_t ReadBits(size_t aNum); + bool ReadBit() { return ReadBits(1) != 0; } + uint32_t ReadU32() { return ReadBits(32); } + uint64_t ReadU64(); + + // Read the UTF-8 sequence and convert it to its 64-bit UCS-4 encoded form. + // Return 0xfffffffffffffff if sequence was invalid. + uint64_t ReadUTF8(); + // Read unsigned integer Exp-Golomb-coded. + uint32_t ReadUE(); + // Read signed integer Exp-Golomb-coded. + int32_t ReadSE(); + // Read unsigned integer Little Endian Base 128 coded. + // Limited to unsigned 64 bits. + CheckedUint64 ReadULEB128(); + + // Return the number of bits parsed so far; + size_t BitCount() const; + // Return the number of bits left. + size_t BitsLeft() const; + + // Return RBSP bit length. + static uint32_t GetBitLength(const MediaByteBuffer* aNAL); + + private: + void FillReservoir(); + const uint8_t* mData; + const size_t mOriginalBitSize; + size_t mTotalBitsLeft; + size_t mSize; // Size left in bytes + uint32_t mReservoir; // Left-aligned bits + size_t mNumBitsLeft; // Number of bits left in reservoir. +}; + +} // namespace mozilla + +#endif // BIT_READER_H_ |