Converting vp8_test to use fileutils and gtest

Review URL: http://webrtc-codereview.appspot.com/289012

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1074 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kjellander@webrtc.org 2011-12-01 15:24:36 +00:00
parent f64162c335
commit 4c4b7f500f
13 changed files with 194 additions and 178 deletions

View File

@ -9,18 +9,22 @@
*/ */
#include "benchmark.h" #include "benchmark.h"
#include "video_source.h"
#include "vplib.h" #include <cassert>
#include <vector>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <cassert> #include <vector>
#if defined(_WIN32) #if defined(_WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
#include "event_wrapper.h" #include "event_wrapper.h"
#include "testsupport/fileutils.h"
#include "video_codec_interface.h" #include "video_codec_interface.h"
#include "video_source.h"
#include "vplib.h"
#define SSIM_CALC 0 // by default, don't compute SSIM #define SSIM_CALC 0 // by default, don't compute SSIM
@ -29,7 +33,7 @@ using namespace webrtc;
Benchmark::Benchmark() Benchmark::Benchmark()
: :
NormalAsyncTest("Benchmark", "Codec benchmark over a range of test cases", 6), NormalAsyncTest("Benchmark", "Codec benchmark over a range of test cases", 6),
_resultsFileName("../../../../testFiles/benchmark.txt"), _resultsFileName(webrtc::test::OutputPath() + "benchmark.txt"),
_codecName("Default") _codecName("Default")
{ {
} }
@ -37,7 +41,7 @@ _codecName("Default")
Benchmark::Benchmark(std::string name, std::string description) Benchmark::Benchmark(std::string name, std::string description)
: :
NormalAsyncTest(name, description, 6), NormalAsyncTest(name, description, 6),
_resultsFileName("../../../../testFiles/benchmark.txt"), _resultsFileName(webrtc::test::OutputPath() + "benchmark.txt"),
_codecName("Default") _codecName("Default")
{ {
} }
@ -57,8 +61,10 @@ Benchmark::Perform()
std::vector<const VideoSource*>::iterator it; std::vector<const VideoSource*>::iterator it;
// Configuration -------------------------- // Configuration --------------------------
sources.push_back(new const VideoSource("test/testFiles/foreman_cif.yuv", kCIF)); sources.push_back(new const VideoSource(webrtc::test::ProjectRootPath() +
sources.push_back(new const VideoSource("test/testFiles/akiyo_cif.yuv", kCIF)); "resources/foreman_cif.yuv", kCIF));
// sources.push_back(new const VideoSource(webrtc::test::ProjectRootPath() +
// "resources/akiyo_cif.yuv", kCIF));
const VideoSize size[] = {kQCIF, kCIF}; const VideoSize size[] = {kQCIF, kCIF};
const int frameRate[] = {10, 15, 30}; const int frameRate[] = {10, 15, 30};

View File

