bool DecoderParseSyntaxTest::ParseBs (const char* sFileName, EDecCase eDecCase) { uint8_t* pBuf = NULL; int32_t iBufPos = 0; int32_t iFileSize; int32_t i = 0; int32_t iSliceSize; int32_t iSliceIndex = 0; int32_t iEndOfStreamFlag = 0; FILE* pH264File; uint8_t uiStartCode[4] = { 0, 0, 0, 1 }; int iRet = 0; #if defined(ANDROID_NDK) std::string filename = std::string ("/sdcard/") + sFileName; if ((pH264File = fopen (filename.c_str(), "rb")) == NULL) return false; #else if ((pH264File = fopen (sFileName, "rb")) == NULL) return false; #endif fseek (pH264File, 0L, SEEK_END); iFileSize = (int32_t)ftell (pH264File); fseek (pH264File, 0L, SEEK_SET); pBuf = new uint8_t[iFileSize + 4]; if (pBuf == NULL) { fclose (pH264File); return false; } if (fread (pBuf, 1, iFileSize, pH264File) != (unsigned int)iFileSize) { fclose (pH264File); if (pBuf) { delete[] pBuf; pBuf = NULL; } return false; } memcpy (pBuf + iFileSize, &uiStartCode[0], 4); //confirmed_safe_unsafe_usage while (true) { if (iBufPos >= iFileSize) { iEndOfStreamFlag = true; if (iEndOfStreamFlag) m_pDec->SetOption (DECODER_OPTION_END_OF_STREAM, (void*)&iEndOfStreamFlag); break; } for (i = 0; i < iFileSize; i++) { if ((pBuf[iBufPos + i] == 0 && pBuf[iBufPos + i + 1] == 0 && pBuf[iBufPos + i + 2] == 0 && pBuf[iBufPos + i + 3] == 1 && i > 0)) { break; } } iSliceSize = i; memset (&m_sParserBsInfo, 0, sizeof (SParserBsInfo)); iRet |= m_pDec->DecodeParser (pBuf + iBufPos, iSliceSize, &m_sParserBsInfo); iRet |= m_pDec->DecodeParser (NULL, 0, &m_sParserBsInfo); if (eDecCase == CorrectParseOnly) EXPECT_TRUE (iRet == dsErrorFree || iRet == dsFramePending); iBufPos += iSliceSize; ++iSliceIndex; if (iSliceIndex == 4) break; } if (eDecCase == ErrorDec) EXPECT_TRUE ((iRet & (dsBitstreamError | dsRefLost | dsDataErrorConcealed)) != 0) << iRet; fclose (pH264File); if (pBuf) { delete[] pBuf; pBuf = NULL; } return true; }