浏览代码

LibVideo: Parameterize UV mode parsing in the VP9 decoder

Zaggy1024 2 年之前
父节点
当前提交
540ef22b95

+ 1 - 1
Userland/Libraries/LibVideo/VP9/Parser.cpp

@@ -1200,7 +1200,7 @@ DecoderErrorOr<void> Parser::intra_block_mode_info()
         }
         }
         m_y_mode = sub_intra_mode;
         m_y_mode = sub_intra_mode;
     }
     }
-    m_uv_mode = TRY_READ(m_tree_parser->parse_tree<PredictionMode>(SyntaxElementType::UVMode));
+    m_uv_mode = TRY_READ(TreeParser::parse_uv_mode(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, m_y_mode));
     return {};
     return {};
 }
 }
 
 

+ 13 - 13
Userland/Libraries/LibVideo/VP9/TreeParser.cpp

@@ -174,14 +174,25 @@ ErrorOr<PredictionMode> TreeParser::parse_sub_intra_mode(BitStream& bit_stream,
     return value;
     return value;
 }
 }
 
 
+ErrorOr<PredictionMode> TreeParser::parse_uv_mode(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, PredictionMode y_mode)
+{
+    // Tree
+    TreeParser::TreeSelection tree = { intra_mode_tree };
+
+    // Probabilities
+    u8 const* probabilities = probability_table.uv_mode_probs()[to_underlying(y_mode)];
+
+    auto value = TRY(parse_tree_new<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
+    increment_counter(counter.m_counts_uv_mode[to_underlying(y_mode)][to_underlying(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
  * 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)
 TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type)
 {
 {
     switch (type) {
     switch (type) {
-    case SyntaxElementType::UVMode:
-        return { intra_mode_tree };
     case SyntaxElementType::SegmentID:
     case SyntaxElementType::SegmentID:
         return { segment_tree };
         return { segment_tree };
     case SyntaxElementType::Skip:
     case SyntaxElementType::Skip:
@@ -232,8 +243,6 @@ TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type)
 u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
 u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
 {
 {
     switch (type) {
     switch (type) {
-    case SyntaxElementType::UVMode:
-        return calculate_uv_mode_probability(node);
     case SyntaxElementType::SegmentID:
     case SyntaxElementType::SegmentID:
         return calculate_segment_id_probability(node);
         return calculate_segment_id_probability(node);
     case SyntaxElementType::Skip:
     case SyntaxElementType::Skip:
@@ -299,12 +308,6 @@ u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
 #define ABOVE_SINGLE m_decoder.m_above_single
 #define ABOVE_SINGLE m_decoder.m_above_single
 #define LEFT_SINGLE m_decoder.m_left_single
 #define LEFT_SINGLE m_decoder.m_left_single
 
 
-u8 TreeParser::calculate_uv_mode_probability(u8 node)
-{
-    m_ctx = to_underlying(m_decoder.m_y_mode);
-    return m_decoder.m_probability_tables->uv_mode_probs()[m_ctx][node];
-}
-
 u8 TreeParser::calculate_segment_id_probability(u8 node)
 u8 TreeParser::calculate_segment_id_probability(u8 node)
 {
 {
     return m_decoder.m_segmentation_tree_probs[node];
     return m_decoder.m_segmentation_tree_probs[node];
@@ -712,9 +715,6 @@ void TreeParser::count_syntax_element(SyntaxElementType type, int value)
         increment_counter(count);
         increment_counter(count);
     };
     };
     switch (type) {
     switch (type) {
-    case SyntaxElementType::UVMode:
-        increment(m_decoder.m_syntax_element_counter->m_counts_uv_mode[m_ctx][value]);
-        return;
     case SyntaxElementType::Skip:
     case SyntaxElementType::Skip:
         increment(m_decoder.m_syntax_element_counter->m_counts_skip[m_ctx][value]);
         increment(m_decoder.m_syntax_element_counter->m_counts_skip[m_ctx][value]);
         return;
         return;

+ 1 - 1
Userland/Libraries/LibVideo/VP9/TreeParser.h

@@ -67,6 +67,7 @@ public:
     static ErrorOr<PredictionMode> parse_default_uv_mode(BitStream&, ProbabilityTables const&, PredictionMode y_mode);
     static ErrorOr<PredictionMode> parse_default_uv_mode(BitStream&, ProbabilityTables const&, PredictionMode y_mode);
     static ErrorOr<PredictionMode> parse_intra_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, BlockSubsize mi_size);
     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_sub_intra_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&);
+    static ErrorOr<PredictionMode> parse_uv_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, PredictionMode y_mode);
 
 
     void set_default_intra_mode_variables(u8 idx, u8 idy)
     void set_default_intra_mode_variables(u8 idx, u8 idy)
     {
     {
@@ -100,7 +101,6 @@ public:
     }
     }
 
 
 private:
 private:
-    u8 calculate_uv_mode_probability(u8 node);
     u8 calculate_segment_id_probability(u8 node);
     u8 calculate_segment_id_probability(u8 node);
     u8 calculate_skip_probability();
     u8 calculate_skip_probability();
     u8 calculate_seg_id_predicted_probability();
     u8 calculate_seg_id_predicted_probability();