2014-02-12 07:52:35 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "codec_api.h"
|
2014-02-12 21:28:35 +01:00
|
|
|
#include <stddef.h>
|
2014-02-12 07:52:35 +01:00
|
|
|
|
|
|
|
static void CheckFunctionOrder(int expect, int actual, const char* name) {
|
|
|
|
EXPECT_EQ(expect, actual) << "Wrong function order: " << name;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void(*CheckFunc)(int, int, const char*);
|
|
|
|
extern "C" void CheckEncoderInterface(ISVCEncoder* p, CheckFunc);
|
|
|
|
extern "C" void CheckDecoderInterface(ISVCDecoder* p, CheckFunc);
|
2014-02-12 21:28:35 +01:00
|
|
|
extern "C" size_t GetBoolSize(void);
|
|
|
|
extern "C" size_t GetBoolOffset(void);
|
|
|
|
extern "C" size_t GetBoolStructSize(void);
|
2014-02-12 07:52:35 +01:00
|
|
|
|
|
|
|
// Store the 'this' pointer to verify 'this' is received as expected from C code.
|
|
|
|
static void* gThis;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a unique number for each virtual function so that we are able to
|
|
|
|
* check if the order of functions in the virtual table is as expected.
|
|
|
|
*/
|
|
|
|
struct SVCEncoderImpl : public ISVCEncoder {
|
|
|
|
virtual ~SVCEncoderImpl() {}
|
2014-02-18 11:29:43 +01:00
|
|
|
virtual int EXTAPI Initialize(const SEncParamBase* pParam) {
|
2014-02-12 07:52:35 +01:00
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 1;
|
|
|
|
}
|
2014-02-18 11:29:43 +01:00
|
|
|
virtual int EXTAPI InitializeExt(const SEncParamExt* pParam) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 2;
|
|
|
|
}
|
2014-02-26 21:08:41 +01:00
|
|
|
virtual int EXTAPI GetDefaultParams(SEncParamExt* pParam) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 10;
|
|
|
|
}
|
2014-02-12 07:52:35 +01:00
|
|
|
virtual int EXTAPI Uninitialize() {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 3;
|
|
|
|
}
|
2014-02-20 03:33:07 +01:00
|
|
|
virtual int EXTAPI EncodeFrame(const SSourcePicture* kpSrcPic,
|
2014-02-12 07:52:35 +01:00
|
|
|
SFrameBSInfo* pBsInfo) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
virtual int EXTAPI EncodeParameterSets(SFrameBSInfo* pBsInfo) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
2014-02-20 03:33:07 +01:00
|
|
|
return 5;
|
2014-02-12 07:52:35 +01:00
|
|
|
}
|
2014-02-20 03:33:07 +01:00
|
|
|
virtual int EXTAPI PauseFrame(const SSourcePicture* kpSrcPic,
|
2014-02-12 07:52:35 +01:00
|
|
|
SFrameBSInfo* pBsInfo) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
2014-02-20 03:33:07 +01:00
|
|
|
return 6;
|
2014-02-12 07:52:35 +01:00
|
|
|
}
|
|
|
|
virtual int EXTAPI ForceIntraFrame(bool bIDR) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
2014-02-20 03:33:07 +01:00
|
|
|
return 7;
|
2014-02-12 07:52:35 +01:00
|
|
|
}
|
|
|
|
virtual int EXTAPI SetOption(ENCODER_OPTION eOptionId, void* pOption) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
2014-02-20 03:33:07 +01:00
|
|
|
return 8;
|
2014-02-12 07:52:35 +01:00
|
|
|
}
|
|
|
|
virtual int EXTAPI GetOption(ENCODER_OPTION eOptionId, void* pOption) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
2014-02-20 03:33:07 +01:00
|
|
|
return 9;
|
2014-02-12 07:52:35 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SVCDecoderImpl : public ISVCDecoder {
|
|
|
|
virtual ~SVCDecoderImpl() {}
|
2014-02-18 11:59:14 +01:00
|
|
|
virtual long EXTAPI Initialize(const SDecodingParam* pParam) {
|
2014-02-12 07:52:35 +01:00
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
virtual long EXTAPI Uninitialize() {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
virtual DECODING_STATE EXTAPI DecodeFrame(const unsigned char* pSrc,
|
|
|
|
const int iSrcLen, unsigned char** ppDst, int* pStride,
|
|
|
|
int& iWidth, int& iHeight) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return static_cast<DECODING_STATE>(3);
|
|
|
|
}
|
|
|
|
virtual DECODING_STATE EXTAPI DecodeFrame2(const unsigned char* pSrc,
|
|
|
|
const int iSrcLen, void** ppDst, SBufferInfo* pDstInfo) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return static_cast<DECODING_STATE>(4);
|
|
|
|
}
|
|
|
|
virtual DECODING_STATE EXTAPI DecodeFrameEx(const unsigned char* pSrc,
|
|
|
|
const int iSrcLen, unsigned char* pDst, int iDstStride,
|
|
|
|
int& iDstLen, int& iWidth, int& iHeight, int& iColorFormat) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return static_cast<DECODING_STATE>(5);
|
|
|
|
}
|
|
|
|
virtual long EXTAPI SetOption (DECODER_OPTION eOptionId, void* pOption) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
virtual long EXTAPI GetOption (DECODER_OPTION eOptionId, void* pOption) {
|
|
|
|
EXPECT_TRUE(gThis == this);
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(ISVCEncoderTest, CheckFunctionOrder) {
|
|
|
|
SVCEncoderImpl* p = new SVCEncoderImpl;
|
|
|
|
gThis = p;
|
|
|
|
CheckEncoderInterface(p, CheckFunctionOrder);
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ISVCDecoderTest, CheckFunctionOrder) {
|
|
|
|
SVCDecoderImpl* p = new SVCDecoderImpl;
|
|
|
|
gThis = p;
|
|
|
|
CheckDecoderInterface(p, CheckFunctionOrder);
|
|
|
|
delete p;
|
|
|
|
}
|
2014-02-12 21:28:35 +01:00
|
|
|
|
|
|
|
struct bool_test_struct {
|
|
|
|
char c;
|
|
|
|
bool b;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(ISVCDecoderEncoderTest, CheckCAbi) {
|
|
|
|
EXPECT_EQ(sizeof(bool), GetBoolSize()) << "Wrong size of bool type";
|
|
|
|
EXPECT_EQ(offsetof(bool_test_struct, b), GetBoolOffset()) << "Wrong alignment of bool in a struct";
|
|
|
|
EXPECT_EQ(sizeof(bool_test_struct), GetBoolStructSize()) << "Wrong size of struct with a bool";
|
|
|
|
}
|