浏览代码

LibVideo: Parameterize coefficient skip parsing for VP9

Zaggy1024 2 年之前
父节点
当前提交
cc735a7001

+ 6 - 3
Userland/Libraries/LibVideo/VP9/Parser.cpp

@@ -1072,10 +1072,13 @@ DecoderErrorOr<void> Parser::intra_segment_id()
 
 
 DecoderErrorOr<void> Parser::read_skip()
 DecoderErrorOr<void> Parser::read_skip()
 {
 {
-    if (seg_feature_active(SEG_LVL_SKIP))
+    if (seg_feature_active(SEG_LVL_SKIP)) {
         m_skip = true;
         m_skip = true;
-    else
-        m_skip = TRY_READ(m_tree_parser->parse_tree<bool>(SyntaxElementType::Skip));
+    } else {
+        Optional<bool> above_skip = m_available_u ? m_skips[get_image_index(m_mi_row - 1, m_mi_col)] : Optional<bool>();
+        Optional<bool> left_skip = m_available_l ? m_skips[get_image_index(m_mi_row, m_mi_col - 1)] : Optional<bool>();
+        m_skip = TRY_READ(TreeParser::parse_skip(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, above_skip, left_skip));
+    }
     return {};
     return {};
 }
 }
 
 

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

@@ -244,13 +244,25 @@ ErrorOr<InterpolationFilter> TreeParser::parse_interpolation_filter(BitStream& b
     return value;
     return value;
 }
 }
 
 
+ErrorOr<bool> TreeParser::parse_skip(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, Optional<bool> const& above_skip, Optional<bool> const& left_skip)
+{
+    // Probabilities
+    u8 context = 0;
+    context += static_cast<u8>(above_skip.value_or(false));
+    context += static_cast<u8>(left_skip.value_or(false));
+    u8 probability = probability_table.skip_prob()[context];
+
+    auto value = TRY(parse_tree_new<bool>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
+    increment_counter(counter.m_counts_skip[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
  * 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::Skip:
     case SyntaxElementType::IsInter:
     case SyntaxElementType::IsInter:
     case SyntaxElementType::CompMode:
     case SyntaxElementType::CompMode:
     case SyntaxElementType::CompRef:
     case SyntaxElementType::CompRef:
@@ -293,8 +305,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::Skip:
-        return calculate_skip_probability();
     case SyntaxElementType::IsInter:
     case SyntaxElementType::IsInter:
         return calculate_is_inter_probability();
         return calculate_is_inter_probability();
     case SyntaxElementType::CompMode:
     case SyntaxElementType::CompMode:
@@ -350,16 +360,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_skip_probability()
-{
-    m_ctx = 0;
-    if (AVAIL_U)
-        m_ctx += m_decoder.m_skips[(m_decoder.m_mi_row - 1) * m_decoder.m_mi_cols + m_decoder.m_mi_col];
-    if (AVAIL_L)
-        m_ctx += m_decoder.m_skips[m_decoder.m_mi_row * m_decoder.m_mi_cols + m_decoder.m_mi_col - 1];
-    return m_decoder.m_probability_tables->skip_prob()[m_ctx];
-}
-
 u8 TreeParser::calculate_is_inter_probability()
 u8 TreeParser::calculate_is_inter_probability()
 {
 {
     if (AVAIL_U && AVAIL_L) {
     if (AVAIL_U && AVAIL_L) {
@@ -718,9 +718,6 @@ void TreeParser::count_syntax_element(SyntaxElementType type, int value)
         increment_counter(count);
         increment_counter(count);
     };
     };
     switch (type) {
     switch (type) {
-    case SyntaxElementType::Skip:
-        increment(m_decoder.m_syntax_element_counter->m_counts_skip[m_ctx][value]);
-        return;
     case SyntaxElementType::IsInter:
     case SyntaxElementType::IsInter:
         increment(m_decoder.m_syntax_element_counter->m_counts_is_inter[m_ctx][value]);
         increment(m_decoder.m_syntax_element_counter->m_counts_is_inter[m_ctx][value]);
         return;
         return;

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

@@ -72,6 +72,7 @@ public:
     static ErrorOr<bool> parse_segment_id_predicted(BitStream&, u8 const probabilities[3], u8 above_seg_pred_context, u8 left_seg_pred_context);
     static ErrorOr<bool> parse_segment_id_predicted(BitStream&, u8 const probabilities[3], u8 above_seg_pred_context, u8 left_seg_pred_context);
     static ErrorOr<PredictionMode> parse_inter_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, u8 mode_context_for_ref_frame_0);
     static ErrorOr<PredictionMode> parse_inter_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, u8 mode_context_for_ref_frame_0);
     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<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);
 
 
     void set_default_intra_mode_variables(u8 idx, u8 idy)
     void set_default_intra_mode_variables(u8 idx, u8 idy)
     {
     {
@@ -105,7 +106,6 @@ public:
     }
     }
 
 
 private:
 private:
-    u8 calculate_skip_probability();
     u8 calculate_is_inter_probability();
     u8 calculate_is_inter_probability();
     u8 calculate_comp_mode_probability();
     u8 calculate_comp_mode_probability();
     u8 calculate_comp_ref_probability();
     u8 calculate_comp_ref_probability();