2014-12-16 22:10:20 +03:00
|
|
|
/*
|
2016-09-02 22:04:54 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2014-12-16 22:10:20 +03:00
|
|
|
*
|
2016-09-02 22:04:54 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
|
|
|
*/
|
2014-12-16 22:10:20 +03:00
|
|
|
|
|
|
|
#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 06:09:59 +03:00
|
|
|
#include "test/util.h"
|
|
|
|
#include "test/y4m_video_source.h"
|
2014-12-16 22:10:20 +03:00
|
|
|
|
|
|
|
namespace {
|
2016-08-31 00:01:10 +03:00
|
|
|
class AVxEncoderThreadTest
|
2016-08-23 02:08:15 +03:00
|
|
|
: public ::libaom_test::EncoderTest,
|
|
|
|
public ::libaom_test::CodecTestWith2Params<libaom_test::TestMode, int> {
|
2014-12-16 22:10:20 +03:00
|
|
|
protected:
|
2016-08-31 00:01:10 +03:00
|
|
|
AVxEncoderThreadTest()
|
2016-08-12 03:46:05 +03:00
|
|
|
: EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
|
|
|
|
encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
|
2016-08-31 00:01:10 +03:00
|
|
|
init_flags_ = AOM_CODEC_USE_PSNR;
|
|
|
|
aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
|
2014-12-16 22:10:20 +03:00
|
|
|
cfg.w = 1280;
|
|
|
|
cfg.h = 720;
|
|
|
|
decoder_ = codec_->CreateDecoder(cfg, 0);
|
2016-08-31 00:01:10 +03:00
|
|
|
#if CONFIG_AV1 && CONFIG_EXT_TILE
|
|
|
|
if (decoder_->IsAV1()) {
|
|
|
|
decoder_->Control(AV1_SET_DECODE_TILE_ROW, -1);
|
|
|
|
decoder_->Control(AV1_SET_DECODE_TILE_COL, -1);
|
2016-05-06 02:42:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
2014-12-16 22:10:20 +03:00
|
|
|
|
2016-05-04 13:25:01 +03:00
|
|
|
size_enc_.clear();
|
|
|
|
md5_dec_.clear();
|
|
|
|
md5_enc_.clear();
|
2014-12-16 22:10:20 +03:00
|
|
|
}
|
2016-08-31 00:01:10 +03:00
|
|
|
virtual ~AVxEncoderThreadTest() { delete decoder_; }
|
2014-12-16 22:10:20 +03:00
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
InitializeConfig();
|
|
|
|
SetMode(encoding_mode_);
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
if (encoding_mode_ != ::libaom_test::kRealTime) {
|
2014-12-16 22:10:20 +03:00
|
|
|
cfg_.g_lag_in_frames = 3;
|
2016-08-31 00:01:10 +03:00
|
|
|
cfg_.rc_end_usage = AOM_VBR;
|
2014-12-16 22:10:20 +03:00
|
|
|
cfg_.rc_2pass_vbr_minsection_pct = 5;
|
2016-03-15 02:32:41 +03:00
|
|
|
cfg_.rc_2pass_vbr_maxsection_pct = 2000;
|
2014-12-16 22:10:20 +03:00
|
|
|
} else {
|
|
|
|
cfg_.g_lag_in_frames = 0;
|
2016-08-31 00:01:10 +03:00
|
|
|
cfg_.rc_end_usage = AOM_CBR;
|
2014-12-16 22:10:20 +03:00
|
|
|
cfg_.g_error_resilient = 1;
|
|
|
|
}
|
|
|
|
cfg_.rc_max_quantizer = 56;
|
|
|
|
cfg_.rc_min_quantizer = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-05 22:47:21 +03:00
|
|
|
virtual void BeginPassHook(unsigned int /*pass*/) {
|
|
|
|
encoder_initialized_ = false;
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
virtual void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
|
|
|
|
::libaom_test::Encoder *encoder) {
|
2015-03-05 22:47:21 +03:00
|
|
|
if (!encoder_initialized_) {
|
2016-08-31 00:01:10 +03:00
|
|
|
#if CONFIG_AV1 && CONFIG_EXT_TILE
|
|
|
|
encoder->Control(AV1E_SET_TILE_COLUMNS, 1);
|
|
|
|
if (codec_ == &libaom_test::kAV1) {
|
2016-05-06 15:27:52 +03:00
|
|
|
// TODO(geza): Start using multiple tile rows when the multi-threaded
|
|
|
|
// encoder can handle them
|
2016-08-31 00:01:10 +03:00
|
|
|
encoder->Control(AV1E_SET_TILE_ROWS, 32);
|
2016-05-06 15:27:52 +03:00
|
|
|
} else {
|
2016-08-31 00:01:10 +03:00
|
|
|
encoder->Control(AV1E_SET_TILE_ROWS, 0);
|
2016-05-06 15:27:52 +03:00
|
|
|
}
|
2016-05-04 13:25:01 +03:00
|
|
|
#else
|
|
|
|
// Encode 4 tile columns.
|
2016-08-31 00:01:10 +03:00
|
|
|
encoder->Control(AV1E_SET_TILE_COLUMNS, 2);
|
|
|
|
encoder->Control(AV1E_SET_TILE_ROWS, 0);
|
|
|
|
#endif // CONFIG_AV1 && CONFIG_EXT_TILE
|
|
|
|
encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
|
2016-08-23 02:08:15 +03:00
|
|
|
if (encoding_mode_ != ::libaom_test::kRealTime) {
|
2016-08-31 00:01:10 +03:00
|
|
|
encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
|
|
|
|
encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
|
|
|
|
encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
|
|
|
|
encoder->Control(AOME_SET_ARNR_TYPE, 3);
|
2014-12-16 22:10:20 +03:00
|
|
|
} else {
|
2016-08-31 00:01:10 +03:00
|
|
|
encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
|
|
|
|
encoder->Control(AV1E_SET_AQ_MODE, 3);
|
2014-12-16 22:10:20 +03:00
|
|
|
}
|
2015-03-05 22:47:21 +03:00
|
|
|
encoder_initialized_ = true;
|
2014-12-16 22:10:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
virtual void FramePktHook(const aom_codec_cx_pkt_t *pkt) {
|
2016-05-04 13:25:01 +03:00
|
|
|
size_enc_.push_back(pkt->data.frame.sz);
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
::libaom_test::MD5 md5_enc;
|
2016-08-12 03:46:05 +03:00
|
|
|
md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
|
2016-05-04 13:25:01 +03:00
|
|
|
pkt->data.frame.sz);
|
|
|
|
md5_enc_.push_back(md5_enc.Get());
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
const aom_codec_err_t res = decoder_->DecodeFrame(
|
2016-08-12 03:46:05 +03:00
|
|
|
reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
|
2016-08-31 00:01:10 +03:00
|
|
|
if (res != AOM_CODEC_OK) {
|
2014-12-16 22:10:20 +03:00
|
|
|
abort_ = true;
|
2016-08-31 00:01:10 +03:00
|
|
|
ASSERT_EQ(AOM_CODEC_OK, res);
|
2014-12-16 22:10:20 +03:00
|
|
|
}
|
2016-08-31 00:01:10 +03:00
|
|
|
const aom_image_t *img = decoder_->GetDxData().Next();
|
2014-12-16 22:10:20 +03:00
|
|
|
|
|
|
|
if (img) {
|
2016-08-23 02:08:15 +03:00
|
|
|
::libaom_test::MD5 md5_res;
|
2014-12-16 22:10:20 +03:00
|
|
|
md5_res.Add(img);
|
2016-05-04 13:25:01 +03:00
|
|
|
md5_dec_.push_back(md5_res.Get());
|
2014-12-16 22:10:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 00:50:30 +03:00
|
|
|
void DoTest() {
|
2016-08-23 02:08:15 +03:00
|
|
|
::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 15, 18);
|
2016-06-15 00:50:30 +03:00
|
|
|
cfg_.rc_target_bitrate = 1000;
|
|
|
|
|
|
|
|
// Encode using single thread.
|
|
|
|
cfg_.g_threads = 1;
|
2016-08-31 00:01:10 +03:00
|
|
|
init_flags_ = AOM_CODEC_USE_PSNR;
|
2016-06-15 00:50:30 +03:00
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
std::vector<size_t> single_thr_size_enc;
|
|
|
|
std::vector<std::string> single_thr_md5_enc;
|
|
|
|
std::vector<std::string> single_thr_md5_dec;
|
|
|
|
single_thr_size_enc = size_enc_;
|
|
|
|
single_thr_md5_enc = md5_enc_;
|
|
|
|
single_thr_md5_dec = md5_dec_;
|
|
|
|
size_enc_.clear();
|
|
|
|
md5_enc_.clear();
|
|
|
|
md5_dec_.clear();
|
|
|
|
|
|
|
|
// Encode using multiple threads.
|
|
|
|
cfg_.g_threads = 4;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
|
|
|
|
std::vector<size_t> multi_thr_size_enc;
|
|
|
|
std::vector<std::string> multi_thr_md5_enc;
|
|
|
|
std::vector<std::string> multi_thr_md5_dec;
|
|
|
|
multi_thr_size_enc = size_enc_;
|
|
|
|
multi_thr_md5_enc = md5_enc_;
|
|
|
|
multi_thr_md5_dec = md5_dec_;
|
|
|
|
size_enc_.clear();
|
|
|
|
md5_enc_.clear();
|
|
|
|
md5_dec_.clear();
|
|
|
|
|
|
|
|
// Check that the vectors are equal.
|
|
|
|
ASSERT_EQ(single_thr_size_enc, multi_thr_size_enc);
|
|
|
|
ASSERT_EQ(single_thr_md5_enc, multi_thr_md5_enc);
|
|
|
|
ASSERT_EQ(single_thr_md5_dec, multi_thr_md5_dec);
|
|
|
|
}
|
|
|
|
|
2015-03-05 22:47:21 +03:00
|
|
|
bool encoder_initialized_;
|
2016-08-23 02:08:15 +03:00
|
|
|
::libaom_test::TestMode encoding_mode_;
|
2014-12-16 22:10:20 +03:00
|
|
|
int set_cpu_used_;
|
2016-08-23 02:08:15 +03:00
|
|
|
::libaom_test::Decoder *decoder_;
|
2016-05-04 13:25:01 +03:00
|
|
|
std::vector<size_t> size_enc_;
|
|
|
|
std::vector<std::string> md5_enc_;
|
|
|
|
std::vector<std::string> md5_dec_;
|
2014-12-16 22:10:20 +03:00
|
|
|
};
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
TEST_P(AVxEncoderThreadTest, EncoderResultTest) { DoTest(); }
|
2016-06-15 00:50:30 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
class AVxEncoderThreadTestLarge : public AVxEncoderThreadTest {};
|
2016-06-15 00:50:30 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
TEST_P(AVxEncoderThreadTestLarge, EncoderResultTest) { DoTest(); }
|
2015-08-20 00:13:18 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTest,
|
|
|
|
::testing::Values(::libaom_test::kTwoPassGood,
|
|
|
|
::libaom_test::kOnePassGood),
|
|
|
|
::testing::Range(3, 9));
|
2016-06-15 00:50:30 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
AV1_INSTANTIATE_TEST_CASE(AVxEncoderThreadTestLarge,
|
|
|
|
::testing::Values(::libaom_test::kTwoPassGood,
|
|
|
|
::libaom_test::kOnePassGood),
|
|
|
|
::testing::Range(1, 3));
|
2014-12-16 22:10:20 +03:00
|
|
|
} // namespace
|