Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/video_coding/codecs/test/packet_manipulator.cc b/webrtc/modules/video_coding/codecs/test/packet_manipulator.cc
index f4ca92a..6e7139e 100644
--- a/webrtc/modules/video_coding/codecs/test/packet_manipulator.cc
+++ b/webrtc/modules/video_coding/codecs/test/packet_manipulator.cc
@@ -13,6 +13,8 @@
#include <assert.h>
#include <stdio.h>
+#include "webrtc/base/format_macros.h"
+
namespace webrtc {
namespace test {
@@ -72,7 +74,7 @@
// 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);
}
diff --git a/webrtc/modules/video_coding/codecs/test/packet_manipulator.h b/webrtc/modules/video_coding/codecs/test/packet_manipulator.h
index 0fafa22..69bc35b 100644
--- a/webrtc/modules/video_coding/codecs/test/packet_manipulator.h
+++ b/webrtc/modules/video_coding/codecs/test/packet_manipulator.h
@@ -42,11 +42,11 @@
}
// 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
diff --git a/webrtc/modules/video_coding/codecs/test/packet_manipulator_unittest.cc b/webrtc/modules/video_coding/codecs/test/packet_manipulator_unittest.cc
index 576d005..ace7bc0 100644
--- a/webrtc/modules/video_coding/codecs/test/packet_manipulator_unittest.cc
+++ b/webrtc/modules/video_coding/codecs/test/packet_manipulator_unittest.cc
@@ -60,11 +60,11 @@
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, 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, 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:
diff --git a/webrtc/modules/video_coding/codecs/test/stats.cc b/webrtc/modules/video_coding/codecs/test/stats.cc
index f6605f9..91a2f3c 100644
--- a/webrtc/modules/video_coding/codecs/test/stats.cc
+++ b/webrtc/modules/video_coding/codecs/test/stats.cc
@@ -15,6 +15,8 @@
#include <algorithm> // min_element, max_element
+#include "webrtc/base/format_macros.h"
+
namespace webrtc {
namespace test {
@@ -70,11 +72,11 @@
// 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 @@
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);
}
diff --git a/webrtc/modules/video_coding/codecs/test/stats.h b/webrtc/modules/video_coding/codecs/test/stats.h
index 2998773..8dc8f15 100644
--- a/webrtc/modules/video_coding/codecs/test/stats.h
+++ b/webrtc/modules/video_coding/codecs/test/stats.h
@@ -31,14 +31,14 @@
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;
};
diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
index 93738ca..412ec10 100644
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.cc
@@ -30,7 +30,7 @@
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 @@
num_spatial_resizes_ = 0;
}
-int VideoProcessorImpl::EncodedFrameSize() {
+size_t VideoProcessorImpl::EncodedFrameSize() {
return encoded_frame_size_;
}
@@ -330,11 +330,12 @@
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 @@
} 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);
diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor.h b/webrtc/modules/video_coding/codecs/test/videoprocessor.h
index 20bcab5..2cfde52 100644
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor.h
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor.h
@@ -76,7 +76,7 @@
// 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 @@
// 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 @@
// 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 @@
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_;
diff --git a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc
index 420ef59..0c423a7 100644
--- a/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc
+++ b/webrtc/modules/video_coding/codecs/test/videoprocessor_integrationtest.cc
@@ -266,8 +266,7 @@
// 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) {