shithub: libvpx

Download patch

ref: e7aa1e3630bf695a739cf455f3eafe7d135608ef
parent: 483bcb310dea5a4fcb91af343408b14a9158ae29
author: angiebird <angiebird@google.com>
date: Mon Mar 2 15:04:11 EST 2020

Add unit test for ref_frame_info

Fix several bugs to make the test pass.
1) Move update_frame_indexes() out of show_frame check.
2) Init coding_indexes[i] to -1 when key frame appears
3) Fix a bug in PostUpdateRefFrameInfo()

Change-Id: Ie7c70a1d460e5b89475a1aef77416fc9a88387e1

--- a/test/simple_encode_test.cc
+++ b/test/simple_encode_test.cc
@@ -92,6 +92,8 @@
       EXPECT_GE(encode_frame_result.psnr, 34)
           << "The psnr is supposed to be greater than 34 given the "
              "target_bitrate 1000 kbps";
+      EXPECT_EQ(encode_frame_result.ref_frame_info,
+                encode_frame_list[group_index].ref_frame_info);
       total_data_bit_size += encode_frame_result.coding_data_bit_size;
       ++frame_coding_index;
     }
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -283,6 +283,8 @@
 
 static INLINE void update_frame_indexes(VP9_COMMON *cm, int show_frame) {
   if (show_frame) {
+    // Don't increment frame counters if this was an altref buffer
+    // update not a real frame
     ++cm->current_video_frame;
   }
 #if CONFIG_RATE_CTRL
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -5394,11 +5394,9 @@
 
   if (cm->show_frame) {
     vp9_swap_mi_and_prev_mi(cm);
-    // Don't increment frame counters if this was an altref buffer
-    // update not a real frame
-    update_frame_indexes(cm, cm->show_frame);
     if (cpi->use_svc) vp9_inc_frame_in_layer(cpi);
   }
+  update_frame_indexes(cm, cm->show_frame);
 
   if (cpi->use_svc) {
     cpi->svc
@@ -7338,7 +7336,7 @@
       encode_frame_result->ref_frame_coding_indexes[i] =
           ref_frame_bufs[i]->frame_coding_index;
       encode_frame_result->ref_frame_valid_list[i] =
-          !(ref_frame_flags & inter_ref_flags[i]);
+          (ref_frame_flags & inter_ref_flags[i]) != 0;
     }
   } else {
     // No reference frame is available when this is a key frame.
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -499,8 +499,8 @@
       encode_frame_result->coding_data_byte_size * 8;
   encode_frame_result->show_idx = encode_frame_info->show_idx;
   encode_frame_result->coding_idx = encode_frame_info->frame_coding_index;
+  assert(kRefFrameTypeMax == MAX_INTER_REF_FRAMES);
   for (int i = 0; i < kRefFrameTypeMax; ++i) {
-    assert(kRefFrameTypeMax == MAX_INTER_REF_FRAMES);
     encode_frame_result->ref_frame_info.coding_indexes[i] =
         encode_frame_info->ref_frame_coding_indexes[i];
     encode_frame_result->ref_frame_info.valid_list[i] =
@@ -532,9 +532,18 @@
          group_of_picture.encode_frame_list.size();
 }
 
+bool operator==(const RefFrameInfo &a, const RefFrameInfo &b) {
+  bool match = true;
+  for (int i = 0; i < kRefFrameTypeMax; ++i) {
+    match &= a.coding_indexes[i] == b.coding_indexes[i];
+    match &= a.valid_list[i] == b.valid_list[i];
+  }
+  return match;
+}
+
 static void InitRefFrameInfo(RefFrameInfo *ref_frame_info) {
   for (int i = 0; i < kRefFrameTypeMax; ++i) {
-    ref_frame_info->coding_indexes[i] = 0;
+    ref_frame_info->coding_indexes[i] = -1;
     ref_frame_info->valid_list[i] = 0;
   }
 }
@@ -587,7 +596,7 @@
   }
 
   if (past_index == last_index) {
-    ref_frame_valid_list[kRefFrameTypeLast] = 0;
+    ref_frame_valid_list[kRefFrameTypePast] = 0;
   }
 
   if (future_index == last_index) {
@@ -864,6 +873,8 @@
       &cpi->oxcf, &cpi->frame_info, &cpi->twopass.first_pass_info,
       key_frame_show_index, cpi->rc.min_gf_interval);
   assert(key_frame_group_size_ > 0);
+  // Init the reference frame info when a new key frame group appears.
+  InitRefFrameInfo(&ref_frame_info_);
 }
 
 void SimpleEncode::PostUpdateKeyFrameGroupIndex(FrameType frame_type) {
@@ -895,15 +906,18 @@
     // Only kFrameTypeAltRef is not a show frame
     ++show_frame_count_;
   }
-  IncreaseGroupOfPictureIndex(&group_of_picture_);
-  if (IsGroupOfPictureFinished(group_of_picture_)) {
-    UpdateGroupOfPicture(impl_ptr_->cpi, frame_coding_index_, ref_frame_info_,
-                         &group_of_picture_);
-  }
 
   PostUpdateKeyFrameGroupIndex(encode_frame_result.frame_type);
   if (key_frame_group_index_ == key_frame_group_size_) {
     UpdateKeyFrameGroup(show_frame_count_);
+  }
+
+  IncreaseGroupOfPictureIndex(&group_of_picture_);
+  if (IsGroupOfPictureFinished(group_of_picture_)) {
+    // This function needs to be called after ref_frame_info_ is updated
+    // properly in PostUpdateRefFrameInfo() and UpdateKeyFrameGroup().
+    UpdateGroupOfPicture(impl_ptr_->cpi, frame_coding_index_, ref_frame_info_,
+                         &group_of_picture_);
   }
 }
 
--- a/vp9/simple_encode.h
+++ b/vp9/simple_encode.h
@@ -86,6 +86,8 @@
   int valid_list[kRefFrameTypeMax];
 };
 
+bool operator==(const RefFrameInfo &a, const RefFrameInfo &b);
+
 struct EncodeFrameInfo {
   int show_idx;
 
@@ -363,7 +365,8 @@
   // The index for the to-be-coded show frame in the key frame group.
   int key_frame_group_index_;
 
-  // Update key_frame_group_size_ and reset key_frame_group_index_.
+  // Update key_frame_group_size_, reset key_frame_group_index_ and init
+  // ref_frame_info_.
   void UpdateKeyFrameGroup(int key_frame_show_index);
 
   // Update key_frame_group_index_.