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 
22 struct 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 
39 static const int priconv_lvl1[REDUCED_PRI_STRENGTHS_LVL1] = { 0, 1, 2, 3,
40  5, 7, 10, 13 };
41 static const int priconv_lvl2[REDUCED_PRI_STRENGTHS_LVL2] = { 0, 2, 4, 8, 14 };
42 static const int priconv_lvl4[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 11 };
43 static const int secconv_lvl3[REDUCED_SEC_STRENGTHS_LVL3] = { 0, 2 };
44 static 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 
53 typedef 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);
56 typedef 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 
61 // Data related to CDEF search multi-thread synchronization.
62 typedef struct AV1CdefSyncData {
63 #if CONFIG_MULTITHREAD
64  // Mutex lock used while dispatching jobs.
65  pthread_mutex_t *mutex_;
66 #endif // CONFIG_MULTITHREAD
67  // Flag to indicate all blocks are processed and end of frame is reached
68  int end_of_frame;
69  // Row index in units of 64x64 block
70  int fbr;
71  // Column index in units of 64x64 block
72  int fbc;
73 } AV1CdefSync;
74 
77 typedef struct {
81  const YV12_BUFFER_CONFIG *ref;
85  CommonModeInfoParams *mi_params;
89  struct macroblockd_plane plane[MAX_MB_PLANE];
93  copy_fn_t copy_fn;
97  compute_cdef_dist_t compute_cdef_dist_fn;
101  int total_strengths;
105  int coeff_shift;
109  int damping;
113  int pick_method;
117  int num_planes;
122  int mi_wide_l2[MAX_MB_PLANE];
127  int mi_high_l2[MAX_MB_PLANE];
132  int xdec[MAX_MB_PLANE];
137  int ydec[MAX_MB_PLANE];
141  int bsize[MAX_MB_PLANE];
145  int nvfb;
149  int nhfb;
156  uint64_t (*mse[2])[TOTAL_STRENGTHS];
161  int *sb_index;
165  int sb_count;
166 } CdefSearchCtx;
167 
168 static INLINE int sb_all_skip(const CommonModeInfoParams *const mi_params,
169  int mi_row, int mi_col) {
170  const int maxr = AOMMIN(mi_params->mi_rows - mi_row, MI_SIZE_64X64);
171  const int maxc = AOMMIN(mi_params->mi_cols - mi_col, MI_SIZE_64X64);
172  const int stride = mi_params->mi_stride;
173  MB_MODE_INFO **mbmi = mi_params->mi_grid_base + mi_row * stride + mi_col;
174  for (int r = 0; r < maxr; ++r, mbmi += stride) {
175  for (int c = 0; c < maxc; ++c) {
176  if (!mbmi[c]->skip_txfm) return 0;
177  }
178  }
179  return 1;
180 }
181 
182 // Checks if cdef processing can be skipped for particular sb.
183 // Inputs:
184 // cdef_search_ctx: Pointer to the structure containing parameters related to
185 // CDEF search context.
186 // fbr: Row index in units of 64x64 block
187 // fbc: Column index in units of 64x64 block
188 // Returns:
189 // 1/0 will be returned to indicate skip/don't skip cdef processing of sb
190 // respectively.
191 static INLINE int cdef_sb_skip(const CommonModeInfoParams *const mi_params,
192  int fbr, int fbc) {
193  const MB_MODE_INFO *const mbmi =
194  mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
195  MI_SIZE_64X64 * fbc];
196  // No filtering if the entire filter block is skipped.
197  if (sb_all_skip(mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64))
198  return 1;
199  // Skip odd numbered 64x64 block rows(cols) when bsize is BLOCK_128X128,
200  // BLOCK_64X128(BLOCK_128X128, BLOCK_128X64) as for such blocks CDEF filtering
201  // is done at the corresponding block sizes.
202  if (((fbc & 1) &&
203  (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_128X64)) ||
204  ((fbr & 1) &&
205  (mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_64X128)))
206  return 1;
207  return 0;
208 }
209 
210 void av1_cdef_mse_calc_block(CdefSearchCtx *cdef_search_ctx, int fbr, int fbc,
211  int sb_count);
239 void av1_cdef_search(struct MultiThreadInfo *mt_info,
240  const YV12_BUFFER_CONFIG *frame,
241  const YV12_BUFFER_CONFIG *ref, AV1_COMMON *cm,
242  MACROBLOCKD *xd, CDEF_PICK_METHOD pick_method, int rdmult);
243 
244 #ifdef __cplusplus
245 } // extern "C"
246 #endif
247 #endif // AOM_AV1_ENCODER_PICKCDEF_H_
MB_MODE_INFO ** mi_grid_base
Definition: av1_common_int.h:535
CDEF_PICK_METHOD
This enumeration defines a variety of CDEF pick methods.
Definition: speed_features.h:156
int mi_cols
Definition: av1_common_int.h:503
Params related to MB_MODE_INFO arrays and related info.
Definition: av1_common_int.h:477
int mi_rows
Definition: av1_common_int.h:498
YV12 frame buffer data structure.
Definition: yv12config.h:38
Variables related to current coding block.
Definition: blockd.h:568
int mi_stride
Definition: av1_common_int.h:543
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:723
BLOCK_SIZE bsize
The block size of the current coding block.
Definition: blockd.h:222
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:216
Encoder parameters related to multi-threading.
Definition: encoder.h:1375
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)
AV1 CDEF parameter search.