pkasting@chromium.org
2014-11-20 22:28:14 +00:00
parent edc6e57a92
commit 4591fbd09f
341 changed files with 2610 additions and 2613 deletions

View File

@ -218,7 +218,7 @@ bool FrameQueue::Empty()
return _frameBufferQueue.empty();
}
uint32_t VideoEncodeCompleteCallback::EncodedBytes()
size_t VideoEncodeCompleteCallback::EncodedBytes()
{
return _encodedBytes;
}
@ -251,7 +251,7 @@ VideoEncodeCompleteCallback::Encoded(EncodedImage& encodedImage,
return 0;
}
uint32_t VideoDecodeCompleteCallback::DecodedBytes()
size_t VideoDecodeCompleteCallback::DecodedBytes()
{
return _decodedBytes;
}

View File

@ -153,12 +153,12 @@ public:
Encoded(webrtc::EncodedImage& encodedImage,
const webrtc::CodecSpecificInfo* codecSpecificInfo = NULL,
const webrtc::RTPFragmentationHeader* fragmentation = NULL);
uint32_t EncodedBytes();
size_t EncodedBytes();
private:
FILE* _encodedFile;
FrameQueue* _frameQueue;
NormalAsyncTest& _test;
uint32_t _encodedBytes;
size_t _encodedBytes;
};
class VideoDecodeCompleteCallback : public webrtc::DecodedImageCallback
@ -176,11 +176,11 @@ public:
ReceivedDecodedReferenceFrame(const uint64_t pictureId);
virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId);
uint32_t DecodedBytes();
size_t DecodedBytes();
private:
FILE* _decodedFile;
NormalAsyncTest& _test;
uint32_t _decodedBytes;
size_t _decodedBytes;
};
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_FRAMEWORK_NORMAL_ASYNC_TEST_H_

View File

