File: encode_decode_api_test.template

package info (click to toggle)
openh264 2.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,120 kB
  • sloc: cpp: 74,004; asm: 34,842; ansic: 23,866; sh: 2,540; python: 937; objc: 612; cs: 471; makefile: 354; java: 319; xml: 204; javascript: 17
file content (149 lines) | stat: -rw-r--r-- 5,044 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <gtest/gtest.h>
#include "codec_def.h"
#include "utils/BufferedData.h"
#include "utils/FileInputStream.h"
#include "BaseDecoderTest.h"
#include "BaseEncoderTest.h"
#include "wels_common_defs.h"
#include "utils/HashFunctions.h"
#include <string>
#include <vector>
#include "encode_decode_api_test.h"
using namespace WelsCommon;


TEST_F (EncodeDecodeTestAPI, LogEncoding) {
#define DEBUG_FILE_SAVE
  //FillInit
  //int iSpatialLayerNum = $SPATIAL_NUM;
  //int iWidth       = $SOURCE_WIDTH;
  //int iHeight      = $SOURCE_HEIGHT;
  //int iEncFrameNum = $TOTAL_FRMS;

  //FillFirstParam
  int iTraceLevel = WELS_LOG_INFO;
  int rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
  rv = encoder_->InitializeExt (&param_);
  EXPECT_TRUE (rv == cmResultSuccess);

  unsigned char*  pBsBuf[MAX_SPATIAL_LAYER_NUM];
  int aLen[MAX_SPATIAL_LAYER_NUM] = {0};
  ISVCDecoder* decoder[MAX_SPATIAL_LAYER_NUM];

#ifdef DEBUG_FILE_SAVE
  FILE* fEnc[MAX_SPATIAL_LAYER_NUM];
  fEnc[0] = fopen ("enc0.264", "wb");
  fEnc[1] = fopen ("enc1.264", "wb");
  fEnc[2] = fopen ("enc2.264", "wb");
  fEnc[3] = fopen ("enc3.264", "wb");
#endif

  int iIdx = 0;

  //create decoder
  for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
    pBsBuf[iIdx] = static_cast<unsigned char*> (malloc (iWidth * iHeight * 3 * sizeof (unsigned char) / 2));
    EXPECT_TRUE (pBsBuf[iIdx] != NULL);
    aLen[iIdx] = 0;

    long rv = WelsCreateDecoder (&decoder[iIdx]);
    EXPECT_TRUE (0 == rv);
    EXPECT_TRUE (decoder[iIdx] != NULL);

    SDecodingParam decParam;
    memset (&decParam, 0, sizeof (SDecodingParam));
    decParam.uiTargetDqLayer = UCHAR_MAX;
    decParam.eEcActiveIdc = ERROR_CON_SLICE_COPY;
    decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;

    rv = decoder[iIdx]->Initialize (&decParam);
    EXPECT_TRUE (0 == rv);
  }


  for (int iFrame = 0; iFrame < iEncFrameNum; iFrame++) {
    int iResult;
    int iLayerLen = 0;
    unsigned char* pData[3] = { NULL };

	if (iFrame % 10 == 0) {
		printf("current iFrame=%d\n", iFrame);
	}

    //FillParam

    ASSERT_TRUE (InitialEncDec (param_.iPicWidth, param_.iPicHeight));
    rv = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_EXT, &param_);
    ASSERT_TRUE (rv == cmResultSuccess) << "SetOption Failed pParam: rv = " << rv;
    EncodeOneFrame (0);

    // init
    for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
      aLen[iIdx] = 0;
    }
    for (int iLayer = 0; iLayer < info.iLayerNum; ++iLayer) {
      iLayerLen = 0;
      const SLayerBSInfo& layerInfo = info.sLayerInfo[iLayer];
      const int kiFirstNalType = ((* (layerInfo.pBsBuf + 4)) & 0x1f);
      if (param_.bSimulcastAVC) {
        ASSERT_TRUE ((kiFirstNalType == NAL_SPS) || (kiFirstNalType == NAL_PPS) || (kiFirstNalType == NAL_SLICE)
                     || (kiFirstNalType == NAL_SLICE_IDR) || (kiFirstNalType == NAL_SEI));
      }
      for (int iNal = 0; iNal < layerInfo.iNalCount; ++iNal) {
        iLayerLen += layerInfo.pNalLengthInByte[iNal];
      }

      if (param_.bSimulcastAVC) {
        iIdx = layerInfo.uiSpatialId;
        EXPECT_TRUE (iIdx < iSpatialLayerNum);
        memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
        aLen[iIdx] += iLayerLen;
      } else {
        if (layerInfo.uiLayerType == NON_VIDEO_CODING_LAYER) {
          // under SimulcastSVC, need to copy non-VCL to all layers
          for (iIdx = 0; iIdx < param_.iSpatialLayerNum; iIdx++) {
            memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
            aLen[iIdx] += iLayerLen;
          }
        } else {
          iIdx = layerInfo.uiSpatialId;
          EXPECT_TRUE (iIdx < iSpatialLayerNum);
          memcpy ((pBsBuf[iIdx] + aLen[iIdx]), layerInfo.pBsBuf, iLayerLen * sizeof (unsigned char));
          aLen[iIdx] += iLayerLen;
        }
      }
    }

    for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
      pData[0] = pData[1] = pData[2] = 0;
      memset (&dstBufInfo_, 0, sizeof (SBufferInfo));

      if (aLen[iIdx] > 0) {
#ifdef DEBUG_FILE_SAVE
        fwrite (pBsBuf[iIdx], aLen[iIdx], 1, fEnc[iIdx]);
#endif
        iResult = decoder[iIdx]->DecodeFrame2 (pBsBuf[iIdx], aLen[iIdx], pData, &dstBufInfo_);
        EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << " iFrame = " << iFrame << " LayerIdx=" << iIdx;

        iResult = decoder[iIdx]->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
        EXPECT_TRUE (iResult == cmResultSuccess) << "iResult=" << iResult << " iFrame = " << iFrame << " LayerIdx=" << iIdx;
        EXPECT_EQ (dstBufInfo_.iBufferStatus, 1) << "LayerIdx=" << iIdx << " LayerLen=" << aLen[iIdx] << " iFrame = " << iFrame;
      }
    }
  }


  for (iIdx = 0; iIdx < iSpatialLayerNum; iIdx++) {
    free (pBsBuf[iIdx]);

    if (decoder[iIdx] != NULL) {
      decoder[iIdx]->Uninitialize();
      WelsDestroyDecoder (decoder[iIdx]);
    }
  }
#ifdef DEBUG_FILE_SAVE
  for (int i = 0; i < MAX_SPATIAL_LAYER_NUM; i++) {
    fclose (fEnc[i]);
  }
#endif
}