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

Method ThreadDecodeFile

test/api/BaseThreadDecoderTest.cpp:251–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249 }
250}
251bool BaseThreadDecoderTest::ThreadDecodeFile (const char* fileName, Callback* cbk) {
252 std::ifstream file (fileName, std::ios::in | std::ios::binary);
253 if (!file.is_open())
254 return false;
255
256 BufferedData buf;
257 char b;
258 for (;;) {
259 file.read (&b, 1);
260 if (file.gcount() != 1) { // end of file
261 break;
262 }
263 if (!buf.PushBack (b)) {
264 std::cout << "unable to allocate memory" << std::endl;
265 return false;
266 }
267 }
268
269 std::string outFileName = std::string (fileName);
270 size_t pos = outFileName.find_last_of (".");
271 if (bEnableYuvDumpTest) {
272 outFileName = outFileName.substr (0, pos) + std::string (".yuv");
273 pYuvFile = fopen (outFileName.c_str(), "wb");
274 }
275
276 uiTimeStamp = 0;
277 memset (&sBufInfo, 0, sizeof (SBufferInfo));
278 int32_t bufPos = 0;
279 int32_t bytesConsumed = 0;
280 int32_t fileSize = (int32_t)buf.Length();
281 while (bytesConsumed < fileSize) {
282 int32_t frameSize = ReadFrame (buf.data(), fileSize, bufPos);
283 if (::testing::Test::HasFatalFailure()) {
284 return false;
285 }
286 uint8_t* frame_ptr = buf.data() + bufPos;
287 DecodeFrame (frame_ptr, frameSize, cbk);
288 if (::testing::Test::HasFatalFailure()) {
289 return false;
290 }
291 bufPos += frameSize;
292 bytesConsumed += frameSize;
293 }
294
295 int32_t iEndOfStreamFlag = 1;
296 decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag);
297
298 // Flush out last frames in decoder buffer
299 int32_t num_of_frames_in_buffer = 0;
300 decoder_->GetOption (DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER, &num_of_frames_in_buffer);
301 for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) {
302 FlushFrame (cbk);
303 }
304 if (bEnableYuvDumpTest) {
305 fclose (pYuvFile);
306 }
307 return true;
308}

Callers

nothing calls this directly

Calls 8

DecodeFrameFunction · 0.85
PushBackMethod · 0.80
LengthMethod · 0.80
dataMethod · 0.80
ReadFrameFunction · 0.70
readMethod · 0.45
SetOptionMethod · 0.45
GetOptionMethod · 0.45

Tested by

no test coverage detected