Updated the sync module with a slow moving filter
Review URL: https://webrtc-codereview.appspot.com/1326008 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3884 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -25,6 +25,7 @@ enum { kMaxDelay = 1500 };
|
||||
enum { kDefaultAudioFrequency = 8000 };
|
||||
enum { kDefaultVideoFrequency = 90000 };
|
||||
const double kNtpFracPerMs = 4.294967296E6;
|
||||
static const int kSmoothingFilter = 4 * 2;
|
||||
|
||||
class Time {
|
||||
public:
|
||||
@ -160,13 +161,14 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
int video_delay_ms = base_target_delay + 100;
|
||||
int extra_audio_delay_ms = 0;
|
||||
int total_video_delay_ms = base_target_delay;
|
||||
int filtered_move = (audio_delay_ms - video_delay_ms) / kSmoothingFilter;
|
||||
|
||||
EXPECT_TRUE(DelayedStreams(audio_delay_ms,
|
||||
video_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms,
|
||||
&total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay + kMaxVideoDiffMs, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay + filtered_move, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
|
||||
current_audio_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
@ -180,7 +182,7 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms,
|
||||
&total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay + 2 * kMaxVideoDiffMs, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay + 2 * filtered_move, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
|
||||
current_audio_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
@ -194,8 +196,7 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms,
|
||||
&total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay + audio_delay_ms - video_delay_ms,
|
||||
total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay + 3 * filtered_move, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
|
||||
|
||||
// Simulate that NetEQ introduces some audio delay.
|
||||
@ -210,8 +211,9 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms,
|
||||
&total_video_delay_ms));
|
||||
EXPECT_EQ(audio_delay_ms - video_delay_ms + current_audio_delay_ms,
|
||||
total_video_delay_ms);
|
||||
filtered_move = 3 * filtered_move +
|
||||
(50 + audio_delay_ms - video_delay_ms) / kSmoothingFilter;
|
||||
EXPECT_EQ(base_target_delay + filtered_move, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
|
||||
|
||||
// Simulate that NetEQ reduces its delay.
|
||||
@ -226,8 +228,11 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms,
|
||||
&total_video_delay_ms));
|
||||
EXPECT_EQ(audio_delay_ms - video_delay_ms + current_audio_delay_ms,
|
||||
total_video_delay_ms);
|
||||
|
||||
filtered_move = filtered_move +
|
||||
(10 + audio_delay_ms - video_delay_ms) / kSmoothingFilter;
|
||||
|
||||
EXPECT_EQ(base_target_delay + filtered_move, total_video_delay_ms);
|
||||
EXPECT_EQ(base_target_delay, extra_audio_delay_ms);
|
||||
}
|
||||
|
||||
@ -245,7 +250,7 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
&total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay, total_video_delay_ms);
|
||||
// The audio delay is not allowed to change more than this in 1 second.
|
||||
EXPECT_EQ(base_target_delay + kMaxAudioDiffMs, extra_audio_delay_ms);
|
||||
EXPECT_GE(base_target_delay + kMaxAudioDiffMs, extra_audio_delay_ms);
|
||||
current_audio_delay_ms = extra_audio_delay_ms;
|
||||
int current_extra_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
@ -283,7 +288,7 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
current_extra_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
// Simulate that NetEQ for some reason reduced the delay.
|
||||
current_audio_delay_ms = base_target_delay + 170;
|
||||
current_audio_delay_ms = base_target_delay + 10;
|
||||
send_time_->IncreaseTimeMs(1000);
|
||||
receive_time_->IncreaseTimeMs(800);
|
||||
EXPECT_TRUE(DelayedStreams(audio_delay_ms,
|
||||
@ -302,7 +307,7 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
current_extra_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
// Simulate that NetEQ for some reason significantly increased the delay.
|
||||
current_audio_delay_ms = base_target_delay + 250;
|
||||
current_audio_delay_ms = base_target_delay + 350;
|
||||
send_time_->IncreaseTimeMs(1000);
|
||||
receive_time_->IncreaseTimeMs(800);
|
||||
EXPECT_TRUE(DelayedStreams(audio_delay_ms,
|
||||
@ -320,12 +325,13 @@ class StreamSynchronizationTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
int MaxAudioDelayIncrease(int current_audio_delay_ms, int delay_ms) {
|
||||
return std::min((delay_ms - current_audio_delay_ms) / 2,
|
||||
return std::min((delay_ms - current_audio_delay_ms) / kSmoothingFilter,
|
||||
static_cast<int>(kMaxAudioDiffMs));
|
||||
}
|
||||
|
||||
int MaxAudioDelayDecrease(int current_audio_delay_ms, int delay_ms) {
|
||||
return std::max((delay_ms - current_audio_delay_ms) / 2, -kMaxAudioDiffMs);
|
||||
return std::max((delay_ms - current_audio_delay_ms) / kSmoothingFilter,
|
||||
-kMaxAudioDiffMs);
|
||||
}
|
||||
|
||||
enum { kSendTimeOffsetMs = 98765 };
|
||||
@ -343,8 +349,8 @@ TEST_F(StreamSynchronizationTest, NoDelay) {
|
||||
int extra_audio_delay_ms = 0;
|
||||
int total_video_delay_ms = 0;
|
||||
|
||||
EXPECT_TRUE(DelayedStreams(0, 0, current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_FALSE(DelayedStreams(0, 0, current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(0, extra_audio_delay_ms);
|
||||
EXPECT_EQ(0, total_video_delay_ms);
|
||||
}
|
||||
@ -359,7 +365,7 @@ TEST_F(StreamSynchronizationTest, VideoDelay) {
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(0, extra_audio_delay_ms);
|
||||
// The video delay is not allowed to change more than this in 1 second.
|
||||
EXPECT_EQ(kMaxVideoDiffMs, total_video_delay_ms);
|
||||
EXPECT_EQ(delay_ms / kSmoothingFilter, total_video_delay_ms);
|
||||
|
||||
send_time_->IncreaseTimeMs(1000);
|
||||
receive_time_->IncreaseTimeMs(800);
|
||||
@ -369,7 +375,7 @@ TEST_F(StreamSynchronizationTest, VideoDelay) {
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(0, extra_audio_delay_ms);
|
||||
// The video delay is not allowed to change more than this in 1 second.
|
||||
EXPECT_EQ(2*kMaxVideoDiffMs, total_video_delay_ms);
|
||||
EXPECT_EQ(2 * delay_ms / kSmoothingFilter, total_video_delay_ms);
|
||||
|
||||
send_time_->IncreaseTimeMs(1000);
|
||||
receive_time_->IncreaseTimeMs(800);
|
||||
@ -380,7 +386,7 @@ TEST_F(StreamSynchronizationTest, VideoDelay) {
|
||||
EXPECT_EQ(0, extra_audio_delay_ms);
|
||||
// Enough time should have elapsed for the requested total video delay to be
|
||||
// equal to the relative delay between audio and video, i.e., we are in sync.
|
||||
EXPECT_EQ(delay_ms, total_video_delay_ms);
|
||||
EXPECT_EQ(3 * delay_ms / kSmoothingFilter, total_video_delay_ms);
|
||||
}
|
||||
|
||||
TEST_F(StreamSynchronizationTest, AudioDelay) {
|
||||
@ -393,7 +399,7 @@ TEST_F(StreamSynchronizationTest, AudioDelay) {
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(0, total_video_delay_ms);
|
||||
// The audio delay is not allowed to change more than this in 1 second.
|
||||
EXPECT_EQ(kMaxAudioDiffMs, extra_audio_delay_ms);
|
||||
EXPECT_EQ(delay_ms / kSmoothingFilter, extra_audio_delay_ms);
|
||||
current_audio_delay_ms = extra_audio_delay_ms;
|
||||
int current_extra_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
@ -423,7 +429,7 @@ TEST_F(StreamSynchronizationTest, AudioDelay) {
|
||||
current_extra_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
// Simulate that NetEQ for some reason reduced the delay.
|
||||
current_audio_delay_ms = 170;
|
||||
current_audio_delay_ms = 10;
|
||||
send_time_->IncreaseTimeMs(1000);
|
||||
receive_time_->IncreaseTimeMs(800);
|
||||
EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
|
||||
@ -438,7 +444,7 @@ TEST_F(StreamSynchronizationTest, AudioDelay) {
|
||||
current_extra_delay_ms = extra_audio_delay_ms;
|
||||
|
||||
// Simulate that NetEQ for some reason significantly increased the delay.
|
||||
current_audio_delay_ms = 250;
|
||||
current_audio_delay_ms = 350;
|
||||
send_time_->IncreaseTimeMs(1000);
|
||||
receive_time_->IncreaseTimeMs(800);
|
||||
EXPECT_TRUE(DelayedStreams(0, delay_ms, current_audio_delay_ms,
|
||||
@ -485,32 +491,29 @@ TEST_F(StreamSynchronizationTest, BaseDelay) {
|
||||
int extra_audio_delay_ms = 0;
|
||||
int total_video_delay_ms = base_target_delay_ms;
|
||||
sync_->SetTargetBufferingDelay(base_target_delay_ms);
|
||||
EXPECT_TRUE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay_ms, extra_audio_delay_ms);
|
||||
EXPECT_EQ(base_target_delay_ms, total_video_delay_ms);
|
||||
// We are in sync don't change.
|
||||
EXPECT_FALSE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
// Triggering another call with the same values. Delay should not be modified.
|
||||
base_target_delay_ms = 2000;
|
||||
current_audio_delay_ms = base_target_delay_ms;
|
||||
total_video_delay_ms = base_target_delay_ms;
|
||||
sync_->SetTargetBufferingDelay(base_target_delay_ms);
|
||||
EXPECT_TRUE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay_ms, extra_audio_delay_ms);
|
||||
EXPECT_EQ(base_target_delay_ms, total_video_delay_ms);
|
||||
// We are in sync don't change.
|
||||
EXPECT_FALSE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
// Changing delay value - intended to test this module only. In practice it
|
||||
// would take VoE time to adapt.
|
||||
base_target_delay_ms = 5000;
|
||||
current_audio_delay_ms = base_target_delay_ms;
|
||||
total_video_delay_ms = base_target_delay_ms;
|
||||
sync_->SetTargetBufferingDelay(base_target_delay_ms);
|
||||
EXPECT_TRUE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
EXPECT_EQ(base_target_delay_ms, extra_audio_delay_ms);
|
||||
EXPECT_EQ(base_target_delay_ms, total_video_delay_ms);
|
||||
// We are in sync don't change.
|
||||
EXPECT_FALSE(DelayedStreams(base_target_delay_ms, base_target_delay_ms,
|
||||
current_audio_delay_ms,
|
||||
&extra_audio_delay_ms, &total_video_delay_ms));
|
||||
}
|
||||
|
||||
TEST_F(StreamSynchronizationTest, BothDelayedAudioLaterWithBaseDelay) {
|
||||
|
||||
Reference in New Issue
Block a user