1#include <gtest/gtest.h> 2#include "codec_def.h" 3#include "utils/BufferedData.h" 4#include "utils/FileInputStream.h" 5#include "BaseDecoderTest.h" 6#include "BaseEncoderTest.h" 7#include "wels_common_defs.h" 8#include "utils/HashFunctions.h" 9#include <string> 10#include <vector> 11#include "encode_decode_api_test.h" 12using namespace WelsCommon; 13 14 15TEST_F (EncodeDecodeTestAPI, LogEncoding) { 16#define DEBUG_FILE_SAVE 17 //FillInit 18 //int iSpatialLayerNum = $SPATIAL_NUM; 19 //int iWidth = $SOURCE_WIDTH; 20 //int iHeight = $SOURCE_HEIGHT; 21 //int iEncFrameNum = $TOTAL_FRMS; 22 23 //FillFirstParam 24 int iTraceLevel = WELS_LOG_INFO; 25 int rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel); 26 rv = encoder_->InitializeExt (¶m_); 27 EXPECT_TRUE (rv == cmResultSuccess); 28 29 unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM]; 30 int aLen[MAX_SPATIAL_LAYER_NUM] = {0}; 31 ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM]; 32 33#ifdef DEBUG_FILE_SAVE 34 FILE* fEnc[MAX_SPATIAL_LAYER_NUM]; 35 fEnc[0] = fopen ("enc0.264", "wb"); 36 fEnc[1] = fopen ("enc1.264", "wb"); 37 fEnc[2] = fopen ("enc2.264", "wb"); 38 fEnc[3] = fopen ("enc3.264", "wb"); 39#endif 40 41 int iIdx = 0; 42 43 //create decoder 44 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { 45 pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2)); 46 EXPECT_TRUE (pBsBuf[iIdx] != NULL); 47 aLen[iIdx] = 0; 48 49 long rv = WelsCreateDecoder (&decoder[iIdx]); 50 EXPECT_TRUE (0 == rv); 51 EXPECT_TRUE (decoder[iIdx] != NULL); 52 53 SDecodingParam decParam; 54 memset (&decParam, 0, sizeof (SDecodingParam)); 55 decParam.uiTargetDqLayer = UCHAR_MAX; 56 decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY; 57 decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; 58 59 rv = decoder[iIdx]->Initialize (&decParam); 60 EXPECT_TRUE (0 == rv); 61 } 62 63 64 for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) { 65 int iResult; 66 int iLayerLen = 0; 67 unsigned char* pData[3] = { NULL }; 68 69 if (iFrame % 10 == 0) { 70 printf("current iFrame=%d\n", iFrame); 71 } 72 73 //FillParam 74 75 ASSERT_TRUE (InitialEncDec (param_.iPicWidth, param_.iPicHeight)); 76 rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, ¶m_); 77 ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv; 78 EncodeOneFrame (0); 79 80 // init 81 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { 82 aLen[iIdx] = 0; 83 } 84 for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) { 85 iLayerLen = 0; 86 const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer]; 87 const int kiFirstNalType = ((* (layerInfo.pBsBuf + 4)) & 0x1f); 88 if (param_.bSimulcastAVC) { 89 ASSERT_TRUE ((kiFirstNalType == NAL_SPS) || (kiFirstNalType == NAL_PPS) || (kiFirstNalType == NAL_SLICE) 90 || (kiFirstNalType == NAL_SLICE_IDR) || (kiFirstNalType == NAL_SEI)); 91 } 92 for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) { 93 iLayerLen += layerInfo.pNalLengthInByte[iNal]; 94 } 95 96 if (param_.bSimulcastAVC) { 97 iIdx = layerInfo.uiSpatialId; 98 EXPECT_TRUE (iIdx < iSpatialLayerNum); 99 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); 100 aLen[iIdx] += iLayerLen; 101 } else { 102 if (layerInfo.uiLayerType == NON_VIDEO_CODING_LAYER) { 103 // under SimulcastSVC, need to copy non-VCL to all layers 104 for (iIdx = 0; iIdx < param_.iSpatialLayerNum; iIdx++) { 105 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); 106 aLen[iIdx] += iLayerLen; 107 } 108 } else { 109 iIdx = layerInfo.uiSpatialId; 110 EXPECT_TRUE (iIdx < iSpatialLayerNum); 111 memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); 112 aLen[iIdx] += iLayerLen; 113 } 114 } 115 } 116 117 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { 118 pData[0] = pData[1] = pData[2] = 0; 119 memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); 120 121 if (aLen[iIdx] > 0) { 122#ifdef DEBUG_FILE_SAVE 123 fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]); 124#endif 125 iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_); 126 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << " iFrame = " << iFrame << " LayerIdx=" << iIdx; 127 128 iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); 129 EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << " iFrame = " << iFrame << " LayerIdx=" << iIdx; 130 EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx << " LayerLen=" << aLen[iIdx] << " iFrame = " << iFrame; 131 } 132 } 133 } 134 135 136 for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { 137 free (pBsBuf[iIdx]); 138 139 if (decoder[iIdx] != NULL) { 140 decoder[iIdx]->Uninitialize(); 141 WelsDestroyDecoder (decoder[iIdx]); 142 } 143 } 144#ifdef DEBUG_FILE_SAVE 145 for (int i = 0; i < MAX_SPATIAL_LAYER_NUM; i++) { 146 fclose (fEnc[i]); 147 } 148#endif 149} 150