| AOMedia AV1 Codec

pickcdef.h
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
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_ADAPTIVE = 3, /* Enable CDEF adaptively based on frame qindex */
29} CDEF_CONTROL;
30
32 struct MultiThreadInfo;
33
34#define REDUCED_PRI_STRENGTHS_LVL1 8
35#define REDUCED_PRI_STRENGTHS_LVL2 5
36#define REDUCED_SEC_STRENGTHS_LVL3 2
37#define REDUCED_SEC_STRENGTHS_LVL5 1
38#define REDUCED_PRI_STRENGTHS_LVL4 2
39
40#define REDUCED_TOTAL_STRENGTHS_LVL1 \
41 (REDUCED_PRI_STRENGTHS_LVL1 * CDEF_SEC_STRENGTHS)
42#define REDUCED_TOTAL_STRENGTHS_LVL2 \
43 (REDUCED_PRI_STRENGTHS_LVL2 * CDEF_SEC_STRENGTHS)
44#define REDUCED_TOTAL_STRENGTHS_LVL3 \
45 (REDUCED_PRI_STRENGTHS_LVL2 * REDUCED_SEC_STRENGTHS_LVL3)
46#define REDUCED_TOTAL_STRENGTHS_LVL4 \
47 (REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL3)
48#define REDUCED_TOTAL_STRENGTHS_LVL5 \
49 (REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL5)
50#define TOTAL_STRENGTHS (CDEF_PRI_STRENGTHS * CDEF_SEC_STRENGTHS)
51
52 static const int priconv_lvl1[REDUCED_PRI_STRENGTHS_LVL1] = { 0, 1, 2, 3,
53 5, 7, 10, 13 };
54 static const int priconv_lvl2[REDUCED_PRI_STRENGTHS_LVL2] = { 0, 2, 4, 8, 14 };
55 static const int priconv_lvl4[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 11 };
56 static const int priconv_lvl5[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 5 };
57 static const int secconv_lvl3[REDUCED_SEC_STRENGTHS_LVL3] = { 0, 2 };
58 static const int secconv_lvl5[REDUCED_SEC_STRENGTHS_LVL5] = { 0 };
59 static const int nb_cdef_strengths[CDEF_PICK_METHODS] = {
60 TOTAL_STRENGTHS,
61 REDUCED_TOTAL_STRENGTHS_LVL1,
62 REDUCED_TOTAL_STRENGTHS_LVL2,
63 REDUCED_TOTAL_STRENGTHS_LVL3,
64 REDUCED_TOTAL_STRENGTHS_LVL4,
65 REDUCED_TOTAL_STRENGTHS_LVL5,
66 TOTAL_STRENGTHS
67};
68
69 typedef void (*copy_fn_t)(uint16_t *dst, int dstride, const uint8_t *src,
70 int src_voffset, int src_hoffset, int sstride,
71 int vsize, int hsize);
72 typedef uint64_t (*compute_cdef_dist_t)(void *dst, int dstride, uint16_t *src,
73 cdef_list *dlist, int cdef_count,
74 BLOCK_SIZE bsize, int coeff_shift,
75 int row, int col);
76
79 typedef struct {
83 const YV12_BUFFER_CONFIG *ref;
87 CommonModeInfoParams *mi_params;
91 struct macroblockd_plane plane[MAX_MB_PLANE];
95 copy_fn_t copy_fn;
99 compute_cdef_dist_t compute_cdef_dist_fn;
103 int total_strengths;
107 int coeff_shift;
111 int damping;
115 int pick_method;
119 int num_planes;
124 int mi_wide_l2[MAX_MB_PLANE];
129 int mi_high_l2[MAX_MB_PLANE];
134 int xdec[MAX_MB_PLANE];
139 int ydec[MAX_MB_PLANE];
143 int bsize[MAX_MB_PLANE];
147 int nvfb;
151 int nhfb;
158 uint64_t (*mse[2])[TOTAL_STRENGTHS];
163 int *sb_index;
167 int sb_count;
172 bool use_highbitdepth;
173} CdefSearchCtx;
174
175 static inline int sb_all_skip(const CommonModeInfoParams *const mi_params,
176 int mi_row, int mi_col) {
177 const int maxr = AOMMIN(mi_params->mi_rows - mi_row, MI_SIZE_64X64);
178 const int maxc = AOMMIN(mi_params->mi_cols - mi_col, MI_SIZE_64X64);
179 const int stride = mi_params->mi_stride;
180 MB_MODE_INFO **mbmi = mi_params->mi_grid_base + mi_row * stride + mi_col;
181 for (int r = 0; r < maxr; ++r, mbmi += stride) {
182 for (int c = 0; c < maxc; ++c) {
183 if (!mbmi[c]->skip_txfm) return 0;
184 }
185 }
186 return 1;
187}
188
189// Checks if cdef processing can be skipped for particular sb.
190// Inputs:
191// cdef_search_ctx: Pointer to the structure containing parameters related to
192// CDEF search context.
193// fbr: Row index in units of 64x64 block
194// fbc: Column index in units of 64x64 block
195// Returns:
196// 1/0 will be returned to indicate skip/don't skip cdef processing of sb
197// respectively.
198 static inline int cdef_sb_skip(const CommonModeInfoParams *const mi_params,
199 int fbr, int fbc) {
200 const MB_MODE_INFO *const mbmi =
201 mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
202 MI_SIZE_64X64 * fbc];
203 // No filtering if the entire filter block is skipped.
204 if (sb_all_skip(mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64))
205 return 1;
206 // Skip odd numbered 64x64 block rows(cols) when bsize is BLOCK_128X128,
207 // BLOCK_64X128(BLOCK_128X128, BLOCK_128X64) as for such blocks CDEF filtering
208 // is done at the corresponding block sizes.
209 if (((fbc & 1) &&
210 (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_128X64)) ||
211 ((fbr & 1) &&
212 (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_64X128)))
213 return 1;
214 return 0;
215}
216
217 void av1_cdef_dealloc_data(CdefSearchCtx *cdef_search_ctx);
218
219 void av1_cdef_mse_calc_block(CdefSearchCtx *cdef_search_ctx,
220 struct aom_internal_error_info *error_info,
221 int fbr, int fbc, int sb_count);
223
243 void av1_cdef_search(struct AV1_COMP *cpi);
244
256 void av1_pick_cdef_from_qp(AV1_COMMON *const cm, int skip_cdef,
257 int is_screen_content);
258
259#ifdef __cplusplus
260} // extern "C"
261#endif
262#endif // AOM_AV1_ENCODER_PICKCDEF_H_
av1_cdef_search
void av1_cdef_search(struct AV1_COMP *cpi)
AV1 CDEF parameter search.
av1_pick_cdef_from_qp
void av1_pick_cdef_from_qp(AV1_COMMON *const cm, int skip_cdef, int is_screen_content)
AV1 CDEF level from QP.
speed_features.h
AV1_COMP
Top level encoder structure.
Definition encoder.h:2896
CommonModeInfoParams
Params related to MB_MODE_INFO arrays and related info.
Definition av1_common_int.h:510
CommonModeInfoParams::mi_rows
int mi_rows
Definition av1_common_int.h:531
CommonModeInfoParams::mi_cols
int mi_cols
Definition av1_common_int.h:536
CommonModeInfoParams::mi_stride
int mi_stride
Definition av1_common_int.h:576
CommonModeInfoParams::mi_grid_base
MB_MODE_INFO ** mi_grid_base
Definition av1_common_int.h:568
MB_MODE_INFO
Stores the prediction/txfm mode of the current coding block.
Definition blockd.h:222
MB_MODE_INFO::bsize
BLOCK_SIZE bsize
The block size of the current coding block.
Definition blockd.h:228
MultiThreadInfo
Encoder parameters related to multi-threading.
Definition encoder.h:1767