MCPcopy Create free account
hub / github.com/cisco/openh264 / SimulateNALLoss

Function SimulateNALLoss

test/api/encode_decode_api_test.cpp:316–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314}
315
316int SimulateNALLoss (const unsigned char* pSrc, int& iSrcLen, std::vector<SLostSim>* p_SLostSim,
317 const char* pLossChars, bool bLossPara, int& iLossIdx, bool& bVCLLoss) {
318 unsigned char* pDst = new unsigned char[iSrcLen];
319 int iLossCharLen = (int) strlen (pLossChars);
320 int iSkipedBytes = 0;
321 int iDstLen = 0;
322 int iBufPos = 0;
323 int ilastprefixlen = 0;
324 int i = 0;
325 bool bLost;
326 bVCLLoss = false;
327 SLostSim tmpSLostSim;
328 p_SLostSim->clear();
329 for (i = 0; i < iSrcLen;) {
330 if (pSrc[i] == 0 && pSrc[i + 1] == 0 && pSrc[i + 2] == 0 && pSrc[i + 3] == 1) {
331 if (i - iBufPos) {
332 tmpSLostSim.eNalType = (EWelsNalUnitType) ((* (pSrc + iBufPos + ilastprefixlen)) & 0x1f); // eNalUnitType
333 bLost = iLossIdx < iLossCharLen ? (pLossChars[iLossIdx] == '1') : (rand() % 2 == 1);
334 bLost = (!bLossPara) && (IS_PARAM_SETS_NALS (tmpSLostSim.eNalType)) ? false : bLost;
335 iLossIdx++;
336 tmpSLostSim.isLost = bLost;
337 p_SLostSim->push_back (tmpSLostSim);
338 if (!bLost) {
339 memcpy (pDst + iDstLen, pSrc + iBufPos, i - iBufPos);
340 iDstLen += (i - iBufPos);
341 } else {
342 bVCLLoss = (IS_VCL_NAL (tmpSLostSim.eNalType, 1)) ? true : bVCLLoss;
343 iSkipedBytes += (i - iBufPos);
344 }
345 }
346 ilastprefixlen = 4;
347 iBufPos = i;
348 i = i + 4;
349 } else if (pSrc[i] == 0 && pSrc[i + 1] == 0 && pSrc[i + 2] == 1) {
350 if (i - iBufPos) {
351 tmpSLostSim.eNalType = (EWelsNalUnitType) ((* (pSrc + iBufPos + ilastprefixlen)) & 0x1f); // eNalUnitType
352 bLost = iLossIdx < iLossCharLen ? (pLossChars[iLossIdx] == '1') : (rand() % 2 == 1);
353 bLost = (!bLossPara) && (IS_PARAM_SETS_NALS (tmpSLostSim.eNalType)) ? false : bLost;
354 iLossIdx++;
355 tmpSLostSim.isLost = bLost;
356 p_SLostSim->push_back (tmpSLostSim);
357 if (!bLost) {
358 memcpy (pDst + iDstLen, pSrc + iBufPos, i - iBufPos);
359 iDstLen += (i - iBufPos);
360 } else {
361 bVCLLoss = (IS_VCL_NAL (tmpSLostSim.eNalType, 1)) ? true : bVCLLoss;
362 iSkipedBytes += (i - iBufPos);
363 }
364 }
365 ilastprefixlen = 3;
366 iBufPos = i;
367 i = i + 3;
368 } else {
369 i++;
370 }
371 }
372 if (i - iBufPos) {
373 tmpSLostSim.eNalType = (EWelsNalUnitType) ((* (pSrc + iBufPos + ilastprefixlen)) & 0x1f); // eNalUnitType

Callers 3

TEST_PFunction · 0.85
TEST_PFunction · 0.85
TEST_PFunction · 0.85

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected