| 6 | #include "BaseDecoderTest.h" |
| 7 | |
| 8 | static bool ReadFrame (std::ifstream* file, BufferedData* buf) { |
| 9 | // start code of a frame is {0, 0, 0, 1} |
| 10 | int zeroCount = 0; |
| 11 | char b; |
| 12 | |
| 13 | buf->Clear(); |
| 14 | for (;;) { |
| 15 | file->read (&b, 1); |
| 16 | if (file->gcount() != 1) { // end of file |
| 17 | return true; |
| 18 | } |
| 19 | if (!buf->PushBack (b)) { |
| 20 | std::cout << "unable to allocate memory" << std::endl; |
| 21 | return false; |
| 22 | } |
| 23 | |
| 24 | if (buf->Length() <= 4) { |
| 25 | continue; |
| 26 | } |
| 27 | |
| 28 | if (zeroCount < 3) { |
| 29 | zeroCount = b != 0 ? 0 : zeroCount + 1; |
| 30 | } else { |
| 31 | if (b == 1) { |
| 32 | if (file->seekg (-4, file->cur).good()) { |
| 33 | if (-1 == buf->SetLength(buf->Length() - 4)) |
| 34 | return false; |
| 35 | return true; |
| 36 | } else { |
| 37 | std::cout << "unable to seek file" << std::endl; |
| 38 | return false; |
| 39 | } |
| 40 | } else if (b == 0) { |
| 41 | zeroCount = 3; |
| 42 | } else { |
| 43 | zeroCount = 0; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | BaseDecoderTest::BaseDecoderTest() |
| 50 | : decoder_ (NULL), decodeStatus_ (OpenFile) {} |