2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * 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.
12 #ifndef TEST_DECODE_TEST_DRIVER_H_
13 #define TEST_DECODE_TEST_DRIVER_H_
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 #include "./aom_config.h"
17 #include "aom/aom_decoder.h"
19 namespace libaom_test
{
22 class CompressedVideoSource
;
24 // Provides an object to handle decoding output
25 class DxDataIterator
{
27 explicit DxDataIterator(aom_codec_ctx_t
*decoder
)
28 : decoder_(decoder
), iter_(NULL
) {}
30 const aom_image_t
*Next() { return aom_codec_get_frame(decoder_
, &iter_
); }
33 aom_codec_ctx_t
*decoder_
;
34 aom_codec_iter_t iter_
;
37 // Provides a simplified interface to manage one video decoding.
38 // Similar to Encoder class, the exact services should be added
39 // as more tests are added.
42 explicit Decoder(aom_codec_dec_cfg_t cfg
)
43 : cfg_(cfg
), flags_(0), init_done_(false) {
44 memset(&decoder_
, 0, sizeof(decoder_
));
47 Decoder(aom_codec_dec_cfg_t cfg
, const aom_codec_flags_t flag
)
48 : cfg_(cfg
), flags_(flag
), init_done_(false) {
49 memset(&decoder_
, 0, sizeof(decoder_
));
52 virtual ~Decoder() { aom_codec_destroy(&decoder_
); }
54 aom_codec_err_t
PeekStream(const uint8_t *cxdata
, size_t size
,
55 aom_codec_stream_info_t
*stream_info
);
57 aom_codec_err_t
DecodeFrame(const uint8_t *cxdata
, size_t size
);
59 aom_codec_err_t
DecodeFrame(const uint8_t *cxdata
, size_t size
,
62 DxDataIterator
GetDxData() { return DxDataIterator(&decoder_
); }
64 void Control(int ctrl_id
, int arg
) { Control(ctrl_id
, arg
, AOM_CODEC_OK
); }
66 void Control(int ctrl_id
, const void *arg
) {
68 const aom_codec_err_t res
= aom_codec_control_(&decoder_
, ctrl_id
, arg
);
69 ASSERT_EQ(AOM_CODEC_OK
, res
) << DecodeError();
72 void Control(int ctrl_id
, int arg
, aom_codec_err_t expected_value
) {
74 const aom_codec_err_t res
= aom_codec_control_(&decoder_
, ctrl_id
, arg
);
75 ASSERT_EQ(expected_value
, res
) << DecodeError();
78 const char *DecodeError() {
79 const char *detail
= aom_codec_error_detail(&decoder_
);
80 return detail
? detail
: aom_codec_error(&decoder_
);
83 // Passes the external frame buffer information to libaom.
84 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
) {
88 return aom_codec_set_frame_buffer_functions(&decoder_
, cb_get
, cb_release
,
92 const char *GetDecoderName() const {
93 return aom_codec_iface_name(CodecInterface());
100 aom_codec_ctx_t
*GetDecoder() { return &decoder_
; }
103 virtual aom_codec_iface_t
*CodecInterface() const = 0;
107 const aom_codec_err_t res
=
108 aom_codec_dec_init(&decoder_
, CodecInterface(), &cfg_
, flags_
);
109 ASSERT_EQ(AOM_CODEC_OK
, res
) << DecodeError();
114 aom_codec_ctx_t decoder_
;
115 aom_codec_dec_cfg_t cfg_
;
116 aom_codec_flags_t flags_
;
120 // Common test functionality for all Decoder tests.
123 // Main decoding loop
124 virtual void RunLoop(CompressedVideoSource
*video
);
125 virtual void RunLoop(CompressedVideoSource
*video
,
126 const aom_codec_dec_cfg_t
&dec_cfg
);
128 virtual void set_cfg(const aom_codec_dec_cfg_t
&dec_cfg
);
129 virtual void set_flags(const aom_codec_flags_t flags
);
131 // Hook to be called before decompressing every frame.
132 virtual void PreDecodeFrameHook(const CompressedVideoSource
& /*video*/,
133 Decoder
* /*decoder*/) {}
135 // Hook to be called to handle decode result. Return true to continue.
136 virtual bool HandleDecodeResult(const aom_codec_err_t res_dec
,
138 EXPECT_EQ(AOM_CODEC_OK
, res_dec
) << decoder
->DecodeError();
139 return AOM_CODEC_OK
== res_dec
;
142 // Hook to be called on every decompressed frame.
143 virtual void DecompressedFrameHook(const aom_image_t
& /*img*/,
144 const unsigned int /*frame_number*/) {}
146 // Hook to be called on peek result
147 virtual void HandlePeekResult(Decoder
*const decoder
,
148 CompressedVideoSource
*video
,
149 const aom_codec_err_t res_peek
);
152 explicit DecoderTest(const CodecFactory
*codec
)
153 : codec_(codec
), cfg_(), flags_(0) {}
155 virtual ~DecoderTest() {}
157 const CodecFactory
*codec_
;
158 aom_codec_dec_cfg_t cfg_
;
159 aom_codec_flags_t flags_
;
162 } // namespace libaom_test
164 #endif // TEST_DECODE_TEST_DRIVER_H_