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;
32 vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
35 decoder_ = codec_->CreateDecoder(cfg, 0);
39 virtual ~VPxEncoderThreadTest() {
43 virtual void SetUp() {
45 SetMode(encoding_mode_);
47 if (encoding_mode_ != ::libvpx_test::kRealTime) {
48 cfg_.g_lag_in_frames = 3;
49 cfg_.rc_end_usage = VPX_VBR;
50 cfg_.rc_2pass_vbr_minsection_pct = 5;
51 cfg_.rc_2pass_vbr_minsection_pct = 2000;
53 cfg_.g_lag_in_frames = 0;
54 cfg_.rc_end_usage = VPX_CBR;
55 cfg_.g_error_resilient = 1;
57 cfg_.rc_max_quantizer = 56;
58 cfg_.rc_min_quantizer = 0;
61 virtual void BeginPassHook(unsigned int /*pass*/) {
62 encoder_initialized_ = false;
65 virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
66 ::libvpx_test::Encoder *encoder) {
67 if (!encoder_initialized_) {
68 // Encode 4 column tiles.
69 encoder->Control(VP9E_SET_TILE_COLUMNS, tiles_);
70 encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
71 if (encoding_mode_ != ::libvpx_test::kRealTime) {
72 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
73 encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
74 encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
75 encoder->Control(VP8E_SET_ARNR_TYPE, 3);
77 encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 0);
78 encoder->Control(VP9E_SET_AQ_MODE, 3);
80 encoder_initialized_ = true;
84 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
85 const vpx_codec_err_t res = decoder_->DecodeFrame(
86 reinterpret_cast<uint8_t*>(pkt->data.frame.buf), pkt->data.frame.sz);
87 if (res != VPX_CODEC_OK) {
89 ASSERT_EQ(VPX_CODEC_OK, res);
91 const vpx_image_t *img = decoder_->GetDxData().Next();
94 ::libvpx_test::MD5 md5_res;
96 md5_.push_back(md5_res.Get());
100 bool encoder_initialized_;
102 ::libvpx_test::TestMode encoding_mode_;
104 ::libvpx_test::Decoder *decoder_;
105 std::vector<std::string> md5_;
108 TEST_P(VPxEncoderThreadTest, EncoderResultTest) {
109 std::vector<std::string> single_thr_md5, multi_thr_md5;
111 ::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 20);
113 cfg_.rc_target_bitrate = 1000;
115 // Encode using single thread.
117 init_flags_ = VPX_CODEC_USE_PSNR;
118 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
119 single_thr_md5 = md5_;
122 // Encode using multiple threads.
124 ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
125 multi_thr_md5 = md5_;
128 // Compare to check if two vectors are equal.
129 ASSERT_EQ(single_thr_md5, multi_thr_md5);
132 VP9_INSTANTIATE_TEST_CASE(
133 VPxEncoderThreadTest,
134 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood,
135 ::libvpx_test::kRealTime),
136 ::testing::Range(1, 9));
138 VP10_INSTANTIATE_TEST_CASE(
139 VPxEncoderThreadTest,
140 ::testing::Values(::libvpx_test::kTwoPassGood, ::libvpx_test::kOnePassGood),
141 ::testing::Range(1, 3));