1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2021, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include <string>
13*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
14*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "test/md5_helper.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/y4m_video_source.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/yuv_video_source.h"
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker namespace {
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_FPMT_TEST && !CONFIG_REALTIME_ONLY
25*77c1e3ccSAndroid Build Coastguard Worker class AVxFrameParallelThreadEncodeTest
26*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith3Params<int, int, int>,
27*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
28*77c1e3ccSAndroid Build Coastguard Worker protected:
AVxFrameParallelThreadEncodeTest()29*77c1e3ccSAndroid Build Coastguard Worker AVxFrameParallelThreadEncodeTest()
30*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), encoder_initialized_(false),
31*77c1e3ccSAndroid Build Coastguard Worker set_cpu_used_(GET_PARAM(1)), tile_cols_(GET_PARAM(2)),
32*77c1e3ccSAndroid Build Coastguard Worker tile_rows_(GET_PARAM(3)) {
33*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t cfg = aom_codec_dec_cfg_t();
34*77c1e3ccSAndroid Build Coastguard Worker cfg.w = 1280;
35*77c1e3ccSAndroid Build Coastguard Worker cfg.h = 720;
36*77c1e3ccSAndroid Build Coastguard Worker cfg.allow_lowbitdepth = 1;
37*77c1e3ccSAndroid Build Coastguard Worker decoder_ = codec_->CreateDecoder(cfg, 0);
38*77c1e3ccSAndroid Build Coastguard Worker }
~AVxFrameParallelThreadEncodeTest()39*77c1e3ccSAndroid Build Coastguard Worker ~AVxFrameParallelThreadEncodeTest() override { delete decoder_; }
40*77c1e3ccSAndroid Build Coastguard Worker
SetUp()41*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
42*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(::libaom_test::kTwoPassGood);
43*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_VBR;
44*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 35;
45*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_minsection_pct = 5;
46*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_2pass_vbr_maxsection_pct = 2000;
47*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 63;
48*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 0;
49*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_threads = 16;
50*77c1e3ccSAndroid Build Coastguard Worker }
51*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)52*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int /*pass*/) override {
53*77c1e3ccSAndroid Build Coastguard Worker encoder_initialized_ = false;
54*77c1e3ccSAndroid Build Coastguard Worker }
55*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(::libaom_test::VideoSource *,::libaom_test::Encoder * encoder)56*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource * /*video*/,
57*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
58*77c1e3ccSAndroid Build Coastguard Worker if (encoder_initialized_) return;
59*77c1e3ccSAndroid Build Coastguard Worker SetTileSize(encoder);
60*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
61*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FP_MT, 1);
62*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FP_MT_UNIT_TEST, enable_actual_parallel_encode_);
63*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
64*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ARNR_MAXFRAMES, 7);
65*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ARNR_STRENGTH, 5);
66*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 0);
67*77c1e3ccSAndroid Build Coastguard Worker
68*77c1e3ccSAndroid Build Coastguard Worker encoder_initialized_ = true;
69*77c1e3ccSAndroid Build Coastguard Worker }
70*77c1e3ccSAndroid Build Coastguard Worker
SetTileSize(libaom_test::Encoder * encoder)71*77c1e3ccSAndroid Build Coastguard Worker virtual void SetTileSize(libaom_test::Encoder *encoder) {
72*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_COLUMNS, tile_cols_);
73*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TILE_ROWS, tile_rows_);
74*77c1e3ccSAndroid Build Coastguard Worker }
75*77c1e3ccSAndroid Build Coastguard Worker
FramePktHook(const aom_codec_cx_pkt_t * pkt)76*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
77*77c1e3ccSAndroid Build Coastguard Worker size_enc_.push_back(pkt->data.frame.sz);
78*77c1e3ccSAndroid Build Coastguard Worker
79*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 md5_enc;
80*77c1e3ccSAndroid Build Coastguard Worker md5_enc.Add(reinterpret_cast<uint8_t *>(pkt->data.frame.buf),
81*77c1e3ccSAndroid Build Coastguard Worker pkt->data.frame.sz);
82*77c1e3ccSAndroid Build Coastguard Worker md5_enc_.push_back(md5_enc.Get());
83*77c1e3ccSAndroid Build Coastguard Worker
84*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_err_t res = decoder_->DecodeFrame(
85*77c1e3ccSAndroid Build Coastguard Worker reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
86*77c1e3ccSAndroid Build Coastguard Worker if (res != AOM_CODEC_OK) {
87*77c1e3ccSAndroid Build Coastguard Worker abort_ = true;
88*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res);
89*77c1e3ccSAndroid Build Coastguard Worker }
90*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img = decoder_->GetDxData().Next();
91*77c1e3ccSAndroid Build Coastguard Worker
92*77c1e3ccSAndroid Build Coastguard Worker if (img) {
93*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::MD5 md5_res;
94*77c1e3ccSAndroid Build Coastguard Worker md5_res.Add(img);
95*77c1e3ccSAndroid Build Coastguard Worker md5_dec_.push_back(md5_res.Get());
96*77c1e3ccSAndroid Build Coastguard Worker }
97*77c1e3ccSAndroid Build Coastguard Worker }
98*77c1e3ccSAndroid Build Coastguard Worker
DoTest(::libaom_test::VideoSource * input_video)99*77c1e3ccSAndroid Build Coastguard Worker void DoTest(::libaom_test::VideoSource *input_video) {
100*77c1e3ccSAndroid Build Coastguard Worker /* This is the actual parallel encode of frames using multiple cpis.
101*77c1e3ccSAndroid Build Coastguard Worker * The parallel frames are independently encoded.
102*77c1e3ccSAndroid Build Coastguard Worker * Threads are distributed among the parallel frames whereas non-parallel
103*77c1e3ccSAndroid Build Coastguard Worker * frames use all the threads. Example: for 8 threads, in case of 4 frames
104*77c1e3ccSAndroid Build Coastguard Worker * in a parallel encode set, each frame gets 2 threads. In case of 3 frames
105*77c1e3ccSAndroid Build Coastguard Worker * in a parallel encode set, threads are distributed as 2, 3 ,3.
106*77c1e3ccSAndroid Build Coastguard Worker */
107*77c1e3ccSAndroid Build Coastguard Worker enable_actual_parallel_encode_ = 1;
108*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(input_video));
109*77c1e3ccSAndroid Build Coastguard Worker std::vector<size_t> enc_stream_fpmt_size;
110*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> enc_stream_fpmt;
111*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> dec_stream_fpmt;
112*77c1e3ccSAndroid Build Coastguard Worker enc_stream_fpmt_size = size_enc_;
113*77c1e3ccSAndroid Build Coastguard Worker enc_stream_fpmt = md5_enc_;
114*77c1e3ccSAndroid Build Coastguard Worker dec_stream_fpmt = md5_dec_;
115*77c1e3ccSAndroid Build Coastguard Worker size_enc_.clear();
116*77c1e3ccSAndroid Build Coastguard Worker md5_enc_.clear();
117*77c1e3ccSAndroid Build Coastguard Worker md5_dec_.clear();
118*77c1e3ccSAndroid Build Coastguard Worker
119*77c1e3ccSAndroid Build Coastguard Worker /* This is the simulation of parallel encode of frames using single cpi.
120*77c1e3ccSAndroid Build Coastguard Worker * In simulation, it should be ensured to have no dependency across frames
121*77c1e3ccSAndroid Build Coastguard Worker * (similar to parallel encode).
122*77c1e3ccSAndroid Build Coastguard Worker * Each frame uses all the threads configured.
123*77c1e3ccSAndroid Build Coastguard Worker */
124*77c1e3ccSAndroid Build Coastguard Worker enable_actual_parallel_encode_ = 0;
125*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(input_video));
126*77c1e3ccSAndroid Build Coastguard Worker std::vector<size_t> enc_stream_sim_size;
127*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> enc_stream_sim;
128*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> dec_stream_sim;
129*77c1e3ccSAndroid Build Coastguard Worker enc_stream_sim_size = size_enc_;
130*77c1e3ccSAndroid Build Coastguard Worker enc_stream_sim = md5_enc_;
131*77c1e3ccSAndroid Build Coastguard Worker dec_stream_sim = md5_dec_;
132*77c1e3ccSAndroid Build Coastguard Worker size_enc_.clear();
133*77c1e3ccSAndroid Build Coastguard Worker md5_enc_.clear();
134*77c1e3ccSAndroid Build Coastguard Worker md5_dec_.clear();
135*77c1e3ccSAndroid Build Coastguard Worker
136*77c1e3ccSAndroid Build Coastguard Worker // Check that the vectors are equal.
137*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(enc_stream_sim_size, enc_stream_fpmt_size);
138*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(enc_stream_sim, enc_stream_fpmt);
139*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(dec_stream_sim, dec_stream_fpmt);
140*77c1e3ccSAndroid Build Coastguard Worker }
141*77c1e3ccSAndroid Build Coastguard Worker
142*77c1e3ccSAndroid Build Coastguard Worker bool encoder_initialized_;
143*77c1e3ccSAndroid Build Coastguard Worker int set_cpu_used_;
144*77c1e3ccSAndroid Build Coastguard Worker int tile_cols_;
145*77c1e3ccSAndroid Build Coastguard Worker int tile_rows_;
146*77c1e3ccSAndroid Build Coastguard Worker int enable_actual_parallel_encode_;
147*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Decoder *decoder_;
148*77c1e3ccSAndroid Build Coastguard Worker std::vector<size_t> size_enc_;
149*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> md5_enc_;
150*77c1e3ccSAndroid Build Coastguard Worker std::vector<std::string> md5_dec_;
151*77c1e3ccSAndroid Build Coastguard Worker };
152*77c1e3ccSAndroid Build Coastguard Worker
153*77c1e3ccSAndroid Build Coastguard Worker class AVxFrameParallelThreadEncodeHDResTestLarge
154*77c1e3ccSAndroid Build Coastguard Worker : public AVxFrameParallelThreadEncodeTest {};
155*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AVxFrameParallelThreadEncodeHDResTestLarge,FrameParallelThreadEncodeTest)156*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AVxFrameParallelThreadEncodeHDResTestLarge,
157*77c1e3ccSAndroid Build Coastguard Worker FrameParallelThreadEncodeTest) {
158*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
159*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 500;
160*77c1e3ccSAndroid Build Coastguard Worker DoTest(&video);
161*77c1e3ccSAndroid Build Coastguard Worker }
162*77c1e3ccSAndroid Build Coastguard Worker
163*77c1e3ccSAndroid Build Coastguard Worker class AVxFrameParallelThreadEncodeLowResTestLarge
164*77c1e3ccSAndroid Build Coastguard Worker : public AVxFrameParallelThreadEncodeTest {};
165*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AVxFrameParallelThreadEncodeLowResTestLarge,FrameParallelThreadEncodeTest)166*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AVxFrameParallelThreadEncodeLowResTestLarge,
167*77c1e3ccSAndroid Build Coastguard Worker FrameParallelThreadEncodeTest) {
168*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::YUVVideoSource video("hantro_collage_w352h288.yuv",
169*77c1e3ccSAndroid Build Coastguard Worker AOM_IMG_FMT_I420, 352, 288, 30, 1, 0, 60);
170*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 200;
171*77c1e3ccSAndroid Build Coastguard Worker DoTest(&video);
172*77c1e3ccSAndroid Build Coastguard Worker }
173*77c1e3ccSAndroid Build Coastguard Worker
174*77c1e3ccSAndroid Build Coastguard Worker class AVxFrameParallelThreadEncodeLowResTest
175*77c1e3ccSAndroid Build Coastguard Worker : public AVxFrameParallelThreadEncodeTest {};
176*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AVxFrameParallelThreadEncodeLowResTest,FrameParallelThreadEncodeTest)177*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AVxFrameParallelThreadEncodeLowResTest, FrameParallelThreadEncodeTest) {
178*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::YUVVideoSource video("hantro_collage_w352h288.yuv",
179*77c1e3ccSAndroid Build Coastguard Worker AOM_IMG_FMT_I420, 352, 288, 30, 1, 0, 60);
180*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 200;
181*77c1e3ccSAndroid Build Coastguard Worker DoTest(&video);
182*77c1e3ccSAndroid Build Coastguard Worker }
183*77c1e3ccSAndroid Build Coastguard Worker
184*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AVxFrameParallelThreadEncodeHDResTestLarge,
185*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(2, 3, 4, 5, 6),
186*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(0, 1, 2), ::testing::Values(0, 1));
187*77c1e3ccSAndroid Build Coastguard Worker
188*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AVxFrameParallelThreadEncodeLowResTestLarge,
189*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(2, 3), ::testing::Values(0, 1, 2),
190*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(0, 1));
191*77c1e3ccSAndroid Build Coastguard Worker
192*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(AVxFrameParallelThreadEncodeLowResTest,
193*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(4, 5, 6), ::testing::Values(1),
194*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(0));
195*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_FPMT_TEST && !CONFIG_REALTIME_ONLY
196*77c1e3ccSAndroid Build Coastguard Worker
197*77c1e3ccSAndroid Build Coastguard Worker } // namespace
198