Improve the quantization table interface

- Add av1_build_quantize() function so that quantization
  related unit test would be able to access quant/dequant
  table without starting an encoder instance and directly
  accessing cpi.

Change-Id: I8ba429e5deb7a4e7f967996aaec1d20bff0feb3c
This commit is contained in:
Yi Luo 2017-05-25 15:09:25 -07:00
Родитель 923377b8d4
Коммит c621023e33
4 изменённых файлов: 50 добавлений и 34 удалений

Просмотреть файл

@ -1594,50 +1594,48 @@ static int get_qzbin_factor(int q, aom_bit_depth_t bit_depth) {
#endif #endif
} }
void av1_init_quantizer(AV1_COMP *cpi) { void av1_build_quantizer(aom_bit_depth_t bit_depth, int y_dc_delta_q,
AV1_COMMON *const cm = &cpi->common; int uv_dc_delta_q, int uv_ac_delta_q,
QUANTS *const quants = &cpi->quants; QUANTS *const quants, Dequants *const deq) {
int i, q, quant; int i, q, quant;
#if CONFIG_NEW_QUANT
int dq;
#endif
for (q = 0; q < QINDEX_RANGE; q++) { for (q = 0; q < QINDEX_RANGE; q++) {
const int qzbin_factor = get_qzbin_factor(q, cm->bit_depth); const int qzbin_factor = get_qzbin_factor(q, bit_depth);
const int qrounding_factor = q == 0 ? 64 : 48; const int qrounding_factor = q == 0 ? 64 : 48;
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
int qrounding_factor_fp = 64; int qrounding_factor_fp = 64;
// y // y
quant = i == 0 ? av1_dc_quant(q, cm->y_dc_delta_q, cm->bit_depth) quant = i == 0 ? av1_dc_quant(q, y_dc_delta_q, bit_depth)
: av1_ac_quant(q, 0, cm->bit_depth); : av1_ac_quant(q, 0, bit_depth);
invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant); invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant);
quants->y_quant_fp[q][i] = (1 << 16) / quant; quants->y_quant_fp[q][i] = (1 << 16) / quant;
quants->y_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7; quants->y_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7;
quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
quants->y_round[q][i] = (qrounding_factor * quant) >> 7; quants->y_round[q][i] = (qrounding_factor * quant) >> 7;
cpi->y_dequant[q][i] = quant; deq->y_dequant[q][i] = quant;
// uv // uv
quant = i == 0 ? av1_dc_quant(q, cm->uv_dc_delta_q, cm->bit_depth) quant = i == 0 ? av1_dc_quant(q, uv_dc_delta_q, bit_depth)
: av1_ac_quant(q, cm->uv_ac_delta_q, cm->bit_depth); : av1_ac_quant(q, uv_ac_delta_q, bit_depth);
invert_quant(&quants->uv_quant[q][i], &quants->uv_quant_shift[q][i], invert_quant(&quants->uv_quant[q][i], &quants->uv_quant_shift[q][i],
quant); quant);
quants->uv_quant_fp[q][i] = (1 << 16) / quant; quants->uv_quant_fp[q][i] = (1 << 16) / quant;
quants->uv_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7; quants->uv_round_fp[q][i] = (qrounding_factor_fp * quant) >> 7;
quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
quants->uv_round[q][i] = (qrounding_factor * quant) >> 7; quants->uv_round[q][i] = (qrounding_factor * quant) >> 7;
cpi->uv_dequant[q][i] = quant; deq->uv_dequant[q][i] = quant;
} }
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
int dq;
for (dq = 0; dq < QUANT_PROFILES; dq++) { for (dq = 0; dq < QUANT_PROFILES; dq++) {
for (i = 0; i < COEF_BANDS; i++) { for (i = 0; i < COEF_BANDS; i++) {
const int y_quant = cpi->y_dequant[q][i != 0]; const int y_quant = deq->y_dequant[q][i != 0];
const int uvquant = cpi->uv_dequant[q][i != 0]; const int uvquant = deq->uv_dequant[q][i != 0];
av1_get_dequant_val_nuq(y_quant, i, cpi->y_dequant_val_nuq[dq][q][i], av1_get_dequant_val_nuq(y_quant, i, deq->y_dequant_val_nuq[dq][q][i],
quants->y_cuml_bins_nuq[dq][q][i], dq); quants->y_cuml_bins_nuq[dq][q][i], dq);
av1_get_dequant_val_nuq(uvquant, i, cpi->uv_dequant_val_nuq[dq][q][i], av1_get_dequant_val_nuq(uvquant, i, deq->uv_dequant_val_nuq[dq][q][i],
quants->uv_cuml_bins_nuq[dq][q][i], dq); quants->uv_cuml_bins_nuq[dq][q][i], dq);
} }
} }
@ -1650,7 +1648,7 @@ void av1_init_quantizer(AV1_COMP *cpi) {
quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1]; quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1];
quants->y_zbin[q][i] = quants->y_zbin[q][1]; quants->y_zbin[q][i] = quants->y_zbin[q][1];
quants->y_round[q][i] = quants->y_round[q][1]; quants->y_round[q][i] = quants->y_round[q][1];
cpi->y_dequant[q][i] = cpi->y_dequant[q][1]; deq->y_dequant[q][i] = deq->y_dequant[q][1];
quants->uv_quant[q][i] = quants->uv_quant[q][1]; quants->uv_quant[q][i] = quants->uv_quant[q][1];
quants->uv_quant_fp[q][i] = quants->uv_quant_fp[q][1]; quants->uv_quant_fp[q][i] = quants->uv_quant_fp[q][1];
@ -1658,11 +1656,19 @@ void av1_init_quantizer(AV1_COMP *cpi) {
quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1]; quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1];
quants->uv_zbin[q][i] = quants->uv_zbin[q][1]; quants->uv_zbin[q][i] = quants->uv_zbin[q][1];
quants->uv_round[q][i] = quants->uv_round[q][1]; quants->uv_round[q][i] = quants->uv_round[q][1];
cpi->uv_dequant[q][i] = cpi->uv_dequant[q][1]; deq->uv_dequant[q][i] = deq->uv_dequant[q][1];
} }
} }
} }
void av1_init_quantizer(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
QUANTS *const quants = &cpi->quants;
Dequants *const dequants = &cpi->dequants;
av1_build_quantizer(cm->bit_depth, cm->y_dc_delta_q, cm->uv_dc_delta_q,
cm->uv_ac_delta_q, quants, dequants);
}
void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x, void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x,
int segment_id) { int segment_id) {
const AV1_COMMON *const cm = &cpi->common; const AV1_COMMON *const cm = &cpi->common;
@ -1712,11 +1718,12 @@ void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x,
memcpy(&xd->plane[0].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][0], memcpy(&xd->plane[0].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][0],
sizeof(cm->giqmatrix[qmlevel][0])); sizeof(cm->giqmatrix[qmlevel][0]));
#endif #endif
xd->plane[0].dequant = cpi->y_dequant[qindex]; xd->plane[0].dequant = cpi->dequants.y_dequant[qindex];
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
for (dq = 0; dq < QUANT_PROFILES; dq++) { for (dq = 0; dq < QUANT_PROFILES; dq++) {
x->plane[0].cuml_bins_nuq[dq] = quants->y_cuml_bins_nuq[dq][qindex]; x->plane[0].cuml_bins_nuq[dq] = quants->y_cuml_bins_nuq[dq][qindex];
xd->plane[0].dequant_val_nuq[dq] = cpi->y_dequant_val_nuq[dq][qindex]; xd->plane[0].dequant_val_nuq[dq] =
cpi->dequants.y_dequant_val_nuq[dq][qindex];
} }
#endif // CONFIG_NEW_QUANT #endif // CONFIG_NEW_QUANT
@ -1734,11 +1741,12 @@ void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x,
memcpy(&xd->plane[i].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][1], memcpy(&xd->plane[i].seg_iqmatrix[segment_id], cm->giqmatrix[qmlevel][1],
sizeof(cm->giqmatrix[qmlevel][1])); sizeof(cm->giqmatrix[qmlevel][1]));
#endif #endif
xd->plane[i].dequant = cpi->uv_dequant[qindex]; xd->plane[i].dequant = cpi->dequants.uv_dequant[qindex];
#if CONFIG_NEW_QUANT #if CONFIG_NEW_QUANT
for (dq = 0; dq < QUANT_PROFILES; dq++) { for (dq = 0; dq < QUANT_PROFILES; dq++) {
x->plane[i].cuml_bins_nuq[dq] = quants->uv_cuml_bins_nuq[dq][qindex]; x->plane[i].cuml_bins_nuq[dq] = quants->uv_cuml_bins_nuq[dq][qindex];
xd->plane[i].dequant_val_nuq[dq] = cpi->uv_dequant_val_nuq[dq][qindex]; xd->plane[i].dequant_val_nuq[dq] =
cpi->dequants.uv_dequant_val_nuq[dq][qindex];
} }
#endif // CONFIG_NEW_QUANT #endif // CONFIG_NEW_QUANT
} }

