blob: c05f48a7af7140f47abd72fed241edc0e8fe268b [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
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_ENCODER_CONTEXT_TREE_H_
13#define AV1_ENCODER_CONTEXT_TREE_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "av1/common/blockd.h"
16#include "av1/encoder/block.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
Yaowu Xuf883b422016-08-30 14:01:10 -070022struct AV1_COMP;
23struct AV1Common;
Yaowu Xuc27fc142016-08-22 16:08:15 -070024struct ThreadData;
25
Jingning Han4489c262018-01-26 16:43:59 -080026typedef enum {
27 // Search all the partition types in this plane.
28 SEARCH_FULL_PLANE = 0,
29 // Only search none_partition coding block.
30 NONE_PARTITION_PLANE = 1,
31 // Search all the partition types in this plane except split.
32 SEARCH_SAME_PLANE = 2,
33 // Skip search partition on this plane. Go split directly.
34 SPLIT_PLANE = 3,
35} CB_TREE_SEARCH;
36
Yaowu Xuc27fc142016-08-22 16:08:15 -070037// Structure to hold snapshot of coding context during the mode picking process
38typedef struct {
Yue Chen53b53f02018-03-29 14:31:23 -070039 MB_MODE_INFO mic;
Yaowu Xuc27fc142016-08-22 16:08:15 -070040 MB_MODE_INFO_EXT mbmi_ext;
41 uint8_t *color_index_map[2];
Hui Suf4b79c72018-03-22 13:14:36 -070042 uint8_t *blk_skip;
Yaowu Xuc27fc142016-08-22 16:08:15 -070043
Brennan Shacklette0b5ae82016-11-07 17:25:20 -080044 tran_low_t *coeff[MAX_MB_PLANE];
45 tran_low_t *qcoeff[MAX_MB_PLANE];
46 tran_low_t *dqcoeff[MAX_MB_PLANE];
Brennan Shacklette0b5ae82016-11-07 17:25:20 -080047 uint16_t *eobs[MAX_MB_PLANE];
Angie Chiang74e23072017-03-24 14:54:23 -070048 uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
Yaowu Xuc27fc142016-08-22 16:08:15 -070049
Yaowu Xuc27fc142016-08-22 16:08:15 -070050 int num_4x4_blk;
51 int skip;
Yaowu Xuc27fc142016-08-22 16:08:15 -070052 // For current partition, only if all Y, U, and V transform blocks'
Yushin Cho7c6d2922017-05-03 17:35:06 -070053 // coefficients are quantized to 0, skippable is set to 1.
Yaowu Xuc27fc142016-08-22 16:08:15 -070054 int skippable;
55 int best_mode_index;
56 int hybrid_pred_diff;
57 int comp_pred_diff;
58 int single_pred_diff;
59
60 // TODO(jingning) Use RD_COST struct here instead. This involves a boarder
61 // scope of refactoring.
62 int rate;
63 int64_t dist;
Zoe Liu6001fb02018-01-04 15:37:16 -080064 int64_t rdcost;
65 int rd_mode_is_ready; // Flag to indicate whether rd pick mode decision has
66 // been made.
Yaowu Xuc27fc142016-08-22 16:08:15 -070067
68 // motion vector cache for adaptive motion search control in partition
69 // search loop
Zoe Liu27deb382018-03-27 15:13:56 -070070 MV pred_mv[REF_FRAMES];
James Zern7b9407a2016-05-18 23:48:05 -070071 InterpFilter pred_interp_filter;
Yaowu Xuc27fc142016-08-22 16:08:15 -070072 PARTITION_TYPE partition;
Yaowu Xuc27fc142016-08-22 16:08:15 -070073} PICK_MODE_CONTEXT;
74
Hui Su6f6091d2018-05-16 11:05:34 -070075typedef struct {
76 int valid;
77 int split;
78 int skip;
79 int64_t rdcost;
80 int sub_block_split[4];
81 int sub_block_skip[4];
82 int64_t sub_block_rdcost[4];
83} PC_TREE_STATS;
84
Yaowu Xuc27fc142016-08-22 16:08:15 -070085typedef struct PC_TREE {
86 int index;
87 PARTITION_TYPE partitioning;
88 BLOCK_SIZE block_size;
89 PICK_MODE_CONTEXT none;
90 PICK_MODE_CONTEXT horizontal[2];
91 PICK_MODE_CONTEXT vertical[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -070092 PICK_MODE_CONTEXT horizontala[3];
93 PICK_MODE_CONTEXT horizontalb[3];
94 PICK_MODE_CONTEXT verticala[3];
95 PICK_MODE_CONTEXT verticalb[3];
Rupert Swarbrick93c39e92017-07-12 11:11:02 +010096 PICK_MODE_CONTEXT horizontal4[4];
97 PICK_MODE_CONTEXT vertical4[4];
Jingning Han4489c262018-01-26 16:43:59 -080098 CB_TREE_SEARCH cb_search_range;
Sebastien Alaiwan841c0302017-12-13 09:32:59 +010099 struct PC_TREE *split[4];
Hui Su6f6091d2018-05-16 11:05:34 -0700100 PC_TREE_STATS pc_tree_stats;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700101} PC_TREE;
102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103void av1_setup_pc_tree(struct AV1Common *cm, struct ThreadData *td);
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000104void av1_free_pc_tree(struct ThreadData *td, const int num_planes);
Zoe Liu6001fb02018-01-04 15:37:16 -0800105void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx,
Hui Suf4b79c72018-03-22 13:14:36 -0700106 PICK_MODE_CONTEXT *src_ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700107
108#ifdef __cplusplus
109} // extern "C"
110#endif
111
Yaowu Xuf883b422016-08-30 14:01:10 -0700112#endif /* AV1_ENCODER_CONTEXT_TREE_H_ */