#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;
++extend_frame_count;
++frame_gop_offset;
}
+
+ return extend_frame_count;
}
static void init_tpl_stats(VP9_COMP *cpi) {
}
}
+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
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);
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