Showing the changes to test/api/encode_decode_api_test.template (1 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,142 @@ | ||
| 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" | |
| 12 | +using namespace WelsCommon; | |
| 13 | + | |
| 14 | + | |
| 15 | +TEST_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 rv = encoder_->InitializeExt (¶m_); | |
| 25 | + ASSERT_TRUE (rv == cmResultSuccess); | |
| 26 | + | |
| 27 | + unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM]; | |
| 28 | + int aLen[MAX_SPATIAL_LAYER_NUM] = {0}; | |
| 29 | + ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM]; | |
| 30 | + | |
| 31 | +#ifdef DEBUG_FILE_SAVE | |
| 32 | + FILE* fEnc[MAX_SPATIAL_LAYER_NUM]; | |
| 33 | + fEnc[0] = fopen ("enc0.264", "wb"); | |
| 34 | + fEnc[1] = fopen ("enc1.264", "wb"); | |
| 35 | + fEnc[2] = fopen ("enc2.264", "wb"); | |
| 36 | + fEnc[3] = fopen ("enc3.264", "wb"); | |
| 37 | +#endif | |
| 38 | + | |
| 39 | + int iIdx = 0; | |
| 40 | + | |
| 41 | + //create decoder | |
| 42 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 43 | + pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2)); | |
| 44 | + EXPECT_TRUE (pBsBuf[iIdx] != NULL); | |
| 45 | + aLen[iIdx] = 0; | |
| 46 | + | |
| 47 | + long rv = WelsCreateDecoder (&decoder[iIdx]); | |
| 48 | + ASSERT_EQ (0, rv); | |
| 49 | + EXPECT_TRUE (decoder[iIdx] != NULL); | |
| 50 | + | |
| 51 | + SDecodingParam decParam; | |
| 52 | + memset (&decParam, 0, sizeof (SDecodingParam)); | |
| 53 | + decParam.eOutputColorFormat = videoFormatI420; | |
| 54 | + decParam.uiTargetDqLayer = UCHAR_MAX; | |
| 55 | + decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY; | |
| 56 | + decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; | |
| 57 | + | |
| 58 | + rv = decoder[iIdx]->Initialize (&decParam); | |
| 59 | + ASSERT_EQ (0, rv); | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) { | |
| 64 | + int iResult; | |
| 65 | + int iLayerLen = 0; | |
| 66 | + unsigned char* pData[3] = { NULL }; | |
| 67 | + | |
| 68 | + //FillParam | |
| 69 | + | |
| 70 | + InitialEncDec (param_.iPicWidth, param_.iPicHeight); | |
| 71 | + EncodeOneFrame (0); | |
| 72 | + | |
| 73 | + // init | |
| 74 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 75 | + aLen[iIdx] = 0; | |
| 76 | + } | |
| 77 | + for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) { | |
| 78 | + iLayerLen = 0; | |
| 79 | + const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer]; | |
| 80 | + const int kiFirstNalType = ((* (layerInfo.pBsBuf + 4)) & 0x1f); | |
| 81 | + if (param_.bSimulcastAVC) { | |
| 82 | + ASSERT_TRUE ((kiFirstNalType == NAL_SPS) || (kiFirstNalType == NAL_PPS) || (kiFirstNalType == NAL_SLICE) | |
| 83 | + || (kiFirstNalType == NAL_SLICE_IDR) || (kiFirstNalType == NAL_SEI)); | |
| 84 | + } | |
| 85 | + for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) { | |
| 86 | + iLayerLen += layerInfo.pNalLengthInByte[iNal]; | |
| 87 | + } | |
| 88 | + | |
| 89 | + if (param_.bSimulcastAVC) { | |
| 90 | + iIdx = layerInfo.uiSpatialId; | |
| 91 | + EXPECT_TRUE (iIdx < iSpatialLayerNum); | |
| 92 | + memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); | |
| 93 | + aLen[iIdx] += iLayerLen; | |
| 94 | + } else { | |
| 95 | + if (layerInfo.uiLayerType == NON_VIDEO_CODING_LAYER) { | |
| 96 | + // under SimulcastSVC, need to copy non-VCL to all layers | |
| 97 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 98 | + memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); | |
| 99 | + aLen[iIdx] += iLayerLen; | |
| 100 | + } | |
| 101 | + } else { | |
| 102 | + iIdx = layerInfo.uiSpatialId; | |
| 103 | + EXPECT_TRUE (iIdx < iSpatialLayerNum); | |
| 104 | + memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char)); | |
| 105 | + aLen[iIdx] += iLayerLen; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 111 | + pData[0] = pData[1] = pData[2] = 0; | |
| 112 | + memset (&dstBufInfo_, 0, sizeof (SBufferInfo)); | |
| 113 | + | |
| 114 | + if (aLen[iIdx] > 0) { | |
| 115 | +#ifdef DEBUG_FILE_SAVE | |
| 116 | + fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]); | |
| 117 | +#endif | |
| 118 | + iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_); | |
| 119 | + EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx; | |
| 120 | + | |
| 121 | + iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_); | |
| 122 | + EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << "LayerIdx=" << iIdx; | |
| 123 | + EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + | |
| 129 | + for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) { | |
| 130 | + free (pBsBuf[iIdx]); | |
| 131 | + | |
| 132 | + if (decoder[iIdx] != NULL) { | |
| 133 | + decoder[iIdx]->Uninitialize(); | |
| 134 | + WelsDestroyDecoder (decoder[iIdx]); | |
| 135 | + } | |
| 136 | + } | |
| 137 | +#ifdef DEBUG_FILE_SAVE | |
| 138 | + for (int i = 0; i < MAX_SPATIAL_LAYER_NUM; i++) { | |
| 139 | + fclose (fEnc[i]); | |
| 140 | + } | |
| 141 | +#endif | |
| 142 | +} | |