/src/aom/av1/encoder/pickcdef.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016, 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 | | #ifndef AOM_AV1_ENCODER_PICKCDEF_H_ |
12 | | #define AOM_AV1_ENCODER_PICKCDEF_H_ |
13 | | |
14 | | #include "av1/common/cdef.h" |
15 | | #include "av1/encoder/speed_features.h" |
16 | | |
17 | | #ifdef __cplusplus |
18 | | extern "C" { |
19 | | #endif |
20 | | |
21 | | /*!\enum CDEF_CONTROL |
22 | | * \brief This enum controls to which frames CDEF is applied. |
23 | | */ |
24 | | typedef enum { |
25 | | CDEF_NONE = 0, /*!< Disable CDEF on all frames. */ |
26 | | CDEF_ALL = 1, /*!< Enable CDEF for all frames. */ |
27 | | CDEF_REFERENCE = 2, /*!< Disable CDEF on non reference frames. */ |
28 | | } CDEF_CONTROL; |
29 | | |
30 | | /*!\cond */ |
31 | | struct MultiThreadInfo; |
32 | | |
33 | | #define REDUCED_PRI_STRENGTHS_LVL1 8 |
34 | | #define REDUCED_PRI_STRENGTHS_LVL2 5 |
35 | 0 | #define REDUCED_SEC_STRENGTHS_LVL3 2 |
36 | 0 | #define REDUCED_SEC_STRENGTHS_LVL5 1 |
37 | | #define REDUCED_PRI_STRENGTHS_LVL4 2 |
38 | | |
39 | | #define REDUCED_TOTAL_STRENGTHS_LVL1 \ |
40 | | (REDUCED_PRI_STRENGTHS_LVL1 * CDEF_SEC_STRENGTHS) |
41 | | #define REDUCED_TOTAL_STRENGTHS_LVL2 \ |
42 | | (REDUCED_PRI_STRENGTHS_LVL2 * CDEF_SEC_STRENGTHS) |
43 | | #define REDUCED_TOTAL_STRENGTHS_LVL3 \ |
44 | | (REDUCED_PRI_STRENGTHS_LVL2 * REDUCED_SEC_STRENGTHS_LVL3) |
45 | | #define REDUCED_TOTAL_STRENGTHS_LVL4 \ |
46 | | (REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL3) |
47 | | #define REDUCED_TOTAL_STRENGTHS_LVL5 \ |
48 | | (REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL5) |
49 | | #define TOTAL_STRENGTHS (CDEF_PRI_STRENGTHS * CDEF_SEC_STRENGTHS) |
50 | | |
51 | | static const int priconv_lvl1[REDUCED_PRI_STRENGTHS_LVL1] = { 0, 1, 2, 3, |
52 | | 5, 7, 10, 13 }; |
53 | | static const int priconv_lvl2[REDUCED_PRI_STRENGTHS_LVL2] = { 0, 2, 4, 8, 14 }; |
54 | | static const int priconv_lvl4[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 11 }; |
55 | | static const int priconv_lvl5[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 5 }; |
56 | | static const int secconv_lvl3[REDUCED_SEC_STRENGTHS_LVL3] = { 0, 2 }; |
57 | | static const int secconv_lvl5[REDUCED_SEC_STRENGTHS_LVL5] = { 0 }; |
58 | | static const int nb_cdef_strengths[CDEF_PICK_METHODS] = { |
59 | | TOTAL_STRENGTHS, |
60 | | REDUCED_TOTAL_STRENGTHS_LVL1, |
61 | | REDUCED_TOTAL_STRENGTHS_LVL2, |
62 | | REDUCED_TOTAL_STRENGTHS_LVL3, |
63 | | REDUCED_TOTAL_STRENGTHS_LVL4, |
64 | | REDUCED_TOTAL_STRENGTHS_LVL5, |
65 | | TOTAL_STRENGTHS |
66 | | }; |
67 | | |
68 | | typedef void (*copy_fn_t)(uint16_t *dst, int dstride, const void *src, |
69 | | int src_voffset, int src_hoffset, int sstride, |
70 | | int vsize, int hsize); |
71 | | typedef uint64_t (*compute_cdef_dist_t)(void *dst, int dstride, uint16_t *src, |
72 | | cdef_list *dlist, int cdef_count, |
73 | | BLOCK_SIZE bsize, int coeff_shift, |
74 | | int row, int col); |
75 | | |
76 | | /*! \brief CDEF search context. |
77 | | */ |
78 | | typedef struct { |
79 | | /*! |
80 | | * Pointer to the frame buffer holding the source frame |
81 | | */ |
82 | | const YV12_BUFFER_CONFIG *ref; |
83 | | /*! |
84 | | * Pointer to params related to MB_MODE_INFO arrays and related info |
85 | | */ |
86 | | CommonModeInfoParams *mi_params; |
87 | | /*! |
88 | | * Info specific to each plane |
89 | | */ |
90 | | struct macroblockd_plane plane[MAX_MB_PLANE]; |
91 | | /*! |
92 | | * Function pointer of copy_fn |
93 | | */ |
94 | | copy_fn_t copy_fn; |
95 | | /*! |
96 | | * Function pointer of compute_cdef_dist_fn |
97 | | */ |
98 | | compute_cdef_dist_t compute_cdef_dist_fn; |
99 | | /*! |
100 | | * Number of strenghts evaluated in CDEF filter search |
101 | | */ |
102 | | int total_strengths; |
103 | | /*! |
104 | | * Bit-depth dependent shift |
105 | | */ |
106 | | int coeff_shift; |
107 | | /*! |
108 | | * CDEF damping factor |
109 | | */ |
110 | | int damping; |
111 | | /*! |
112 | | * Search method used to select CDEF parameters |
113 | | */ |
114 | | int pick_method; |
115 | | /*! |
116 | | * Number of planes |
117 | | */ |
118 | | int num_planes; |
119 | | /*! |
120 | | * Log2 of width of the MI unit in pixels. mi_wide_l2[i] |
121 | | * indicates the width of the MI unit in pixels for the ith plane |
122 | | */ |
123 | | int mi_wide_l2[MAX_MB_PLANE]; |
124 | | /*! |
125 | | * Log2 of height of the MI unit in pixels. mi_high_l2[i] |
126 | | * indicates the height of the MI unit in pixels for the ith plane |
127 | | */ |
128 | | int mi_high_l2[MAX_MB_PLANE]; |
129 | | /*! |
130 | | * Subsampling in x direction. xdec[i] indicates the subsampling |
131 | | * for the ith plane |
132 | | */ |
133 | | int xdec[MAX_MB_PLANE]; |
134 | | /*! |
135 | | * Subsampling in y direction. ydec[i] indicates the subsampling |
136 | | * for the ith plane |
137 | | */ |
138 | | int ydec[MAX_MB_PLANE]; |
139 | | /*! |
140 | | * bsize[i] indicates the block size of ith plane |
141 | | */ |
142 | | int bsize[MAX_MB_PLANE]; |
143 | | /*! |
144 | | * Number of 64x64 blocks in vertical direction of a frame |
145 | | */ |
146 | | int nvfb; |
147 | | /*! |
148 | | * Number of 64x64 blocks in horizontal direction of a frame |
149 | | */ |
150 | | int nhfb; |
151 | | /*! |
152 | | * Pointer to the mean squared error between the CDEF filtered block and the |
153 | | * source block. mse[i][j][k] stores the MSE of the ith plane (i=0 corresponds |
154 | | * to Y-plane, i=1 corresponds to U and V planes), jth block and kth strength |
155 | | * index |
156 | | */ |
157 | | uint64_t (*mse[2])[TOTAL_STRENGTHS]; |
158 | | /*! |
159 | | * Holds the position (in units of mi's) of the cdef filtered |
160 | | * block in raster scan order |
161 | | */ |
162 | | int *sb_index; |
163 | | /*! |
164 | | * Holds the count of cdef filtered blocks |
165 | | */ |
166 | | int sb_count; |
167 | | } CdefSearchCtx; |
168 | | |
169 | | static INLINE int sb_all_skip(const CommonModeInfoParams *const mi_params, |
170 | 0 | int mi_row, int mi_col) { |
171 | 0 | const int maxr = AOMMIN(mi_params->mi_rows - mi_row, MI_SIZE_64X64); |
172 | 0 | const int maxc = AOMMIN(mi_params->mi_cols - mi_col, MI_SIZE_64X64); |
173 | 0 | const int stride = mi_params->mi_stride; |
174 | 0 | MB_MODE_INFO **mbmi = mi_params->mi_grid_base + mi_row * stride + mi_col; |
175 | 0 | for (int r = 0; r < maxr; ++r, mbmi += stride) { |
176 | 0 | for (int c = 0; c < maxc; ++c) { |
177 | 0 | if (!mbmi[c]->skip_txfm) return 0; |
178 | 0 | } |
179 | 0 | } |
180 | 0 | return 1; |
181 | 0 | } Unexecuted instantiation: av1_cx_iface.c:sb_all_skip Unexecuted instantiation: av1_quantize.c:sb_all_skip Unexecuted instantiation: bitstream.c:sb_all_skip Unexecuted instantiation: encodemv.c:sb_all_skip Unexecuted instantiation: encoder.c:sb_all_skip Unexecuted instantiation: encoder_utils.c:sb_all_skip Unexecuted instantiation: encodetxb.c:sb_all_skip Unexecuted instantiation: ethread.c:sb_all_skip Unexecuted instantiation: firstpass.c:sb_all_skip Unexecuted instantiation: global_motion_facade.c:sb_all_skip Unexecuted instantiation: level.c:sb_all_skip Unexecuted instantiation: lookahead.c:sb_all_skip Unexecuted instantiation: mcomp.c:sb_all_skip Unexecuted instantiation: mv_prec.c:sb_all_skip Unexecuted instantiation: palette.c:sb_all_skip Unexecuted instantiation: pass2_strategy.c:sb_all_skip Unexecuted instantiation: pickcdef.c:sb_all_skip Unexecuted instantiation: picklpf.c:sb_all_skip Unexecuted instantiation: pickrst.c:sb_all_skip Unexecuted instantiation: ratectrl.c:sb_all_skip Unexecuted instantiation: rd.c:sb_all_skip Unexecuted instantiation: rdopt.c:sb_all_skip Unexecuted instantiation: segmentation.c:sb_all_skip Unexecuted instantiation: speed_features.c:sb_all_skip Unexecuted instantiation: superres_scale.c:sb_all_skip Unexecuted instantiation: svc_layercontext.c:sb_all_skip Unexecuted instantiation: temporal_filter.c:sb_all_skip Unexecuted instantiation: thirdpass.c:sb_all_skip Unexecuted instantiation: tokenize.c:sb_all_skip Unexecuted instantiation: tpl_model.c:sb_all_skip Unexecuted instantiation: tx_search.c:sb_all_skip Unexecuted instantiation: txb_rdopt.c:sb_all_skip Unexecuted instantiation: intra_mode_search.c:sb_all_skip Unexecuted instantiation: var_based_part.c:sb_all_skip Unexecuted instantiation: av1_noise_estimate.c:sb_all_skip Unexecuted instantiation: aq_complexity.c:sb_all_skip Unexecuted instantiation: aq_cyclicrefresh.c:sb_all_skip Unexecuted instantiation: aq_variance.c:sb_all_skip Unexecuted instantiation: allintra_vis.c:sb_all_skip Unexecuted instantiation: compound_type.c:sb_all_skip Unexecuted instantiation: context_tree.c:sb_all_skip Unexecuted instantiation: encodeframe.c:sb_all_skip Unexecuted instantiation: encodeframe_utils.c:sb_all_skip Unexecuted instantiation: encodemb.c:sb_all_skip Unexecuted instantiation: encode_strategy.c:sb_all_skip Unexecuted instantiation: global_motion.c:sb_all_skip Unexecuted instantiation: gop_structure.c:sb_all_skip Unexecuted instantiation: interp_search.c:sb_all_skip Unexecuted instantiation: motion_search_facade.c:sb_all_skip Unexecuted instantiation: partition_search.c:sb_all_skip Unexecuted instantiation: partition_strategy.c:sb_all_skip Unexecuted instantiation: nonrd_pickmode.c:sb_all_skip |
182 | | |
183 | | // Checks if cdef processing can be skipped for particular sb. |
184 | | // Inputs: |
185 | | // cdef_search_ctx: Pointer to the structure containing parameters related to |
186 | | // CDEF search context. |
187 | | // fbr: Row index in units of 64x64 block |
188 | | // fbc: Column index in units of 64x64 block |
189 | | // Returns: |
190 | | // 1/0 will be returned to indicate skip/don't skip cdef processing of sb |
191 | | // respectively. |
192 | | static INLINE int cdef_sb_skip(const CommonModeInfoParams *const mi_params, |
193 | 0 | int fbr, int fbc) { |
194 | 0 | const MB_MODE_INFO *const mbmi = |
195 | 0 | mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride + |
196 | 0 | MI_SIZE_64X64 * fbc]; |
197 | | // No filtering if the entire filter block is skipped. |
198 | 0 | if (sb_all_skip(mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64)) |
199 | 0 | return 1; |
200 | | // Skip odd numbered 64x64 block rows(cols) when bsize is BLOCK_128X128, |
201 | | // BLOCK_64X128(BLOCK_128X128, BLOCK_128X64) as for such blocks CDEF filtering |
202 | | // is done at the corresponding block sizes. |
203 | 0 | if (((fbc & 1) && |
204 | 0 | (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_128X64)) || |
205 | 0 | ((fbr & 1) && |
206 | 0 | (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_64X128))) |
207 | 0 | return 1; |
208 | 0 | return 0; |
209 | 0 | } Unexecuted instantiation: av1_cx_iface.c:cdef_sb_skip Unexecuted instantiation: av1_quantize.c:cdef_sb_skip Unexecuted instantiation: bitstream.c:cdef_sb_skip Unexecuted instantiation: encodemv.c:cdef_sb_skip Unexecuted instantiation: encoder.c:cdef_sb_skip Unexecuted instantiation: encoder_utils.c:cdef_sb_skip Unexecuted instantiation: encodetxb.c:cdef_sb_skip Unexecuted instantiation: ethread.c:cdef_sb_skip Unexecuted instantiation: firstpass.c:cdef_sb_skip Unexecuted instantiation: global_motion_facade.c:cdef_sb_skip Unexecuted instantiation: level.c:cdef_sb_skip Unexecuted instantiation: lookahead.c:cdef_sb_skip Unexecuted instantiation: mcomp.c:cdef_sb_skip Unexecuted instantiation: mv_prec.c:cdef_sb_skip Unexecuted instantiation: palette.c:cdef_sb_skip Unexecuted instantiation: pass2_strategy.c:cdef_sb_skip Unexecuted instantiation: pickcdef.c:cdef_sb_skip Unexecuted instantiation: picklpf.c:cdef_sb_skip Unexecuted instantiation: pickrst.c:cdef_sb_skip Unexecuted instantiation: ratectrl.c:cdef_sb_skip Unexecuted instantiation: rd.c:cdef_sb_skip Unexecuted instantiation: rdopt.c:cdef_sb_skip Unexecuted instantiation: segmentation.c:cdef_sb_skip Unexecuted instantiation: speed_features.c:cdef_sb_skip Unexecuted instantiation: superres_scale.c:cdef_sb_skip Unexecuted instantiation: svc_layercontext.c:cdef_sb_skip Unexecuted instantiation: temporal_filter.c:cdef_sb_skip Unexecuted instantiation: thirdpass.c:cdef_sb_skip Unexecuted instantiation: tokenize.c:cdef_sb_skip Unexecuted instantiation: tpl_model.c:cdef_sb_skip Unexecuted instantiation: tx_search.c:cdef_sb_skip Unexecuted instantiation: txb_rdopt.c:cdef_sb_skip Unexecuted instantiation: intra_mode_search.c:cdef_sb_skip Unexecuted instantiation: var_based_part.c:cdef_sb_skip Unexecuted instantiation: av1_noise_estimate.c:cdef_sb_skip Unexecuted instantiation: aq_complexity.c:cdef_sb_skip Unexecuted instantiation: aq_cyclicrefresh.c:cdef_sb_skip Unexecuted instantiation: aq_variance.c:cdef_sb_skip Unexecuted instantiation: allintra_vis.c:cdef_sb_skip Unexecuted instantiation: compound_type.c:cdef_sb_skip Unexecuted instantiation: context_tree.c:cdef_sb_skip Unexecuted instantiation: encodeframe.c:cdef_sb_skip Unexecuted instantiation: encodeframe_utils.c:cdef_sb_skip Unexecuted instantiation: encodemb.c:cdef_sb_skip Unexecuted instantiation: encode_strategy.c:cdef_sb_skip Unexecuted instantiation: global_motion.c:cdef_sb_skip Unexecuted instantiation: gop_structure.c:cdef_sb_skip Unexecuted instantiation: interp_search.c:cdef_sb_skip Unexecuted instantiation: motion_search_facade.c:cdef_sb_skip Unexecuted instantiation: partition_search.c:cdef_sb_skip Unexecuted instantiation: partition_strategy.c:cdef_sb_skip Unexecuted instantiation: nonrd_pickmode.c:cdef_sb_skip |
210 | | |
211 | | void av1_cdef_mse_calc_block(CdefSearchCtx *cdef_search_ctx, int fbr, int fbc, |
212 | | int sb_count); |
213 | | /*!\endcond */ |
214 | | |
215 | | /*!\brief AV1 CDEF parameter search |
216 | | * |
217 | | * \ingroup in_loop_cdef |
218 | | * |
219 | | * Searches for optimal CDEF parameters for frame |
220 | | * |
221 | | * \param[in] mt_info Pointer to multi-threading parameters |
222 | | * \param[in] frame Compressed frame buffer |
223 | | * \param[in] ref Source frame buffer |
224 | | * \param[in,out] cm Pointer to top level common structure |
225 | | * \param[in] xd Pointer to common current coding block structure |
226 | | * \param[in] pick_method The method used to select params |
227 | | * \param[in] rdmult rd multiplier to use in making param choices |
228 | | * \param[in] skip_cdef_feature Speed feature to skip cdef |
229 | | * \param[in] frames_since_key Number of frames since key frame |
230 | | * \param[in] cdef_control Parameter that controls CDEF application |
231 | | * \param[in] non_reference_frame Indicates if current frame is |
232 | | * non-reference |
233 | | * |
234 | | * \return Nothing is returned. Instead, optimal CDEF parameters are stored |
235 | | * in the \c cdef_info structure of type \ref CdefInfo inside \c cm: |
236 | | * \arg \c cdef_bits: Bits of strength parameters |
237 | | * \arg \c nb_cdef_strengths: Number of strength parameters |
238 | | * \arg \c cdef_strengths: list of \c nb_cdef_strengths strength parameters |
239 | | * for the luma plane. |
240 | | * \arg \c uv_cdef_strengths: list of \c nb_cdef_strengths strength parameters |
241 | | * for the chroma planes. |
242 | | * \arg \c damping_factor: CDEF damping factor. |
243 | | * |
244 | | */ |
245 | | void av1_cdef_search(struct MultiThreadInfo *mt_info, |
246 | | const YV12_BUFFER_CONFIG *frame, |
247 | | const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm, |
248 | | MACROBLOCKD *xd, CDEF_PICK_METHOD pick_method, int rdmult, |
249 | | int skip_cdef_feature, int frames_since_key, |
250 | | CDEF_CONTROL cdef_control, int non_reference_frame); |
251 | | |
252 | | #ifdef __cplusplus |
253 | | } // extern "C" |
254 | | #endif |
255 | | #endif // AOM_AV1_ENCODER_PICKCDEF_H_ |