mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:57:35 +00:00
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.
This commit is contained in:
parent
18759ff56d
commit
2e31b9cf7c
3 changed files with 193 additions and 0 deletions
50
Userland/Libraries/LibVideo/VP9/BitStream.h
Normal file
50
Userland/Libraries/LibVideo/VP9/BitStream.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue