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-Commit-Position: refs/heads/master@{#19558}
This commit is contained in:
ilnik
2017-08-28 06:08:33 -07:00
committed by Commit Bot
parent b32aaf97bd
commit d986d76806
6 changed files with 41 additions and 9 deletions

View File

@ -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 = [

View File

@ -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

View File

@ -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<uint8_t[]> rgb_buf(new uint8_t[rgb_len]);

View File

@ -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

View File

@ -178,10 +178,8 @@ class FileRenderPassthrough : public rtc::VideoSinkInterface<VideoFrame> {
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_;

View File

@ -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.