diff --git a/webrtc/video_engine/stream_synchronization.cc b/webrtc/video_engine/stream_synchronization.cc index a7e3b25b6..48eb36a5c 100644 --- a/webrtc/video_engine/stream_synchronization.cc +++ b/webrtc/video_engine/stream_synchronization.cc @@ -249,13 +249,15 @@ bool StreamSynchronization::ComputeDelays(int relative_delay_ms, } void StreamSynchronization::SetTargetBufferingDelay(int target_delay_ms) { + // Initial extra delay for audio (accounting for existing extra delay). + channel_delay_->extra_audio_delay_ms += + target_delay_ms - base_target_delay_ms_; + // The video delay is compared to the last value (and how much we can update + // is limited by that as well). + channel_delay_->last_video_delay_ms += + target_delay_ms - base_target_delay_ms_; // Video is already delayed by the desired amount. base_target_delay_ms_ = target_delay_ms; - // Setting initial extra delay for audio. - channel_delay_->extra_audio_delay_ms += target_delay_ms; - // The video delay is compared to the last value (and how much we can updated - // is limited by that as well). - channel_delay_->last_video_delay_ms += target_delay_ms; } } // namespace webrtc diff --git a/webrtc/video_engine/stream_synchronization_unittest.cc b/webrtc/video_engine/stream_synchronization_unittest.cc index 49629f56a..44cb146d2 100644 --- a/webrtc/video_engine/stream_synchronization_unittest.cc +++ b/webrtc/video_engine/stream_synchronization_unittest.cc @@ -490,6 +490,27 @@ TEST_F(StreamSynchronizationTest, BaseDelay) { &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); + // 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); + // 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); } TEST_F(StreamSynchronizationTest, BothDelayedAudioLaterWithBaseDelay) {