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
18 extern "C" {
19 #endif
20 
24 typedef enum {
25  CDEF_NONE = 0,
26  CDEF_ALL = 1,
27  CDEF_REFERENCE = 2,
28 } CDEF_CONTROL;
29 
31 struct MultiThreadInfo;
32 
33 #define REDUCED_PRI_STRENGTHS_LVL1 8
34 #define REDUCED_PRI_STRENGTHS_LVL2 5
35 #define REDUCED_SEC_STRENGTHS_LVL3 2
36 #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 
78 typedef struct {
82  const YV12_BUFFER_CONFIG *ref;
86  CommonModeInfoParams *mi_params;
90  struct macroblockd_plane plane[MAX_MB_PLANE];
94  copy_fn_t copy_fn;
98  compute_cdef_dist_t compute_cdef_dist_fn;
102  int total_strengths;
106  int coeff_shift;
110  int damping;
114  int pick_method;
118  int num_planes;
123  int mi_wide_l2[MAX_MB_PLANE];
128  int mi_high_l2[MAX_MB_PLANE];
133  int xdec[MAX_MB_PLANE];
138  int ydec[MAX_MB_PLANE];
142  int bsize[MAX_MB_PLANE];
146  int nvfb;
150  int nhfb;
157  uint64_t (*mse[2])[TOTAL_STRENGTHS];
162  int *sb_index;
166  int sb_count;
167 } CdefSearchCtx;
168 
169 static INLINE int sb_all_skip(const CommonModeInfoParams *const mi_params,
170  int mi_row, int mi_col) {
171  const int maxr = AOMMIN(mi_params->mi_rows - mi_row, MI_SIZE_64X64);
172  const int maxc = AOMMIN(mi_params->mi_cols - mi_col, MI_SIZE_64X64);
173  const int stride = mi_params->mi_stride;
174  MB_MODE_INFO **mbmi = mi_params->mi_grid_base + mi_row * stride + mi_col;
175  for (int r = 0; r < maxr; ++r, mbmi += stride) {
176  for (int c = 0; c < maxc; ++c) {
177  if (!mbmi[c]->skip_txfm) return 0;
178  }
179  }
180  return 1;
181 }
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  int fbr, int fbc) {
194  const MB_MODE_INFO *const mbmi =
195  mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
196  MI_SIZE_64X64 * fbc];
197  // No filtering if the entire filter block is skipped.
198  if (sb_all_skip(mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64))
199  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  if (((fbc & 1) &&
204  (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_128X64)) ||
205  ((fbr & 1) &&
206  (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_64X128)))
207  return 1;
208  return 0;
209 }
210 
211 void av1_cdef_mse_calc_block(CdefSearchCtx *cdef_search_ctx, int fbr, int fbc,
212  int sb_count);
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_
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, CDEF_CONTROL cdef_control, int non_reference_frame)
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:750
Params related to MB_MODE_INFO arrays and related info.
Definition: av1_common_int.h:501
int mi_rows
Definition: av1_common_int.h:522
int mi_cols
Definition: av1_common_int.h:527
int mi_stride
Definition: av1_common_int.h:567
MB_MODE_INFO ** mi_grid_base
Definition: av1_common_int.h:559
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
Encoder parameters related to multi-threading.
Definition: encoder.h:1593
Variables related to current coding block.
Definition: blockd.h:577
YV12 frame buffer data structure.
Definition: yv12config.h:39