1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, 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 <climits>
13*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aomcx.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/aom_dsp_common.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/encoder.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/i420_video_source.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "test/video_source.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "test/y4m_video_source.h"
25*77c1e3ccSAndroid Build Coastguard Worker
26*77c1e3ccSAndroid Build Coastguard Worker // Enable(1) or Disable(0) writing of the compressed bitstream.
27*77c1e3ccSAndroid Build Coastguard Worker #define WRITE_COMPRESSED_STREAM 0
28*77c1e3ccSAndroid Build Coastguard Worker
29*77c1e3ccSAndroid Build Coastguard Worker namespace {
30*77c1e3ccSAndroid Build Coastguard Worker
31*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
mem_put_le16(char * const mem,unsigned int val)32*77c1e3ccSAndroid Build Coastguard Worker static void mem_put_le16(char *const mem, unsigned int val) {
33*77c1e3ccSAndroid Build Coastguard Worker mem[0] = val;
34*77c1e3ccSAndroid Build Coastguard Worker mem[1] = val >> 8;
35*77c1e3ccSAndroid Build Coastguard Worker }
36*77c1e3ccSAndroid Build Coastguard Worker
mem_put_le32(char * const mem,unsigned int val)37*77c1e3ccSAndroid Build Coastguard Worker static void mem_put_le32(char *const mem, unsigned int val) {
38*77c1e3ccSAndroid Build Coastguard Worker mem[0] = val;
39*77c1e3ccSAndroid Build Coastguard Worker mem[1] = val >> 8;
40*77c1e3ccSAndroid Build Coastguard Worker mem[2] = val >> 16;
41*77c1e3ccSAndroid Build Coastguard Worker mem[3] = val >> 24;
42*77c1e3ccSAndroid Build Coastguard Worker }
43*77c1e3ccSAndroid Build Coastguard Worker
write_ivf_file_header(const aom_codec_enc_cfg_t * const cfg,int frame_cnt,FILE * const outfile)44*77c1e3ccSAndroid Build Coastguard Worker static void write_ivf_file_header(const aom_codec_enc_cfg_t *const cfg,
45*77c1e3ccSAndroid Build Coastguard Worker int frame_cnt, FILE *const outfile) {
46*77c1e3ccSAndroid Build Coastguard Worker char header[32];
47*77c1e3ccSAndroid Build Coastguard Worker
48*77c1e3ccSAndroid Build Coastguard Worker header[0] = 'D';
49*77c1e3ccSAndroid Build Coastguard Worker header[1] = 'K';
50*77c1e3ccSAndroid Build Coastguard Worker header[2] = 'I';
51*77c1e3ccSAndroid Build Coastguard Worker header[3] = 'F';
52*77c1e3ccSAndroid Build Coastguard Worker mem_put_le16(header + 4, 0); /* version */
53*77c1e3ccSAndroid Build Coastguard Worker mem_put_le16(header + 6, 32); /* headersize */
54*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 8, AV1_FOURCC); /* fourcc (av1) */
55*77c1e3ccSAndroid Build Coastguard Worker mem_put_le16(header + 12, cfg->g_w); /* width */
56*77c1e3ccSAndroid Build Coastguard Worker mem_put_le16(header + 14, cfg->g_h); /* height */
57*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 16, cfg->g_timebase.den); /* rate */
58*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 20, cfg->g_timebase.num); /* scale */
59*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 24, frame_cnt); /* length */
60*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 28, 0); /* unused */
61*77c1e3ccSAndroid Build Coastguard Worker
62*77c1e3ccSAndroid Build Coastguard Worker (void)fwrite(header, 1, 32, outfile);
63*77c1e3ccSAndroid Build Coastguard Worker }
64*77c1e3ccSAndroid Build Coastguard Worker
write_ivf_frame_size(FILE * const outfile,const size_t size)65*77c1e3ccSAndroid Build Coastguard Worker static void write_ivf_frame_size(FILE *const outfile, const size_t size) {
66*77c1e3ccSAndroid Build Coastguard Worker char header[4];
67*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header, static_cast<unsigned int>(size));
68*77c1e3ccSAndroid Build Coastguard Worker (void)fwrite(header, 1, 4, outfile);
69*77c1e3ccSAndroid Build Coastguard Worker }
70*77c1e3ccSAndroid Build Coastguard Worker
write_ivf_frame_header(const aom_codec_cx_pkt_t * const pkt,FILE * const outfile)71*77c1e3ccSAndroid Build Coastguard Worker static void write_ivf_frame_header(const aom_codec_cx_pkt_t *const pkt,
72*77c1e3ccSAndroid Build Coastguard Worker FILE *const outfile) {
73*77c1e3ccSAndroid Build Coastguard Worker char header[12];
74*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t pts;
75*77c1e3ccSAndroid Build Coastguard Worker
76*77c1e3ccSAndroid Build Coastguard Worker if (pkt->kind != AOM_CODEC_CX_FRAME_PKT) return;
77*77c1e3ccSAndroid Build Coastguard Worker
78*77c1e3ccSAndroid Build Coastguard Worker pts = pkt->data.frame.pts;
79*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header, static_cast<unsigned int>(pkt->data.frame.sz));
80*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 4, pts & 0xFFFFFFFF);
81*77c1e3ccSAndroid Build Coastguard Worker mem_put_le32(header + 8, pts >> 32);
82*77c1e3ccSAndroid Build Coastguard Worker
83*77c1e3ccSAndroid Build Coastguard Worker (void)fwrite(header, 1, 12, outfile);
84*77c1e3ccSAndroid Build Coastguard Worker }
85*77c1e3ccSAndroid Build Coastguard Worker #endif // WRITE_COMPRESSED_STREAM
86*77c1e3ccSAndroid Build Coastguard Worker
87*77c1e3ccSAndroid Build Coastguard Worker const unsigned int kInitialWidth = 320;
88*77c1e3ccSAndroid Build Coastguard Worker const unsigned int kInitialHeight = 240;
89*77c1e3ccSAndroid Build Coastguard Worker
90*77c1e3ccSAndroid Build Coastguard Worker struct FrameInfo {
FrameInfo__anone64d961e0111::FrameInfo91*77c1e3ccSAndroid Build Coastguard Worker FrameInfo(aom_codec_pts_t _pts, unsigned int _w, unsigned int _h)
92*77c1e3ccSAndroid Build Coastguard Worker : pts(_pts), w(_w), h(_h) {}
93*77c1e3ccSAndroid Build Coastguard Worker
94*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t pts;
95*77c1e3ccSAndroid Build Coastguard Worker unsigned int w;
96*77c1e3ccSAndroid Build Coastguard Worker unsigned int h;
97*77c1e3ccSAndroid Build Coastguard Worker };
98*77c1e3ccSAndroid Build Coastguard Worker
ScaleForFrameNumber(unsigned int frame,unsigned int initial_w,unsigned int initial_h,int flag_codec,bool change_start_resln,unsigned int * w,unsigned int * h)99*77c1e3ccSAndroid Build Coastguard Worker void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w,
100*77c1e3ccSAndroid Build Coastguard Worker unsigned int initial_h, int flag_codec,
101*77c1e3ccSAndroid Build Coastguard Worker bool change_start_resln, unsigned int *w,
102*77c1e3ccSAndroid Build Coastguard Worker unsigned int *h) {
103*77c1e3ccSAndroid Build Coastguard Worker if (frame < 10) {
104*77c1e3ccSAndroid Build Coastguard Worker if (change_start_resln) {
105*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w / 4;
106*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h / 4;
107*77c1e3ccSAndroid Build Coastguard Worker } else {
108*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w;
109*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h;
110*77c1e3ccSAndroid Build Coastguard Worker }
111*77c1e3ccSAndroid Build Coastguard Worker return;
112*77c1e3ccSAndroid Build Coastguard Worker }
113*77c1e3ccSAndroid Build Coastguard Worker if (frame < 20) {
114*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w * 3 / 4;
115*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h * 3 / 4;
116*77c1e3ccSAndroid Build Coastguard Worker return;
117*77c1e3ccSAndroid Build Coastguard Worker }
118*77c1e3ccSAndroid Build Coastguard Worker if (frame < 30) {
119*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w / 2;
120*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h / 2;
121*77c1e3ccSAndroid Build Coastguard Worker return;
122*77c1e3ccSAndroid Build Coastguard Worker }
123*77c1e3ccSAndroid Build Coastguard Worker if (frame < 40) {
124*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w;
125*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h;
126*77c1e3ccSAndroid Build Coastguard Worker return;
127*77c1e3ccSAndroid Build Coastguard Worker }
128*77c1e3ccSAndroid Build Coastguard Worker if (frame < 50) {
129*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w * 3 / 4;
130*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h * 3 / 4;
131*77c1e3ccSAndroid Build Coastguard Worker return;
132*77c1e3ccSAndroid Build Coastguard Worker }
133*77c1e3ccSAndroid Build Coastguard Worker if (frame < 60) {
134*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w / 2;
135*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h / 2;
136*77c1e3ccSAndroid Build Coastguard Worker return;
137*77c1e3ccSAndroid Build Coastguard Worker }
138*77c1e3ccSAndroid Build Coastguard Worker if (frame < 70) {
139*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w;
140*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h;
141*77c1e3ccSAndroid Build Coastguard Worker return;
142*77c1e3ccSAndroid Build Coastguard Worker }
143*77c1e3ccSAndroid Build Coastguard Worker if (frame < 80) {
144*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w * 3 / 4;
145*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h * 3 / 4;
146*77c1e3ccSAndroid Build Coastguard Worker return;
147*77c1e3ccSAndroid Build Coastguard Worker }
148*77c1e3ccSAndroid Build Coastguard Worker if (frame < 90) {
149*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w / 2;
150*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h / 2;
151*77c1e3ccSAndroid Build Coastguard Worker return;
152*77c1e3ccSAndroid Build Coastguard Worker }
153*77c1e3ccSAndroid Build Coastguard Worker if (frame < 100) {
154*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w * 3 / 4;
155*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h * 3 / 4;
156*77c1e3ccSAndroid Build Coastguard Worker return;
157*77c1e3ccSAndroid Build Coastguard Worker }
158*77c1e3ccSAndroid Build Coastguard Worker if (frame < 110) {
159*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w;
160*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h;
161*77c1e3ccSAndroid Build Coastguard Worker return;
162*77c1e3ccSAndroid Build Coastguard Worker }
163*77c1e3ccSAndroid Build Coastguard Worker // Go down very low
164*77c1e3ccSAndroid Build Coastguard Worker if (frame < 120) {
165*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w / 4;
166*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h / 4;
167*77c1e3ccSAndroid Build Coastguard Worker return;
168*77c1e3ccSAndroid Build Coastguard Worker }
169*77c1e3ccSAndroid Build Coastguard Worker if (flag_codec == 1) {
170*77c1e3ccSAndroid Build Coastguard Worker // Cases that only works for AV1.
171*77c1e3ccSAndroid Build Coastguard Worker // For AV1: Swap width and height of original.
172*77c1e3ccSAndroid Build Coastguard Worker if (frame < 140) {
173*77c1e3ccSAndroid Build Coastguard Worker *w = initial_h;
174*77c1e3ccSAndroid Build Coastguard Worker *h = initial_w;
175*77c1e3ccSAndroid Build Coastguard Worker return;
176*77c1e3ccSAndroid Build Coastguard Worker }
177*77c1e3ccSAndroid Build Coastguard Worker }
178*77c1e3ccSAndroid Build Coastguard Worker *w = initial_w;
179*77c1e3ccSAndroid Build Coastguard Worker *h = initial_h;
180*77c1e3ccSAndroid Build Coastguard Worker }
181*77c1e3ccSAndroid Build Coastguard Worker
182*77c1e3ccSAndroid Build Coastguard Worker class ResizingVideoSource : public ::libaom_test::DummyVideoSource {
183*77c1e3ccSAndroid Build Coastguard Worker public:
ResizingVideoSource()184*77c1e3ccSAndroid Build Coastguard Worker ResizingVideoSource() {
185*77c1e3ccSAndroid Build Coastguard Worker SetSize(kInitialWidth, kInitialHeight);
186*77c1e3ccSAndroid Build Coastguard Worker limit_ = 150;
187*77c1e3ccSAndroid Build Coastguard Worker }
188*77c1e3ccSAndroid Build Coastguard Worker int flag_codec_;
189*77c1e3ccSAndroid Build Coastguard Worker bool change_start_resln_;
190*77c1e3ccSAndroid Build Coastguard Worker ~ResizingVideoSource() override = default;
191*77c1e3ccSAndroid Build Coastguard Worker
192*77c1e3ccSAndroid Build Coastguard Worker protected:
Begin()193*77c1e3ccSAndroid Build Coastguard Worker void Begin() override {
194*77c1e3ccSAndroid Build Coastguard Worker frame_ = 0;
195*77c1e3ccSAndroid Build Coastguard Worker unsigned int width;
196*77c1e3ccSAndroid Build Coastguard Worker unsigned int height;
197*77c1e3ccSAndroid Build Coastguard Worker ScaleForFrameNumber(frame_, kInitialWidth, kInitialHeight, flag_codec_,
198*77c1e3ccSAndroid Build Coastguard Worker change_start_resln_, &width, &height);
199*77c1e3ccSAndroid Build Coastguard Worker SetSize(width, height);
200*77c1e3ccSAndroid Build Coastguard Worker FillFrame();
201*77c1e3ccSAndroid Build Coastguard Worker }
Next()202*77c1e3ccSAndroid Build Coastguard Worker void Next() override {
203*77c1e3ccSAndroid Build Coastguard Worker ++frame_;
204*77c1e3ccSAndroid Build Coastguard Worker unsigned int width;
205*77c1e3ccSAndroid Build Coastguard Worker unsigned int height;
206*77c1e3ccSAndroid Build Coastguard Worker ScaleForFrameNumber(frame_, kInitialWidth, kInitialHeight, flag_codec_,
207*77c1e3ccSAndroid Build Coastguard Worker change_start_resln_, &width, &height);
208*77c1e3ccSAndroid Build Coastguard Worker SetSize(width, height);
209*77c1e3ccSAndroid Build Coastguard Worker FillFrame();
210*77c1e3ccSAndroid Build Coastguard Worker }
211*77c1e3ccSAndroid Build Coastguard Worker };
212*77c1e3ccSAndroid Build Coastguard Worker
213*77c1e3ccSAndroid Build Coastguard Worker class ResizeTest
214*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWithParam<libaom_test::TestMode>,
215*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
216*77c1e3ccSAndroid Build Coastguard Worker protected:
ResizeTest()217*77c1e3ccSAndroid Build Coastguard Worker ResizeTest() : EncoderTest(GET_PARAM(0)) {}
218*77c1e3ccSAndroid Build Coastguard Worker
219*77c1e3ccSAndroid Build Coastguard Worker ~ResizeTest() override = default;
220*77c1e3ccSAndroid Build Coastguard Worker
SetUp()221*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override { InitializeConfig(GET_PARAM(1)); }
222*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(libaom_test::VideoSource * video,libaom_test::Encoder * encoder)223*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(libaom_test::VideoSource *video,
224*77c1e3ccSAndroid Build Coastguard Worker libaom_test::Encoder *encoder) override {
225*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
226*77c1e3ccSAndroid Build Coastguard Worker if (GET_PARAM(1) == ::libaom_test::kRealTime) {
227*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_AQ_MODE, 3);
228*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, 5);
229*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
230*77c1e3ccSAndroid Build Coastguard Worker }
231*77c1e3ccSAndroid Build Coastguard Worker }
232*77c1e3ccSAndroid Build Coastguard Worker }
233*77c1e3ccSAndroid Build Coastguard Worker
DecompressedFrameHook(const aom_image_t & img,aom_codec_pts_t pts)234*77c1e3ccSAndroid Build Coastguard Worker void DecompressedFrameHook(const aom_image_t &img,
235*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t pts) override {
236*77c1e3ccSAndroid Build Coastguard Worker frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h));
237*77c1e3ccSAndroid Build Coastguard Worker }
238*77c1e3ccSAndroid Build Coastguard Worker
239*77c1e3ccSAndroid Build Coastguard Worker std::vector<FrameInfo> frame_info_list_;
240*77c1e3ccSAndroid Build Coastguard Worker };
241*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ResizeTest,TestExternalResizeWorks)242*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeTest, TestExternalResizeWorks) {
243*77c1e3ccSAndroid Build Coastguard Worker ResizingVideoSource video;
244*77c1e3ccSAndroid Build Coastguard Worker video.flag_codec_ = 0;
245*77c1e3ccSAndroid Build Coastguard Worker video.change_start_resln_ = false;
246*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
247*77c1e3ccSAndroid Build Coastguard Worker // We use max(kInitialWidth, kInitialHeight) because during the test
248*77c1e3ccSAndroid Build Coastguard Worker // the width and height of the frame are swapped
249*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_width = cfg_.g_forced_max_frame_height =
250*77c1e3ccSAndroid Build Coastguard Worker AOMMAX(kInitialWidth, kInitialHeight);
251*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
252*77c1e3ccSAndroid Build Coastguard Worker
253*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
254*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
255*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
256*77c1e3ccSAndroid Build Coastguard Worker
257*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
258*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
259*77c1e3ccSAndroid Build Coastguard Worker const unsigned int frame = static_cast<unsigned>(info->pts);
260*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w;
261*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h;
262*77c1e3ccSAndroid Build Coastguard Worker ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight, video.flag_codec_,
263*77c1e3ccSAndroid Build Coastguard Worker video.change_start_resln_, &expected_w, &expected_h);
264*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info->w)
265*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
266*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info->h)
267*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
268*77c1e3ccSAndroid Build Coastguard Worker }
269*77c1e3ccSAndroid Build Coastguard Worker #endif
270*77c1e3ccSAndroid Build Coastguard Worker }
271*77c1e3ccSAndroid Build Coastguard Worker
272*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
273*77c1e3ccSAndroid Build Coastguard Worker const unsigned int kStepDownFrame = 3;
274*77c1e3ccSAndroid Build Coastguard Worker const unsigned int kStepUpFrame = 6;
275*77c1e3ccSAndroid Build Coastguard Worker
276*77c1e3ccSAndroid Build Coastguard Worker class ResizeInternalTestLarge : public ResizeTest {
277*77c1e3ccSAndroid Build Coastguard Worker protected:
278*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
ResizeInternalTestLarge()279*77c1e3ccSAndroid Build Coastguard Worker ResizeInternalTestLarge()
280*77c1e3ccSAndroid Build Coastguard Worker : ResizeTest(), frame0_psnr_(0.0), outfile_(nullptr), out_frames_(0) {}
281*77c1e3ccSAndroid Build Coastguard Worker #else
282*77c1e3ccSAndroid Build Coastguard Worker ResizeInternalTestLarge() : ResizeTest(), frame0_psnr_(0.0) {}
283*77c1e3ccSAndroid Build Coastguard Worker #endif
284*77c1e3ccSAndroid Build Coastguard Worker
285*77c1e3ccSAndroid Build Coastguard Worker ~ResizeInternalTestLarge() override = default;
286*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)287*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int /*pass*/) override {
288*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
289*77c1e3ccSAndroid Build Coastguard Worker outfile_ = fopen("av10-2-05-resize.ivf", "wb");
290*77c1e3ccSAndroid Build Coastguard Worker #endif
291*77c1e3ccSAndroid Build Coastguard Worker }
292*77c1e3ccSAndroid Build Coastguard Worker
EndPassHook()293*77c1e3ccSAndroid Build Coastguard Worker void EndPassHook() override {
294*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
295*77c1e3ccSAndroid Build Coastguard Worker if (outfile_) {
296*77c1e3ccSAndroid Build Coastguard Worker if (!fseek(outfile_, 0, SEEK_SET))
297*77c1e3ccSAndroid Build Coastguard Worker write_ivf_file_header(&cfg_, out_frames_, outfile_);
298*77c1e3ccSAndroid Build Coastguard Worker fclose(outfile_);
299*77c1e3ccSAndroid Build Coastguard Worker outfile_ = nullptr;
300*77c1e3ccSAndroid Build Coastguard Worker }
301*77c1e3ccSAndroid Build Coastguard Worker #endif
302*77c1e3ccSAndroid Build Coastguard Worker }
303*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(libaom_test::VideoSource * video,libaom_test::Encoder * encoder)304*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(libaom_test::VideoSource *video,
305*77c1e3ccSAndroid Build Coastguard Worker libaom_test::Encoder *encoder) override {
306*77c1e3ccSAndroid Build Coastguard Worker if (change_config_) {
307*77c1e3ccSAndroid Build Coastguard Worker int new_q = 60;
308*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
309*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode = { AOME_ONETWO, AOME_ONETWO };
310*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
311*77c1e3ccSAndroid Build Coastguard Worker } else if (video->frame() == 1) {
312*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode = { AOME_NORMAL, AOME_NORMAL };
313*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
314*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = new_q;
315*77c1e3ccSAndroid Build Coastguard Worker encoder->Config(&cfg_);
316*77c1e3ccSAndroid Build Coastguard Worker }
317*77c1e3ccSAndroid Build Coastguard Worker } else {
318*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() >= kStepDownFrame && video->frame() < kStepUpFrame) {
319*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode = { AOME_FOURFIVE, AOME_THREEFIVE };
320*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
321*77c1e3ccSAndroid Build Coastguard Worker }
322*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() >= kStepUpFrame) {
323*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode = { AOME_NORMAL, AOME_NORMAL };
324*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
325*77c1e3ccSAndroid Build Coastguard Worker }
326*77c1e3ccSAndroid Build Coastguard Worker }
327*77c1e3ccSAndroid Build Coastguard Worker }
328*77c1e3ccSAndroid Build Coastguard Worker
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)329*77c1e3ccSAndroid Build Coastguard Worker void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
330*77c1e3ccSAndroid Build Coastguard Worker if (frame0_psnr_ == 0.) frame0_psnr_ = pkt->data.psnr.psnr[0];
331*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 4.1);
332*77c1e3ccSAndroid Build Coastguard Worker }
333*77c1e3ccSAndroid Build Coastguard Worker
334*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
FramePktHook(const aom_codec_cx_pkt_t * pkt)335*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
336*77c1e3ccSAndroid Build Coastguard Worker ++out_frames_;
337*77c1e3ccSAndroid Build Coastguard Worker
338*77c1e3ccSAndroid Build Coastguard Worker // Write initial file header if first frame.
339*77c1e3ccSAndroid Build Coastguard Worker if (pkt->data.frame.pts == 0) write_ivf_file_header(&cfg_, 0, outfile_);
340*77c1e3ccSAndroid Build Coastguard Worker
341*77c1e3ccSAndroid Build Coastguard Worker // Write frame header and data.
342*77c1e3ccSAndroid Build Coastguard Worker write_ivf_frame_header(pkt, outfile_);
343*77c1e3ccSAndroid Build Coastguard Worker (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_);
344*77c1e3ccSAndroid Build Coastguard Worker }
345*77c1e3ccSAndroid Build Coastguard Worker #endif
346*77c1e3ccSAndroid Build Coastguard Worker
347*77c1e3ccSAndroid Build Coastguard Worker double frame0_psnr_;
348*77c1e3ccSAndroid Build Coastguard Worker bool change_config_;
349*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
350*77c1e3ccSAndroid Build Coastguard Worker FILE *outfile_;
351*77c1e3ccSAndroid Build Coastguard Worker unsigned int out_frames_;
352*77c1e3ccSAndroid Build Coastguard Worker #endif
353*77c1e3ccSAndroid Build Coastguard Worker };
354*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ResizeInternalTestLarge,TestInternalResizeWorks)355*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeInternalTestLarge, TestInternalResizeWorks) {
356*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
357*77c1e3ccSAndroid Build Coastguard Worker 30, 1, 0, 10);
358*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
359*77c1e3ccSAndroid Build Coastguard Worker change_config_ = false;
360*77c1e3ccSAndroid Build Coastguard Worker
361*77c1e3ccSAndroid Build Coastguard Worker // q picked such that initial keyframe on this clip is ~30dB PSNR
362*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48;
363*77c1e3ccSAndroid Build Coastguard Worker
364*77c1e3ccSAndroid Build Coastguard Worker // If the number of frames being encoded is smaller than g_lag_in_frames
365*77c1e3ccSAndroid Build Coastguard Worker // the encoded frame is unavailable using the current API. Comparing
366*77c1e3ccSAndroid Build Coastguard Worker // frames to detect mismatch would then not be possible. Set
367*77c1e3ccSAndroid Build Coastguard Worker // g_lag_in_frames = 0 to get around this.
368*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
369*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
370*77c1e3ccSAndroid Build Coastguard Worker
371*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
372*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
373*77c1e3ccSAndroid Build Coastguard Worker }
374*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
375*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
376*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_pts_t pts = info->pts;
377*77c1e3ccSAndroid Build Coastguard Worker if (pts >= kStepDownFrame && pts < kStepUpFrame) {
378*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width";
379*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height";
380*77c1e3ccSAndroid Build Coastguard Worker } else {
381*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width";
382*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height";
383*77c1e3ccSAndroid Build Coastguard Worker }
384*77c1e3ccSAndroid Build Coastguard Worker }
385*77c1e3ccSAndroid Build Coastguard Worker }
386*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ResizeInternalTestLarge,TestInternalResizeChangeConfig)387*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeInternalTestLarge, TestInternalResizeChangeConfig) {
388*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
389*77c1e3ccSAndroid Build Coastguard Worker 30, 1, 0, 10);
390*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 352;
391*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 288;
392*77c1e3ccSAndroid Build Coastguard Worker change_config_ = true;
393*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
394*77c1e3ccSAndroid Build Coastguard Worker }
395*77c1e3ccSAndroid Build Coastguard Worker
396*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ResizeInternalTestLarge,
397*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kOnePassGood));
398*77c1e3ccSAndroid Build Coastguard Worker #endif
399*77c1e3ccSAndroid Build Coastguard Worker
400*77c1e3ccSAndroid Build Coastguard Worker // Parameters: test mode, speed, threads
401*77c1e3ccSAndroid Build Coastguard Worker class ResizeRealtimeTest
402*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith3Params<libaom_test::TestMode, int,
403*77c1e3ccSAndroid Build Coastguard Worker int>,
404*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
405*77c1e3ccSAndroid Build Coastguard Worker protected:
ResizeRealtimeTest()406*77c1e3ccSAndroid Build Coastguard Worker ResizeRealtimeTest()
407*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), num_threads_(GET_PARAM(3)),
408*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_(false), set_scale_mode2_(false),
409*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_(false), is_screen_(false) {}
410*77c1e3ccSAndroid Build Coastguard Worker ~ResizeRealtimeTest() override = default;
411*77c1e3ccSAndroid Build Coastguard Worker
PreEncodeFrameHook(libaom_test::VideoSource * video,libaom_test::Encoder * encoder)412*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(libaom_test::VideoSource *video,
413*77c1e3ccSAndroid Build Coastguard Worker libaom_test::Encoder *encoder) override {
414*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
415*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_AQ_MODE, 3);
416*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_ALLOW_WARPED_MOTION, 0);
417*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_ENABLE_GLOBAL_MOTION, 0);
418*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_ENABLE_OBMC, 0);
419*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, set_cpu_used_);
420*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_FRAME_PARALLEL_DECODING, 1);
421*77c1e3ccSAndroid Build Coastguard Worker if (is_screen_)
422*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN);
423*77c1e3ccSAndroid Build Coastguard Worker }
424*77c1e3ccSAndroid Build Coastguard Worker if (set_scale_mode_) {
425*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode;
426*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() <= 20)
427*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_ONETWO, AOME_ONETWO };
428*77c1e3ccSAndroid Build Coastguard Worker else if (video->frame() <= 40)
429*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_ONEFOUR, AOME_ONEFOUR };
430*77c1e3ccSAndroid Build Coastguard Worker else if (video->frame() > 40)
431*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_NORMAL, AOME_NORMAL };
432*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
433*77c1e3ccSAndroid Build Coastguard Worker } else if (set_scale_mode2_) {
434*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode;
435*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() <= 20)
436*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_ONEFOUR, AOME_ONEFOUR };
437*77c1e3ccSAndroid Build Coastguard Worker else if (video->frame() <= 40)
438*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_ONETWO, AOME_ONETWO };
439*77c1e3ccSAndroid Build Coastguard Worker else if (video->frame() > 40)
440*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_THREEFOUR, AOME_THREEFOUR };
441*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
442*77c1e3ccSAndroid Build Coastguard Worker } else if (set_scale_mode3_) {
443*77c1e3ccSAndroid Build Coastguard Worker struct aom_scaling_mode mode;
444*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() <= 30)
445*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_ONETWO, AOME_NORMAL };
446*77c1e3ccSAndroid Build Coastguard Worker else
447*77c1e3ccSAndroid Build Coastguard Worker mode = { AOME_NORMAL, AOME_NORMAL };
448*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_SCALEMODE, &mode);
449*77c1e3ccSAndroid Build Coastguard Worker }
450*77c1e3ccSAndroid Build Coastguard Worker
451*77c1e3ccSAndroid Build Coastguard Worker if (change_bitrate_ && video->frame() == frame_change_bitrate_) {
452*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
453*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 500;
454*77c1e3ccSAndroid Build Coastguard Worker encoder->Config(&cfg_);
455*77c1e3ccSAndroid Build Coastguard Worker }
456*77c1e3ccSAndroid Build Coastguard Worker }
457*77c1e3ccSAndroid Build Coastguard Worker
SetUp()458*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
459*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(GET_PARAM(1));
460*77c1e3ccSAndroid Build Coastguard Worker set_cpu_used_ = GET_PARAM(2);
461*77c1e3ccSAndroid Build Coastguard Worker }
462*77c1e3ccSAndroid Build Coastguard Worker
DecompressedFrameHook(const aom_image_t & img,aom_codec_pts_t pts)463*77c1e3ccSAndroid Build Coastguard Worker void DecompressedFrameHook(const aom_image_t &img,
464*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t pts) override {
465*77c1e3ccSAndroid Build Coastguard Worker frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h));
466*77c1e3ccSAndroid Build Coastguard Worker }
467*77c1e3ccSAndroid Build Coastguard Worker
MismatchHook(const aom_image_t * img1,const aom_image_t * img2)468*77c1e3ccSAndroid Build Coastguard Worker void MismatchHook(const aom_image_t *img1, const aom_image_t *img2) override {
469*77c1e3ccSAndroid Build Coastguard Worker double mismatch_psnr = compute_psnr(img1, img2);
470*77c1e3ccSAndroid Build Coastguard Worker mismatch_psnr_ += mismatch_psnr;
471*77c1e3ccSAndroid Build Coastguard Worker ++mismatch_nframes_;
472*77c1e3ccSAndroid Build Coastguard Worker }
473*77c1e3ccSAndroid Build Coastguard Worker
GetMismatchFrames()474*77c1e3ccSAndroid Build Coastguard Worker unsigned int GetMismatchFrames() { return mismatch_nframes_; }
475*77c1e3ccSAndroid Build Coastguard Worker
DefaultConfig()476*77c1e3ccSAndroid Build Coastguard Worker void DefaultConfig() {
477*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_initial_sz = 500;
478*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_optimal_sz = 600;
479*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_buf_sz = 1000;
480*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = 2;
481*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_max_quantizer = 56;
482*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_undershoot_pct = 50;
483*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_overshoot_pct = 50;
484*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_CBR;
485*77c1e3ccSAndroid Build Coastguard Worker cfg_.kf_mode = AOM_KF_AUTO;
486*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
487*77c1e3ccSAndroid Build Coastguard Worker cfg_.kf_min_dist = cfg_.kf_max_dist = 3000;
488*77c1e3ccSAndroid Build Coastguard Worker // Enable dropped frames.
489*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 1;
490*77c1e3ccSAndroid Build Coastguard Worker // Disable error_resilience mode.
491*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_error_resilient = 0;
492*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_threads = num_threads_;
493*77c1e3ccSAndroid Build Coastguard Worker // Run at low bitrate.
494*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 200;
495*77c1e3ccSAndroid Build Coastguard Worker // We use max(kInitialWidth, kInitialHeight) because during the test
496*77c1e3ccSAndroid Build Coastguard Worker // the width and height of the frame are swapped
497*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_width = cfg_.g_forced_max_frame_height =
498*77c1e3ccSAndroid Build Coastguard Worker AOMMAX(kInitialWidth, kInitialHeight);
499*77c1e3ccSAndroid Build Coastguard Worker if (set_scale_mode_ || set_scale_mode2_ || set_scale_mode3_) {
500*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 0;
501*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_width = 1280;
502*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_height = 1280;
503*77c1e3ccSAndroid Build Coastguard Worker }
504*77c1e3ccSAndroid Build Coastguard Worker }
505*77c1e3ccSAndroid Build Coastguard Worker
506*77c1e3ccSAndroid Build Coastguard Worker std::vector<FrameInfo> frame_info_list_;
507*77c1e3ccSAndroid Build Coastguard Worker int set_cpu_used_;
508*77c1e3ccSAndroid Build Coastguard Worker int num_threads_;
509*77c1e3ccSAndroid Build Coastguard Worker bool change_bitrate_;
510*77c1e3ccSAndroid Build Coastguard Worker unsigned int frame_change_bitrate_;
511*77c1e3ccSAndroid Build Coastguard Worker double mismatch_psnr_;
512*77c1e3ccSAndroid Build Coastguard Worker int mismatch_nframes_;
513*77c1e3ccSAndroid Build Coastguard Worker bool set_scale_mode_;
514*77c1e3ccSAndroid Build Coastguard Worker bool set_scale_mode2_;
515*77c1e3ccSAndroid Build Coastguard Worker bool set_scale_mode3_;
516*77c1e3ccSAndroid Build Coastguard Worker bool is_screen_;
517*77c1e3ccSAndroid Build Coastguard Worker };
518*77c1e3ccSAndroid Build Coastguard Worker
519*77c1e3ccSAndroid Build Coastguard Worker // Check the AOME_SET_SCALEMODE control by downsizing to
520*77c1e3ccSAndroid Build Coastguard Worker // 1/2, then 1/4, and then back up to originsal.
TEST_P(ResizeRealtimeTest,TestInternalResizeSetScaleMode1)521*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeSetScaleMode1) {
522*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
523*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 1280;
524*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 720;
525*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = true;
526*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
527*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
528*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
529*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
530*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
531*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
532*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
533*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
534*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
535*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
536*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
537*77c1e3ccSAndroid Build Coastguard Worker const auto frame = static_cast<unsigned>(info->pts);
538*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w = 1280 >> 1;
539*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h = 720 >> 1;
540*77c1e3ccSAndroid Build Coastguard Worker if (frame > 40) {
541*77c1e3ccSAndroid Build Coastguard Worker expected_w = 1280;
542*77c1e3ccSAndroid Build Coastguard Worker expected_h = 720;
543*77c1e3ccSAndroid Build Coastguard Worker } else if (frame > 20 && frame <= 40) {
544*77c1e3ccSAndroid Build Coastguard Worker expected_w = 1280 >> 2;
545*77c1e3ccSAndroid Build Coastguard Worker expected_h = 720 >> 2;
546*77c1e3ccSAndroid Build Coastguard Worker }
547*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info->w)
548*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
549*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info->h)
550*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
551*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
552*77c1e3ccSAndroid Build Coastguard Worker }
553*77c1e3ccSAndroid Build Coastguard Worker #else
554*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
555*77c1e3ccSAndroid Build Coastguard Worker #endif
556*77c1e3ccSAndroid Build Coastguard Worker }
557*77c1e3ccSAndroid Build Coastguard Worker
558*77c1e3ccSAndroid Build Coastguard Worker // Check the AOME_SET_SCALEMODE control by downsizing to
559*77c1e3ccSAndroid Build Coastguard Worker // 1/2, then 1/4, and then back up to originsal.
TEST_P(ResizeRealtimeTest,TestInternalResizeSetScaleMode1QVGA)560*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeSetScaleMode1QVGA) {
561*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("desktop1.320_180.yuv", 320, 180, 30, 1,
562*77c1e3ccSAndroid Build Coastguard Worker 0, 80);
563*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 320;
564*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 180;
565*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = true;
566*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
567*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
568*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
569*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
570*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
571*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
572*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
573*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
574*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
575*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
576*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
577*77c1e3ccSAndroid Build Coastguard Worker const auto frame = static_cast<unsigned>(info->pts);
578*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w = 320 >> 1;
579*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h = 180 >> 1;
580*77c1e3ccSAndroid Build Coastguard Worker if (frame > 40) {
581*77c1e3ccSAndroid Build Coastguard Worker expected_w = 320;
582*77c1e3ccSAndroid Build Coastguard Worker expected_h = 180;
583*77c1e3ccSAndroid Build Coastguard Worker } else if (frame > 20 && frame <= 40) {
584*77c1e3ccSAndroid Build Coastguard Worker expected_w = 320 >> 2;
585*77c1e3ccSAndroid Build Coastguard Worker expected_h = 180 >> 2;
586*77c1e3ccSAndroid Build Coastguard Worker }
587*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info->w)
588*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
589*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info->h)
590*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
591*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
592*77c1e3ccSAndroid Build Coastguard Worker }
593*77c1e3ccSAndroid Build Coastguard Worker #else
594*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
595*77c1e3ccSAndroid Build Coastguard Worker #endif
596*77c1e3ccSAndroid Build Coastguard Worker }
597*77c1e3ccSAndroid Build Coastguard Worker
598*77c1e3ccSAndroid Build Coastguard Worker // Check the AOME_SET_SCALEMODE control by downsizing to
599*77c1e3ccSAndroid Build Coastguard Worker // 1/4, then 1/2, and then up to 3/4.
TEST_P(ResizeRealtimeTest,TestInternalResizeSetScaleMode2)600*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeSetScaleMode2) {
601*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
602*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 1280;
603*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 720;
604*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
605*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = true;
606*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
607*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
608*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
609*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
610*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
611*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
612*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
613*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
614*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
615*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
616*77c1e3ccSAndroid Build Coastguard Worker const auto frame = static_cast<unsigned>(info->pts);
617*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w = 1280 >> 2;
618*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h = 720 >> 2;
619*77c1e3ccSAndroid Build Coastguard Worker if (frame > 40) {
620*77c1e3ccSAndroid Build Coastguard Worker expected_w = (3 * 1280) >> 2;
621*77c1e3ccSAndroid Build Coastguard Worker expected_h = (3 * 720) >> 2;
622*77c1e3ccSAndroid Build Coastguard Worker } else if (frame > 20 && frame <= 40) {
623*77c1e3ccSAndroid Build Coastguard Worker expected_w = 1280 >> 1;
624*77c1e3ccSAndroid Build Coastguard Worker expected_h = 720 >> 1;
625*77c1e3ccSAndroid Build Coastguard Worker }
626*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info->w)
627*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
628*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info->h)
629*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
630*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
631*77c1e3ccSAndroid Build Coastguard Worker }
632*77c1e3ccSAndroid Build Coastguard Worker #else
633*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
634*77c1e3ccSAndroid Build Coastguard Worker #endif
635*77c1e3ccSAndroid Build Coastguard Worker }
636*77c1e3ccSAndroid Build Coastguard Worker
637*77c1e3ccSAndroid Build Coastguard Worker // Check the AOME_SET_SCALEMODE control by downsizing to
638*77c1e3ccSAndroid Build Coastguard Worker // 1/2 horizontally only and then back up to original.
TEST_P(ResizeRealtimeTest,TestInternalResizeSetScaleMode3)639*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeSetScaleMode3) {
640*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 60);
641*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 1280;
642*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 720;
643*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
644*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
645*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = true;
646*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
647*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
648*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
649*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
650*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
651*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
652*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
653*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
654*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
655*77c1e3ccSAndroid Build Coastguard Worker const auto frame = static_cast<unsigned>(info->pts);
656*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w = 640;
657*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h = 720;
658*77c1e3ccSAndroid Build Coastguard Worker if (frame > 30) {
659*77c1e3ccSAndroid Build Coastguard Worker expected_w = 1280;
660*77c1e3ccSAndroid Build Coastguard Worker expected_h = 720;
661*77c1e3ccSAndroid Build Coastguard Worker }
662*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info->w)
663*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
664*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info->h)
665*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
666*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
667*77c1e3ccSAndroid Build Coastguard Worker }
668*77c1e3ccSAndroid Build Coastguard Worker #else
669*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
670*77c1e3ccSAndroid Build Coastguard Worker #endif
671*77c1e3ccSAndroid Build Coastguard Worker }
672*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ResizeRealtimeTest,TestExternalResizeWorks)673*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) {
674*77c1e3ccSAndroid Build Coastguard Worker ResizingVideoSource video;
675*77c1e3ccSAndroid Build Coastguard Worker video.flag_codec_ = 1;
676*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
677*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
678*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
679*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
680*77c1e3ccSAndroid Build Coastguard Worker mismatch_psnr_ = 0.0;
681*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
682*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
683*77c1e3ccSAndroid Build Coastguard Worker // Test external resizing with start resolution equal to
684*77c1e3ccSAndroid Build Coastguard Worker // 1. kInitialWidth and kInitialHeight
685*77c1e3ccSAndroid Build Coastguard Worker // 2. down-scaled kInitialWidth and kInitialHeight
686*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < 2; i++) {
687*77c1e3ccSAndroid Build Coastguard Worker video.change_start_resln_ = static_cast<bool>(i);
688*77c1e3ccSAndroid Build Coastguard Worker
689*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
690*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
691*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
692*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
693*77c1e3ccSAndroid Build Coastguard Worker for (const auto &info : frame_info_list_) {
694*77c1e3ccSAndroid Build Coastguard Worker const unsigned int frame = static_cast<unsigned>(info.pts);
695*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w;
696*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h;
697*77c1e3ccSAndroid Build Coastguard Worker ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight,
698*77c1e3ccSAndroid Build Coastguard Worker video.flag_codec_, video.change_start_resln_,
699*77c1e3ccSAndroid Build Coastguard Worker &expected_w, &expected_h);
700*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info.w)
701*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
702*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info.h)
703*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
704*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
705*77c1e3ccSAndroid Build Coastguard Worker }
706*77c1e3ccSAndroid Build Coastguard Worker #else
707*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
708*77c1e3ccSAndroid Build Coastguard Worker #endif
709*77c1e3ccSAndroid Build Coastguard Worker frame_info_list_.clear();
710*77c1e3ccSAndroid Build Coastguard Worker }
711*77c1e3ccSAndroid Build Coastguard Worker }
712*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(ResizeRealtimeTest,TestExternalResizeWorksUsePSNR)713*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestExternalResizeWorksUsePSNR) {
714*77c1e3ccSAndroid Build Coastguard Worker ResizingVideoSource video;
715*77c1e3ccSAndroid Build Coastguard Worker video.flag_codec_ = 1;
716*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
717*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
718*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
719*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
720*77c1e3ccSAndroid Build Coastguard Worker mismatch_psnr_ = 0.0;
721*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
722*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
723*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 30;
724*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
725*77c1e3ccSAndroid Build Coastguard Worker // Test external resizing with start resolution equal to
726*77c1e3ccSAndroid Build Coastguard Worker // 1. kInitialWidth and kInitialHeight
727*77c1e3ccSAndroid Build Coastguard Worker // 2. down-scaled kInitialWidth and kInitialHeight
728*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < 2; i++) {
729*77c1e3ccSAndroid Build Coastguard Worker video.change_start_resln_ = static_cast<bool>(i);
730*77c1e3ccSAndroid Build Coastguard Worker
731*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
732*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
733*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
734*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
735*77c1e3ccSAndroid Build Coastguard Worker for (const auto &info : frame_info_list_) {
736*77c1e3ccSAndroid Build Coastguard Worker const unsigned int frame = static_cast<unsigned>(info.pts);
737*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_w;
738*77c1e3ccSAndroid Build Coastguard Worker unsigned int expected_h;
739*77c1e3ccSAndroid Build Coastguard Worker ScaleForFrameNumber(frame, kInitialWidth, kInitialHeight,
740*77c1e3ccSAndroid Build Coastguard Worker video.flag_codec_, video.change_start_resln_,
741*77c1e3ccSAndroid Build Coastguard Worker &expected_w, &expected_h);
742*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_w, info.w)
743*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected width";
744*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(expected_h, info.h)
745*77c1e3ccSAndroid Build Coastguard Worker << "Frame " << frame << " had unexpected height";
746*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
747*77c1e3ccSAndroid Build Coastguard Worker }
748*77c1e3ccSAndroid Build Coastguard Worker #else
749*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
750*77c1e3ccSAndroid Build Coastguard Worker #endif
751*77c1e3ccSAndroid Build Coastguard Worker frame_info_list_.clear();
752*77c1e3ccSAndroid Build Coastguard Worker }
753*77c1e3ccSAndroid Build Coastguard Worker }
754*77c1e3ccSAndroid Build Coastguard Worker
755*77c1e3ccSAndroid Build Coastguard Worker // Verify the dynamic resizer behavior for real time, 1 pass CBR mode.
756*77c1e3ccSAndroid Build Coastguard Worker // Run at low bitrate, with resize_allowed = 1, and verify that we get
757*77c1e3ccSAndroid Build Coastguard Worker // one resize down event.
TEST_P(ResizeRealtimeTest,TestInternalResizeDown)758*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeDown) {
759*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
760*77c1e3ccSAndroid Build Coastguard Worker 0, 400);
761*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 640;
762*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 480;
763*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = false;
764*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
765*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
766*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
767*77c1e3ccSAndroid Build Coastguard Worker mismatch_psnr_ = 0.0;
768*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
769*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
770*77c1e3ccSAndroid Build Coastguard Worker // Disable dropped frames.
771*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 0;
772*77c1e3ccSAndroid Build Coastguard Worker // Starting bitrate low.
773*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 150;
774*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_resize_mode = RESIZE_DYNAMIC;
775*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_width = 1280;
776*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_height = 1280;
777*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
778*77c1e3ccSAndroid Build Coastguard Worker
779*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
780*77c1e3ccSAndroid Build Coastguard Worker unsigned int last_w = cfg_.g_w;
781*77c1e3ccSAndroid Build Coastguard Worker unsigned int last_h = cfg_.g_h;
782*77c1e3ccSAndroid Build Coastguard Worker int resize_down_count = 0;
783*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
784*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
785*77c1e3ccSAndroid Build Coastguard Worker if (info->w != last_w || info->h != last_h) {
786*77c1e3ccSAndroid Build Coastguard Worker // Verify that resize down occurs.
787*77c1e3ccSAndroid Build Coastguard Worker if (info->w < last_w && info->h < last_h) {
788*77c1e3ccSAndroid Build Coastguard Worker resize_down_count++;
789*77c1e3ccSAndroid Build Coastguard Worker }
790*77c1e3ccSAndroid Build Coastguard Worker last_w = info->w;
791*77c1e3ccSAndroid Build Coastguard Worker last_h = info->h;
792*77c1e3ccSAndroid Build Coastguard Worker }
793*77c1e3ccSAndroid Build Coastguard Worker }
794*77c1e3ccSAndroid Build Coastguard Worker
795*77c1e3ccSAndroid Build Coastguard Worker // Verify that we get at lease 1 resize down event in this test.
796*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GE(resize_down_count, 1) << "Resizing should occur.";
797*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
798*77c1e3ccSAndroid Build Coastguard Worker #else
799*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
800*77c1e3ccSAndroid Build Coastguard Worker #endif
801*77c1e3ccSAndroid Build Coastguard Worker }
802*77c1e3ccSAndroid Build Coastguard Worker
803*77c1e3ccSAndroid Build Coastguard Worker // Verify the dynamic resizer behavior for real time, 1 pass CBR mode.
804*77c1e3ccSAndroid Build Coastguard Worker // Start at low target bitrate, raise the bitrate in the middle of the clip
805*77c1e3ccSAndroid Build Coastguard Worker // (at frame# = frame_change_bitrate_), scaling-up should occur after bitrate
806*77c1e3ccSAndroid Build Coastguard Worker // is increased.
TEST_P(ResizeRealtimeTest,TestInternalResizeDownUpChangeBitRate)807*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeDownUpChangeBitRate) {
808*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("niklas_640_480_30.yuv", 640, 480, 30, 1,
809*77c1e3ccSAndroid Build Coastguard Worker 0, 400);
810*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
811*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 640;
812*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 480;
813*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = true;
814*77c1e3ccSAndroid Build Coastguard Worker frame_change_bitrate_ = 120;
815*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
816*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
817*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
818*77c1e3ccSAndroid Build Coastguard Worker mismatch_psnr_ = 0.0;
819*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
820*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
821*77c1e3ccSAndroid Build Coastguard Worker // Disable dropped frames.
822*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 0;
823*77c1e3ccSAndroid Build Coastguard Worker // Starting bitrate low.
824*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 150;
825*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_resize_mode = RESIZE_DYNAMIC;
826*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_width = 1280;
827*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_height = 1280;
828*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
829*77c1e3ccSAndroid Build Coastguard Worker
830*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
831*77c1e3ccSAndroid Build Coastguard Worker unsigned int last_w = cfg_.g_w;
832*77c1e3ccSAndroid Build Coastguard Worker unsigned int last_h = cfg_.g_h;
833*77c1e3ccSAndroid Build Coastguard Worker unsigned int frame_number = 0;
834*77c1e3ccSAndroid Build Coastguard Worker int resize_down_count = 0;
835*77c1e3ccSAndroid Build Coastguard Worker int resize_up_count = 0;
836*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
837*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
838*77c1e3ccSAndroid Build Coastguard Worker if (info->w != last_w || info->h != last_h) {
839*77c1e3ccSAndroid Build Coastguard Worker if (frame_number < frame_change_bitrate_) {
840*77c1e3ccSAndroid Build Coastguard Worker // Verify that resize down occurs, before bitrate is increased.
841*77c1e3ccSAndroid Build Coastguard Worker ASSERT_LT(info->w, last_w);
842*77c1e3ccSAndroid Build Coastguard Worker ASSERT_LT(info->h, last_h);
843*77c1e3ccSAndroid Build Coastguard Worker resize_down_count++;
844*77c1e3ccSAndroid Build Coastguard Worker } else {
845*77c1e3ccSAndroid Build Coastguard Worker // Verify that resize up occurs, after bitrate is increased.
846*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GT(info->w, last_w);
847*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GT(info->h, last_h);
848*77c1e3ccSAndroid Build Coastguard Worker resize_up_count++;
849*77c1e3ccSAndroid Build Coastguard Worker }
850*77c1e3ccSAndroid Build Coastguard Worker last_w = info->w;
851*77c1e3ccSAndroid Build Coastguard Worker last_h = info->h;
852*77c1e3ccSAndroid Build Coastguard Worker }
853*77c1e3ccSAndroid Build Coastguard Worker frame_number++;
854*77c1e3ccSAndroid Build Coastguard Worker }
855*77c1e3ccSAndroid Build Coastguard Worker
856*77c1e3ccSAndroid Build Coastguard Worker // Verify that we get at least 2 resize events in this test.
857*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GE(resize_up_count, 1) << "Resizing up should occur at lease once.";
858*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GE(resize_down_count, 1)
859*77c1e3ccSAndroid Build Coastguard Worker << "Resizing down should occur at lease once.";
860*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
861*77c1e3ccSAndroid Build Coastguard Worker #else
862*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
863*77c1e3ccSAndroid Build Coastguard Worker #endif
864*77c1e3ccSAndroid Build Coastguard Worker }
865*77c1e3ccSAndroid Build Coastguard Worker
866*77c1e3ccSAndroid Build Coastguard Worker // Verify the dynamic resizer behavior for real time, 1 pass CBR mode for
867*77c1e3ccSAndroid Build Coastguard Worker // screen content mode. Start at low target bitrate, raise the bitrate in the
868*77c1e3ccSAndroid Build Coastguard Worker // middle of the clip (at frame# = frame_change_bitrate_), scaling-up should
869*77c1e3ccSAndroid Build Coastguard Worker // occur after bitrate is increased.
TEST_P(ResizeRealtimeTest,TestInternalResizeDownUpChangeBitRateScreen)870*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeRealtimeTest, TestInternalResizeDownUpChangeBitRateScreen) {
871*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::I420VideoSource video("hantro_collage_w352h288.yuv", 352, 288,
872*77c1e3ccSAndroid Build Coastguard Worker 30, 1, 0, 300);
873*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
874*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = 352;
875*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = 288;
876*77c1e3ccSAndroid Build Coastguard Worker change_bitrate_ = true;
877*77c1e3ccSAndroid Build Coastguard Worker frame_change_bitrate_ = 120;
878*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode_ = false;
879*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode2_ = false;
880*77c1e3ccSAndroid Build Coastguard Worker set_scale_mode3_ = false;
881*77c1e3ccSAndroid Build Coastguard Worker mismatch_psnr_ = 0.0;
882*77c1e3ccSAndroid Build Coastguard Worker mismatch_nframes_ = 0;
883*77c1e3ccSAndroid Build Coastguard Worker is_screen_ = true;
884*77c1e3ccSAndroid Build Coastguard Worker DefaultConfig();
885*77c1e3ccSAndroid Build Coastguard Worker // Disable dropped frames.
886*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_dropframe_thresh = 0;
887*77c1e3ccSAndroid Build Coastguard Worker // Starting bitrate low.
888*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 100;
889*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_resize_mode = RESIZE_DYNAMIC;
890*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_width = 1280;
891*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_forced_max_frame_height = 1280;
892*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
893*77c1e3ccSAndroid Build Coastguard Worker
894*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
895*77c1e3ccSAndroid Build Coastguard Worker unsigned int last_w = cfg_.g_w;
896*77c1e3ccSAndroid Build Coastguard Worker unsigned int last_h = cfg_.g_h;
897*77c1e3ccSAndroid Build Coastguard Worker unsigned int frame_number = 0;
898*77c1e3ccSAndroid Build Coastguard Worker int resize_down_count = 0;
899*77c1e3ccSAndroid Build Coastguard Worker for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin();
900*77c1e3ccSAndroid Build Coastguard Worker info != frame_info_list_.end(); ++info) {
901*77c1e3ccSAndroid Build Coastguard Worker if (info->w != last_w || info->h != last_h) {
902*77c1e3ccSAndroid Build Coastguard Worker if (frame_number < frame_change_bitrate_) {
903*77c1e3ccSAndroid Build Coastguard Worker // Verify that resize down occurs, before bitrate is increased.
904*77c1e3ccSAndroid Build Coastguard Worker ASSERT_LT(info->w, last_w);
905*77c1e3ccSAndroid Build Coastguard Worker ASSERT_LT(info->h, last_h);
906*77c1e3ccSAndroid Build Coastguard Worker resize_down_count++;
907*77c1e3ccSAndroid Build Coastguard Worker }
908*77c1e3ccSAndroid Build Coastguard Worker last_w = info->w;
909*77c1e3ccSAndroid Build Coastguard Worker last_h = info->h;
910*77c1e3ccSAndroid Build Coastguard Worker }
911*77c1e3ccSAndroid Build Coastguard Worker frame_number++;
912*77c1e3ccSAndroid Build Coastguard Worker }
913*77c1e3ccSAndroid Build Coastguard Worker
914*77c1e3ccSAndroid Build Coastguard Worker // Verify that we get at least 1 resize event in this test.
915*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GE(resize_down_count, 1)
916*77c1e3ccSAndroid Build Coastguard Worker << "Resizing down should occur at lease once.";
917*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(static_cast<unsigned int>(0), GetMismatchFrames());
918*77c1e3ccSAndroid Build Coastguard Worker #else
919*77c1e3ccSAndroid Build Coastguard Worker printf("Warning: AV1 decoder unavailable, unable to check resize count!\n");
920*77c1e3ccSAndroid Build Coastguard Worker #endif
921*77c1e3ccSAndroid Build Coastguard Worker }
922*77c1e3ccSAndroid Build Coastguard Worker
923*77c1e3ccSAndroid Build Coastguard Worker class ResizeCspTest : public ResizeTest {
924*77c1e3ccSAndroid Build Coastguard Worker protected:
925*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
ResizeCspTest()926*77c1e3ccSAndroid Build Coastguard Worker ResizeCspTest()
927*77c1e3ccSAndroid Build Coastguard Worker : ResizeTest(), frame0_psnr_(0.0), outfile_(nullptr), out_frames_(0) {}
928*77c1e3ccSAndroid Build Coastguard Worker #else
929*77c1e3ccSAndroid Build Coastguard Worker ResizeCspTest() : ResizeTest(), frame0_psnr_(0.0) {}
930*77c1e3ccSAndroid Build Coastguard Worker #endif
931*77c1e3ccSAndroid Build Coastguard Worker
932*77c1e3ccSAndroid Build Coastguard Worker ~ResizeCspTest() override = default;
933*77c1e3ccSAndroid Build Coastguard Worker
BeginPassHook(unsigned int)934*77c1e3ccSAndroid Build Coastguard Worker void BeginPassHook(unsigned int /*pass*/) override {
935*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
936*77c1e3ccSAndroid Build Coastguard Worker outfile_ = fopen("av11-2-05-cspchape.ivf", "wb");
937*77c1e3ccSAndroid Build Coastguard Worker #endif
938*77c1e3ccSAndroid Build Coastguard Worker }
939*77c1e3ccSAndroid Build Coastguard Worker
EndPassHook()940*77c1e3ccSAndroid Build Coastguard Worker void EndPassHook() override {
941*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
942*77c1e3ccSAndroid Build Coastguard Worker if (outfile_) {
943*77c1e3ccSAndroid Build Coastguard Worker if (!fseek(outfile_, 0, SEEK_SET))
944*77c1e3ccSAndroid Build Coastguard Worker write_ivf_file_header(&cfg_, out_frames_, outfile_);
945*77c1e3ccSAndroid Build Coastguard Worker fclose(outfile_);
946*77c1e3ccSAndroid Build Coastguard Worker outfile_ = nullptr;
947*77c1e3ccSAndroid Build Coastguard Worker }
948*77c1e3ccSAndroid Build Coastguard Worker #endif
949*77c1e3ccSAndroid Build Coastguard Worker }
950*77c1e3ccSAndroid Build Coastguard Worker
PSNRPktHook(const aom_codec_cx_pkt_t * pkt)951*77c1e3ccSAndroid Build Coastguard Worker void PSNRPktHook(const aom_codec_cx_pkt_t *pkt) override {
952*77c1e3ccSAndroid Build Coastguard Worker if (frame0_psnr_ == 0.) frame0_psnr_ = pkt->data.psnr.psnr[0];
953*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0);
954*77c1e3ccSAndroid Build Coastguard Worker }
955*77c1e3ccSAndroid Build Coastguard Worker
956*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
FramePktHook(const aom_codec_cx_pkt_t * pkt)957*77c1e3ccSAndroid Build Coastguard Worker void FramePktHook(const aom_codec_cx_pkt_t *pkt) override {
958*77c1e3ccSAndroid Build Coastguard Worker ++out_frames_;
959*77c1e3ccSAndroid Build Coastguard Worker
960*77c1e3ccSAndroid Build Coastguard Worker // Write initial file header if first frame.
961*77c1e3ccSAndroid Build Coastguard Worker if (pkt->data.frame.pts == 0) write_ivf_file_header(&cfg_, 0, outfile_);
962*77c1e3ccSAndroid Build Coastguard Worker
963*77c1e3ccSAndroid Build Coastguard Worker // Write frame header and data.
964*77c1e3ccSAndroid Build Coastguard Worker write_ivf_frame_header(pkt, outfile_);
965*77c1e3ccSAndroid Build Coastguard Worker (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_);
966*77c1e3ccSAndroid Build Coastguard Worker }
967*77c1e3ccSAndroid Build Coastguard Worker #endif
968*77c1e3ccSAndroid Build Coastguard Worker
969*77c1e3ccSAndroid Build Coastguard Worker double frame0_psnr_;
970*77c1e3ccSAndroid Build Coastguard Worker #if WRITE_COMPRESSED_STREAM
971*77c1e3ccSAndroid Build Coastguard Worker FILE *outfile_;
972*77c1e3ccSAndroid Build Coastguard Worker unsigned int out_frames_;
973*77c1e3ccSAndroid Build Coastguard Worker #endif
974*77c1e3ccSAndroid Build Coastguard Worker };
975*77c1e3ccSAndroid Build Coastguard Worker
976*77c1e3ccSAndroid Build Coastguard Worker class ResizingCspVideoSource : public ::libaom_test::DummyVideoSource {
977*77c1e3ccSAndroid Build Coastguard Worker public:
ResizingCspVideoSource(aom_img_fmt_t image_format)978*77c1e3ccSAndroid Build Coastguard Worker explicit ResizingCspVideoSource(aom_img_fmt_t image_format) {
979*77c1e3ccSAndroid Build Coastguard Worker SetSize(kInitialWidth, kInitialHeight);
980*77c1e3ccSAndroid Build Coastguard Worker SetImageFormat(image_format);
981*77c1e3ccSAndroid Build Coastguard Worker limit_ = 30;
982*77c1e3ccSAndroid Build Coastguard Worker }
983*77c1e3ccSAndroid Build Coastguard Worker
984*77c1e3ccSAndroid Build Coastguard Worker ~ResizingCspVideoSource() override = default;
985*77c1e3ccSAndroid Build Coastguard Worker };
986*77c1e3ccSAndroid Build Coastguard Worker
987*77c1e3ccSAndroid Build Coastguard Worker #if (defined(DISABLE_TRELLISQ_SEARCH) && DISABLE_TRELLISQ_SEARCH) || \
988*77c1e3ccSAndroid Build Coastguard Worker (defined(CONFIG_MAX_DECODE_PROFILE) && CONFIG_MAX_DECODE_PROFILE < 1)
TEST_P(ResizeCspTest,DISABLED_TestResizeCspWorks)989*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeCspTest, DISABLED_TestResizeCspWorks) {
990*77c1e3ccSAndroid Build Coastguard Worker #else
991*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeCspTest, TestResizeCspWorks) {
992*77c1e3ccSAndroid Build Coastguard Worker #endif
993*77c1e3ccSAndroid Build Coastguard Worker const aom_img_fmt_t image_formats[] = { AOM_IMG_FMT_I420, AOM_IMG_FMT_I444 };
994*77c1e3ccSAndroid Build Coastguard Worker for (const aom_img_fmt_t &img_format : image_formats) {
995*77c1e3ccSAndroid Build Coastguard Worker ResizingCspVideoSource video(img_format);
996*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
997*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48;
998*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 0;
999*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_profile = (img_format == AOM_IMG_FMT_I420) ? 0 : 1;
1000*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1001*77c1e3ccSAndroid Build Coastguard Worker
1002*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
1003*77c1e3ccSAndroid Build Coastguard Worker // Check we decoded the same number of frames as we attempted to encode
1004*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(frame_info_list_.size(), video.limit());
1005*77c1e3ccSAndroid Build Coastguard Worker frame_info_list_.clear();
1006*77c1e3ccSAndroid Build Coastguard Worker #endif
1007*77c1e3ccSAndroid Build Coastguard Worker }
1008*77c1e3ccSAndroid Build Coastguard Worker }
1009*77c1e3ccSAndroid Build Coastguard Worker
1010*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
1011*77c1e3ccSAndroid Build Coastguard Worker // This class is used to check if there are any fatal
1012*77c1e3ccSAndroid Build Coastguard Worker // failures while encoding with resize-mode > 0
1013*77c1e3ccSAndroid Build Coastguard Worker class ResizeModeTestLarge
1014*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith5Params<libaom_test::TestMode, int,
1015*77c1e3ccSAndroid Build Coastguard Worker int, int, int>,
1016*77c1e3ccSAndroid Build Coastguard Worker public ::libaom_test::EncoderTest {
1017*77c1e3ccSAndroid Build Coastguard Worker protected:
1018*77c1e3ccSAndroid Build Coastguard Worker ResizeModeTestLarge()
1019*77c1e3ccSAndroid Build Coastguard Worker : EncoderTest(GET_PARAM(0)), encoding_mode_(GET_PARAM(1)),
1020*77c1e3ccSAndroid Build Coastguard Worker resize_mode_(GET_PARAM(2)), resize_denominator_(GET_PARAM(3)),
1021*77c1e3ccSAndroid Build Coastguard Worker resize_kf_denominator_(GET_PARAM(4)), cpu_used_(GET_PARAM(5)) {}
1022*77c1e3ccSAndroid Build Coastguard Worker ~ResizeModeTestLarge() override = default;
1023*77c1e3ccSAndroid Build Coastguard Worker
1024*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
1025*77c1e3ccSAndroid Build Coastguard Worker InitializeConfig(encoding_mode_);
1026*77c1e3ccSAndroid Build Coastguard Worker const aom_rational timebase = { 1, 30 };
1027*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = timebase;
1028*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_end_usage = AOM_VBR;
1029*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_threads = 1;
1030*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_lag_in_frames = 35;
1031*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_target_bitrate = 1000;
1032*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_resize_mode = resize_mode_;
1033*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_resize_denominator = resize_denominator_;
1034*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_resize_kf_denominator = resize_kf_denominator_;
1035*77c1e3ccSAndroid Build Coastguard Worker init_flags_ = AOM_CODEC_USE_PSNR;
1036*77c1e3ccSAndroid Build Coastguard Worker }
1037*77c1e3ccSAndroid Build Coastguard Worker
1038*77c1e3ccSAndroid Build Coastguard Worker void PreEncodeFrameHook(::libaom_test::VideoSource *video,
1039*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Encoder *encoder) override {
1040*77c1e3ccSAndroid Build Coastguard Worker if (video->frame() == 0) {
1041*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_CPUUSED, cpu_used_);
1042*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 1);
1043*77c1e3ccSAndroid Build Coastguard Worker }
1044*77c1e3ccSAndroid Build Coastguard Worker }
1045*77c1e3ccSAndroid Build Coastguard Worker
1046*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::TestMode encoding_mode_;
1047*77c1e3ccSAndroid Build Coastguard Worker int resize_mode_;
1048*77c1e3ccSAndroid Build Coastguard Worker int resize_denominator_;
1049*77c1e3ccSAndroid Build Coastguard Worker int resize_kf_denominator_;
1050*77c1e3ccSAndroid Build Coastguard Worker int cpu_used_;
1051*77c1e3ccSAndroid Build Coastguard Worker };
1052*77c1e3ccSAndroid Build Coastguard Worker
1053*77c1e3ccSAndroid Build Coastguard Worker TEST_P(ResizeModeTestLarge, ResizeModeTest) {
1054*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::Y4mVideoSource video("niklas_1280_720_30.y4m", 0, 30);
1055*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
1056*77c1e3ccSAndroid Build Coastguard Worker }
1057*77c1e3ccSAndroid Build Coastguard Worker
1058*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ResizeModeTestLarge);
1059*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ResizeModeTestLarge,
1060*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kOnePassGood,
1061*77c1e3ccSAndroid Build Coastguard Worker ::libaom_test::kTwoPassGood),
1062*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(1, 2), ::testing::Values(8, 12),
1063*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(10, 14), ::testing::Values(3, 6));
1064*77c1e3ccSAndroid Build Coastguard Worker #endif // !CONFIG_REALTIME_ONLY
1065*77c1e3ccSAndroid Build Coastguard Worker
1066*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ResizeTest,
1067*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kRealTime));
1068*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ResizeRealtimeTest,
1069*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kRealTime),
1070*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(6, 10), ::testing::Values(1, 2, 4));
1071*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(ResizeCspTest,
1072*77c1e3ccSAndroid Build Coastguard Worker ::testing::Values(::libaom_test::kRealTime));
1073*77c1e3ccSAndroid Build Coastguard Worker
1074*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces crbug.com/1393384. In realtime usage mode, encode
1075*77c1e3ccSAndroid Build Coastguard Worker // frames of sizes 202x202, 1x202, and 202x202. ASan should report no memory
1076*77c1e3ccSAndroid Build Coastguard Worker // errors.
1077*77c1e3ccSAndroid Build Coastguard Worker TEST(ResizeSimpleTest, TemporarySmallerFrameSize) {
1078*77c1e3ccSAndroid Build Coastguard Worker constexpr int kWidth = 202;
1079*77c1e3ccSAndroid Build Coastguard Worker constexpr int kHeight = 202;
1080*77c1e3ccSAndroid Build Coastguard Worker // Dummy buffer of zero samples.
1081*77c1e3ccSAndroid Build Coastguard Worker constexpr size_t kBufferSize =
1082*77c1e3ccSAndroid Build Coastguard Worker kWidth * kHeight + 2 * (kWidth + 1) / 2 * (kHeight + 1) / 2;
1083*77c1e3ccSAndroid Build Coastguard Worker std::vector<unsigned char> buffer(kBufferSize);
1084*77c1e3ccSAndroid Build Coastguard Worker
1085*77c1e3ccSAndroid Build Coastguard Worker aom_image_t img;
1086*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, kWidth, kHeight, 1,
1087*77c1e3ccSAndroid Build Coastguard Worker buffer.data()));
1088*77c1e3ccSAndroid Build Coastguard Worker aom_image_t img2;
1089*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(&img2, aom_img_wrap(&img2, AOM_IMG_FMT_I420, 1, kHeight, 1,
1090*77c1e3ccSAndroid Build Coastguard Worker buffer.data()));
1091*77c1e3ccSAndroid Build Coastguard Worker
1092*77c1e3ccSAndroid Build Coastguard Worker aom_codec_iface_t *iface = aom_codec_av1_cx();
1093*77c1e3ccSAndroid Build Coastguard Worker aom_codec_enc_cfg_t cfg;
1094*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1095*77c1e3ccSAndroid Build Coastguard Worker aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_REALTIME));
1096*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = kWidth;
1097*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kHeight;
1098*77c1e3ccSAndroid Build Coastguard Worker aom_codec_ctx_t enc;
1099*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0));
1100*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 5));
1101*77c1e3ccSAndroid Build Coastguard Worker
1102*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1103*77c1e3ccSAndroid Build Coastguard Worker
1104*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = 1;
1105*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kHeight;
1106*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_set(&enc, &cfg));
1107*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img2, 1, 1, 0));
1108*77c1e3ccSAndroid Build Coastguard Worker
1109*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = kWidth;
1110*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kHeight;
1111*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_set(&enc, &cfg));
1112*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 2, 1, 0));
1113*77c1e3ccSAndroid Build Coastguard Worker
1114*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 0, 0));
1115*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1116*77c1e3ccSAndroid Build Coastguard Worker }
1117*77c1e3ccSAndroid Build Coastguard Worker
1118*77c1e3ccSAndroid Build Coastguard Worker // A test that reproduces crbug.com/1410766. In realtime usage mode
1119*77c1e3ccSAndroid Build Coastguard Worker // for SVC with temporal layers, encode frames of sizes 600x600,
1120*77c1e3ccSAndroid Build Coastguard Worker // 600x600, and 100x480. ASan should report no memory errors.
1121*77c1e3ccSAndroid Build Coastguard Worker TEST(ResizeSimpleTest, SmallerFrameSizeSVC) {
1122*77c1e3ccSAndroid Build Coastguard Worker constexpr int kWidth = 600;
1123*77c1e3ccSAndroid Build Coastguard Worker constexpr int kHeight = 600;
1124*77c1e3ccSAndroid Build Coastguard Worker // Dummy buffer of zero samples.
1125*77c1e3ccSAndroid Build Coastguard Worker constexpr size_t kBufferSize =
1126*77c1e3ccSAndroid Build Coastguard Worker kWidth * kHeight + 2 * (kWidth + 1) / 2 * (kHeight + 1) / 2;
1127*77c1e3ccSAndroid Build Coastguard Worker std::vector<unsigned char> buffer(kBufferSize);
1128*77c1e3ccSAndroid Build Coastguard Worker
1129*77c1e3ccSAndroid Build Coastguard Worker aom_image_t img;
1130*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(&img, aom_img_wrap(&img, AOM_IMG_FMT_I420, kWidth, kHeight, 1,
1131*77c1e3ccSAndroid Build Coastguard Worker buffer.data()));
1132*77c1e3ccSAndroid Build Coastguard Worker aom_image_t img2;
1133*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(&img2,
1134*77c1e3ccSAndroid Build Coastguard Worker aom_img_wrap(&img2, AOM_IMG_FMT_I420, 100, 480, 1, buffer.data()));
1135*77c1e3ccSAndroid Build Coastguard Worker
1136*77c1e3ccSAndroid Build Coastguard Worker aom_codec_iface_t *iface = aom_codec_av1_cx();
1137*77c1e3ccSAndroid Build Coastguard Worker aom_codec_enc_cfg_t cfg;
1138*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1139*77c1e3ccSAndroid Build Coastguard Worker aom_codec_enc_config_default(iface, &cfg, AOM_USAGE_REALTIME));
1140*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = kWidth;
1141*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kHeight;
1142*77c1e3ccSAndroid Build Coastguard Worker aom_codec_ctx_t enc;
1143*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0));
1144*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_control(&enc, AOME_SET_CPUUSED, 5));
1145*77c1e3ccSAndroid Build Coastguard Worker
1146*77c1e3ccSAndroid Build Coastguard Worker aom_svc_params_t svc_params = {};
1147*77c1e3ccSAndroid Build Coastguard Worker aom_svc_layer_id_t layer_id;
1148*77c1e3ccSAndroid Build Coastguard Worker svc_params.number_spatial_layers = 1;
1149*77c1e3ccSAndroid Build Coastguard Worker svc_params.framerate_factor[0] = 2;
1150*77c1e3ccSAndroid Build Coastguard Worker svc_params.framerate_factor[1] = 1;
1151*77c1e3ccSAndroid Build Coastguard Worker svc_params.number_temporal_layers = 2;
1152*77c1e3ccSAndroid Build Coastguard Worker // Bitrate allocation L0: 60% L1: 40%
1153*77c1e3ccSAndroid Build Coastguard Worker svc_params.layer_target_bitrate[0] = 60 * cfg.rc_target_bitrate / 100;
1154*77c1e3ccSAndroid Build Coastguard Worker svc_params.layer_target_bitrate[1] = cfg.rc_target_bitrate;
1155*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1156*77c1e3ccSAndroid Build Coastguard Worker aom_codec_control(&enc, AV1E_SET_SVC_PARAMS, &svc_params));
1157*77c1e3ccSAndroid Build Coastguard Worker
1158*77c1e3ccSAndroid Build Coastguard Worker layer_id.spatial_layer_id = 0;
1159*77c1e3ccSAndroid Build Coastguard Worker layer_id.temporal_layer_id = 0;
1160*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1161*77c1e3ccSAndroid Build Coastguard Worker aom_codec_control(&enc, AV1E_SET_SVC_LAYER_ID, &layer_id));
1162*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 0, 1, 0));
1163*77c1e3ccSAndroid Build Coastguard Worker
1164*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = kWidth;
1165*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kHeight;
1166*77c1e3ccSAndroid Build Coastguard Worker layer_id.temporal_layer_id = 1;
1167*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1168*77c1e3ccSAndroid Build Coastguard Worker aom_codec_control(&enc, AV1E_SET_SVC_LAYER_ID, &layer_id));
1169*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_set(&enc, &cfg));
1170*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img, 1, 1, 0));
1171*77c1e3ccSAndroid Build Coastguard Worker
1172*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = 100;
1173*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = 480;
1174*77c1e3ccSAndroid Build Coastguard Worker layer_id.temporal_layer_id = 0;
1175*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1176*77c1e3ccSAndroid Build Coastguard Worker aom_codec_control(&enc, AV1E_SET_SVC_LAYER_ID, &layer_id));
1177*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_set(&enc, &cfg));
1178*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img2, 2, 1, 0));
1179*77c1e3ccSAndroid Build Coastguard Worker
1180*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 0, 0));
1181*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1182*77c1e3ccSAndroid Build Coastguard Worker }
1183*77c1e3ccSAndroid Build Coastguard Worker
1184*77c1e3ccSAndroid Build Coastguard Worker const int kUsages[] =
1185*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_REALTIME_ONLY
1186*77c1e3ccSAndroid Build Coastguard Worker { AOM_USAGE_REALTIME };
1187*77c1e3ccSAndroid Build Coastguard Worker #else
1188*77c1e3ccSAndroid Build Coastguard Worker { AOM_USAGE_GOOD_QUALITY, AOM_USAGE_REALTIME, AOM_USAGE_ALL_INTRA };
1189*77c1e3ccSAndroid Build Coastguard Worker #endif
1190*77c1e3ccSAndroid Build Coastguard Worker
1191*77c1e3ccSAndroid Build Coastguard Worker const int kNumThreads[] = { 2, 4, 8 };
1192*77c1e3ccSAndroid Build Coastguard Worker
1193*77c1e3ccSAndroid Build Coastguard Worker class FrameSizeChangeTest
1194*77c1e3ccSAndroid Build Coastguard Worker : public ::libaom_test::CodecTestWith3Params<int, int, int> {
1195*77c1e3ccSAndroid Build Coastguard Worker protected:
1196*77c1e3ccSAndroid Build Coastguard Worker FrameSizeChangeTest() {}
1197*77c1e3ccSAndroid Build Coastguard Worker ~FrameSizeChangeTest() override = default;
1198*77c1e3ccSAndroid Build Coastguard Worker
1199*77c1e3ccSAndroid Build Coastguard Worker void DoTest(int change_thread) {
1200*77c1e3ccSAndroid Build Coastguard Worker usage_ = GET_PARAM(1);
1201*77c1e3ccSAndroid Build Coastguard Worker cpu_used_ = GET_PARAM(2);
1202*77c1e3ccSAndroid Build Coastguard Worker threads_ = GET_PARAM(3);
1203*77c1e3ccSAndroid Build Coastguard Worker constexpr int kWidth = 512;
1204*77c1e3ccSAndroid Build Coastguard Worker constexpr int kHeight = 512;
1205*77c1e3ccSAndroid Build Coastguard Worker constexpr int kFirstWidth = 256;
1206*77c1e3ccSAndroid Build Coastguard Worker constexpr int kFirstHeight = 256;
1207*77c1e3ccSAndroid Build Coastguard Worker // Buffer of zero samples.
1208*77c1e3ccSAndroid Build Coastguard Worker constexpr size_t kBufferSize = 3 * kWidth * kHeight;
1209*77c1e3ccSAndroid Build Coastguard Worker std::vector<unsigned char> buffer(kBufferSize,
1210*77c1e3ccSAndroid Build Coastguard Worker static_cast<unsigned char>(0));
1211*77c1e3ccSAndroid Build Coastguard Worker
1212*77c1e3ccSAndroid Build Coastguard Worker aom_image_t img1;
1213*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(&img1, aom_img_wrap(&img1, AOM_IMG_FMT_I420, kFirstWidth,
1214*77c1e3ccSAndroid Build Coastguard Worker kFirstHeight, 1, buffer.data()));
1215*77c1e3ccSAndroid Build Coastguard Worker
1216*77c1e3ccSAndroid Build Coastguard Worker aom_image_t img2;
1217*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(&img2, aom_img_wrap(&img2, AOM_IMG_FMT_I420, kWidth, kHeight, 1,
1218*77c1e3ccSAndroid Build Coastguard Worker buffer.data()));
1219*77c1e3ccSAndroid Build Coastguard Worker
1220*77c1e3ccSAndroid Build Coastguard Worker aom_codec_iface_t *iface = aom_codec_av1_cx();
1221*77c1e3ccSAndroid Build Coastguard Worker aom_codec_enc_cfg_t cfg;
1222*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_default(iface, &cfg, usage_));
1223*77c1e3ccSAndroid Build Coastguard Worker cfg.g_threads = threads_;
1224*77c1e3ccSAndroid Build Coastguard Worker cfg.g_lag_in_frames = usage_ == AOM_USAGE_ALL_INTRA ? 0 : 1;
1225*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = kFirstWidth;
1226*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kFirstHeight;
1227*77c1e3ccSAndroid Build Coastguard Worker cfg.g_forced_max_frame_width = kWidth;
1228*77c1e3ccSAndroid Build Coastguard Worker cfg.g_forced_max_frame_height = kHeight;
1229*77c1e3ccSAndroid Build Coastguard Worker aom_codec_ctx_t enc;
1230*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_init(&enc, iface, &cfg, 0));
1231*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK,
1232*77c1e3ccSAndroid Build Coastguard Worker aom_codec_control(&enc, AOME_SET_CPUUSED, cpu_used_));
1233*77c1e3ccSAndroid Build Coastguard Worker
1234*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img1, 0, 1, 0));
1235*77c1e3ccSAndroid Build Coastguard Worker
1236*77c1e3ccSAndroid Build Coastguard Worker if (change_thread == 1) {
1237*77c1e3ccSAndroid Build Coastguard Worker cfg.g_threads = AOMMAX(1, threads_ / 2);
1238*77c1e3ccSAndroid Build Coastguard Worker } else if (change_thread == 2) {
1239*77c1e3ccSAndroid Build Coastguard Worker cfg.g_threads = threads_ * 2;
1240*77c1e3ccSAndroid Build Coastguard Worker }
1241*77c1e3ccSAndroid Build Coastguard Worker cfg.g_w = kWidth;
1242*77c1e3ccSAndroid Build Coastguard Worker cfg.g_h = kHeight;
1243*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_enc_config_set(&enc, &cfg));
1244*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, &img2, 1, 1, 0));
1245*77c1e3ccSAndroid Build Coastguard Worker
1246*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_encode(&enc, nullptr, 0, 0, 0));
1247*77c1e3ccSAndroid Build Coastguard Worker EXPECT_EQ(AOM_CODEC_OK, aom_codec_destroy(&enc));
1248*77c1e3ccSAndroid Build Coastguard Worker }
1249*77c1e3ccSAndroid Build Coastguard Worker
1250*77c1e3ccSAndroid Build Coastguard Worker int cpu_used_;
1251*77c1e3ccSAndroid Build Coastguard Worker int threads_;
1252*77c1e3ccSAndroid Build Coastguard Worker int usage_;
1253*77c1e3ccSAndroid Build Coastguard Worker };
1254*77c1e3ccSAndroid Build Coastguard Worker
1255*77c1e3ccSAndroid Build Coastguard Worker TEST_P(FrameSizeChangeTest, FixedThreads) { DoTest(0); }
1256*77c1e3ccSAndroid Build Coastguard Worker TEST_P(FrameSizeChangeTest, DecreasingThreads) { DoTest(1); }
1257*77c1e3ccSAndroid Build Coastguard Worker TEST_P(FrameSizeChangeTest, IncreasingThreads) { DoTest(2); }
1258*77c1e3ccSAndroid Build Coastguard Worker
1259*77c1e3ccSAndroid Build Coastguard Worker AV1_INSTANTIATE_TEST_SUITE(FrameSizeChangeTest, ::testing::ValuesIn(kUsages),
1260*77c1e3ccSAndroid Build Coastguard Worker ::testing::Range(6, 7),
1261*77c1e3ccSAndroid Build Coastguard Worker ::testing::ValuesIn(kNumThreads));
1262*77c1e3ccSAndroid Build Coastguard Worker
1263*77c1e3ccSAndroid Build Coastguard Worker } // namespace
1264