1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 20:55:07 +00:00
serenity/Userland/Libraries/LibVideo/VP9/BitStream.h
FalseHonesty 2e31b9cf7c LibVideo/VP9: Implement a bit stream to decode VP9 data
The VP9 specification requires a special decoding process to parse a
lot of the data read from a frame, so this BitStream wrapper implements
that behavior. These processes are defined in section 9 of the
VP9 spec.
2021-06-12 22:48:28 +04:30

50 lines
957 B
C++

/*
* Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Optional.h>
#include <AK/Types.h>
namespace Video::VP9 {
class BitStream {
public:
BitStream(const u8* data, size_t size)
: m_data_ptr(data)
, m_bytes_remaining(size)
{
}
u8 read_byte();
bool read_bit();
u8 read_f(size_t n);
i8 read_s(size_t n);
u8 read_f8();
u16 read_f16();
u8 read_literal(size_t n);
u64 get_position();
size_t bytes_remaining();
size_t bits_remaining();
bool init_bool(size_t bytes);
bool read_bool(u8 probability);
bool exit_bool();
private:
const u8* m_data_ptr { nullptr };
size_t m_bytes_remaining { 0 };
Optional<u8> m_current_byte;
i8 m_current_bit_position { 0 };
u64 m_bytes_read { 0 };
u8 m_bool_value { 0 };
u8 m_bool_range { 0 };
u64 m_bool_max_bits { 0 };
};
}