From 78d8d99180dc9bfa021f8d4fa2aaf446e5c428e2 Mon Sep 17 00:00:00 2001 From: "stefan@webrtc.org" Date: Wed, 23 May 2012 14:18:56 +0000 Subject: [PATCH] Fixes the vp8_test on Linux. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/579015 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2277 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../test_framework/normal_async_test.cc | 4 +- .../codecs/test_framework/normal_test.cc | 12 ++-- .../codecs/test_framework/normal_test.h | 4 +- .../codecs/test_framework/test.cc | 32 +++++---- .../video_coding/codecs/test_framework/test.h | 16 +++-- .../codecs/test_framework/unit_test.cc | 68 +++++-------------- .../codecs/test_framework/unit_test.h | 6 +- .../codecs/test_framework/video_source.cc | 22 +++--- .../codecs/vp8/main/source/vp8.gypi | 5 +- .../codecs/vp8/main/test/tester.cc | 14 ++-- .../codecs/vp8/main/test/unit_test.h | 39 ----------- .../test/{unit_test.cc => vp8_unittest.cc} | 52 ++------------ .../codecs/vp8/main/test/vp8_unittest.h | 29 ++++++++ 13 files changed, 114 insertions(+), 189 deletions(-) delete mode 100644 src/modules/video_coding/codecs/vp8/main/test/unit_test.h rename src/modules/video_coding/codecs/vp8/main/test/{unit_test.cc => vp8_unittest.cc} (67%) create mode 100644 src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.h diff --git a/src/modules/video_coding/codecs/test_framework/normal_async_test.cc b/src/modules/video_coding/codecs/test_framework/normal_async_test.cc index 8570ce79d..43b644001 100644 --- a/src/modules/video_coding/codecs/test_framework/normal_async_test.cc +++ b/src/modules/video_coding/codecs/test_framework/normal_async_test.cc @@ -129,7 +129,7 @@ _waitForKey(false) void NormalAsyncTest::Setup() { - Test::Setup(); + CodecTest::Setup(); std::stringstream ss; std::string strTestNo; ss << _testNo; @@ -178,7 +178,7 @@ NormalAsyncTest::Setup() void NormalAsyncTest::Teardown() { - Test::Teardown(); + CodecTest::Teardown(); fclose(_sourceFile); fclose(_encodedFile); fclose(_decodedFile); diff --git a/src/modules/video_coding/codecs/test_framework/normal_test.cc b/src/modules/video_coding/codecs/test_framework/normal_test.cc index 2dd7bce2f..2adb0763d 100644 --- a/src/modules/video_coding/codecs/test_framework/normal_test.cc +++ b/src/modules/video_coding/codecs/test_framework/normal_test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -19,7 +19,7 @@ NormalTest::NormalTest() : -Test("Normal Test 1", "A test of normal execution of the codec"), +CodecTest("Normal Test 1", "A test of normal execution of the codec"), _testNo(1), _lengthEncFrame(0), _appendNext(false) @@ -29,7 +29,7 @@ _appendNext(false) NormalTest::NormalTest(std::string name, std::string description, unsigned int testNo) : -Test(name, description), +CodecTest(name, description), _requestKeyFrame(false), _testNo(testNo), _lengthEncFrame(0), @@ -40,7 +40,7 @@ _appendNext(false) NormalTest::NormalTest(std::string name, std::string description, WebRtc_UWord32 bitRate, unsigned int testNo) : -Test(name, description, bitRate), +CodecTest(name, description, bitRate), _requestKeyFrame(false), _testNo(testNo), _lengthEncFrame(0), @@ -51,7 +51,7 @@ _appendNext(false) void NormalTest::Setup() { - Test::Setup(); + CodecTest::Setup(); std::stringstream ss; std::string strTestNo; ss << _testNo; @@ -100,7 +100,7 @@ NormalTest::Setup() void NormalTest::Teardown() { - Test::Teardown(); + CodecTest::Teardown(); fclose(_sourceFile); fclose(_decodedFile); } diff --git a/src/modules/video_coding/codecs/test_framework/normal_test.h b/src/modules/video_coding/codecs/test_framework/normal_test.h index 0dcd9c269..061fb6d96 100644 --- a/src/modules/video_coding/codecs/test_framework/normal_test.h +++ b/src/modules/video_coding/codecs/test_framework/normal_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -13,7 +13,7 @@ #include "test.h" -class NormalTest : public Test +class NormalTest : public CodecTest { public: NormalTest(); diff --git a/src/modules/video_coding/codecs/test_framework/test.cc b/src/modules/video_coding/codecs/test_framework/test.cc index 3eb693509..3cb107ef5 100644 --- a/src/modules/video_coding/codecs/test_framework/test.cc +++ b/src/modules/video_coding/codecs/test_framework/test.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -19,7 +19,7 @@ using namespace webrtc; long filesize(const char *filename); // local function defined at end of file -Test::Test(std::string name, std::string description) +CodecTest::CodecTest(std::string name, std::string description) : _bitRate(0), _inname(""), @@ -33,7 +33,8 @@ _description(description) std::srand(seed); } -Test::Test(std::string name, std::string description, WebRtc_UWord32 bitRate) +CodecTest::CodecTest(std::string name, std::string description, + WebRtc_UWord32 bitRate) : _bitRate(bitRate), _inname(""), @@ -48,7 +49,7 @@ _description(description) } void -Test::Print() +CodecTest::Print() { std::cout << _name << " completed!" << std::endl; (*_log) << _name << std::endl; @@ -70,7 +71,7 @@ Test::Print() } void -Test::Setup() +CodecTest::Setup() { int widhei = _inst.width*_inst.height; _lengthSourceFrame = 3*widhei/2; @@ -78,7 +79,9 @@ Test::Setup() } void -Test::CodecSettings(int width, int height, WebRtc_UWord32 frameRate /*=30*/, WebRtc_UWord32 bitRate /*=0*/) +CodecTest::CodecSettings(int width, int height, + WebRtc_UWord32 frameRate /*=30*/, + WebRtc_UWord32 bitRate /*=0*/) { if (bitRate > 0) { @@ -98,41 +101,41 @@ Test::CodecSettings(int width, int height, WebRtc_UWord32 frameRate /*=30*/, Web } void -Test::Teardown() +CodecTest::Teardown() { delete [] _sourceBuffer; } void -Test::SetEncoder(webrtc::VideoEncoder*encoder) +CodecTest::SetEncoder(webrtc::VideoEncoder*encoder) { _encoder = encoder; } void -Test::SetDecoder(VideoDecoder*decoder) +CodecTest::SetDecoder(VideoDecoder*decoder) { _decoder = decoder; } void -Test::SetLog(std::fstream* log) +CodecTest::SetLog(std::fstream* log) { _log = log; } -double Test::ActualBitRate(int nFrames) +double CodecTest::ActualBitRate(int nFrames) { return 8.0 * _sumEncBytes / (nFrames / _inst.maxFramerate); } -bool Test::PacketLoss(double lossRate, int /*thrown*/) +bool CodecTest::PacketLoss(double lossRate, int /*thrown*/) { return RandUniform() < lossRate; } void -Test::VideoBufferToRawImage(TestVideoBuffer& videoBuffer, RawImage &image) +CodecTest::VideoBufferToRawImage(TestVideoBuffer& videoBuffer, RawImage &image) { image._buffer = videoBuffer.GetBuffer(); image._size = videoBuffer.GetSize(); @@ -142,7 +145,8 @@ Test::VideoBufferToRawImage(TestVideoBuffer& videoBuffer, RawImage &image) image._timeStamp = videoBuffer.GetTimeStamp(); } void -Test::VideoEncodedBufferToEncodedImage(TestVideoEncodedBuffer& videoBuffer, EncodedImage &image) +CodecTest::VideoEncodedBufferToEncodedImage(TestVideoEncodedBuffer& videoBuffer, + EncodedImage &image) { image._buffer = videoBuffer.GetBuffer(); image._length = videoBuffer.GetLength(); diff --git a/src/modules/video_coding/codecs/test_framework/test.h b/src/modules/video_coding/codecs/test_framework/test.h index a31868b5c..d42880359 100644 --- a/src/modules/video_coding/codecs/test_framework/test.h +++ b/src/modules/video_coding/codecs/test_framework/test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -17,12 +17,13 @@ #include #include -class Test +class CodecTest { public: - Test(std::string name, std::string description); - Test(std::string name, std::string description, WebRtc_UWord32 bitRate); - virtual ~Test() {}; + CodecTest(std::string name, std::string description); + CodecTest(std::string name, std::string description, + WebRtc_UWord32 bitRate); + virtual ~CodecTest() {}; virtual void Perform()=0; virtual void Print(); void SetEncoder(webrtc::VideoEncoder *encoder); @@ -41,8 +42,9 @@ protected: static double RandUniform() { return (std::rand() + 1.0)/(RAND_MAX + 1.0); } static void VideoBufferToRawImage(TestVideoBuffer& videoBuffer, webrtc::RawImage &image); - static void VideoEncodedBufferToEncodedImage(TestVideoEncodedBuffer& videoBuffer, - webrtc::EncodedImage &image); + static void VideoEncodedBufferToEncodedImage( + TestVideoEncodedBuffer& videoBuffer, + webrtc::EncodedImage &image); webrtc::VideoEncoder* _encoder; webrtc::VideoDecoder* _decoder; diff --git a/src/modules/video_coding/codecs/test_framework/unit_test.cc b/src/modules/video_coding/codecs/test_framework/unit_test.cc index 623303a7c..07197c429 100644 --- a/src/modules/video_coding/codecs/test_framework/unit_test.cc +++ b/src/modules/video_coding/codecs/test_framework/unit_test.cc @@ -24,7 +24,7 @@ using namespace webrtc; UnitTest::UnitTest() : -Test("UnitTest", "Unit test"), +CodecTest("UnitTest", "Unit test"), _tests(0), _errors(0), _source(NULL), @@ -40,7 +40,7 @@ _decodeCompleteCallback(NULL) UnitTest::UnitTest(std::string name, std::string description) : -Test(name, description), +CodecTest(name, description), _tests(0), _errors(0), _source(NULL), @@ -222,12 +222,15 @@ UnitTest::Setup() _inst.maxBitrate = 4000; _inst.width = _source->GetWidth(); _inst.height = _source->GetHeight(); + _inst.codecSpecific.VP8.denoisingOn = true; // Get input frame. _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); ASSERT_TRUE(fread(_refFrame, 1, _lengthSourceFrame, _sourceFile) == _lengthSourceFrame); _inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame); + _inputVideoBuffer.SetWidth(_source->GetWidth()); + _inputVideoBuffer.SetHeight(_source->GetHeight()); rewind(_sourceFile); // Get a reference encoded frame. @@ -248,11 +251,7 @@ UnitTest::Setup() // Get a reference decoded frame. _decodedVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); - - if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) - { - exit(EXIT_FAILURE); - } + ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK); unsigned int frameLength = 0; int i=0; @@ -312,15 +311,6 @@ UnitTest::Teardown() void UnitTest::Print() { - printf("Unit Test\n\n%i tests completed\n", _tests); - if (_errors > 0) - { - printf("%i FAILED\n\n", _errors); - } - else - { - printf("ALL PASSED\n\n"); - } } int @@ -416,9 +406,6 @@ UnitTest::Perform() // Bad width. _inst.width = 0; EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) < 0); - // Should there be a width and height cap? - //_inst.width = 10000; - //EXPECT_TRUE(_encoder->InitEncode(&_inst, 1) == -1); _inst.width = _source->GetWidth(); // Bad height. @@ -441,6 +428,8 @@ UnitTest::Perform() WEBRTC_VIDEO_CODEC_ERR_PARAMETER); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame); + _inputVideoBuffer.SetWidth(_source->GetWidth()); + _inputVideoBuffer.SetHeight(_source->GetHeight()); //----- Encoder stress tests ----- @@ -506,11 +495,7 @@ UnitTest::Perform() WaitForDecodedFrame(); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_UNINITIALIZED); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); - - if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) - { - exit(EXIT_FAILURE); - } + ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK); //-- Decode() errors -- // Unallocated encodedVideoBuffer. @@ -527,21 +512,16 @@ UnitTest::Perform() // "Random" and zero data. // We either expect an error, or at the least, no output. // This relies on the codec's ability to detect an erroneous bitstream. - /* EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); - if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) - { - exit(EXIT_FAILURE); - } + ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK); for (int i = 0; i < 100; i++) { ASSERT_TRUE(fread(tmpBuf, 1, _refEncFrameLength, _sourceFile) == _refEncFrameLength); _encodedVideoBuffer.CopyBuffer(_refEncFrameLength, tmpBuf); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); - FillDecoderSpecificInfo(encodedImage); - int ret = _decoder->Decode(encodedImage, false, _decoderSpecificInfo); + int ret = _decoder->Decode(encodedImage, false, NULL); EXPECT_TRUE(ret <= 0); if (ret == 0) { @@ -551,15 +531,13 @@ UnitTest::Perform() memset(tmpBuf, 0, _refEncFrameLength); _encodedVideoBuffer.CopyBuffer(_refEncFrameLength, tmpBuf); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); - FillDecoderSpecificInfo(encodedImage); - ret = _decoder->Decode(encodedImage, false, _decoderSpecificInfo); + ret = _decoder->Decode(encodedImage, false, NULL); EXPECT_TRUE(ret <= 0); if (ret == 0) { EXPECT_TRUE(WaitForDecodedFrame() == 0); } } - */ rewind(_sourceFile); _encodedVideoBuffer.UpdateLength(_refEncFrameLength); @@ -567,10 +545,7 @@ UnitTest::Perform() // Init then decode. EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); - if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) - { - exit(EXIT_FAILURE); - } + ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK); frameLength = 0; VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); while (frameLength == 0) @@ -611,6 +586,8 @@ UnitTest::Perform() WEBRTC_VIDEO_CODEC_OK); RawImage tempInput(inputImage._buffer, inputImage._length/4, inputImage._size/4); + tempInput._width = tempInst.width; + tempInput._height = tempInst.height; VideoFrameType videoFrameType = kDeltaFrame; _encoder->Encode(tempInput, NULL, videoFrameType); frameLength = WaitForEncodedFrame(); @@ -653,10 +630,7 @@ UnitTest::Perform() // Release then decode. EXPECT_TRUE(_decoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); - if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) - { - exit(EXIT_FAILURE); - } + ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK); frameLength = 0; VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); while (frameLength == 0) @@ -680,12 +654,8 @@ UnitTest::Perform() EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); - if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) - { - exit(EXIT_FAILURE); - } + ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK); - printf("\nTimestamp propagation test...\n"); frames = 0; int frameDelay = 0; int encTimeStamp; @@ -732,7 +702,6 @@ UnitTest::Perform() void UnitTest::RateControlTests() { - std::string outFileName; int frames = 0; RawImage inputImage; WebRtc_UWord32 frameLength; @@ -744,8 +713,7 @@ UnitTest::RateControlTests() EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); // add: should also be 0, and 1 - const int bitRate[] = - {100, 200, 300, 400, 500, 600, 800, 1000, 2000, 3000, 4000, 10000}; + const int bitRate[] = {30, 100, 500, 1000, 2000}; const int nBitrates = sizeof(bitRate)/sizeof(*bitRate); printf("\nRate control test\n"); diff --git a/src/modules/video_coding/codecs/test_framework/unit_test.h b/src/modules/video_coding/codecs/test_framework/unit_test.h index 01b348d24..e306f0302 100644 --- a/src/modules/video_coding/codecs/test_framework/unit_test.h +++ b/src/modules/video_coding/codecs/test_framework/unit_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -28,7 +28,7 @@ class VideoSource; class UnitTestEncodeCompleteCallback; class UnitTestDecodeCompleteCallback; -class UnitTest : public Test +class UnitTest : public CodecTest { public: UnitTest(); @@ -61,7 +61,7 @@ protected: unsigned char* _refFrame; unsigned char* _refEncFrame; unsigned char* _refDecFrame; - int _refEncFrameLength; + unsigned int _refEncFrameLength; FILE* _sourceFile; UnitTestEncodeCompleteCallback* _encodeCompleteCallback; diff --git a/src/modules/video_coding/codecs/test_framework/video_source.cc b/src/modules/video_coding/codecs/test_framework/video_source.cc index 8abad1bd1..932e24c3f 100644 --- a/src/modules/video_coding/codecs/test_framework/video_source.cc +++ b/src/modules/video_coding/codecs/test_framework/video_source.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -11,8 +11,8 @@ #include "video_source.h" #include -#include +#include "gtest/gtest.h" #include "testsupport/fileutils.h" VideoSource::VideoSource() @@ -35,7 +35,9 @@ _frameRate(frameRate) assert(size != kUndefined && size != kNumberOfVideoSizes); assert(type != webrtc::kUnknown); assert(frameRate > 0); - assert(GetWidthHeight(size, _width, _height) == 0); + if (GetWidthHeight(size, _width, _height) != 0) { + assert(false); + } } VideoSource::VideoSource(std::string fileName, int width, int height, @@ -202,9 +204,9 @@ VideoSource::Convert(const VideoSource &target, bool force /* = false */) const { // Ensure target rate is less than or equal to source // (i.e. we are only temporally downsampling). - assert(target.GetFrameRate() <= _frameRate); + ASSERT_TRUE(target.GetFrameRate() <= _frameRate); // Only supports YUV420 currently. - assert(_type == webrtc::kI420 && target.GetType() == webrtc::kI420); + ASSERT_TRUE(_type == webrtc::kI420 && target.GetType() == webrtc::kI420); if (!force && (FileExists(target.GetFileName().c_str()) || (target.GetWidth() == _width && target.GetHeight() == _height && target.GetFrameRate() == _frameRate))) { @@ -216,28 +218,28 @@ VideoSource::Convert(const VideoSource &target, bool force /* = false */) const FILE *outFile = NULL; inFile = fopen(_fileName.c_str(), "rb"); - assert(inFile != NULL); + ASSERT_TRUE(inFile != NULL); outFile = fopen(target.GetFileName().c_str(), "wb"); - assert(outFile != NULL); + ASSERT_TRUE(outFile != NULL); FrameDropper fd; fd.SetFrameRate(target.GetFrameRate(), _frameRate); const size_t lengthOutFrame = webrtc::CalcBufferSize(target.GetType(), target.GetWidth(), target.GetHeight()); - assert(lengthOutFrame > 0); + ASSERT_TRUE(lengthOutFrame > 0); unsigned char *outFrame = new unsigned char[lengthOutFrame]; const size_t lengthInFrame = webrtc::CalcBufferSize(_type, _width, _height); - assert(lengthInFrame > 0); + ASSERT_TRUE(lengthInFrame > 0); unsigned char *inFrame = new unsigned char[lengthInFrame]; while (fread(inFrame, 1, lengthInFrame, inFile) == lengthInFrame) { if (!fd.DropFrame()) { - assert(target.GetWidth() == _width && + ASSERT_TRUE(target.GetWidth() == _width && target.GetHeight() == _height); // Add video interpolator here! fwrite(outFrame, 1, lengthOutFrame, outFile); } diff --git a/src/modules/video_coding/codecs/vp8/main/source/vp8.gypi b/src/modules/video_coding/codecs/vp8/main/source/vp8.gypi index 89d8c7860..5989fc895 100644 --- a/src/modules/video_coding/codecs/vp8/main/source/vp8.gypi +++ b/src/modules/video_coding/codecs/vp8/main/source/vp8.gypi @@ -71,6 +71,7 @@ '<(webrtc_root)/common_video/common_video.gyp:webrtc_libyuv', '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/../test/test.gyp:test_support', + '<(webrtc_root)/../test/test.gyp:test_support_main', '<(webrtc_root)/../testing/gtest.gyp:gtest', ], 'sources': [ @@ -80,7 +81,7 @@ '../test/normal_async_test.h', '../test/packet_loss_test.h', '../test/rps_test.h', - '../test/unit_test.h', + '../test/vp8_unittest.h', # source files '../test/benchmark.cc', @@ -89,7 +90,7 @@ '../test/packet_loss_test.cc', '../test/rps_test.cc', '../test/tester.cc', - '../test/unit_test.cc', + '../test/vp8_unittest.cc', ], }, { diff --git a/src/modules/video_coding/codecs/vp8/main/test/tester.cc b/src/modules/video_coding/codecs/vp8/main/test/tester.cc index 350d9a311..769c0f183 100644 --- a/src/modules/video_coding/codecs/vp8/main/test/tester.cc +++ b/src/modules/video_coding/codecs/vp8/main/test/tester.cc @@ -14,35 +14,36 @@ #include "benchmark.h" #include "dual_decoder_test.h" +#include "gtest/gtest.h" #include "normal_async_test.h" #include "packet_loss_test.h" -#include "unit_test.h" +#include "vp8_unittest.h" #include "rps_test.h" #include "testsupport/fileutils.h" #include "vp8.h" using namespace webrtc; -void PopulateTests(std::vector* tests) +void PopulateTests(std::vector* tests) { // tests->push_back(new VP8RpsTest()); -// tests->push_back(new VP8UnitTest()); + tests->push_back(new VP8UnitTest()); // tests->push_back(new VP8DualDecoderTest()); // tests->push_back(new VP8Benchmark()); // tests->push_back(new VP8PacketLossTest(0.05, false, 5)); tests->push_back(new VP8NormalAsyncTest()); } -int main() +TEST(Vp8WrapperTest, RunAllTests) { VP8Encoder* enc; VP8Decoder* dec; - std::vector tests; + std::vector tests; PopulateTests(&tests); std::fstream log; std::string log_file = webrtc::test::OutputPath() + "VP8_test_log.txt"; log.open(log_file.c_str(), std::fstream::out | std::fstream::app); - std::vector::iterator it; + std::vector::iterator it; for (it = tests.begin() ; it < tests.end(); it++) { enc = VP8Encoder::Create(); @@ -58,5 +59,4 @@ int main() } log.close(); tests.pop_back(); - return 0; } diff --git a/src/modules/video_coding/codecs/vp8/main/test/unit_test.h b/src/modules/video_coding/codecs/vp8/main/test/unit_test.h deleted file mode 100644 index e9287e61d..000000000 --- a/src/modules/video_coding/codecs/vp8/main/test/unit_test.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_UNIT_TEST_H_ -#define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_UNIT_TEST_H_ - -#include "../../../test_framework/unit_test.h" - -class VP8UnitTest : public UnitTest -{ -public: - VP8UnitTest(); - VP8UnitTest(std::string name, std::string description); - virtual void Perform(); - -protected: - virtual WebRtc_UWord32 CodecSpecific_SetBitrate(WebRtc_UWord32 bitRate, - WebRtc_UWord32 /*frameRate*/); - virtual bool CheckIfBitExact(const void *ptrA, unsigned int aLengthBytes, - const void *ptrB, unsigned int bLengthBytes); - static int PicIdLength(const unsigned char* ptr); -}; - -//////////////////////////////////////////////////////////////// -// RESERVATIONS TO PASSING UNIT TEST ON VP8 CODEC // -// Test that will not pass: // -// 1. Check bit exact for decoded images. // -// 2. Target bitrate - Allow a margin of 10% instead of 5% // -// 3. Detecting errors in bit stream - NA. // -//////////////////////////////////////////////////////////////// - -#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_UNIT_TEST_H_ diff --git a/src/modules/video_coding/codecs/vp8/main/test/unit_test.cc b/src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.cc similarity index 67% rename from src/modules/video_coding/codecs/vp8/main/test/unit_test.cc rename to src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.cc index 5ba35ec17..5908185b1 100644 --- a/src/modules/video_coding/codecs/vp8/main/test/unit_test.cc +++ b/src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.cc @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "unit_test.h" +#include "vp8_unittest.h" #include @@ -32,47 +32,18 @@ UnitTest(name, description) } WebRtc_UWord32 -VP8UnitTest::CodecSpecific_SetBitrate(WebRtc_UWord32 bitRate, WebRtc_UWord32 /*frameRate*/) +VP8UnitTest::CodecSpecific_SetBitrate(WebRtc_UWord32 bitRate, + WebRtc_UWord32 /*frameRate*/) { int rate = _encoder->SetRates(bitRate, _inst.maxFramerate); EXPECT_TRUE(rate >= 0); return rate; } -bool -VP8UnitTest::CheckIfBitExact(const void* ptrA, unsigned int aLengthBytes, - const void* ptrB, unsigned int bLengthBytes) -{ - const unsigned char* cPtrA = (const unsigned char*)ptrA; - const unsigned char* cPtrB = (const unsigned char*)ptrB; - // Skip picture ID before comparing - int aSkip = PicIdLength(cPtrA); - int bSkip = PicIdLength(cPtrB); - return UnitTest::CheckIfBitExact(cPtrA + aSkip, aLengthBytes, - cPtrB + bSkip, bLengthBytes); -} - -int -VP8UnitTest::PicIdLength(const unsigned char* ptr) -{ - WebRtc_UWord8 numberOfBytes; - WebRtc_UWord64 pictureID = 0; - for (numberOfBytes = 0; (ptr[numberOfBytes] & 0x80) && numberOfBytes < 8; numberOfBytes++) - { - pictureID += ptr[numberOfBytes] & 0x7f; - pictureID <<= 7; - } - pictureID += ptr[numberOfBytes] & 0x7f; - numberOfBytes++; - return numberOfBytes; -} - void VP8UnitTest::Perform() { Setup(); - FILE *outFile = NULL; - std::string outFileName; VP8Encoder* enc = (VP8Encoder*)_encoder; VP8Decoder* dec = (VP8Decoder*)_decoder; @@ -84,11 +55,9 @@ VP8UnitTest::Perform() EXPECT_EQ(enc->SetRates(_bitRate, _inst.maxFramerate), WEBRTC_VIDEO_CODEC_UNINITIALIZED); - // EXPECT_TRUE(enc->GetCodecConfigParameters(configParameters, sizeof(configParameters)) == - // WEBRTC_VIDEO_CODEC_UNINITIALIZED); - VideoCodec codecInst; + memset(&codecInst, 0, sizeof(codecInst)); strncpy(codecInst.plName, "VP8", 31); codecInst.plType = 126; codecInst.maxBitrate = 0; @@ -98,6 +67,7 @@ VP8UnitTest::Perform() codecInst.maxFramerate = 30; codecInst.startBitrate = 300; codecInst.codecSpecific.VP8.complexity = kComplexityNormal; + codecInst.codecSpecific.VP8.numberOfTemporalLayers = 1; EXPECT_EQ(enc->InitEncode(&codecInst, 1, 1440), WEBRTC_VIDEO_CODEC_OK); @@ -123,8 +93,6 @@ VP8UnitTest::Perform() codecInst.maxFramerate = 15; codecInst.codecSpecific.VP8.complexity = kComplexityNormal; codecInst.startBitrate = 300; - //EXPECT_TRUE(enc->InitEncode(&codecInst, 1, 1440) == WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED); - ASSERT_EQ(enc->InitEncode(&_inst, 1, 1440), WEBRTC_VIDEO_CODEC_OK); @@ -133,11 +101,6 @@ VP8UnitTest::Perform() EXPECT_EQ(enc->SetRates(_inst.maxBitrate + 1, _inst.maxFramerate), WEBRTC_VIDEO_CODEC_OK); - // Signaling not used. - - // Bad packetloss. -// EXPECT_TRUE(enc->SetPacketLoss(300) < 0); - //----- Decoder parameter tests ----- //-- Calls before InitDecode() -- EXPECT_TRUE(dec->Release() == 0); @@ -150,11 +113,6 @@ VP8UnitTest::Perform() // Garbage data. EXPECT_TRUE(dec->SetCodecConfigParameters(tmpBuf, sizeof(tmpBuf)) == -1); - //----- Function tests ----- - outFileName = webrtc::test::OutputPath() + _source->GetName() + "-errResTest.yuv"; - outFile = fopen(outFileName.c_str(), "wb"); - ASSERT_TRUE(outFile != NULL); - UnitTest::Perform(); Teardown(); diff --git a/src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.h b/src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.h new file mode 100644 index 000000000..f2629fece --- /dev/null +++ b/src/modules/video_coding/codecs/vp8/main/test/vp8_unittest.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_UNITTEST_H_ +#define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_UNITTEST_H_ + +#include "../../../test_framework/unit_test.h" + +class VP8UnitTest : public UnitTest +{ +public: + VP8UnitTest(); + VP8UnitTest(std::string name, std::string description); + virtual void Perform(); + +protected: + virtual WebRtc_UWord32 CodecSpecific_SetBitrate( + WebRtc_UWord32 bitRate, + WebRtc_UWord32 /*frameRate*/); +}; + +#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_VP8_UNITTEST_H_