History

add UT for LTR setopton and fix crash issue

ruil2 committed 12 years ago

Commit 7e8cde01 parent cef43e34 files · +125 −56Browse files

Unified · Split

4 files
  1. codec/encoder/core/inc/extern.h +1 −1
  2. codec/encoder/core/src/encoder_ext.cpp +4 −4
  3. codec/encoder/plus/src/welsEncoderExt.cpp +51 −51
  4. test/encoder/EncUT_InterfaceTest.cpp +69 −0
codec/encoder/core/inc/extern.h+1−1
@@ -108,7 +108,7 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx); · 107 unmodified lines
108int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew);108int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew);
109void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);109void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);
110void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer);110void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer);
111void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx*pCtx,SLTRConfig* pLTRValue);111void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx** ppCtx, SLTRConfig* pLTRValue);
112int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);112int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);
113 113
114void FilterLTRMarkingFeedback (sWelsEncCtx* pCtx, SLTRMarkingFeedback* pLTRMarkingFeedback);114void FilterLTRMarkingFeedback (sWelsEncCtx* pCtx, SLTRMarkingFeedback* pLTRMarkingFeedback);
codec/encoder/core/src/encoder_ext.cpp+4−4
@@ -3825,10 +3825,10 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 3824 unmodified lines
3825 return 0;3825 return 0;
3826}3826}
3827 3827
3828void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx* pCtx, SLTRConfig* pLTRValue) {3828void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx** ppCtx, SLTRConfig* pLTRValue) {
3829 SWelsSvcCodingParam sConfig;3829 SWelsSvcCodingParam sConfig;
3830 int32_t iNumRefFrame = 1;3830 int32_t iNumRefFrame = 1;
3831 memcpy (&sConfig, pCtx->pSvcParam, sizeof (SWelsSvcCodingParam));3831 memcpy (&sConfig, (*ppCtx)->pSvcParam, sizeof (SWelsSvcCodingParam));
3832 sConfig.bEnableLongTermReference = pLTRValue->bEnableLongTermReference;3832 sConfig.bEnableLongTermReference = pLTRValue->bEnableLongTermReference;
3833 sConfig.iLTRRefNum = pLTRValue->iLTRRefNum;3833 sConfig.iLTRRefNum = pLTRValue->iLTRRefNum;
3834 int32_t uiGopSize = 1 << (sConfig.iTemporalLayerNum - 1);3834 int32_t uiGopSize = 1 << (sConfig.iTemporalLayerNum - 1);
@@ -3856,9 +3856,9 @@ void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx* pCtx, SLTRConfig* p · 21 unmodified lines
3856 if (sConfig.iNumRefFrame > sConfig.iMaxNumRefFrame)3856 if (sConfig.iNumRefFrame > sConfig.iMaxNumRefFrame)
3857 sConfig.iMaxNumRefFrame = sConfig.iNumRefFrame;3857 sConfig.iMaxNumRefFrame = sConfig.iNumRefFrame;
3858 3858
3859 WelsLog (pLogCtx, WELS_LOG_WARNING, " CWelsH264SVCEncoder::SetOption enable LTR = %d,ltrnum = %d",3859 WelsLog (pLogCtx, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption enable LTR = %d,ltrnum = %d",
3860 sConfig.bEnableLongTermReference, sConfig.iLTRRefNum);3860 sConfig.bEnableLongTermReference, sConfig.iLTRRefNum);
3861 WelsEncoderParamAdjust (&pCtx, &sConfig);3861 WelsEncoderParamAdjust (ppCtx, &sConfig);
3862}3862}
3863int32_t DynSliceRealloc (sWelsEncCtx* pCtx,3863int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
3864 SFrameBSInfo* pFrameBsInfo,3864 SFrameBSInfo* pFrameBsInfo,
codec/encoder/plus/src/welsEncoderExt.cpp+51−51
@@ -343,7 +343,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 342 unmodified lines
343 m_iMaxPicWidth = pCfg->iPicWidth;343 m_iMaxPicWidth = pCfg->iPicWidth;
344 m_iMaxPicHeight = pCfg->iPicHeight;344 m_iMaxPicHeight = pCfg->iPicHeight;
345 345
346 TraceParamInfo(pCfg);346 TraceParamInfo (pCfg);
347 if (WelsInitEncoderExt (&m_pEncContext, pCfg, &m_pWelsTrace->m_sLogCtx)) {347 if (WelsInitEncoderExt (&m_pEncContext, pCfg, &m_pWelsTrace->m_sLogCtx)) {
348 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.");348 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.");
349 Uninitialize();349 Uninitialize();
@@ -525,57 +525,57 @@ void CWelsH264SVCEncoder::CheckReferenceNumSetting (int32_t iNumRef) { · 175 unmodified lines
525 "doesn't support the number of reference frame(%d) change to auto select mode", iNumRef);525 "doesn't support the number of reference frame(%d) change to auto select mode", iNumRef);
526 }526 }
527}527}
528void CWelsH264SVCEncoder::TraceParamInfo(SEncParamExt *pParam){528void CWelsH264SVCEncoder::TraceParamInfo (SEncParamExt* pParam) {
529 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,529 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
530 "iUsageType = %d,iPicWidth= %d;iPicHeight= %d;iTargetBitrate= %d;iMaxBitrate= %d;iRCMode= %d;iPaddingFlag= %d;iTemporalLayerNum= %d;iSpatialLayerNum= %d;fFrameRate= %.6ff;uiIntraPeriod= %d;\530 "iUsageType = %d,iPicWidth= %d;iPicHeight= %d;iTargetBitrate= %d;iMaxBitrate= %d;iRCMode= %d;iPaddingFlag= %d;iTemporalLayerNum= %d;iSpatialLayerNum= %d;fFrameRate= %.6ff;uiIntraPeriod= %d;\
531 bEnableSpsPpsIdAddition = %d;bPrefixNalAddingCtrl = %d;bEnableDenoise= %d;bEnableBackgroundDetection= %d;bEnableAdaptiveQuant= %d;bEnableFrameSkip= %d;bEnableLongTermReference= %d;iLtrMarkPeriod= %d;\531 bEnableSpsPpsIdAddition = %d;bPrefixNalAddingCtrl = %d;bEnableDenoise= %d;bEnableBackgroundDetection= %d;bEnableAdaptiveQuant= %d;bEnableFrameSkip= %d;bEnableLongTermReference= %d;iLtrMarkPeriod= %d;\
532 iComplexityMode = %d;iNumRefFrame = %d;iEntropyCodingModeFlag = %d;uiMaxNalSize = %d;iLTRRefNum = %d;iMultipleThreadIdc = %d;iLoopFilterDisableIdc = %d",532 iComplexityMode = %d;iNumRefFrame = %d;iEntropyCodingModeFlag = %d;uiMaxNalSize = %d;iLTRRefNum = %d;iMultipleThreadIdc = %d;iLoopFilterDisableIdc = %d",
533 pParam->iUsageType,533 pParam->iUsageType,
534 pParam->iPicWidth,534 pParam->iPicWidth,
535 pParam->iPicHeight,535 pParam->iPicHeight,
536 pParam->iTargetBitrate,536 pParam->iTargetBitrate,
537 pParam->iMaxBitrate,537 pParam->iMaxBitrate,
538 pParam->iRCMode,538 pParam->iRCMode,
539 pParam->iPaddingFlag,539 pParam->iPaddingFlag,
540 pParam->iTemporalLayerNum,540 pParam->iTemporalLayerNum,
541 pParam->iSpatialLayerNum,541 pParam->iSpatialLayerNum,
542 pParam->fMaxFrameRate,542 pParam->fMaxFrameRate,
543 pParam->uiIntraPeriod,543 pParam->uiIntraPeriod,
544 pParam->bEnableSpsPpsIdAddition,544 pParam->bEnableSpsPpsIdAddition,
545 pParam->bPrefixNalAddingCtrl,545 pParam->bPrefixNalAddingCtrl,
546 pParam->bEnableDenoise,546 pParam->bEnableDenoise,
547 pParam->bEnableBackgroundDetection,547 pParam->bEnableBackgroundDetection,
548 pParam->bEnableAdaptiveQuant,548 pParam->bEnableAdaptiveQuant,
549 pParam->bEnableFrameSkip,549 pParam->bEnableFrameSkip,
550 pParam->bEnableLongTermReference,550 pParam->bEnableLongTermReference,
551 pParam->iLtrMarkPeriod,551 pParam->iLtrMarkPeriod,
552 pParam->iComplexityMode,552 pParam->iComplexityMode,
553 pParam->iNumRefFrame,553 pParam->iNumRefFrame,
554 pParam->iEntropyCodingModeFlag,554 pParam->iEntropyCodingModeFlag,
555 pParam->uiMaxNalSize,555 pParam->uiMaxNalSize,
556 pParam->iLTRRefNum,556 pParam->iLTRRefNum,
557 pParam->iMultipleThreadIdc,557 pParam->iMultipleThreadIdc,
558 pParam->iLoopFilterDisableIdc558 pParam->iLoopFilterDisableIdc
559 );559 );
560 int32_t i = 0;560 int32_t i = 0;
561 while (i < pParam->iSpatialLayerNum) {561 while (i < pParam->iSpatialLayerNum) {
562 SSpatialLayerConfig* pSpatialCfg = &pParam->sSpatialLayers[i];562 SSpatialLayerConfig* pSpatialCfg = &pParam->sSpatialLayers[i];
563 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,563 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
564 "sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .iMaxSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.iSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\564 "sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .iMaxSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.iSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\
565 uiProfileIdc = %d;uiLevelIdc = %d",565 uiProfileIdc = %d;uiLevelIdc = %d",
566 i, pSpatialCfg->iVideoWidth,566 i, pSpatialCfg->iVideoWidth,
567 pSpatialCfg->iVideoHeight,567 pSpatialCfg->iVideoHeight,
568 pSpatialCfg->fFrameRate,568 pSpatialCfg->fFrameRate,
569 pSpatialCfg->iSpatialBitrate,569 pSpatialCfg->iSpatialBitrate,
570 pSpatialCfg->iMaxSpatialBitrate,570 pSpatialCfg->iMaxSpatialBitrate,
571 pSpatialCfg->sSliceCfg.uiSliceMode,571 pSpatialCfg->sSliceCfg.uiSliceMode,
572 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceNum,572 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceNum,
573 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint,573 pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint,
574 pSpatialCfg->uiProfileIdc,574 pSpatialCfg->uiProfileIdc,
575 pSpatialCfg->uiLevelIdc575 pSpatialCfg->uiLevelIdc
576 );576 );
577 ++ i;577 ++ i;
578 }578 }
579}579}
580/************************************************************************580/************************************************************************
581* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..581* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
@@ -642,7 +642,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 60 unmodified lines
642 int32_t iTargetHeight = 0;642 int32_t iTargetHeight = 0;
643 643
644 memcpy (&sEncodingParam, pOption, sizeof (SEncParamExt)); // confirmed_safe_unsafe_usage644 memcpy (&sEncodingParam, pOption, sizeof (SEncParamExt)); // confirmed_safe_unsafe_usage
645 TraceParamInfo(&sEncodingParam);645 TraceParamInfo (&sEncodingParam);
646#ifdef OUTPUT_BIT_STREAM646#ifdef OUTPUT_BIT_STREAM
647 if (sEncodingParam.sSpatialLayers[sEncodingParam.iSpatialLayerNum - 1].iVideoWidth !=647 if (sEncodingParam.sSpatialLayers[sEncodingParam.iSpatialLayerNum - 1].iVideoWidth !=
648 m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iSpatialLayerNum - 1].iActualWidth) {648 m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iSpatialLayerNum - 1].iActualWidth) {
@@ -808,7 +808,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 159 unmodified lines
808 break;808 break;
809 case ENCODER_OPTION_LTR: {809 case ENCODER_OPTION_LTR: {
810 SLTRConfig* pLTRValue = ((SLTRConfig*) (pOption));810 SLTRConfig* pLTRValue = ((SLTRConfig*) (pOption));
811 WelsEncoderApplyLTR (&m_pWelsTrace->m_sLogCtx, m_pEncContext, pLTRValue);811 WelsEncoderApplyLTR (&m_pWelsTrace->m_sLogCtx, &m_pEncContext, pLTRValue);
812 }812 }
813 break;813 break;
814 case ENCODER_OPTION_ENABLE_SSEI: {814 case ENCODER_OPTION_ENABLE_SSEI: {
test/encoder/EncUT_InterfaceTest.cpp+69−0
@@ -1,6 +1,8 @@
1#include <gtest/gtest.h>1#include <gtest/gtest.h>
2#include "codec_def.h"2#include "codec_def.h"
3#include "codec_api.h"3#include "codec_api.h"
4#include "utils/BufferedData.h"
5#include "utils/FileInputStream.h"
4#include "BaseEncoderTest.h"6#include "BaseEncoderTest.h"
5 7
6class EncInterfaceCallTest : public ::testing::Test, public BaseEncoderTest {8class EncInterfaceCallTest : public ::testing::Test, public BaseEncoderTest {
@@ -12,6 +14,9 @@ class EncInterfaceCallTest : public ::testing::Test, public BaseEncoderTest { · 5 unmodified lines
12 BaseEncoderTest::TearDown();14 BaseEncoderTest::TearDown();
13 };15 };
14 16
17 virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
18 //nothing
19 }
15 //testing case20 //testing case
16 21
17};22};
@@ -34,3 +39,67 @@ TEST_F (EncInterfaceCallTest, BaseParameterVerify) { · 16 unmodified lines
34 uiTraceLevel = WELS_LOG_ERROR;39 uiTraceLevel = WELS_LOG_ERROR;
35 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel);40 encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel);
36}41}
42
43void outputData() {
44
45}
46
47TEST_F (EncInterfaceCallTest, SetOptionLTR) {
48
49 int iTotalFrameNum = 100;
50 int iFrameNum = 0;
51 int frameSize = 0;
52 int ret = cmResultSuccess;
53 int width = 320;
54 int height = 192;
55
56
57 SEncParamBase baseparam;
58 memset (&baseparam, 0, sizeof (SEncParamBase));
59
60 baseparam.iUsageType = CAMERA_VIDEO_REAL_TIME;
61 baseparam.fMaxFrameRate = 12;
62 baseparam.iPicWidth = width;
63 baseparam.iPicHeight = height;
64 baseparam.iTargetBitrate = 5000000;
65 encoder_->Initialize (&baseparam);
66
67 frameSize = width * height * 3 / 2;
68
69 BufferedData buf;
70 buf.SetLength (frameSize);
71 ASSERT_TRUE (buf.Length() == (size_t)frameSize);
72
73 SFrameBSInfo info;
74 memset (&info, 0, sizeof (SFrameBSInfo));
75
76 SSourcePicture pic;
77 memset (&pic, 0, sizeof (SSourcePicture));
78 pic.iPicWidth = width;
79 pic.iPicHeight = height;
80 pic.iColorFormat = videoFormatI420;
81 pic.iStride[0] = pic.iPicWidth;
82 pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
83 pic.pData[0] = buf.data();
84 pic.pData[1] = pic.pData[0] + width * height;
85 pic.pData[2] = pic.pData[1] + (width * height >> 2);
86
87 SLTRConfig config;
88 config.bEnableLongTermReference = true;
89 config.iLTRRefNum = rand() % 4;
90 encoder_->SetOption (ENCODER_OPTION_LTR, &config);
91 do {
92 FileInputStream fileStream;
93 ASSERT_TRUE (fileStream.Open ("res/CiscoVT2people_320x192_12fps.yuv"));
94
95 while (fileStream.read (buf.data(), frameSize) == frameSize) {
96 ret = encoder_->EncodeFrame (&pic, &info);
97 ASSERT_TRUE (ret == cmResultSuccess);
98 if (info.eFrameType != videoFrameTypeSkip && this != NULL) {
99 this->onEncodeFrame (info);
100 iFrameNum++;
101 }
102 }
103 } while (iFrameNum < iTotalFrameNum);
104
105}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t