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"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
22struct MultiThreadInfo;
23
24#define REDUCED_PRI_STRENGTHS_LVL1 8
25#define REDUCED_PRI_STRENGTHS_LVL2 5
26#define REDUCED_SEC_STRENGTHS_LVL3 2
27#define REDUCED_PRI_STRENGTHS_LVL4 2
28
29#define REDUCED_TOTAL_STRENGTHS_LVL1 \
30 (REDUCED_PRI_STRENGTHS_LVL1 * CDEF_SEC_STRENGTHS)
31#define REDUCED_TOTAL_STRENGTHS_LVL2 \
32 (REDUCED_PRI_STRENGTHS_LVL2 * CDEF_SEC_STRENGTHS)
33#define REDUCED_TOTAL_STRENGTHS_LVL3 \
34 (REDUCED_PRI_STRENGTHS_LVL2 * REDUCED_SEC_STRENGTHS_LVL3)
35#define REDUCED_TOTAL_STRENGTHS_LVL4 \
36 (REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL3)
37#define TOTAL_STRENGTHS (CDEF_PRI_STRENGTHS * CDEF_SEC_STRENGTHS)
38
39static const int priconv_lvl1[REDUCED_PRI_STRENGTHS_LVL1] = { 0, 1, 2, 3,
40 5, 7, 10, 13 };
41static const int priconv_lvl2[REDUCED_PRI_STRENGTHS_LVL2] = { 0, 2, 4, 8, 14 };
42static const int priconv_lvl4[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 11 };
43static const int secconv_lvl3[REDUCED_SEC_STRENGTHS_LVL3] = { 0, 2 };
44static const int nb_cdef_strengths[CDEF_PICK_METHODS] = {
45 TOTAL_STRENGTHS,
46 REDUCED_TOTAL_STRENGTHS_LVL1,
47 REDUCED_TOTAL_STRENGTHS_LVL2,
48 REDUCED_TOTAL_STRENGTHS_LVL3,
49 REDUCED_TOTAL_STRENGTHS_LVL4,
50 TOTAL_STRENGTHS
51};
52
53typedef void (*copy_fn_t)(uint16_t *dst, int dstride, const void *src,
54 int src_voffset, int src_hoffset, int sstride,
55 int vsize, int hsize);
56typedef uint64_t (*compute_cdef_dist_t)(void *dst, int dstride, uint16_t *src,
57 cdef_list *dlist, int cdef_count,
58 BLOCK_SIZE bsize, int coeff_shift,
59 int row, int col);
60
63typedef struct {
67 const YV12_BUFFER_CONFIG *ref;
71 CommonModeInfoParams *mi_params;
75 struct macroblockd_plane plane[MAX_MB_PLANE];
79 copy_fn_t copy_fn;
83 compute_cdef_dist_t compute_cdef_dist_fn;
87 int total_strengths;
91 int coeff_shift;
95 int damping;
99 int pick_method;
103 int num_planes;
108 int mi_wide_l2[MAX_MB_PLANE];
113 int mi_high_l2[MAX_MB_PLANE];
118 int xdec[MAX_MB_PLANE];
123 int ydec[MAX_MB_PLANE];
127 int bsize[MAX_MB_PLANE];
131 int nvfb;
135 int nhfb;
142 uint64_t (*mse[2])[TOTAL_STRENGTHS];
147 int *sb_index;
151 int sb_count;
152} CdefSearchCtx;
153
154static INLINE int sb_all_skip(const CommonModeInfoParams *const mi_params,
155 int mi_row, int mi_col) {
156 const int maxr = AOMMIN(mi_params->mi_rows - mi_row, MI_SIZE_64X64);
157 const int maxc = AOMMIN(mi_params->mi_cols - mi_col, MI_SIZE_64X64);
158 const int stride = mi_params->mi_stride;
159 MB_MODE_INFO **mbmi = mi_params->mi_grid_base + mi_row * stride + mi_col;
160 for (int r = 0; r < maxr; ++r, mbmi += stride) {
161 for (int c = 0; c < maxc; ++c) {
162 if (!mbmi[c]->skip_txfm) return 0;
163 }
164 }
165 return 1;
166}
167
168// Checks if cdef processing can be skipped for particular sb.
169// Inputs:
170// cdef_search_ctx: Pointer to the structure containing parameters related to
171// CDEF search context.
172// fbr: Row index in units of 64x64 block
173// fbc: Column index in units of 64x64 block
174// Returns:
175// 1/0 will be returned to indicate skip/don't skip cdef processing of sb
176// respectively.
177static INLINE int cdef_sb_skip(const CommonModeInfoParams *const mi_params,
178 int fbr, int fbc) {
179 const MB_MODE_INFO *const mbmi =
180 mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
181 MI_SIZE_64X64 * fbc];
182 // No filtering if the entire filter block is skipped.
183 if (sb_all_skip(mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64))
184 return 1;
185 // Skip odd numbered 64x64 block rows(cols) when bsize is BLOCK_128X128,
186 // BLOCK_64X128(BLOCK_128X128, BLOCK_128X64) as for such blocks CDEF filtering
187 // is done at the corresponding block sizes.
188 if (((fbc & 1) &&
189 (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_128X64)) ||
190 ((fbr & 1) &&
191 (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_64X128)))
192 return 1;
193 return 0;
194}
195
196void av1_cdef_mse_calc_block(CdefSearchCtx *cdef_search_ctx, int fbr, int fbc,
197 int sb_count);
227void av1_cdef_search(struct MultiThreadInfo *mt_info,
228 const YV12_BUFFER_CONFIG *frame,
229 const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm,
230 MACROBLOCKD *xd, CDEF_PICK_METHOD pick_method, int rdmult,
231 int skip_cdef_feature, int frames_since_key);
232
233#ifdef __cplusplus
234} // extern "C"
235#endif
236#endif // AOM_AV1_ENCODER_PICKCDEF_H_
void av1_cdef_search(struct MultiThreadInfo *mt_info, const YV12_BUFFER_CONFIG *frame, const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm, MACROBLOCKD *xd, CDEF_PICK_METHOD pick_method, int rdmult, int skip_cdef_feature, int frames_since_key)
AV1 CDEF parameter search.
CDEF_PICK_METHOD
This enumeration defines a variety of CDEF pick methods.
Definition speed_features.h:156
Top level common structure used by both encoder and decoder.
Definition av1_common_int.h:751
Params related to MB_MODE_INFO arrays and related info.
Definition av1_common_int.h:505
int mi_rows
Definition av1_common_int.h:526
int mi_cols
Definition av1_common_int.h:531
int mi_stride
Definition av1_common_int.h:571
MB_MODE_INFO ** mi_grid_base
Definition av1_common_int.h:563
Stores the prediction/txfm mode of the current coding block.
Definition blockd.h:222
BLOCK_SIZE bsize
The block size of the current coding block.
Definition blockd.h:228
Variables related to current coding block.
Definition blockd.h:577
YV12 frame buffer data structure.
Definition yv12config.h:38