2012-08-30 22:43:15 +02:00
|
|
|
/*
|
|
|
|
* 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 TEST_DECODE_TEST_DRIVER_H_
|
|
|
|
#define TEST_DECODE_TEST_DRIVER_H_
|
2012-10-04 21:59:36 +02:00
|
|
|
#include <cstring>
|
2012-08-30 22:43:15 +02:00
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
2013-09-05 17:45:56 +02:00
|
|
|
#include "./vpx_config.h"
|
2012-08-30 22:43:15 +02:00
|
|
|
#include "vpx/vpx_decoder.h"
|
2012-10-04 21:59:36 +02:00
|
|
|
|
2012-08-30 22:43:15 +02:00
|
|
|
namespace libvpx_test {
|
|
|
|
|
2013-01-18 20:51:12 +01:00
|
|
|
class CodecFactory;
|
2012-10-04 21:59:36 +02:00
|
|
|
class CompressedVideoSource;
|
2012-08-30 22:43:15 +02:00
|
|
|
|
|
|
|
// Provides an object to handle decoding output
|
|
|
|
class DxDataIterator {
|
|
|
|
public:
|
|
|
|
explicit DxDataIterator(vpx_codec_ctx_t *decoder)
|
2012-10-04 21:59:36 +02:00
|
|
|
: decoder_(decoder), iter_(NULL) {}
|
2012-08-30 22:43:15 +02:00
|
|
|
|
|
|
|
const vpx_image_t *Next() {
|
|
|
|
return vpx_codec_get_frame(decoder_, &iter_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vpx_codec_ctx_t *decoder_;
|
|
|
|
vpx_codec_iter_t iter_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Provides a simplified interface to manage one video decoding.
|
2013-09-05 17:45:56 +02:00
|
|
|
// Similar to Encoder class, the exact services should be added
|
|
|
|
// as more tests are added.
|
2012-08-30 22:43:15 +02:00
|
|
|
class Decoder {
|
|
|
|
public:
|
2012-10-04 21:59:36 +02:00
|
|
|
Decoder(vpx_codec_dec_cfg_t cfg, unsigned long deadline)
|
2013-03-27 18:41:29 +01:00
|
|
|
: cfg_(cfg), deadline_(deadline), init_done_(false) {
|
2012-08-30 22:43:15 +02:00
|
|
|
memset(&decoder_, 0, sizeof(decoder_));
|
|
|
|
}
|
|
|
|
|
2013-01-18 20:51:12 +01:00
|
|
|
virtual ~Decoder() {
|
2012-08-30 22:43:15 +02:00
|
|
|
vpx_codec_destroy(&decoder_);
|
|
|
|
}
|
|
|
|
|
2013-03-16 02:21:55 +01:00
|
|
|
vpx_codec_err_t DecodeFrame(const uint8_t *cxdata, int size);
|
2012-08-30 22:43:15 +02:00
|
|
|
|
|
|
|
DxDataIterator GetDxData() {
|
|
|
|
return DxDataIterator(&decoder_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_deadline(unsigned long deadline) {
|
|
|
|
deadline_ = deadline;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Control(int ctrl_id, int arg) {
|
2013-03-27 18:41:29 +01:00
|
|
|
InitOnce();
|
2012-08-30 22:43:15 +02:00
|
|
|
const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
|
|
|
|
ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
|
|
|
|
}
|
|
|
|
|
2013-03-16 02:21:55 +01:00
|
|
|
void Control(int ctrl_id, const void *arg) {
|
2013-03-27 18:41:29 +01:00
|
|
|
InitOnce();
|
2013-03-16 02:21:55 +01:00
|
|
|
const vpx_codec_err_t res = vpx_codec_control_(&decoder_, ctrl_id, arg);
|
|
|
|
ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
|
|
|
|
}
|
2013-01-18 20:51:12 +01:00
|
|
|
|
|
|
|
const char* DecodeError() {
|
2012-08-30 22:43:15 +02:00
|
|
|
const char *detail = vpx_codec_error_detail(&decoder_);
|
|
|
|
return detail ? detail : vpx_codec_error(&decoder_);
|
|
|
|
}
|
|
|
|
|
2013-03-16 02:21:55 +01:00
|
|
|
protected:
|
2013-03-27 18:41:29 +01:00
|
|
|
virtual const vpx_codec_iface_t* CodecInterface() const = 0;
|
|
|
|
|
|
|
|
void InitOnce() {
|
|
|
|
if (!init_done_) {
|
|
|
|
const vpx_codec_err_t res = vpx_codec_dec_init(&decoder_,
|
|
|
|
CodecInterface(),
|
|
|
|
&cfg_, 0);
|
|
|
|
ASSERT_EQ(VPX_CODEC_OK, res) << DecodeError();
|
|
|
|
init_done_ = true;
|
|
|
|
}
|
2013-03-16 02:21:55 +01:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:43:15 +02:00
|
|
|
vpx_codec_ctx_t decoder_;
|
|
|
|
vpx_codec_dec_cfg_t cfg_;
|
|
|
|
unsigned int deadline_;
|
2013-03-27 18:41:29 +01:00
|
|
|
bool init_done_;
|
2012-08-30 22:43:15 +02:00
|
|
|
};
|
|
|
|
|
2012-10-04 21:59:36 +02:00
|
|
|
// Common test functionality for all Decoder tests.
|
|
|
|
class DecoderTest {
|
|
|
|
public:
|
2013-01-15 15:43:35 +01:00
|
|
|
// Main decoding loop
|
2012-10-04 21:59:36 +02:00
|
|
|
virtual void RunLoop(CompressedVideoSource *video);
|
|
|
|
|
2013-12-10 02:07:10 +01:00
|
|
|
// Hook to be called before decompressing every frame.
|
|
|
|
virtual void PreDecodeFrameHook(const CompressedVideoSource& video,
|
|
|
|
Decoder *decoder) {}
|
|
|
|
|
2012-10-04 21:59:36 +02:00
|
|
|
// Hook to be called on every decompressed frame.
|
|
|
|
virtual void DecompressedFrameHook(const vpx_image_t& img,
|
|
|
|
const unsigned int frame_number) {}
|
|
|
|
|
|
|
|
protected:
|
2013-01-18 20:51:12 +01:00
|
|
|
explicit DecoderTest(const CodecFactory *codec) : codec_(codec) {}
|
2012-10-04 21:59:36 +02:00
|
|
|
|
|
|
|
virtual ~DecoderTest() {}
|
2013-01-18 20:51:12 +01:00
|
|
|
|
|
|
|
const CodecFactory *codec_;
|
2012-10-04 21:59:36 +02:00
|
|
|
};
|
|
|
|
|
2012-08-30 22:43:15 +02:00
|
|
|
} // namespace libvpx_test
|
2012-10-04 21:59:36 +02:00
|
|
|
|
|
|
|
#endif // TEST_DECODE_TEST_DRIVER_H_
|