2014-12-16 20:10:20 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
|
|
|
#include "test/codec_factory.h"
|
|
|
|
#include "test/encode_test_driver.h"
|
|
|
|
#include "test/md5_helper.h"
|
2015-02-26 04:09:59 +01:00
|
|
|
#include "test/util.h"
|
|
|
|
#include "test/y4m_video_source.h"
|
2014-12-16 20:10:20 +01:00
|
|
|
|
|
|
|
namespace {
|
2015-08-19 23:13:18 +02:00
|
|
|
class VPxEncoderThreadTest
|
2014-12-16 20:10:20 +01:00
|
|
|
: public ::libvpx_test::EncoderTest,
|
2016-10-19 20:07:41 +02:00
|
|
|
public ::libvpx_test::CodecTestWith4Params<libvpx_test::TestMode, int,
|
|
|
|
int, int> {
|
2014-12-16 20:10:20 +01:00
|
|
|
protected:
|
2015-08-19 23:13:18 +02:00
|
|
|
VPxEncoderThreadTest()
|
2016-10-19 20:07:41 +02:00
|
|
|
: EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
|
|
|
|
tiles_(GET_PARAM(3)), threads_(GET_PARAM(4)),
|
2016-07-26 07:50:48 +02:00
|
|
|
encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
|
2014-12-16 20:10:20 +01:00
|
|
|
init_flags_ = VPX_CODEC_USE_PSNR;
|
|
|
|
md5_.clear();
|
|
|
|
}
|
2016-04-28 22:09:08 +02:00
|
|
|
virtual ~VPxEncoderThreadTest() {}
|
2014-12-16 20:10:20 +01:00
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
InitializeConfig();
|
|
|
|
SetMode(encoding_mode_);
|
|
|
|
|
|
|
|
if (encoding_mode_ != ::libvpx_test::kRealTime) {
|
|
|
|
cfg_.g_lag_in_frames = 3;
|
|
|
|
cfg_.rc_end_usage = VPX_VBR;
|
|
|
|
cfg_.rc_2pass_vbr_minsection_pct = 5;
|
2016-03-15 17:28:16 +01:00
|
|
|
cfg_.rc_2pass_vbr_maxsection_pct = 2000;
|
2014-12-16 20:10:20 +01:00
|
|
|
} else {
|
|
|
|
cfg_.g_lag_in_frames = 0;
|
|
|
|
cfg_.rc_end_usage = VPX_CBR;
|
|
|
|
cfg_.g_error_resilient = 1;
|
|
|
|
}
|
|
|
|
cfg_.rc_max_quantizer = 56;
|
|
|
|
cfg_.rc_min_quantizer = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-05 20:47:21 +01:00
|
|
|
virtual void BeginPassHook(unsigned int /*pass*/) {
|
|
|
|
encoder_initialized_ = false;
|
|
|
|
}
|
|
|
|
|
2016-02-12 03:27:00 +01:00
|
|
|
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource * /*video*/,
|
2014-12-16 20:10:20 +01:00
|
|
|
::libvpx_test::Encoder *encoder) {
|
2015-03-05 20:47:21 +01:00
|
|
|
if (!encoder_initialized_) {
|
2014-12-16 20:10:20 +01:00
|
|
|
// Encode 4 column tiles.
|
|
|
|
encoder->Control(VP9E_SET_TILE_COLUMNS, tiles_);
|
|
|
|
encoder->Control(VP8E_SET_CPUUSED, set_cpu_used_);
|
|
|
|
if (encoding_mode_ != ::libvpx_test::kRealTime) {
|
|
|
|
encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
|
|
|
|
encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
|
|
|
|
encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
|
|
|
|
encoder->Control(VP8E_SET_ARNR_TYPE, 3);
|
2016-10-25 19:47:21 +02:00
|
|
|
encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 0);
|
2014-12-16 20:10:20 +01:00
|
|
|
} else {
|
|
|
|
encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 0);
|
2015-03-06 19:47:09 +01:00
|
|
|
encoder->Control(VP9E_SET_AQ_MODE, 3);
|
2014-12-16 20:10:20 +01:00
|
|
|
}
|
2015-03-05 20:47:21 +01:00
|
|
|
encoder_initialized_ = true;
|
2014-12-16 20:10:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 22:09:08 +02:00
|
|
|
virtual void DecompressedFrameHook(const vpx_image_t &img,
|
|
|
|
vpx_codec_pts_t /*pts*/) {
|
|
|
|
::libvpx_test::MD5 md5_res;
|
|
|
|
md5_res.Add(&img);
|
|
|
|
md5_.push_back(md5_res.Get());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool HandleDecodeResult(const vpx_codec_err_t res,
|
2016-07-26 07:50:48 +02:00
|
|
|
const libvpx_test::VideoSource & /*video*/,
|
2016-04-28 22:09:08 +02:00
|
|
|
libvpx_test::Decoder * /*decoder*/) {
|
2014-12-16 20:10:20 +01:00
|
|
|
if (res != VPX_CODEC_OK) {
|
2016-04-28 22:09:08 +02:00
|
|
|
EXPECT_EQ(VPX_CODEC_OK, res);
|
|
|
|
return false;
|
2014-12-16 20:10:20 +01:00
|
|
|
}
|
|
|
|
|
2016-04-28 22:09:08 +02:00
|
|
|
return true;
|
2014-12-16 20:10:20 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 20:47:21 +01:00
|
|
|
bool encoder_initialized_;
|
2014-12-16 20:10:20 +01:00
|
|
|
int tiles_;
|
2016-10-19 20:07:41 +02:00
|
|
|
int threads_;
|
2014-12-16 20:10:20 +01:00
|
|
|
::libvpx_test::TestMode encoding_mode_;
|
|
|
|
int set_cpu_used_;
|
|
|
|
std::vector<std::string> md5_;
|
|
|
|
};
|
|
|
|
|
2015-08-19 23:13:18 +02:00
|
|
|
TEST_P(VPxEncoderThreadTest, EncoderResultTest) {
|
2014-12-16 20:10:20 +01:00
|
|
|
std::vector<std::string> single_thr_md5, multi_thr_md5;
|
|
|
|
|
2015-02-26 04:09:59 +01:00
|
|
|
::libvpx_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 20);
|
2014-12-16 20:10:20 +01:00
|
|
|
|
|
|
|
cfg_.rc_target_bitrate = 1000;
|
|
|
|
|
|
|
|
// Encode using single thread.
|
|
|
|
cfg_.g_threads = 1;
|
|
|
|
init_flags_ = VPX_CODEC_USE_PSNR;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
single_thr_md5 = md5_;
|
|
|
|
md5_.clear();
|
|
|
|
|
|
|
|
// Encode using multiple threads.
|
2016-10-19 20:07:41 +02:00
|
|
|
cfg_.g_threads = threads_;
|
2014-12-16 20:10:20 +01:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
multi_thr_md5 = md5_;
|
|
|
|
md5_.clear();
|
|
|
|
|
|
|
|
// Compare to check if two vectors are equal.
|
|
|
|
ASSERT_EQ(single_thr_md5, multi_thr_md5);
|
|
|
|
}
|
|
|
|
|
2016-07-26 07:50:48 +02:00
|
|
|
VP9_INSTANTIATE_TEST_CASE(VPxEncoderThreadTest,
|
|
|
|
::testing::Values(::libvpx_test::kTwoPassGood,
|
|
|
|
::libvpx_test::kOnePassGood,
|
|
|
|
::libvpx_test::kRealTime),
|
2016-10-25 19:47:21 +02:00
|
|
|
::testing::Range(0, 9), // cpu_used
|
2016-10-19 20:07:41 +02:00
|
|
|
::testing::Range(0, 3), // tile_columns
|
|
|
|
::testing::Range(2, 5)); // threads
|
2014-12-16 20:10:20 +01:00
|
|
|
} // namespace
|