Showing the changes to test/encoder/EncUT_EncoderExt.cpp (1 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,118 @@ | ||
| 1 | +#include<gtest/gtest.h> | |
| 2 | +#include<stdlib.h> | |
| 3 | +#include "codec_api.h" | |
| 4 | +#include "welsEncoderExt.h" | |
| 5 | + | |
| 6 | +using namespace WelsSVCEnc; | |
| 7 | + | |
| 8 | +class EncoderInterfaceTest : public ::testing::Test { | |
| 9 | + public: | |
| 10 | + virtual void SetUp() { | |
| 11 | + pPtrEnc = new CWelsH264SVCEncoder(); | |
| 12 | + pParamExt = new SEncParamExt(); | |
| 13 | + pSrcPic = new SSourcePicture; | |
| 14 | + pOption = new SEncParamExt(); | |
| 15 | + pYUV = NULL; | |
| 16 | + | |
| 17 | + m_iWidth = 1280; | |
| 18 | + m_iHeight = 720; | |
| 19 | + m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1; | |
| 20 | + pYUV = new uint8_t [m_iPicResSize]; | |
| 21 | + } | |
| 22 | + void TemporalLayerSettingTest(); | |
| 23 | + virtual void TearDown() { | |
| 24 | + delete pPtrEnc; | |
| 25 | + delete pParamExt; | |
| 26 | + delete pOption; | |
| 27 | + delete pSrcPic; | |
| 28 | + delete []pYUV; | |
| 29 | + } | |
| 30 | + public: | |
| 31 | + CWelsH264SVCEncoder* pPtrEnc; | |
| 32 | + SEncParamExt* pParamExt; | |
| 33 | + SSourcePicture* pSrcPic; | |
| 34 | + 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() { | |
| 43 | + | |
| 44 | + pParamExt->iInputCsp = 23; | |
| 45 | + pParamExt->iPicWidth = m_iWidth; | |
| 46 | + pParamExt->iPicHeight = m_iHeight; | |
| 47 | + pParamExt->iTargetBitrate = 60000; | |
| 48 | + pParamExt->sSpatialLayers[0].iVideoHeight = pParamExt->iPicHeight; | |
| 49 | + pParamExt->sSpatialLayers[0].iVideoWidth = pParamExt->iPicWidth; | |
| 50 | + pParamExt->sSpatialLayers[0].iSpatialBitrate = 50000; | |
| 51 | + pParamExt->iTemporalLayerNum = 1; | |
| 52 | + pParamExt->iSpatialLayerNum = 1; | |
| 53 | + | |
| 54 | + int32_t iResult = pPtrEnc->InitializeExt (pParamExt); | |
| 55 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 56 | + | |
| 57 | + pSrcPic->iColorFormat = videoFormatI420; | |
| 58 | + pSrcPic->uiTimeStamp = 0; | |
| 59 | + pSrcPic->iPicWidth = pParamExt->iPicWidth; | |
| 60 | + pSrcPic->iPicHeight = pParamExt->iPicHeight; | |
| 61 | + | |
| 62 | + for (int32_t i = 0; i < m_iPicResSize; i++) | |
| 63 | + pYUV[i] = rand() % 256; | |
| 64 | + | |
| 65 | + pSrcPic->iStride[0] = m_iWidth; | |
| 66 | + pSrcPic->iStride[1] = pSrcPic->iStride[2] = pSrcPic->iStride[0] >> 1; | |
| 67 | + | |
| 68 | + pSrcPic->pData[0] = pYUV; | |
| 69 | + pSrcPic->pData[1] = pSrcPic->pData[0] + (m_iWidth * m_iHeight); | |
| 70 | + pSrcPic->pData[2] = pSrcPic->pData[1] + (m_iWidth * m_iHeight >> 2); | |
| 71 | + | |
| 72 | + SFrameBSInfo sFbi; | |
| 73 | + memset (&sFbi, 0, sizeof (SFrameBSInfo)); | |
| 74 | + | |
| 75 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 76 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 77 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeIDR)); | |
| 78 | + | |
| 79 | + pSrcPic->uiTimeStamp = 30; | |
| 80 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 81 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 82 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeP)); | |
| 83 | + | |
| 84 | + memcpy (pOption, pParamExt, sizeof (SEncParamExt)); | |
| 85 | + pOption ->iTemporalLayerNum = 4; | |
| 86 | + | |
| 87 | + ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT; | |
| 88 | + iResult = pPtrEnc->SetOption (eOptionId, pOption); | |
| 89 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 90 | + | |
| 91 | + pSrcPic->uiTimeStamp = 60; | |
| 92 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 93 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 94 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeIDR)); | |
| 95 | + | |
| 96 | + pOption ->iTemporalLayerNum = 2; | |
| 97 | + iResult = pPtrEnc->SetOption (eOptionId, pOption); | |
| 98 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 99 | + pSrcPic->uiTimeStamp = 90; | |
| 100 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 101 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 102 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeP)); | |
| 103 | + | |
| 104 | + pOption ->iTemporalLayerNum = 4; | |
| 105 | + iResult = pPtrEnc->SetOption (eOptionId, pOption); | |
| 106 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 107 | + pSrcPic->uiTimeStamp = 120; | |
| 108 | + iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi); | |
| 109 | + EXPECT_EQ (iResult, static_cast<int32_t> (cmResultSuccess)); | |
| 110 | + EXPECT_EQ (sFbi.eFrameType, static_cast<int32_t> (videoFrameTypeP)); | |
| 111 | + | |
| 112 | + pPtrEnc->Uninitialize(); | |
| 113 | + | |
| 114 | +} | |
| 115 | + | |
| 116 | +TEST_F (EncoderInterfaceTest, TestTemporalLayerSetting) { | |
| 117 | + TemporalLayerSettingTest(); | |
| 118 | +} | |