1 /* 2 * Copyright (c) 2020, Alliance for Open Media. All rights reserved 3 * 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. 10 */ 11 12 #ifndef AOM_AV1_ENCODER_INTERP_FILTER_SEARCH_H_ 13 #define AOM_AV1_ENCODER_INTERP_FILTER_SEARCH_H_ 14 15 #include "av1/encoder/block.h" 16 #include "av1/encoder/encoder.h" 17 #include "av1/encoder/rdopt_utils.h" 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /*!\cond */ 24 #define MAX_INTERP_FILTER_STATS 128 25 #define DUAL_FILTER_SET_SIZE (SWITCHABLE_FILTERS * SWITCHABLE_FILTERS) 26 27 typedef struct { 28 int_interpfilters filters; 29 int_mv mv[2]; 30 int8_t ref_frames[2]; 31 COMPOUND_TYPE comp_type; 32 int compound_idx; 33 int64_t rd; 34 unsigned int pred_sse; 35 } INTERPOLATION_FILTER_STATS; 36 /*!\endcond */ 37 38 /*!\brief Miscellaneous arguments for inter mode search. 39 */ 40 typedef struct HandleInterModeArgs { 41 /*! 42 * Buffer for the above predictor in OBMC 43 */ 44 uint8_t *above_pred_buf[MAX_MB_PLANE]; 45 /*! 46 * Stride for the above predictor in OBMC 47 */ 48 int above_pred_stride[MAX_MB_PLANE]; 49 /*! 50 * Buffer for the left predictor in OBMC 51 */ 52 uint8_t *left_pred_buf[MAX_MB_PLANE]; 53 /*! 54 * Stride for the left predictor in OBMC 55 */ 56 int left_pred_stride[MAX_MB_PLANE]; 57 /*! 58 * Pointer to the first member in a 2D array which holds 59 * single reference mode motion vectors to be used as a starting 60 * point in the mv search for compound modes. Each array is length REF_FRAMES, 61 * meaning there is a slot for a single reference motion vector for 62 * each possible reference frame. The 2D array consists of N of these arrays, 63 * where N is the length of the reference mv stack computed for the single 64 * reference case for that particular reference frame. 65 */ 66 int_mv (*single_newmv)[REF_FRAMES]; 67 /*! 68 * Pointer to the first array of a 2D array with the same setup as 69 * single_newmv array above. This is a 2D array to hold the rate 70 * corresponding to each of the single reference mode motion vectors 71 * held in single_newmv. 72 */ 73 int (*single_newmv_rate)[REF_FRAMES]; 74 /*! 75 * Pointer to the first array of a 2D array with the same setup as 76 * single_newmv array above. This is a 2D array to hold a 0 or 1 77 * validity value corresponding to each of the single reference mode motion 78 * vectors held in single_newmv. 79 */ 80 int (*single_newmv_valid)[REF_FRAMES]; 81 /*! 82 * Pointer to the first array in a 3D array of predicted rate-distortion. 83 * The dimensions of this structure are: 84 * (number of possible inter modes) X 85 * (number of reference MVs) X 86 * (number of reference frames). 87 */ 88 int64_t (*modelled_rd)[MAX_REF_MV_SEARCH][REF_FRAMES]; 89 /*! 90 * Holds an estimated entropy cost for picking the current reference frame. 91 * This is used to compute an rd estimate. 92 */ 93 int ref_frame_cost; 94 /*! 95 * Holds an estimated entropy cost for picking single or compound 96 * reference. This is used to compute an rd estimate. 97 */ 98 int single_comp_cost; 99 /*! 100 * Pointer to the first element in a 3D array holding rd's of 101 * SIMPLE_TRANSLATION used to prune out the motion mode search in single ref 102 * modes used to determine compound ref modes. The full structure is: 103 * (number of inter modes) X (length of refmv list) X (number of ref frames) 104 */ 105 int64_t (*simple_rd)[MAX_REF_MV_SEARCH][REF_FRAMES]; 106 /*! 107 * An integer value 0 or 1 which indicates whether or not to skip the motion 108 * mode search and default to SIMPLE_TRANSLATION as a speed feature. 109 */ 110 int skip_motion_mode; 111 /*! 112 * A pointer to the first element in an array of INTERINTRA_MODE types. This 113 * contains the best inter_intra mode for each reference frame. 114 */ 115 INTERINTRA_MODE *inter_intra_mode; 116 /*! 117 * Array of saved interpolation filter stats collected to avoid repeating 118 * an interpolation filter search when the mv and ref_frame are the same 119 * as a previous search. 120 */ 121 INTERPOLATION_FILTER_STATS interp_filter_stats[MAX_INTERP_FILTER_STATS]; 122 123 /*! 124 * Stack to store full pixel search start mv of NEWMV mode. 125 */ 126 FULLPEL_MV start_mv_stack[(MAX_REF_MV_SEARCH - 1) * 2]; 127 128 /*! 129 * Count of mvs in start mv stack. 130 */ 131 int start_mv_cnt; 132 133 /*! 134 * Index of the last set of saved stats in the interp_filter_stats array. 135 */ 136 int interp_filter_stats_idx; 137 /*! 138 * Estimated wedge index. 139 */ 140 int wedge_index; 141 /*! 142 * Estimated wedge sign. 143 */ 144 int wedge_sign; 145 /*! 146 * Estimated diff wtd index. 147 */ 148 int diffwtd_index; 149 /*! 150 * Estimated cmp mode. 151 */ 152 int cmp_mode[MODE_CTX_REF_FRAMES]; 153 /*! 154 * The best sse during single new_mv search. Note that the sse here comes from 155 * single_motion_search, and not from interpolation_filter_search. This has 156 * two implications: 157 * 1. The mv used to calculate the sse here does not have to be the best sse 158 * found in handle_inter_mode. 159 * 2. Even if the mvs agree, the sse here can differ from the sse in \ref 160 * MACROBLOCK::pred_sse due to different interpolation filter used. 161 */ 162 unsigned int best_single_sse_in_refs[REF_FRAMES]; 163 /*! 164 * Holds the sse of best mode so far in the mode evaluation process. This is 165 * used in intermediate termination of NEWMV mode evaluation. 166 */ 167 unsigned int best_pred_sse; 168 } HandleInterModeArgs; 169 170 /*!\cond */ 171 static const int_interpfilters filter_sets[DUAL_FILTER_SET_SIZE] = { 172 { 0x00000000 }, { 0x00010000 }, { 0x00020000 }, // y = 0 173 { 0x00000001 }, { 0x00010001 }, { 0x00020001 }, // y = 1 174 { 0x00000002 }, { 0x00010002 }, { 0x00020002 }, // y = 2 175 }; 176 177 int av1_find_interp_filter_match( 178 MB_MODE_INFO *const mbmi, const AV1_COMP *const cpi, 179 const InterpFilter assign_filter, const int need_search, 180 INTERPOLATION_FILTER_STATS *interp_filter_stats, 181 int interp_filter_stats_idx); 182 183 int64_t av1_interpolation_filter_search( 184 MACROBLOCK *const x, const AV1_COMP *const cpi, 185 const TileDataEnc *tile_data, BLOCK_SIZE bsize, 186 const BUFFER_SET *const tmp_dst, const BUFFER_SET *const orig_dst, 187 int64_t *const rd, int *const switchable_rate, int *skip_build_pred, 188 HandleInterModeArgs *args, int64_t ref_best_rd); 189 190 /*!\endcond */ 191 #ifdef __cplusplus 192 } // extern "C" 193 #endif 194 195 #endif // AOM_AV1_ENCODER_INTERP_FILTER_SEARCH_H_ 196