@ -92,8 +92,8 @@ PacketLossTest::Decoded(const I420VideoFrame& decodedImage)
_frameQueue.pop_front();
// save image for future freeze-frame
unsigned int length = CalcBufferSize(kI420, decodedImage.width(),
decodedImage.height());
size_t length =
CalcBufferSize(kI420, decodedImage.width(), decodedImage.height());
if (_lastFrameLength < length)
{
if (_lastFrame) delete [] _lastFrame;
@ -189,7 +189,7 @@ int PacketLossTest::DoPacketLoss()
newEncBuf.VerifyAndAllocate(_lengthSourceFrame);
_inBufIdx = 0;
_outBufIdx = 0;
int size = 1;
size_t size = 1;
int kept = 0;
int thrown = 0;
while ((size = NextPacket(1500, &packet)) > 0)
@ -204,7 +204,7 @@ int PacketLossTest::DoPacketLoss()
// Use the ByteLoss function if you want to lose only
// parts of a packet, and not the whole packet.
//int size2 = ByteLoss(size, packet, 15);
//size_t size2 = ByteLoss(size, packet, 15);
thrown++;
//if (size2 != size)
//{
@ -227,28 +227,27 @@ int PacketLossTest::DoPacketLoss()
//printf("Encoded left: %d bytes\n", _encodedVideoBuffer.Length());
}
int PacketLossTest::NextPacket(int mtu, unsigned char **pkg)
size_t PacketLossTest::NextPacket(size_t mtu, unsigned char **pkg)
{
unsigned char *buf = _frameToDecode->_frame->Buffer();
*pkg = buf + _inBufIdx;
if (static_cast<long>(_frameToDecode->_frame->Length()) - _inBufIdx <= mtu)
{
int size = _frameToDecode->_frame->Length() - _inBufIdx;
_inBufIdx = _frameToDecode->_frame->Length();
return size;
}
_inBufIdx += mtu;
return mtu;
size_t old_idx = _inBufIdx;
_inBufIdx = std::min(_inBufIdx + mtu, _frameToDecode->_frame->Length());
return _inBufIdx - old_idx;
}
int PacketLossTest::ByteLoss(int size, unsigned char *pkg, int bytesToLose)
size_t PacketLossTest::ByteLoss(size_t size,
unsigned char *pkg,
size_t bytesToLose)
{
return size;
}
void PacketLossTest::InsertPacket(VideoFrame *buf, unsigned char *pkg, int size)
void PacketLossTest::InsertPacket(VideoFrame *buf,
unsigned char *pkg,
size_t size)
{
if (static_cast<long>(buf->Size()) - _outBufIdx < size)
if ((_outBufIdx + size) > buf->Size())
{
printf("InsertPacket error!\n");
return;

View File

@ -34,12 +34,15 @@ protected:
virtual void Teardown();
virtual void CodecSpecific_InitBitrate();
virtual int DoPacketLoss();
virtual int NextPacket(int size, unsigned char **pkg);
virtual int ByteLoss(int size, unsigned char *pkg, int bytesToLose);
virtual void InsertPacket(webrtc::VideoFrame *buf, unsigned char *pkg,
int size);
int _inBufIdx;
int _outBufIdx;
virtual size_t NextPacket(size_t mtu, unsigned char **pkg);
virtual size_t ByteLoss(size_t size,
unsigned char *pkg,
size_t bytesToLose);
virtual void InsertPacket(webrtc::VideoFrame *buf,
unsigned char *pkg,
size_t size);
size_t _inBufIdx;
size_t _outBufIdx;
// When NACK is being simulated _lossProbabilty is zero,
// otherwise it is set equal to _lossRate.
@ -50,10 +53,10 @@ protected:
int _totalKept;
int _totalThrown;
int _sumChannelBytes;
size_t _sumChannelBytes;
std::list<uint32_t> _frameQueue;
uint8_t* _lastFrame;
uint32_t _lastFrameLength;
size_t _lastFrameLength;
};

View File

@ -48,8 +48,8 @@ protected:
webrtc::VideoEncoder* _encoder;
webrtc::VideoDecoder* _decoder;
uint32_t _bitRate;
unsigned int _lengthSourceFrame;
uint32_t _bitRate;
size_t _lengthSourceFrame;
unsigned char* _sourceBuffer;
webrtc::I420VideoFrame _inputVideoBuffer;
// TODO(mikhal): For now using VideoFrame for encodedBuffer, should use a
@ -61,7 +61,7 @@ protected:
std::string _inname;
std::string _outname;
std::string _encodedName;
int _sumEncBytes;
size_t _sumEncBytes;
int _width;
int _halfWidth;
int _height;

View File

@ -146,7 +146,7 @@ UnitTestDecodeCompleteCallback::DecodeComplete()
return false;
}
uint32_t
size_t
UnitTest::WaitForEncodedFrame() const
{
int64_t startTime = TickTime::MillisecondTimestamp();
@ -160,7 +160,7 @@ UnitTest::WaitForEncodedFrame() const
return 0;
}
uint32_t
size_t
UnitTest::WaitForDecodedFrame() const
{
int64_t startTime = TickTime::MillisecondTimestamp();
@ -225,8 +225,8 @@ UnitTest::Setup()
_inst.codecSpecific.VP8.denoisingOn = true;
// Get input frame.
ASSERT_TRUE(fread(_refFrame, 1, _lengthSourceFrame, _sourceFile)
== _lengthSourceFrame);
ASSERT_EQ(_lengthSourceFrame,
fread(_refFrame, 1, _lengthSourceFrame, _sourceFile));
int size_y = _inst.width * _inst.height;
int size_uv = ((_inst.width + 1) / 2) * ((_inst.height + 1) / 2);
_inputVideoBuffer.CreateFrame(size_y, _refFrame,
@ -244,7 +244,7 @@ UnitTest::Setup()
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(_inputVideoBuffer, NULL, NULL);
_refEncFrameLength = WaitForEncodedFrame();
ASSERT_TRUE(_refEncFrameLength > 0);
ASSERT_GT(_refEncFrameLength, 0u);
_refEncFrame = new unsigned char[_refEncFrameLength];
memcpy(_refEncFrame, _encodedVideoBuffer.Buffer(), _refEncFrameLength);
@ -255,7 +255,7 @@ UnitTest::Setup()
EXPECT_TRUE(_decoder->InitDecode(&_inst, 1) == WEBRTC_VIDEO_CODEC_OK);
ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK);
unsigned int frameLength = 0;
size_t frameLength = 0;
int i = 0;
_inputVideoBuffer.CreateEmptyFrame(_inst.width, _inst.height, _inst.width,
(_inst.width + 1) / 2,
@ -266,12 +266,12 @@ UnitTest::Setup()
if (i > 0)
{
// Insert yet another frame.
ASSERT_TRUE(fread(_refFrame, 1, _lengthSourceFrame,
_sourceFile) == _lengthSourceFrame);
ASSERT_EQ(_lengthSourceFrame,
fread(_refFrame, 1, _lengthSourceFrame, _sourceFile));
EXPECT_EQ(0, ConvertToI420(kI420, _refFrame, 0, 0, _width, _height,
0, kRotateNone, &_inputVideoBuffer));
_encoder->Encode(_inputVideoBuffer, NULL, NULL);
ASSERT_TRUE(WaitForEncodedFrame() > 0);
ASSERT_GT(WaitForEncodedFrame(), 0u);
} else {
// The first frame is always a key frame.
encodedImage._frameType = kKeyFrame;
@ -285,7 +285,7 @@ UnitTest::Setup()
i++;
}
rewind(_sourceFile);
EXPECT_TRUE(frameLength == _lengthSourceFrame);
EXPECT_EQ(_lengthSourceFrame, frameLength);
ExtractBuffer(_decodedVideoBuffer, _lengthSourceFrame, _refDecFrame);
}
@ -324,9 +324,9 @@ UnitTest::DecodeWithoutAssert()
EncodedImage encodedImage;
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
int ret = _decoder->Decode(encodedImage, 0, NULL);
int frameLength = WaitForDecodedFrame();
size_t frameLength = WaitForDecodedFrame();
_encodedVideoBuffer.SetLength(0);
return ret == WEBRTC_VIDEO_CODEC_OK ? frameLength : ret;
return ret == WEBRTC_VIDEO_CODEC_OK ? static_cast<int>(frameLength) : ret;
}
int
@ -343,13 +343,11 @@ UnitTest::Decode()
}
int ret = _decoder->Decode(encodedImage, 0, NULL);
unsigned int frameLength = WaitForDecodedFrame();
assert(ret == WEBRTC_VIDEO_CODEC_OK && (frameLength == 0 || frameLength
== _lengthSourceFrame));
EXPECT_TRUE(ret == WEBRTC_VIDEO_CODEC_OK && (frameLength == 0 || frameLength
== _lengthSourceFrame));
size_t frameLength = WaitForDecodedFrame();
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, ret);
EXPECT_TRUE(frameLength == 0 || frameLength == _lengthSourceFrame);
_encodedVideoBuffer.SetLength(0);
return ret == WEBRTC_VIDEO_CODEC_OK ? frameLength : ret;
return ret == WEBRTC_VIDEO_CODEC_OK ? static_cast<int>(frameLength) : ret;
}
// Test pure virtual VideoEncoder and VideoDecoder APIs.
@ -357,7 +355,7 @@ void
UnitTest::Perform()
{
UnitTest::Setup();
int frameLength;
size_t frameLength;
I420VideoFrame inputImage;
EncodedImage encodedImage;
@ -448,21 +446,21 @@ UnitTest::Perform()
std::vector<VideoFrameType> frame_types(1, frame_type);
EXPECT_TRUE(_encoder->Encode(_inputVideoBuffer, NULL, &frame_types) ==
WEBRTC_VIDEO_CODEC_OK);
EXPECT_TRUE(WaitForEncodedFrame() > 0);
EXPECT_GT(WaitForEncodedFrame(), 0u);
}
// Init then encode.
_encodedVideoBuffer.SetLength(0);
EXPECT_TRUE(_encoder->Encode(_inputVideoBuffer, NULL, NULL) ==
WEBRTC_VIDEO_CODEC_OK);
EXPECT_TRUE(WaitForEncodedFrame() > 0);
EXPECT_GT(WaitForEncodedFrame(), 0u);
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(_inputVideoBuffer, NULL, NULL);
frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0);
EXPECT_GT(frameLength, 0u);
EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
_encodedVideoBuffer.Buffer(), frameLength) == true);
_encodedVideoBuffer.Buffer(), frameLength));
// Reset then encode.
_encodedVideoBuffer.SetLength(0);
@ -472,9 +470,9 @@ UnitTest::Perform()
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(_inputVideoBuffer, NULL, NULL);
frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0);
EXPECT_GT(frameLength, 0u);
EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
_encodedVideoBuffer.Buffer(), frameLength) == true);
_encodedVideoBuffer.Buffer(), frameLength));
// Release then encode.
_encodedVideoBuffer.SetLength(0);
@ -485,9 +483,9 @@ UnitTest::Perform()
EXPECT_TRUE(_encoder->InitEncode(&_inst, 1, 1440) == WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(_inputVideoBuffer, NULL, NULL);
frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0);
EXPECT_GT(frameLength, 0u);
EXPECT_TRUE(CheckIfBitExact(_refEncFrame, _refEncFrameLength,
_encodedVideoBuffer.Buffer(), frameLength) == true);
_encodedVideoBuffer.Buffer(), frameLength));
//----- Decoder parameter tests -----
@ -522,8 +520,8 @@ UnitTest::Perform()
ASSERT_FALSE(SetCodecSpecificParameters() != WEBRTC_VIDEO_CODEC_OK);
for (int i = 0; i < 100; i++)
{
ASSERT_TRUE(fread(tmpBuf, 1, _refEncFrameLength, _sourceFile)
== _refEncFrameLength);
ASSERT_EQ(_refEncFrameLength,
fread(tmpBuf, 1, _refEncFrameLength, _sourceFile));
_encodedVideoBuffer.CopyFrame(_refEncFrameLength, tmpBuf);
VideoEncodedBufferToEncodedImage(_encodedVideoBuffer, encodedImage);
int ret = _decoder->Decode(encodedImage, false, NULL);
@ -564,12 +562,12 @@ UnitTest::Perform()
_decoder->Decode(encodedImage, false, NULL);
frameLength = WaitForDecodedFrame();
}
unsigned int length = CalcBufferSize(kI420, width, height);
size_t length = CalcBufferSize(kI420, width, height);
scoped_ptr<uint8_t[]> decoded_buffer(new uint8_t[length]);
ExtractBuffer(_decodedVideoBuffer, _lengthSourceFrame,
decoded_buffer.get());
EXPECT_TRUE(CheckIfBitExact(decoded_buffer.get(), frameLength, _refDecFrame,
_lengthSourceFrame) == true);
_lengthSourceFrame));
// Reset then decode.
EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
@ -583,7 +581,7 @@ UnitTest::Perform()
ExtractBuffer(_decodedVideoBuffer, _lengthSourceFrame,
decoded_buffer.get());
EXPECT_TRUE(CheckIfBitExact(decoded_buffer.get(), frameLength,
_refDecFrame, _lengthSourceFrame) == true);
_refDecFrame, _lengthSourceFrame));
// Decode with other size, reset, then decode with original size again
// to verify that decoder is reset to a "fresh" state upon Reset().
@ -614,7 +612,7 @@ UnitTest::Perform()
tempInst.width, tmpHalfWidth, tmpHalfWidth);
_encoder->Encode(tempInput, NULL, NULL);
frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0);
EXPECT_GT(frameLength, 0u);
// Reset then decode.
EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
frameLength = 0;
@ -631,7 +629,7 @@ UnitTest::Perform()
WEBRTC_VIDEO_CODEC_OK);
_encoder->Encode(_inputVideoBuffer, NULL, NULL);
frameLength = WaitForEncodedFrame();
EXPECT_TRUE(frameLength > 0);
EXPECT_GT(frameLength, 0u);
// Reset then decode original frame again.
EXPECT_TRUE(_decoder->Reset() == WEBRTC_VIDEO_CODEC_OK);
@ -644,11 +642,11 @@ UnitTest::Perform()
}
// check that decoded frame matches with reference
unsigned int length = CalcBufferSize(kI420, width, height);
size_t length = CalcBufferSize(kI420, width, height);
scoped_ptr<uint8_t[]> decoded_buffer(new uint8_t[length]);
ExtractBuffer(_decodedVideoBuffer, length, decoded_buffer.get());
EXPECT_TRUE(CheckIfBitExact(decoded_buffer.get(), length,
_refDecFrame, _lengthSourceFrame) == true);
_refDecFrame, _lengthSourceFrame));
}
// Release then decode.
@ -664,7 +662,7 @@ UnitTest::Perform()
}
ExtractBuffer(_decodedVideoBuffer, length, decoded_buffer.get());
EXPECT_TRUE(CheckIfBitExact(decoded_buffer.get(), frameLength,
_refDecFrame, _lengthSourceFrame) == true);
_refDecFrame, _lengthSourceFrame));
_encodedVideoBuffer.SetLength(0);
delete [] tmpBuf;
@ -697,8 +695,7 @@ UnitTest::Perform()
ASSERT_TRUE(_encoder->Encode(_inputVideoBuffer, NULL, NULL) ==
WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForEncodedFrame();
//ASSERT_TRUE(frameLength);
EXPECT_TRUE(frameLength > 0);
EXPECT_GT(frameLength, 0u);
encTimeStamp = _encodedVideoBuffer.TimeStamp();
EXPECT_TRUE(_inputVideoBuffer.timestamp() ==
static_cast<unsigned>(encTimeStamp));
@ -707,8 +704,7 @@ UnitTest::Perform()
is_key_frame_ = true;
}
frameLength = Decode();
if (frameLength == 0)
if (Decode() == 0)
{
frameDelay++;
}
@ -735,7 +731,7 @@ UnitTest::RateControlTests()
{
int frames = 0;
VideoFrame inputImage;
uint32_t frameLength;
size_t frameLength;
// Do not specify maxBitRate (as in ViE).
_inst.maxBitrate = 0;
@ -754,7 +750,7 @@ UnitTest::RateControlTests()
for (int i = 0; i < nBitrates; i++)
{
_bitRate = bitRate[i];
int totalBytes = 0;
size_t totalBytes = 0;
_inst.startBitrate = _bitRate;
_encoder->InitEncode(&_inst, 4, 1440);
_decoder->Reset();
@ -789,27 +785,26 @@ UnitTest::RateControlTests()
ASSERT_EQ(_encoder->Encode(_inputVideoBuffer, NULL, NULL),
WEBRTC_VIDEO_CODEC_OK);
frameLength = WaitForEncodedFrame();
ASSERT_GE(frameLength, 0u);
totalBytes += frameLength;
frames++;
_encodedVideoBuffer.SetLength(0);
}
uint32_t actualBitrate =
(totalBytes / frames * _inst.maxFramerate * 8)/1000;
printf("Target bitrate: %d kbps, actual bitrate: %d kbps\n", _bitRate,
actualBitrate);
uint32_t actualBitrate = static_cast<uint32_t>(
(totalBytes / frames * _inst.maxFramerate * 8) / 1000);
printf("Target bitrate: %u kbps, actual bitrate: %u kbps\n", _bitRate,
actualBitrate);
// Test for close match over reasonable range.
EXPECT_TRUE(abs(int32_t(actualBitrate - _bitRate)) <
0.12 * _bitRate);
EXPECT_LT(abs(static_cast<int32_t>(actualBitrate - _bitRate)),
0.12 * _bitRate);
ASSERT_TRUE(feof(_sourceFile) != 0);
rewind(_sourceFile);
}
}
bool
UnitTest::CheckIfBitExact(const void* ptrA, unsigned int aLengthBytes,
const void* ptrB, unsigned int bLengthBytes)
UnitTest::CheckIfBitExact(const void* ptrA, size_t aLengthBytes,
const void* ptrB, size_t bLengthBytes)
{
if (aLengthBytes != bLengthBytes)
{

View File

@ -48,11 +48,11 @@ protected:
virtual int DecodeWithoutAssert();
virtual int SetCodecSpecificParameters() {return 0;};
virtual bool CheckIfBitExact(const void *ptrA, unsigned int aLengthBytes,
const void *ptrB, unsigned int bLengthBytes);
virtual bool CheckIfBitExact(const void *ptrA, size_t aLengthBytes,
const void *ptrB, size_t bLengthBytes);
uint32_t WaitForEncodedFrame() const;
uint32_t WaitForDecodedFrame() const;
size_t WaitForEncodedFrame() const;
size_t WaitForDecodedFrame() const;
int _tests;
int _errors;
@ -61,7 +61,7 @@ protected:
unsigned char* _refFrame;
unsigned char* _refEncFrame;
unsigned char* _refDecFrame;
unsigned int _refEncFrameLength;
size_t _refEncFrameLength;
FILE* _sourceFile;
bool is_key_frame_;

View File

@ -116,7 +116,7 @@ VideoSource::GetSize(uint16_t width, uint16_t height)
return kUndefined;
}
unsigned int
size_t
VideoSource::GetFrameLength() const
{
return webrtc::CalcBufferSize(_type, _width, _height);

View File

@ -71,7 +71,7 @@ public:
VideoSize GetSize() const;
static VideoSize GetSize(uint16_t width, uint16_t height);
unsigned int GetFrameLength() const;
size_t GetFrameLength() const;
// Returns a human-readable size string.
static const char* GetSizeString(VideoSize size);