Delete BitBuffer
All BitBuffer usage was replaced with BitstreamReader Bug: None Change-Id: Ia91826cea2561679709c0c22767958de596a282c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/232125 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35056}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
b918230640
commit
48f9525078
@ -14,21 +14,18 @@
|
||||
#include <stddef.h> // For size_t.
|
||||
#include <stdint.h> // For integer types.
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// A class, similar to ByteBuffer, that can parse bit-sized data out of a set of
|
||||
// bytes. Has a similar API to ByteBuffer, plus methods for reading bit-sized
|
||||
// and exponential golomb encoded data. For a writable version, use
|
||||
// BitBufferWriter. Unlike ByteBuffer, this class doesn't make a copy of the
|
||||
// source bytes, so it can be used on read-only data.
|
||||
// A BitBuffer API for write operations. Supports symmetric write APIs to the
|
||||
// reading APIs of BitstreamReader.
|
||||
// Sizes/counts specify bits/bytes, for clarity.
|
||||
// Byte order is assumed big-endian/network.
|
||||
class BitBuffer {
|
||||
class BitBufferWriter {
|
||||
public:
|
||||
BitBuffer(const uint8_t* bytes, size_t byte_count);
|
||||
// Constructs a bit buffer for the writable buffer of `bytes`.
|
||||
BitBufferWriter(uint8_t* bytes, size_t byte_count);
|
||||
|
||||
// Gets the current offset, in bytes/bits, from the start of the buffer. The
|
||||
// bit offset is the offset into the current byte, in the range [0,7].
|
||||
@ -37,75 +34,6 @@ class BitBuffer {
|
||||
// The remaining bits in the byte buffer.
|
||||
uint64_t RemainingBitCount() const;
|
||||
|
||||
// Reads byte-sized values from the buffer. Returns false if there isn't
|
||||
// enough data left for the specified type.
|
||||
bool ReadUInt8(uint8_t& val);
|
||||
bool ReadUInt16(uint16_t& val);
|
||||
bool ReadUInt32(uint32_t& val);
|
||||
ABSL_DEPRECATED("") bool ReadUInt8(uint8_t* val) {
|
||||
return val ? ReadUInt8(*val) : false;
|
||||
}
|
||||
ABSL_DEPRECATED("") bool ReadUInt16(uint16_t* val) {
|
||||
return val ? ReadUInt16(*val) : false;
|
||||
}
|
||||
ABSL_DEPRECATED("") bool ReadUInt32(uint32_t* val) {
|
||||
return val ? ReadUInt32(*val) : false;
|
||||
}
|
||||
|
||||
// Reads bit-sized values from the buffer. Returns false if there isn't enough
|
||||
// data left for the specified bit count.
|
||||
bool ReadBits(size_t bit_count, uint32_t& val);
|
||||
bool ReadBits(size_t bit_count, uint64_t& val);
|
||||
ABSL_DEPRECATED("") bool ReadBits(uint32_t* val, size_t bit_count) {
|
||||
return val ? ReadBits(bit_count, *val) : false;
|
||||
}
|
||||
|
||||
// Peeks bit-sized values from the buffer. Returns false if there isn't enough
|
||||
// data left for the specified number of bits. Doesn't move the current
|
||||
// offset.
|
||||
bool PeekBits(size_t bit_count, uint32_t& val);
|
||||
bool PeekBits(size_t bit_count, uint64_t& val);
|
||||
ABSL_DEPRECATED("") bool PeekBits(uint32_t* val, size_t bit_count) {
|
||||
return val ? PeekBits(bit_count, *val) : false;
|
||||
}
|
||||
|
||||
// Reads value in range [0, num_values - 1].
|
||||
// This encoding is similar to ReadBits(val, Ceil(Log2(num_values)),
|
||||
// but reduces wastage incurred when encoding non-power of two value ranges
|
||||
// Non symmetric values are encoded as:
|
||||
// 1) n = countbits(num_values)
|
||||
// 2) k = (1 << n) - num_values
|
||||
// Value v in range [0, k - 1] is encoded in (n-1) bits.
|
||||
// Value v in range [k, num_values - 1] is encoded as (v+k) in n bits.
|
||||
// https://aomediacodec.github.io/av1-spec/#nsn
|
||||
// Returns false if there isn't enough data left.
|
||||
bool ReadNonSymmetric(uint32_t num_values, uint32_t& val);
|
||||
ABSL_DEPRECATED("")
|
||||
bool ReadNonSymmetric(uint32_t* val, uint32_t num_values) {
|
||||
return val ? ReadNonSymmetric(num_values, *val) : false;
|
||||
}
|
||||
|
||||
// Reads the exponential golomb encoded value at the current offset.
|
||||
// Exponential golomb values are encoded as:
|
||||
// 1) x = source val + 1
|
||||
// 2) In binary, write [countbits(x) - 1] 0s, then x
|
||||
// To decode, we count the number of leading 0 bits, read that many + 1 bits,
|
||||
// and increment the result by 1.
|
||||
// Returns false if there isn't enough data left for the specified type, or if
|
||||
// the value wouldn't fit in a uint32_t.
|
||||
bool ReadExponentialGolomb(uint32_t& val);
|
||||
ABSL_DEPRECATED("") bool ReadExponentialGolomb(uint32_t* val) {
|
||||
return val ? ReadExponentialGolomb(*val) : false;
|
||||
}
|
||||
|
||||
// Reads signed exponential golomb values at the current offset. Signed
|
||||
// exponential golomb values are just the unsigned values mapped to the
|
||||
// sequence 0, 1, -1, 2, -2, etc. in order.
|
||||
bool ReadSignedExponentialGolomb(int32_t& val);
|
||||
ABSL_DEPRECATED("") bool ReadSignedExponentialGolomb(int32_t* val) {
|
||||
return val ? ReadSignedExponentialGolomb(*val) : false;
|
||||
}
|
||||
|
||||
// Moves current position `byte_count` bytes forward. Returns false if
|
||||
// there aren't enough bytes left in the buffer.
|
||||
bool ConsumeBytes(size_t byte_count);
|
||||
@ -117,26 +45,6 @@ class BitBuffer {
|
||||
// offset is from the given byte, in the range [0,7].
|
||||
bool Seek(size_t byte_offset, size_t bit_offset);
|
||||
|
||||
protected:
|
||||
const uint8_t* const bytes_;
|
||||
// The total size of `bytes_`.
|
||||
size_t byte_count_;
|
||||
// The current offset, in bytes, from the start of `bytes_`.
|
||||
size_t byte_offset_;
|
||||
// The current offset, in bits, into the current byte.
|
||||
size_t bit_offset_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(BitBuffer);
|
||||
};
|
||||
|
||||
// A BitBuffer API for write operations. Supports symmetric write APIs to the
|
||||
// reading APIs of BitBuffer. Note that the read/write offset is shared with the
|
||||
// BitBuffer API, so both reading and writing will consume bytes/bits.
|
||||
class BitBufferWriter : public BitBuffer {
|
||||
public:
|
||||
// Constructs a bit buffer for the writable buffer of `bytes`.
|
||||
BitBufferWriter(uint8_t* bytes, size_t byte_count);
|
||||
|
||||
// Writes byte-sized values from the buffer. Returns false if there isn't
|
||||
// enough data left for the specified type.
|
||||
bool WriteUInt8(uint8_t val);
|
||||
@ -166,6 +74,12 @@ class BitBufferWriter : public BitBuffer {
|
||||
private:
|
||||
// The buffer, as a writable array.
|
||||
uint8_t* const writable_bytes_;
|
||||
// The total size of `bytes_`.
|
||||
const size_t byte_count_;
|
||||
// The current offset, in bytes, from the start of `bytes_`.
|
||||
size_t byte_offset_;
|
||||
// The current offset, in bits, into the current byte.
|
||||
size_t bit_offset_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(BitBufferWriter);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user