xref: /aosp_15_r20/external/libaom/test/encode_test_driver.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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 #ifndef AOM_TEST_ENCODE_TEST_DRIVER_H_
12*77c1e3ccSAndroid Build Coastguard Worker #define AOM_TEST_ENCODE_TEST_DRIVER_H_
13*77c1e3ccSAndroid Build Coastguard Worker 
14*77c1e3ccSAndroid Build Coastguard Worker #include <string>
15*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
16*77c1e3ccSAndroid Build Coastguard Worker 
17*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
20*77c1e3ccSAndroid Build Coastguard Worker 
21*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
22*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aomcx.h"
23*77c1e3ccSAndroid Build Coastguard Worker #endif
24*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_encoder.h"
25*77c1e3ccSAndroid Build Coastguard Worker 
26*77c1e3ccSAndroid Build Coastguard Worker namespace libaom_test {
27*77c1e3ccSAndroid Build Coastguard Worker 
28*77c1e3ccSAndroid Build Coastguard Worker class CodecFactory;
29*77c1e3ccSAndroid Build Coastguard Worker class VideoSource;
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker enum TestMode { kRealTime, kOnePassGood, kTwoPassGood, kAllIntra };
32*77c1e3ccSAndroid Build Coastguard Worker #define ALL_TEST_MODES                                                     \
33*77c1e3ccSAndroid Build Coastguard Worker   ::testing::Values(::libaom_test::kRealTime, ::libaom_test::kOnePassGood, \
34*77c1e3ccSAndroid Build Coastguard Worker                     ::libaom_test::kTwoPassGood)
35*77c1e3ccSAndroid Build Coastguard Worker 
36*77c1e3ccSAndroid Build Coastguard Worker #define ONE_PASS_TEST_MODES \
37*77c1e3ccSAndroid Build Coastguard Worker   ::testing::Values(::libaom_test::kRealTime, ::libaom_test::kOnePassGood)
38*77c1e3ccSAndroid Build Coastguard Worker 
39*77c1e3ccSAndroid Build Coastguard Worker #define TWO_PASS_TEST_MODES ::testing::Values(::libaom_test::kTwoPassGood)
40*77c1e3ccSAndroid Build Coastguard Worker 
41*77c1e3ccSAndroid Build Coastguard Worker #define NONREALTIME_TEST_MODES \
42*77c1e3ccSAndroid Build Coastguard Worker   ::testing::Values(::libaom_test::kOnePassGood, ::libaom_test::kTwoPassGood)
43*77c1e3ccSAndroid Build Coastguard Worker 
44*77c1e3ccSAndroid Build Coastguard Worker // Provides an object to handle the libaom get_cx_data() iteration pattern
45*77c1e3ccSAndroid Build Coastguard Worker class CxDataIterator {
46*77c1e3ccSAndroid Build Coastguard Worker  public:
CxDataIterator(aom_codec_ctx_t * encoder)47*77c1e3ccSAndroid Build Coastguard Worker   explicit CxDataIterator(aom_codec_ctx_t *encoder)
48*77c1e3ccSAndroid Build Coastguard Worker       : encoder_(encoder), iter_(nullptr) {}
49*77c1e3ccSAndroid Build Coastguard Worker 
Next()50*77c1e3ccSAndroid Build Coastguard Worker   const aom_codec_cx_pkt_t *Next() {
51*77c1e3ccSAndroid Build Coastguard Worker     return aom_codec_get_cx_data(encoder_, &iter_);
52*77c1e3ccSAndroid Build Coastguard Worker   }
53*77c1e3ccSAndroid Build Coastguard Worker 
54*77c1e3ccSAndroid Build Coastguard Worker  private:
55*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t *encoder_;
56*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_iter_t iter_;
57*77c1e3ccSAndroid Build Coastguard Worker };
58*77c1e3ccSAndroid Build Coastguard Worker 
59*77c1e3ccSAndroid Build Coastguard Worker // Implements an in-memory store for libaom twopass statistics
60*77c1e3ccSAndroid Build Coastguard Worker class TwopassStatsStore {
61*77c1e3ccSAndroid Build Coastguard Worker  public:
Append(const aom_codec_cx_pkt_t & pkt)62*77c1e3ccSAndroid Build Coastguard Worker   void Append(const aom_codec_cx_pkt_t &pkt) {
63*77c1e3ccSAndroid Build Coastguard Worker     buffer_.append(reinterpret_cast<char *>(pkt.data.twopass_stats.buf),
64*77c1e3ccSAndroid Build Coastguard Worker                    pkt.data.twopass_stats.sz);
65*77c1e3ccSAndroid Build Coastguard Worker   }
66*77c1e3ccSAndroid Build Coastguard Worker 
buf()67*77c1e3ccSAndroid Build Coastguard Worker   aom_fixed_buf_t buf() {
68*77c1e3ccSAndroid Build Coastguard Worker     const aom_fixed_buf_t buf = { &buffer_[0], buffer_.size() };
69*77c1e3ccSAndroid Build Coastguard Worker     return buf;
70*77c1e3ccSAndroid Build Coastguard Worker   }
71*77c1e3ccSAndroid Build Coastguard Worker 
Reset()72*77c1e3ccSAndroid Build Coastguard Worker   void Reset() { buffer_.clear(); }
73*77c1e3ccSAndroid Build Coastguard Worker 
74*77c1e3ccSAndroid Build Coastguard Worker  protected:
75*77c1e3ccSAndroid Build Coastguard Worker   std::string buffer_;
76*77c1e3ccSAndroid Build Coastguard Worker };
77*77c1e3ccSAndroid Build Coastguard Worker 
78*77c1e3ccSAndroid Build Coastguard Worker // Provides a simplified interface to manage one video encoding pass, given
79*77c1e3ccSAndroid Build Coastguard Worker // a configuration and video source.
80*77c1e3ccSAndroid Build Coastguard Worker //
81*77c1e3ccSAndroid Build Coastguard Worker // TODO(jkoleszar): The exact services it provides and the appropriate
82*77c1e3ccSAndroid Build Coastguard Worker // level of abstraction will be fleshed out as more tests are written.
83*77c1e3ccSAndroid Build Coastguard Worker class Encoder {
84*77c1e3ccSAndroid Build Coastguard Worker  public:
Encoder(aom_codec_enc_cfg_t cfg,const aom_codec_flags_t init_flags,TwopassStatsStore * stats)85*77c1e3ccSAndroid Build Coastguard Worker   Encoder(aom_codec_enc_cfg_t cfg, const aom_codec_flags_t init_flags,
86*77c1e3ccSAndroid Build Coastguard Worker           TwopassStatsStore *stats)
87*77c1e3ccSAndroid Build Coastguard Worker       : cfg_(cfg), init_flags_(init_flags), stats_(stats) {
88*77c1e3ccSAndroid Build Coastguard Worker     memset(&encoder_, 0, sizeof(encoder_));
89*77c1e3ccSAndroid Build Coastguard Worker   }
90*77c1e3ccSAndroid Build Coastguard Worker 
~Encoder()91*77c1e3ccSAndroid Build Coastguard Worker   virtual ~Encoder() { aom_codec_destroy(&encoder_); }
92*77c1e3ccSAndroid Build Coastguard Worker 
GetCxData()93*77c1e3ccSAndroid Build Coastguard Worker   CxDataIterator GetCxData() { return CxDataIterator(&encoder_); }
94*77c1e3ccSAndroid Build Coastguard Worker 
95*77c1e3ccSAndroid Build Coastguard Worker   void InitEncoder(VideoSource *video);
96*77c1e3ccSAndroid Build Coastguard Worker 
GetPreviewFrame()97*77c1e3ccSAndroid Build Coastguard Worker   const aom_image_t *GetPreviewFrame() {
98*77c1e3ccSAndroid Build Coastguard Worker     return aom_codec_get_preview_frame(&encoder_);
99*77c1e3ccSAndroid Build Coastguard Worker   }
100*77c1e3ccSAndroid Build Coastguard Worker   // This is a thin wrapper around aom_codec_encode(), so refer to
101*77c1e3ccSAndroid Build Coastguard Worker   // aom_encoder.h for its semantics.
102*77c1e3ccSAndroid Build Coastguard Worker   void EncodeFrame(VideoSource *video, aom_enc_frame_flags_t frame_flags);
103*77c1e3ccSAndroid Build Coastguard Worker 
104*77c1e3ccSAndroid Build Coastguard Worker   // Convenience wrapper for EncodeFrame()
EncodeFrame(VideoSource * video)105*77c1e3ccSAndroid Build Coastguard Worker   void EncodeFrame(VideoSource *video) { EncodeFrame(video, 0); }
106*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,int arg)107*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, int arg) {
108*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
109*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
110*77c1e3ccSAndroid Build Coastguard Worker   }
111*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,int * arg)112*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, int *arg) {
113*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
114*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
115*77c1e3ccSAndroid Build Coastguard Worker   }
116*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,struct aom_scaling_mode * arg)117*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, struct aom_scaling_mode *arg) {
118*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
119*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
120*77c1e3ccSAndroid Build Coastguard Worker   }
121*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,struct aom_svc_layer_id * arg)122*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, struct aom_svc_layer_id *arg) {
123*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
124*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
125*77c1e3ccSAndroid Build Coastguard Worker   }
126*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,struct aom_svc_ref_frame_config * arg)127*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, struct aom_svc_ref_frame_config *arg) {
128*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
129*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
130*77c1e3ccSAndroid Build Coastguard Worker   }
131*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,struct aom_svc_ref_frame_comp_pred * arg)132*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, struct aom_svc_ref_frame_comp_pred *arg) {
133*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
134*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
135*77c1e3ccSAndroid Build Coastguard Worker   }
136*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,struct aom_svc_params * arg)137*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, struct aom_svc_params *arg) {
138*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
139*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
140*77c1e3ccSAndroid Build Coastguard Worker   }
141*77c1e3ccSAndroid Build Coastguard Worker 
Control(int ctrl_id,struct aom_ext_part_funcs * arg)142*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, struct aom_ext_part_funcs *arg) {
143*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
144*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
145*77c1e3ccSAndroid Build Coastguard Worker   }
146*77c1e3ccSAndroid Build Coastguard Worker 
147*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_ENCODER
Control(int ctrl_id,aom_active_map_t * arg)148*77c1e3ccSAndroid Build Coastguard Worker   void Control(int ctrl_id, aom_active_map_t *arg) {
149*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_control(&encoder_, ctrl_id, arg);
150*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
151*77c1e3ccSAndroid Build Coastguard Worker   }
152*77c1e3ccSAndroid Build Coastguard Worker #endif
153*77c1e3ccSAndroid Build Coastguard Worker 
SetOption(const char * name,const char * value)154*77c1e3ccSAndroid Build Coastguard Worker   void SetOption(const char *name, const char *value) {
155*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_set_option(&encoder_, name, value);
156*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
157*77c1e3ccSAndroid Build Coastguard Worker   }
158*77c1e3ccSAndroid Build Coastguard Worker 
Config(const aom_codec_enc_cfg_t * cfg)159*77c1e3ccSAndroid Build Coastguard Worker   void Config(const aom_codec_enc_cfg_t *cfg) {
160*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_err_t res = aom_codec_enc_config_set(&encoder_, cfg);
161*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(AOM_CODEC_OK, res) << EncoderError();
162*77c1e3ccSAndroid Build Coastguard Worker     cfg_ = *cfg;
163*77c1e3ccSAndroid Build Coastguard Worker   }
164*77c1e3ccSAndroid Build Coastguard Worker 
165*77c1e3ccSAndroid Build Coastguard Worker  protected:
166*77c1e3ccSAndroid Build Coastguard Worker   virtual aom_codec_iface_t *CodecInterface() const = 0;
167*77c1e3ccSAndroid Build Coastguard Worker 
EncoderError()168*77c1e3ccSAndroid Build Coastguard Worker   const char *EncoderError() {
169*77c1e3ccSAndroid Build Coastguard Worker     const char *detail = aom_codec_error_detail(&encoder_);
170*77c1e3ccSAndroid Build Coastguard Worker     return detail ? detail : aom_codec_error(&encoder_);
171*77c1e3ccSAndroid Build Coastguard Worker   }
172*77c1e3ccSAndroid Build Coastguard Worker 
173*77c1e3ccSAndroid Build Coastguard Worker   // Encode an image
174*77c1e3ccSAndroid Build Coastguard Worker   void EncodeFrameInternal(const VideoSource &video,
175*77c1e3ccSAndroid Build Coastguard Worker                            aom_enc_frame_flags_t frame_flags);
176*77c1e3ccSAndroid Build Coastguard Worker 
177*77c1e3ccSAndroid Build Coastguard Worker   // Flush the encoder on EOS
178*77c1e3ccSAndroid Build Coastguard Worker   void Flush();
179*77c1e3ccSAndroid Build Coastguard Worker 
180*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctx_t encoder_;
181*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg_;
182*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_flags_t init_flags_;
183*77c1e3ccSAndroid Build Coastguard Worker   TwopassStatsStore *stats_;
184*77c1e3ccSAndroid Build Coastguard Worker };
185*77c1e3ccSAndroid Build Coastguard Worker 
186*77c1e3ccSAndroid Build Coastguard Worker // Common test functionality for all Encoder tests.
187*77c1e3ccSAndroid Build Coastguard Worker //
188*77c1e3ccSAndroid Build Coastguard Worker // This class is a mixin which provides the main loop common to all
189*77c1e3ccSAndroid Build Coastguard Worker // encoder tests. It provides hooks which can be overridden by subclasses
190*77c1e3ccSAndroid Build Coastguard Worker // to implement each test's specific behavior, while centralizing the bulk
191*77c1e3ccSAndroid Build Coastguard Worker // of the boilerplate. Note that it doesn't inherit the gtest testing
192*77c1e3ccSAndroid Build Coastguard Worker // classes directly, so that tests can be parameterized differently.
193*77c1e3ccSAndroid Build Coastguard Worker class EncoderTest {
194*77c1e3ccSAndroid Build Coastguard Worker  protected:
EncoderTest(const CodecFactory * codec)195*77c1e3ccSAndroid Build Coastguard Worker   explicit EncoderTest(const CodecFactory *codec)
196*77c1e3ccSAndroid Build Coastguard Worker       : codec_(codec), abort_(false), init_flags_(0), frame_flags_(0),
197*77c1e3ccSAndroid Build Coastguard Worker         mode_(kRealTime) {
198*77c1e3ccSAndroid Build Coastguard Worker     // Default to 1 thread.
199*77c1e3ccSAndroid Build Coastguard Worker     cfg_.g_threads = 1;
200*77c1e3ccSAndroid Build Coastguard Worker   }
201*77c1e3ccSAndroid Build Coastguard Worker 
202*77c1e3ccSAndroid Build Coastguard Worker   virtual ~EncoderTest() = default;
203*77c1e3ccSAndroid Build Coastguard Worker 
204*77c1e3ccSAndroid Build Coastguard Worker   // Initialize the cfg_ member with the default configuration for the
205*77c1e3ccSAndroid Build Coastguard Worker   // TestMode enum and maps the TestMode enum to the passes_ variable.
206*77c1e3ccSAndroid Build Coastguard Worker   void InitializeConfig(TestMode mode);
207*77c1e3ccSAndroid Build Coastguard Worker 
208*77c1e3ccSAndroid Build Coastguard Worker   // Set encoder flag.
set_init_flags(aom_codec_flags_t flag)209*77c1e3ccSAndroid Build Coastguard Worker   void set_init_flags(aom_codec_flags_t flag) { init_flags_ = flag; }
210*77c1e3ccSAndroid Build Coastguard Worker 
211*77c1e3ccSAndroid Build Coastguard Worker   // Main loop
212*77c1e3ccSAndroid Build Coastguard Worker   virtual void RunLoop(VideoSource *video);
213*77c1e3ccSAndroid Build Coastguard Worker 
214*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called at the beginning of a pass.
BeginPassHook(unsigned int)215*77c1e3ccSAndroid Build Coastguard Worker   virtual void BeginPassHook(unsigned int /*pass*/) {}
216*77c1e3ccSAndroid Build Coastguard Worker 
217*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called at the end of a pass.
EndPassHook()218*77c1e3ccSAndroid Build Coastguard Worker   virtual void EndPassHook() {}
219*77c1e3ccSAndroid Build Coastguard Worker 
220*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called before encoding a frame.
PreEncodeFrameHook(VideoSource *,Encoder *)221*77c1e3ccSAndroid Build Coastguard Worker   virtual void PreEncodeFrameHook(VideoSource * /*video*/,
222*77c1e3ccSAndroid Build Coastguard Worker                                   Encoder * /*encoder*/) {}
223*77c1e3ccSAndroid Build Coastguard Worker 
PostEncodeFrameHook(Encoder *)224*77c1e3ccSAndroid Build Coastguard Worker   virtual void PostEncodeFrameHook(Encoder * /*encoder*/) {}
225*77c1e3ccSAndroid Build Coastguard Worker 
226*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called on every compressed data packet.
FramePktHook(const aom_codec_cx_pkt_t *)227*77c1e3ccSAndroid Build Coastguard Worker   virtual void FramePktHook(const aom_codec_cx_pkt_t * /*pkt*/) {}
228*77c1e3ccSAndroid Build Coastguard Worker 
229*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called on every PSNR packet.
PSNRPktHook(const aom_codec_cx_pkt_t *)230*77c1e3ccSAndroid Build Coastguard Worker   virtual void PSNRPktHook(const aom_codec_cx_pkt_t * /*pkt*/) {}
231*77c1e3ccSAndroid Build Coastguard Worker 
232*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called on every first pass stats packet.
StatsPktHook(const aom_codec_cx_pkt_t *)233*77c1e3ccSAndroid Build Coastguard Worker   virtual void StatsPktHook(const aom_codec_cx_pkt_t * /*pkt*/) {}
234*77c1e3ccSAndroid Build Coastguard Worker 
235*77c1e3ccSAndroid Build Coastguard Worker   // Calculates SSIM at frame level.
CalculateFrameLevelSSIM(const aom_image_t *,const aom_image_t *,aom_bit_depth_t,unsigned int)236*77c1e3ccSAndroid Build Coastguard Worker   virtual void CalculateFrameLevelSSIM(const aom_image_t * /*img_src*/,
237*77c1e3ccSAndroid Build Coastguard Worker                                        const aom_image_t * /*img_enc*/,
238*77c1e3ccSAndroid Build Coastguard Worker                                        aom_bit_depth_t /*bit_depth*/,
239*77c1e3ccSAndroid Build Coastguard Worker                                        unsigned int /*input_bit_depth*/) {}
240*77c1e3ccSAndroid Build Coastguard Worker 
241*77c1e3ccSAndroid Build Coastguard Worker   // Hook to determine whether the encode loop should continue.
Continue()242*77c1e3ccSAndroid Build Coastguard Worker   virtual bool Continue() const {
243*77c1e3ccSAndroid Build Coastguard Worker     return !(::testing::Test::HasFatalFailure() || abort_);
244*77c1e3ccSAndroid Build Coastguard Worker   }
245*77c1e3ccSAndroid Build Coastguard Worker 
246*77c1e3ccSAndroid Build Coastguard Worker   // Hook to determine whether to decode frame after encoding
DoDecode()247*77c1e3ccSAndroid Build Coastguard Worker   virtual bool DoDecode() const { return true; }
248*77c1e3ccSAndroid Build Coastguard Worker 
249*77c1e3ccSAndroid Build Coastguard Worker   // Hook to determine whether to decode invisible frames after encoding
DoDecodeInvisible()250*77c1e3ccSAndroid Build Coastguard Worker   virtual bool DoDecodeInvisible() const { return true; }
251*77c1e3ccSAndroid Build Coastguard Worker 
252*77c1e3ccSAndroid Build Coastguard Worker   // Hook to handle encode/decode mismatch
253*77c1e3ccSAndroid Build Coastguard Worker   virtual void MismatchHook(const aom_image_t *img1, const aom_image_t *img2);
254*77c1e3ccSAndroid Build Coastguard Worker 
255*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called on every decompressed frame.
DecompressedFrameHook(const aom_image_t &,aom_codec_pts_t)256*77c1e3ccSAndroid Build Coastguard Worker   virtual void DecompressedFrameHook(const aom_image_t & /*img*/,
257*77c1e3ccSAndroid Build Coastguard Worker                                      aom_codec_pts_t /*pts*/) {}
258*77c1e3ccSAndroid Build Coastguard Worker 
259*77c1e3ccSAndroid Build Coastguard Worker   // Hook to be called to handle decode result. Return true to continue.
HandleDecodeResult(const aom_codec_err_t res_dec,Decoder * decoder)260*77c1e3ccSAndroid Build Coastguard Worker   virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
261*77c1e3ccSAndroid Build Coastguard Worker                                   Decoder *decoder) {
262*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
263*77c1e3ccSAndroid Build Coastguard Worker     return AOM_CODEC_OK == res_dec;
264*77c1e3ccSAndroid Build Coastguard Worker   }
265*77c1e3ccSAndroid Build Coastguard Worker 
GetNumSpatialLayers()266*77c1e3ccSAndroid Build Coastguard Worker   virtual int GetNumSpatialLayers() { return 1; }
267*77c1e3ccSAndroid Build Coastguard Worker 
268*77c1e3ccSAndroid Build Coastguard Worker   // Hook that can modify the encoder's output data
MutateEncoderOutputHook(const aom_codec_cx_pkt_t * pkt)269*77c1e3ccSAndroid Build Coastguard Worker   virtual const aom_codec_cx_pkt_t *MutateEncoderOutputHook(
270*77c1e3ccSAndroid Build Coastguard Worker       const aom_codec_cx_pkt_t *pkt) {
271*77c1e3ccSAndroid Build Coastguard Worker     return pkt;
272*77c1e3ccSAndroid Build Coastguard Worker   }
273*77c1e3ccSAndroid Build Coastguard Worker 
274*77c1e3ccSAndroid Build Coastguard Worker   const CodecFactory *codec_;
275*77c1e3ccSAndroid Build Coastguard Worker   bool abort_;
276*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_enc_cfg_t cfg_;
277*77c1e3ccSAndroid Build Coastguard Worker   unsigned int passes_;
278*77c1e3ccSAndroid Build Coastguard Worker   TwopassStatsStore stats_;
279*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_flags_t init_flags_;
280*77c1e3ccSAndroid Build Coastguard Worker   aom_enc_frame_flags_t frame_flags_;
281*77c1e3ccSAndroid Build Coastguard Worker   TestMode mode_;
282*77c1e3ccSAndroid Build Coastguard Worker };
283*77c1e3ccSAndroid Build Coastguard Worker 
284*77c1e3ccSAndroid Build Coastguard Worker }  // namespace libaom_test
285*77c1e3ccSAndroid Build Coastguard Worker 
286*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_TEST_ENCODE_TEST_DRIVER_H_
287