1 /*
2 * Copyright (c) 2017 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12
13 #include "gtest/gtest.h"
14
15 #include "test/codec_factory.h"
16 #include "test/encode_test_driver.h"
17 #include "test/util.h"
18 #include "test/yuv_video_source.h"
19 #include "vpx_config.h"
20
21 namespace {
22 #define MAX_EXTREME_MV 1
23 #define MIN_EXTREME_MV 2
24
25 // Encoding modes
26 const libvpx_test::TestMode kEncodingModeVectors[] = {
27 #if !CONFIG_REALTIME_ONLY
28 ::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
29 #endif
30 ::libvpx_test::kRealTime
31 };
32
33 // Encoding speeds
34 const int kCpuUsedVectors[] = { 0, 1, 2, 3, 4, 5, 6 };
35
36 // MV test modes: 1 - always use maximum MV; 2 - always use minimum MV.
37 const int kMVTestModes[] = { MAX_EXTREME_MV, MIN_EXTREME_MV };
38
39 class MotionVectorTestLarge
40 : public ::libvpx_test::EncoderTest,
41 public ::libvpx_test::CodecTestWith3Params<libvpx_test::TestMode, int,
42 int> {
43 protected:
MotionVectorTestLarge()44 MotionVectorTestLarge()
45 : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
46 cpu_used_(GET_PARAM(2)), mv_test_mode_(GET_PARAM(3)) {}
47
48 ~MotionVectorTestLarge() override = default;
49
SetUp()50 void SetUp() override {
51 InitializeConfig();
52 SetMode(encoding_mode_);
53 if (encoding_mode_ != ::libvpx_test::kRealTime) {
54 cfg_.g_lag_in_frames = 3;
55 cfg_.rc_end_usage = VPX_VBR;
56 } else {
57 cfg_.g_lag_in_frames = 0;
58 cfg_.rc_end_usage = VPX_CBR;
59 cfg_.rc_buf_sz = 1000;
60 cfg_.rc_buf_initial_sz = 500;
61 cfg_.rc_buf_optimal_sz = 600;
62 }
63 }
64
PreEncodeFrameHook(::libvpx_test::VideoSource * video,::libvpx_test::Encoder * encoder)65 void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
66 ::libvpx_test::Encoder *encoder) override {
67 if (video->frame() == 0) {
68 encoder->Control(VP8E_SET_CPUUSED, cpu_used_);
69 encoder->Control(VP9E_ENABLE_MOTION_VECTOR_UNIT_TEST, mv_test_mode_);
70 if (encoding_mode_ != ::libvpx_test::kRealTime) {
71 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
72 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
73 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
74 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
75 }
76 }
77 }
78
79 libvpx_test::TestMode encoding_mode_;
80 int cpu_used_;
81 int mv_test_mode_;
82 };
83
TEST_P(MotionVectorTestLarge,OverallTest)84 TEST_P(MotionVectorTestLarge, OverallTest) {
85 cfg_.rc_target_bitrate = 24000;
86 cfg_.g_profile = 0;
87 init_flags_ = VPX_CODEC_USE_PSNR;
88
89 std::unique_ptr<libvpx_test::VideoSource> video;
90 video.reset(new libvpx_test::YUVVideoSource(
91 "niklas_640_480_30.yuv", VPX_IMG_FMT_I420, 3840, 2160, // 2048, 1080,
92 30, 1, 0, 5));
93
94 ASSERT_NE(video.get(), nullptr);
95 ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
96 }
97
98 VP9_INSTANTIATE_TEST_SUITE(MotionVectorTestLarge,
99 ::testing::ValuesIn(kEncodingModeVectors),
100 ::testing::ValuesIn(kCpuUsedVectors),
101 ::testing::ValuesIn(kMVTestModes));
102 } // namespace
103