Showing the changes to test/api/BaseDecoderTest.cpp (1 of 85 files). Show all
Unified · Split
| @@ -5,18 +5,18 @@ · 4 unmodified lines | ||
| 5 | 5 | #include "utils/BufferedData.h" |
| 6 | 6 | #include "BaseDecoderTest.h" |
| 7 | 7 | |
| 8 | −static void ReadFrame(std::ifstream* file, BufferedData* buf) { | |
| 8 | +static void ReadFrame (std::ifstream* file, BufferedData* buf) { | |
| 9 | 9 | // start code of a frame is {0, 0, 0, 1} |
| 10 | 10 | int zeroCount = 0; |
| 11 | 11 | char b; |
| 12 | 12 | |
| 13 | 13 | buf->Clear(); |
| 14 | 14 | for (;;) { |
| 15 | − file->read(&b, 1); | |
| 15 | + file->read (&b, 1); | |
| 16 | 16 | if (file->gcount() != 1) { // end of file |
| 17 | 17 | return; |
| 18 | 18 | } |
| 19 | − if (!buf->PushBack(b)) { | |
| 19 | + if (!buf->PushBack (b)) { | |
| 20 | 20 | FAIL() << "unable to allocate memory"; |
| 21 | 21 | } |
| 22 | 22 | |
| @@ -28,8 +28,8 @@ static void ReadFrame(std::ifstream* file, BufferedData* buf) { · 5 unmodified lines | ||
| 28 | 28 | zeroCount = b != 0 ? 0 : zeroCount + 1; |
| 29 | 29 | } else { |
| 30 | 30 | if (b == 1) { |
| 31 | − if (file->seekg(-4, file->cur).good()) { | |
| 32 | − buf->SetLength(buf->Length() - 4); | |
| 31 | + if (file->seekg (-4, file->cur).good()) { | |
| 32 | + buf->SetLength (buf->Length() - 4); | |
| 33 | 33 | return; |
| 34 | 34 | } else { |
| 35 | 35 | FAIL() << "unable to seek file"; |
| @@ -44,94 +44,97 @@ static void ReadFrame(std::ifstream* file, BufferedData* buf) { · 8 unmodified lines | ||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | BaseDecoderTest::BaseDecoderTest() |
| 47 | − : decoder_(NULL), decodeStatus_(OpenFile) {} | |
| 47 | + : decoder_ (NULL), decodeStatus_ (OpenFile) {} | |
| 48 | 48 | |
| 49 | 49 | void BaseDecoderTest::SetUp() { |
| 50 | − long rv = WelsCreateDecoder(&decoder_); | |
| 51 | − ASSERT_EQ(0, rv); | |
| 52 | − ASSERT_TRUE(decoder_ != NULL); | |
| 50 | + long rv = WelsCreateDecoder (&decoder_); | |
| 51 | + ASSERT_EQ (0, rv); | |
| 52 | + ASSERT_TRUE (decoder_ != NULL); | |
| 53 | 53 | |
| 54 | 54 | SDecodingParam decParam; |
| 55 | − memset(&decParam, 0, sizeof(SDecodingParam)); | |
| 55 | + memset (&decParam, 0, sizeof (SDecodingParam)); | |
| 56 | 56 | decParam.iOutputColorFormat = videoFormatI420; |
| 57 | 57 | decParam.uiTargetDqLayer = UCHAR_MAX; |
| 58 | 58 | decParam.uiEcActiveFlag = 1; |
| 59 | 59 | decParam.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; |
| 60 | 60 | |
| 61 | − rv = decoder_->Initialize(&decParam); | |
| 62 | − ASSERT_EQ(0, rv); | |
| 61 | + rv = decoder_->Initialize (&decParam); | |
| 62 | + ASSERT_EQ (0, rv); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | void BaseDecoderTest::TearDown() { |
| 66 | 66 | if (decoder_ != NULL) { |
| 67 | 67 | decoder_->Uninitialize(); |
| 68 | − WelsDestroyDecoder(decoder_); | |
| 68 | + WelsDestroyDecoder (decoder_); | |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
| 73 | −void BaseDecoderTest::DecodeFrame(const uint8_t* src, int sliceSize, Callback* cbk) { | |
| 73 | +void BaseDecoderTest::DecodeFrame (const uint8_t* src, int sliceSize, Callback* cbk) { | |
| 74 | 74 | uint8_t* data[3]; |
| 75 | 75 | SBufferInfo bufInfo; |
| 76 | − memset(data, 0, sizeof(data)); | |
| 77 | − memset(&bufInfo, 0, sizeof(SBufferInfo)); | |
| 76 | + memset (data, 0, sizeof (data)); | |
| 77 | + memset (&bufInfo, 0, sizeof (SBufferInfo)); | |
| 78 | 78 | |
| 79 | − DECODING_STATE rv = decoder_->DecodeFrame2(src, sliceSize, data, &bufInfo); | |
| 80 | − ASSERT_TRUE(rv == dsErrorFree); | |
| 79 | + DECODING_STATE rv = decoder_->DecodeFrame2 (src, sliceSize, data, &bufInfo); | |
| 80 | + ASSERT_TRUE (rv == dsErrorFree); | |
| 81 | 81 | |
| 82 | 82 | if (bufInfo.iBufferStatus == 1 && cbk != NULL) { |
| 83 | 83 | const Frame frame = { |
| 84 | − { // y plane | |
| 85 | − data[0], | |
| 86 | − bufInfo.UsrData.sSystemBuffer.iWidth, | |
| 87 | − bufInfo.UsrData.sSystemBuffer.iHeight, | |
| 88 | − bufInfo.UsrData.sSystemBuffer.iStride[0] | |
| 89 | − }, | |
| 90 | − { // u plane | |
| 91 | − data[1], | |
| 92 | − bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 93 | − bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 94 | − bufInfo.UsrData.sSystemBuffer.iStride[1] | |
| 95 | − }, | |
| 96 | − { // v plane | |
| 97 | − data[2], | |
| 98 | − bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 99 | − bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 100 | − bufInfo.UsrData.sSystemBuffer.iStride[1] | |
| 101 | − }, | |
| 84 | + { | |
| 85 | + // y plane | |
| 86 | + data[0], | |
| 87 | + bufInfo.UsrData.sSystemBuffer.iWidth, | |
| 88 | + bufInfo.UsrData.sSystemBuffer.iHeight, | |
| 89 | + bufInfo.UsrData.sSystemBuffer.iStride[0] | |
| 90 | + }, | |
| 91 | + { | |
| 92 | + // u plane | |
| 93 | + data[1], | |
| 94 | + bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 95 | + bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 96 | + bufInfo.UsrData.sSystemBuffer.iStride[1] | |
| 97 | + }, | |
| 98 | + { | |
| 99 | + // v plane | |
| 100 | + data[2], | |
| 101 | + bufInfo.UsrData.sSystemBuffer.iWidth / 2, | |
| 102 | + bufInfo.UsrData.sSystemBuffer.iHeight / 2, | |
| 103 | + bufInfo.UsrData.sSystemBuffer.iStride[1] | |
| 104 | + }, | |
| 102 | 105 | }; |
| 103 | − cbk->onDecodeFrame(frame); | |
| 106 | + cbk->onDecodeFrame (frame); | |
| 104 | 107 | } |
| 105 | 108 | } |
| 106 | −void BaseDecoderTest::DecodeFile(const char* fileName, Callback* cbk) { | |
| 107 | − std::ifstream file(fileName, std::ios::in | std::ios::binary); | |
| 108 | − ASSERT_TRUE(file.is_open()); | |
| 109 | +void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) { | |
| 110 | + std::ifstream file (fileName, std::ios::in | std::ios::binary); | |
| 111 | + ASSERT_TRUE (file.is_open()); | |
| 109 | 112 | |
| 110 | 113 | BufferedData buf; |
| 111 | 114 | while (true) { |
| 112 | − ReadFrame(&file, &buf); | |
| 115 | + ReadFrame (&file, &buf); | |
| 113 | 116 | if (::testing::Test::HasFatalFailure()) { |
| 114 | 117 | return; |
| 115 | 118 | } |
| 116 | 119 | if (buf.Length() == 0) { |
| 117 | 120 | break; |
| 118 | 121 | } |
| 119 | − DecodeFrame(buf.data(), buf.Length(), cbk); | |
| 122 | + DecodeFrame (buf.data(), buf.Length(), cbk); | |
| 120 | 123 | if (::testing::Test::HasFatalFailure()) { |
| 121 | 124 | return; |
| 122 | 125 | } |
| 123 | 126 | } |
| 124 | 127 | |
| 125 | 128 | int32_t iEndOfStreamFlag = 1; |
| 126 | − decoder_->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag); | |
| 129 | + decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag); | |
| 127 | 130 | |
| 128 | 131 | // Get pending last frame |
| 129 | − DecodeFrame(NULL, 0, cbk); | |
| 132 | + DecodeFrame (NULL, 0, cbk); | |
| 130 | 133 | } |
| 131 | 134 | |
| 132 | −bool BaseDecoderTest::Open(const char* fileName) { | |
| 135 | +bool BaseDecoderTest::Open (const char* fileName) { | |
| 133 | 136 | if (decodeStatus_ == OpenFile) { |
| 134 | − file_.open(fileName, std::ios_base::out | std::ios_base::binary); | |
| 137 | + file_.open (fileName, std::ios_base::out | std::ios_base::binary); | |
| 135 | 138 | if (file_.is_open()) { |
| 136 | 139 | decodeStatus_ = Decoding; |
| 137 | 140 | return true; |
| @@ -140,10 +143,10 @@ bool BaseDecoderTest::Open(const char* fileName) { · 2 unmodified lines | ||
| 140 | 143 | return false; |
| 141 | 144 | } |
| 142 | 145 | |
| 143 | −bool BaseDecoderTest::DecodeNextFrame(Callback* cbk) { | |
| 146 | +bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) { | |
| 144 | 147 | switch (decodeStatus_) { |
| 145 | 148 | case Decoding: |
| 146 | − ReadFrame(&file_, &buf_); | |
| 149 | + ReadFrame (&file_, &buf_); | |
| 147 | 150 | if (::testing::Test::HasFatalFailure()) { |
| 148 | 151 | return false; |
| 149 | 152 | } |
| @@ -151,15 +154,15 @@ bool BaseDecoderTest::DecodeNextFrame(Callback* cbk) { · 1 unmodified line | ||
| 151 | 154 | decodeStatus_ = EndOfStream; |
| 152 | 155 | return true; |
| 153 | 156 | } |
| 154 | − DecodeFrame(buf_.data(), buf_.Length(), cbk); | |
| 157 | + DecodeFrame (buf_.data(), buf_.Length(), cbk); | |
| 155 | 158 | if (::testing::Test::HasFatalFailure()) { |
| 156 | 159 | return false; |
| 157 | 160 | } |
| 158 | 161 | return true; |
| 159 | 162 | case EndOfStream: { |
| 160 | 163 | int32_t iEndOfStreamFlag = 1; |
| 161 | − decoder_->SetOption(DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag); | |
| 162 | − DecodeFrame(NULL, 0, cbk); | |
| 164 | + decoder_->SetOption (DECODER_OPTION_END_OF_STREAM, &iEndOfStreamFlag); | |
| 165 | + DecodeFrame (NULL, 0, cbk); | |
| 163 | 166 | decodeStatus_ = End; |
| 164 | 167 | break; |
| 165 | 168 | } |