Fix frame offset in lookahead for tpl tool
Change-Id: I6fccc10c3683129b71c1f8471e500fd06f580ec5
diff --git a/av1/encoder/firstpass.h b/av1/encoder/firstpass.h
index 1b8636c..a6c5336 100644
--- a/av1/encoder/firstpass.h
+++ b/av1/encoder/firstpass.h
@@ -119,6 +119,7 @@
unsigned char arf_src_offset[MAX_STATIC_GF_GROUP_LENGTH + 1];
unsigned char arf_update_idx[MAX_STATIC_GF_GROUP_LENGTH + 1];
unsigned char arf_pos_in_gf[MAX_STATIC_GF_GROUP_LENGTH + 1];
+ unsigned char frame_gop_index[MAX_STATIC_GF_GROUP_LENGTH + 1];
unsigned char pyramid_level[MAX_STATIC_GF_GROUP_LENGTH + 1];
unsigned char pyramid_height;
unsigned char pyramid_lvl_nodes[MAX_PYRAMID_LVL];
diff --git a/av1/encoder/gop_structure.c b/av1/encoder/gop_structure.c
index 73cb0ed..66f96b3 100644
--- a/av1/encoder/gop_structure.c
+++ b/av1/encoder/gop_structure.c
@@ -42,6 +42,7 @@
gf_group->arf_src_offset[*frame_ind] = 0;
gf_group->arf_pos_in_gf[*frame_ind] = 0;
gf_group->arf_update_idx[*frame_ind] = arf_ind;
+ gf_group->frame_gop_index[*frame_ind] = start;
gf_group->pyramid_level[*frame_ind] = MIN_PYRAMID_LVL;
++gf_group->pyramid_lvl_nodes[MIN_PYRAMID_LVL];
++(*frame_ind);
@@ -55,6 +56,7 @@
gf_group->arf_src_offset[*frame_ind] = m - start - 1;
gf_group->arf_pos_in_gf[*frame_ind] = 0;
gf_group->arf_update_idx[*frame_ind] = 1; // mark all internal ARF 1
+ gf_group->frame_gop_index[*frame_ind] = m;
gf_group->pyramid_level[*frame_ind] = level;
++gf_group->pyramid_lvl_nodes[level];
++(*frame_ind);
@@ -67,6 +69,7 @@
gf_group->arf_src_offset[*frame_ind] = 0;
gf_group->arf_pos_in_gf[*frame_ind] = arf_pos_in_gf; // For bit allocation.
gf_group->arf_update_idx[*frame_ind] = 1;
+ gf_group->frame_gop_index[*frame_ind] = m;
gf_group->pyramid_level[*frame_ind] = MIN_PYRAMID_LVL;
++(*frame_ind);
@@ -101,6 +104,7 @@
gf_group->arf_src_offset[frame_index] = gf_interval - 1;
gf_group->arf_pos_in_gf[frame_index] = 0;
gf_group->arf_update_idx[frame_index] = 0;
+ gf_group->frame_gop_index[frame_index] = gf_interval;
gf_group->pyramid_level[frame_index] = gf_group->pyramid_height;
++frame_index;
}
diff --git a/av1/encoder/tpl_model.c b/av1/encoder/tpl_model.c
index 79afb6d..b4705af 100644
--- a/av1/encoder/tpl_model.c
+++ b/av1/encoder/tpl_model.c
@@ -470,15 +470,13 @@
int alt_index = -1;
int lst_index = -1;
int extend_frame_count = 0;
+ int frame_gop_offset = 0;
int pframe_qindex = cpi->tpl_stats[2].base_qindex;
RefCntBuffer *frame_bufs = cm->buffer_pool->frame_bufs;
int recon_frame_index[INTER_REFS_PER_FRAME + 1] = { -1, -1, -1, -1,
-1, -1, -1, -1 };
- // TODO(jingning): To be used later for gf frame type parsing.
- (void)gf_group;
-
for (i = 0; i < FRAME_BUFFERS && frame_idx < INTER_REFS_PER_FRAME + 1; ++i) {
if (frame_bufs[i].ref_count == 0) {
alloc_frame_mvs(cm, &frame_bufs[i]);
@@ -522,8 +520,9 @@
// Initialize P frames
for (frame_idx = 2; frame_idx < MAX_LAG_BUFFERS; ++frame_idx) {
- struct lookahead_entry *buf =
- av1_lookahead_peek(cpi->lookahead, frame_idx - 2);
+ struct lookahead_entry *buf;
+ frame_gop_offset = gf_group->frame_gop_index[frame_idx];
+ buf = av1_lookahead_peek(cpi->lookahead, frame_gop_offset - 1);
if (buf == NULL) break;
@@ -543,11 +542,12 @@
lst_index = AOMMAX(0, frame_idx - 1);
alt_index = -1;
++frame_idx;
+ ++frame_gop_offset;
// Extend two frames outside the current gf group.
for (; frame_idx < MAX_LAG_BUFFERS && extend_frame_count < 2; ++frame_idx) {
struct lookahead_entry *buf =
- av1_lookahead_peek(cpi->lookahead, frame_idx - 2);
+ av1_lookahead_peek(cpi->lookahead, frame_gop_offset - 1);
if (buf == NULL) break;
@@ -561,6 +561,7 @@
lst_index = frame_idx;
++*tpl_group_frames;
++extend_frame_count;
+ ++frame_gop_offset;
}
}