mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:38:12 +00:00

The TreeParser requires information about a lot of the decoder's current state in order to parse syntax tree elements correctly, so there has to be some communication between the Decoder and the TreeParser. Previously, the Decoder would copy its state to the TreeParser when it changed, however, this was a poor choice. Now, the TreeParser simply has a reference to its owning Decoder, and accesses its state directly.
58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "BitStream.h"
|
|
#include "Enums.h"
|
|
#include "ProbabilityTables.h"
|
|
#include "SyntaxElementCounter.h"
|
|
|
|
namespace Video::VP9 {
|
|
|
|
class Decoder;
|
|
|
|
class TreeParser {
|
|
public:
|
|
explicit TreeParser(Decoder& decoder)
|
|
: m_decoder(decoder)
|
|
{
|
|
}
|
|
|
|
class TreeSelection {
|
|
public:
|
|
union TreeSelectionValue {
|
|
const int* m_tree;
|
|
int m_value;
|
|
};
|
|
|
|
TreeSelection(const int* values);
|
|
TreeSelection(int value);
|
|
|
|
bool is_single_value() const { return m_is_single_value; }
|
|
int get_single_value() const { return m_value.m_value; }
|
|
const int* get_tree_value() const { return m_value.m_tree; }
|
|
|
|
private:
|
|
bool m_is_single_value;
|
|
TreeSelectionValue m_value;
|
|
};
|
|
|
|
int parse_tree(SyntaxElementType type);
|
|
TreeSelection select_tree(SyntaxElementType type);
|
|
u8 select_tree_probability(SyntaxElementType type, u8 node);
|
|
void count_syntax_element(SyntaxElementType type, int value);
|
|
|
|
private:
|
|
u8 calculate_partition_probability(u8 node);
|
|
u8 calculate_skip_probability();
|
|
|
|
Decoder& m_decoder;
|
|
// m_ctx is a member variable because it is required for syntax element counting (section 9.3.4)
|
|
u8 m_ctx { 0 };
|
|
};
|
|
|
|
}
|