Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_ENCODER_CONTEXT_TREE_H_ |
| 13 | #define AOM_AV1_ENCODER_CONTEXT_TREE_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
chiyotsai | 03c48a8 | 2019-10-18 16:48:59 -0700 | [diff] [blame] | 15 | #include "config/aom_config.h" |
| 16 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "av1/common/blockd.h" |
| 18 | #include "av1/encoder/block.h" |
Neha Mary Thomas | 70d547d | 2023-03-03 02:52:45 +0530 | [diff] [blame] | 19 | #include "av1/encoder/speed_features.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
Mufaddal Chakera | 8c2d517 | 2021-06-09 01:33:48 +0530 | [diff] [blame] | 25 | struct AV1_PRIMARY; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | struct AV1_COMP; |
| 27 | struct AV1Common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | struct ThreadData; |
| 29 | |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 30 | typedef struct { |
| 31 | tran_low_t *coeff_buf[MAX_MB_PLANE]; |
| 32 | tran_low_t *qcoeff_buf[MAX_MB_PLANE]; |
| 33 | tran_low_t *dqcoeff_buf[MAX_MB_PLANE]; |
| 34 | } PC_TREE_SHARED_BUFFERS; |
| 35 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | // Structure to hold snapshot of coding context during the mode picking process |
chiyotsai | c9b9fa5 | 2020-06-12 15:19:50 -0700 | [diff] [blame] | 37 | typedef struct PICK_MODE_CONTEXT { |
Yue Chen | 53b53f0 | 2018-03-29 14:31:23 -0700 | [diff] [blame] | 38 | MB_MODE_INFO mic; |
Ravi Chaudhary | e1a59ce | 2020-03-24 08:21:18 +0530 | [diff] [blame] | 39 | MB_MODE_INFO_EXT_FRAME mbmi_ext_best; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 40 | uint8_t *color_index_map[2]; |
Hui Su | f4b79c7 | 2018-03-22 13:14:36 -0700 | [diff] [blame] | 41 | uint8_t *blk_skip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 42 | |
Brennan Shacklett | e0b5ae8 | 2016-11-07 17:25:20 -0800 | [diff] [blame] | 43 | tran_low_t *coeff[MAX_MB_PLANE]; |
| 44 | tran_low_t *qcoeff[MAX_MB_PLANE]; |
| 45 | tran_low_t *dqcoeff[MAX_MB_PLANE]; |
Brennan Shacklett | e0b5ae8 | 2016-11-07 17:25:20 -0800 | [diff] [blame] | 46 | uint16_t *eobs[MAX_MB_PLANE]; |
Angie Chiang | 74e2307 | 2017-03-24 14:54:23 -0700 | [diff] [blame] | 47 | uint8_t *txb_entropy_ctx[MAX_MB_PLANE]; |
Hui Su | 52b7ddc | 2019-10-10 16:27:16 -0700 | [diff] [blame] | 48 | uint8_t *tx_type_map; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | int num_4x4_blk; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | // For current partition, only if all Y, U, and V transform blocks' |
Yushin Cho | 7c6d292 | 2017-05-03 17:35:06 -0700 | [diff] [blame] | 52 | // coefficients are quantized to 0, skippable is set to 1. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | int skippable; |
chiyotsai | 03c48a8 | 2019-10-18 16:48:59 -0700 | [diff] [blame] | 54 | #if CONFIG_INTERNAL_STATS |
chiyotsai | 2b471a3 | 2019-10-18 16:31:24 -0700 | [diff] [blame] | 55 | THR_MODES best_mode_index; |
chiyotsai | 03c48a8 | 2019-10-18 16:48:59 -0700 | [diff] [blame] | 56 | #endif // CONFIG_INTERNAL_STATS |
Hui Su | cff7444 | 2019-04-08 11:54:47 -0700 | [diff] [blame] | 57 | RD_STATS rd_stats; |
Satish Kumar Suman | 69e9329 | 2018-11-28 16:05:33 +0530 | [diff] [blame] | 58 | |
Zoe Liu | 6001fb0 | 2018-01-04 15:37:16 -0800 | [diff] [blame] | 59 | int rd_mode_is_ready; // Flag to indicate whether rd pick mode decision has |
| 60 | // been made. |
Fyodor Kyslov | b790c9c | 2021-01-12 15:33:36 -0800 | [diff] [blame] | 61 | #if CONFIG_AV1_TEMPORAL_DENOISING |
| 62 | int64_t newmv_sse; |
| 63 | int64_t zeromv_sse; |
| 64 | int64_t zeromv_lastref_sse; |
| 65 | PREDICTION_MODE best_sse_inter_mode; |
| 66 | int_mv best_sse_mv; |
| 67 | MV_REFERENCE_FRAME best_reference_frame; |
| 68 | MV_REFERENCE_FRAME best_zeromv_reference_frame; |
| 69 | int sb_skip_denoising; |
| 70 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 71 | } PICK_MODE_CONTEXT; |
| 72 | |
| 73 | typedef struct PC_TREE { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | PARTITION_TYPE partitioning; |
| 75 | BLOCK_SIZE block_size; |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 76 | PICK_MODE_CONTEXT *none; |
| 77 | PICK_MODE_CONTEXT *horizontal[2]; |
| 78 | PICK_MODE_CONTEXT *vertical[2]; |
Yunqing Wang | c9fc4fb | 2022-07-21 15:21:54 -0700 | [diff] [blame] | 79 | #if !CONFIG_REALTIME_ONLY |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 80 | PICK_MODE_CONTEXT *horizontala[3]; |
| 81 | PICK_MODE_CONTEXT *horizontalb[3]; |
| 82 | PICK_MODE_CONTEXT *verticala[3]; |
| 83 | PICK_MODE_CONTEXT *verticalb[3]; |
| 84 | PICK_MODE_CONTEXT *horizontal4[4]; |
| 85 | PICK_MODE_CONTEXT *vertical4[4]; |
Yunqing Wang | c9fc4fb | 2022-07-21 15:21:54 -0700 | [diff] [blame] | 86 | #endif |
Sebastien Alaiwan | 841c030 | 2017-12-13 09:32:59 +0100 | [diff] [blame] | 87 | struct PC_TREE *split[4]; |
Satish Kumar Suman | 69e9329 | 2018-11-28 16:05:33 +0530 | [diff] [blame] | 88 | int index; |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 89 | } PC_TREE; |
| 90 | |
| 91 | typedef struct SIMPLE_MOTION_DATA_TREE { |
| 92 | BLOCK_SIZE block_size; |
| 93 | PARTITION_TYPE partitioning; |
| 94 | struct SIMPLE_MOTION_DATA_TREE *split[4]; |
chiyotsai | 748f93b | 2019-03-21 17:52:44 -0700 | [diff] [blame] | 95 | |
| 96 | // Simple motion search_features |
chiyotsai | e46cff7 | 2020-02-05 15:03:34 -0800 | [diff] [blame] | 97 | FULLPEL_MV start_mvs[REF_FRAMES]; |
chiyotsai | 748f93b | 2019-03-21 17:52:44 -0700 | [diff] [blame] | 98 | unsigned int sms_none_feat[2]; |
chiyotsai | 748f93b | 2019-03-21 17:52:44 -0700 | [diff] [blame] | 99 | unsigned int sms_rect_feat[8]; |
| 100 | int sms_none_valid; |
chiyotsai | 748f93b | 2019-03-21 17:52:44 -0700 | [diff] [blame] | 101 | int sms_rect_valid; |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 102 | } SIMPLE_MOTION_DATA_TREE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 103 | |
Cherma Rajan A | b15d416 | 2021-08-17 11:34:13 +0530 | [diff] [blame] | 104 | void av1_setup_shared_coeff_buffer(const SequenceHeader *const seq_params, |
Cherma Rajan A | 04f3e64 | 2021-08-13 12:47:49 +0530 | [diff] [blame] | 105 | PC_TREE_SHARED_BUFFERS *shared_bufs, |
Cherma Rajan A | b15d416 | 2021-08-17 11:34:13 +0530 | [diff] [blame] | 106 | struct aom_internal_error_info *error); |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 107 | void av1_free_shared_coeff_buffer(PC_TREE_SHARED_BUFFERS *shared_bufs); |
| 108 | |
| 109 | PC_TREE *av1_alloc_pc_tree_node(BLOCK_SIZE bsize); |
| 110 | void av1_free_pc_tree_recursive(PC_TREE *tree, int num_planes, int keep_best, |
Neha Mary Thomas | 70d547d | 2023-03-03 02:52:45 +0530 | [diff] [blame] | 111 | int keep_none, |
| 112 | PARTITION_SEARCH_TYPE partition_search_type); |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 113 | |
Fyodor Kyslov | 6c1b9bd | 2021-02-08 19:37:30 -0800 | [diff] [blame] | 114 | PICK_MODE_CONTEXT *av1_alloc_pmc(const struct AV1_COMP *const cpi, |
| 115 | BLOCK_SIZE bsize, |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 116 | PC_TREE_SHARED_BUFFERS *shared_bufs); |
chiyotsai | 0f67511 | 2022-04-27 10:58:23 -0700 | [diff] [blame] | 117 | void av1_reset_pmc(PICK_MODE_CONTEXT *ctx); |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 118 | void av1_free_pmc(PICK_MODE_CONTEXT *ctx, int num_planes); |
Zoe Liu | 6001fb0 | 2018-01-04 15:37:16 -0800 | [diff] [blame] | 119 | void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx, |
Hui Su | f4b79c7 | 2018-03-22 13:14:36 -0700 | [diff] [blame] | 120 | PICK_MODE_CONTEXT *src_ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 121 | |
Cheng Chen | a92050a | 2021-06-09 22:34:37 -0700 | [diff] [blame] | 122 | static const BLOCK_SIZE square[MAX_SB_SIZE_LOG2 - 1] = { |
| 123 | BLOCK_4X4, BLOCK_8X8, BLOCK_16X16, BLOCK_32X32, BLOCK_64X64, BLOCK_128X128, |
| 124 | }; |
| 125 | |
| 126 | static AOM_INLINE int av1_get_pc_tree_nodes(const int is_sb_size_128, |
| 127 | int stat_generation_stage) { |
| 128 | const int tree_nodes_inc = is_sb_size_128 ? 1024 : 0; |
| 129 | const int tree_nodes = |
| 130 | stat_generation_stage ? 1 : (tree_nodes_inc + 256 + 64 + 16 + 4 + 1); |
| 131 | return tree_nodes; |
| 132 | } |
| 133 | |
Yue Chen | eb62898 | 2019-08-29 15:17:13 -0700 | [diff] [blame] | 134 | void av1_setup_sms_tree(struct AV1_COMP *const cpi, struct ThreadData *td); |
| 135 | void av1_free_sms_tree(struct ThreadData *td); |
| 136 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 137 | #ifdef __cplusplus |
| 138 | } // extern "C" |
| 139 | #endif |
| 140 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 141 | #endif // AOM_AV1_ENCODER_CONTEXT_TREE_H_ |