Add recrf_rate and recrf_dist to Q Mode RC API

These fields are optional, but will either be available on all blocks
or on none (and likewise, should be present on all frames if they are
present on any).

The field TplFrameStats::rate_dist_present indicates whether the
fields in a frame are populated.

Also changed the width, height, row, and col fields to int16_t
to avoid increasing the memory footprint of the TPL stats any more
than necessary (b/241589513).
Before this CL, sizeof(TplBlockStats) = 64
After  this CL, sizeof(TplBlockStats) = 72

Bug: b/236983774
Change-Id: I29ad537a15887afa21846e31f7f5b889c60ea6f6
diff --git a/av1/ratectrl_qmode_interface.h b/av1/ratectrl_qmode_interface.h
index 1e4e5c6..da1da2e 100644
--- a/av1/ratectrl_qmode_interface.h
+++ b/av1/ratectrl_qmode_interface.h
@@ -24,8 +24,10 @@
 constexpr int kBlockRefCount = 2;
 
 struct MotionVector {
-  int row;          // subpel row
-  int col;          // subpel col
+  int row;  // subpel row
+  int col;  // subpel col
+  // TODO(b/241589513): Move this to TPLFrameStats; it's wasteful to code it
+  // separately for each block.
   int subpel_bits;  // number of fractional bits used by row/col
 };
 
@@ -48,12 +50,17 @@
 };
 
 struct TplBlockStats {
-  int height;  // pixel height
-  int width;   // pixel width
-  int row;     // pixel row of the top left corner
-  int col;     // pixel col of the top lef corner
+  int16_t height;  // Pixel height.
+  int16_t width;   // Pixel width.
+  int16_t row;     // Pixel row of the top left corner.
+  int16_t col;     // Pixel col of the top lef corner.
   int64_t intra_cost;
   int64_t inter_cost;
+
+  // Valid only if TplFrameStats::rate_dist_present is true:
+  int64_t recrf_rate;  // Bits when using recon as reference.
+  int64_t recrf_dist;  // Distortion when using recon as reference.
+
   std::array<MotionVector, kBlockRefCount> mv;
   std::array<int, kBlockRefCount> ref_frame_index;
 };
@@ -233,6 +240,7 @@
   int min_block_size;
   int frame_width;
   int frame_height;
+  bool rate_dist_present;  // True if recrf_rate and recrf_dist are populated.
   std::vector<TplBlockStats> block_stats_list;
 };
 
diff --git a/test/ratectrl_qmode_test.cc b/test/ratectrl_qmode_test.cc
index d950626..a4df92a 100644
--- a/test/ratectrl_qmode_test.cc
+++ b/test/ratectrl_qmode_test.cc
@@ -316,6 +316,7 @@
   frame_stats.min_block_size = min_block_size;
   frame_stats.frame_height = max_h * count;
   frame_stats.frame_width = max_w * count;
+  frame_stats.rate_dist_present = false;
   for (int i = 0; i < count; ++i) {
     for (int j = 0; j < count; ++j) {
       int h = max_h >> i;
@@ -1081,7 +1082,7 @@
 
   // Only frame 0 has TPL block stats.
   TplGopStats tpl_gop_stats;
-  tpl_gop_stats.frame_stats_list.assign(3, { 8, 176, 144, {} });
+  tpl_gop_stats.frame_stats_list.assign(3, { 8, 176, 144, false, {} });
   tpl_gop_stats.frame_stats_list[0] = CreateToyTplFrameStatsWithDiffSizes(8, 8);
 
   AV1RateControlQMode rc;