@ -10,13 +10,14 @@
#include "normal_async_test.h" #include "normal_async_test.h"
#include <sstream>
#include <assert.h> #include <assert.h>
#include <queue>
#include <string.h> #include <string.h>
#include <sstream>
#include <queue>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "tick_util.h" #include "tick_util.h"
#include "testsupport/fileutils.h"
#include "typedefs.h" #include "typedefs.h"
using namespace webrtc; using namespace webrtc;
@ -132,12 +133,14 @@ NormalAsyncTest::Setup()
// Check if settings exist. Otherwise use defaults. // Check if settings exist. Otherwise use defaults.
if (_outname == "") if (_outname == "")
{ {
_outname = "../../out_normaltest" + strTestNo + ".yuv"; _outname = webrtc::test::OutputPath() + "out_normaltest" + strTestNo +
".yuv";
} }
if (_encodedName == "") if (_encodedName == "")
{ {
_encodedName = "../../encoded_normaltest" + strTestNo + ".yuv"; _encodedName = webrtc::test::OutputPath() + "encoded_normaltest" +
strTestNo + ".yuv";
} }
if ((_sourceFile = fopen(_inname.c_str(), "rb")) == NULL) if ((_sourceFile = fopen(_inname.c_str(), "rb")) == NULL)
@ -298,7 +301,7 @@ NormalAsyncTest::Decoded(const RawImage& decodedImage)
void void
NormalAsyncTest::Perform() NormalAsyncTest::Perform()
{ {
_inname = "test/testFiles/foreman_cif.yuv"; _inname = webrtc::test::ProjectRootPath() + "resources/foreman_cif.yuv";
CodecSettings(352, 288, 30, _bitRate); CodecSettings(352, 288, 30, _bitRate);
Setup(); Setup();
_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);

View File

@ -15,6 +15,7 @@
#include <string.h> #include <string.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "testsupport/fileutils.h"
NormalTest::NormalTest() NormalTest::NormalTest()
: :
@ -25,7 +26,8 @@ _appendNext(false)
{ {
} }
NormalTest::NormalTest(std::string name, std::string description, unsigned int testNo) NormalTest::NormalTest(std::string name, std::string description,
unsigned int testNo)
: :
Test(name, description), Test(name, description),
_requestKeyFrame(false), _requestKeyFrame(false),
@ -35,7 +37,8 @@ _appendNext(false)
{ {
} }
NormalTest::NormalTest(std::string name, std::string description, WebRtc_UWord32 bitRate, unsigned int testNo) NormalTest::NormalTest(std::string name, std::string description,
WebRtc_UWord32 bitRate, unsigned int testNo)
: :
Test(name, description, bitRate), Test(name, description, bitRate),
_requestKeyFrame(false), _requestKeyFrame(false),
@ -57,12 +60,14 @@ NormalTest::Setup()
// Check if settings exist. Otherwise use defaults. // Check if settings exist. Otherwise use defaults.
if (_outname == "") if (_outname == "")
{ {
_outname = "../../out_normaltest" + strTestNo + ".yuv"; _outname = webrtc::test::OutputPath() + "out_normaltest" + strTestNo +
".yuv";
} }
if (_encodedName == "") if (_encodedName == "")
{ {
_encodedName = "../../encoded_normaltest" + strTestNo + ".yuv"; _encodedName = webrtc::test::OutputPath() + "encoded_normaltest" +
strTestNo + ".yuv";
} }
if ((_sourceFile = fopen(_inname.c_str(), "rb")) == NULL) if ((_sourceFile = fopen(_inname.c_str(), "rb")) == NULL)
@ -103,7 +108,7 @@ NormalTest::Teardown()
void void
NormalTest::Perform() NormalTest::Perform()
{ {
_inname = "../../../../testFiles/foreman.yuv"; _inname = webrtc::test::ProjectRootPath() + "resources/foreman_cif.yuv";
CodecSettings(352, 288, 30, _bitRate); CodecSettings(352, 288, 30, _bitRate);
Setup(); Setup();

View File

@ -13,6 +13,7 @@
#include <assert.h> #include <assert.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "testsupport/fileutils.h"
#include "tick_util.h" #include "tick_util.h"
using namespace webrtc; using namespace webrtc;
@ -87,7 +88,7 @@ PerformanceTest::~PerformanceTest()
void void
PerformanceTest::Setup() PerformanceTest::Setup()
{ {
_inname = "../../../../testFiles/foreman.yuv"; _inname = webrtc::test::ProjectRootPath() + "resources/foreman_cif.yuv";
NormalAsyncTest::Setup(); // Setup input and output files NormalAsyncTest::Setup(); // Setup input and output files
CodecSettings(352, 288, 30, _bitRate); // common to all codecs CodecSettings(352, 288, 30, _bitRate); // common to all codecs
for (int i=0; i < _numCodecs; i++) for (int i=0; i < _numCodecs; i++)

View File

@ -16,6 +16,7 @@
'type': '<(library)', 'type': '<(library)',
'dependencies': [ 'dependencies': [
'<(webrtc_root)/../test/test.gyp:test_support',
'<(webrtc_root)/../testing/gtest.gyp:gtest', '<(webrtc_root)/../testing/gtest.gyp:gtest',
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
'<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib', '<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib',
@ -23,6 +24,7 @@
'include_dirs': [ 'include_dirs': [
'../interface', '../interface',
'<(webrtc_root)/../testing/gtest/include',
'../../../../common_video/interface', '../../../../common_video/interface',
], ],

View File

@ -8,13 +8,17 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "unit_test.h" #include <math.h>
#include "video_source.h"
#include "tick_util.h"
#include <cassert>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <cassert>
#include "gtest/gtest.h"
#include "testsupport/fileutils.h"
#include "tick_util.h"
#include "unit_test.h"
#include "video_source.h"
using namespace webrtc; using namespace webrtc;
@ -202,14 +206,15 @@ UnitTest::Setup()
_encoder->RegisterEncodeCompleteCallback(_encodeCompleteCallback); _encoder->RegisterEncodeCompleteCallback(_encodeCompleteCallback);
_decoder->RegisterDecodeCompleteCallback(_decodeCompleteCallback); _decoder->RegisterDecodeCompleteCallback(_decodeCompleteCallback);
_source = new VideoSource("test/testFiles/foreman_cif.yuv", kCIF); _source = new VideoSource(webrtc::test::ProjectRootPath() +
"resources/foreman_cif.yuv", kCIF);
_lengthSourceFrame = _source->GetFrameLength(); _lengthSourceFrame = _source->GetFrameLength();
_refFrame = new unsigned char[_lengthSourceFrame]; _refFrame = new unsigned char[_lengthSourceFrame];
_refDecFrame = new unsigned char[_lengthSourceFrame]; _refDecFrame = new unsigned char[_lengthSourceFrame];
_sourceBuffer = new unsigned char [_lengthSourceFrame]; _sourceBuffer = new unsigned char [_lengthSourceFrame];
_sourceFile = fopen(_source->GetFileName().c_str(), "rb"); _sourceFile = fopen(_source->GetFileName().c_str(), "rb");
VIDEO_TEST_EXIT_ON_ERR(_sourceFile != NULL); ASSERT_TRUE(_sourceFile != NULL);
_inst.maxFramerate = _source->GetFrameRate(); _inst.maxFramerate = _source->GetFrameRate();
_bitRate = 300; _bitRate = 300;
@ -220,7 +225,7 @@ UnitTest::Setup()
// Get input frame. // Get input frame.
_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);
VIDEO_TEST_EXIT_ON_ERR(fread(_refFrame, 1, _lengthSourceFrame, _sourceFile) ASSERT_TRUE(fread(_refFrame, 1, _lengthSourceFrame, _sourceFile)
== _lengthSourceFrame); == _lengthSourceFrame);
_inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame); _inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame);
rewind(_sourceFile); rewind(_sourceFile);
@ -232,17 +237,17 @@ UnitTest::Setup()
VideoBufferToRawImage(_inputVideoBuffer, image); VideoBufferToRawImage(_inputVideoBuffer, image);
// Ensures our initial parameters are valid. // Ensures our initial parameters are valid.
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
_encoder->Encode(image, NULL, &videoFrameType); _encoder->Encode(image, NULL, &videoFrameType);
_refEncFrameLength = WaitForEncodedFrame(); _refEncFrameLength = WaitForEncodedFrame();
VIDEO_TEST_EXIT_ON_ERR(_refEncFrameLength > 0); ASSERT_TRUE(_refEncFrameLength > 0);
_refEncFrame = new unsigned char[_refEncFrameLength]; _refEncFrame = new unsigned char[_refEncFrameLength];
memcpy(_refEncFrame, _encodedVideoBuffer.GetBuffer(), _refEncFrameLength); memcpy(_refEncFrame, _encodedVideoBuffer.GetBuffer(), _refEncFrameLength);
// Get a reference decoded frame. // Get a reference decoded frame.
_decodedVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _decodedVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK)
{ {
@ -257,18 +262,18 @@ UnitTest::Setup()
{ {
// Insert yet another frame // Insert yet another frame
_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);
VIDEO_TEST_EXIT_ON_ERR(fread(_refFrame, 1, _lengthSourceFrame, ASSERT_TRUE(fread(_refFrame, 1, _lengthSourceFrame,
_sourceFile) == _lengthSourceFrame); _sourceFile) == _lengthSourceFrame);
_inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame); _inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame);
_inputVideoBuffer.SetWidth(_source->GetWidth()); _inputVideoBuffer.SetWidth(_source->GetWidth());
_inputVideoBuffer.SetHeight(_source->GetHeight()); _inputVideoBuffer.SetHeight(_source->GetHeight());
VideoBufferToRawImage(_inputVideoBuffer, image); VideoBufferToRawImage(_inputVideoBuffer, image);
_encoder->Encode(image, NULL, &videoFrameType); _encoder->Encode(image, NULL, &videoFrameType);
VIDEO_TEST_EXIT_ON_ERR(WaitForEncodedFrame() > 0); ASSERT_TRUE(WaitForEncodedFrame() > 0);
} }
EncodedImage encodedImage; EncodedImage encodedImage;
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
VIDEO_TEST_EXIT_ON_ERR(_decoder->Decode(encodedImage, 0, NULL) ASSERT_TRUE(_decoder->Decode(encodedImage, 0, NULL)
== WEBRTC_VIDEO_CODEC_OK); == WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForDecodedFrame(); frameLength = WaitForDecodedFrame();
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
@ -276,7 +281,7 @@ UnitTest::Setup()
i++; i++;
} }
rewind(_sourceFile); rewind(_sourceFile);
VIDEO_TEST(frameLength == _lengthSourceFrame); EXPECT_TRUE(frameLength == _lengthSourceFrame);
memcpy(_refDecFrame, _decodedVideoBuffer.GetBuffer(), _lengthSourceFrame); memcpy(_refDecFrame, _decodedVideoBuffer.GetBuffer(), _lengthSourceFrame);
} }
@ -343,7 +348,7 @@ UnitTest::Decode()
unsigned int frameLength = WaitForDecodedFrame(); unsigned int frameLength = WaitForDecodedFrame();
assert(ret == WEBRTC_VIDEO_CODEC_OK && (frameLength == 0 || frameLength assert(ret == WEBRTC_VIDEO_CODEC_OK && (frameLength == 0 || frameLength
== _lengthSourceFrame)); == _lengthSourceFrame));
VIDEO_TEST(ret == WEBRTC_VIDEO_CODEC_OK && (frameLength == 0 || frameLength EXPECT_TRUE(ret == WEBRTC_VIDEO_CODEC_OK && (frameLength == 0 || frameLength
== _lengthSourceFrame)); == _lengthSourceFrame));
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
@ -365,76 +370,76 @@ UnitTest::Perform()
//-- Calls before InitEncode() -- //-- Calls before InitEncode() --
// We want to revert the initialization done in Setup(). // We want to revert the initialization done in Setup().
VIDEO_TEST(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
VIDEO_TEST(_encoder->Encode(inputImage, NULL, &videoFrameType ) EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType )
== WEBRTC_VIDEO_CODEC_UNINITIALIZED); == WEBRTC_VIDEO_CODEC_UNINITIALIZED);
VIDEO_TEST(_encoder->Reset() == WEBRTC_VIDEO_CODEC_UNINITIALIZED); EXPECT_TRUE(_encoder->Reset() == WEBRTC_VIDEO_CODEC_UNINITIALIZED);
//-- InitEncode() errors -- //-- InitEncode() errors --
// Null pointer. // Null pointer.
VIDEO_TEST(_encoder->InitEncode(NULL, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(NULL, 1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
// bit rate exceeds max bit rate // bit rate exceeds max bit rate
WebRtc_Word32 tmpBitRate = _inst.startBitrate; WebRtc_Word32 tmpBitRate = _inst.startBitrate;
WebRtc_Word32 tmpMaxBitRate = _inst.maxBitrate; WebRtc_Word32 tmpMaxBitRate = _inst.maxBitrate;
_inst.startBitrate = 4000; _inst.startBitrate = 4000;
_inst.maxBitrate = 3000; _inst.maxBitrate = 3000;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_inst.startBitrate = tmpBitRate; _inst.startBitrate = tmpBitRate;
_inst.maxBitrate = tmpMaxBitRate; //unspecified value _inst.maxBitrate = tmpMaxBitRate; //unspecified value
// Bad framerate. // Bad framerate.
_inst.maxFramerate = 0; _inst.maxFramerate = 0;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
// Seems like we should allow any framerate in range [0, 255]. // Seems like we should allow any framerate in range [0, 255].
//_inst.frameRate = 100; //_inst.frameRate = 100;
//VIDEO_TEST(_encoder->InitEncode(&_inst, 1) == -1); // FAILS //EXPECT_TRUE(_encoder->InitEncode(&_inst, 1) == -1); // FAILS
_inst.maxFramerate = 30; _inst.maxFramerate = 30;
// Bad bitrate. // Bad bitrate.
_inst.startBitrate = -1; _inst.startBitrate = -1;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_inst.maxBitrate = _inst.startBitrate - 1; _inst.maxBitrate = _inst.startBitrate - 1;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_inst.maxBitrate = 0; _inst.maxBitrate = 0;
_inst.startBitrate = 300; _inst.startBitrate = 300;
// Bad maxBitRate. // Bad maxBitRate.
_inst.maxBitrate = 200; _inst.maxBitrate = 200;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_inst.maxBitrate = 4000; _inst.maxBitrate = 4000;
// Bad width. // Bad width.
_inst.width = 0; _inst.width = 0;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) < 0); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) < 0);
// Should there be a width and height cap? // Should there be a width and height cap?
//_inst.width = 10000; //_inst.width = 10000;
//VIDEO_TEST(_encoder->InitEncode(&_inst, 1) == -1); //EXPECT_TRUE(_encoder->InitEncode(&_inst, 1) == -1);
_inst.width = _source->GetWidth(); _inst.width = _source->GetWidth();
// Bad height. // Bad height.
_inst.height = 0; _inst.height = 0;
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) < 0); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) < 0);
_inst.height = _source->GetHeight(); _inst.height = _source->GetHeight();
// Bad number of cores. // Bad number of cores.
VIDEO_TEST(_encoder->InitEncode(&_inst, -1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, -1, 1440) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
//-- Encode() errors -- //-- Encode() errors --
// inputVideoBuffer unallocated. // inputVideoBuffer unallocated.
_inputVideoBuffer.Free(); _inputVideoBuffer.Free();
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
VIDEO_TEST(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) ==
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);
_inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame); _inputVideoBuffer.CopyBuffer(_lengthSourceFrame, _refFrame);
@ -446,65 +451,65 @@ UnitTest::Perform()
for (int i = 1; i <= 60; i++) for (int i = 1; i <= 60; i++)
{ {
VideoFrameType frameType = !(i % 2) ? kKeyFrame : kDeltaFrame; VideoFrameType frameType = !(i % 2) ? kKeyFrame : kDeltaFrame;
VIDEO_TEST(_encoder->Encode(inputImage, NULL, &frameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &frameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(WaitForEncodedFrame() > 0); EXPECT_TRUE(WaitForEncodedFrame() > 0);
sleepEvent.Wait(10); // Allow the encoder's queue to realize it's empty. sleepEvent.Wait(10); // Allow the encoder's queue to realize it's empty.
} }
// Init then encode. // Init then encode.
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
VIDEO_TEST(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(WaitForEncodedFrame() > 0); EXPECT_TRUE(WaitForEncodedFrame() > 0);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, &videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
VIDEO_TEST(frameLength > 0); EXPECT_TRUE(frameLength > 0);
VIDEO_TEST(CheckIfBitExact(_refEncFrame, _refEncFrameLength, EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
_encodedVideoBuffer.GetBuffer(), frameLength) == true); _encodedVideoBuffer.GetBuffer(), frameLength) == true);
// Reset then encode. // Reset then encode.
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
VIDEO_TEST(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
WaitForEncodedFrame(); WaitForEncodedFrame();
VIDEO_TEST(_encoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, &videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
VIDEO_TEST(frameLength > 0); EXPECT_TRUE(frameLength > 0);
VIDEO_TEST(CheckIfBitExact(_refEncFrame, _refEncFrameLength, EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
_encodedVideoBuffer.GetBuffer(), frameLength) == true); _encodedVideoBuffer.GetBuffer(), frameLength) == true);
// Release then encode. // Release then encode.
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
VIDEO_TEST(_encoder->Encode(inputImage, NULL, &videoFrameType) == EXPECT_TRUE(_encoder->Encode(inputImage, NULL, &videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
WaitForEncodedFrame(); WaitForEncodedFrame();
VIDEO_TEST(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, &videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
VIDEO_TEST(frameLength > 0); EXPECT_TRUE(frameLength > 0);
VIDEO_TEST(CheckIfBitExact(_refEncFrame, _refEncFrameLength, EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
_encodedVideoBuffer.GetBuffer(), frameLength) == true); _encodedVideoBuffer.GetBuffer(), frameLength) == true);
//----- Decoder parameter tests ----- //----- Decoder parameter tests -----
//-- Calls before InitDecode() -- //-- Calls before InitDecode() --
// We want to revert the initialization done in Setup(). // We want to revert the initialization done in Setup().
VIDEO_TEST(_decoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
VIDEO_TEST(_decoder->Decode(encodedImage, false, NULL) == EXPECT_TRUE(_decoder->Decode(encodedImage, false, NULL) ==
WEBRTC_VIDEO_CODEC_UNINITIALIZED); WEBRTC_VIDEO_CODEC_UNINITIALIZED);
WaitForDecodedFrame(); WaitForDecodedFrame();
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_UNINITIALIZED); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_UNINITIALIZED);
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK)
{ {
@ -516,8 +521,8 @@ UnitTest::Perform()
_encodedVideoBuffer.Free(); _encodedVideoBuffer.Free();
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
encodedImage._length = 10; // Buffer NULL but length > 0 encodedImage._length = 10; // Buffer NULL but length > 0
VIDEO_TEST(_decoder->Decode(encodedImage, false, NULL) == EXPECT_EQ(_decoder->Decode(encodedImage, false, NULL),
WEBRTC_VIDEO_CODEC_ERR_PARAMETER); WEBRTC_VIDEO_CODEC_ERR_PARAMETER);
_encodedVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _encodedVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);
//----- Decoder stress tests ----- //----- Decoder stress tests -----
@ -527,24 +532,24 @@ UnitTest::Perform()
// We either expect an error, or at the least, no output. // We either expect an error, or at the least, no output.
// This relies on the codec's ability to detect an erroneous bitstream. // This relies on the codec's ability to detect an erroneous bitstream.
/* /*
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK)
{ {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
VIDEO_TEST_EXIT_ON_ERR(fread(tmpBuf, 1, _refEncFrameLength, _sourceFile) ASSERT_TRUE(fread(tmpBuf, 1, _refEncFrameLength, _sourceFile)
== _refEncFrameLength); == _refEncFrameLength);
_encodedVideoBuffer.CopyBuffer(_refEncFrameLength, tmpBuf); _encodedVideoBuffer.CopyBuffer(_refEncFrameLength, tmpBuf);
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
FillDecoderSpecificInfo(encodedImage); FillDecoderSpecificInfo(encodedImage);
int ret = _decoder->Decode(encodedImage, false, _decoderSpecificInfo); int ret = _decoder->Decode(encodedImage, false, _decoderSpecificInfo);
VIDEO_TEST(ret <= 0); EXPECT_TRUE(ret <= 0);
if (ret == 0) if (ret == 0)
{ {
VIDEO_TEST(WaitForDecodedFrame() == 0); EXPECT_TRUE(WaitForDecodedFrame() == 0);
} }
memset(tmpBuf, 0, _refEncFrameLength); memset(tmpBuf, 0, _refEncFrameLength);
@ -552,10 +557,10 @@ UnitTest::Perform()
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
FillDecoderSpecificInfo(encodedImage); FillDecoderSpecificInfo(encodedImage);
ret = _decoder->Decode(encodedImage, false, _decoderSpecificInfo); ret = _decoder->Decode(encodedImage, false, _decoderSpecificInfo);
VIDEO_TEST(ret <= 0); EXPECT_TRUE(ret <= 0);
if (ret == 0) if (ret == 0)
{ {
VIDEO_TEST(WaitForDecodedFrame() == 0); EXPECT_TRUE(WaitForDecodedFrame() == 0);
} }
} }
*/ */
@ -565,7 +570,7 @@ UnitTest::Perform()
_encodedVideoBuffer.CopyBuffer(_refEncFrameLength, _refEncFrame); _encodedVideoBuffer.CopyBuffer(_refEncFrameLength, _refEncFrame);
// Init then decode. // Init then decode.
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK)
{ {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -577,11 +582,11 @@ UnitTest::Perform()
_decoder->Decode(encodedImage, false, NULL); _decoder->Decode(encodedImage, false, NULL);
frameLength = WaitForDecodedFrame(); frameLength = WaitForDecodedFrame();
} }
VIDEO_TEST(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength, EXPECT_TRUE(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength,
_refDecFrame, _lengthSourceFrame) == true); _refDecFrame, _lengthSourceFrame) == true);
// Reset then decode. // Reset then decode.
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
frameLength = 0; frameLength = 0;
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
while (frameLength == 0) while (frameLength == 0)
@ -589,7 +594,7 @@ UnitTest::Perform()
_decoder->Decode(encodedImage, false, NULL); _decoder->Decode(encodedImage, false, NULL);
frameLength = WaitForDecodedFrame(); frameLength = WaitForDecodedFrame();
} }
VIDEO_TEST(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength, EXPECT_TRUE(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength,
_refDecFrame, _lengthSourceFrame) == true); _refDecFrame, _lengthSourceFrame) == true);
// Decode with other size, reset, then decode with original size again // Decode with other size, reset, then decode with original size again
@ -597,7 +602,7 @@ UnitTest::Perform()
{ {
// assert that input frame size is a factor of two, so that we can use // assert that input frame size is a factor of two, so that we can use
// quarter size below // quarter size below
VIDEO_TEST((_inst.width % 2 == 0) && (_inst.height % 2 == 0)); EXPECT_TRUE((_inst.width % 2 == 0) && (_inst.height % 2 == 0));
VideoCodec tempInst; VideoCodec tempInst;
memcpy(&tempInst, &_inst, sizeof(VideoCodec)); memcpy(&tempInst, &_inst, sizeof(VideoCodec));
@ -605,18 +610,18 @@ UnitTest::Perform()
tempInst.height /= 2; tempInst.height /= 2;
// Encode reduced (quarter) frame size // Encode reduced (quarter) frame size
VIDEO_TEST(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_encoder->InitEncode(&tempInst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&tempInst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
RawImage tempInput(inputImage._buffer, inputImage._length/4, RawImage tempInput(inputImage._buffer, inputImage._length/4,
inputImage._size/4); inputImage._size/4);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
_encoder->Encode(tempInput, NULL, &videoFrameType); _encoder->Encode(tempInput, NULL, &videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
VIDEO_TEST(frameLength > 0); EXPECT_TRUE(frameLength > 0);
// Reset then decode. // Reset then decode.
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
frameLength = 0; frameLength = 0;
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
while (frameLength == 0) while (frameLength == 0)
@ -626,15 +631,15 @@ UnitTest::Perform()
} }
// Encode original frame again // Encode original frame again
VIDEO_TEST(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(inputImage, NULL, &videoFrameType); _encoder->Encode(inputImage, NULL, &videoFrameType);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
VIDEO_TEST(frameLength > 0); EXPECT_TRUE(frameLength > 0);
// Reset then decode original frame again. // Reset then decode original frame again.
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
frameLength = 0; frameLength = 0;
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage); VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
while (frameLength == 0) while (frameLength == 0)
@ -644,14 +649,14 @@ UnitTest::Perform()
} }
// check that decoded frame matches with reference // check that decoded frame matches with reference
VIDEO_TEST(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength, EXPECT_TRUE(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength,
_refDecFrame, _lengthSourceFrame) == true); _refDecFrame, _lengthSourceFrame) == true);
} }
// Release then decode. // Release then decode.
VIDEO_TEST(_decoder->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Release() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK)
{ {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -663,7 +668,7 @@ UnitTest::Perform()
_decoder->Decode(encodedImage, false, NULL); _decoder->Decode(encodedImage, false, NULL);
frameLength = WaitForDecodedFrame(); frameLength = WaitForDecodedFrame();
} }
VIDEO_TEST(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength, EXPECT_TRUE(CheckIfBitExact(_decodedVideoBuffer.GetBuffer(), frameLength,
_refDecFrame, _lengthSourceFrame) == true); _refDecFrame, _lengthSourceFrame) == true);
_encodedVideoBuffer.UpdateLength(0); _encodedVideoBuffer.UpdateLength(0);
_encodedVideoBuffer.Reset(); _encodedVideoBuffer.Reset();
@ -676,10 +681,10 @@ UnitTest::Perform()
_inst.maxBitrate = 0; _inst.maxBitrate = 0;
//-- Timestamp propagation -- //-- Timestamp propagation --
VIDEO_TEST(_encoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK) if (SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK)
{ {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -697,15 +702,15 @@ UnitTest::Perform()
_inputVideoBuffer.SetTimeStamp(frames); _inputVideoBuffer.SetTimeStamp(frames);
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
VIDEO_TEST_EXIT_ON_ERR(_encoder->Encode(inputImage, ASSERT_TRUE(_encoder->Encode(inputImage,
NULL, NULL,
&videoFrameType) == &videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
//VIDEO_TEST_EXIT_ON_ERR(frameLength); //ASSERT_TRUE(frameLength);
VIDEO_TEST(frameLength > 0); EXPECT_TRUE(frameLength > 0);
encTimeStamp = _encodedVideoBuffer.GetTimeStamp(); encTimeStamp = _encodedVideoBuffer.GetTimeStamp();
VIDEO_TEST(_inputVideoBuffer.GetTimeStamp() == EXPECT_TRUE(_inputVideoBuffer.GetTimeStamp() ==
static_cast<unsigned>(encTimeStamp)); static_cast<unsigned>(encTimeStamp));
frameLength = Decode(); frameLength = Decode();
@ -719,13 +724,13 @@ UnitTest::Perform()
{ {
encTimeStamp = 0; encTimeStamp = 0;
} }
VIDEO_TEST(_decodedVideoBuffer.GetTimeStamp() == EXPECT_TRUE(_decodedVideoBuffer.GetTimeStamp() ==
static_cast<unsigned>(encTimeStamp)); static_cast<unsigned>(encTimeStamp));
frames++; frames++;
sleepEvent.Wait(33); sleepEvent.Wait(33);
} }
delete &sleepEvent; delete &sleepEvent;
VIDEO_TEST_EXIT_ON_ERR(feof(_sourceFile) != 0); ASSERT_TRUE(feof(_sourceFile) != 0);
rewind(_sourceFile); rewind(_sourceFile);
RateControlTests(); RateControlTests();
@ -745,10 +750,10 @@ UnitTest::RateControlTests()
// Do not specify maxBitRate (as in ViE). // Do not specify maxBitRate (as in ViE).
_inst.maxBitrate = 0; _inst.maxBitrate = 0;
//-- Verify rate control -- //-- Verify rate control --
VIDEO_TEST(_encoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
// add: should also be 0, and 1 // add: should also be 0, and 1
const int bitRate[] = const int bitRate[] =
{100, 200, 300, 400, 500, 600, 800, 1000, 2000, 3000, 4000, 10000}; {100, 200, 300, 400, 500, 600, 800, 1000, 2000, 3000, 4000, 10000};
@ -784,12 +789,10 @@ UnitTest::RateControlTests()
static_cast<float>(_inst.maxFramerate))); static_cast<float>(_inst.maxFramerate)));
VideoBufferToRawImage(_inputVideoBuffer, inputImage); VideoBufferToRawImage(_inputVideoBuffer, inputImage);
VideoFrameType videoFrameType = kDeltaFrame; VideoFrameType videoFrameType = kDeltaFrame;
VIDEO_TEST_EXIT_ON_ERR(_encoder->Encode(inputImage, ASSERT_EQ(_encoder->Encode(inputImage, NULL, &videoFrameType),
NULL, WEBRTC_VIDEO_CODEC_OK);
&videoFrameType) ==
WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForEncodedFrame(); frameLength = WaitForEncodedFrame();
VIDEO_TEST_EXIT_ON_ERR(frameLength >= 0); ASSERT_GE(frameLength, 0u);
totalBytes += frameLength; totalBytes += frameLength;
frames++; frames++;
@ -805,10 +808,10 @@ UnitTest::RateControlTests()
// Test for close match over reasonable range. // Test for close match over reasonable range.
if (_bitRate >= 100 && _bitRate <= 2500) if (_bitRate >= 100 && _bitRate <= 2500)
{ {
VIDEO_TEST(abs(WebRtc_Word32(actualBitrate - _bitRate)) < EXPECT_TRUE(abs(WebRtc_Word32(actualBitrate - _bitRate)) <
0.1 * _bitRate); // for VP8 0.1 * _bitRate); // for VP8
} }
VIDEO_TEST_EXIT_ON_ERR(feof(_sourceFile) != 0); ASSERT_TRUE(feof(_sourceFile) != 0);
rewind(_sourceFile); rewind(_sourceFile);
} }
} }

