pickcdef.h
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved.
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AOM_AV1_ENCODER_PICKCDEF_H_
#define AOM_AV1_ENCODER_PICKCDEF_H_
#include "av1/common/cdef.h"
#include "av1/encoder/speed_features.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
CDEF_NONE = 0, /* Disable CDEF on all frames. */
CDEF_ALL = 1, /* Enable CDEF for all frames. */
CDEF_REFERENCE = 2, /* Disable CDEF on non reference frames. */
CDEF_ADAPTIVE = 3, /* Enable CDEF adaptively based on frame qindex */
} CDEF_CONTROL;
struct MultiThreadInfo;
#define REDUCED_PRI_STRENGTHS_LVL1 8
#define REDUCED_PRI_STRENGTHS_LVL2 5
#define REDUCED_SEC_STRENGTHS_LVL3 2
#define REDUCED_SEC_STRENGTHS_LVL5 1
#define REDUCED_PRI_STRENGTHS_LVL4 2
#define REDUCED_TOTAL_STRENGTHS_LVL1 \
(REDUCED_PRI_STRENGTHS_LVL1 * CDEF_SEC_STRENGTHS)
#define REDUCED_TOTAL_STRENGTHS_LVL2 \
(REDUCED_PRI_STRENGTHS_LVL2 * CDEF_SEC_STRENGTHS)
#define REDUCED_TOTAL_STRENGTHS_LVL3 \
(REDUCED_PRI_STRENGTHS_LVL2 * REDUCED_SEC_STRENGTHS_LVL3)
#define REDUCED_TOTAL_STRENGTHS_LVL4 \
(REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL3)
#define REDUCED_TOTAL_STRENGTHS_LVL5 \
(REDUCED_PRI_STRENGTHS_LVL4 * REDUCED_SEC_STRENGTHS_LVL5)
#define TOTAL_STRENGTHS (CDEF_PRI_STRENGTHS * CDEF_SEC_STRENGTHS)
static const int priconv_lvl1[REDUCED_PRI_STRENGTHS_LVL1] = { 0, 1, 2, 3,
5, 7, 10, 13 };
static const int priconv_lvl2[REDUCED_PRI_STRENGTHS_LVL2] = { 0, 2, 4, 8, 14 };
static const int priconv_lvl4[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 11 };
static const int priconv_lvl5[REDUCED_PRI_STRENGTHS_LVL4] = { 0, 5 };
static const int secconv_lvl3[REDUCED_SEC_STRENGTHS_LVL3] = { 0, 2 };
static const int secconv_lvl5[REDUCED_SEC_STRENGTHS_LVL5] = { 0 };
static const int nb_cdef_strengths[CDEF_PICK_METHODS] = {
TOTAL_STRENGTHS,
REDUCED_TOTAL_STRENGTHS_LVL1,
REDUCED_TOTAL_STRENGTHS_LVL2,
REDUCED_TOTAL_STRENGTHS_LVL3,
REDUCED_TOTAL_STRENGTHS_LVL4,
REDUCED_TOTAL_STRENGTHS_LVL5,
TOTAL_STRENGTHS
};
typedef void (*copy_fn_t)(uint16_t *dst, int dstride, const uint8_t *src,
int src_voffset, int src_hoffset, int sstride,
int vsize, int hsize);
typedef uint64_t (*compute_cdef_dist_t)(void *dst, int dstride, uint16_t *src,
cdef_list *dlist, int cdef_count,
BLOCK_SIZE bsize, int coeff_shift,
int row, int col);
typedef struct {
const YV12_BUFFER_CONFIG *ref;
CommonModeInfoParams *mi_params;
struct macroblockd_plane plane[MAX_MB_PLANE];
copy_fn_t copy_fn;
compute_cdef_dist_t compute_cdef_dist_fn;
int total_strengths;
int coeff_shift;
int damping;
int pick_method;
int num_planes;
int mi_wide_l2[MAX_MB_PLANE];
int mi_high_l2[MAX_MB_PLANE];
int xdec[MAX_MB_PLANE];
int ydec[MAX_MB_PLANE];
int bsize[MAX_MB_PLANE];
int nvfb;
int nhfb;
uint64_t (*mse[2])[TOTAL_STRENGTHS];
int *sb_index;
int sb_count;
bool use_highbitdepth;
} CdefSearchCtx;
static inline int sb_all_skip(const CommonModeInfoParams *const mi_params,
int mi_row, int mi_col) {
const int maxr = AOMMIN(mi_params->mi_rows - mi_row, MI_SIZE_64X64);
const int maxc = AOMMIN(mi_params->mi_cols - mi_col, MI_SIZE_64X64);
const int stride = mi_params->mi_stride;
MB_MODE_INFO **mbmi = mi_params->mi_grid_base + mi_row * stride + mi_col;
for (int r = 0; r < maxr; ++r, mbmi += stride) {
for (int c = 0; c < maxc; ++c) {
if (!mbmi[c]->skip_txfm) return 0;
}
}
return 1;
}
// Checks if cdef processing can be skipped for particular sb.
// Inputs:
// cdef_search_ctx: Pointer to the structure containing parameters related to
// CDEF search context.
// fbr: Row index in units of 64x64 block
// fbc: Column index in units of 64x64 block
// Returns:
// 1/0 will be returned to indicate skip/don't skip cdef processing of sb
// respectively.
static inline int cdef_sb_skip(const CommonModeInfoParams *const mi_params,
int fbr, int fbc) {
const MB_MODE_INFO *const mbmi =
mi_params->mi_grid_base[MI_SIZE_64X64 * fbr * mi_params->mi_stride +
MI_SIZE_64X64 * fbc];
// No filtering if the entire filter block is skipped.
if (sb_all_skip(mi_params, fbr * MI_SIZE_64X64, fbc * MI_SIZE_64X64))
return 1;
// Skip odd numbered 64x64 block rows(cols) when bsize is BLOCK_128X128,
// BLOCK_64X128(BLOCK_128X128, BLOCK_128X64) as for such blocks CDEF filtering
// is done at the corresponding block sizes.
if (((fbc & 1) &&
(mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_128X64)) ||
((fbr & 1) &&
(mbmi->bsize == BLOCK_128X128 || mbmi->bsize == BLOCK_64X128)))
return 1;
return 0;
}
void av1_cdef_dealloc_data(CdefSearchCtx *cdef_search_ctx);
void av1_cdef_mse_calc_block(CdefSearchCtx *cdef_search_ctx,
struct aom_internal_error_info *error_info,
int fbr, int fbc, int sb_count,
int adaptive_cdef_mode);
void av1_cdef_search(struct AV1_COMP *cpi);
void av1_pick_cdef_from_qp(AV1_COMMON *const cm, int skip_cdef,
int is_screen_content, bool avoid_uv_cdef);
#ifdef __cplusplus
} // extern "C"
#endif
#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, bool avoid_uv_cdef)
AV1 CDEF level from QP.
speed_features.h
AV1_COMP
Top level encoder structure.
Definition encoder.h:2897
CommonModeInfoParams
Params related to MB_MODE_INFO arrays and related info.
Definition av1_common_int.h:511
CommonModeInfoParams::mi_rows
int mi_rows
Definition av1_common_int.h:532
CommonModeInfoParams::mi_cols
int mi_cols
Definition av1_common_int.h:537
CommonModeInfoParams::mi_stride
int mi_stride
Definition av1_common_int.h:577
CommonModeInfoParams::mi_grid_base
MB_MODE_INFO ** mi_grid_base
Definition av1_common_int.h:569
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:1759