diff options
author | Jerome Jiang <jianj@google.com> | 2023-05-31 19:31:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-05-31 19:31:04 +0000 |
commit | 575bd73f6118a88c5a0cf1d27a8ec9b5bda8c278 (patch) | |
tree | 388a7519c6731ec2d1eb5a0b473ce911d5aececd | |
parent | 60ee1b149bd3de8e53857ff5a9f7f19d9398144e (diff) | |
parent | 1aff4a5655855c20b6766a91b9dacc8d78279c92 (diff) | |
download | libvpx-575bd73f6118a88c5a0cf1d27a8ec9b5bda8c278.tar libvpx-575bd73f6118a88c5a0cf1d27a8ec9b5bda8c278.tar.gz libvpx-575bd73f6118a88c5a0cf1d27a8ec9b5bda8c278.tar.bz2 libvpx-575bd73f6118a88c5a0cf1d27a8ec9b5bda8c278.zip |
Merge "Trim tpl stats by 2 extra frames" into main
-rw-r--r-- | vp9/encoder/vp9_tpl_model.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/vp9/encoder/vp9_tpl_model.c b/vp9/encoder/vp9_tpl_model.c index 9f4bafdf8..8d203bbf4 100644 --- a/vp9/encoder/vp9_tpl_model.c +++ b/vp9/encoder/vp9_tpl_model.c @@ -20,8 +20,8 @@ #include "vp9/encoder/vp9_encoder.h" #include "vp9/encoder/vp9_tpl_model.h" -static void init_gop_frames(VP9_COMP *cpi, GF_PICTURE *gf_picture, - const GF_GROUP *gf_group, int *tpl_group_frames) { +static int init_gop_frames(VP9_COMP *cpi, GF_PICTURE *gf_picture, + const GF_GROUP *gf_group, int *tpl_group_frames) { VP9_COMMON *cm = &cpi->common; int frame_idx = 0; int i; @@ -148,6 +148,8 @@ static void init_gop_frames(VP9_COMP *cpi, GF_PICTURE *gf_picture, ++extend_frame_count; ++frame_gop_offset; } + + return extend_frame_count; } static void init_tpl_stats(VP9_COMP *cpi) { @@ -1245,6 +1247,35 @@ static void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, } } +static void trim_tpl_stats(struct vpx_internal_error_info *error_info, + VpxTplGopStats *tpl_gop_stats, int extra_frames) { + int i; + VpxTplFrameStats *new_frame_stats; + const int new_size = tpl_gop_stats->size - extra_frames; + if (tpl_gop_stats->size <= extra_frames) + vpx_internal_error( + error_info, VPX_CODEC_ERROR, + "The number of frames in VpxTplGopStats is fewer than expected."); + CHECK_MEM_ERROR(error_info, new_frame_stats, + vpx_calloc(new_size, sizeof(*new_frame_stats))); + for (i = 0; i < new_size; i++) { + VpxTplFrameStats *frame_stats = &tpl_gop_stats->frame_stats_list[i]; + const int num_blocks = frame_stats->num_blocks; + new_frame_stats[i].num_blocks = frame_stats->num_blocks; + new_frame_stats[i].frame_width = frame_stats->frame_width; + new_frame_stats[i].frame_height = frame_stats->frame_height; + new_frame_stats[i].num_blocks = num_blocks; + CHECK_MEM_ERROR( + error_info, new_frame_stats[i].block_stats_list, + vpx_calloc(num_blocks, sizeof(*new_frame_stats[i].block_stats_list))); + memcpy(new_frame_stats[i].block_stats_list, frame_stats->block_stats_list, + num_blocks * sizeof(*new_frame_stats[i].block_stats_list)); + } + free_tpl_frame_stats_list(tpl_gop_stats); + tpl_gop_stats->size = new_size; + tpl_gop_stats->frame_stats_list = new_frame_stats; +} + #if CONFIG_NON_GREEDY_MV #define DUMP_TPL_STATS 0 #if DUMP_TPL_STATS @@ -1456,9 +1487,11 @@ void vp9_setup_tpl_stats(VP9_COMP *cpi) { const GF_GROUP *gf_group = &cpi->twopass.gf_group; int tpl_group_frames = 0; int frame_idx; + int extended_frame_count; cpi->tpl_bsize = BLOCK_32X32; - init_gop_frames(cpi, gf_picture, gf_group, &tpl_group_frames); + extended_frame_count = + init_gop_frames(cpi, gf_picture, gf_group, &tpl_group_frames); init_tpl_stats(cpi); @@ -1470,6 +1503,11 @@ void vp9_setup_tpl_stats(VP9_COMP *cpi) { if (gf_picture[frame_idx].update_type == USE_BUF_FRAME) continue; mc_flow_dispenser(cpi, gf_picture, frame_idx, cpi->tpl_bsize); } + + // TPL stats has extra frames from next GOP. Trim those extra frames for + // Qmode. + trim_tpl_stats(&cpi->common.error, &cpi->tpl_gop_stats, extended_frame_count); + #if CONFIG_NON_GREEDY_MV cpi->tpl_ready = 1; #if DUMP_TPL_STATS |