keyframe_test: use a fixed speed step for realtime
The lower complexity modes may not generate a keyframe automatically.
This behavior was found when running under Valgrind, as the slow
performance caused the speed selection to pick lower complexities than
when running natively. Instead, use a fixed complexity for the
realtime auto keyframe test.
Affected tests:
AllModes/KeyframeTest.TestAutoKeyframe/0
Change-Id: I44e3f44e125ad587c293ab5ece29511d7023be9b
diff --git a/test/encode_test_driver.cc b/test/encode_test_driver.cc
index d7aaf6b..d40256a 100644
--- a/test/encode_test_driver.cc
+++ b/test/encode_test_driver.cc
@@ -109,6 +109,7 @@
again = video->img() != NULL;
PreEncodeFrameHook(video);
+ PreEncodeFrameHook(video, &encoder);
encoder.EncodeFrame(video, flags_);
CxDataIterator iter = encoder.GetCxData();
diff --git a/test/encode_test_driver.h b/test/encode_test_driver.h
index 2fb627c..de47830 100644
--- a/test/encode_test_driver.h
+++ b/test/encode_test_driver.h
@@ -101,6 +101,11 @@
EncodeFrame(video, 0);
}
+ void Control(int ctrl_id, int arg) {
+ const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg);
+ ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError();
+ }
+
void set_deadline(unsigned long deadline) {
deadline_ = deadline;
}
@@ -158,6 +163,7 @@
// Hook to be called before encoding a frame.
virtual void PreEncodeFrameHook(VideoSource *video) {}
+ virtual void PreEncodeFrameHook(VideoSource *video, Encoder *encoder) {}
// Hook to be called on every compressed data packet.
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {}
diff --git a/test/keyframe_test.cc b/test/keyframe_test.cc
index aacccb1..4244f61 100644
--- a/test/keyframe_test.cc
+++ b/test/keyframe_test.cc
@@ -24,15 +24,19 @@
kf_count_ = 0;
kf_count_max_ = INT_MAX;
kf_do_force_kf_ = false;
+ set_cpu_used_ = 0;
}
virtual bool Continue() {
return !HasFatalFailure() && !abort_;
}
- virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video) {
+ virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
+ ::libvpx_test::Encoder *encoder) {
if (kf_do_force_kf_)
flags_ = (video->frame() % 3) ? 0 : VPX_EFLAG_FORCE_KF;
+ if (set_cpu_used_ && video->frame() == 1)
+ encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
}
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
@@ -47,6 +51,7 @@
int kf_count_;
int kf_count_max_;
std::vector<vpx_codec_pts_t> kf_pts_list_;
+ int set_cpu_used_;
};
TEST_P(KeyframeTest, TestRandomVideoSource) {
@@ -101,6 +106,13 @@
cfg_.kf_mode = VPX_KF_AUTO;
kf_do_force_kf_ = false;
+ // Force a deterministic speed step in Real Time mode, as the faster modes
+ // may not produce a keyframe like we expect. This is necessary when running
+ // on very slow environments (like Valgrind). The step -11 was determined
+ // experimentally as the fastest mode that still throws the keyframe.
+ if (deadline_ == VPX_DL_REALTIME)
+ set_cpu_used_ = -11;
+
// This clip has a cut scene every 30 frames -> Frame 0, 30, 60, 90, 120.
// I check only the first 40 frames to make sure there's a keyframe at frame
// 0 and 30.