TreeParser.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "BitStream.h"
  8. #include "Enums.h"
  9. #include "ProbabilityTables.h"
  10. #include "SyntaxElementCounter.h"
  11. namespace Video::VP9 {
  12. class Parser;
  13. class TreeParser {
  14. public:
  15. explicit TreeParser(Parser& decoder)
  16. : m_decoder(decoder)
  17. {
  18. }
  19. class TreeSelection {
  20. public:
  21. union TreeSelectionValue {
  22. int const* m_tree;
  23. int m_value;
  24. };
  25. TreeSelection(int const* values);
  26. TreeSelection(int value);
  27. bool is_single_value() const { return m_is_single_value; }
  28. int get_single_value() const { return m_value.m_value; }
  29. int const* get_tree_value() const { return m_value.m_tree; }
  30. private:
  31. bool m_is_single_value;
  32. TreeSelectionValue m_value;
  33. };
  34. /* (9.3.3) */
  35. template<typename T = int>
  36. T parse_tree(SyntaxElementType type);
  37. /* (9.3.1) */
  38. TreeSelection select_tree(SyntaxElementType type);
  39. /* (9.3.2) */
  40. u8 select_tree_probability(SyntaxElementType type, u8 node);
  41. /* (9.3.4) */
  42. void count_syntax_element(SyntaxElementType type, int value);
  43. void set_default_intra_mode_variables(u8 idx, u8 idy)
  44. {
  45. m_idx = idx;
  46. m_idy = idy;
  47. }
  48. void set_tokens_variables(u8 band, u32 c, u32 plane, TXSize tx_size, u32 pos)
  49. {
  50. m_band = band;
  51. m_c = c;
  52. m_plane = plane;
  53. m_tx_size = tx_size;
  54. m_pos = pos;
  55. }
  56. void set_start_x_and_y(u32 start_x, u32 start_y)
  57. {
  58. m_start_x = start_x;
  59. m_start_y = start_y;
  60. }
  61. private:
  62. u8 calculate_partition_probability(u8 node);
  63. u8 calculate_default_intra_mode_probability(u8 node);
  64. u8 calculate_default_uv_mode_probability(u8 node);
  65. u8 calculate_intra_mode_probability(u8 node);
  66. u8 calculate_sub_intra_mode_probability(u8 node);
  67. u8 calculate_uv_mode_probability(u8 node);
  68. u8 calculate_segment_id_probability(u8 node);
  69. u8 calculate_skip_probability();
  70. u8 calculate_seg_id_predicted_probability();
  71. u8 calculate_is_inter_probability();
  72. u8 calculate_comp_mode_probability();
  73. u8 calculate_comp_ref_probability();
  74. u8 calculate_single_ref_p1_probability();
  75. u8 calculate_single_ref_p2_probability();
  76. u8 calculate_tx_size_probability(u8 node);
  77. u8 calculate_inter_mode_probability(u8 node);
  78. u8 calculate_interp_filter_probability(u8 node);
  79. u8 calculate_token_probability(u8 node);
  80. u8 calculate_more_coefs_probability();
  81. Parser& m_decoder;
  82. // m_ctx is a member variable because it is required for syntax element counting (section 9.3.4)
  83. u8 m_ctx { 0 };
  84. // These are variables necessary for parsing tree data, but aren't useful otherwise, so they're
  85. // not stored in the Decoder itself.
  86. u8 m_idx { 0 };
  87. u8 m_idy { 0 };
  88. u8 m_band { 0 };
  89. u32 m_start_x { 0 };
  90. u32 m_start_y { 0 };
  91. u32 m_c { 0 };
  92. u32 m_plane { 0 };
  93. TXSize m_tx_size;
  94. u32 m_pos { 0 };
  95. };
  96. }