Skip SSIM calculation in real time mode.

SSIM calculation is not optimized. It takes ~100ms to process 720p frame
on Galaxy S8.

Bug: none
Change-Id: I51cc26d81124f06b2dfb27814edf2e4ae58141ce
Reviewed-on: https://webrtc-review.googlesource.com/c/121762
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26730}
diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
index 01b09bf..b59f35c 100644
--- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
+++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
@@ -539,8 +539,13 @@
   if (quality_thresholds) {
     EXPECT_GT(video_stat.avg_psnr, quality_thresholds->min_avg_psnr);
     EXPECT_GT(video_stat.min_psnr, quality_thresholds->min_min_psnr);
-    EXPECT_GT(video_stat.avg_ssim, quality_thresholds->min_avg_ssim);
-    EXPECT_GT(video_stat.min_ssim, quality_thresholds->min_min_ssim);
+
+    // SSIM calculation is not optimized and thus it is disabled in real-time
+    // mode.
+    if (!config_.encode_in_real_time) {
+      EXPECT_GT(video_stat.avg_ssim, quality_thresholds->min_avg_ssim);
+      EXPECT_GT(video_stat.min_ssim, quality_thresholds->min_min_ssim);
+    }
   }
 
   if (bs_thresholds) {
diff --git a/modules/video_coding/codecs/test/videoprocessor.cc b/modules/video_coding/codecs/test/videoprocessor.cc
index fafb676..4192540 100644
--- a/modules/video_coding/codecs/test/videoprocessor.cc
+++ b/modules/video_coding/codecs/test/videoprocessor.cc
@@ -109,7 +109,8 @@
 
 void CalculateFrameQuality(const I420BufferInterface& ref_buffer,
                            const I420BufferInterface& dec_buffer,
-                           FrameStatistics* frame_stat) {
+                           FrameStatistics* frame_stat,
+                           bool calc_ssim) {
   if (ref_buffer.width() != dec_buffer.width() ||
       ref_buffer.height() != dec_buffer.height()) {
     RTC_CHECK_GE(ref_buffer.width(), dec_buffer.width());
@@ -126,7 +127,7 @@
               scaled_buffer->width(), scaled_buffer->height(),
               libyuv::kFilterBox);
 
-    CalculateFrameQuality(*scaled_buffer, dec_buffer, frame_stat);
+    CalculateFrameQuality(*scaled_buffer, dec_buffer, frame_stat, calc_ssim);
   } else {
     const uint64_t sse_y = libyuv::ComputeSumSquareErrorPlane(
         dec_buffer.DataY(), dec_buffer.StrideY(), ref_buffer.DataY(),
@@ -149,7 +150,10 @@
     frame_stat->psnr_v = libyuv::SumSquareErrorToPsnr(sse_v, num_u_samples);
     frame_stat->psnr = libyuv::SumSquareErrorToPsnr(
         sse_y + sse_u + sse_v, num_y_samples + 2 * num_u_samples);
-    frame_stat->ssim = I420SSIM(ref_buffer, dec_buffer);
+
+    if (calc_ssim) {
+      frame_stat->ssim = I420SSIM(ref_buffer, dec_buffer);
+    }
   }
 }
 
@@ -495,9 +499,12 @@
     RTC_CHECK(reference_frame != input_frames_.cend())
         << "The codecs are either buffering too much, dropping too much, or "
            "being too slow relative the input frame rate.";
+
+    // SSIM calculation is not optimized. Skip it in real-time mode.
+    const bool calc_ssim = !config_.encode_in_real_time;
     CalculateFrameQuality(
         *reference_frame->second.video_frame_buffer()->ToI420(),
-        *decoded_frame.video_frame_buffer()->ToI420(), frame_stat);
+        *decoded_frame.video_frame_buffer()->ToI420(), frame_stat, calc_ssim);
 
     // Erase all buffered input frames that we have moved past for all
     // simulcast/spatial layers. Never buffer more than