Просмотреть файл

@ -69,6 +69,17 @@ typedef struct {
DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]); DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]);
} QUANTS; } QUANTS;
typedef struct {
DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]); // 8: SIMD width
DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]); // 8: SIMD width
#if CONFIG_NEW_QUANT
DECLARE_ALIGNED(16, dequant_val_type_nuq,
y_dequant_val_nuq[QUANT_PROFILES][QINDEX_RANGE][COEF_BANDS]);
DECLARE_ALIGNED(16, dequant_val_type_nuq,
uv_dequant_val_nuq[QUANT_PROFILES][QINDEX_RANGE][COEF_BANDS]);
#endif // CONFIG_NEW_QUANT
} Dequants;
struct AV1_COMP; struct AV1_COMP;
struct AV1Common; struct AV1Common;
@ -77,6 +88,10 @@ void av1_frame_init_quantizer(struct AV1_COMP *cpi);
void av1_init_plane_quantizers(const struct AV1_COMP *cpi, MACROBLOCK *x, void av1_init_plane_quantizers(const struct AV1_COMP *cpi, MACROBLOCK *x,
int segment_id); int segment_id);
void av1_build_quantizer(aom_bit_depth_t bit_depth, int y_dc_delta_q,
int uv_dc_delta_q, int uv_ac_delta_q,
QUANTS *const quants, Dequants *const deq);
void av1_init_quantizer(struct AV1_COMP *cpi); void av1_init_quantizer(struct AV1_COMP *cpi);
void av1_set_quantizer(struct AV1Common *cm, int q); void av1_set_quantizer(struct AV1Common *cm, int q);