View File

@ -24,30 +24,6 @@
#pragma warning(disable : 4127) #pragma warning(disable : 4127)
#endif #endif
#define VIDEO_TEST(expr) \
do \
{ \
_tests++; \
if (!(expr)) \
{ \
fprintf(stderr, "Error at line %i of %s\nAssertion failed: %s\n\n",\
__LINE__, __FILE__, #expr); \
_errors++; \
} \
} while (0)
#define VIDEO_TEST_EXIT_ON_ERR(expr) \
do \
{ \
if (!(expr)) \
{ \
fprintf(stderr, "Error at line %i of %s\nAssertion failed: %s\n", \
__LINE__, __FILE__, #expr); \
fprintf(stderr, "Exiting...\n\n"); \
exit(EXIT_FAILURE); \
} \
} while (0)
class VideoSource; class VideoSource;
class UnitTestEncodeCompleteCallback; class UnitTestEncodeCompleteCallback;
class UnitTestDecodeCompleteCallback; class UnitTestDecodeCompleteCallback;

View File

@ -9,13 +9,16 @@
*/ */
#include "video_source.h" #include "video_source.h"
#include "vplib.h"
#include <cassert>
#include <stdio.h> #include <stdio.h>
#include <cassert>
#include "testsupport/fileutils.h"
#include "vplib.h"
VideoSource::VideoSource() VideoSource::VideoSource()
: :
_fileName("../../../../testFiles/foreman.yuv"), _fileName(webrtc::test::ProjectRootPath() + "resources/foreman_cif.yuv"),
_width(352), _width(352),
_height(288), _height(288),
_type(webrtc::kI420), _type(webrtc::kI420),

View File

@ -65,6 +65,8 @@
'webrtc_vp8', 'webrtc_vp8',
'<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib', '<(webrtc_root)/common_video/common_video.gyp:webrtc_vplib',
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers',
'<(webrtc_root)/../test/test.gyp:test_support',
'<(webrtc_root)/../testing/gtest.gyp:gtest',
], ],
'sources': [ 'sources': [
# header files # header files

View File

@ -9,23 +9,27 @@
*/ */
#include "benchmark.h" #include "benchmark.h"
#include "testsupport/fileutils.h"
#include "vp8.h" #include "vp8.h"
using namespace webrtc; using namespace webrtc;
VP8Benchmark::VP8Benchmark() VP8Benchmark::VP8Benchmark()
: :
Benchmark("VP8Benchmark", "VP8 benchmark over a range of test cases", "../../VP8Benchmark.txt", "VP8") Benchmark("VP8Benchmark", "VP8 benchmark over a range of test cases",
webrtc::test::OutputPath() + "VP8Benchmark.txt", "VP8")
{ {
} }
VP8Benchmark::VP8Benchmark(std::string name, std::string description) VP8Benchmark::VP8Benchmark(std::string name, std::string description)
: :
Benchmark(name, description, "../../VP8Benchmark.txt", "VP8") Benchmark(name, description, webrtc::test::OutputPath() + "VP8Benchmark.txt",
"VP8")
{ {
} }
VP8Benchmark::VP8Benchmark(std::string name, std::string description, std::string resultsFileName) VP8Benchmark::VP8Benchmark(std::string name, std::string description,
std::string resultsFileName)
: :
Benchmark(name, description, resultsFileName, "VP8") Benchmark(name, description, resultsFileName, "VP8")
{ {

View File

@ -14,6 +14,8 @@
#include <string.h> // memcmp #include <string.h> // memcmp
#include <time.h> #include <time.h>
#include "testsupport/fileutils.h"
VP8DualDecoderTest::VP8DualDecoderTest(float bitRate) VP8DualDecoderTest::VP8DualDecoderTest(float bitRate)
: :
VP8NormalAsyncTest(bitRate) VP8NormalAsyncTest(bitRate)
@ -41,7 +43,7 @@ VP8DualDecoderTest::~VP8DualDecoderTest()
void void
VP8DualDecoderTest::Perform() VP8DualDecoderTest::Perform()
{ {
_inname = "test/testFiles/foreman_cif.yuv"; _inname = webrtc::test::ProjectRootPath() + "resources/foreman_cif.yuv";
CodecSettings(352, 288, 30, _bitRate); CodecSettings(352, 288, 30, _bitRate);
Setup(); Setup();
_inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame); _inputVideoBuffer.VerifyAndAllocate(_lengthSourceFrame);

View File

@ -8,16 +8,18 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "packet_loss_test.h"
#include "benchmark.h"
#include "unit_test.h"
#include "normal_async_test.h"
#include "dual_decoder_test.h"
#include "vp8.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "benchmark.h"
#include "dual_decoder_test.h"
#include "normal_async_test.h"
#include "packet_loss_test.h"
#include "unit_test.h"
#include "testsupport/fileutils.h"
#include "vp8.h"
using namespace webrtc; using namespace webrtc;
void PopulateTests(std::vector<Test*>* tests) void PopulateTests(std::vector<Test*>* tests)
@ -36,7 +38,8 @@ int main()
std::vector<Test*> tests; std::vector<Test*> tests;
PopulateTests(&tests); PopulateTests(&tests);
std::fstream log; std::fstream log;
log.open("../../TestLog.txt", std::fstream::out | std::fstream::app); 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<Test*>::iterator it; std::vector<Test*>::iterator it;
for (it = tests.begin() ; it < tests.end(); it++) for (it = tests.begin() ; it < tests.end(); it++)
{ {

View File

@ -9,11 +9,14 @@
*/ */
#include "unit_test.h" #include "unit_test.h"
#include "../../../test_framework/video_source.h"
#include "vp8.h"
#include <string.h> #include <string.h>
#include "../../../test_framework/video_source.h"
#include "gtest/gtest.h"
#include "testsupport/fileutils.h"
#include "vp8.h"
using namespace webrtc; using namespace webrtc;
VP8UnitTest::VP8UnitTest() VP8UnitTest::VP8UnitTest()
@ -35,7 +38,7 @@ VP8UnitTest::Print()
// GetVersion tests. // GetVersion tests.
VIDEO_TEST(_encoder->Version(versionStr, sizeof(versionStr)) > 0); EXPECT_TRUE(_encoder->Version(versionStr, sizeof(versionStr)) > 0);
// printf("\n%s", versionStr); // printf("\n%s", versionStr);
// UnitTest::Print(); // UnitTest::Print();
} }
@ -44,7 +47,7 @@ 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); int rate = _encoder->SetRates(bitRate, _inst.maxFramerate);
VIDEO_TEST_EXIT_ON_ERR(rate >= 0); EXPECT_TRUE(rate >= 0);
return rate; return rate;
} }
@ -87,11 +90,13 @@ VP8UnitTest::Perform()
//----- Encoder parameter tests ----- //----- Encoder parameter tests -----
//-- Calls before InitEncode() -- //-- Calls before InitEncode() --
VIDEO_TEST(enc->Release() == WEBRTC_VIDEO_CODEC_OK); EXPECT_EQ(enc->Release(), WEBRTC_VIDEO_CODEC_OK);
VIDEO_TEST(enc->SetRates(_bitRate, _inst.maxFramerate) == WEBRTC_VIDEO_CODEC_UNINITIALIZED); EXPECT_EQ(enc->SetRates(_bitRate, _inst.maxFramerate),
WEBRTC_VIDEO_CODEC_UNINITIALIZED);
VIDEO_TEST(enc->SetRates(_bitRate, _inst.maxFramerate) == WEBRTC_VIDEO_CODEC_UNINITIALIZED); EXPECT_EQ(enc->SetRates(_bitRate, _inst.maxFramerate),
// VIDEO_TEST(enc->GetCodecConfigParameters(configParameters, sizeof(configParameters)) == WEBRTC_VIDEO_CODEC_UNINITIALIZED);
// EXPECT_TRUE(enc->GetCodecConfigParameters(configParameters, sizeof(configParameters)) ==
// WEBRTC_VIDEO_CODEC_UNINITIALIZED); // WEBRTC_VIDEO_CODEC_UNINITIALIZED);
@ -105,7 +110,7 @@ VP8UnitTest::Perform()
codecInst.maxFramerate = 30; codecInst.maxFramerate = 30;
codecInst.startBitrate = 300; codecInst.startBitrate = 300;
codecInst.codecSpecific.VP8.complexity = kComplexityNormal; codecInst.codecSpecific.VP8.complexity = kComplexityNormal;
VIDEO_TEST(enc->InitEncode(&codecInst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_EQ(enc->InitEncode(&codecInst, 1, 1440), WEBRTC_VIDEO_CODEC_OK);
//-- Test two problematic level settings -- //-- Test two problematic level settings --
@ -118,7 +123,7 @@ VP8UnitTest::Perform()
codecInst.maxFramerate = 30; codecInst.maxFramerate = 30;
codecInst.codecSpecific.VP8.complexity = kComplexityNormal; codecInst.codecSpecific.VP8.complexity = kComplexityNormal;
codecInst.startBitrate = 300; codecInst.startBitrate = 300;
VIDEO_TEST(enc->InitEncode(&codecInst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); EXPECT_EQ(enc->InitEncode(&codecInst, 1, 1440), WEBRTC_VIDEO_CODEC_OK);
// Settings not correct for this profile // Settings not correct for this profile
strncpy(codecInst.plName, "VP8", 31); strncpy(codecInst.plName, "VP8", 31);
@ -130,36 +135,37 @@ VP8UnitTest::Perform()
codecInst.maxFramerate = 15; codecInst.maxFramerate = 15;
codecInst.codecSpecific.VP8.complexity = kComplexityNormal; codecInst.codecSpecific.VP8.complexity = kComplexityNormal;
codecInst.startBitrate = 300; codecInst.startBitrate = 300;
//VIDEO_TEST(enc->InitEncode(&codecInst, 1, 1440) == WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED); //EXPECT_TRUE(enc->InitEncode(&codecInst, 1, 1440) == WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED);
VIDEO_TEST_EXIT_ON_ERR(enc->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK); ASSERT_EQ(enc->InitEncode(&_inst, 1, 1440), WEBRTC_VIDEO_CODEC_OK);
//-- ProcessNewBitrate() errors -- //-- ProcessNewBitrate() errors --
// Bad bitrate. // Bad bitrate.
VIDEO_TEST(enc->SetRates(_inst.maxBitrate + 1, _inst.maxFramerate) == WEBRTC_VIDEO_CODEC_OK); EXPECT_EQ(enc->SetRates(_inst.maxBitrate + 1, _inst.maxFramerate),
WEBRTC_VIDEO_CODEC_OK);
// Signaling not used. // Signaling not used.
// Bad packetloss. // Bad packetloss.
// VIDEO_TEST(enc->SetPacketLoss(300) < 0); // EXPECT_TRUE(enc->SetPacketLoss(300) < 0);
//----- Decoder parameter tests ----- //----- Decoder parameter tests -----
//-- Calls before InitDecode() -- //-- Calls before InitDecode() --
VIDEO_TEST(dec->Release() == 0); EXPECT_TRUE(dec->Release() == 0);
VIDEO_TEST_EXIT_ON_ERR(dec->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK); ASSERT_TRUE(dec->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
//-- SetCodecConfigParameters() errors -- //-- SetCodecConfigParameters() errors --
unsigned char tmpBuf[128]; unsigned char tmpBuf[128];
VIDEO_TEST(dec->SetCodecConfigParameters(NULL, sizeof(tmpBuf)) == -1); EXPECT_TRUE(dec->SetCodecConfigParameters(NULL, sizeof(tmpBuf)) == -1);
VIDEO_TEST(dec->SetCodecConfigParameters(tmpBuf, 1) == -1); EXPECT_TRUE(dec->SetCodecConfigParameters(tmpBuf, 1) == -1);
// Garbage data. // Garbage data.
VIDEO_TEST(dec->SetCodecConfigParameters(tmpBuf, sizeof(tmpBuf)) == -1); EXPECT_TRUE(dec->SetCodecConfigParameters(tmpBuf, sizeof(tmpBuf)) == -1);
//----- Function tests ----- //----- Function tests -----
outFileName = "../../" + _source->GetName() + "-errResTest.yuv"; outFileName = webrtc::test::OutputPath() + _source->GetName() + "-errResTest.yuv";
outFile = fopen(outFileName.c_str(), "wb"); outFile = fopen(outFileName.c_str(), "wb");
VIDEO_TEST_EXIT_ON_ERR(outFile != NULL); ASSERT_TRUE(outFile != NULL);
UnitTest::Perform(); UnitTest::Perform();
Teardown(); Teardown();