Update sending resolution only on top spatial layer frame.

Don't update frame resolution in sender stats if current frame is not
top spatial layer frame.

Bug: webrtc:9715
Change-Id: I8361f8ccf7e7d092d143291fc54ab20ae091954b
Reviewed-on: https://webrtc-review.googlesource.com/97608
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24595}
diff --git a/video/send_statistics_proxy_unittest.cc b/video/send_statistics_proxy_unittest.cc
index 4dbfc03..fba46b9 100644
--- a/video/send_statistics_proxy_unittest.cc
+++ b/video/send_statistics_proxy_unittest.cc
@@ -2177,6 +2177,43 @@
       kName, statistics_proxy_->GetStats().encoder_implementation_name.c_str());
 }
 
+TEST_F(SendStatisticsProxyTest, Vp9SvcLowSpatialLayerDoesNotUpdateResolution) {
+  static const int kEncodedWidth = 123;
+  static const int kEncodedHeight = 81;
+  EncodedImage encoded_image;
+  encoded_image._encodedWidth = kEncodedWidth;
+  encoded_image._encodedHeight = kEncodedHeight;
+  encoded_image.SetSpatialIndex(0);
+
+  CodecSpecificInfo codec_info;
+  codec_info.codecType = kVideoCodecVP9;
+
+  // For first picture, it is expected that low layer updates resolution.
+  codec_info.codecSpecific.VP9.end_of_picture = false;
+  statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
+  VideoSendStream::Stats stats = statistics_proxy_->GetStats();
+  EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].width);
+  EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].height);
+
+  // Top layer updates resolution.
+  encoded_image._encodedWidth = kEncodedWidth * 2;
+  encoded_image._encodedHeight = kEncodedHeight * 2;
+  codec_info.codecSpecific.VP9.end_of_picture = true;
+  statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
+  stats = statistics_proxy_->GetStats();
+  EXPECT_EQ(kEncodedWidth * 2, stats.substreams[config_.rtp.ssrcs[0]].width);
+  EXPECT_EQ(kEncodedHeight * 2, stats.substreams[config_.rtp.ssrcs[0]].height);
+
+  // Low layer of next frame doesn't update resolution.
+  encoded_image._encodedWidth = kEncodedWidth;
+  encoded_image._encodedHeight = kEncodedHeight;
+  codec_info.codecSpecific.VP9.end_of_picture = false;
+  statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
+  stats = statistics_proxy_->GetStats();
+  EXPECT_EQ(kEncodedWidth * 2, stats.substreams[config_.rtp.ssrcs[0]].width);
+  EXPECT_EQ(kEncodedHeight * 2, stats.substreams[config_.rtp.ssrcs[0]].height);
+}
+
 class ForcedFallbackTest : public SendStatisticsProxyTest {
  public:
   explicit ForcedFallbackTest(const std::string& field_trials)