/* * Copyright (c) 2012 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/ #ifndef VPX_TEST_ENCODE_TEST_DRIVER_H_ #define VPX_TEST_ENCODE_TEST_DRIVER_H_
// Provides a simplified interface to manage one video encoding pass, given // a configuration and video source. // // TODO(jkoleszar): The exact services it provides and the appropriate // level of abstraction will be fleshed out as more tests are written. class Encoder { public:
Encoder(vpx_codec_enc_cfg_t cfg, vpx_enc_deadline_t deadline, constunsignedlong init_flags, TwopassStatsStore *stats)
: cfg_(cfg), deadline_(deadline), init_flags_(init_flags), stats_(stats) {
memset(&encoder_, 0, sizeof(encoder_));
}
const vpx_image_t *GetPreviewFrame() { return vpx_codec_get_preview_frame(&encoder_);
} // This is a thin wrapper around vpx_codec_encode(), so refer to // vpx_encoder.h for its semantics. void EncodeFrame(VideoSource *video, vpx_enc_frame_flags_t frame_flags);
// Common test functionality for all Encoder tests. // // This class is a mixin which provides the main loop common to all // encoder tests. It provides hooks which can be overridden by subclasses // to implement each test's specific behavior, while centralizing the bulk // of the boilerplate. Note that it doesn't inherit the gtest testing // classes directly, so that tests can be parameterized differently. class EncoderTest { protected: explicit EncoderTest(const CodecFactory *codec)
: codec_(codec), abort_(false), init_flags_(0), frame_flags_(0) { // Default to 1 thread.
cfg_.g_threads = 1;
}
virtual ~EncoderTest() {}
// Initialize the cfg_ member with the default configuration. void InitializeConfig();
// Map the TestMode enum to the deadline_ and passes_ variables. void SetMode(TestMode mode);
// Main loop virtualvoid RunLoop(VideoSource *video);
// Hook to be called at the beginning of a pass. virtualvoid BeginPassHook(unsignedint/*pass*/) {}
// Hook to be called at the end of a pass. virtualvoid EndPassHook() {}
// Hook to be called before encoding a frame. virtualvoid PreEncodeFrameHook(VideoSource * /*video*/) {} virtualvoid PreEncodeFrameHook(VideoSource * /*video*/,
Encoder * /*encoder*/) {}
// Hook to be called on every decompressed frame. virtualvoid DecompressedFrameHook(const vpx_image_t & /*img*/,
vpx_codec_pts_t /*pts*/) {}
// Hook to be called to handle decode result. Return true to continue. virtualbool HandleDecodeResult(const vpx_codec_err_t res_dec, const VideoSource & /*video*/,
Decoder *decoder) {
EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError(); return VPX_CODEC_OK == res_dec;
}
// Hook that can modify the encoder's output data virtualconst vpx_codec_cx_pkt_t *MutateEncoderOutputHook( const vpx_codec_cx_pkt_t *pkt) { return pkt;
}