blob: 78f20764dfa4d6755e75de1f50dc04786fd3c690 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AV1_ENCODER_CONTEXT_TREE_H_
13#define AOM_AV1_ENCODER_CONTEXT_TREE_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
chiyotsai03c48a82019-10-18 16:48:59 -070015#include "config/aom_config.h"
16
Yaowu Xuc27fc142016-08-22 16:08:15 -070017#include "av1/common/blockd.h"
18#include "av1/encoder/block.h"
Neha Mary Thomas70d547d2023-03-03 02:52:45 +053019#include "av1/encoder/speed_features.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070020
21#ifdef __cplusplus
22extern "C" {
23#endif
24
Mufaddal Chakera8c2d5172021-06-09 01:33:48 +053025struct AV1_PRIMARY;
Yaowu Xuf883b422016-08-30 14:01:10 -070026struct AV1_COMP;
27struct AV1Common;
Yaowu Xuc27fc142016-08-22 16:08:15 -070028struct ThreadData;
29
Yue Cheneb628982019-08-29 15:17:13 -070030typedef 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 Xuc27fc142016-08-22 16:08:15 -070036// Structure to hold snapshot of coding context during the mode picking process
chiyotsaic9b9fa52020-06-12 15:19:50 -070037typedef struct PICK_MODE_CONTEXT {
Yue Chen53b53f02018-03-29 14:31:23 -070038 MB_MODE_INFO mic;
Ravi Chaudharye1a59ce2020-03-24 08:21:18 +053039 MB_MODE_INFO_EXT_FRAME mbmi_ext_best;
Yaowu Xuc27fc142016-08-22 16:08:15 -070040 uint8_t *color_index_map[2];
Hui Suf4b79c72018-03-22 13:14:36 -070041 uint8_t *blk_skip;
Yaowu Xuc27fc142016-08-22 16:08:15 -070042
Brennan Shacklette0b5ae82016-11-07 17:25:20 -080043 tran_low_t *coeff[MAX_MB_PLANE];
44 tran_low_t *qcoeff[MAX_MB_PLANE];
45 tran_low_t *dqcoeff[MAX_MB_PLANE];
Brennan Shacklette0b5ae82016-11-07 17:25:20 -080046 uint16_t *eobs[MAX_MB_PLANE];
Angie Chiang74e23072017-03-24 14:54:23 -070047 uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
Hui Su52b7ddc2019-10-10 16:27:16 -070048 uint8_t *tx_type_map;
Yaowu Xuc27fc142016-08-22 16:08:15 -070049
Yaowu Xuc27fc142016-08-22 16:08:15 -070050 int num_4x4_blk;
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 // For current partition, only if all Y, U, and V transform blocks'
Yushin Cho7c6d2922017-05-03 17:35:06 -070052 // coefficients are quantized to 0, skippable is set to 1.
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 int skippable;
chiyotsai03c48a82019-10-18 16:48:59 -070054#if CONFIG_INTERNAL_STATS
chiyotsai2b471a32019-10-18 16:31:24 -070055 THR_MODES best_mode_index;
chiyotsai03c48a82019-10-18 16:48:59 -070056#endif // CONFIG_INTERNAL_STATS
Hui Sucff74442019-04-08 11:54:47 -070057 RD_STATS rd_stats;
Satish Kumar Suman69e93292018-11-28 16:05:33 +053058
Zoe Liu6001fb02018-01-04 15:37:16 -080059 int rd_mode_is_ready; // Flag to indicate whether rd pick mode decision has
60 // been made.
Fyodor Kyslovb790c9c2021-01-12 15:33:36 -080061#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 Xuc27fc142016-08-22 16:08:15 -070071} PICK_MODE_CONTEXT;
72
73typedef struct PC_TREE {
Yaowu Xuc27fc142016-08-22 16:08:15 -070074 PARTITION_TYPE partitioning;
75 BLOCK_SIZE block_size;
Yue Cheneb628982019-08-29 15:17:13 -070076 PICK_MODE_CONTEXT *none;
77 PICK_MODE_CONTEXT *horizontal[2];
78 PICK_MODE_CONTEXT *vertical[2];
Yunqing Wangc9fc4fb2022-07-21 15:21:54 -070079#if !CONFIG_REALTIME_ONLY
Yue Cheneb628982019-08-29 15:17:13 -070080 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 Wangc9fc4fb2022-07-21 15:21:54 -070086#endif
Sebastien Alaiwan841c0302017-12-13 09:32:59 +010087 struct PC_TREE *split[4];
Satish Kumar Suman69e93292018-11-28 16:05:33 +053088 int index;
Yue Cheneb628982019-08-29 15:17:13 -070089} PC_TREE;
90
91typedef struct SIMPLE_MOTION_DATA_TREE {
92 BLOCK_SIZE block_size;
93 PARTITION_TYPE partitioning;
94 struct SIMPLE_MOTION_DATA_TREE *split[4];
chiyotsai748f93b2019-03-21 17:52:44 -070095
96 // Simple motion search_features
chiyotsaie46cff72020-02-05 15:03:34 -080097 FULLPEL_MV start_mvs[REF_FRAMES];
chiyotsai748f93b2019-03-21 17:52:44 -070098 unsigned int sms_none_feat[2];
chiyotsai748f93b2019-03-21 17:52:44 -070099 unsigned int sms_rect_feat[8];
100 int sms_none_valid;
chiyotsai748f93b2019-03-21 17:52:44 -0700101 int sms_rect_valid;
Yue Cheneb628982019-08-29 15:17:13 -0700102} SIMPLE_MOTION_DATA_TREE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103
Cherma Rajan Ab15d4162021-08-17 11:34:13 +0530104void av1_setup_shared_coeff_buffer(const SequenceHeader *const seq_params,
Cherma Rajan A04f3e642021-08-13 12:47:49 +0530105 PC_TREE_SHARED_BUFFERS *shared_bufs,
Cherma Rajan Ab15d4162021-08-17 11:34:13 +0530106 struct aom_internal_error_info *error);
Yue Cheneb628982019-08-29 15:17:13 -0700107void av1_free_shared_coeff_buffer(PC_TREE_SHARED_BUFFERS *shared_bufs);
108
109PC_TREE *av1_alloc_pc_tree_node(BLOCK_SIZE bsize);
110void av1_free_pc_tree_recursive(PC_TREE *tree, int num_planes, int keep_best,
Neha Mary Thomas70d547d2023-03-03 02:52:45 +0530111 int keep_none,
112 PARTITION_SEARCH_TYPE partition_search_type);
Yue Cheneb628982019-08-29 15:17:13 -0700113
Fyodor Kyslov6c1b9bd2021-02-08 19:37:30 -0800114PICK_MODE_CONTEXT *av1_alloc_pmc(const struct AV1_COMP *const cpi,
115 BLOCK_SIZE bsize,
Yue Cheneb628982019-08-29 15:17:13 -0700116 PC_TREE_SHARED_BUFFERS *shared_bufs);
chiyotsai0f675112022-04-27 10:58:23 -0700117void av1_reset_pmc(PICK_MODE_CONTEXT *ctx);
Yue Cheneb628982019-08-29 15:17:13 -0700118void av1_free_pmc(PICK_MODE_CONTEXT *ctx, int num_planes);
Zoe Liu6001fb02018-01-04 15:37:16 -0800119void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx,
Hui Suf4b79c72018-03-22 13:14:36 -0700120 PICK_MODE_CONTEXT *src_ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700121
Cheng Chena92050a2021-06-09 22:34:37 -0700122static const BLOCK_SIZE square[MAX_SB_SIZE_LOG2 - 1] = {
123 BLOCK_4X4, BLOCK_8X8, BLOCK_16X16, BLOCK_32X32, BLOCK_64X64, BLOCK_128X128,
124};
125
126static 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 Cheneb628982019-08-29 15:17:13 -0700134void av1_setup_sms_tree(struct AV1_COMP *const cpi, struct ThreadData *td);
135void av1_free_sms_tree(struct ThreadData *td);
136
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137#ifdef __cplusplus
138} // extern "C"
139#endif
140
James Zerne1cbb132018-08-22 14:10:36 -0700141#endif // AOM_AV1_ENCODER_CONTEXT_TREE_H_