2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
13 #include "third_party/googletest/src/include/gtest/gtest.h"
14 #include "test/codec_factory.h"
15 #include "test/encode_test_driver.h"
16 #include "test/md5_helper.h"
17 #include "test/util.h"
18 #include "test/y4m_video_source.h"
21 class VPxEncoderThreadTest
22 : public ::libvpx_test::EncoderTest
,
23 public ::libvpx_test::CodecTestWith2Params
<libvpx_test::TestMode
, int> {
25 VPxEncoderThreadTest()
26 : EncoderTest(GET_PARAM(0)),
27 encoder_initialized_(false),
29 encoding_mode_(GET_PARAM(1)),
30 set_cpu_used_(GET_PARAM(2)) {
31 init_flags_
= VPX_CODEC_USE_PSNR
;
34 virtual ~VPxEncoderThreadTest() {}
36 virtual void SetUp() {
38 SetMode(encoding_mode_
);
40 if (encoding_mode_
!= ::libvpx_test::kRealTime
) {
41 cfg_
.g_lag_in_frames
= 3;
42 cfg_
.rc_end_usage
= VPX_VBR
;
43 cfg_
.rc_2pass_vbr_minsection_pct
= 5;
44 cfg_
.rc_2pass_vbr_maxsection_pct
= 2000;
46 cfg_
.g_lag_in_frames
= 0;
47 cfg_
.rc_end_usage
= VPX_CBR
;
48 cfg_
.g_error_resilient
= 1;
50 cfg_
.rc_max_quantizer
= 56;
51 cfg_
.rc_min_quantizer
= 0;
54 virtual void BeginPassHook(unsigned int /*pass*/) {
55 encoder_initialized_
= false;
58 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource
* /*video*/,
59 ::libvpx_test::Encoder
*encoder
) {
60 if (!encoder_initialized_
) {
61 // Encode 4 column tiles.
62 encoder
->Control(VP9E_SET_TILE_COLUMNS
, tiles_
);
63 encoder
->Control(VP8E_SET_CPUUSED
, set_cpu_used_
);
64 if (encoding_mode_
!= ::libvpx_test::kRealTime
) {
65 encoder
->Control(VP8E_SET_ENABLEAUTOALTREF
, 1);
66 encoder
->Control(VP8E_SET_ARNR_MAXFRAMES
, 7);
67 encoder
->Control(VP8E_SET_ARNR_STRENGTH
, 5);
68 encoder
->Control(VP8E_SET_ARNR_TYPE
, 3);
70 encoder
->Control(VP8E_SET_ENABLEAUTOALTREF
, 0);
71 encoder
->Control(VP9E_SET_AQ_MODE
, 3);
73 encoder_initialized_
= true;
77 virtual void DecompressedFrameHook(const vpx_image_t
&img
,
78 vpx_codec_pts_t
/*pts*/) {
79 ::libvpx_test::MD5 md5_res
;
81 md5_
.push_back(md5_res
.Get());
84 virtual bool HandleDecodeResult(const vpx_codec_err_t res
,
85 const libvpx_test::VideoSource
& /*video*/,
86 libvpx_test::Decoder
* /*decoder*/) {
87 if (res
!= VPX_CODEC_OK
) {
88 EXPECT_EQ(VPX_CODEC_OK
, res
);
95 bool encoder_initialized_
;
97 ::libvpx_test::TestMode encoding_mode_
;
99 std::vector
<std::string
> md5_
;
102 TEST_P(VPxEncoderThreadTest
, EncoderResultTest
) {
103 std::vector
<std::string
> single_thr_md5
, multi_thr_md5
;
105 ::libvpx_test::Y4mVideoSource
video("niklas_1280_720_30.y4m", 15, 20);
107 cfg_
.rc_target_bitrate
= 1000;
109 // Encode using single thread.
111 init_flags_
= VPX_CODEC_USE_PSNR
;
112 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
113 single_thr_md5
= md5_
;
116 // Encode using multiple threads.
118 ASSERT_NO_FATAL_FAILURE(RunLoop(&video
));
119 multi_thr_md5
= md5_
;
122 // Compare to check if two vectors are equal.
123 ASSERT_EQ(single_thr_md5
, multi_thr_md5
);
126 VP9_INSTANTIATE_TEST_CASE(
127 VPxEncoderThreadTest
,
128 ::testing::Values(::libvpx_test::kTwoPassGood
, ::libvpx_test::kOnePassGood
,
129 ::libvpx_test::kRealTime
),
130 ::testing::Range(1, 9));
132 VP10_INSTANTIATE_TEST_CASE(
133 VPxEncoderThreadTest
,
134 ::testing::Values(::libvpx_test::kTwoPassGood
, ::libvpx_test::kOnePassGood
),
135 ::testing::Range(1, 3));