LibVideo: Parameterize inter mode parsing in the VP9 decoder

This commit is contained in:
Zaggy1024 2022-11-06 20:05:31 -06:00 committed by Andrew Kaster
parent 540ef22b95
commit cbb8a3f0f4
Notes: sideshowbarker 2024-07-17 04:32:54 +09:00
3 changed files with 16 additions and 16 deletions

View file

@ -1217,7 +1217,7 @@ DecoderErrorOr<void> Parser::inter_block_mode_info()
if (seg_feature_active(SEG_LVL_SKIP)) {
m_y_mode = PredictionMode::ZeroMv;
} else if (m_mi_size >= Block_8x8) {
m_y_mode = TRY_READ(m_tree_parser->parse_tree<PredictionMode>(SyntaxElementType::InterMode));
m_y_mode = TRY_READ(TreeParser::parse_inter_mode(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, m_mode_context[m_ref_frame[0]]));
}
if (m_interpolation_filter == Switchable)
m_interp_filter = TRY_READ(m_tree_parser->parse_tree<InterpolationFilter>(SyntaxElementType::InterpFilter));
@ -1228,7 +1228,7 @@ DecoderErrorOr<void> Parser::inter_block_mode_info()
m_num_4x4_h = num_4x4_blocks_high_lookup[m_mi_size];
for (auto idy = 0; idy < 2; idy += m_num_4x4_h) {
for (auto idx = 0; idx < 2; idx += m_num_4x4_w) {
m_y_mode = TRY_READ(m_tree_parser->parse_tree<PredictionMode>(SyntaxElementType::InterMode));
m_y_mode = TRY_READ(TreeParser::parse_inter_mode(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, m_mode_context[m_ref_frame[0]]));
if (m_y_mode == PredictionMode::NearestMv || m_y_mode == PredictionMode::NearMv) {
for (auto j = 0; j < 1 + is_compound; j++)
append_sub8x8_mvs(idy * 2 + idx, j);

View file

@ -187,6 +187,19 @@ ErrorOr<PredictionMode> TreeParser::parse_uv_mode(BitStream& bit_stream, Probabi
return value;
}
ErrorOr<PredictionMode> TreeParser::parse_inter_mode(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, u8 mode_context_for_ref_frame_0)
{
// Tree
TreeParser::TreeSelection tree = { inter_mode_tree };
// Probabilities
u8 const* probabilities = probability_table.inter_mode_probs()[mode_context_for_ref_frame_0];
auto value = TRY(parse_tree_new<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
increment_counter(counter.m_counts_inter_mode[mode_context_for_ref_frame_0][to_underlying(value) - to_underlying(PredictionMode::NearestMv)]);
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
*/
@ -213,8 +226,6 @@ TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type)
if (m_decoder.m_max_tx_size == TX_16x16)
return { tx_size_16_tree };
return { tx_size_8_tree };
case SyntaxElementType::InterMode:
return { inter_mode_tree };
case SyntaxElementType::InterpFilter:
return { interp_filter_tree };
case SyntaxElementType::MVJoint:
@ -268,8 +279,6 @@ u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
return m_decoder.m_probability_tables->mv_bits_prob()[m_mv_component][m_mv_bit];
case SyntaxElementType::TXSize:
return calculate_tx_size_probability(node);
case SyntaxElementType::InterMode:
return calculate_inter_mode_probability(node);
case SyntaxElementType::InterpFilter:
return calculate_interp_filter_probability(node);
case SyntaxElementType::MVJoint:
@ -610,12 +619,6 @@ u8 TreeParser::calculate_tx_size_probability(u8 node)
return m_decoder.m_probability_tables->tx_probs()[m_decoder.m_max_tx_size][m_ctx][node];
}
u8 TreeParser::calculate_inter_mode_probability(u8 node)
{
m_ctx = m_decoder.m_mode_context[m_decoder.m_ref_frame[0]];
return m_decoder.m_probability_tables->inter_mode_probs()[m_ctx][node];
}
u8 TreeParser::calculate_interp_filter_probability(u8 node)
{
// NOTE: SWITCHABLE_FILTERS is not used in the spec for this function. Therefore, the number
@ -747,9 +750,6 @@ void TreeParser::count_syntax_element(SyntaxElementType type, int value)
case SyntaxElementType::TXSize:
increment(m_decoder.m_syntax_element_counter->m_counts_tx_size[m_decoder.m_max_tx_size][m_ctx][value]);
return;
case SyntaxElementType::InterMode:
increment(m_decoder.m_syntax_element_counter->m_counts_inter_mode[m_ctx][value]);
return;
case SyntaxElementType::InterpFilter:
increment(m_decoder.m_syntax_element_counter->m_counts_interp_filter[m_ctx][value]);
return;

View file

@ -68,6 +68,7 @@ public:
static ErrorOr<PredictionMode> parse_intra_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, BlockSubsize mi_size);
static ErrorOr<PredictionMode> parse_sub_intra_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&);
static ErrorOr<PredictionMode> parse_uv_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, PredictionMode y_mode);
static ErrorOr<PredictionMode> parse_inter_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, u8 mode_context_for_ref_frame_0);
void set_default_intra_mode_variables(u8 idx, u8 idy)
{
@ -110,7 +111,6 @@ private:
u8 calculate_single_ref_p1_probability();
u8 calculate_single_ref_p2_probability();
u8 calculate_tx_size_probability(u8 node);
u8 calculate_inter_mode_probability(u8 node);
u8 calculate_interp_filter_probability(u8 node);
u8 calculate_token_probability(u8 node);
u8 calculate_more_coefs_probability();