summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Jiang <jianj@google.com>2023-05-26 12:02:36 -0400
committerJerome Jiang <jianj@google.com>2023-05-31 14:26:49 -0400
commit1aff4a5655855c20b6766a91b9dacc8d78279c92 (patch)
tree210f728d5a888d9be4a17f74ce5fb26401347c11
parentad5677eafceac4eccf7a7fd506a4e1f081cea22d (diff)
downloadlibvpx-1aff4a5655855c20b6766a91b9dacc8d78279c92.tar
libvpx-1aff4a5655855c20b6766a91b9dacc8d78279c92.tar.gz
libvpx-1aff4a5655855c20b6766a91b9dacc8d78279c92.tar.bz2
libvpx-1aff4a5655855c20b6766a91b9dacc8d78279c92.zip
Trim tpl stats by 2 extra frames
Not applicable to the last GOP. Bug: b/284162396 Change-Id: I55b7e04e9fc4b68a08ce3e00b10743823c828954
-rw-r--r--vp9/encoder/vp9_tpl_model.c44
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