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 <memory>
13*77c1e3ccSAndroid Build Coastguard Worker #include <string>
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
18*77c1e3ccSAndroid Build Coastguard Worker
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/mem.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/codec_factory.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/decode_test_driver.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "test/encode_test_driver.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "test/register_state_check.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "test/video_source.h"
25*77c1e3ccSAndroid Build Coastguard Worker
26*77c1e3ccSAndroid Build Coastguard Worker namespace libaom_test {
InitEncoder(VideoSource * video)27*77c1e3ccSAndroid Build Coastguard Worker void Encoder::InitEncoder(VideoSource *video) {
28*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t res;
29*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img = video->img();
30*77c1e3ccSAndroid Build Coastguard Worker
31*77c1e3ccSAndroid Build Coastguard Worker if (video->img() && !encoder_.priv) {
32*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = img->d_w;
33*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = img->d_h;
34*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_timebase = video->timebase();
35*77c1e3ccSAndroid Build Coastguard Worker cfg_.rc_twopass_stats_in = stats_->buf();
36*77c1e3ccSAndroid Build Coastguard Worker
37*77c1e3ccSAndroid Build Coastguard Worker res = aom_codec_enc_init(&encoder_, CodecInterface(), &cfg_, init_flags_);
38*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
39*77c1e3ccSAndroid Build Coastguard Worker }
40*77c1e3ccSAndroid Build Coastguard Worker }
41*77c1e3ccSAndroid Build Coastguard Worker
EncodeFrame(VideoSource * video,const aom_enc_frame_flags_t frame_flags)42*77c1e3ccSAndroid Build Coastguard Worker void Encoder::EncodeFrame(VideoSource *video,
43*77c1e3ccSAndroid Build Coastguard Worker const aom_enc_frame_flags_t frame_flags) {
44*77c1e3ccSAndroid Build Coastguard Worker if (video->img())
45*77c1e3ccSAndroid Build Coastguard Worker EncodeFrameInternal(*video, frame_flags);
46*77c1e3ccSAndroid Build Coastguard Worker else
47*77c1e3ccSAndroid Build Coastguard Worker Flush();
48*77c1e3ccSAndroid Build Coastguard Worker
49*77c1e3ccSAndroid Build Coastguard Worker // Handle twopass stats
50*77c1e3ccSAndroid Build Coastguard Worker CxDataIterator iter = GetCxData();
51*77c1e3ccSAndroid Build Coastguard Worker
52*77c1e3ccSAndroid Build Coastguard Worker while (const aom_codec_cx_pkt_t *pkt = iter.Next()) {
53*77c1e3ccSAndroid Build Coastguard Worker if (pkt->kind != AOM_CODEC_STATS_PKT) continue;
54*77c1e3ccSAndroid Build Coastguard Worker
55*77c1e3ccSAndroid Build Coastguard Worker stats_->Append(*pkt);
56*77c1e3ccSAndroid Build Coastguard Worker }
57*77c1e3ccSAndroid Build Coastguard Worker }
58*77c1e3ccSAndroid Build Coastguard Worker
EncodeFrameInternal(const VideoSource & video,const aom_enc_frame_flags_t frame_flags)59*77c1e3ccSAndroid Build Coastguard Worker void Encoder::EncodeFrameInternal(const VideoSource &video,
60*77c1e3ccSAndroid Build Coastguard Worker const aom_enc_frame_flags_t frame_flags) {
61*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t res;
62*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img = video.img();
63*77c1e3ccSAndroid Build Coastguard Worker
64*77c1e3ccSAndroid Build Coastguard Worker // Handle frame resizing
65*77c1e3ccSAndroid Build Coastguard Worker if (cfg_.g_w != img->d_w || cfg_.g_h != img->d_h) {
66*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_w = img->d_w;
67*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_h = img->d_h;
68*77c1e3ccSAndroid Build Coastguard Worker res = aom_codec_enc_config_set(&encoder_, &cfg_);
69*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
70*77c1e3ccSAndroid Build Coastguard Worker }
71*77c1e3ccSAndroid Build Coastguard Worker
72*77c1e3ccSAndroid Build Coastguard Worker // Encode the frame
73*77c1e3ccSAndroid Build Coastguard Worker API_REGISTER_STATE_CHECK(res =
74*77c1e3ccSAndroid Build Coastguard Worker aom_codec_encode(&encoder_, img, video.pts(),
75*77c1e3ccSAndroid Build Coastguard Worker video.duration(), frame_flags));
76*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
77*77c1e3ccSAndroid Build Coastguard Worker }
78*77c1e3ccSAndroid Build Coastguard Worker
Flush()79*77c1e3ccSAndroid Build Coastguard Worker void Encoder::Flush() {
80*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_err_t res = aom_codec_encode(&encoder_, nullptr, 0, 0, 0);
81*77c1e3ccSAndroid Build Coastguard Worker if (!encoder_.priv)
82*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_ERROR, res) << EncoderError();
83*77c1e3ccSAndroid Build Coastguard Worker else
84*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
85*77c1e3ccSAndroid Build Coastguard Worker }
86*77c1e3ccSAndroid Build Coastguard Worker
InitializeConfig(TestMode mode)87*77c1e3ccSAndroid Build Coastguard Worker void EncoderTest::InitializeConfig(TestMode mode) {
88*77c1e3ccSAndroid Build Coastguard Worker int usage = AOM_USAGE_GOOD_QUALITY;
89*77c1e3ccSAndroid Build Coastguard Worker switch (mode) {
90*77c1e3ccSAndroid Build Coastguard Worker case kOnePassGood:
91*77c1e3ccSAndroid Build Coastguard Worker case kTwoPassGood: break;
92*77c1e3ccSAndroid Build Coastguard Worker case kRealTime: usage = AOM_USAGE_REALTIME; break;
93*77c1e3ccSAndroid Build Coastguard Worker case kAllIntra: usage = AOM_USAGE_ALL_INTRA; break;
94*77c1e3ccSAndroid Build Coastguard Worker default: ASSERT_TRUE(false) << "Unexpected mode " << mode;
95*77c1e3ccSAndroid Build Coastguard Worker }
96*77c1e3ccSAndroid Build Coastguard Worker mode_ = mode;
97*77c1e3ccSAndroid Build Coastguard Worker passes_ = (mode == kTwoPassGood) ? 2 : 1;
98*77c1e3ccSAndroid Build Coastguard Worker
99*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_err_t res = codec_->DefaultEncoderConfig(&cfg_, usage);
100*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(AOM_CODEC_OK, res);
101*77c1e3ccSAndroid Build Coastguard Worker }
102*77c1e3ccSAndroid Build Coastguard Worker
compare_plane(const uint8_t * const buf1,int stride1,const uint8_t * const buf2,int stride2,int w,int h,int * const mismatch_row,int * const mismatch_col,int * const mismatch_pix1,int * const mismatch_pix2)103*77c1e3ccSAndroid Build Coastguard Worker static bool compare_plane(const uint8_t *const buf1, int stride1,
104*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *const buf2, int stride2, int w, int h,
105*77c1e3ccSAndroid Build Coastguard Worker int *const mismatch_row, int *const mismatch_col,
106*77c1e3ccSAndroid Build Coastguard Worker int *const mismatch_pix1, int *const mismatch_pix2) {
107*77c1e3ccSAndroid Build Coastguard Worker int r, c;
108*77c1e3ccSAndroid Build Coastguard Worker
109*77c1e3ccSAndroid Build Coastguard Worker for (r = 0; r < h; ++r) {
110*77c1e3ccSAndroid Build Coastguard Worker for (c = 0; c < w; ++c) {
111*77c1e3ccSAndroid Build Coastguard Worker const int pix1 = buf1[r * stride1 + c];
112*77c1e3ccSAndroid Build Coastguard Worker const int pix2 = buf2[r * stride2 + c];
113*77c1e3ccSAndroid Build Coastguard Worker
114*77c1e3ccSAndroid Build Coastguard Worker if (pix1 != pix2) {
115*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_row != nullptr) *mismatch_row = r;
116*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_col != nullptr) *mismatch_col = c;
117*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_pix1 != nullptr) *mismatch_pix1 = pix1;
118*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_pix2 != nullptr) *mismatch_pix2 = pix2;
119*77c1e3ccSAndroid Build Coastguard Worker return false;
120*77c1e3ccSAndroid Build Coastguard Worker }
121*77c1e3ccSAndroid Build Coastguard Worker }
122*77c1e3ccSAndroid Build Coastguard Worker }
123*77c1e3ccSAndroid Build Coastguard Worker
124*77c1e3ccSAndroid Build Coastguard Worker return true;
125*77c1e3ccSAndroid Build Coastguard Worker }
126*77c1e3ccSAndroid Build Coastguard Worker
127*77c1e3ccSAndroid Build Coastguard Worker // The function should return "true" most of the time, therefore no early
128*77c1e3ccSAndroid Build Coastguard Worker // break-out is implemented within the match checking process.
compare_img(const aom_image_t * img1,const aom_image_t * img2,int * const mismatch_row,int * const mismatch_col,int * const mismatch_plane,int * const mismatch_pix1,int * const mismatch_pix2)129*77c1e3ccSAndroid Build Coastguard Worker static bool compare_img(const aom_image_t *img1, const aom_image_t *img2,
130*77c1e3ccSAndroid Build Coastguard Worker int *const mismatch_row, int *const mismatch_col,
131*77c1e3ccSAndroid Build Coastguard Worker int *const mismatch_plane, int *const mismatch_pix1,
132*77c1e3ccSAndroid Build Coastguard Worker int *const mismatch_pix2) {
133*77c1e3ccSAndroid Build Coastguard Worker if (img1->fmt != img2->fmt || img1->cp != img2->cp || img1->tc != img2->tc ||
134*77c1e3ccSAndroid Build Coastguard Worker img1->mc != img2->mc || img1->d_w != img2->d_w ||
135*77c1e3ccSAndroid Build Coastguard Worker img1->d_h != img2->d_h || img1->monochrome != img2->monochrome) {
136*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_row != nullptr) *mismatch_row = -1;
137*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_col != nullptr) *mismatch_col = -1;
138*77c1e3ccSAndroid Build Coastguard Worker return false;
139*77c1e3ccSAndroid Build Coastguard Worker }
140*77c1e3ccSAndroid Build Coastguard Worker
141*77c1e3ccSAndroid Build Coastguard Worker const int num_planes = img1->monochrome ? 1 : 3;
142*77c1e3ccSAndroid Build Coastguard Worker for (int plane = 0; plane < num_planes; plane++) {
143*77c1e3ccSAndroid Build Coastguard Worker if (!compare_plane(img1->planes[plane], img1->stride[plane],
144*77c1e3ccSAndroid Build Coastguard Worker img2->planes[plane], img2->stride[plane],
145*77c1e3ccSAndroid Build Coastguard Worker aom_img_plane_width(img1, plane),
146*77c1e3ccSAndroid Build Coastguard Worker aom_img_plane_height(img1, plane), mismatch_row,
147*77c1e3ccSAndroid Build Coastguard Worker mismatch_col, mismatch_pix1, mismatch_pix2)) {
148*77c1e3ccSAndroid Build Coastguard Worker if (mismatch_plane != nullptr) *mismatch_plane = plane;
149*77c1e3ccSAndroid Build Coastguard Worker return false;
150*77c1e3ccSAndroid Build Coastguard Worker }
151*77c1e3ccSAndroid Build Coastguard Worker }
152*77c1e3ccSAndroid Build Coastguard Worker
153*77c1e3ccSAndroid Build Coastguard Worker return true;
154*77c1e3ccSAndroid Build Coastguard Worker }
155*77c1e3ccSAndroid Build Coastguard Worker
MismatchHook(const aom_image_t * img_enc,const aom_image_t * img_dec)156*77c1e3ccSAndroid Build Coastguard Worker void EncoderTest::MismatchHook(const aom_image_t *img_enc,
157*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img_dec) {
158*77c1e3ccSAndroid Build Coastguard Worker int mismatch_row = 0;
159*77c1e3ccSAndroid Build Coastguard Worker int mismatch_col = 0;
160*77c1e3ccSAndroid Build Coastguard Worker int mismatch_plane = 0;
161*77c1e3ccSAndroid Build Coastguard Worker int mismatch_pix_enc = 0;
162*77c1e3ccSAndroid Build Coastguard Worker int mismatch_pix_dec = 0;
163*77c1e3ccSAndroid Build Coastguard Worker
164*77c1e3ccSAndroid Build Coastguard Worker ASSERT_FALSE(compare_img(img_enc, img_dec, &mismatch_row, &mismatch_col,
165*77c1e3ccSAndroid Build Coastguard Worker &mismatch_plane, &mismatch_pix_enc,
166*77c1e3ccSAndroid Build Coastguard Worker &mismatch_pix_dec));
167*77c1e3ccSAndroid Build Coastguard Worker
168*77c1e3ccSAndroid Build Coastguard Worker GTEST_FAIL() << "Encode/Decode mismatch found:" << std::endl
169*77c1e3ccSAndroid Build Coastguard Worker << " pixel value enc/dec: " << mismatch_pix_enc << "/"
170*77c1e3ccSAndroid Build Coastguard Worker << mismatch_pix_dec << std::endl
171*77c1e3ccSAndroid Build Coastguard Worker << " plane: " << mismatch_plane << std::endl
172*77c1e3ccSAndroid Build Coastguard Worker << " row/col: " << mismatch_row << "/"
173*77c1e3ccSAndroid Build Coastguard Worker << mismatch_col << std::endl;
174*77c1e3ccSAndroid Build Coastguard Worker }
175*77c1e3ccSAndroid Build Coastguard Worker
RunLoop(VideoSource * video)176*77c1e3ccSAndroid Build Coastguard Worker void EncoderTest::RunLoop(VideoSource *video) {
177*77c1e3ccSAndroid Build Coastguard Worker stats_.Reset();
178*77c1e3ccSAndroid Build Coastguard Worker
179*77c1e3ccSAndroid Build Coastguard Worker ASSERT_TRUE(passes_ == 1 || passes_ == 2);
180*77c1e3ccSAndroid Build Coastguard Worker for (unsigned int pass = 0; pass < passes_; pass++) {
181*77c1e3ccSAndroid Build Coastguard Worker aom_codec_pts_t last_pts = 0;
182*77c1e3ccSAndroid Build Coastguard Worker
183*77c1e3ccSAndroid Build Coastguard Worker if (passes_ == 1)
184*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_pass = AOM_RC_ONE_PASS;
185*77c1e3ccSAndroid Build Coastguard Worker else if (pass == 0)
186*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_pass = AOM_RC_FIRST_PASS;
187*77c1e3ccSAndroid Build Coastguard Worker else
188*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_pass = AOM_RC_LAST_PASS;
189*77c1e3ccSAndroid Build Coastguard Worker
190*77c1e3ccSAndroid Build Coastguard Worker BeginPassHook(pass);
191*77c1e3ccSAndroid Build Coastguard Worker std::unique_ptr<Encoder> encoder(
192*77c1e3ccSAndroid Build Coastguard Worker codec_->CreateEncoder(cfg_, init_flags_, &stats_));
193*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(encoder, nullptr);
194*77c1e3ccSAndroid Build Coastguard Worker
195*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NO_FATAL_FAILURE(video->Begin());
196*77c1e3ccSAndroid Build Coastguard Worker encoder->InitEncoder(video);
197*77c1e3ccSAndroid Build Coastguard Worker
198*77c1e3ccSAndroid Build Coastguard Worker if (mode_ == kRealTime) {
199*77c1e3ccSAndroid Build Coastguard Worker encoder->Control(AOME_SET_ENABLEAUTOALTREF, 0);
200*77c1e3ccSAndroid Build Coastguard Worker }
201*77c1e3ccSAndroid Build Coastguard Worker
202*77c1e3ccSAndroid Build Coastguard Worker ASSERT_FALSE(::testing::Test::HasFatalFailure());
203*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
204*77c1e3ccSAndroid Build Coastguard Worker aom_codec_dec_cfg_t dec_cfg = aom_codec_dec_cfg_t();
205*77c1e3ccSAndroid Build Coastguard Worker dec_cfg.allow_lowbitdepth = 1;
206*77c1e3ccSAndroid Build Coastguard Worker std::unique_ptr<Decoder> decoder(
207*77c1e3ccSAndroid Build Coastguard Worker codec_->CreateDecoder(dec_cfg, 0 /* flags */));
208*77c1e3ccSAndroid Build Coastguard Worker if (decoder->IsAV1()) {
209*77c1e3ccSAndroid Build Coastguard Worker // Set dec_cfg.tile_row = -1 and dec_cfg.tile_col = -1 so that the whole
210*77c1e3ccSAndroid Build Coastguard Worker // frame is decoded.
211*77c1e3ccSAndroid Build Coastguard Worker decoder->Control(AV1_SET_TILE_MODE, cfg_.large_scale_tile);
212*77c1e3ccSAndroid Build Coastguard Worker decoder->Control(AV1D_EXT_TILE_DEBUG, 1);
213*77c1e3ccSAndroid Build Coastguard Worker decoder->Control(AV1_SET_DECODE_TILE_ROW, -1);
214*77c1e3ccSAndroid Build Coastguard Worker decoder->Control(AV1_SET_DECODE_TILE_COL, -1);
215*77c1e3ccSAndroid Build Coastguard Worker }
216*77c1e3ccSAndroid Build Coastguard Worker #endif
217*77c1e3ccSAndroid Build Coastguard Worker
218*77c1e3ccSAndroid Build Coastguard Worker int number_spatial_layers = GetNumSpatialLayers();
219*77c1e3ccSAndroid Build Coastguard Worker
220*77c1e3ccSAndroid Build Coastguard Worker bool again;
221*77c1e3ccSAndroid Build Coastguard Worker for (again = true; again; video->Next()) {
222*77c1e3ccSAndroid Build Coastguard Worker again = (video->img() != nullptr);
223*77c1e3ccSAndroid Build Coastguard Worker
224*77c1e3ccSAndroid Build Coastguard Worker for (int sl = 0; sl < number_spatial_layers; sl++) {
225*77c1e3ccSAndroid Build Coastguard Worker PreEncodeFrameHook(video, encoder.get());
226*77c1e3ccSAndroid Build Coastguard Worker encoder->EncodeFrame(video, frame_flags_);
227*77c1e3ccSAndroid Build Coastguard Worker PostEncodeFrameHook(encoder.get());
228*77c1e3ccSAndroid Build Coastguard Worker CxDataIterator iter = encoder->GetCxData();
229*77c1e3ccSAndroid Build Coastguard Worker bool has_cxdata = false;
230*77c1e3ccSAndroid Build Coastguard Worker
231*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
232*77c1e3ccSAndroid Build Coastguard Worker bool has_dxdata = false;
233*77c1e3ccSAndroid Build Coastguard Worker #endif
234*77c1e3ccSAndroid Build Coastguard Worker while (const aom_codec_cx_pkt_t *pkt = iter.Next()) {
235*77c1e3ccSAndroid Build Coastguard Worker pkt = MutateEncoderOutputHook(pkt);
236*77c1e3ccSAndroid Build Coastguard Worker again = true;
237*77c1e3ccSAndroid Build Coastguard Worker switch (pkt->kind) {
238*77c1e3ccSAndroid Build Coastguard Worker case AOM_CODEC_CX_FRAME_PKT: //
239*77c1e3ccSAndroid Build Coastguard Worker has_cxdata = true;
240*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
241*77c1e3ccSAndroid Build Coastguard Worker if (decoder.get() != nullptr && DoDecode()) {
242*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t res_dec;
243*77c1e3ccSAndroid Build Coastguard Worker if (DoDecodeInvisible()) {
244*77c1e3ccSAndroid Build Coastguard Worker res_dec = decoder->DecodeFrame(
245*77c1e3ccSAndroid Build Coastguard Worker (const uint8_t *)pkt->data.frame.buf, pkt->data.frame.sz);
246*77c1e3ccSAndroid Build Coastguard Worker } else {
247*77c1e3ccSAndroid Build Coastguard Worker res_dec = decoder->DecodeFrame(
248*77c1e3ccSAndroid Build Coastguard Worker (const uint8_t *)pkt->data.frame.buf +
249*77c1e3ccSAndroid Build Coastguard Worker (pkt->data.frame.sz - pkt->data.frame.vis_frame_size),
250*77c1e3ccSAndroid Build Coastguard Worker pkt->data.frame.vis_frame_size);
251*77c1e3ccSAndroid Build Coastguard Worker }
252*77c1e3ccSAndroid Build Coastguard Worker
253*77c1e3ccSAndroid Build Coastguard Worker if (!HandleDecodeResult(res_dec, decoder.get())) break;
254*77c1e3ccSAndroid Build Coastguard Worker
255*77c1e3ccSAndroid Build Coastguard Worker has_dxdata = true;
256*77c1e3ccSAndroid Build Coastguard Worker }
257*77c1e3ccSAndroid Build Coastguard Worker #endif
258*77c1e3ccSAndroid Build Coastguard Worker ASSERT_GE(pkt->data.frame.pts, last_pts);
259*77c1e3ccSAndroid Build Coastguard Worker if (sl == number_spatial_layers - 1)
260*77c1e3ccSAndroid Build Coastguard Worker last_pts = pkt->data.frame.pts;
261*77c1e3ccSAndroid Build Coastguard Worker FramePktHook(pkt);
262*77c1e3ccSAndroid Build Coastguard Worker break;
263*77c1e3ccSAndroid Build Coastguard Worker
264*77c1e3ccSAndroid Build Coastguard Worker case AOM_CODEC_PSNR_PKT: PSNRPktHook(pkt); break;
265*77c1e3ccSAndroid Build Coastguard Worker
266*77c1e3ccSAndroid Build Coastguard Worker case AOM_CODEC_STATS_PKT: StatsPktHook(pkt); break;
267*77c1e3ccSAndroid Build Coastguard Worker
268*77c1e3ccSAndroid Build Coastguard Worker default: break;
269*77c1e3ccSAndroid Build Coastguard Worker }
270*77c1e3ccSAndroid Build Coastguard Worker }
271*77c1e3ccSAndroid Build Coastguard Worker if (has_cxdata) {
272*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img_enc = encoder->GetPreviewFrame();
273*77c1e3ccSAndroid Build Coastguard Worker if (img_enc) {
274*77c1e3ccSAndroid Build Coastguard Worker CalculateFrameLevelSSIM(video->img(), img_enc, cfg_.g_bit_depth,
275*77c1e3ccSAndroid Build Coastguard Worker cfg_.g_input_bit_depth);
276*77c1e3ccSAndroid Build Coastguard Worker }
277*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_DECODER
278*77c1e3ccSAndroid Build Coastguard Worker if (has_dxdata) {
279*77c1e3ccSAndroid Build Coastguard Worker DxDataIterator dec_iter = decoder->GetDxData();
280*77c1e3ccSAndroid Build Coastguard Worker const aom_image_t *img_dec = dec_iter.Next();
281*77c1e3ccSAndroid Build Coastguard Worker if (img_enc && img_dec) {
282*77c1e3ccSAndroid Build Coastguard Worker const bool res = compare_img(img_enc, img_dec, nullptr, nullptr,
283*77c1e3ccSAndroid Build Coastguard Worker nullptr, nullptr, nullptr);
284*77c1e3ccSAndroid Build Coastguard Worker if (!res) { // Mismatch
285*77c1e3ccSAndroid Build Coastguard Worker MismatchHook(img_enc, img_dec);
286*77c1e3ccSAndroid Build Coastguard Worker }
287*77c1e3ccSAndroid Build Coastguard Worker }
288*77c1e3ccSAndroid Build Coastguard Worker if (img_dec) DecompressedFrameHook(*img_dec, video->pts());
289*77c1e3ccSAndroid Build Coastguard Worker }
290*77c1e3ccSAndroid Build Coastguard Worker #endif
291*77c1e3ccSAndroid Build Coastguard Worker }
292*77c1e3ccSAndroid Build Coastguard Worker if (!Continue()) break;
293*77c1e3ccSAndroid Build Coastguard Worker } // Loop over spatial layers
294*77c1e3ccSAndroid Build Coastguard Worker }
295*77c1e3ccSAndroid Build Coastguard Worker
296*77c1e3ccSAndroid Build Coastguard Worker EndPassHook();
297*77c1e3ccSAndroid Build Coastguard Worker
298*77c1e3ccSAndroid Build Coastguard Worker if (!Continue()) break;
299*77c1e3ccSAndroid Build Coastguard Worker }
300*77c1e3ccSAndroid Build Coastguard Worker }
301*77c1e3ccSAndroid Build Coastguard Worker
302*77c1e3ccSAndroid Build Coastguard Worker } // namespace libaom_test
303