2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef TEST_DECODE_TEST_DRIVER_H_
12 #define TEST_DECODE_TEST_DRIVER_H_
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "./vpx_config.h"
16 #include "vpx/vpx_decoder.h"
18 namespace libvpx_test {
21 class CompressedVideoSource;
23 // Provides an object to handle decoding output
24 class DxDataIterator {
26 explicit DxDataIterator(vpx_codec_ctx_t *decoder)
27 : decoder_(decoder), iter_(NULL) {}
29 const vpx_image_t *Next() {
30 return vpx_codec_get_frame(decoder_, &iter_);
34 vpx_codec_ctx_t *decoder_;
35 vpx_codec_iter_t iter_;
38 // Provides a simplified interface to manage one video decoding.
39 // Similar to Encoder class, the exact services should be added
40 // as more tests are added.
43 Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
44 : cfg_(cfg), deadline_(deadline), init_done_(false) {
45 memset(&decoder_, 0, sizeof(decoder_));
49 vpx_codec_destroy(&decoder_);
52 vpx_codec_err_t PeekStream(const uint8_t *cxdata, size_t size,
53 vpx_codec_stream_info_t *stream_info);
55 vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size);
57 vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, size_t size,
60 DxDataIterator GetDxData() {
61 return DxDataIterator(&decoder_);
64 void set_deadline(unsigned long deadline) {
68 void Control(int ctrl_id, int arg) {
70 const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
71 ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
74 void Control(int ctrl_id, const void *arg) {
76 const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
77 ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
80 const char* DecodeError() {
81 const char *detail = vpx_codec_error_detail(&decoder_);
82 return detail ? detail : vpx_codec_error(&decoder_);
85 // Passes the external frame buffer information to libvpx.
86 vpx_codec_err_t SetFrameBufferFunctions(
87 vpx_get_frame_buffer_cb_fn_t cb_get,
88 vpx_release_frame_buffer_cb_fn_t cb_release, void *user_priv) {
90 return vpx_codec_set_frame_buffer_functions(
91 &decoder_, cb_get, cb_release, user_priv);
94 const char* GetDecoderName() const {
95 return vpx_codec_iface_name(CodecInterface());
101 virtual vpx_codec_iface_t* CodecInterface() const = 0;
105 const vpx_codec_err_t res = vpx_codec_dec_init(&decoder_,
108 ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
113 vpx_codec_ctx_t decoder_;
114 vpx_codec_dec_cfg_t cfg_;
115 unsigned int deadline_;
119 // Common test functionality for all Decoder tests.
122 // Main decoding loop
123 virtual void RunLoop(CompressedVideoSource *video);
124 virtual void RunLoop(CompressedVideoSource *video,
125 const vpx_codec_dec_cfg_t &dec_cfg);
127 // Hook to be called before decompressing every frame.
128 virtual void PreDecodeFrameHook(const CompressedVideoSource& /*video*/,
129 Decoder* /*decoder*/) {}
131 // Hook to be called to handle decode result. Return true to continue.
132 virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
133 const CompressedVideoSource& /*video*/,
135 EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
136 return VPX_CODEC_OK == res_dec;
139 // Hook to be called on every decompressed frame.
140 virtual void DecompressedFrameHook(const vpx_image_t& /*img*/,
141 const unsigned int /*frame_number*/) {}
143 // Hook to be called on peek result
144 virtual void HandlePeekResult(Decoder* const decoder,
145 CompressedVideoSource *video,
146 const vpx_codec_err_t res_peek);
149 explicit DecoderTest(const CodecFactory *codec) : codec_(codec) {}
151 virtual ~DecoderTest() {}
153 const CodecFactory *codec_;
156 } // namespace libvpx_test
158 #endif // TEST_DECODE_TEST_DRIVER_H_