enable api test for decoder VclNal
This commit is contained in:
parent
49f8fe8c5c
commit
f82726d7ef
@ -34,11 +34,11 @@ class BaseDecoderTest {
|
||||
|
||||
bool Open (const char* fileName);
|
||||
bool DecodeNextFrame (Callback* cbk);
|
||||
ISVCDecoder* decoder_;
|
||||
|
||||
private:
|
||||
void DecodeFrame (const uint8_t* src, int sliceSize, Callback* cbk);
|
||||
|
||||
ISVCDecoder* decoder_;
|
||||
std::ifstream file_;
|
||||
BufferedData buf_;
|
||||
enum {
|
||||
|
131
test/api/encode_decode_api_test.cpp
Normal file
131
test/api/encode_decode_api_test.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "codec_def.h"
|
||||
#include "utils/BufferedData.h"
|
||||
#include "utils/FileInputStream.h"
|
||||
#include "BaseDecoderTest.h"
|
||||
#include "BaseEncoderTest.h"
|
||||
#include <string>
|
||||
|
||||
struct EncodeDecodeFileParamBase {
|
||||
const char* fileName;
|
||||
int width;
|
||||
int height;
|
||||
float frameRate;
|
||||
};
|
||||
|
||||
class EncodeDecodeTestBase : public ::testing::Test,
|
||||
public BaseEncoderTest, public BaseDecoderTest {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
BaseEncoderTest::SetUp();
|
||||
BaseDecoderTest::SetUp();
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
BaseEncoderTest::TearDown();
|
||||
BaseDecoderTest::TearDown();
|
||||
}
|
||||
|
||||
virtual void prepareParam (int width, int height, float framerate) {
|
||||
memset (¶m_, 0, sizeof (SEncParamExt));
|
||||
param_.iUsageType = CAMERA_VIDEO_REAL_TIME;
|
||||
param_.iPicWidth = width;
|
||||
param_.iPicHeight = height;
|
||||
param_.fMaxFrameRate = framerate;
|
||||
param_.iRCMode = RC_OFF_MODE; //rc off
|
||||
param_.iMultipleThreadIdc = 1; //single thread
|
||||
param_.sSpatialLayers[0].iVideoWidth = width;
|
||||
param_.sSpatialLayers[0].iVideoHeight = height;
|
||||
param_.sSpatialLayers[0].fFrameRate = framerate;
|
||||
param_.sSpatialLayers[0].sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
|
||||
}
|
||||
|
||||
virtual void encToDecData (const SFrameBSInfo& info, int& len) {
|
||||
len = 0;
|
||||
for (int i = 0; i < info.iLayerNum; ++i) {
|
||||
const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
|
||||
for (int j = 0; j < layerInfo.iNalCount; ++j) {
|
||||
len += layerInfo.pNalLengthInByte[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
SEncParamExt param_;
|
||||
BufferedData buf_;
|
||||
SBufferInfo dstBufInfo_;
|
||||
};
|
||||
|
||||
class EncodeDecodeTestVclNal : public EncodeDecodeTestBase {
|
||||
public:
|
||||
void SetUp() {
|
||||
EncodeDecodeTestBase::SetUp();
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
EncodeDecodeTestBase::TearDown();
|
||||
}
|
||||
|
||||
void prepareParam (int width, int height, float framerate) {
|
||||
EncodeDecodeTestBase::prepareParam (width, height, framerate);
|
||||
}
|
||||
};
|
||||
|
||||
static const EncodeDecodeFileParamBase kFileParamArray =
|
||||
{"res/CiscoVT2people_160x96_6fps.yuv", 160, 96, 6.0f};
|
||||
|
||||
TEST_F (EncodeDecodeTestVclNal, DecoderVclNal) {
|
||||
EncodeDecodeFileParamBase p = kFileParamArray;
|
||||
FileInputStream fileStream;
|
||||
#if defined(ANDROID_NDK)
|
||||
std::string filename = std::string ("/sdcard/") + p.fileName;
|
||||
ASSERT_TRUE (fileStream.Open (filename.c_str()));
|
||||
#else
|
||||
ASSERT_TRUE (fileStream.Open (p.fileName));
|
||||
#endif
|
||||
|
||||
prepareParam (p.width, p.height, p.frameRate);
|
||||
int rv = encoder_->InitializeExt (¶m_);
|
||||
ASSERT_TRUE (rv == cmResultSuccess);
|
||||
|
||||
//init for encoder
|
||||
// I420: 1(Y) + 1/4(U) + 1/4(V)
|
||||
int frameSize = p.width * p.height * 3 / 2;
|
||||
|
||||
buf_.SetLength (frameSize);
|
||||
ASSERT_TRUE (buf_.Length() == (size_t)frameSize);
|
||||
|
||||
SFrameBSInfo info;
|
||||
memset (&info, 0, sizeof (SFrameBSInfo));
|
||||
|
||||
SSourcePicture pic;
|
||||
memset (&pic, 0, sizeof (SSourcePicture));
|
||||
pic.iPicWidth = p.width;
|
||||
pic.iPicHeight = p.height;
|
||||
pic.iColorFormat = videoFormatI420;
|
||||
pic.iStride[0] = pic.iPicWidth;
|
||||
pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
|
||||
pic.pData[0] = buf_.data();
|
||||
pic.pData[1] = pic.pData[0] + p.width * p.height;
|
||||
pic.pData[2] = pic.pData[1] + (p.width * p.height >> 2);
|
||||
while (fileStream.read (buf_.data(), frameSize) == frameSize) {
|
||||
rv = encoder_->EncodeFrame (&pic, &info);
|
||||
ASSERT_TRUE (rv == cmResultSuccess);
|
||||
//decoding after each encoding frame
|
||||
int vclNal, len = 0;
|
||||
encToDecData (info, len);
|
||||
unsigned char* pData[3] = { NULL };
|
||||
memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
|
||||
rv = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
|
||||
ASSERT_TRUE (rv == cmResultSuccess);
|
||||
rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
|
||||
EXPECT_EQ (vclNal, FEEDBACK_UNKNOWN_NAL); //no reconstruction, unknown return
|
||||
rv = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); //reconstruction
|
||||
ASSERT_TRUE (rv == cmResultSuccess);
|
||||
rv = decoder_->GetOption (DECODER_OPTION_VCL_NAL, &vclNal);
|
||||
EXPECT_EQ (vclNal, FEEDBACK_VCL_NAL);
|
||||
|
||||
} //while
|
||||
//ignore last frame
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ API_TEST_CPP_SRCS=\
|
||||
$(API_TEST_SRCDIR)/DataGenerator.cpp\
|
||||
$(API_TEST_SRCDIR)/decode_encode_test.cpp\
|
||||
$(API_TEST_SRCDIR)/decoder_test.cpp\
|
||||
$(API_TEST_SRCDIR)/encode_decode_api_test.cpp\
|
||||
$(API_TEST_SRCDIR)/encoder_test.cpp\
|
||||
$(API_TEST_SRCDIR)/simple_test.cpp\
|
||||
|
||||
|
@ -145,8 +145,10 @@ void DecoderInterfaceTest::TestInitUninit() {
|
||||
CM_RETURN eRet;
|
||||
//No initialize, no GetOption can be done
|
||||
m_pDec->Uninitialize();
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_DATAFORMAT, &iOutput);
|
||||
EXPECT_EQ (eRet, cmInitExpected);
|
||||
for (int i = 0; i <= (int) DECODER_OPTION_TRACE_CALLBACK_CONTEXT; ++i) {
|
||||
eRet = (CM_RETURN) m_pDec->GetOption ((DECODER_OPTION) i, &iOutput);
|
||||
EXPECT_EQ (eRet, cmInitExpected);
|
||||
}
|
||||
//Initialize first, can get input color format
|
||||
m_sDecParam.eOutputColorFormat = (EVideoFormatType) 20; //just for test
|
||||
m_pDec->Initialize (&m_sDecParam);
|
||||
@ -157,9 +159,11 @@ void DecoderInterfaceTest::TestInitUninit() {
|
||||
//Uninitialize, no GetOption can be done
|
||||
m_pDec->Uninitialize();
|
||||
iOutput = 21;
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_DATAFORMAT, &iOutput);
|
||||
EXPECT_EQ (iOutput, 21);
|
||||
EXPECT_EQ (eRet, cmInitExpected);
|
||||
for (int i = 0; i <= (int) DECODER_OPTION_TRACE_CALLBACK_CONTEXT; ++i) {
|
||||
eRet = (CM_RETURN) m_pDec->GetOption ((DECODER_OPTION) i, &iOutput);
|
||||
EXPECT_EQ (iOutput, 21);
|
||||
EXPECT_EQ (eRet, cmInitExpected);
|
||||
}
|
||||
}
|
||||
|
||||
//DECODER_OPTION_DATAFORMAT
|
||||
@ -168,6 +172,8 @@ void DecoderInterfaceTest::TestDataFormat() {
|
||||
int iOut;
|
||||
CM_RETURN eRet;
|
||||
|
||||
Init();
|
||||
|
||||
//invalid input
|
||||
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_DATAFORMAT, NULL);
|
||||
EXPECT_EQ (eRet, cmInitParaError);
|
||||
@ -179,6 +185,8 @@ void DecoderInterfaceTest::TestDataFormat() {
|
||||
EXPECT_EQ (eRet, cmResultSuccess);
|
||||
|
||||
EXPECT_EQ (iOut, (int32_t) videoFormatI420);
|
||||
|
||||
Uninit();
|
||||
}
|
||||
|
||||
//DECODER_OPTION_END_OF_STREAM
|
||||
@ -186,6 +194,8 @@ void DecoderInterfaceTest::TestEndOfStream() {
|
||||
int iTmp, iOut;
|
||||
CM_RETURN eRet;
|
||||
|
||||
Init();
|
||||
|
||||
//invalid input
|
||||
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, NULL);
|
||||
EXPECT_EQ (eRet, cmInitParaError);
|
||||
@ -234,12 +244,48 @@ void DecoderInterfaceTest::TestEndOfStream() {
|
||||
eRet = (CM_RETURN) m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_END_OF_STREAM, &iOut);
|
||||
EXPECT_EQ (iOut, true); //decoder should have EOS == true
|
||||
|
||||
Uninit();
|
||||
}
|
||||
|
||||
|
||||
//DECODER_OPTION_VCL_NAL
|
||||
//Here Test illegal bitstream input
|
||||
//legal bitstream decoding test, please see api test
|
||||
void DecoderInterfaceTest::TestVclNal() {
|
||||
//TODO
|
||||
int iTmp, iOut;
|
||||
CM_RETURN eRet;
|
||||
|
||||
Init();
|
||||
|
||||
//Test SetOption
|
||||
//VclNal never supports SetOption
|
||||
iTmp = rand();
|
||||
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_VCL_NAL, &iTmp);
|
||||
EXPECT_EQ (eRet, cmInitParaError);
|
||||
|
||||
//Test GetOption
|
||||
//invalid input
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, NULL);
|
||||
EXPECT_EQ (eRet, cmInitParaError);
|
||||
|
||||
//valid input without actual decoding
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, &iOut);
|
||||
EXPECT_EQ (eRet, cmResultSuccess);
|
||||
EXPECT_EQ (iOut, FEEDBACK_NON_VCL_NAL);
|
||||
|
||||
//valid input with decoding error
|
||||
MockPacketType (NAL_UNIT_CODED_SLICE_IDR, 50);
|
||||
m_pDec->DecodeFrame2 (m_szBuffer, m_iBufLength, m_pData, &m_sBufferInfo);
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, &iOut);
|
||||
EXPECT_EQ (eRet, cmResultSuccess);
|
||||
EXPECT_EQ (iOut, FEEDBACK_UNKNOWN_NAL);
|
||||
m_pDec->DecodeFrame2 (NULL, 0, m_pData, &m_sBufferInfo);
|
||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_VCL_NAL, &iOut);
|
||||
EXPECT_EQ (eRet, cmResultSuccess);
|
||||
EXPECT_EQ (iOut, FEEDBACK_UNKNOWN_NAL);
|
||||
|
||||
Uninit();
|
||||
}
|
||||
|
||||
//DECODER_OPTION_TEMPORAL_ID
|
||||
@ -293,9 +339,6 @@ TEST_F (DecoderInterfaceTest, DecoderInterfaceAll) {
|
||||
|
||||
//Initialize Uninitialize
|
||||
TestInitUninit();
|
||||
|
||||
//AfterInitialize is OK, do the following tests
|
||||
Init();
|
||||
//DECODER_OPTION_DATAFORMAT
|
||||
TestDataFormat();
|
||||
//DECODER_OPTION_END_OF_STREAM
|
||||
@ -320,9 +363,6 @@ TEST_F (DecoderInterfaceTest, DecoderInterfaceAll) {
|
||||
TestTraceCallback();
|
||||
//DECODER_OPTION_TRACE_CALLBACK_CONTEXT
|
||||
TestTraceCallbackContext();
|
||||
|
||||
//uninitialize
|
||||
Uninit();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user