11b362b15af34006e6a11974088a46d42b903418eJohann/* 21b362b15af34006e6a11974088a46d42b903418eJohann * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 31b362b15af34006e6a11974088a46d42b903418eJohann * 41b362b15af34006e6a11974088a46d42b903418eJohann * Use of this source code is governed by a BSD-style license 51b362b15af34006e6a11974088a46d42b903418eJohann * that can be found in the LICENSE file in the root of the source 61b362b15af34006e6a11974088a46d42b903418eJohann * tree. An additional intellectual property rights grant can be found 71b362b15af34006e6a11974088a46d42b903418eJohann * in the file PATENTS. All contributing project authors may 81b362b15af34006e6a11974088a46d42b903418eJohann * be found in the AUTHORS file in the root of the source tree. 91b362b15af34006e6a11974088a46d42b903418eJohann */ 101b362b15af34006e6a11974088a46d42b903418eJohann#include "third_party/googletest/src/include/gtest/gtest.h" 11ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/codec_factory.h" 121b362b15af34006e6a11974088a46d42b903418eJohann#include "test/encode_test_driver.h" 131b362b15af34006e6a11974088a46d42b903418eJohann#include "test/i420_video_source.h" 14ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "test/util.h" 151b362b15af34006e6a11974088a46d42b903418eJohannnamespace { 161b362b15af34006e6a11974088a46d42b903418eJohann 1768e1c830ade592be74773e249bf94e2bbfb50de7Johann#if CONFIG_VP8_ENCODER 1868e1c830ade592be74773e249bf94e2bbfb50de7Johann 191b362b15af34006e6a11974088a46d42b903418eJohann// lookahead range: [kLookAheadMin, kLookAheadMax). 201b362b15af34006e6a11974088a46d42b903418eJohannconst int kLookAheadMin = 5; 211b362b15af34006e6a11974088a46d42b903418eJohannconst int kLookAheadMax = 26; 221b362b15af34006e6a11974088a46d42b903418eJohann 23ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangclass AltRefTest : public ::libvpx_test::EncoderTest, 247bc9febe8749e98a3812a0dc4380ceae75c29450Johann public ::libvpx_test::CodecTestWithParam<int> { 251b362b15af34006e6a11974088a46d42b903418eJohann protected: 26ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang AltRefTest() : EncoderTest(GET_PARAM(0)), altref_count_(0) {} 271b362b15af34006e6a11974088a46d42b903418eJohann virtual ~AltRefTest() {} 281b362b15af34006e6a11974088a46d42b903418eJohann 291b362b15af34006e6a11974088a46d42b903418eJohann virtual void SetUp() { 301b362b15af34006e6a11974088a46d42b903418eJohann InitializeConfig(); 311b362b15af34006e6a11974088a46d42b903418eJohann SetMode(libvpx_test::kTwoPassGood); 321b362b15af34006e6a11974088a46d42b903418eJohann } 331b362b15af34006e6a11974088a46d42b903418eJohann 347bc9febe8749e98a3812a0dc4380ceae75c29450Johann virtual void BeginPassHook(unsigned int /*pass*/) { altref_count_ = 0; } 351b362b15af34006e6a11974088a46d42b903418eJohann 361b362b15af34006e6a11974088a46d42b903418eJohann virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, 371b362b15af34006e6a11974088a46d42b903418eJohann libvpx_test::Encoder *encoder) { 381b362b15af34006e6a11974088a46d42b903418eJohann if (video->frame() == 1) { 391b362b15af34006e6a11974088a46d42b903418eJohann encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); 401b362b15af34006e6a11974088a46d42b903418eJohann encoder->Control(VP8E_SET_CPUUSED, 3); 411b362b15af34006e6a11974088a46d42b903418eJohann } 421b362b15af34006e6a11974088a46d42b903418eJohann } 431b362b15af34006e6a11974088a46d42b903418eJohann 441b362b15af34006e6a11974088a46d42b903418eJohann virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { 451b362b15af34006e6a11974088a46d42b903418eJohann if (pkt->data.frame.flags & VPX_FRAME_IS_INVISIBLE) ++altref_count_; 461b362b15af34006e6a11974088a46d42b903418eJohann } 471b362b15af34006e6a11974088a46d42b903418eJohann 481b362b15af34006e6a11974088a46d42b903418eJohann int altref_count() const { return altref_count_; } 491b362b15af34006e6a11974088a46d42b903418eJohann 501b362b15af34006e6a11974088a46d42b903418eJohann private: 511b362b15af34006e6a11974088a46d42b903418eJohann int altref_count_; 521b362b15af34006e6a11974088a46d42b903418eJohann}; 531b362b15af34006e6a11974088a46d42b903418eJohann 541b362b15af34006e6a11974088a46d42b903418eJohannTEST_P(AltRefTest, MonotonicTimestamps) { 551b362b15af34006e6a11974088a46d42b903418eJohann const vpx_rational timebase = { 33333333, 1000000000 }; 561b362b15af34006e6a11974088a46d42b903418eJohann cfg_.g_timebase = timebase; 571b362b15af34006e6a11974088a46d42b903418eJohann cfg_.rc_target_bitrate = 1000; 58ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang cfg_.g_lag_in_frames = GET_PARAM(1); 591b362b15af34006e6a11974088a46d42b903418eJohann 601b362b15af34006e6a11974088a46d42b903418eJohann libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 611b362b15af34006e6a11974088a46d42b903418eJohann timebase.den, timebase.num, 0, 30); 621b362b15af34006e6a11974088a46d42b903418eJohann ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 631b362b15af34006e6a11974088a46d42b903418eJohann EXPECT_GE(altref_count(), 1); 641b362b15af34006e6a11974088a46d42b903418eJohann} 651b362b15af34006e6a11974088a46d42b903418eJohann 66ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangVP8_INSTANTIATE_TEST_CASE(AltRefTest, 67ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ::testing::Range(kLookAheadMin, kLookAheadMax)); 6868e1c830ade592be74773e249bf94e2bbfb50de7Johann 6968e1c830ade592be74773e249bf94e2bbfb50de7Johann#endif // CONFIG_VP8_ENCODER 7068e1c830ade592be74773e249bf94e2bbfb50de7Johann 7168e1c830ade592be74773e249bf94e2bbfb50de7Johannclass AltRefForcedKeyTestLarge 7268e1c830ade592be74773e249bf94e2bbfb50de7Johann : public ::libvpx_test::EncoderTest, 7368e1c830ade592be74773e249bf94e2bbfb50de7Johann public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> { 7468e1c830ade592be74773e249bf94e2bbfb50de7Johann protected: 7568e1c830ade592be74773e249bf94e2bbfb50de7Johann AltRefForcedKeyTestLarge() 767bc9febe8749e98a3812a0dc4380ceae75c29450Johann : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)), 777bc9febe8749e98a3812a0dc4380ceae75c29450Johann cpu_used_(GET_PARAM(2)), forced_kf_frame_num_(1), frame_num_(0) {} 7868e1c830ade592be74773e249bf94e2bbfb50de7Johann virtual ~AltRefForcedKeyTestLarge() {} 7968e1c830ade592be74773e249bf94e2bbfb50de7Johann 8068e1c830ade592be74773e249bf94e2bbfb50de7Johann virtual void SetUp() { 8168e1c830ade592be74773e249bf94e2bbfb50de7Johann InitializeConfig(); 8268e1c830ade592be74773e249bf94e2bbfb50de7Johann SetMode(encoding_mode_); 8368e1c830ade592be74773e249bf94e2bbfb50de7Johann cfg_.rc_end_usage = VPX_VBR; 8468e1c830ade592be74773e249bf94e2bbfb50de7Johann cfg_.g_threads = 0; 8568e1c830ade592be74773e249bf94e2bbfb50de7Johann } 8668e1c830ade592be74773e249bf94e2bbfb50de7Johann 8768e1c830ade592be74773e249bf94e2bbfb50de7Johann virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, 8868e1c830ade592be74773e249bf94e2bbfb50de7Johann ::libvpx_test::Encoder *encoder) { 8968e1c830ade592be74773e249bf94e2bbfb50de7Johann if (video->frame() == 0) { 9068e1c830ade592be74773e249bf94e2bbfb50de7Johann encoder->Control(VP8E_SET_CPUUSED, cpu_used_); 9168e1c830ade592be74773e249bf94e2bbfb50de7Johann encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1); 9268e1c830ade592be74773e249bf94e2bbfb50de7Johann#if CONFIG_VP9_ENCODER 937bc9febe8749e98a3812a0dc4380ceae75c29450Johann // override test default for tile columns if necessary. 9468e1c830ade592be74773e249bf94e2bbfb50de7Johann if (GET_PARAM(0) == &libvpx_test::kVP9) { 9568e1c830ade592be74773e249bf94e2bbfb50de7Johann encoder->Control(VP9E_SET_TILE_COLUMNS, 6); 9668e1c830ade592be74773e249bf94e2bbfb50de7Johann } 9768e1c830ade592be74773e249bf94e2bbfb50de7Johann#endif 9868e1c830ade592be74773e249bf94e2bbfb50de7Johann } 9968e1c830ade592be74773e249bf94e2bbfb50de7Johann frame_flags_ = 10068e1c830ade592be74773e249bf94e2bbfb50de7Johann (video->frame() == forced_kf_frame_num_) ? VPX_EFLAG_FORCE_KF : 0; 10168e1c830ade592be74773e249bf94e2bbfb50de7Johann } 10268e1c830ade592be74773e249bf94e2bbfb50de7Johann 10368e1c830ade592be74773e249bf94e2bbfb50de7Johann virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { 10468e1c830ade592be74773e249bf94e2bbfb50de7Johann if (frame_num_ == forced_kf_frame_num_) { 10568e1c830ade592be74773e249bf94e2bbfb50de7Johann ASSERT_TRUE(!!(pkt->data.frame.flags & VPX_FRAME_IS_KEY)) 10668e1c830ade592be74773e249bf94e2bbfb50de7Johann << "Frame #" << frame_num_ << " isn't a keyframe!"; 10768e1c830ade592be74773e249bf94e2bbfb50de7Johann } 10868e1c830ade592be74773e249bf94e2bbfb50de7Johann ++frame_num_; 10968e1c830ade592be74773e249bf94e2bbfb50de7Johann } 11068e1c830ade592be74773e249bf94e2bbfb50de7Johann 11168e1c830ade592be74773e249bf94e2bbfb50de7Johann ::libvpx_test::TestMode encoding_mode_; 11268e1c830ade592be74773e249bf94e2bbfb50de7Johann int cpu_used_; 11368e1c830ade592be74773e249bf94e2bbfb50de7Johann unsigned int forced_kf_frame_num_; 11468e1c830ade592be74773e249bf94e2bbfb50de7Johann unsigned int frame_num_; 11568e1c830ade592be74773e249bf94e2bbfb50de7Johann}; 11668e1c830ade592be74773e249bf94e2bbfb50de7Johann 11768e1c830ade592be74773e249bf94e2bbfb50de7JohannTEST_P(AltRefForcedKeyTestLarge, Frame1IsKey) { 11868e1c830ade592be74773e249bf94e2bbfb50de7Johann const vpx_rational timebase = { 1, 30 }; 11968e1c830ade592be74773e249bf94e2bbfb50de7Johann const int lag_values[] = { 3, 15, 25, -1 }; 12068e1c830ade592be74773e249bf94e2bbfb50de7Johann 12168e1c830ade592be74773e249bf94e2bbfb50de7Johann forced_kf_frame_num_ = 1; 12268e1c830ade592be74773e249bf94e2bbfb50de7Johann for (int i = 0; lag_values[i] != -1; ++i) { 12368e1c830ade592be74773e249bf94e2bbfb50de7Johann frame_num_ = 0; 12468e1c830ade592be74773e249bf94e2bbfb50de7Johann cfg_.g_lag_in_frames = lag_values[i]; 12568e1c830ade592be74773e249bf94e2bbfb50de7Johann libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 12668e1c830ade592be74773e249bf94e2bbfb50de7Johann timebase.den, timebase.num, 0, 30); 12768e1c830ade592be74773e249bf94e2bbfb50de7Johann ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 12868e1c830ade592be74773e249bf94e2bbfb50de7Johann } 12968e1c830ade592be74773e249bf94e2bbfb50de7Johann} 13068e1c830ade592be74773e249bf94e2bbfb50de7Johann 13168e1c830ade592be74773e249bf94e2bbfb50de7JohannTEST_P(AltRefForcedKeyTestLarge, ForcedFrameIsKey) { 13268e1c830ade592be74773e249bf94e2bbfb50de7Johann const vpx_rational timebase = { 1, 30 }; 13368e1c830ade592be74773e249bf94e2bbfb50de7Johann const int lag_values[] = { 3, 15, 25, -1 }; 13468e1c830ade592be74773e249bf94e2bbfb50de7Johann 13568e1c830ade592be74773e249bf94e2bbfb50de7Johann for (int i = 0; lag_values[i] != -1; ++i) { 13668e1c830ade592be74773e249bf94e2bbfb50de7Johann frame_num_ = 0; 13768e1c830ade592be74773e249bf94e2bbfb50de7Johann forced_kf_frame_num_ = lag_values[i] - 1; 13868e1c830ade592be74773e249bf94e2bbfb50de7Johann cfg_.g_lag_in_frames = lag_values[i]; 13968e1c830ade592be74773e249bf94e2bbfb50de7Johann libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288, 14068e1c830ade592be74773e249bf94e2bbfb50de7Johann timebase.den, timebase.num, 0, 30); 14168e1c830ade592be74773e249bf94e2bbfb50de7Johann ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); 14268e1c830ade592be74773e249bf94e2bbfb50de7Johann } 14368e1c830ade592be74773e249bf94e2bbfb50de7Johann} 14468e1c830ade592be74773e249bf94e2bbfb50de7Johann 1457bc9febe8749e98a3812a0dc4380ceae75c29450JohannVP8_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge, 1467bc9febe8749e98a3812a0dc4380ceae75c29450Johann ::testing::Values(::libvpx_test::kOnePassGood), 1477bc9febe8749e98a3812a0dc4380ceae75c29450Johann ::testing::Range(0, 9)); 14868e1c830ade592be74773e249bf94e2bbfb50de7Johann 1497bc9febe8749e98a3812a0dc4380ceae75c29450JohannVP9_INSTANTIATE_TEST_CASE(AltRefForcedKeyTestLarge, 1507bc9febe8749e98a3812a0dc4380ceae75c29450Johann ::testing::Values(::libvpx_test::kOnePassGood), 1517bc9febe8749e98a3812a0dc4380ceae75c29450Johann ::testing::Range(0, 9)); 1521b362b15af34006e6a11974088a46d42b903418eJohann} // namespace 153