shithub: openh264

Download patch

ref: f82726d7ef09ce43997acd8e65e75e35153d73d3
parent: 49f8fe8c5c55766e6445b922855e9adbefa6fe8a
author: huili2 <huili2@cisco.com>
date: Tue Aug 12 14:31:41 EDT 2014

enable api test for decoder VclNal

--- a/test/BaseDecoderTest.h
+++ b/test/BaseDecoderTest.h
@@ -34,11 +34,11 @@
 
   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 {
--- /dev/null
+++ b/test/api/encode_decode_api_test.cpp
@@ -1,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 (&param_, 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 (&param_);
+  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
+}
+
--- a/test/api/targets.mk
+++ b/test/api/targets.mk
@@ -6,6 +6,7 @@
 	$(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\
 
--- a/test/decoder/DecUT_DecExt.cpp
+++ b/test/decoder/DecUT_DecExt.cpp
@@ -145,8 +145,10 @@
   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 @@
   //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 @@
   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 @@
   EXPECT_EQ (eRet, cmResultSuccess);
 
   EXPECT_EQ (iOut, (int32_t) videoFormatI420);
+
+  Uninit();
 }
 
 //DECODER_OPTION_END_OF_STREAM
@@ -186,6 +194,8 @@
   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 @@
   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 @@
 
   //Initialize Uninitialize
   TestInitUninit();
-
-  //AfterInitialize is OK, do the following tests
-  Init();
   //DECODER_OPTION_DATAFORMAT
   TestDataFormat();
   //DECODER_OPTION_END_OF_STREAM
@@ -320,9 +363,6 @@
   TestTraceCallback();
   //DECODER_OPTION_TRACE_CALLBACK_CONTEXT
   TestTraceCallbackContext();
-
-  //uninitialize
-  Uninit();
 }