Update jpeg writer to compile on iOS and document it better

Original implementation of jpeg writer didn't compile on iOS at all.
This required clients to exclude some code using defines, which leads to
more complicated code.

Now, instead, jpeg writer will compile but will do nothing on iOS. Clients'
code don't need any additional checks now.

BUG=none

Review-Url: https://codereview.webrtc.org/3004603002
Cr-Original-Commit-Position: refs/heads/master@{#19558}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: d986d768061f45a1d34ab8e97406ebcb6c15618a
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 9dd2472..1480448 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -226,6 +226,8 @@
     if (!is_ios) {
       deps += [ "//third_party:jpeg" ]
       sources += [ "testsupport/jpeg_frame_writer.cc" ]
+    } else {
+      sources += [ "testsupport/jpeg_frame_writer_ios.cc" ]
     }
 
     public_deps = [
diff --git a/test/testsupport/frame_writer.h b/test/testsupport/frame_writer.h
index 148f233..faab50e 100644
--- a/test/testsupport/frame_writer.h
+++ b/test/testsupport/frame_writer.h
@@ -83,19 +83,21 @@
   const int frame_rate_;
 };
 
-// LibJpeg is not available on iOS
-#if !defined(is_ios)
+// LibJpeg is not available on iOS. This class will do nothing on iOS.
 class JpegFrameWriter {
  public:
   JpegFrameWriter(const std::string &output_filename);
+  // Quality can be from 0 (worst) to 100 (best). Best quality is still lossy.
+  // WriteFrame can be called only once. Subsequent calls will fail.
   bool WriteFrame(const VideoFrame& input_frame, int quality);
 
+#if !defined(WEBRTC_IOS)
  private:
   bool frame_written_;
   const std::string output_filename_;
   FILE* output_file_;
-};
 #endif
+};
 
 }  // namespace test
 }  // namespace webrtc
diff --git a/test/testsupport/jpeg_frame_writer.cc b/test/testsupport/jpeg_frame_writer.cc
index 483a2e0..8174cc2 100644
--- a/test/testsupport/jpeg_frame_writer.cc
+++ b/test/testsupport/jpeg_frame_writer.cc
@@ -35,7 +35,10 @@
       output_file_(nullptr) {}
 
 bool JpegFrameWriter::WriteFrame(const VideoFrame& input_frame, int quality) {
-  RTC_CHECK(!frame_written_) << "Only a single frame can be saved to Jpeg.";
+  if (frame_written_) {
+    LOG(LS_ERROR) << "Only a single frame can be saved to Jpeg.";
+    return false;
+  }
   const int kColorPlanes = 3;  // R, G and B.
   size_t rgb_len = input_frame.height() * input_frame.width() * kColorPlanes;
   std::unique_ptr<uint8_t[]> rgb_buf(new uint8_t[rgb_len]);
diff --git a/test/testsupport/jpeg_frame_writer_ios.cc b/test/testsupport/jpeg_frame_writer_ios.cc
new file mode 100644
index 0000000..835a8ad
--- /dev/null
+++ b/test/testsupport/jpeg_frame_writer_ios.cc
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/rtc_base/checks.h"
+#include "webrtc/rtc_base/logging.h"
+#include "webrtc/test/testsupport/frame_writer.h"
+
+
+namespace webrtc {
+namespace test {
+
+JpegFrameWriter::JpegFrameWriter(const std::string& /*output_filename*/) {}
+
+bool JpegFrameWriter::WriteFrame(const VideoFrame& /*input_frame*/,
+                                 int /*quality*/) {
+  LOG(LS_WARNING) << "Libjpeg isn't available on IOS. Jpeg frame writer is not "
+      "supported. No frame will be saved.";
+  // Don't fail.
+  return true;
+}
+
+}  // namespace test
+}  // namespace webrtc
diff --git a/video/replay.cc b/video/replay.cc
index ed33a28..e23ff29 100644
--- a/video/replay.cc
+++ b/video/replay.cc
@@ -178,10 +178,8 @@
     filename << basename_ << count_++ << "_" << video_frame.timestamp()
              << ".jpg";
 
-#if !defined(WEBRTC_IOS)
     test::JpegFrameWriter frame_writer(filename.str());
     RTC_CHECK(frame_writer.WriteFrame(video_frame, 100));
-#endif
   }
 
   const std::string basename_;
diff --git a/video/video_quality_test.cc b/video/video_quality_test.cc
index 3882f71..7caa636 100644
--- a/video/video_quality_test.cc
+++ b/video/video_quality_test.cc
@@ -835,8 +835,6 @@
     PrintResult("memory_usage", memory_usage_, " bytes");
 #endif
 
-    // LibJpeg is not available on iOS.
-#if !defined(WEBRTC_IOS)
     // Saving only the worst frame for manual analysis. Intention here is to
     // only detect video corruptions and not to track picture quality. Thus,
     // jpeg is used here.
@@ -850,7 +848,6 @@
       RTC_CHECK(frame_writer.WriteFrame(worst_frame_->frame,
                                         100 /*best quality*/));
     }
-#endif
 
     //  Disable quality check for quick test, as quality checks may fail
     //  because too few samples were collected.