blob: e7deb389c9fedeb1f54b0aeee1d283afb275ea5a [file] [log] [blame]
Yaowu Xuc953aea2012-08-30 13:43:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc953aea2012-08-30 13:43:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc953aea2012-08-30 13:43:15 -070010 */
11
12#ifndef TEST_DECODE_TEST_DRIVER_H_
13#define TEST_DECODE_TEST_DRIVER_H_
Yunqing Wang15dffcf2012-10-04 12:59:36 -070014#include <cstring>
Tom Finegan7a07ece2017-02-07 17:14:05 -080015#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
17#include "aom/aom_decoder.h"
Yunqing Wang15dffcf2012-10-04 12:59:36 -070018
Yaowu Xuc27fc142016-08-22 16:08:15 -070019namespace libaom_test {
Yaowu Xuc953aea2012-08-30 13:43:15 -070020
John Koleszar706cafe2013-01-18 11:51:12 -080021class CodecFactory;
Yunqing Wang15dffcf2012-10-04 12:59:36 -070022class CompressedVideoSource;
Yaowu Xuc953aea2012-08-30 13:43:15 -070023
24// Provides an object to handle decoding output
25class DxDataIterator {
26 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070027 explicit DxDataIterator(aom_codec_ctx_t *decoder)
Yunqing Wang15dffcf2012-10-04 12:59:36 -070028 : decoder_(decoder), iter_(NULL) {}
Yaowu Xuc953aea2012-08-30 13:43:15 -070029
Yaowu Xuf883b422016-08-30 14:01:10 -070030 const aom_image_t *Next() { return aom_codec_get_frame(decoder_, &iter_); }
Yaowu Xuc953aea2012-08-30 13:43:15 -070031
32 private:
Yaowu Xuf883b422016-08-30 14:01:10 -070033 aom_codec_ctx_t *decoder_;
34 aom_codec_iter_t iter_;
Yaowu Xuc953aea2012-08-30 13:43:15 -070035};
36
37// Provides a simplified interface to manage one video decoding.
Yaowu Xuafffa3d2013-09-05 08:45:56 -070038// Similar to Encoder class, the exact services should be added
39// as more tests are added.
Yaowu Xuc953aea2012-08-30 13:43:15 -070040class Decoder {
41 public:
James Zern3b96b762017-03-24 17:12:19 -070042 explicit Decoder(aom_codec_dec_cfg_t cfg)
43 : cfg_(cfg), flags_(0), init_done_(false) {
hkuang93536072014-11-20 15:39:56 -080044 memset(&decoder_, 0, sizeof(decoder_));
45 }
46
James Zern3b96b762017-03-24 17:12:19 -070047 Decoder(aom_codec_dec_cfg_t cfg, const aom_codec_flags_t flag)
48 : cfg_(cfg), flags_(flag), init_done_(false) {
Yaowu Xuc953aea2012-08-30 13:43:15 -070049 memset(&decoder_, 0, sizeof(decoder_));
50 }
51
Yaowu Xuf883b422016-08-30 14:01:10 -070052 virtual ~Decoder() { aom_codec_destroy(&decoder_); }
Yaowu Xuc953aea2012-08-30 13:43:15 -070053
Yaowu Xuf883b422016-08-30 14:01:10 -070054 aom_codec_err_t PeekStream(const uint8_t *cxdata, size_t size,
55 aom_codec_stream_info_t *stream_info);
Jim Bankoski96727b92014-06-23 08:37:18 -070056
Yaowu Xuf883b422016-08-30 14:01:10 -070057 aom_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size);
Yaowu Xuc953aea2012-08-30 13:43:15 -070058
Yaowu Xuf883b422016-08-30 14:01:10 -070059 aom_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size,
hkuang5e7242d2014-06-23 14:59:20 -070060 void *user_priv);
61
clang-format3a826f12016-08-11 17:46:05 -070062 DxDataIterator GetDxData() { return DxDataIterator(&decoder_); }
Yaowu Xuc953aea2012-08-30 13:43:15 -070063
Yaowu Xuf883b422016-08-30 14:01:10 -070064 void Control(int ctrl_id, int arg) { Control(ctrl_id, arg, AOM_CODEC_OK); }
Yaowu Xuc953aea2012-08-30 13:43:15 -070065
Dmitry Kovalev26cec5c2013-03-15 18:21:55 -070066 void Control(int ctrl_id, const void *arg) {
John Koleszar771fc832013-03-27 10:41:29 -070067 InitOnce();
Yaowu Xuf883b422016-08-30 14:01:10 -070068 const aom_codec_err_t res = aom_codec_control_(&decoder_, ctrl_id, arg);
69 ASSERT_EQ(AOM_CODEC_OK, res) << DecodeError();
Dmitry Kovalev26cec5c2013-03-15 18:21:55 -070070 }
John Koleszar706cafe2013-01-18 11:51:12 -080071
Yaowu Xuf883b422016-08-30 14:01:10 -070072 void Control(int ctrl_id, int arg, aom_codec_err_t expected_value) {
Frank Galliganc4f70792014-12-15 12:00:09 -080073 InitOnce();
Yaowu Xuf883b422016-08-30 14:01:10 -070074 const aom_codec_err_t res = aom_codec_control_(&decoder_, ctrl_id, arg);
Frank Galliganc4f70792014-12-15 12:00:09 -080075 ASSERT_EQ(expected_value, res) << DecodeError();
76 }
77
clang-format3a826f12016-08-11 17:46:05 -070078 const char *DecodeError() {
Yaowu Xuf883b422016-08-30 14:01:10 -070079 const char *detail = aom_codec_error_detail(&decoder_);
80 return detail ? detail : aom_codec_error(&decoder_);
Yaowu Xuc953aea2012-08-30 13:43:15 -070081 }
82
Yaowu Xuc27fc142016-08-22 16:08:15 -070083 // Passes the external frame buffer information to libaom.
Yaowu Xuf883b422016-08-30 14:01:10 -070084 aom_codec_err_t SetFrameBufferFunctions(
85 aom_get_frame_buffer_cb_fn_t cb_get,
86 aom_release_frame_buffer_cb_fn_t cb_release, void *user_priv) {
Frank Galligana4f30a52014-02-06 17:13:08 -080087 InitOnce();
Yaowu Xuf883b422016-08-30 14:01:10 -070088 return aom_codec_set_frame_buffer_functions(&decoder_, cb_get, cb_release,
clang-format3a826f12016-08-11 17:46:05 -070089 user_priv);
Frank Galligana4f30a52014-02-06 17:13:08 -080090 }
91
clang-format3a826f12016-08-11 17:46:05 -070092 const char *GetDecoderName() const {
Yaowu Xuf883b422016-08-30 14:01:10 -070093 return aom_codec_iface_name(CodecInterface());
Jim Bankoski96727b92014-06-23 08:37:18 -070094 }
95
Deb Mukherjeec447a502014-07-15 01:54:29 -070096 bool IsVP8() const;
97
Yaowu Xuf883b422016-08-30 14:01:10 -070098 bool IsAV1() const;
Yunqing Wang8e5e3382016-05-05 16:42:57 -070099
Yaowu Xuf883b422016-08-30 14:01:10 -0700100 aom_codec_ctx_t *GetDecoder() { return &decoder_; }
Jim Bankoskia0d9a9d2014-12-11 17:34:32 -0800101
Dmitry Kovalev26cec5c2013-03-15 18:21:55 -0700102 protected:
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 virtual aom_codec_iface_t *CodecInterface() const = 0;
John Koleszar771fc832013-03-27 10:41:29 -0700104
105 void InitOnce() {
106 if (!init_done_) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 const aom_codec_err_t res =
108 aom_codec_dec_init(&decoder_, CodecInterface(), &cfg_, flags_);
109 ASSERT_EQ(AOM_CODEC_OK, res) << DecodeError();
John Koleszar771fc832013-03-27 10:41:29 -0700110 init_done_ = true;
111 }
Dmitry Kovalev26cec5c2013-03-15 18:21:55 -0700112 }
113
Yaowu Xuf883b422016-08-30 14:01:10 -0700114 aom_codec_ctx_t decoder_;
115 aom_codec_dec_cfg_t cfg_;
116 aom_codec_flags_t flags_;
clang-format3a826f12016-08-11 17:46:05 -0700117 bool init_done_;
Yaowu Xuc953aea2012-08-30 13:43:15 -0700118};
119
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700120// Common test functionality for all Decoder tests.
121class DecoderTest {
122 public:
Deb Mukherjee01cafaa2013-01-15 06:43:35 -0800123 // Main decoding loop
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700124 virtual void RunLoop(CompressedVideoSource *video);
hkuangc147cf32014-07-01 16:04:53 -0700125 virtual void RunLoop(CompressedVideoSource *video,
Yaowu Xuf883b422016-08-30 14:01:10 -0700126 const aom_codec_dec_cfg_t &dec_cfg);
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700127
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 virtual void set_cfg(const aom_codec_dec_cfg_t &dec_cfg);
129 virtual void set_flags(const aom_codec_flags_t flags);
hkuang93536072014-11-20 15:39:56 -0800130
Frank Galliganf9d69bd2013-12-09 17:07:10 -0800131 // Hook to be called before decompressing every frame.
clang-format3a826f12016-08-11 17:46:05 -0700132 virtual void PreDecodeFrameHook(const CompressedVideoSource & /*video*/,
133 Decoder * /*decoder*/) {}
Frank Galliganf9d69bd2013-12-09 17:07:10 -0800134
Jim Bankoskidc2f2ce2014-06-20 13:52:06 -0700135 // Hook to be called to handle decode result. Return true to continue.
Yaowu Xuf883b422016-08-30 14:01:10 -0700136 virtual bool HandleDecodeResult(const aom_codec_err_t res_dec,
Jim Bankoskidc2f2ce2014-06-20 13:52:06 -0700137 Decoder *decoder) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700138 EXPECT_EQ(AOM_CODEC_OK, res_dec) << decoder->DecodeError();
139 return AOM_CODEC_OK == res_dec;
Jim Bankoskidc2f2ce2014-06-20 13:52:06 -0700140 }
141
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700142 // Hook to be called on every decompressed frame.
Yaowu Xuf883b422016-08-30 14:01:10 -0700143 virtual void DecompressedFrameHook(const aom_image_t & /*img*/,
James Zernadfda322014-08-22 11:58:48 -0700144 const unsigned int /*frame_number*/) {}
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700145
Deb Mukherjeec447a502014-07-15 01:54:29 -0700146 // Hook to be called on peek result
clang-format3a826f12016-08-11 17:46:05 -0700147 virtual void HandlePeekResult(Decoder *const decoder,
Deb Mukherjeec447a502014-07-15 01:54:29 -0700148 CompressedVideoSource *video,
Yaowu Xuf883b422016-08-30 14:01:10 -0700149 const aom_codec_err_t res_peek);
Deb Mukherjeec447a502014-07-15 01:54:29 -0700150
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700151 protected:
hkuang93536072014-11-20 15:39:56 -0800152 explicit DecoderTest(const CodecFactory *codec)
clang-format3a826f12016-08-11 17:46:05 -0700153 : codec_(codec), cfg_(), flags_(0) {}
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700154
155 virtual ~DecoderTest() {}
John Koleszar706cafe2013-01-18 11:51:12 -0800156
157 const CodecFactory *codec_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700158 aom_codec_dec_cfg_t cfg_;
159 aom_codec_flags_t flags_;
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700160};
161
Yaowu Xuc27fc142016-08-22 16:08:15 -0700162} // namespace libaom_test
Yunqing Wang15dffcf2012-10-04 12:59:36 -0700163
164#endif // TEST_DECODE_TEST_DRIVER_H_