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

@ -18,8 +18,6 @@
namespace webrtc {
enum { kI420HeaderSize = 4 };
class I420Encoder : public VideoEncoder {
public:
I420Encoder();
@ -38,7 +36,7 @@ class I420Encoder : public VideoEncoder {
// <0 - Error
virtual int InitEncode(const VideoCodec* codecSettings,
int /*numberOfCores*/,
uint32_t /*maxPayloadSize*/) OVERRIDE;
size_t /*maxPayloadSize*/) OVERRIDE;
// "Encode" an I420 image (as a part of a video stream). The encoded image
// will be returned to the user via the encode complete callback.

View File

@ -15,6 +15,10 @@
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
namespace {
const size_t kI420HeaderSize = 4;
}
namespace webrtc {
I420Encoder::I420Encoder() : _inited(false), _encodedImage(),
@ -39,7 +43,7 @@ int I420Encoder::Release() {
int I420Encoder::InitEncode(const VideoCodec* codecSettings,
int /*numberOfCores*/,
uint32_t /*maxPayloadSize */) {
size_t /*maxPayloadSize */) {
if (codecSettings == NULL) {
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
@ -53,10 +57,9 @@ int I420Encoder::InitEncode(const VideoCodec* codecSettings,
_encodedImage._buffer = NULL;
_encodedImage._size = 0;
}
const uint32_t newSize = CalcBufferSize(kI420,
codecSettings->width,
codecSettings->height)
+ kI420HeaderSize;
const size_t newSize =
CalcBufferSize(kI420, codecSettings->width, codecSettings->height) +
kI420HeaderSize;
uint8_t* newBuffer = new uint8_t[newSize];
if (newBuffer == NULL) {
return WEBRTC_VIDEO_CODEC_MEMORY;
@ -95,9 +98,10 @@ int I420Encoder::Encode(const I420VideoFrame& inputImage,
return WEBRTC_VIDEO_CODEC_ERR_SIZE;
}
int req_length = CalcBufferSize(kI420, inputImage.width(),
inputImage.height()) + kI420HeaderSize;
if (_encodedImage._size > static_cast<unsigned int>(req_length)) {
size_t req_length =
CalcBufferSize(kI420, inputImage.width(), inputImage.height()) +
kI420HeaderSize;
if (_encodedImage._size > req_length) {
// Reallocate buffer.
delete [] _encodedImage._buffer;
@ -194,8 +198,7 @@ int I420Decoder::Decode(const EncodedImage& inputImage, bool /*missingFrames*/,
_height = height;
// Verify that the available length is sufficient:
uint32_t req_length = CalcBufferSize(kI420, _width, _height)
+ kI420HeaderSize;
size_t req_length = CalcBufferSize(kI420, _width, _height) + kI420HeaderSize;
if (req_length > inputImage._length) {
return WEBRTC_VIDEO_CODEC_ERROR;

View File

@ -31,7 +31,7 @@ class MockVideoEncoder : public VideoEncoder {
MOCK_CONST_METHOD2(Version, int32_t(int8_t *version, int32_t length));
MOCK_METHOD3(InitEncode, int32_t(const VideoCodec* codecSettings,
int32_t numberOfCores,
uint32_t maxPayloadSize));
size_t maxPayloadSize));
MOCK_METHOD3(Encode, int32_t(const I420VideoFrame& inputImage,
const CodecSpecificInfo* codecSpecificInfo,
const std::vector<VideoFrameType>* frame_types));

View File

@ -13,6 +13,8 @@
#include <assert.h>
#include <stdio.h>
#include "webrtc/base/format_macros.h"
namespace webrtc {
namespace test {
@ -72,7 +74,7 @@ int PacketManipulatorImpl::ManipulatePackets(
// Must set completeFrame to false to inform the decoder about this:
encoded_image->_completeFrame = false;
if (verbose_) {
printf("Dropped %d packets for frame %d (frame length: %d)\n",
printf("Dropped %d packets for frame %d (frame length: %" PRIuS ")\n",
nbr_packets_dropped, encoded_image->_timeStamp,
encoded_image->_length);
}

View File

@ -42,11 +42,11 @@ struct NetworkingConfig {
}
// Packet size in bytes. Default: 1500 bytes.
int packet_size_in_bytes;
size_t packet_size_in_bytes;
// Encoder specific setting of maximum size in bytes of each payload.
// Default: 1440 bytes.
int max_payload_size_in_bytes;
size_t max_payload_size_in_bytes;
// Packet loss mode. Two different packet loss models are supported:
// uniform or burst. This setting has no effect unless

View File

@ -60,11 +60,11 @@ class PacketManipulatorTest: public PacketRelatedTest {
void VerifyPacketLoss(int expected_nbr_packets_dropped,
int actual_nbr_packets_dropped,
int expected_packet_data_length,
size_t expected_packet_data_length,
uint8_t* expected_packet_data,
EncodedImage& actual_image) {
EXPECT_EQ(expected_nbr_packets_dropped, actual_nbr_packets_dropped);
EXPECT_EQ(expected_packet_data_length, static_cast<int>(image_._length));
EXPECT_EQ(expected_packet_data_length, image_._length);
EXPECT_EQ(0, memcmp(expected_packet_data, actual_image._buffer,
expected_packet_data_length));
}
@ -82,7 +82,7 @@ TEST_F(PacketManipulatorTest, DropNone) {
}
TEST_F(PacketManipulatorTest, UniformDropNoneSmallFrame) {
int data_length = 400; // smaller than the packet size
size_t data_length = 400; // smaller than the packet size
image_._length = data_length;
PacketManipulatorImpl manipulator(&packet_reader_, no_drop_config_, false);
int nbr_packets_dropped = manipulator.ManipulatePackets(&image_);
@ -120,7 +120,7 @@ TEST_F(PacketManipulatorTest, UniformDropSinglePacket) {
TEST_F(PacketManipulatorTest, BurstDropNinePackets) {
// Create a longer packet data structure (10 packets)
const int kNbrPackets = 10;
const int kDataLength = kPacketSizeInBytes * kNbrPackets;
const size_t kDataLength = kPacketSizeInBytes * kNbrPackets;
uint8_t data[kDataLength];
uint8_t* data_pointer = data;
// Fill with 0s, 1s and so on to be able to easily verify which were dropped:

View File

@ -15,6 +15,8 @@
#include <algorithm> // min_element, max_element
#include "webrtc/base/format_macros.h"
namespace webrtc {
namespace test {
@ -70,11 +72,11 @@ void Stats::PrintSummary() {
// Calculate min, max, average and total encoding time
int total_encoding_time_in_us = 0;
int total_decoding_time_in_us = 0;
int total_encoded_frames_lengths = 0;
int total_encoded_key_frames_lengths = 0;
int total_encoded_nonkey_frames_lengths = 0;
int nbr_keyframes = 0;
int nbr_nonkeyframes = 0;
size_t total_encoded_frames_lengths = 0;
size_t total_encoded_key_frames_lengths = 0;
size_t total_encoded_nonkey_frames_lengths = 0;
size_t nbr_keyframes = 0;
size_t nbr_nonkeyframes = 0;
for (FrameStatisticsIterator it = stats_.begin();
it != stats_.end(); ++it) {
@ -141,23 +143,24 @@ void Stats::PrintSummary() {
printf("Frame sizes:\n");
frame = std::min_element(stats_.begin(),
stats_.end(), LessForEncodedSize);
printf(" Min : %7d bytes (frame %d)\n",
printf(" Min : %7" PRIuS " bytes (frame %d)\n",
frame->encoded_frame_length_in_bytes, frame->frame_number);
frame = std::max_element(stats_.begin(),
stats_.end(), LessForEncodedSize);
printf(" Max : %7d bytes (frame %d)\n",
printf(" Max : %7" PRIuS " bytes (frame %d)\n",
frame->encoded_frame_length_in_bytes, frame->frame_number);
printf(" Average : %7d bytes\n",
static_cast<int>(total_encoded_frames_lengths / stats_.size()));
printf(" Average : %7" PRIuS " bytes\n",
total_encoded_frames_lengths / stats_.size());
if (nbr_keyframes > 0) {
printf(" Average key frame size : %7d bytes (%d keyframes)\n",
total_encoded_key_frames_lengths / nbr_keyframes,
nbr_keyframes);
printf(" Average key frame size : %7" PRIuS " bytes (%" PRIuS
" keyframes)\n",
total_encoded_key_frames_lengths / nbr_keyframes, nbr_keyframes);
}
if (nbr_nonkeyframes > 0) {
printf(" Average non-key frame size: %7d bytes (%d frames)\n",
printf(" Average non-key frame size: %7" PRIuS " bytes (%" PRIuS
" frames)\n",
total_encoded_nonkey_frames_lengths / nbr_nonkeyframes,
nbr_nonkeyframes);
}

View File

@ -31,14 +31,14 @@ struct FrameStatistic {
int frame_number;
// How many packets were discarded of the encoded frame data (if any).
int packets_dropped;
int total_packets;
size_t total_packets;
// Current bit rate. Calculated out of the size divided with the time
// interval per frame.
int bit_rate_in_kbps;
// Copied from EncodedImage
int encoded_frame_length_in_bytes;
size_t encoded_frame_length_in_bytes;
webrtc::VideoFrameType frame_type;
};

View File

@ -30,7 +30,7 @@ TestConfig::TestConfig()
output_dir("out"),
networking_config(),
exclude_frame_types(kExcludeOnlyFirstKeyFrame),
frame_length_in_bytes(-1),
frame_length_in_bytes(0),
use_single_core(false),
keyframe_interval(0),
codec_settings(NULL),
@ -157,7 +157,7 @@ void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
num_spatial_resizes_ = 0;
}
int VideoProcessorImpl::EncodedFrameSize() {
size_t VideoProcessorImpl::EncodedFrameSize() {
return encoded_frame_size_;
}
@ -330,11 +330,12 @@ void VideoProcessorImpl::FrameDecoded(const I420VideoFrame& image) {
frame_number, ret_val);
}
// TODO(mikhal): Extracting the buffer for now - need to update test.
int length = CalcBufferSize(kI420, up_image.width(), up_image.height());
size_t length = CalcBufferSize(kI420, up_image.width(), up_image.height());
scoped_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
length = ExtractBuffer(up_image, length, image_buffer.get());
int extracted_length = ExtractBuffer(up_image, length, image_buffer.get());
assert(extracted_length > 0);
// Update our copy of the last successful frame:
memcpy(last_successful_frame_buffer_, image_buffer.get(), length);
memcpy(last_successful_frame_buffer_, image_buffer.get(), extracted_length);
bool write_success = frame_writer_->WriteFrame(image_buffer.get());
assert(write_success);
if (!write_success) {
@ -343,11 +344,11 @@ void VideoProcessorImpl::FrameDecoded(const I420VideoFrame& image) {
} else { // No resize.
// Update our copy of the last successful frame:
// TODO(mikhal): Add as a member function, so won't be allocated per frame.
int length = CalcBufferSize(kI420, image.width(), image.height());
size_t length = CalcBufferSize(kI420, image.width(), image.height());
scoped_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
length = ExtractBuffer(image, length, image_buffer.get());
assert(length > 0);
memcpy(last_successful_frame_buffer_, image_buffer.get(), length);
int extracted_length = ExtractBuffer(image, length, image_buffer.get());
assert(extracted_length > 0);
memcpy(last_successful_frame_buffer_, image_buffer.get(), extracted_length);
bool write_success = frame_writer_->WriteFrame(image_buffer.get());
assert(write_success);

View File

@ -76,7 +76,7 @@ struct TestConfig {
// The length of a single frame of the input video file. This value is
// calculated out of the width and height according to the video format
// specification. Must be set before processing.
int frame_length_in_bytes;
size_t frame_length_in_bytes;
// Force the encoder and decoder to use a single core for processing.
// Using a single core is necessary to get a deterministic behavior for the
@ -144,7 +144,7 @@ class VideoProcessor {
// Return the size of the encoded frame in bytes. Dropped frames by the
// encoder are regarded as zero size.
virtual int EncodedFrameSize() = 0;
virtual size_t EncodedFrameSize() = 0;
// Return the number of dropped frames.
virtual int NumberDroppedFrames() = 0;
@ -178,7 +178,7 @@ class VideoProcessorImpl : public VideoProcessor {
// Updates the encoder with the target bit rate and the frame rate.
virtual void SetRates(int bit_rate, int frame_rate) OVERRIDE;
// Return the size of the encoded frame in bytes.
virtual int EncodedFrameSize() OVERRIDE;
virtual size_t EncodedFrameSize() OVERRIDE;
// Return the number of dropped frames.
virtual int NumberDroppedFrames() OVERRIDE;
// Return the number of spatial resizes.
@ -206,7 +206,7 @@ class VideoProcessorImpl : public VideoProcessor {
bool last_frame_missing_;
// If Init() has executed successfully.
bool initialized_;
int encoded_frame_size_;
size_t encoded_frame_size_;
int prev_time_stamp_;
int num_dropped_frames_;
int num_spatial_resizes_;

View File

@ -266,8 +266,7 @@ class VideoProcessorIntegrationTest: public testing::Test {
// For every encoded frame, update the rate control metrics.
void UpdateRateControlMetrics(int frame_num, VideoFrameType frame_type) {
int encoded_frame_size = processor_->EncodedFrameSize();
float encoded_size_kbits = encoded_frame_size * 8.0f / 1000.0f;
float encoded_size_kbits = processor_->EncodedFrameSize() * 8.0f / 1000.0f;
// Update layer data.
// Update rate mismatch relative to per-frame bandwidth for delta frames.
if (frame_type == kDeltaFrame) {

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);

View File

@ -20,6 +20,7 @@
#endif
#include "gflags/gflags.h"
#include "webrtc/base/format_macros.h"
#include "webrtc/common_types.h"
#include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h"
#include "webrtc/modules/video_coding/codecs/test/stats.h"
@ -204,7 +205,8 @@ int HandleCommandLineFlags(webrtc::test::TestConfig* config) {
FLAGS_packet_size);
return 7;
}
config->networking_config.packet_size_in_bytes = FLAGS_packet_size;
config->networking_config.packet_size_in_bytes =
static_cast<size_t>(FLAGS_packet_size);
if (FLAGS_max_payload_size <= 0) {
fprintf(stderr, "Max payload size must be >0 bytes, was: %d\n",
@ -212,7 +214,7 @@ int HandleCommandLineFlags(webrtc::test::TestConfig* config) {
return 8;
}
config->networking_config.max_payload_size_in_bytes =
FLAGS_max_payload_size;
static_cast<size_t>(FLAGS_max_payload_size);
// Check the width and height
if (FLAGS_width <= 0 || FLAGS_height <= 0) {
@ -290,10 +292,10 @@ void PrintConfigurationSummary(const webrtc::test::TestConfig& config) {
Log(" Input filename : %s\n", config.input_filename.c_str());
Log(" Output directory : %s\n", config.output_dir.c_str());
Log(" Output filename : %s\n", config.output_filename.c_str());
Log(" Frame length : %d bytes\n", config.frame_length_in_bytes);
Log(" Packet size : %d bytes\n",
Log(" Frame length : %" PRIuS " bytes\n", config.frame_length_in_bytes);
Log(" Packet size : %" PRIuS " bytes\n",
config.networking_config.packet_size_in_bytes);
Log(" Max payload size : %d bytes\n",
Log(" Max payload size : %" PRIuS " bytes\n",
config.networking_config.max_payload_size_in_bytes);
Log(" Packet loss:\n");
Log(" Mode : %s\n",
@ -320,8 +322,8 @@ void PrintCsvOutput(const webrtc::test::Stats& stats,
const webrtc::test::FrameStatistic& f = stats.stats_[i];
const webrtc::test::FrameResult& ssim = ssim_result.frames[i];
const webrtc::test::FrameResult& psnr = psnr_result.frames[i];
printf("%4d, %d, %d, %2d, %2d, %6d, %6d, %5d, %7d, %d, %2d, %2d, "
"%5.3f, %5.2f\n",
printf("%4d, %d, %d, %2d, %2d, %6d, %6d, %5d, %7" PRIuS ", %d, %2d, %2"
PRIuS ", %5.3f, %5.2f\n",
f.frame_number,
f.encoding_successful,
f.decoding_successful,
@ -352,13 +354,13 @@ void PrintPythonOutput(const webrtc::test::TestConfig& config,
"{'name': 'input_filename', 'value': '%s'},\n"
"{'name': 'output_filename', 'value': '%s'},\n"
"{'name': 'output_dir', 'value': '%s'},\n"
"{'name': 'packet_size_in_bytes', 'value': '%d'},\n"
"{'name': 'max_payload_size_in_bytes', 'value': '%d'},\n"
"{'name': 'packet_size_in_bytes', 'value': '%" PRIuS "'},\n"
"{'name': 'max_payload_size_in_bytes', 'value': '%" PRIuS "'},\n"
"{'name': 'packet_loss_mode', 'value': '%s'},\n"
"{'name': 'packet_loss_probability', 'value': '%f'},\n"
"{'name': 'packet_loss_burst_length', 'value': '%d'},\n"
"{'name': 'exclude_frame_types', 'value': '%s'},\n"
"{'name': 'frame_length_in_bytes', 'value': '%d'},\n"
"{'name': 'frame_length_in_bytes', 'value': '%" PRIuS "'},\n"
"{'name': 'use_single_core', 'value': '%s'},\n"
"{'name': 'keyframe_interval;', 'value': '%d'},\n"
"{'name': 'video_codec_type', 'value': '%s'},\n"
@ -411,9 +413,9 @@ void PrintPythonOutput(const webrtc::test::TestConfig& config,
"'encoding_successful': %s, 'decoding_successful': %s, "
"'encode_time': %d, 'decode_time': %d, "
"'encode_return_code': %d, 'decode_return_code': %d, "
"'bit_rate': %d, 'encoded_frame_length': %d, 'frame_type': %s, "
"'packets_dropped': %d, 'total_packets': %d, "
"'ssim': %f, 'psnr': %f},\n",
"'bit_rate': %d, 'encoded_frame_length': %" PRIuS ", "
"'frame_type': %s, 'packets_dropped': %d, "
"'total_packets': %" PRIuS ", 'ssim': %f, 'psnr': %f},\n",
f.frame_number,
f.encoding_successful ? "True " : "False",
f.decoding_successful ? "True " : "False",

View File

@ -148,7 +148,7 @@ class TestVp8Impl : public ::testing::Test {
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1));
}
int WaitForEncodedFrame() const {
size_t WaitForEncodedFrame() const {
int64_t startTime = TickTime::MillisecondTimestamp();
while (TickTime::MillisecondTimestamp() - startTime < kMaxWaitEncTimeMs) {
if (encode_complete_callback_->EncodeComplete()) {
@ -158,7 +158,7 @@ class TestVp8Impl : public ::testing::Test {
return 0;
}
int WaitForDecodedFrame() const {
size_t WaitForDecodedFrame() const {
int64_t startTime = TickTime::MillisecondTimestamp();
while (TickTime::MillisecondTimestamp() - startTime < kMaxWaitDecTimeMs) {
if (decode_complete_callback_->DecodeComplete()) {
@ -188,7 +188,7 @@ class TestVp8Impl : public ::testing::Test {
scoped_ptr<VideoDecoder> decoder_;
VideoFrame encoded_video_frame_;
I420VideoFrame decoded_video_frame_;
unsigned int length_source_frame_;
size_t length_source_frame_;
VideoCodec codec_inst_;
};
@ -239,14 +239,14 @@ TEST_F(TestVp8Impl, EncoderParameterTest) {
TEST_F(TestVp8Impl, DISABLED_ON_ANDROID(AlignedStrideEncodeDecode)) {
SetUpEncodeDecode();
encoder_->Encode(input_frame_, NULL, NULL);
EXPECT_GT(WaitForEncodedFrame(), 0);
EXPECT_GT(WaitForEncodedFrame(), 0u);
EncodedImage encodedImage;
VideoFrameToEncodedImage(encoded_video_frame_, encodedImage);
// First frame should be a key frame.
encodedImage._frameType = kKeyFrame;
encodedImage.ntp_time_ms_ = kTestNtpTimeMs;
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Decode(encodedImage, false, NULL));
EXPECT_GT(WaitForDecodedFrame(), 0);
EXPECT_GT(WaitForDecodedFrame(), 0u);
// Compute PSNR on all planes (faster than SSIM).
EXPECT_GT(I420PSNR(&input_frame_, &decoded_video_frame_), 36);
EXPECT_EQ(kTestTimestamp, decoded_video_frame_.timestamp());
@ -256,7 +256,7 @@ TEST_F(TestVp8Impl, DISABLED_ON_ANDROID(AlignedStrideEncodeDecode)) {
TEST_F(TestVp8Impl, DISABLED_ON_ANDROID(DecodeWithACompleteKeyFrame)) {
SetUpEncodeDecode();
encoder_->Encode(input_frame_, NULL, NULL);
EXPECT_GT(WaitForEncodedFrame(), 0);
EXPECT_GT(WaitForEncodedFrame(), 0u);
EncodedImage encodedImage;
VideoFrameToEncodedImage(encoded_video_frame_, encodedImage);
// Setting complete to false -> should return an error.

View File

@ -116,7 +116,7 @@ int VP8EncoderImpl::SetRates(uint32_t new_bitrate_kbit,
int VP8EncoderImpl::InitEncode(const VideoCodec* inst,
int number_of_cores,
uint32_t /*max_payload_size*/) {
size_t /*max_payload_size*/) {
if (inst == NULL) {
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
@ -791,7 +791,7 @@ int VP8DecoderImpl::DecodePartitions(
for (int i = 0; i < fragmentation->fragmentationVectorSize; ++i) {
const uint8_t* partition = input_image._buffer +
fragmentation->fragmentationOffset[i];
const uint32_t partition_length =
const size_t partition_length =
fragmentation->fragmentationLength[i];
if (vpx_codec_decode(decoder_,
partition,

View File

@ -39,7 +39,7 @@ class VP8EncoderImpl : public VP8Encoder {
virtual int InitEncode(const VideoCodec* codec_settings,
int number_of_cores,
uint32_t max_payload_size);
size_t max_payload_size);
virtual int Encode(const I420VideoFrame& input_image,
const CodecSpecificInfo* codec_specific_info,

View File

@ -30,11 +30,11 @@ class Vp8SequenceCoderEncodeCallback : public webrtc::EncodedImageCallback {
const webrtc::RTPFragmentationHeader*);
// Returns the encoded image.
webrtc::EncodedImage encoded_image() { return encoded_image_; }
int encoded_bytes() { return encoded_bytes_; }
size_t encoded_bytes() { return encoded_bytes_; }
private:
webrtc::EncodedImage encoded_image_;
FILE* encoded_file_;
int encoded_bytes_;
size_t encoded_bytes_;
};
Vp8SequenceCoderEncodeCallback::~Vp8SequenceCoderEncodeCallback() {
@ -141,7 +141,7 @@ int SequenceCoder(webrtc::test::CommandLineParser& parser) {
}
EXPECT_EQ(0, decoder->InitDecode(&inst, 1));
webrtc::I420VideoFrame input_frame;
unsigned int length = webrtc::CalcBufferSize(webrtc::kI420, width, height);
size_t length = webrtc::CalcBufferSize(webrtc::kI420, width, height);
webrtc::scoped_ptr<uint8_t[]> frame_buffer(new uint8_t[length]);
int half_width = (width + 1) / 2;
@ -175,9 +175,8 @@ int SequenceCoder(webrtc::test::CommandLineParser& parser) {
int64_t totalExecutionTime = endtime - starttime;
printf("Total execution time: %.2lf ms\n",
static_cast<double>(totalExecutionTime));
int sum_enc_bytes = encoder_callback.encoded_bytes();
double actual_bit_rate = 8.0 * sum_enc_bytes /
(frame_cnt / inst.maxFramerate);
double actual_bit_rate =
8.0 * encoder_callback.encoded_bytes() / (frame_cnt / inst.maxFramerate);
printf("Actual bitrate: %f kbps\n", actual_bit_rate / 1000);
webrtc::test::QualityMetricsResult psnr_result, ssim_result;
EXPECT_EQ(0, webrtc::test::I420MetricsFromFiles(

View File

@ -103,7 +103,7 @@ int VP9EncoderImpl::SetRates(uint32_t new_bitrate_kbit,
int VP9EncoderImpl::InitEncode(const VideoCodec* inst,
int number_of_cores,
uint32_t /*max_payload_size*/) {
size_t /*max_payload_size*/) {
if (inst == NULL) {
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
@ -428,7 +428,7 @@ int VP9DecoderImpl::Decode(const EncodedImage& input_image,
}
if (vpx_codec_decode(decoder_,
buffer,
input_image._length,
static_cast<unsigned int>(input_image._length),
0,
VPX_DL_REALTIME)) {
return WEBRTC_VIDEO_CODEC_ERROR;

View File

@ -34,7 +34,7 @@ class VP9EncoderImpl : public VP9Encoder {
virtual int InitEncode(const VideoCodec* codec_settings,
int number_of_cores,
uint32_t max_payload_size) OVERRIDE;
size_t max_payload_size) OVERRIDE;
virtual int Encode(const I420VideoFrame& input_image,
const CodecSpecificInfo* codec_specific_info,