Showing the changes to test/decoder_test.cpp (1 of 3 files). Show all
Unified · Split
| @@ -15,7 +15,6 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | static void UpdateHashFromPlane(SHA_CTX* ctx, const uint8_t* plane, |
| 17 | 17 | int width, int height, int stride) { |
| 18 | − | |
| 19 | 18 | for (int i = 0; i < height; i++) { |
| 20 | 19 | SHA1_Update(ctx, plane, width); |
| 21 | 20 | plane += stride; |
| @@ -30,7 +29,11 @@ static int ReadFrame(std::ifstream* file, BufferedData* buf) { · 8 unmodified lines | ||
| 30 | 29 | int zeroCount = 0; |
| 31 | 30 | char b; |
| 32 | 31 | |
| 33 | − while (file->read(&b, 1), file->gcount() == 1) { | |
| 32 | + for (;;) { | |
| 33 | + file->read(&b, 1); | |
| 34 | + if (file->gcount() != 1) { | |
| 35 | + break; | |
| 36 | + } | |
| 34 | 37 | if (!buf->Push(b)) { |
| 35 | 38 | return -1; |
| 36 | 39 | } |
| @@ -43,8 +46,12 @@ static int ReadFrame(std::ifstream* file, BufferedData* buf) { · 6 unmodified lines | ||
| 43 | 46 | zeroCount = b != 0 ? 0 : zeroCount + 1; |
| 44 | 47 | } else { |
| 45 | 48 | if (b == 1) { |
| 46 | − file->seekg(-4, file->cur); | |
| 47 | − return buf->Length() - 4; | |
| 49 | + if (file->seekg(-4, file->cur).good()) { | |
| 50 | + return buf->Length() - 4; | |
| 51 | + } else { | |
| 52 | + // seeking fails | |
| 53 | + return -1; | |
| 54 | + } | |
| 48 | 55 | } else if (b == 0) { |
| 49 | 56 | zeroCount = 3; |
| 50 | 57 | } else { |
| @@ -60,40 +67,38 @@ static int ReadFrame(std::ifstream* file, BufferedData* buf) { · 9 unmodified lines | ||
| 60 | 67 | */ |
| 61 | 68 | static bool DecodeAndProcess(ISVCDecoder* decoder, const uint8_t* src, |
| 62 | 69 | int sliceSize, SHA_CTX* ctx) { |
| 63 | − | |
| 64 | 70 | void* data[3]; |
| 65 | 71 | SBufferInfo bufInfo; |
| 66 | 72 | memset(data, 0, sizeof(data)); |
| 67 | 73 | memset(&bufInfo, 0, sizeof(SBufferInfo)); |
| 68 | 74 | |
| 69 | 75 | DECODING_STATE rv = decoder->DecodeFrame(src, sliceSize, data, &bufInfo); |
| 70 | − if (rv == dsErrorFree) { | |
| 71 | − if (bufInfo.iBufferStatus == 1) { | |
| 72 | − // y plane | |
| 73 | − UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[0]), | |
| 74 | − bufInfo.UsrData.sSystemBuffer.iWidth, | |
| 75 | − bufInfo.UsrData.sSystemBuffer.iHeight, | |
| 76 | − bufInfo.UsrData.sSystemBuffer.iStride[0]); | |
| 77 | − // u plane | |
| 78 | − UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[1]), | |
| 79 | − bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 80 | − bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 81 | − bufInfo.UsrData.sSystemBuffer.iStride[1]); | |
| 82 | − // v plane | |
| 83 | − UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[2]), | |
| 84 | − bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 85 | − bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 86 | − bufInfo.UsrData.sSystemBuffer.iStride[1]); | |
| 87 | − } | |
| 88 | − return true; | |
| 89 | − } else { | |
| 76 | + if (rv != dsErrorFree) { | |
| 90 | 77 | return false; |
| 91 | 78 | } |
| 79 | + | |
| 80 | + if (bufInfo.iBufferStatus == 1) { | |
| 81 | + // y plane | |
| 82 | + UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[0]), | |
| 83 | + bufInfo.UsrData.sSystemBuffer.iWidth, | |
| 84 | + bufInfo.UsrData.sSystemBuffer.iHeight, | |
| 85 | + bufInfo.UsrData.sSystemBuffer.iStride[0]); | |
| 86 | + // u plane | |
| 87 | + UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[1]), | |
| 88 | + bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 89 | + bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 90 | + bufInfo.UsrData.sSystemBuffer.iStride[1]); | |
| 91 | + // v plane | |
| 92 | + UpdateHashFromPlane(ctx, static_cast<uint8_t*>(data[2]), | |
| 93 | + bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 94 | + bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 95 | + bufInfo.UsrData.sSystemBuffer.iStride[1]); | |
| 96 | + } | |
| 97 | + return true; | |
| 92 | 98 | } |
| 93 | 99 | |
| 94 | 100 | static void CompareFileToHash(ISVCDecoder* decoder, |
| 95 | 101 | const char* fileName, const char* hashStr) { |
| 96 | − | |
| 97 | 102 | std::ifstream file(fileName, std::ios::in | std::ios::binary); |
| 98 | 103 | ASSERT_TRUE(file.is_open()); |
| 99 | 104 | |
| @@ -118,7 +123,7 @@ static void CompareFileToHash(ISVCDecoder* decoder, · 18 unmodified lines | ||
| 118 | 123 | FAIL() << "unable to allocate memory"; |
| 119 | 124 | } |
| 120 | 125 | |
| 121 | − int32_t iEndOfStreamFlag = true; | |
| 126 | + int32_t iEndOfStreamFlag = 1; | |
| 122 | 127 | decoder->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag); |
| 123 | 128 | |
| 124 | 129 | // Get pending last frame |
| @@ -132,7 +137,7 @@ static void CompareFileToHash(ISVCDecoder* decoder, · 7 unmodified lines | ||
| 132 | 137 | } |
| 133 | 138 | |
| 134 | 139 | class DecoderInitTest : public ::testing::Test { |
| 135 | −public: | |
| 140 | + public: | |
| 136 | 141 | DecoderInitTest() : decoder_(NULL) {} |
| 137 | 142 | |
| 138 | 143 | virtual void SetUp() { |
| @@ -158,7 +163,7 @@ public: · 19 unmodified lines | ||
| 158 | 163 | } |
| 159 | 164 | } |
| 160 | 165 | |
| 161 | −protected: | |
| 166 | + protected: | |
| 162 | 167 | ISVCDecoder* decoder_; |
| 163 | 168 | }; |
| 164 | 169 | |