1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:47:37 +00:00

LibVideo: Parameterize parsing if a block is inter predicted in VP9

This commit is contained in:
Zaggy1024 2022-11-07 01:13:19 -06:00 committed by Andrew Kaster
parent 93caa1e19d
commit 372a4ea8c1
3 changed files with 24 additions and 22 deletions

View file

@ -1178,10 +1178,13 @@ u8 Parser::get_segment_id()
DecoderErrorOr<void> Parser::read_is_inter()
{
if (seg_feature_active(SEG_LVL_REF_FRAME))
if (seg_feature_active(SEG_LVL_REF_FRAME)) {
m_is_inter = m_feature_data[m_segment_id][SEG_LVL_REF_FRAME] != IntraFrame;
else
m_is_inter = TRY_READ(m_tree_parser->parse_tree<bool>(SyntaxElementType::IsInter));
} else {
Optional<bool> above_intra = m_available_u ? m_above_intra : Optional<bool>();
Optional<bool> left_intra = m_available_l ? m_left_intra : Optional<bool>();
m_is_inter = TRY_READ(TreeParser::parse_is_inter(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, above_intra, left_intra));
}
return {};
}

View file

@ -289,13 +289,29 @@ ErrorOr<TXSize> TreeParser::parse_tx_size(BitStream& bit_stream, ProbabilityTabl
return value;
}
ErrorOr<bool> TreeParser::parse_is_inter(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, Optional<bool> above_intra, Optional<bool> left_intra)
{
// FIXME: Above and left contexts should be in structs.
// Probabilities
u8 context = 0;
if (above_intra.has_value() && left_intra.has_value())
context = (left_intra.value() && above_intra.value()) ? 3 : static_cast<u8>(above_intra.value() || left_intra.value());
else if (above_intra.has_value() || left_intra.has_value())
context = 2 * static_cast<u8>(above_intra.has_value() ? above_intra.value() : left_intra.value());
u8 probability = probability_table.is_inter_prob()[context];
auto value = TRY(parse_tree_new<bool>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
increment_counter(counter.m_counts_is_inter[context][value]);
return value;
}
/*
* Select a tree value based on the type of syntax element being parsed, as well as some parser state, as specified in section 9.3.1
*/
TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type)
{
switch (type) {
case SyntaxElementType::IsInter:
case SyntaxElementType::CompMode:
case SyntaxElementType::CompRef:
case SyntaxElementType::SingleRefP1:
@ -331,8 +347,6 @@ TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type)
u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
{
switch (type) {
case SyntaxElementType::IsInter:
return calculate_is_inter_probability();
case SyntaxElementType::CompMode:
return calculate_comp_mode_probability();
case SyntaxElementType::CompRef:
@ -384,18 +398,6 @@ u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
#define ABOVE_SINGLE m_decoder.m_above_single
#define LEFT_SINGLE m_decoder.m_left_single
u8 TreeParser::calculate_is_inter_probability()
{
if (AVAIL_U && AVAIL_L) {
m_ctx = (LEFT_INTRA && ABOVE_INTRA) ? 3 : LEFT_INTRA || ABOVE_INTRA;
} else if (AVAIL_U || AVAIL_L) {
m_ctx = 2 * (AVAIL_U ? ABOVE_INTRA : LEFT_INTRA);
} else {
m_ctx = 0;
}
return m_decoder.m_probability_tables->is_inter_prob()[m_ctx];
}
u8 TreeParser::calculate_comp_mode_probability()
{
if (AVAIL_U && AVAIL_L) {
@ -720,9 +722,6 @@ void TreeParser::count_syntax_element(SyntaxElementType type, int value)
increment_counter(count);
};
switch (type) {
case SyntaxElementType::IsInter:
increment(m_decoder.m_syntax_element_counter->m_counts_is_inter[m_ctx][value]);
return;
case SyntaxElementType::CompMode:
increment(m_decoder.m_syntax_element_counter->m_counts_comp_mode[m_ctx][value]);
return;

View file

@ -74,6 +74,7 @@ public:
static ErrorOr<InterpolationFilter> parse_interpolation_filter(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, Optional<ReferenceFrameType> above_ref_frame, Optional<ReferenceFrameType> left_ref_frame, Optional<InterpolationFilter> above_interpolation_filter, Optional<InterpolationFilter> left_interpolation_filter);
static ErrorOr<bool> parse_skip(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, Optional<bool> const& above_skip, Optional<bool> const& left_skip);
static ErrorOr<TXSize> parse_tx_size(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, TXSize max_tx_size, Optional<bool> above_skip, Optional<bool> left_skip, Optional<TXSize> above_tx_size, Optional<TXSize> left_tx_size);
static ErrorOr<bool> parse_is_inter(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, Optional<bool> above_intra, Optional<bool> left_intra);
void set_default_intra_mode_variables(u8 idx, u8 idy)
{
@ -107,7 +108,6 @@ public:
}
private:
u8 calculate_is_inter_probability();
u8 calculate_comp_mode_probability();
u8 calculate_comp_ref_probability();
u8 calculate_single_ref_p1_probability();