Showing the changes to test/encoder/EncUT_EncoderExt.cpp (1 of 2 files). Show all
Unified · Split
| @@ -1,64 +1,73 @@ | ||
| 1 | 1 | #include <gtest/gtest.h> |
| 2 | 2 | #include <stdlib.h> |
| 3 | 3 | #include "codec_api.h" |
| 4 | −#include "welsEncoderExt.h" | |
| 5 | − | |
| 6 | −using namespace WelsSVCEnc; | |
| 4 | +#include "codec_app_def.h" | |
| 5 | +//TODO: consider using BaseEncoderTest class from #include "../BaseEncoderTest.h" | |
| 7 | 6 | |
| 8 | 7 | class EncoderInterfaceTest : public ::testing::Test { |
| 8 | +#define MB_SIZE (16) | |
| 9 | +#define MAX_WIDTH (3840) | |
| 10 | +#define MAX_HEIGHT (2160) | |
| 9 | 11 | public: |
| 10 | 12 | virtual void SetUp() { |
| 11 | − pPtrEnc = new CWelsH264SVCEncoder(); | |
| 13 | + int rv = WelsCreateSVCEncoder (&pPtrEnc); | |
| 14 | + ASSERT_EQ (0, rv); | |
| 15 | + ASSERT_TRUE (pPtrEnc != NULL); | |
| 16 | + | |
| 12 | 17 | pParamExt = new SEncParamExt(); |
| 18 | + ASSERT_TRUE (pParamExt != NULL); | |
| 19 | + | |
| 13 | 20 | pSrcPic = new SSourcePicture; |
| 21 | + ASSERT_TRUE (pSrcPic != NULL); | |
| 22 | + | |
| 14 | 23 | pOption = new SEncParamExt(); |
| 15 | − pYUV = NULL; | |
| 24 | + ASSERT_TRUE (pOption != NULL); | |
| 16 | 25 | |
| 17 | − m_iWidth = 1280; | |
| 18 | − m_iHeight = 720; | |
| 26 | + pYUV = NULL; | |
| 27 | + m_iWidth = MAX_WIDTH; | |
| 28 | + m_iHeight = MAX_HEIGHT; | |
| 19 | 29 | m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; |
| 20 | − pYUV = new uint8_t [m_iPicResSize]; | |
| 30 | + pYUV = new unsigned char [m_iPicResSize]; | |
| 31 | + ASSERT_TRUE (pYUV != NULL); | |
| 21 | 32 | } |
| 22 | − void TemporalLayerSettingTest(); | |
| 33 | + | |
| 23 | 34 | virtual void TearDown() { |
| 24 | − delete pPtrEnc; | |
| 25 | 35 | delete pParamExt; |
| 26 | 36 | delete pOption; |
| 27 | 37 | delete pSrcPic; |
| 28 | 38 | delete []pYUV; |
| 39 | + if (pPtrEnc) { | |
| 40 | + WelsDestroySVCEncoder (pPtrEnc); | |
| 41 | + pPtrEnc = NULL; | |
| 42 | + } | |
| 29 | 43 | } |
| 44 | + | |
| 45 | + void TemporalLayerSettingTest(); | |
| 46 | + void EncodeOneFrame (SEncParamBase* pEncParamBase); | |
| 47 | + void PrepareOneSrcFrame(); | |
| 48 | + | |
| 30 | 49 | public: |
| 31 | − CWelsH264SVCEncoder* pPtrEnc; | |
| 50 | + ISVCEncoder* pPtrEnc; | |
| 51 | + | |
| 32 | 52 | SEncParamExt* pParamExt; |
| 33 | 53 | SSourcePicture* pSrcPic; |
| 34 | 54 | SEncParamExt* pOption; |
| 35 | − uint8_t* pYUV; | |
| 36 | − | |
| 37 | − int32_t m_iWidth; | |
| 38 | − int32_t m_iHeight; | |
| 39 | − int32_t m_iPicResSize; | |
| 40 | −}; | |
| 41 | − | |
| 42 | −void EncoderInterfaceTest::TemporalLayerSettingTest() { | |
| 55 | + unsigned char* pYUV; | |
| 43 | 56 | |
| 44 | − pParamExt->iPicWidth = m_iWidth; | |
| 45 | − pParamExt->iPicHeight = m_iHeight; | |
| 46 | − pParamExt->iTargetBitrate = 60000; | |
| 47 | − pParamExt->sSpatialLayers[0].iVideoHeight = pParamExt->iPicHeight; | |
| 48 | − pParamExt->sSpatialLayers[0].iVideoWidth = pParamExt->iPicWidth; | |
| 49 | − pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000; | |
| 50 | − pParamExt->iTemporalLayerNum = 1; | |
| 51 | − pParamExt->iSpatialLayerNum = 1; | |
| 57 | + SFrameBSInfo sFbi; | |
| 52 | 58 | |
| 53 | − int32_t iResult = pPtrEnc->InitializeExt (pParamExt); | |
| 54 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 59 | + int m_iWidth; | |
| 60 | + int m_iHeight; | |
| 61 | + int m_iPicResSize; | |
| 62 | +}; | |
| 55 | 63 | |
| 64 | +void EncoderInterfaceTest::PrepareOneSrcFrame() { | |
| 56 | 65 | pSrcPic->iColorFormat = videoFormatI420; |
| 57 | 66 | pSrcPic->uiTimeStamp = 0; |
| 58 | 67 | pSrcPic->iPicWidth = pParamExt->iPicWidth; |
| 59 | 68 | pSrcPic->iPicHeight = pParamExt->iPicHeight; |
| 60 | 69 | |
| 61 | − for (int32_t i = 0; i < m_iPicResSize; i++) | |
| 70 | + for (int i = 0; i < m_iPicResSize; i++) | |
| 62 | 71 | pYUV[i] = rand() % 256; |
| 63 | 72 | |
| 64 | 73 | pSrcPic->iStride[0] = m_iWidth; |
| @@ -68,45 +77,81 @@ void EncoderInterfaceTest::TemporalLayerSettingTest() { · 3 unmodified lines | ||
| 68 | 77 | pSrcPic->pData[1] = pSrcPic->pData[0] + (m_iWidth * m_iHeight); |
| 69 | 78 | pSrcPic->pData[2] = pSrcPic->pData[1] + (m_iWidth * m_iHeight >> 2); |
| 70 | 79 | |
| 71 | − SFrameBSInfo sFbi; | |
| 80 | + //clean the output | |
| 72 | 81 | memset (&sFbi, 0, sizeof (SFrameBSInfo)); |
| 82 | +} | |
| 73 | 83 | |
| 84 | +void EncoderInterfaceTest::EncodeOneFrame (SEncParamBase* pEncParamBase) { | |
| 85 | + int iResult; | |
| 86 | + | |
| 87 | + iResult = pPtrEnc->Initialize (pEncParamBase); | |
| 88 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 89 | + PrepareOneSrcFrame(); | |
| 74 | 90 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); |
| 75 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 76 | − EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeIDR)); | |
| 91 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 92 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR)); | |
| 93 | + | |
| 94 | + iResult = pPtrEnc->GetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, pEncParamBase); | |
| 95 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 96 | + | |
| 97 | + pPtrEnc->Uninitialize(); | |
| 98 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 99 | +} | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | +void EncoderInterfaceTest::TemporalLayerSettingTest() { | |
| 104 | + | |
| 105 | + pParamExt->iPicWidth = m_iWidth; | |
| 106 | + pParamExt->iPicHeight = m_iHeight; | |
| 107 | + pParamExt->iTargetBitrate = 60000; | |
| 108 | + pParamExt->sSpatialLayers[0].iVideoHeight = pParamExt->iPicHeight; | |
| 109 | + pParamExt->sSpatialLayers[0].iVideoWidth = pParamExt->iPicWidth; | |
| 110 | + pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000; | |
| 111 | + pParamExt->iTemporalLayerNum = 1; | |
| 112 | + pParamExt->iSpatialLayerNum = 1; | |
| 113 | + | |
| 114 | + int iResult = pPtrEnc->InitializeExt (pParamExt); | |
| 115 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 116 | + | |
| 117 | + PrepareOneSrcFrame(); | |
| 118 | + | |
| 119 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 120 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 121 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR)); | |
| 77 | 122 | |
| 78 | 123 | pSrcPic->uiTimeStamp = 30; |
| 79 | 124 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); |
| 80 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 81 | − EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeP)); | |
| 125 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 126 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP)); | |
| 82 | 127 | |
| 83 | 128 | memcpy (pOption, pParamExt, sizeof (SEncParamExt)); |
| 84 | 129 | pOption ->iTemporalLayerNum = 4; |
| 85 | 130 | |
| 86 | 131 | ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT; |
| 87 | 132 | iResult = pPtrEnc->SetOption (eOptionId, pOption); |
| 88 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 133 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 89 | 134 | |
| 90 | 135 | pSrcPic->uiTimeStamp = 60; |
| 91 | 136 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); |
| 92 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 93 | − EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeIDR)); | |
| 137 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 138 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR)); | |
| 94 | 139 | |
| 95 | 140 | pOption ->iTemporalLayerNum = 2; |
| 96 | 141 | iResult = pPtrEnc->SetOption (eOptionId, pOption); |
| 97 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 142 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 98 | 143 | pSrcPic->uiTimeStamp = 90; |
| 99 | 144 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); |
| 100 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 101 | − EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeP)); | |
| 145 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 146 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP)); | |
| 102 | 147 | |
| 103 | 148 | pOption ->iTemporalLayerNum = 4; |
| 104 | 149 | iResult = pPtrEnc->SetOption (eOptionId, pOption); |
| 105 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 150 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 106 | 151 | pSrcPic->uiTimeStamp = 120; |
| 107 | 152 | iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); |
| 108 | − EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 109 | − EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeP)); | |
| 153 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 154 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeP)); | |
| 110 | 155 | |
| 111 | 156 | pPtrEnc->Uninitialize(); |
| 112 | 157 | |
| @@ -115,3 +160,123 @@ void EncoderInterfaceTest::TemporalLayerSettingTest() { · 2 unmodified lines | ||
| 115 | 160 | TEST_F (EncoderInterfaceTest, TestTemporalLayerSetting) { |
| 116 | 161 | TemporalLayerSettingTest(); |
| 117 | 162 | } |
| 163 | + | |
| 164 | +void GetValidEncParamBase (SEncParamBase* pEncParamBase) { | |
| 165 | + pEncParamBase->iUsageType = CAMERA_VIDEO_REAL_TIME; | |
| 166 | + pEncParamBase->iPicWidth = abs ((rand() * 2) + MB_SIZE) % (MAX_WIDTH+1); | |
| 167 | + pEncParamBase->iPicHeight = abs ((rand() * 2) + MB_SIZE) % (MAX_HEIGHT+1); | |
| 168 | + pEncParamBase->iTargetBitrate = rand() + 1; //!=0 | |
| 169 | + pEncParamBase->iRCMode = RC_BITRATE_MODE; //-1, 0, 1, 2 | |
| 170 | + pEncParamBase->fMaxFrameRate = rand() + 0.5f; //!=0 | |
| 171 | +} | |
| 172 | + | |
| 173 | +TEST_F (EncoderInterfaceTest, BasicInitializeTest) { | |
| 174 | + SEncParamBase sEncParamBase; | |
| 175 | + GetValidEncParamBase (&sEncParamBase); | |
| 176 | + | |
| 177 | + int iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 178 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 179 | + if (iResult != cmResultSuccess) { | |
| 180 | + fprintf (stderr, "Unexpected ParamBase? \ | |
| 181 | + iUsageType=%d, Pic=%dx%d, TargetBitrate=%d, iRCMode=%d, fMaxFrameRate=%.1f\n", | |
| 182 | + sEncParamBase.iUsageType, sEncParamBase.iPicWidth, sEncParamBase.iPicHeight, | |
| 183 | + sEncParamBase.iTargetBitrate, sEncParamBase.iRCMode, sEncParamBase.fMaxFrameRate); | |
| 184 | + } | |
| 185 | + | |
| 186 | + PrepareOneSrcFrame(); | |
| 187 | + | |
| 188 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 189 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 190 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int> (videoFrameTypeIDR)); | |
| 191 | + | |
| 192 | + pPtrEnc->Uninitialize(); | |
| 193 | + EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess)); | |
| 194 | +} | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | +TEST_F (EncoderInterfaceTest, BasicInitializeTestFalse) { | |
| 199 | + int iResult; | |
| 200 | + SEncParamBase sEncParamBase; | |
| 201 | + | |
| 202 | + //iUsageType | |
| 203 | + GetValidEncParamBase (&sEncParamBase); | |
| 204 | + sEncParamBase.iUsageType = static_cast<EUsageType> (2); | |
| 205 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 206 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 207 | + | |
| 208 | + //iPicWidth | |
| 209 | + GetValidEncParamBase (&sEncParamBase); | |
| 210 | + sEncParamBase.iPicWidth = 0; | |
| 211 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 212 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 213 | + | |
| 214 | + GetValidEncParamBase (&sEncParamBase); | |
| 215 | + sEncParamBase.iPicWidth = -1; | |
| 216 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 217 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 218 | + | |
| 219 | + //TODO: add checking max in interface and then enable this checking | |
| 220 | + //GetValidEncParamBase(&sEncParamBase); | |
| 221 | + //sEncParamBase.iPicWidth = rand()+(MAX_WIDTH+1); | |
| 222 | + //iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 223 | + //EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 224 | + | |
| 225 | + //iPicHeight | |
| 226 | + GetValidEncParamBase (&sEncParamBase); | |
| 227 | + sEncParamBase.iPicHeight = 0; | |
| 228 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 229 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 230 | + | |
| 231 | + GetValidEncParamBase (&sEncParamBase); | |
| 232 | + sEncParamBase.iPicHeight = -1; | |
| 233 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 234 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 235 | + | |
| 236 | + //TODO: add checking max in interface and then enable this checking | |
| 237 | + //GetValidEncParamBase(&sEncParamBase); | |
| 238 | + //sEncParamBase.iPicWidth = rand()+(MAX_HEIGHT+1); | |
| 239 | + //iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 240 | + //EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 241 | + | |
| 242 | + //iTargetBitrate | |
| 243 | + GetValidEncParamBase (&sEncParamBase); | |
| 244 | + sEncParamBase.iTargetBitrate = 0; | |
| 245 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 246 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 247 | + GetValidEncParamBase (&sEncParamBase); | |
| 248 | + sEncParamBase.iTargetBitrate = -1; | |
| 249 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 250 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 251 | + | |
| 252 | + //iUsageType | |
| 253 | + GetValidEncParamBase (&sEncParamBase); | |
| 254 | + sEncParamBase.iRCMode = static_cast<RC_MODES> (3); | |
| 255 | + iResult = pPtrEnc->Initialize (&sEncParamBase); | |
| 256 | + EXPECT_EQ (iResult, static_cast<int> (cmInitParaError)); | |
| 257 | +} | |
| 258 | + | |
| 259 | +TEST_F (EncoderInterfaceTest, BasicInitializeTestAutoAdjustment) { | |
| 260 | + SEncParamBase sEncParamBase; | |
| 261 | + | |
| 262 | + // large fMaxFrameRate | |
| 263 | + GetValidEncParamBase (&sEncParamBase); | |
| 264 | + sEncParamBase.fMaxFrameRate = 50000; | |
| 265 | + EncodeOneFrame (&sEncParamBase); | |
| 266 | + EXPECT_LE (sEncParamBase.fMaxFrameRate, 30.0); | |
| 267 | + EXPECT_GE (sEncParamBase.fMaxFrameRate, 1.0); | |
| 268 | + | |
| 269 | + // fMaxFrameRate = 0 | |
| 270 | + GetValidEncParamBase (&sEncParamBase); | |
| 271 | + sEncParamBase.fMaxFrameRate = 0; | |
| 272 | + EncodeOneFrame (&sEncParamBase); | |
| 273 | + EXPECT_LE (sEncParamBase.fMaxFrameRate, 30.0); | |
| 274 | + EXPECT_GE (sEncParamBase.fMaxFrameRate, 1.0); | |
| 275 | + | |
| 276 | + // fMaxFrameRate = -1 | |
| 277 | + GetValidEncParamBase (&sEncParamBase); | |
| 278 | + sEncParamBase.fMaxFrameRate = -1; | |
| 279 | + EncodeOneFrame (&sEncParamBase); | |
| 280 | + EXPECT_LE (sEncParamBase.fMaxFrameRate, 30.0); | |
| 281 | + EXPECT_GE (sEncParamBase.fMaxFrameRate, 1.0); | |
| 282 | +} | |