Miscellaneous cleanups in VCMReceiver and its unit tests.

The most important change is to prevent a potential buffer overflow in
NackList(). It cannot happen if the |size| argument passed to NackList()
is consistent with the |max_nack_list_size| argument passed to
SetNackSettings(), and there is an assertion to check that. But it is
good to defend against this in the release build because assert() is
compiled away in the release build.

Remove the unused |master| parameter to the VCMReceiver constructor.

Remove the unused State() getter method and the corresponding state_
member.

Remove the declarations for the nonexistent GenerateReceiverId()
method and the receiver_id_counter_ member.

Remove the unneeded data_buffer_ member of TestVCMReceiver. It was
assigned to packet.dataPtr and then immediately overwritten by
stream_generator_->GetPacket() or stream_generator_->PopPacket().

R=stefan@webrtc.org
BUG=none
TEST=none

Review URL: https://webrtc-codereview.appspot.com/51119004

Cr-Commit-Position: refs/heads/master@{#9318}
This commit is contained in:
Wan-Teh Chang
2015-05-28 13:36:06 -07:00
parent 645299d4e0
commit 92d9489881
4 changed files with 8 additions and 32 deletions

View File

@ -24,17 +24,15 @@ namespace webrtc {
class TestVCMReceiver : public ::testing::Test {
protected:
enum { kDataBufferSize = 10 };
enum { kWidth = 640 };
enum { kHeight = 480 };
TestVCMReceiver()
: clock_(new SimulatedClock(0)),
timing_(clock_.get()),
receiver_(&timing_, clock_.get(), &event_factory_, true) {
receiver_(&timing_, clock_.get(), &event_factory_) {
stream_generator_.reset(new
StreamGenerator(0, 0, clock_->TimeInMilliseconds()));
memset(data_buffer_, 0, kDataBufferSize);
}
virtual void SetUp() {
@ -43,18 +41,15 @@ class TestVCMReceiver : public ::testing::Test {
int32_t InsertPacket(int index) {
VCMPacket packet;
packet.dataPtr = data_buffer_;
bool packet_available = stream_generator_->GetPacket(&packet, index);
EXPECT_TRUE(packet_available);
if (!packet_available)
return kGeneralError; // Return here to avoid crashes below.
// Arbitrary width and height.
return receiver_.InsertPacket(packet, 640, 480);
return receiver_.InsertPacket(packet, kWidth, kHeight);
}
int32_t InsertPacketAndPop(int index) {
VCMPacket packet;
packet.dataPtr = data_buffer_;
bool packet_available = stream_generator_->PopPacket(&packet, index);
EXPECT_TRUE(packet_available);
if (!packet_available)
@ -94,7 +89,6 @@ class TestVCMReceiver : public ::testing::Test {
NullEventFactory event_factory_;
VCMReceiver receiver_;
rtc::scoped_ptr<StreamGenerator> stream_generator_;
uint8_t data_buffer_[kDataBufferSize];
};
TEST_F(TestVCMReceiver, RenderBufferSize_AllComplete) {