From 86675d87a3d3b639fb2f93a42619638447fd5e90 Mon Sep 17 00:00:00 2001 From: Cheng Chen Date: Thu, 2 Jan 2020 17:22:21 -0800 Subject: Copy frame counts to the encode result. Explicitly copy frame counts of each frame to the encode result struct. Change-Id: Icc18ac83a9e2be8d7a4819f2fffcfda6568b275c --- vp9/simple_encode.cc | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) (limited to 'vp9/simple_encode.cc') diff --git a/vp9/simple_encode.cc b/vp9/simple_encode.cc index 80f238447..604317067 100644 --- a/vp9/simple_encode.cc +++ b/vp9/simple_encode.cc @@ -1,4 +1,6 @@ #include +#include "vp9/common/vp9_entropymode.h" +#include "vp9/common/vp9_enums.h" #include "vp9/common/vp9_onyxc_int.h" #include "vp9/vp9_iface_common.h" #include "vp9/encoder/vp9_encoder.h" @@ -89,6 +91,227 @@ get_frame_type_from_update_type(FRAME_UPDATE_TYPE update_type) { } } +static void update_frame_counts(const FRAME_COUNTS *input_counts, + FrameCounts *output_counts) { + // Init array sizes. + output_counts->y_mode.resize(BLOCK_SIZE_GROUPS); + for (int i = 0; i < BLOCK_SIZE_GROUPS; ++i) { + output_counts->y_mode[i].resize(INTRA_MODES); + } + + output_counts->uv_mode.resize(INTRA_MODES); + for (int i = 0; i < INTRA_MODES; ++i) { + output_counts->uv_mode[i].resize(INTRA_MODES); + } + + output_counts->partition.resize(PARTITION_CONTEXTS); + for (int i = 0; i < PARTITION_CONTEXTS; ++i) { + output_counts->partition[i].resize(PARTITION_TYPES); + } + + output_counts->coef.resize(TX_SIZES); + output_counts->eob_branch.resize(TX_SIZES); + for (int i = 0; i < TX_SIZES; ++i) { + output_counts->coef[i].resize(PLANE_TYPES); + output_counts->eob_branch[i].resize(PLANE_TYPES); + for (int j = 0; j < PLANE_TYPES; ++j) { + output_counts->coef[i][j].resize(REF_TYPES); + output_counts->eob_branch[i][j].resize(REF_TYPES); + for (int k = 0; k < REF_TYPES; ++k) { + output_counts->coef[i][j][k].resize(COEF_BANDS); + output_counts->eob_branch[i][j][k].resize(COEF_BANDS); + for (int l = 0; l < COEF_BANDS; ++l) { + output_counts->coef[i][j][k][l].resize(COEFF_CONTEXTS); + output_counts->eob_branch[i][j][k][l].resize(COEFF_CONTEXTS); + for (int m = 0; m < COEFF_CONTEXTS; ++m) { + output_counts->coef[i][j][k][l][m].resize(UNCONSTRAINED_NODES + 1); + } + } + } + } + } + + output_counts->switchable_interp.resize(SWITCHABLE_FILTER_CONTEXTS); + for (int i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) { + output_counts->switchable_interp[i].resize(SWITCHABLE_FILTERS); + } + + output_counts->inter_mode.resize(INTER_MODE_CONTEXTS); + for (int i = 0; i < INTER_MODE_CONTEXTS; ++i) { + output_counts->inter_mode[i].resize(INTER_MODES); + } + + output_counts->intra_inter.resize(INTRA_INTER_CONTEXTS); + for (int i = 0; i < INTRA_INTER_CONTEXTS; ++i) { + output_counts->intra_inter[i].resize(2); + } + + output_counts->comp_inter.resize(COMP_INTER_CONTEXTS); + for (int i = 0; i < COMP_INTER_CONTEXTS; ++i) { + output_counts->comp_inter[i].resize(2); + } + + output_counts->single_ref.resize(REF_CONTEXTS); + for (int i = 0; i < REF_CONTEXTS; ++i) { + output_counts->single_ref[i].resize(2); + for (int j = 0; j < 2; ++j) { + output_counts->single_ref[i][j].resize(2); + } + } + + output_counts->comp_ref.resize(REF_CONTEXTS); + for (int i = 0; i < REF_CONTEXTS; ++i) { + output_counts->comp_ref[i].resize(2); + } + + output_counts->skip.resize(SKIP_CONTEXTS); + for (int i = 0; i < SKIP_CONTEXTS; ++i) { + output_counts->skip[i].resize(2); + } + + output_counts->tx.p32x32.resize(TX_SIZE_CONTEXTS); + output_counts->tx.p16x16.resize(TX_SIZE_CONTEXTS); + output_counts->tx.p8x8.resize(TX_SIZE_CONTEXTS); + for (int i = 0; i < TX_SIZE_CONTEXTS; i++) { + output_counts->tx.p32x32[i].resize(TX_SIZES); + output_counts->tx.p16x16[i].resize(TX_SIZES - 1); + output_counts->tx.p8x8[i].resize(TX_SIZES - 2); + } + output_counts->tx.tx_totals.resize(TX_SIZES); + + output_counts->mv.joints.resize(MV_JOINTS); + output_counts->mv.comps.resize(2); + for (int i = 0; i < 2; ++i) { + output_counts->mv.comps[i].sign.resize(2); + output_counts->mv.comps[i].classes.resize(MV_CLASSES); + output_counts->mv.comps[i].class0.resize(CLASS0_SIZE); + output_counts->mv.comps[i].bits.resize(MV_OFFSET_BITS); + for (int j = 0; j < MV_OFFSET_BITS; ++j) { + output_counts->mv.comps[i].bits[j].resize(2); + } + output_counts->mv.comps[i].class0_fp.resize(CLASS0_SIZE); + for (int j = 0; j < CLASS0_SIZE; ++j) { + output_counts->mv.comps[i].class0_fp[j].resize(MV_FP_SIZE); + } + output_counts->mv.comps[i].fp.resize(MV_FP_SIZE); + output_counts->mv.comps[i].class0_hp.resize(2); + output_counts->mv.comps[i].hp.resize(2); + } + + // Populate counts. + for (int i = 0; i < BLOCK_SIZE_GROUPS; ++i) { + for (int j = 0; j < INTRA_MODES; ++j) { + output_counts->y_mode[i][j] = input_counts->y_mode[i][j]; + } + } + for (int i = 0; i < INTRA_MODES; ++i) { + for (int j = 0; j < INTRA_MODES; ++j) { + output_counts->uv_mode[i][j] = input_counts->uv_mode[i][j]; + } + } + for (int i = 0; i < PARTITION_CONTEXTS; ++i) { + for (int j = 0; j < PARTITION_TYPES; ++j) { + output_counts->partition[i][j] = input_counts->partition[i][j]; + } + } + for (int i = 0; i < TX_SIZES; ++i) { + for (int j = 0; j < PLANE_TYPES; ++j) { + for (int k = 0; k < REF_TYPES; ++k) { + for (int l = 0; l < COEF_BANDS; ++l) { + for (int m = 0; m < COEFF_CONTEXTS; ++m) { + output_counts->eob_branch[i][j][k][l][m] = + input_counts->eob_branch[i][j][k][l][m]; + for (int n = 0; n < UNCONSTRAINED_NODES + 1; n++) { + output_counts->coef[i][j][k][l][m][n] = + input_counts->coef[i][j][k][l][m][n]; + } + } + } + } + } + } + for (int i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) { + for (int j = 0; j < SWITCHABLE_FILTERS; ++j) { + output_counts->switchable_interp[i][j] = + input_counts->switchable_interp[i][j]; + } + } + for (int i = 0; i < INTER_MODE_CONTEXTS; ++i) { + for (int j = 0; j < INTER_MODES; ++j) { + output_counts->inter_mode[i][j] = input_counts->inter_mode[i][j]; + } + } + for (int i = 0; i < INTRA_INTER_CONTEXTS; ++i) { + for (int j = 0; j < 2; ++j) { + output_counts->intra_inter[i][j] = input_counts->intra_inter[i][j]; + } + } + for (int i = 0; i < COMP_INTER_CONTEXTS; ++i) { + for (int j = 0; j < 2; ++j) { + output_counts->comp_inter[i][j] = input_counts->comp_inter[i][j]; + } + } + for (int i = 0; i < REF_CONTEXTS; ++i) { + for (int j = 0; j < 2; ++j) { + for (int k = 0; k < 2; ++k) { + output_counts->single_ref[i][j][k] = input_counts->single_ref[i][j][k]; + } + } + } + for (int i = 0; i < REF_CONTEXTS; ++i) { + for (int j = 0; j < 2; ++j) { + output_counts->comp_ref[i][j] = input_counts->comp_ref[i][j]; + } + } + for (int i = 0; i < SKIP_CONTEXTS; ++i) { + for (int j = 0; j < 2; ++j) { + output_counts->skip[i][j] = input_counts->skip[i][j]; + } + } + for (int i = 0; i < TX_SIZE_CONTEXTS; i++) { + for (int j = 0; j < TX_SIZES; j++) { + output_counts->tx.p32x32[i][j] = input_counts->tx.p32x32[i][j]; + } + for (int j = 0; j < TX_SIZES - 1; j++) { + output_counts->tx.p16x16[i][j] = input_counts->tx.p16x16[i][j]; + } + for (int j = 0; j < TX_SIZES - 2; j++) { + output_counts->tx.p8x8[i][j] = input_counts->tx.p8x8[i][j]; + } + } + for (int i = 0; i < TX_SIZES; i++) { + output_counts->tx.tx_totals[i] = input_counts->tx.tx_totals[i]; + } + for (int i = 0; i < MV_JOINTS; i++) { + output_counts->mv.joints[i] = input_counts->mv.joints[i]; + } + for (int k = 0; k < 2; k++) { + const nmv_component_counts *const comps_t = &input_counts->mv.comps[k]; + for (int i = 0; i < 2; i++) { + output_counts->mv.comps[k].sign[i] = comps_t->sign[i]; + output_counts->mv.comps[k].class0_hp[i] = comps_t->class0_hp[i]; + output_counts->mv.comps[k].hp[i] = comps_t->hp[i]; + } + for (int i = 0; i < MV_CLASSES; i++) { + output_counts->mv.comps[k].classes[i] = comps_t->classes[i]; + } + for (int i = 0; i < CLASS0_SIZE; i++) { + output_counts->mv.comps[k].class0[i] = comps_t->class0[i]; + for (int j = 0; j < MV_FP_SIZE; j++) { + output_counts->mv.comps[k].class0_fp[i][j] = comps_t->class0_fp[i][j]; + } + } + for (int i = 0; i < MV_OFFSET_BITS; i++) { + for (int j = 0; j < 2; j++) { + output_counts->mv.comps[k].bits[i][j] = comps_t->bits[i][j]; + } + } + for (int i = 0; i < MV_FP_SIZE; i++) { + output_counts->mv.comps[k].fp[i] = comps_t->fp[i]; + } + } +} + static void update_encode_frame_result( EncodeFrameResult *encode_frame_result, const ENCODE_FRAME_RESULT *encode_frame_info) { @@ -100,6 +323,8 @@ static void update_encode_frame_result( encode_frame_result->psnr = encode_frame_info->psnr; encode_frame_result->sse = encode_frame_info->sse; encode_frame_result->quantize_index = encode_frame_info->quantize_index; + update_frame_counts(&encode_frame_info->frame_counts, + &encode_frame_result->frame_counts); } static void IncreaseGroupOfPictureIndex(GroupOfPicture *group_of_picture) { -- cgit v1.2.3