• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdlib.h>
2 #include "gtest/gtest.h"
3 
4 #include "au_set.h"
5 #include "param_svc.h"
6 #include "parameter_sets.h"
7 #include "wels_const.h"
8 #include "paraset_strategy.h"
9 
10 using namespace WelsEnc;
11 
12 class ParameterSetStrategyTest : public ::testing::Test {
13  public:
SetUp()14   virtual void SetUp() {
15     pMa = NULL;
16     m_pSpsArray = NULL;
17     m_pSubsetArray = NULL;
18 
19     pMa = new CMemoryAlign (0);
20     m_pSpsArray = (SWelsSPS*)pMa->WelsMalloc (MAX_SPS_COUNT * sizeof (SWelsSPS), "m_pSpsArray");
21     ASSERT_TRUE (NULL != m_pSpsArray);
22     m_pSubsetArray = (SSubsetSps*)pMa->WelsMalloc (MAX_SPS_COUNT * sizeof (SSubsetSps), "m_pSubsetArray");
23     ASSERT_TRUE (NULL != m_pSubsetArray);
24 
25     m_pSpsArrayPointer = &m_pSpsArray[0];
26     m_pSubsetArrayPointer = &m_pSubsetArray[0];
27 
28   }
TearDown()29   virtual void TearDown() {
30     pMa->WelsFree (m_pSpsArray, "m_pSpsArray");
31     pMa->WelsFree (m_pSubsetArray, "m_pSubsetArray");
32     delete pMa;
33   }
34   void GenerateParam (SWelsSvcCodingParam* pParam);
35  public:
36   CMemoryAlign* pMa;
37   SWelsSPS*     m_pSpsArray;
38   SSubsetSps*   m_pSubsetArray;
39 
40   SWelsSPS*     m_pSpsArrayPointer;
41   SSubsetSps*   m_pSubsetArrayPointer;
42 
43 };
44 
GenerateParam(SWelsSvcCodingParam * pParam)45 void ParameterSetStrategyTest::GenerateParam (SWelsSvcCodingParam* pParam) {
46   SEncParamBase sEncParamBase;
47   //TODO: consider randomize it
48   sEncParamBase.iUsageType = CAMERA_VIDEO_REAL_TIME;
49   sEncParamBase.iPicWidth = 1280;
50   sEncParamBase.iPicHeight = 720;
51   sEncParamBase.iTargetBitrate = 1000000;
52   sEncParamBase.iRCMode = RC_BITRATE_MODE;
53   sEncParamBase.fMaxFrameRate = 30.0f;
54   pParam->ParamBaseTranscode (sEncParamBase);
55 }
56 
TEST_F(ParameterSetStrategyTest,FindExistingSps)57 TEST_F (ParameterSetStrategyTest, FindExistingSps) {
58   int iDlayerIndex = 0;
59   int iDlayerCount = 0;
60   bool bUseSubsetSps = false;
61   int iFoundId = -1;
62   int iRet = 0;
63   SSpatialLayerConfig* pDlayerParam;
64 
65   //init parameter
66   SWelsSvcCodingParam sParam1;
67   GenerateParam (&sParam1);
68 
69   //prepare first SPS
70   int iCurSpsId = 0;
71   int iCurSpsInUse = 1;
72   m_pSpsArrayPointer = &m_pSpsArray[iCurSpsId];
73 
74   pDlayerParam = & (sParam1.sSpatialLayers[iDlayerIndex]);
75   iRet = WelsInitSps (m_pSpsArrayPointer, pDlayerParam, &sParam1.sDependencyLayers[iDlayerIndex], sParam1.uiIntraPeriod,
76                       sParam1.iMaxNumRefFrame,
77                       iCurSpsId, sParam1.bEnableFrameCroppingFlag, sParam1.iRCMode != RC_OFF_MODE, iDlayerCount, false);
78 
79   // try finding #0
80   iFoundId = FindExistingSps (&sParam1, bUseSubsetSps, iDlayerIndex, iDlayerCount, iCurSpsInUse,
81                               m_pSpsArray, m_pSubsetArray, false);
82   EXPECT_EQ (iFoundId, iCurSpsId);
83 
84   // try not finding
85   SWelsSvcCodingParam sParam2 = sParam1;
86   sParam2.iMaxNumRefFrame ++;
87   iFoundId = FindExistingSps (&sParam2, bUseSubsetSps, iDlayerIndex, iDlayerCount, iCurSpsInUse,
88                               m_pSpsArray, m_pSubsetArray, false);
89   EXPECT_EQ (iFoundId, INVALID_ID);
90 
91   // add new sps
92   iCurSpsId = 1;
93   m_pSpsArrayPointer = &m_pSpsArray[iCurSpsId];
94   pDlayerParam = & (sParam2.sSpatialLayers[iDlayerIndex]);
95   iRet = WelsInitSps (m_pSpsArrayPointer, pDlayerParam, &sParam2.sDependencyLayers[iDlayerIndex], sParam2.uiIntraPeriod,
96                       sParam2.iMaxNumRefFrame,
97                       iCurSpsId, sParam2.bEnableFrameCroppingFlag, sParam2.iRCMode != RC_OFF_MODE, iDlayerCount, false);
98   iCurSpsInUse = 2;
99 
100   // try finding #1
101   iFoundId = FindExistingSps (&sParam2, bUseSubsetSps, iDlayerIndex, iDlayerCount, iCurSpsInUse,
102                               m_pSpsArray, m_pSubsetArray, false);
103   EXPECT_EQ (iFoundId, iCurSpsId);
104 
105   // try finding #0
106   iFoundId = FindExistingSps (&sParam1, bUseSubsetSps, iDlayerIndex, iDlayerCount, iCurSpsInUse,
107                               m_pSpsArray, m_pSubsetArray, false);
108   EXPECT_EQ (iFoundId, 0);
109 
110   // try not finding
111   if (sParam2.sDependencyLayers[0].iActualWidth > 1) {
112 
113     sParam2.sDependencyLayers[0].iActualWidth--;
114   } else {
115     sParam2.sDependencyLayers[0].iActualWidth++;
116   }
117 
118   iFoundId = FindExistingSps (&sParam2, bUseSubsetSps, iDlayerIndex, iDlayerCount, iCurSpsInUse,
119                               m_pSpsArray, m_pSubsetArray, false);
120   EXPECT_EQ (iFoundId, INVALID_ID);
121   (void) iRet; // Not using iRet at the moment
122 }
123 
TEST_F(ParameterSetStrategyTest,TestVSTPParameters)124 TEST_F (ParameterSetStrategyTest, TestVSTPParameters) {
125   int32_t iRet = 0;
126   bool FalseLocal = false;	// EXPECT_EQ does not like "true" or "false" as its first arg
127 
128   // this test verifies that the client's "video signal type present" parameter values end up in SWelsSPS
129 
130   //init client parameters
131   SEncParamExt sParamExt;
132   SWelsSvcCodingParam::FillDefault(sParamExt);
133   sParamExt.iUsageType = CAMERA_VIDEO_REAL_TIME;
134   sParamExt.iPicWidth = 1280;
135   sParamExt.iPicHeight = 720;
136   sParamExt.iTargetBitrate = 1000000;
137   sParamExt.iRCMode = RC_BITRATE_MODE;
138   sParamExt.fMaxFrameRate = 30.0f;
139 
140   // VSTP parameters should be their default values (see SWelsSvcCodingParam::FillDefault())
141   for  ( int i = 0; i < MAX_SPATIAL_LAYER_NUM; i++ )
142   {
143     //         expected    actual
144     EXPECT_EQ( FalseLocal, sParamExt.sSpatialLayers[i].bVideoSignalTypePresent);
145     EXPECT_EQ( VF_UNDEF,   sParamExt.sSpatialLayers[i].uiVideoFormat);//5
146     EXPECT_EQ( FalseLocal, sParamExt.sSpatialLayers[i].bFullRange);
147     EXPECT_EQ( FalseLocal, sParamExt.sSpatialLayers[i].bColorDescriptionPresent);
148     EXPECT_EQ( CP_UNDEF,   sParamExt.sSpatialLayers[i].uiColorPrimaries);//2
149     EXPECT_EQ( TRC_UNDEF,  sParamExt.sSpatialLayers[i].uiTransferCharacteristics);//2
150     EXPECT_EQ( CM_UNDEF,   sParamExt.sSpatialLayers[i].uiColorMatrix);//2
151   }
152 
153   // set non-default VSTP values
154   sParamExt.iSpatialLayerNum = 2;
155 
156   sParamExt.sSpatialLayers[0].bVideoSignalTypePresent   = true;
157   sParamExt.sSpatialLayers[0].uiVideoFormat             = VF_NTSC;//2
158   sParamExt.sSpatialLayers[0].bFullRange                = true;
159   sParamExt.sSpatialLayers[0].bColorDescriptionPresent  = true;
160   sParamExt.sSpatialLayers[0].uiColorPrimaries          = CP_BT709;//1
161   sParamExt.sSpatialLayers[0].uiTransferCharacteristics = TRC_BT709;//1
162   sParamExt.sSpatialLayers[0].uiColorMatrix             = CM_BT709;//1
163 
164   sParamExt.sSpatialLayers[1].bVideoSignalTypePresent   = true;
165   sParamExt.sSpatialLayers[1].uiVideoFormat             = VF_PAL;//1
166   sParamExt.sSpatialLayers[1].bFullRange                = true;
167   sParamExt.sSpatialLayers[1].bColorDescriptionPresent  = true;
168   sParamExt.sSpatialLayers[1].uiColorPrimaries          = CP_SMPTE170M;//6
169   sParamExt.sSpatialLayers[1].uiTransferCharacteristics = TRC_SMPTE170M;//6
170   sParamExt.sSpatialLayers[1].uiColorMatrix             = CM_SMPTE170M;//6
171 
172   // transcode parameters from client
173   SWelsSvcCodingParam sSvcCodingParam;
174   iRet = sSvcCodingParam.ParamTranscode(sParamExt);
175   EXPECT_EQ (iRet, 0);
176 
177   // transcoded VSTP parameters should match the client values
178   for  ( int i = 0; i < sParamExt.iSpatialLayerNum; i++ )
179   {
180     EXPECT_EQ( sParamExt.sSpatialLayers[i].bVideoSignalTypePresent,   sSvcCodingParam.sSpatialLayers[i].bVideoSignalTypePresent);
181     EXPECT_EQ( sParamExt.sSpatialLayers[i].uiVideoFormat,             sSvcCodingParam.sSpatialLayers[i].uiVideoFormat);
182     EXPECT_EQ( sParamExt.sSpatialLayers[i].bFullRange,                sSvcCodingParam.sSpatialLayers[i].bFullRange);
183     EXPECT_EQ( sParamExt.sSpatialLayers[i].bColorDescriptionPresent,  sSvcCodingParam.sSpatialLayers[i].bColorDescriptionPresent);
184     EXPECT_EQ( sParamExt.sSpatialLayers[i].uiColorPrimaries,          sSvcCodingParam.sSpatialLayers[i].uiColorPrimaries);
185     EXPECT_EQ( sParamExt.sSpatialLayers[i].uiTransferCharacteristics, sSvcCodingParam.sSpatialLayers[i].uiTransferCharacteristics);
186     EXPECT_EQ( sParamExt.sSpatialLayers[i].uiColorMatrix,             sSvcCodingParam.sSpatialLayers[i].uiColorMatrix);
187   }
188 
189   // use transcoded parameters to initialize an SWelsSPS
190   m_pSpsArrayPointer = &m_pSpsArray[0];
191   SSpatialLayerConfig* pDlayerParam = &(sSvcCodingParam.sSpatialLayers[0]);
192   iRet = WelsInitSps (
193     m_pSpsArrayPointer,
194     pDlayerParam,
195     &sSvcCodingParam.sDependencyLayers[0],
196     sSvcCodingParam.uiIntraPeriod,
197     sSvcCodingParam.iMaxNumRefFrame,
198     0, //SpsId
199     sSvcCodingParam.bEnableFrameCroppingFlag,
200     sSvcCodingParam.iRCMode != RC_OFF_MODE,
201     0, //DlayerCount
202     false
203     );
204   EXPECT_EQ (iRet, 0);
205 
206   // SPS VSTP parameters should match the transcoded values
207   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].bVideoSignalTypePresent,   m_pSpsArrayPointer->bVideoSignalTypePresent);
208   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].uiVideoFormat,             m_pSpsArrayPointer->uiVideoFormat);
209   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].bFullRange,                m_pSpsArrayPointer->bFullRange);
210   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].bColorDescriptionPresent,  m_pSpsArrayPointer->bColorDescriptionPresent);
211   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].uiColorPrimaries,          m_pSpsArrayPointer->uiColorPrimaries);
212   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].uiTransferCharacteristics, m_pSpsArrayPointer->uiTransferCharacteristics);
213   EXPECT_EQ( sSvcCodingParam.sSpatialLayers[0].uiColorMatrix,             m_pSpsArrayPointer->uiColorMatrix);
214 
215   // TODO: verify that WriteVUI (au_set.cpp) writes the SPS VSTP values to the output file (verified using FFmpeg)
216 
217   (void) iRet; // Not using iRet at the moment
218 }
219 
220 
221