Trigger a PLI if the duration of non-decodable frames exceeds a threshold.

BUG=1663
R=mikhal@webrtc.org, ronghuawu@chromium.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3975 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org
2013-05-07 19:16:33 +00:00
parent 8f86cc8712
commit ef14488d03
17 changed files with 392 additions and 135 deletions

View File

@ -70,10 +70,25 @@ class TestVCMReceiver : public ::testing::Test {
(frame_type == kFrameEmpty) ? 1 : 0,
clock_->TimeInMilliseconds());
int32_t ret = InsertPacketAndPop(0);
if (!complete) {
// Drop the second packet.
VCMPacket packet;
stream_generator_->PopPacket(&packet, 0);
}
clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
return ret;
}
bool DecodeNextFrame() {
int64_t render_time_ms = 0;
VCMEncodedFrame* frame = receiver_.FrameForDecoding(0, render_time_ms,
false, NULL);
if (!frame)
return false;
receiver_.ReleaseFrame(frame);
return true;
}
scoped_ptr<SimulatedClock> clock_;
VCMTiming timing_;
NullEventFactory event_factory_;
@ -85,28 +100,43 @@ class TestVCMReceiver : public ::testing::Test {
TEST_F(TestVCMReceiver, RenderBufferSize_AllComplete) {
EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
size_t num_of_frames = 10;
for (size_t i = 0; i < num_of_frames; ++i) {
int num_of_frames = 10;
for (int i = 0; i < num_of_frames; ++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
EXPECT_EQ(static_cast<int>(num_of_frames * kDefaultFramePeriodMs),
EXPECT_EQ(num_of_frames * kDefaultFramePeriodMs,
receiver_.RenderBufferSizeMs());
}
TEST_F(TestVCMReceiver, RenderBufferSize_SkipToKeyFrame) {
EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
const int kNumOfNonDecodableFrames = 2;
for (int i = 0; i < kNumOfNonDecodableFrames; ++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
const int kNumOfFrames = 10;
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
for (int i = 0; i < kNumOfFrames - 1; ++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
EXPECT_EQ((kNumOfFrames - 1) * kDefaultFramePeriodMs,
receiver_.RenderBufferSizeMs());
}
TEST_F(TestVCMReceiver, RenderBufferSize_NotAllComplete) {
EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
size_t num_of_frames = 10;
for (size_t i = 0; i < num_of_frames; ++i) {
int num_of_frames = 10;
for (int i = 0; i < num_of_frames; ++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
num_of_frames++;
EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
for (size_t i = 0; i < num_of_frames; ++i) {
for (int i = 0; i < num_of_frames; ++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
EXPECT_EQ(static_cast<int>(num_of_frames * kDefaultFramePeriodMs),
receiver_.RenderBufferSizeMs());
EXPECT_EQ((num_of_frames - 1) * kDefaultFramePeriodMs,
receiver_.RenderBufferSizeMs());
}
TEST_F(TestVCMReceiver, RenderBufferSize_NoKeyFrame) {
@ -126,4 +156,145 @@ TEST_F(TestVCMReceiver, RenderBufferSize_NoKeyFrame) {
EXPECT_EQ(0, receiver_.RenderBufferSizeMs());
}
TEST_F(TestVCMReceiver, NonDecodableDuration_Empty) {
// Enable NACK and with no RTT thresholds for disabling retransmission delay.
receiver_.SetNackMode(kNack, -1, -1);
const size_t kMaxNackListSize = 1000;
const int kMaxPacketAgeToNack = 1000;
const int kMaxNonDecodableDuration = 500;
const int kMinDelayMs = 500;
receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
kMaxNonDecodableDuration);
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
// Advance time until it's time to decode the key frame.
clock_->AdvanceTimeMilliseconds(kMinDelayMs);
EXPECT_TRUE(DecodeNextFrame());
uint16_t nack_list[kMaxNackListSize];
uint16_t nack_list_length = 0;
VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
&nack_list_length);
EXPECT_EQ(kNackOk, ret);
}
TEST_F(TestVCMReceiver, NonDecodableDuration_NoKeyFrame) {
// Enable NACK and with no RTT thresholds for disabling retransmission delay.
receiver_.SetNackMode(kNack, -1, -1);
const size_t kMaxNackListSize = 1000;
const int kMaxPacketAgeToNack = 1000;
const int kMaxNonDecodableDuration = 500;
receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
kMaxNonDecodableDuration);
const int kNumFrames = kDefaultFrameRate * kMaxNonDecodableDuration / 1000;
for (int i = 0; i < kNumFrames; ++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
uint16_t nack_list[kMaxNackListSize];
uint16_t nack_list_length = 0;
VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
&nack_list_length);
EXPECT_EQ(kNackKeyFrameRequest, ret);
}
TEST_F(TestVCMReceiver, NonDecodableDuration_OneIncomplete) {
// Enable NACK and with no RTT thresholds for disabling retransmission delay.
receiver_.SetNackMode(kNack, -1, -1);
const size_t kMaxNackListSize = 1000;
const int kMaxPacketAgeToNack = 1000;
const int kMaxNonDecodableDuration = 500;
const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
kMaxNonDecodableDuration + 500) / 1000;
const int kMinDelayMs = 500;
receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
kMaxNonDecodableDuration);
receiver_.SetMinReceiverDelay(kMinDelayMs);
int64_t key_frame_inserted = clock_->TimeInMilliseconds();
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
// Insert an incomplete frame.
EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
// Insert enough frames to have too long non-decodable sequence.
for (int i = 0; i < kMaxNonDecodableDurationFrames;
++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
// Advance time until it's time to decode the key frame.
clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
key_frame_inserted);
EXPECT_TRUE(DecodeNextFrame());
// Make sure we get a key frame request.
uint16_t nack_list[kMaxNackListSize];
uint16_t nack_list_length = 0;
VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
&nack_list_length);
EXPECT_EQ(kNackKeyFrameRequest, ret);
}
TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger) {
// Enable NACK and with no RTT thresholds for disabling retransmission delay.
receiver_.SetNackMode(kNack, -1, -1);
const size_t kMaxNackListSize = 1000;
const int kMaxPacketAgeToNack = 1000;
const int kMaxNonDecodableDuration = 500;
const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
kMaxNonDecodableDuration + 500) / 1000;
const int kMinDelayMs = 500;
receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
kMaxNonDecodableDuration);
receiver_.SetMinReceiverDelay(kMinDelayMs);
int64_t key_frame_inserted = clock_->TimeInMilliseconds();
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
// Insert an incomplete frame.
EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
// Insert all but one frame to not trigger a key frame request due to
// too long duration of non-decodable frames.
for (int i = 0; i < kMaxNonDecodableDurationFrames - 1;
++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
// Advance time until it's time to decode the key frame.
clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
key_frame_inserted);
EXPECT_TRUE(DecodeNextFrame());
// Make sure we don't get a key frame request since we haven't generated
// enough frames.
uint16_t nack_list[kMaxNackListSize];
uint16_t nack_list_length = 0;
VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
&nack_list_length);
EXPECT_EQ(kNackOk, ret);
}
TEST_F(TestVCMReceiver, NonDecodableDuration_KeyFrameAfterIncompleteFrames) {
// Enable NACK and with no RTT thresholds for disabling retransmission delay.
receiver_.SetNackMode(kNack, -1, -1);
const size_t kMaxNackListSize = 1000;
const int kMaxPacketAgeToNack = 1000;
const int kMaxNonDecodableDuration = 500;
const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate *
kMaxNonDecodableDuration + 500) / 1000;
const int kMinDelayMs = 500;
receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack,
kMaxNonDecodableDuration);
receiver_.SetMinReceiverDelay(kMinDelayMs);
int64_t key_frame_inserted = clock_->TimeInMilliseconds();
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
// Insert an incomplete frame.
EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError);
// Insert enough frames to have too long non-decodable sequence.
for (int i = 0; i < kMaxNonDecodableDurationFrames;
++i) {
EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError);
}
EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError);
// Advance time until it's time to decode the key frame.
clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() -
key_frame_inserted);
EXPECT_TRUE(DecodeNextFrame());
// Make sure we don't get a key frame request since we have a key frame
// in the list.
uint16_t nack_list[kMaxNackListSize];
uint16_t nack_list_length = 0;
VCMNackStatus ret = receiver_.NackList(nack_list, kMaxNackListSize,
&nack_list_length);
EXPECT_EQ(kNackOk, ret);
}
} // namespace webrtc