Fix mismatch between different NACK list lengths and packet buffers.

This is a second version of http://review.webrtc.org/1065006/ which passes the parameters via methods instead of via constructors.

BUG=1289

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3456 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org
2013-02-01 15:09:57 +00:00
parent b586507986
commit becf9c897c
36 changed files with 316 additions and 130 deletions

View File

@ -546,6 +546,13 @@ public:
virtual int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode,
DecodeErrors errorMode) = 0;
// Sets the maximum number of sequence numbers that we are allowed to NACK
// and the oldest sequence number that we will consider to NACK. If a
// sequence number older than |max_packet_age_to_nack| is missing
// a key frame will be requested.
virtual void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack) = 0;
// Enables recording of debugging information.
virtual int StartDebugRecording(const char* file_name_utf8) = 0;

View File

@ -41,10 +41,6 @@ namespace webrtc {
#define VCM_VP8_PAYLOAD_TYPE 120
#define VCM_I420_PAYLOAD_TYPE 124
enum VCMNackProperties {
kNackHistoryLength = 450
};
enum VCMVideoProtection {
kProtectionNack, // Both send-side and receive-side
kProtectionNackSender, // Send-side only

View File

@ -95,12 +95,14 @@ VCMJitterBuffer::VCMJitterBuffer(Clock* clock,
nack_mode_(kNoNack),
low_rtt_nack_threshold_ms_(-1),
high_rtt_nack_threshold_ms_(-1),
nack_seq_nums_internal_(),
nack_seq_nums_(),
nack_seq_nums_length_(0),
max_nack_list_size_(0),
max_packet_age_to_nack_(0),
waiting_for_key_frame_(false) {
memset(frame_buffers_, 0, sizeof(frame_buffers_));
memset(receive_statistics_, 0, sizeof(receive_statistics_));
memset(nack_seq_nums_internal_, -1, sizeof(nack_seq_nums_internal_));
for (int i = 0; i < kStartNumberOfFrames; i++) {
frame_buffers_[i] = new VCMFrameBuffer();
@ -144,11 +146,17 @@ void VCMJitterBuffer::CopyFrom(const VCMJitterBuffer& rhs) {
first_packet_ = rhs.first_packet_;
last_decoded_state_ = rhs.last_decoded_state_;
num_not_decodable_packets_ = rhs.num_not_decodable_packets_;
assert(max_nack_list_size_ == rhs.max_nack_list_size_);
assert(max_packet_age_to_nack_ == rhs.max_packet_age_to_nack_);
memcpy(receive_statistics_, rhs.receive_statistics_,
sizeof(receive_statistics_));
memcpy(nack_seq_nums_internal_, rhs.nack_seq_nums_internal_,
sizeof(nack_seq_nums_internal_));
memcpy(nack_seq_nums_, rhs.nack_seq_nums_, sizeof(nack_seq_nums_));
nack_seq_nums_internal_.resize(rhs.nack_seq_nums_internal_.size());
std::copy(rhs.nack_seq_nums_internal_.begin(),
rhs.nack_seq_nums_internal_.end(),
nack_seq_nums_internal_.begin());
nack_seq_nums_.resize(rhs.nack_seq_nums_.size());
std::copy(rhs.nack_seq_nums_.begin(), rhs.nack_seq_nums_.end(),
nack_seq_nums_.begin());
for (int i = 0; i < kMaxNumberOfFrames; i++) {
if (frame_buffers_[i] != NULL) {
delete frame_buffers_[i];
@ -810,6 +818,20 @@ void VCMJitterBuffer::SetNackMode(VCMNackMode mode,
}
}
void VCMJitterBuffer::SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack) {
CriticalSectionScoped cs(crit_sect_);
assert(max_packet_age_to_nack >= 0);
if (max_packet_age_to_nack <= 0) {
return;
}
max_nack_list_size_ = max_nack_list_size;
max_packet_age_to_nack_ = max_packet_age_to_nack;
nack_seq_nums_internal_.resize(max_packet_age_to_nack_);
std::fill(nack_seq_nums_internal_.begin(), nack_seq_nums_internal_.end(), -1);
nack_seq_nums_.resize(max_nack_list_size_);
}
VCMNackMode VCMJitterBuffer::nack_mode() const {
CriticalSectionScoped cs(crit_sect_);
return nack_mode_;
@ -861,8 +883,8 @@ uint16_t* VCMJitterBuffer::CreateNackList(uint16_t* nack_list_size,
number_of_seq_num = high_seq_num - low_seq_num;
}
if (number_of_seq_num > kNackHistoryLength) {
// NACK list has grown too big, flush and try to restart.
if (number_of_seq_num > max_packet_age_to_nack_) {
// Some of the missing packets are too old.
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceVideoCoding,
VCMId(vcm_id_, receiver_id_),
"Nack list too large, try to find a key frame and restart "
@ -872,14 +894,14 @@ uint16_t* VCMJitterBuffer::CreateNackList(uint16_t* nack_list_size,
// This NACK size will trigger a key frame request.
bool found_key_frame = false;
while (number_of_seq_num > kNackHistoryLength) {
while (number_of_seq_num > max_packet_age_to_nack_) {
found_key_frame = RecycleFramesUntilKeyFrame();
if (!found_key_frame) {
break;
}
// Check if we still have too many packets in the jitter buffer.
// Check if we are still missing too old sequence numbers.
low_seq_num = -1;
high_seq_num = -1;
GetLowHighSequenceNumbers(&low_seq_num, &high_seq_num);
@ -937,16 +959,15 @@ uint16_t* VCMJitterBuffer::CreateNackList(uint16_t* nack_list_size,
// Reaching thus far means we are going to update the NACK list
// When in hybrid mode, we use the soft NACKing feature.
if (nack_mode_ == kNackHybrid) {
nack_seq_nums_index = (*it)->BuildSoftNackList(nack_seq_nums_internal_,
number_of_seq_num,
nack_seq_nums_index,
rtt_ms_);
nack_seq_nums_index = (*it)->BuildSoftNackList(
&nack_seq_nums_internal_[0], number_of_seq_num,
nack_seq_nums_index, rtt_ms_);
} else {
// Used when the frame is being processed by the decoding thread
// don't need to use that info in this loop.
nack_seq_nums_index = (*it)->BuildHardNackList(nack_seq_nums_internal_,
number_of_seq_num,
nack_seq_nums_index);
nack_seq_nums_index = (*it)->BuildHardNackList(
&nack_seq_nums_internal_[0], number_of_seq_num,
nack_seq_nums_index);
}
}
}
@ -979,6 +1000,26 @@ uint16_t* VCMJitterBuffer::CreateNackList(uint16_t* nack_list_size,
*nack_list_size = empty_index;
}
if (*nack_list_size > max_nack_list_size_) {
// Too many packets missing. Better to skip ahead to the next key frame or
// to request one.
bool found_key_frame = RecycleFramesUntilKeyFrame();
if (!found_key_frame) {
// Set the last decoded sequence number to current high.
// This is to not get a large nack list again right away.
last_decoded_state_.SetSeqNum(static_cast<uint16_t>(high_seq_num));
// Set to trigger key frame signal.
*nack_list_size = 0xffff;
*list_extended = true;
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCoding, -1,
"\tNo key frame found, request one. nack_list_size: "
"%u", *nack_list_size);
} else {
*nack_list_size = 0;
}
return NULL;
}
if (*nack_list_size > nack_seq_nums_length_) {
// Larger list: NACK list was extended since the last call.
*list_extended = true;
@ -1006,7 +1047,7 @@ uint16_t* VCMJitterBuffer::CreateNackList(uint16_t* nack_list_size,
nack_seq_nums_length_ = *nack_list_size;
return nack_seq_nums_;
return &nack_seq_nums_[0];
}
int64_t VCMJitterBuffer::LastDecodedTimestamp() const {

View File

@ -12,6 +12,7 @@
#define WEBRTC_MODULES_VIDEO_CODING_MAIN_SOURCE_JITTER_BUFFER_H_
#include <list>
#include <vector>
#include "webrtc/modules/interface/module_common_types.h"
#include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
@ -49,8 +50,10 @@ struct VCMJitterSample {
class VCMJitterBuffer {
public:
VCMJitterBuffer(Clock* clock, int vcm_id = -1, int receiver_id = -1,
bool master = true);
VCMJitterBuffer(Clock* clock,
int vcm_id,
int receiver_id,
bool master);
virtual ~VCMJitterBuffer();
// Makes |this| a deep copy of |rhs|.
@ -144,6 +147,9 @@ class VCMJitterBuffer {
void SetNackMode(VCMNackMode mode, int low_rtt_nack_threshold_ms,
int high_rtt_nack_threshold_ms);
void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack);
// Returns the current NACK mode.
VCMNackMode nack_mode() const;
@ -259,9 +265,11 @@ class VCMJitterBuffer {
int low_rtt_nack_threshold_ms_;
int high_rtt_nack_threshold_ms_;
// Holds the internal NACK list (the missing sequence numbers).
int32_t nack_seq_nums_internal_[kNackHistoryLength];
uint16_t nack_seq_nums_[kNackHistoryLength];
std::vector<int> nack_seq_nums_internal_;
std::vector<uint16_t> nack_seq_nums_;
unsigned int nack_seq_nums_length_;
size_t max_nack_list_size_;
int max_packet_age_to_nack_; // Measured in sequence numbers.
bool waiting_for_key_frame_;
DISALLOW_COPY_AND_ASSIGN(VCMJitterBuffer);

View File

@ -146,10 +146,14 @@ class TestRunningJitterBuffer : public ::testing::Test {
virtual void SetUp() {
clock_.reset(new SimulatedClock(0));
jitter_buffer_ = new VCMJitterBuffer(clock_.get());
max_nack_list_size_ = 250;
oldest_packet_to_nack_ = 450;
jitter_buffer_ = new VCMJitterBuffer(clock_.get(), -1, -1, true);
stream_generator = new StreamGenerator(0, 0,
clock_->TimeInMilliseconds());
jitter_buffer_->Start();
jitter_buffer_->SetNackSettings(max_nack_list_size_,
oldest_packet_to_nack_);
memset(data_buffer_, 0, kDataBufferSize);
}
@ -223,6 +227,8 @@ class TestRunningJitterBuffer : public ::testing::Test {
VCMJitterBuffer* jitter_buffer_;
StreamGenerator* stream_generator;
scoped_ptr<SimulatedClock> clock_;
size_t max_nack_list_size_;
int oldest_packet_to_nack_;
uint8_t data_buffer_[kDataBufferSize];
};
@ -300,18 +306,19 @@ TEST_F(TestJitterBufferNack, TestEmptyPackets) {
EXPECT_TRUE(DecodeCompleteFrame());
}
TEST_F(TestJitterBufferNack, TestNackListFull) {
TEST_F(TestJitterBufferNack, TestNackTooOldPackets) {
// Insert a key frame and decode it.
InsertFrame(kVideoFrameKey);
EXPECT_TRUE(DecodeCompleteFrame());
// Generate and drop |kNackHistoryLength| packets to fill the NACK list.
DropFrame(kNackHistoryLength);
// Drop one frame and insert |kNackHistoryLength| to trigger NACKing a too
// old packet.
DropFrame(1);
// Insert a frame which should trigger a recycle until the next key frame.
InsertFrame(kVideoFrameDelta);
InsertFrames(oldest_packet_to_nack_, kVideoFrameDelta);
EXPECT_FALSE(DecodeCompleteFrame());
uint16_t nack_list_length = kNackHistoryLength;
uint16_t nack_list_length = max_nack_list_size_;
bool extended;
uint16_t* nack_list = jitter_buffer_->CreateNackList(&nack_list_length,
&extended);
@ -319,8 +326,47 @@ TEST_F(TestJitterBufferNack, TestNackListFull) {
EXPECT_TRUE(nack_list_length == 0xffff && nack_list == NULL);
InsertFrame(kVideoFrameDelta);
// Waiting for a key frame.
EXPECT_FALSE(DecodeCompleteFrame());
EXPECT_FALSE(DecodeFrame());
InsertFrame(kVideoFrameKey);
// The next complete continuous frame isn't a key frame, but we're waiting
// for one.
EXPECT_FALSE(DecodeCompleteFrame());
// Skipping ahead to the key frame.
EXPECT_TRUE(DecodeFrame());
}
TEST_F(TestJitterBufferNack, TestNackListFull) {
// Insert a key frame and decode it.
InsertFrame(kVideoFrameKey);
EXPECT_TRUE(DecodeCompleteFrame());
// Generate and drop |kNackHistoryLength| packets to fill the NACK list.
DropFrame(max_nack_list_size_);
// Insert a frame which should trigger a recycle until the next key frame.
InsertFrame(kVideoFrameDelta);
EXPECT_FALSE(DecodeCompleteFrame());
uint16_t nack_list_length = max_nack_list_size_;
bool extended;
uint16_t* nack_list = jitter_buffer_->CreateNackList(&nack_list_length,
&extended);
// Verify that the jitter buffer requests a key frame.
EXPECT_TRUE(nack_list_length == 0xffff && nack_list == NULL);
InsertFrame(kVideoFrameDelta);
// Waiting for a key frame.
EXPECT_FALSE(DecodeCompleteFrame());
EXPECT_FALSE(DecodeFrame());
InsertFrame(kVideoFrameKey);
// The next complete continuous frame isn't a key frame, but we're waiting
// for one.
EXPECT_FALSE(DecodeCompleteFrame());
// Skipping ahead to the key frame.
EXPECT_TRUE(DecodeFrame());
}
TEST_F(TestJitterBufferNack, TestNackBeforeDecode) {

View File

@ -345,6 +345,12 @@ void VCMReceiver::SetNackMode(VCMNackMode nackMode) {
}
}
void VCMReceiver::SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack) {
jitter_buffer_.SetNackSettings(max_nack_list_size,
max_packet_age_to_nack);
}
VCMNackMode VCMReceiver::NackMode() const {
CriticalSectionScoped cs(crit_sect_);
return jitter_buffer_.nack_mode();

View File

@ -59,6 +59,8 @@ class VCMReceiver {
// NACK.
void SetNackMode(VCMNackMode nackMode);
void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack);
VCMNackMode NackMode() const;
VCMNackStatus NackList(uint16_t* nackList, uint16_t* size);

View File

@ -68,6 +68,7 @@ _bitStreamBeforeDecoder(NULL),
_frameFromFile(),
_keyRequestMode(kKeyOnError),
_scheduleKeyRequest(false),
max_nack_list_size_(0),
_sendCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_encoder(),
@ -166,21 +167,27 @@ VideoCodingModuleImpl::Process()
}
// Packet retransmission requests
// TODO(holmer): Add API for changing Process interval and make sure it's
// disabled when NACK is off.
if (_retransmissionTimer.TimeUntilProcess() == 0)
{
_retransmissionTimer.Processed();
if (_packetRequestCallback != NULL)
{
WebRtc_UWord16 nackList[kNackHistoryLength];
WebRtc_UWord16 length = kNackHistoryLength;
const WebRtc_Word32 ret = NackList(nackList, length);
WebRtc_UWord16 length;
{
CriticalSectionScoped cs(_receiveCritSect);
length = max_nack_list_size_;
}
std::vector<uint16_t> nackList(length);
const WebRtc_Word32 ret = NackList(&nackList[0], length);
if (ret != VCM_OK && returnValue == VCM_OK)
{
returnValue = ret;
}
if (length > 0)
{
_packetRequestCallback->ResendPackets(nackList, length);
_packetRequestCallback->ResendPackets(&nackList[0], length);
}
}
}
@ -517,7 +524,6 @@ WebRtc_Word32
VideoCodingModuleImpl::SetVideoProtection(VCMVideoProtection videoProtection,
bool enable)
{
switch (videoProtection)
{
@ -1372,6 +1378,17 @@ int VideoCodingModuleImpl::SetReceiverRobustnessMode(
return VCM_OK;
}
void VideoCodingModuleImpl::SetNackSettings(
size_t max_nack_list_size, int max_packet_age_to_nack) {
if (max_nack_list_size != 0) {
CriticalSectionScoped cs(_receiveCritSect);
max_nack_list_size_ = max_nack_list_size;
}
_receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack);
_dualReceiver.SetNackSettings(max_nack_list_size,
max_packet_age_to_nack);
}
int VideoCodingModuleImpl::StartDebugRecording(const char* file_name_utf8) {
CriticalSectionScoped cs(_sendCritSect);
_encoderInputFile = fopen(file_name_utf8, "wb");

View File

@ -58,8 +58,7 @@ enum VCMKeyRequestMode
class VideoCodingModuleImpl : public VideoCodingModule
{
public:
VideoCodingModuleImpl(const WebRtc_Word32 id,
Clock* clock);
VideoCodingModuleImpl(const WebRtc_Word32 id, Clock* clock);
virtual ~VideoCodingModuleImpl();
@ -259,6 +258,10 @@ public:
// Set the receiver robustness mode.
virtual int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode,
DecodeErrors errorMode);
virtual void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack);
// Enables recording of debugging information.
virtual int StartDebugRecording(const char* file_name_utf8);
@ -295,6 +298,7 @@ private:
VCMFrameBuffer _frameFromFile;
VCMKeyRequestMode _keyRequestMode;
bool _scheduleKeyRequest;
size_t max_nack_list_size_;
CriticalSectionWrapper* _sendCritSect; // Critical section for send side
VCMGenericEncoder* _encoder;

View File

@ -46,6 +46,9 @@ class TestVideoCodingModule : public ::testing::Test {
false));
EXPECT_EQ(0, vcm_->RegisterExternalDecoder(&decoder_, kUnusedPayloadType,
true));
const size_t kMaxNackListSize = 250;
const int kMaxPacketAgeToNack = 450;
vcm_->SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack);
memset(&settings_, 0, sizeof(settings_));
EXPECT_EQ(0, vcm_->Codec(kVideoCodecVP8, &settings_));
settings_.numberOfSimulcastStreams = kNumberOfStreams;

View File

@ -37,6 +37,9 @@ class VCMRobustnessTest : public ::testing::Test {
vcm_ = VideoCodingModule::Create(0, clock_.get());
ASSERT_TRUE(vcm_ != NULL);
ASSERT_EQ(0, vcm_->InitializeReceiver());
const size_t kMaxNackListSize = 250;
const int kMaxPacketAgeToNack = 450;
vcm_->SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack);
ASSERT_EQ(0, vcm_->RegisterFrameTypeCallback(&frame_type_callback_));
ASSERT_EQ(0, vcm_->RegisterPacketRequestCallback(&request_callback_));
ASSERT_EQ(VCM_OK, vcm_->Codec(kVideoCodecVP8, &video_codec_));

View File

@ -106,7 +106,7 @@ int JitterBufferTest(CmdArgs& args)
WebRtc_UWord8 data[1500];
VCMPacket packet(data, size, seqNum, timeStamp, true);
VCMJitterBuffer jb(clock);
VCMJitterBuffer jb(clock, -1, -1, true);
seqNum = 1234;
timeStamp = 123*90;

View File

@ -239,7 +239,7 @@ int MTRxTxTest(CmdArgs& args)
FecProtectionParams delta_params = protectionCallback.DeltaFecParameters();
FecProtectionParams key_params = protectionCallback.KeyFecParameters();
rtp->SetFecParameters(&delta_params, &key_params);
rtp->SetNACKStatus(nackEnabled ? kNackRtcp : kNackOff);
rtp->SetNACKStatus(nackEnabled ? kNackRtcp : kNackOff, kMaxPacketAgeToNack);
vcm->SetChannelParameters((WebRtc_UWord32) bitRate,
(WebRtc_UWord8) lossRate, rttMS);

View File

@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "rtp_player.h"
#include "webrtc/modules/video_coding/main/test/rtp_player.h"
#include <cstdlib>
#ifdef WIN32
@ -18,9 +18,10 @@
#include <arpa/inet.h>
#endif
#include "../source/internal_defines.h"
#include "gtest/gtest.h"
#include "rtp_rtcp.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
#include "webrtc/modules/video_coding/main/source/internal_defines.h"
#include "webrtc/modules/video_coding/main/test/test_util.h"
#include "webrtc/system_wrappers/interface/clock.h"
using namespace webrtc;
@ -191,7 +192,8 @@ WebRtc_Word32 RTPPlayer::Initialize(const PayloadTypeList* payloadList)
_randVec[i] = rand();
}
_randVecPos = 0;
WebRtc_Word32 ret = _rtpModule->SetNACKStatus(kNackOff);
WebRtc_Word32 ret = _rtpModule->SetNACKStatus(kNackOff,
kMaxPacketAgeToNack);
if (ret < 0)
{
return -1;

View File

@ -22,6 +22,9 @@
#include "module_common_types.h"
#include "testsupport/fileutils.h"
enum { kMaxNackListSize = 250 };
enum { kMaxPacketAgeToNack = 450 };
// Class used for passing command line arguments to tests
class CmdArgs
{

View File

@ -194,6 +194,7 @@ int RtpPlay(CmdArgs& args)
vcm->SetVideoProtection(protectionMethod, protectionEnabled);
vcm->SetRenderDelay(renderDelayMs);
vcm->SetMinimumPlayoutDelay(minPlayoutDelayMs);
vcm->SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack);
ret = 0;

View File

@ -84,8 +84,7 @@ int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTe
protection == kProtectionNack ||
kProtectionNackFEC));
Clock* clock = Clock::GetRealTimeClock();
VideoCodingModule* vcm =
VideoCodingModule::Create(1, clock);
VideoCodingModule* vcm = VideoCodingModule::Create(1, clock);
RtpDataCallback dataCallback(vcm);
std::string rtpFilename;
rtpFilename = args.inputFile;
@ -227,6 +226,7 @@ int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTe
vcm->SetVideoProtection(protection, protectionEnabled);
vcm->SetRenderDelay(renderDelayMs);
vcm->SetMinimumPlayoutDelay(minPlayoutDelayMs);
vcm->SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack);
EventWrapper& waitEvent = *EventWrapper::Create();