cbs_av1.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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_AV1_H
  19. #define AVCODEC_CBS_AV1_H
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. #include "av1.h"
  23. #include "cbs.h"
  24. typedef struct AV1RawOBUHeader {
  25. uint8_t obu_forbidden_bit;
  26. uint8_t obu_type;
  27. uint8_t obu_extension_flag;
  28. uint8_t obu_has_size_field;
  29. uint8_t obu_reserved_1bit;
  30. uint8_t temporal_id;
  31. uint8_t spatial_id;
  32. uint8_t extension_header_reserved_3bits;
  33. } AV1RawOBUHeader;
  34. typedef struct AV1RawColorConfig {
  35. uint8_t high_bitdepth;
  36. uint8_t twelve_bit;
  37. uint8_t mono_chrome;
  38. uint8_t color_description_present_flag;
  39. uint8_t color_primaries;
  40. uint8_t transfer_characteristics;
  41. uint8_t matrix_coefficients;
  42. uint8_t color_range;
  43. uint8_t subsampling_x;
  44. uint8_t subsampling_y;
  45. uint8_t chroma_sample_position;
  46. uint8_t separate_uv_delta_q;
  47. } AV1RawColorConfig;
  48. typedef struct AV1RawTimingInfo {
  49. uint32_t num_units_in_display_tick;
  50. uint32_t time_scale;
  51. uint8_t equal_picture_interval;
  52. uint32_t num_ticks_per_picture_minus_1;
  53. } AV1RawTimingInfo;
  54. typedef struct AV1RawDecoderModelInfo {
  55. uint8_t buffer_delay_length_minus_1;
  56. uint32_t num_units_in_decoding_tick;
  57. uint8_t buffer_removal_time_length_minus_1;
  58. uint8_t frame_presentation_time_length_minus_1;
  59. } AV1RawDecoderModelInfo;
  60. typedef struct AV1RawSequenceHeader {
  61. uint8_t seq_profile;
  62. uint8_t still_picture;
  63. uint8_t reduced_still_picture_header;
  64. uint8_t timing_info_present_flag;
  65. uint8_t decoder_model_info_present_flag;
  66. uint8_t initial_display_delay_present_flag;
  67. uint8_t operating_points_cnt_minus_1;
  68. AV1RawTimingInfo timing_info;
  69. AV1RawDecoderModelInfo decoder_model_info;
  70. uint16_t operating_point_idc[AV1_MAX_OPERATING_POINTS];
  71. uint8_t seq_level_idx[AV1_MAX_OPERATING_POINTS];
  72. uint8_t seq_tier[AV1_MAX_OPERATING_POINTS];
  73. uint8_t decoder_model_present_for_this_op[AV1_MAX_OPERATING_POINTS];
  74. uint32_t decoder_buffer_delay[AV1_MAX_OPERATING_POINTS];
  75. uint32_t encoder_buffer_delay[AV1_MAX_OPERATING_POINTS];
  76. uint8_t low_delay_mode_flag[AV1_MAX_OPERATING_POINTS];
  77. uint8_t initial_display_delay_present_for_this_op[AV1_MAX_OPERATING_POINTS];
  78. uint8_t initial_display_delay_minus_1[AV1_MAX_OPERATING_POINTS];
  79. uint8_t frame_width_bits_minus_1;
  80. uint8_t frame_height_bits_minus_1;
  81. uint16_t max_frame_width_minus_1;
  82. uint16_t max_frame_height_minus_1;
  83. uint8_t frame_id_numbers_present_flag;
  84. uint8_t delta_frame_id_length_minus_2;
  85. uint8_t additional_frame_id_length_minus_1;
  86. uint8_t use_128x128_superblock;
  87. uint8_t enable_filter_intra;
  88. uint8_t enable_intra_edge_filter;
  89. uint8_t enable_interintra_compound;
  90. uint8_t enable_masked_compound;
  91. uint8_t enable_warped_motion;
  92. uint8_t enable_dual_filter;
  93. uint8_t enable_order_hint;
  94. uint8_t enable_jnt_comp;
  95. uint8_t enable_ref_frame_mvs;
  96. uint8_t seq_choose_screen_content_tools;
  97. uint8_t seq_force_screen_content_tools;
  98. uint8_t seq_choose_integer_mv;
  99. uint8_t seq_force_integer_mv;
  100. uint8_t order_hint_bits_minus_1;
  101. uint8_t enable_superres;
  102. uint8_t enable_cdef;
  103. uint8_t enable_restoration;
  104. AV1RawColorConfig color_config;
  105. uint8_t film_grain_params_present;
  106. } AV1RawSequenceHeader;
  107. typedef struct AV1RawFrameHeader {
  108. uint8_t show_existing_frame;
  109. uint8_t frame_to_show_map_idx;
  110. uint32_t frame_presentation_time;
  111. uint32_t display_frame_id;
  112. uint8_t frame_type;
  113. uint8_t show_frame;
  114. uint8_t showable_frame;
  115. uint8_t error_resilient_mode;
  116. uint8_t disable_cdf_update;
  117. uint8_t allow_screen_content_tools;
  118. uint8_t force_integer_mv;
  119. uint32_t current_frame_id;
  120. uint8_t frame_size_override_flag;
  121. uint8_t order_hint;
  122. uint8_t buffer_removal_time_present_flag;
  123. uint32_t buffer_removal_time[AV1_MAX_OPERATING_POINTS];
  124. uint8_t primary_ref_frame;
  125. uint16_t frame_width_minus_1;
  126. uint16_t frame_height_minus_1;
  127. uint8_t use_superres;
  128. uint8_t coded_denom;
  129. uint8_t render_and_frame_size_different;
  130. uint16_t render_width_minus_1;
  131. uint16_t render_height_minus_1;
  132. uint8_t found_ref[AV1_REFS_PER_FRAME];
  133. uint8_t refresh_frame_flags;
  134. uint8_t allow_intrabc;
  135. uint8_t ref_order_hint[AV1_NUM_REF_FRAMES];
  136. uint8_t frame_refs_short_signaling;
  137. uint8_t last_frame_idx;
  138. uint8_t golden_frame_idx;
  139. int8_t ref_frame_idx[AV1_REFS_PER_FRAME];
  140. uint32_t delta_frame_id_minus1[AV1_REFS_PER_FRAME];
  141. uint8_t allow_high_precision_mv;
  142. uint8_t is_filter_switchable;
  143. uint8_t interpolation_filter;
  144. uint8_t is_motion_mode_switchable;
  145. uint8_t use_ref_frame_mvs;
  146. uint8_t disable_frame_end_update_cdf;
  147. uint8_t uniform_tile_spacing_flag;
  148. uint8_t tile_cols_log2;
  149. uint8_t tile_rows_log2;
  150. uint8_t width_in_sbs_minus_1[AV1_MAX_TILE_COLS];
  151. uint8_t height_in_sbs_minus_1[AV1_MAX_TILE_ROWS];
  152. uint16_t context_update_tile_id;
  153. uint8_t tile_size_bytes_minus1;
  154. // These are derived values, but it's very unhelpful to have to
  155. // recalculate them all the time so we store them here.
  156. uint16_t tile_cols;
  157. uint16_t tile_rows;
  158. uint8_t base_q_idx;
  159. int8_t delta_q_y_dc;
  160. uint8_t diff_uv_delta;
  161. int8_t delta_q_u_dc;
  162. int8_t delta_q_u_ac;
  163. int8_t delta_q_v_dc;
  164. int8_t delta_q_v_ac;
  165. uint8_t using_qmatrix;
  166. uint8_t qm_y;
  167. uint8_t qm_u;
  168. uint8_t qm_v;
  169. uint8_t segmentation_enabled;
  170. uint8_t segmentation_update_map;
  171. uint8_t segmentation_temporal_update;
  172. uint8_t segmentation_update_data;
  173. uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
  174. int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
  175. uint8_t delta_q_present;
  176. uint8_t delta_q_res;
  177. uint8_t delta_lf_present;
  178. uint8_t delta_lf_res;
  179. uint8_t delta_lf_multi;
  180. uint8_t loop_filter_level[4];
  181. uint8_t loop_filter_sharpness;
  182. uint8_t loop_filter_delta_enabled;
  183. uint8_t loop_filter_delta_update;
  184. uint8_t update_ref_delta[AV1_TOTAL_REFS_PER_FRAME];
  185. int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME];
  186. uint8_t update_mode_delta[2];
  187. int8_t loop_filter_mode_deltas[2];
  188. uint8_t cdef_damping_minus_3;
  189. uint8_t cdef_bits;
  190. uint8_t cdef_y_pri_strength[8];
  191. uint8_t cdef_y_sec_strength[8];
  192. uint8_t cdef_uv_pri_strength[8];
  193. uint8_t cdef_uv_sec_strength[8];
  194. uint8_t lr_type[3];
  195. uint8_t lr_unit_shift;
  196. uint8_t lr_uv_shift;
  197. uint8_t tx_mode;
  198. uint8_t reference_select;
  199. uint8_t skip_mode_present;
  200. uint8_t allow_warped_motion;
  201. uint8_t reduced_tx_set;
  202. uint8_t is_global[AV1_TOTAL_REFS_PER_FRAME];
  203. uint8_t is_rot_zoom[AV1_TOTAL_REFS_PER_FRAME];
  204. uint8_t is_translation[AV1_TOTAL_REFS_PER_FRAME];
  205. //AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
  206. uint32_t gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
  207. uint8_t apply_grain;
  208. uint16_t grain_seed;
  209. uint8_t update_grain;
  210. uint8_t film_grain_params_ref_idx;
  211. uint8_t num_y_points;
  212. uint8_t point_y_value[14];
  213. uint8_t point_y_scaling[14];
  214. uint8_t chroma_scaling_from_luma;
  215. uint8_t num_cb_points;
  216. uint8_t point_cb_value[10];
  217. uint8_t point_cb_scaling[10];
  218. uint8_t num_cr_points;
  219. uint8_t point_cr_value[10];
  220. uint8_t point_cr_scaling[10];
  221. uint8_t grain_scaling_minus_8;
  222. uint8_t ar_coeff_lag;
  223. uint8_t ar_coeffs_y_plus_128[24];
  224. uint8_t ar_coeffs_cb_plus_128[25];
  225. uint8_t ar_coeffs_cr_plus_128[25];
  226. uint8_t ar_coeff_shift_minus_6;
  227. uint8_t grain_scale_shift;
  228. uint8_t cb_mult;
  229. uint8_t cb_luma_mult;
  230. uint16_t cb_offset;
  231. uint8_t cr_mult;
  232. uint8_t cr_luma_mult;
  233. uint16_t cr_offset;
  234. uint8_t overlap_flag;
  235. uint8_t clip_to_restricted_range;
  236. } AV1RawFrameHeader;
  237. typedef struct AV1RawTileData {
  238. uint8_t *data;
  239. size_t data_size;
  240. AVBufferRef *data_ref;
  241. } AV1RawTileData;
  242. typedef struct AV1RawTileGroup {
  243. uint8_t tile_start_and_end_present_flag;
  244. uint16_t tg_start;
  245. uint16_t tg_end;
  246. AV1RawTileData tile_data;
  247. } AV1RawTileGroup;
  248. typedef struct AV1RawFrame {
  249. AV1RawFrameHeader header;
  250. AV1RawTileGroup tile_group;
  251. } AV1RawFrame;
  252. typedef struct AV1RawTileList {
  253. uint8_t output_frame_width_in_tiles_minus_1;
  254. uint8_t output_frame_height_in_tiles_minus_1;
  255. uint16_t tile_count_minus_1;
  256. AV1RawTileData tile_data;
  257. } AV1RawTileList;
  258. typedef struct AV1RawMetadataHDRCLL {
  259. uint16_t max_cll;
  260. uint16_t max_fall;
  261. } AV1RawMetadataHDRCLL;
  262. typedef struct AV1RawMetadataHDRMDCV {
  263. uint16_t primary_chromaticity_x[3];
  264. uint16_t primary_chromaticity_y[3];
  265. uint16_t white_point_chromaticity_x;
  266. uint16_t white_point_chromaticity_y;
  267. uint32_t luminance_max;
  268. uint32_t luminance_min;
  269. } AV1RawMetadataHDRMDCV;
  270. typedef struct AV1RawMetadataScalability {
  271. uint8_t scalability_mode_idc;
  272. uint8_t spatial_layers_cnt_minus_1;
  273. uint8_t spatial_layer_dimensions_present_flag;
  274. uint8_t spatial_layer_description_present_flag;
  275. uint8_t temporal_group_description_present_flag;
  276. uint8_t scalability_structure_reserved_3bits;
  277. uint16_t spatial_layer_max_width[4];
  278. uint16_t spatial_layer_max_height[4];
  279. uint8_t spatial_layer_ref_id[4];
  280. uint8_t temporal_group_size;
  281. uint8_t temporal_group_temporal_id[255];
  282. uint8_t temporal_group_temporal_switching_up_point_flag[255];
  283. uint8_t temporal_group_spatial_switching_up_point_flag[255];
  284. uint8_t temporal_group_ref_cnt[255];
  285. uint8_t temporal_group_ref_pic_diff[255][7];
  286. } AV1RawMetadataScalability;
  287. typedef struct AV1RawMetadataITUTT35 {
  288. uint8_t itu_t_t35_country_code;
  289. uint8_t itu_t_t35_country_code_extension_byte;
  290. uint8_t *payload;
  291. size_t payload_size;
  292. AVBufferRef *payload_ref;
  293. } AV1RawMetadataITUTT35;
  294. typedef struct AV1RawMetadataTimecode {
  295. uint8_t counting_type;
  296. uint8_t full_timestamp_flag;
  297. uint8_t discontinuity_flag;
  298. uint8_t cnt_dropped_flag;
  299. uint16_t n_frames;
  300. uint8_t seconds_value;
  301. uint8_t minutes_value;
  302. uint8_t hours_value;
  303. uint8_t seconds_flag;
  304. uint8_t minutes_flag;
  305. uint8_t hours_flag;
  306. uint8_t time_offset_length;
  307. uint32_t time_offset_value;
  308. } AV1RawMetadataTimecode;
  309. typedef struct AV1RawMetadata {
  310. uint64_t metadata_type;
  311. union {
  312. AV1RawMetadataHDRCLL hdr_cll;
  313. AV1RawMetadataHDRMDCV hdr_mdcv;
  314. AV1RawMetadataScalability scalability;
  315. AV1RawMetadataITUTT35 itut_t35;
  316. AV1RawMetadataTimecode timecode;
  317. } metadata;
  318. } AV1RawMetadata;
  319. typedef struct AV1RawPadding {
  320. uint8_t *payload;
  321. size_t payload_size;
  322. AVBufferRef *payload_ref;
  323. } AV1RawPadding;
  324. typedef struct AV1RawOBU {
  325. AV1RawOBUHeader header;
  326. size_t obu_size;
  327. union {
  328. AV1RawSequenceHeader sequence_header;
  329. AV1RawFrameHeader frame_header;
  330. AV1RawFrame frame;
  331. AV1RawTileGroup tile_group;
  332. AV1RawTileList tile_list;
  333. AV1RawMetadata metadata;
  334. AV1RawPadding padding;
  335. } obu;
  336. } AV1RawOBU;
  337. typedef struct AV1ReferenceFrameState {
  338. int valid; // RefValid
  339. int frame_id; // RefFrameId
  340. int upscaled_width; // RefUpscaledWidth
  341. int frame_width; // RefFrameWidth
  342. int frame_height; // RefFrameHeight
  343. int render_width; // RefRenderWidth
  344. int render_height; // RefRenderHeight
  345. int frame_type; // RefFrameType
  346. int subsampling_x; // RefSubsamplingX
  347. int subsampling_y; // RefSubsamplingY
  348. int bit_depth; // RefBitDepth
  349. int order_hint; // RefOrderHint
  350. } AV1ReferenceFrameState;
  351. typedef struct CodedBitstreamAV1Context {
  352. AV1RawSequenceHeader *sequence_header;
  353. AVBufferRef *sequence_header_ref;
  354. int seen_frame_header;
  355. AVBufferRef *frame_header_ref;
  356. uint8_t *frame_header;
  357. size_t frame_header_size;
  358. int temporal_id;
  359. int spatial_id;
  360. int operating_point_idc;
  361. int bit_depth;
  362. int order_hint;
  363. int frame_width;
  364. int frame_height;
  365. int upscaled_width;
  366. int render_width;
  367. int render_height;
  368. int num_planes;
  369. int coded_lossless;
  370. int all_lossless;
  371. int tile_cols;
  372. int tile_rows;
  373. AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES];
  374. } CodedBitstreamAV1Context;
  375. #endif /* AVCODEC_CBS_AV1_H */