diff --git a/webrtc/test/BUILD.gn b/webrtc/test/BUILD.gn index 9dd2472f9d..1480448698 100644 --- a/webrtc/test/BUILD.gn +++ b/webrtc/test/BUILD.gn @@ -226,6 +226,8 @@ if (!build_with_chromium) { 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/webrtc/test/testsupport/frame_writer.h b/webrtc/test/testsupport/frame_writer.h index 148f23338c..faab50edcf 100644 --- a/webrtc/test/testsupport/frame_writer.h +++ b/webrtc/test/testsupport/frame_writer.h @@ -83,19 +83,21 @@ class Y4mFrameWriterImpl : public YuvFrameWriterImpl { 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/webrtc/test/testsupport/jpeg_frame_writer.cc b/webrtc/test/testsupport/jpeg_frame_writer.cc index 483a2e02c5..8174cc207c 100644 --- a/webrtc/test/testsupport/jpeg_frame_writer.cc +++ b/webrtc/test/testsupport/jpeg_frame_writer.cc @@ -35,7 +35,10 @@ JpegFrameWriter::JpegFrameWriter(const std::string &output_filename) 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 rgb_buf(new uint8_t[rgb_len]); diff --git a/webrtc/test/testsupport/jpeg_frame_writer_ios.cc b/webrtc/test/testsupport/jpeg_frame_writer_ios.cc new file mode 100644 index 0000000000..835a8adc44 --- /dev/null +++ b/webrtc/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/webrtc/video/replay.cc b/webrtc/video/replay.cc index ed33a2892c..e23ff2920f 100644 --- a/webrtc/video/replay.cc +++ b/webrtc/video/replay.cc @@ -178,10 +178,8 @@ class FileRenderPassthrough : public rtc::VideoSinkInterface { 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/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc index 3882f71273..7caa6367b0 100644 --- a/webrtc/video/video_quality_test.cc +++ b/webrtc/video/video_quality_test.cc @@ -835,8 +835,6 @@ class VideoAnalyzer : public PacketReceiver, 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 @@ class VideoAnalyzer : public PacketReceiver, 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.