summaryrefslogtreecommitdiffstats
path: root/remoting/codec
diff options
context:
space:
mode:
authorsergeyu <sergeyu@chromium.org>2016-01-20 13:21:54 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-20 21:23:15 +0000
commit2e0319b8d2aa7544e2d51b0a7e7acd353cf578e3 (patch)
tree2b0eb45ef2e4ccd8e60ff912a02b05c51e0f17db /remoting/codec
parent7f7f15423695263a2b63232f783c05029beb4653 (diff)
downloadchromium_src-2e0319b8d2aa7544e2d51b0a7e7acd353cf578e3.zip
chromium_src-2e0319b8d2aa7544e2d51b0a7e7acd353cf578e3.tar.gz
chromium_src-2e0319b8d2aa7544e2d51b0a7e7acd353cf578e3.tar.bz2
Implement new video encoder performance tests, for VP9/VP8 comparison.
The old encoder perf tests (in VideoEncoderVpxTest) were not providing very realistic results because: - They were measuring performance on frames with random data. - They were testing the case when the whole frame is changing every time. - They were using real clock, which affects results. This change implements new tests that provide closer approximation to how the codec is being used. CyclicFrameGenerator added in this test will also be used to test performance of the new WebRTC-based protocol. Review URL: https://codereview.chromium.org/1601303002 Cr-Commit-Position: refs/heads/master@{#370491}
Diffstat (limited to 'remoting/codec')
-rw-r--r--remoting/codec/codec_test.cc44
-rw-r--r--remoting/codec/video_encoder_vpx.cc13
-rw-r--r--remoting/codec/video_encoder_vpx.h6
-rw-r--r--remoting/codec/video_encoder_vpx_perftest.cc64
4 files changed, 15 insertions, 112 deletions
diff --git a/remoting/codec/codec_test.cc b/remoting/codec/codec_test.cc
index 0c4f431..3da3793 100644
--- a/remoting/codec/codec_test.cc
+++ b/remoting/codec/codec_test.cc
@@ -343,48 +343,4 @@ void TestVideoEncoderDecoderGradient(VideoEncoder* encoder,
decoder_tester.VerifyResultsApprox(max_error_limit, mean_error_limit);
}
-float MeasureVideoEncoderFpsWithSize(VideoEncoder* encoder,
- const DesktopSize& size) {
- scoped_ptr<DesktopFrame> frame(PrepareFrame(size));
- frame->mutable_updated_region()->SetRect(DesktopRect::MakeSize(size));
- std::list<DesktopFrame*> frames;
- frames.push_back(frame.get());
- return MeasureVideoEncoderFpsWithFrames(encoder, frames);
-}
-
-float MeasureVideoEncoderFpsWithFrames(VideoEncoder* encoder,
- const std::list<DesktopFrame*>& frames) {
- const base::TimeDelta kTestTime = base::TimeDelta::FromSeconds(1);
-
- // Encode some frames to "warm up" the encoder (i.e. to let it set up initial
- // structures, establish a stable working set, etc), then encode at least
- // kMinimumFrameCount frames to measure the encoder's performance.
- const int kWarmUpFrameCount = 10;
- const int kMinimumFrameCount = 10;
- base::TimeTicks start_time;
- base::TimeDelta elapsed;
- std::list<DesktopFrame*> test_frames;
- int frame_count;
- for (frame_count = 0;
- (frame_count < kMinimumFrameCount + kWarmUpFrameCount ||
- elapsed < kTestTime);
- ++frame_count) {
- if (frame_count == kWarmUpFrameCount) {
- start_time = base::TimeTicks::Now();
- }
-
- if (test_frames.empty()) {
- test_frames = frames;
- }
- scoped_ptr<VideoPacket> packet = encoder->Encode(*test_frames.front());
- test_frames.pop_front();
-
- if (frame_count >= kWarmUpFrameCount) {
- elapsed = base::TimeTicks::Now() - start_time;
- }
- }
-
- return (frame_count * base::TimeDelta::FromSeconds(1)) / elapsed;
-}
-
} // namespace remoting
diff --git a/remoting/codec/video_encoder_vpx.cc b/remoting/codec/video_encoder_vpx.cc
index 57a1d5a..2a5894d 100644
--- a/remoting/codec/video_encoder_vpx.cc
+++ b/remoting/codec/video_encoder_vpx.cc
@@ -242,6 +242,10 @@ scoped_ptr<VideoEncoderVpx> VideoEncoderVpx::CreateForVP9() {
VideoEncoderVpx::~VideoEncoderVpx() {}
+void VideoEncoderVpx::SetTickClockForTests(base::TickClock* tick_clock) {
+ clock_ = tick_clock;
+}
+
void VideoEncoderVpx::SetLosslessEncode(bool want_lossless) {
if (use_vp9_ && (want_lossless != lossless_encode_)) {
lossless_encode_ = want_lossless;
@@ -296,7 +300,7 @@ scoped_ptr<VideoPacket> VideoEncoderVpx::Encode(
}
// Do the actual encoding.
- int timestamp = (base::TimeTicks::Now() - timestamp_base_).InMilliseconds();
+ int timestamp = (clock_->NowTicks() - timestamp_base_).InMilliseconds();
vpx_codec_err_t ret = vpx_codec_encode(
codec_.get(), image_.get(), timestamp, 1, 0, VPX_DL_REALTIME);
DCHECK_EQ(ret, VPX_CODEC_OK)
@@ -345,8 +349,9 @@ scoped_ptr<VideoPacket> VideoEncoderVpx::Encode(
}
VideoEncoderVpx::VideoEncoderVpx(bool use_vp9)
- : use_vp9_(use_vp9), encode_unchanged_frame_(false) {
-}
+ : use_vp9_(use_vp9),
+ encode_unchanged_frame_(false),
+ clock_(&default_tick_clock_) {}
void VideoEncoderVpx::Configure(const webrtc::DesktopSize& size) {
DCHECK(use_vp9_ || !lossless_color_);
@@ -376,7 +381,7 @@ void VideoEncoderVpx::Configure(const webrtc::DesktopSize& size) {
// (Re)Set the base for frame timestamps if the codec is being (re)created.
if (!codec_) {
- timestamp_base_ = base::TimeTicks::Now();
+ timestamp_base_ = clock_->NowTicks();
}
// Fetch a default configuration for the desired codec.
diff --git a/remoting/codec/video_encoder_vpx.h b/remoting/codec/video_encoder_vpx.h
index 83c3549..35d5f67 100644
--- a/remoting/codec/video_encoder_vpx.h
+++ b/remoting/codec/video_encoder_vpx.h
@@ -9,6 +9,7 @@
#include "base/callback.h"
#include "base/macros.h"
+#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "remoting/codec/scoped_vpx_codec.h"
#include "remoting/codec/video_encoder.h"
@@ -31,6 +32,8 @@ class VideoEncoderVpx : public VideoEncoder {
~VideoEncoderVpx() override;
+ void SetTickClockForTests(base::TickClock* tick_clock);
+
// VideoEncoder interface.
void SetLosslessEncode(bool want_lossless) override;
void SetLosslessColor(bool want_lossless) override;
@@ -84,6 +87,9 @@ class VideoEncoderVpx : public VideoEncoder {
// Used to help initialize VideoPackets from DesktopFrames.
VideoEncoderHelper helper_;
+ base::DefaultTickClock default_tick_clock_;
+ base::TickClock* clock_;
+
DISALLOW_COPY_AND_ASSIGN(VideoEncoderVpx);
};
diff --git a/remoting/codec/video_encoder_vpx_perftest.cc b/remoting/codec/video_encoder_vpx_perftest.cc
deleted file mode 100644
index 0c2cf7f..0000000
--- a/remoting/codec/video_encoder_vpx_perftest.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/codec/video_encoder_vpx.h"
-
-#include <stddef.h>
-
-#include <limits>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "remoting/codec/codec_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
-
-using webrtc::DesktopSize;
-
-namespace remoting {
-
-// Measure the performance of the VP8 encoder.
-TEST(VideoEncoderVpxTest, MeasureVp8Fps) {
- scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP8());
-
- const DesktopSize kFrameSizes[] = {
- DesktopSize(1280, 1024), DesktopSize(1920, 1200)
- };
-
- for (size_t i = 0; i < arraysize(kFrameSizes); ++i) {
- float fps =
- MeasureVideoEncoderFpsWithSize(encoder.get(), kFrameSizes[i]);
- LOG(ERROR) << kFrameSizes[i].width() << "x" << kFrameSizes[i].height()
- << ": " << fps << "fps";
- }
-}
-
-// Measure the performance of the VP9 encoder.
-TEST(VideoEncoderVpxTest, MeasureVp9Fps) {
- const DesktopSize kFrameSizes[] = {
- DesktopSize(1280, 1024), DesktopSize(1920, 1200)
- };
-
- for (int lossless_mode = 0; lossless_mode < 4; ++lossless_mode) {
- bool lossless_color = lossless_mode & 1;
- bool lossless_encode = lossless_mode & 2;
-
- scoped_ptr<VideoEncoderVpx> encoder(VideoEncoderVpx::CreateForVP9());
- encoder->SetLosslessColor(lossless_color);
- encoder->SetLosslessEncode(lossless_encode);
-
- for (size_t i = 0; i < arraysize(kFrameSizes); ++i) {
- float fps =
- MeasureVideoEncoderFpsWithSize(encoder.get(), kFrameSizes[i]);
- LOG(ERROR) << kFrameSizes[i].width() << "x" << kFrameSizes[i].height()
- << "(" << (lossless_encode ? "lossless" : "lossy ") << ")"
- << "(" << (lossless_color ? "I444" : "I420") << ")"
- << ": " << fps << "fps";
- }
- }
-}
-
-} // namespace remoting