Просмотреть файл

@ -563,7 +563,7 @@ static void set_vbp_thresholds(AV1_COMP *cpi, int64_t thresholds[], int q) {
const int is_key_frame = (cm->frame_type == KEY_FRAME); const int is_key_frame = (cm->frame_type == KEY_FRAME);
const int threshold_multiplier = is_key_frame ? 20 : 1; const int threshold_multiplier = is_key_frame ? 20 : 1;
const int64_t threshold_base = const int64_t threshold_base =
(int64_t)(threshold_multiplier * cpi->y_dequant[q][1]); (int64_t)(threshold_multiplier * cpi->dequants.y_dequant[q][1]);
if (is_key_frame) { if (is_key_frame) {
thresholds[1] = threshold_base; thresholds[1] = threshold_base;
thresholds[2] = threshold_base >> 2; thresholds[2] = threshold_base >> 2;
@ -602,8 +602,8 @@ void av1_set_variance_partition_thresholds(AV1_COMP *cpi, int q) {
if (cm->width <= 352 && cm->height <= 288) if (cm->width <= 352 && cm->height <= 288)
cpi->vbp_threshold_sad = 100; cpi->vbp_threshold_sad = 100;
else else
cpi->vbp_threshold_sad = (cpi->y_dequant[q][1] << 1) > 1000 cpi->vbp_threshold_sad = (cpi->dequants.y_dequant[q][1] << 1) > 1000
? (cpi->y_dequant[q][1] << 1) ? (cpi->dequants.y_dequant[q][1] << 1)
: 1000; : 1000;
cpi->vbp_bsize_min = BLOCK_16X16; cpi->vbp_bsize_min = BLOCK_16X16;
} }

Просмотреть файл

@ -366,14 +366,7 @@ typedef struct AV1_COMP {
QUANTS quants; QUANTS quants;
ThreadData td; ThreadData td;
MB_MODE_INFO_EXT *mbmi_ext_base; MB_MODE_INFO_EXT *mbmi_ext_base;
DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]); // 8: SIMD width Dequants dequants;
DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]); // 8: SIMD width
#if CONFIG_NEW_QUANT
DECLARE_ALIGNED(16, dequant_val_type_nuq,
y_dequant_val_nuq[QUANT_PROFILES][QINDEX_RANGE][COEF_BANDS]);
DECLARE_ALIGNED(16, dequant_val_type_nuq,
uv_dequant_val_nuq[QUANT_PROFILES][QINDEX_RANGE][COEF_BANDS]);
#endif // CONFIG_NEW_QUANT
AV1_COMMON common; AV1_COMMON common;
AV1EncoderConfig oxcf; AV1EncoderConfig oxcf;
struct lookahead_ctx *lookahead; struct lookahead_ctx *lookahead;