mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-10-22 07:21:21 +00:00
bit writer: add put_leb128() implementation for AV1
This commit is contained in:
parent
bba41f81dd
commit
62b9bc38ff
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user