bit writer: add put_leb128() implementation for AV1

This commit is contained in:
Moritz Bunkus 2022-11-06 20:15:18 +01:00
parent bba41f81dd
commit 62b9bc38ff
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85
2 changed files with 25 additions and 0 deletions

View File

@ -110,6 +110,19 @@ public:
update_size();
}
inline void put_leb128(uint64_t value) {
do {
auto this_byte = value & 0x7f;
value >>= 7;
if (value != 0)
this_byte |= 0x80;
put_bits(8, this_byte);
} while (value != 0);
}
inline void byte_align() {
while (0x80 != m_mask)
put_bit(false);

View File

@ -170,4 +170,16 @@ TEST(BitWriter, ProvidingABuffer) {
ASSERT_EQ(0x0001020304050607ull, get_uint64_be(buffer->get_buffer()));
}
TEST(BitWriter, PutLEB128) {
unsigned char buf[4] = { 0x00, 0x00, 0x00, 0x00 };
auto w = mtx::bits::writer_c{buf, 4};
w.put_leb128(0x21);
EXPECT_EQ(get_uint32_be(buf), 0x21000000u);
w = mtx::bits::writer_c{buf, 4};
w.put_leb128((0x17) | (0x01 << 7) | (0x07 << 14));
EXPECT_EQ(get_uint32_be(buf), 0x97810700u);
}
}