cbs_vp9.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVCODEC_CBS_VP9_H
  19. #define AVCODEC_CBS_VP9_H
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. #include "cbs.h"
  23. // Miscellaneous constants (section 3).
  24. enum {
  25. VP9_REFS_PER_FRAME = 3,
  26. VP9_MIN_TILE_WIDTH_B64 = 4,
  27. VP9_MAX_TILE_WIDTH_B64 = 64,
  28. VP9_NUM_REF_FRAMES = 8,
  29. VP9_MAX_REF_FRAMES = 4,
  30. VP9_MAX_SEGMENTS = 8,
  31. VP9_SEG_LVL_MAX = 4,
  32. };
  33. // Frame types (section 7.2).
  34. enum {
  35. VP9_KEY_FRAME = 0,
  36. VP9_NON_KEY_FRAME = 1,
  37. };
  38. // Frame sync bytes (section 7.2.1).
  39. enum {
  40. VP9_FRAME_SYNC_0 = 0x49,
  41. VP9_FRAME_SYNC_1 = 0x83,
  42. VP9_FRAME_SYNC_2 = 0x42,
  43. };
  44. // Color space values (section 7.2.2).
  45. enum {
  46. VP9_CS_UNKNOWN = 0,
  47. VP9_CS_BT_601 = 1,
  48. VP9_CS_BT_709 = 2,
  49. VP9_CS_SMPTE_170 = 3,
  50. VP9_CS_SMPTE_240 = 4,
  51. VP9_CS_BT_2020 = 5,
  52. VP9_CS_RESERVED = 6,
  53. VP9_CS_RGB = 7,
  54. };
  55. // Reference frame types (section 7.4.12).
  56. enum {
  57. VP9_INTRA_FRAME = 0,
  58. VP9_LAST_FRAME = 1,
  59. VP9_GOLDEN_FRAME = 2,
  60. VP9_ALTREF_FRAME = 3,
  61. };
  62. // Superframe properties (section B.3).
  63. enum {
  64. VP9_MAX_FRAMES_IN_SUPERFRAME = 8,
  65. VP9_SUPERFRAME_MARKER = 6,
  66. };
  67. typedef struct VP9RawFrameHeader {
  68. uint8_t frame_marker;
  69. uint8_t profile_low_bit;
  70. uint8_t profile_high_bit;
  71. uint8_t show_existing_frame;
  72. uint8_t frame_to_show_map_idx;
  73. uint8_t frame_type;
  74. uint8_t show_frame;
  75. uint8_t error_resilient_mode;
  76. // Color config.
  77. uint8_t ten_or_twelve_bit;
  78. uint8_t color_space;
  79. uint8_t color_range;
  80. uint8_t subsampling_x;
  81. uint8_t subsampling_y;
  82. uint8_t refresh_frame_flags;
  83. uint8_t intra_only;
  84. uint8_t reset_frame_context;
  85. uint8_t ref_frame_idx[VP9_REFS_PER_FRAME];
  86. uint8_t ref_frame_sign_bias[VP9_MAX_REF_FRAMES];
  87. uint8_t allow_high_precision_mv;
  88. uint8_t refresh_frame_context;
  89. uint8_t frame_parallel_decoding_mode;
  90. uint8_t frame_context_idx;
  91. // Frame/render size.
  92. uint8_t found_ref[VP9_REFS_PER_FRAME];
  93. uint16_t frame_width_minus_1;
  94. uint16_t frame_height_minus_1;
  95. uint8_t render_and_frame_size_different;
  96. uint16_t render_width_minus_1;
  97. uint16_t render_height_minus_1;
  98. // Interpolation filter.
  99. uint8_t is_filter_switchable;
  100. uint8_t raw_interpolation_filter_type;
  101. // Loop filter params.
  102. uint8_t loop_filter_level;
  103. uint8_t loop_filter_sharpness;
  104. uint8_t loop_filter_delta_enabled;
  105. uint8_t loop_filter_delta_update;
  106. uint8_t update_ref_delta[VP9_MAX_REF_FRAMES];
  107. int8_t loop_filter_ref_deltas[VP9_MAX_REF_FRAMES];
  108. uint8_t update_mode_delta[2];
  109. int8_t loop_filter_mode_deltas[2];
  110. // Quantization params.
  111. uint8_t base_q_idx;
  112. int8_t delta_q_y_dc;
  113. int8_t delta_q_uv_dc;
  114. int8_t delta_q_uv_ac;
  115. // Segmentation params.
  116. uint8_t segmentation_enabled;
  117. uint8_t segmentation_update_map;
  118. uint8_t segmentation_tree_probs[7];
  119. uint8_t segmentation_temporal_update;
  120. uint8_t segmentation_pred_prob[3];
  121. uint8_t segmentation_update_data;
  122. uint8_t segmentation_abs_or_delta_update;
  123. uint8_t feature_enabled[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
  124. uint8_t feature_value[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
  125. uint8_t feature_sign[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX];
  126. // Tile info.
  127. uint8_t tile_cols_log2;
  128. uint8_t tile_rows_log2;
  129. uint16_t header_size_in_bytes;
  130. } VP9RawFrameHeader;
  131. typedef struct VP9RawFrame {
  132. VP9RawFrameHeader header;
  133. uint8_t *data;
  134. size_t data_size;
  135. AVBufferRef *data_ref;
  136. } VP9RawFrame;
  137. typedef struct VP9RawSuperframeIndex {
  138. uint8_t superframe_marker;
  139. uint8_t bytes_per_framesize_minus_1;
  140. uint8_t frames_in_superframe_minus_1;
  141. uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME];
  142. } VP9RawSuperframeIndex;
  143. typedef struct VP9RawSuperframe {
  144. VP9RawFrame frames[VP9_MAX_FRAMES_IN_SUPERFRAME];
  145. VP9RawSuperframeIndex index;
  146. } VP9RawSuperframe;
  147. typedef struct VP9ReferenceFrameState {
  148. int frame_width; // RefFrameWidth
  149. int frame_height; // RefFrameHeight
  150. int subsampling_x; // RefSubsamplingX
  151. int subsampling_y; // RefSubsamplingY
  152. int bit_depth; // RefBitDepth
  153. } VP9ReferenceFrameState;
  154. typedef struct CodedBitstreamVP9Context {
  155. int profile;
  156. // Frame dimensions in 8x8 mode info blocks.
  157. uint16_t mi_cols;
  158. uint16_t mi_rows;
  159. // Frame dimensions in 64x64 superblocks.
  160. uint16_t sb64_cols;
  161. uint16_t sb64_rows;
  162. int frame_width;
  163. int frame_height;
  164. uint8_t subsampling_x;
  165. uint8_t subsampling_y;
  166. int bit_depth;
  167. VP9ReferenceFrameState ref[VP9_NUM_REF_FRAMES];
  168. } CodedBitstreamVP9Context;
  169. #endif /* AVCODEC_CBS_VP9_H */