From e5f74bdbbc8d87a965244696bd5e6f6dfdaddee0 Mon Sep 17 00:00:00 2001 From: "phoglund@webrtc.org" Date: Fri, 30 Mar 2012 19:51:11 +0000 Subject: [PATCH] Rewrote the video sync test. BUG= TEST= Review URL: https://webrtc-codereview.appspot.com/463001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1969 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../auto_test/standard/video_sync_test.cc | 120 ++++++++++++++++++ .../main/test/auto_test/voe_standard_test.cc | 69 ---------- .../main/test/voice_engine_tests.gypi | 1 + 3 files changed, 121 insertions(+), 69 deletions(-) create mode 100644 src/voice_engine/main/test/auto_test/standard/video_sync_test.cc diff --git a/src/voice_engine/main/test/auto_test/standard/video_sync_test.cc b/src/voice_engine/main/test/auto_test/standard/video_sync_test.cc new file mode 100644 index 0000000000..d24be444a4 --- /dev/null +++ b/src/voice_engine/main/test/auto_test/standard/video_sync_test.cc @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include +#include +#include + +#include "voice_engine/main/test/auto_test/fixtures/after_streaming_fixture.h" + +#ifdef MAC_IPHONE + const int kMinimumReasonableDelayEstimateMs = 30; +#else + const int kMinimumReasonableDelayEstimateMs = 45; +#endif // !MAC_IPHONE + +class VideoSyncTest : public AfterStreamingFixture { + protected: + // This test will verify that delay estimates converge (e.g. the standard + // deviation for the last five seconds' estimates is less than 20) without + // manual observation. The test runs for 15 seconds, sampling once per second. + // All samples are checked so they are greater than |min_estimate|. + int CollectEstimatesDuring15Seconds(int min_estimate) { + Sleep(1000); + + std::vector all_delay_estimates; + for (int second = 0; second < 15; second++) { + int delay_estimate = 0; + EXPECT_EQ(0, voe_vsync_->GetDelayEstimate(channel_, delay_estimate)); + + EXPECT_GT(delay_estimate, min_estimate) << + "The delay estimate can not conceivably get lower than " << + min_estimate << " ms, it's unrealistic."; + + all_delay_estimates.push_back(delay_estimate); + Sleep(1000); + } + + return ComputeStandardDeviation( + all_delay_estimates.begin() + 10, all_delay_estimates.end()); + } + + void CheckEstimatesConvergeReasonablyWell(int min_estimate) { + int standard_deviation = CollectEstimatesDuring15Seconds(min_estimate); + EXPECT_LT(standard_deviation, 20); + } + + // Computes the standard deviation by first estimating the sample variance + // with an unbiased estimator. + int ComputeStandardDeviation(std::vector::const_iterator start, + std::vector::const_iterator end) const { + int num_elements = end - start; + int mean = std::accumulate(start, end, 0) / num_elements; + assert(num_elements > 1); + + int variance = 0; + for (; start != end; ++start) { + variance += (*start - mean) * (*start - mean) / (num_elements - 1); + } + return std::sqrt(variance); + } +}; + +TEST_F(VideoSyncTest, CanGetPlayoutTimestampWhilePlayingWithoutSettingItFirst) { + unsigned int ignored; + EXPECT_EQ(0, voe_vsync_->GetPlayoutTimestamp(channel_, ignored)); +} + +TEST_F(VideoSyncTest, CannotSetInitTimestampWhilePlaying) { + EXPECT_EQ(-1, voe_vsync_->SetInitTimestamp(channel_, 12345)); +} + +TEST_F(VideoSyncTest, CannotSetInitSequenceNumberWhilePlaying) { + EXPECT_EQ(-1, voe_vsync_->SetInitSequenceNumber(channel_, 123)); +} + +TEST_F(VideoSyncTest, CanSetInitTimestampWhileStopped) { + EXPECT_EQ(0, voe_base_->StopSend(channel_)); + EXPECT_EQ(0, voe_vsync_->SetInitTimestamp(channel_, 12345)); +} + +TEST_F(VideoSyncTest, CanSetInitSequenceNumberWhileStopped) { + EXPECT_EQ(0, voe_base_->StopSend(channel_)); + EXPECT_EQ(0, voe_vsync_->SetInitSequenceNumber(channel_, 123)); +} + +TEST_F(VideoSyncTest, DelayEstimatesStabilizeDuring15sAndAreNotTooLow) { + EXPECT_EQ(0, voe_base_->StopSend(channel_)); + EXPECT_EQ(0, voe_vsync_->SetInitTimestamp(channel_, 12345)); + EXPECT_EQ(0, voe_vsync_->SetInitSequenceNumber(channel_, 123)); + EXPECT_EQ(0, voe_base_->StartSend(channel_)); + + CheckEstimatesConvergeReasonablyWell(kMinimumReasonableDelayEstimateMs); +} + +TEST_F(VideoSyncTest, DelayEstimatesStabilizeAfterNetEqMinDelayChanges45s) { + EXPECT_EQ(0, voe_base_->StopSend(channel_)); + EXPECT_EQ(0, voe_vsync_->SetInitTimestamp(channel_, 12345)); + EXPECT_EQ(0, voe_vsync_->SetInitSequenceNumber(channel_, 123)); + EXPECT_EQ(0, voe_base_->StartSend(channel_)); + + CheckEstimatesConvergeReasonablyWell(kMinimumReasonableDelayEstimateMs); + EXPECT_EQ(0, voe_vsync_->SetMinimumPlayoutDelay(channel_, 200)); + CheckEstimatesConvergeReasonablyWell(kMinimumReasonableDelayEstimateMs); + EXPECT_EQ(0, voe_vsync_->SetMinimumPlayoutDelay(channel_, 0)); + CheckEstimatesConvergeReasonablyWell(kMinimumReasonableDelayEstimateMs); +} + +#if !defined(WEBRTC_ANDROID) +TEST_F(VideoSyncTest, CanGetPlayoutBufferSize) { + int ignored; + EXPECT_EQ(0, voe_vsync_->GetPlayoutBufferSize(ignored)); +} +#endif // !ANDROID diff --git a/src/voice_engine/main/test/auto_test/voe_standard_test.cc b/src/voice_engine/main/test/auto_test/voe_standard_test.cc index 771932b587..6fcecd942b 100644 --- a/src/voice_engine/main/test/auto_test/voe_standard_test.cc +++ b/src/voice_engine/main/test/auto_test/voe_standard_test.cc @@ -942,75 +942,6 @@ int VoETestManager::DoStandardTest() { if (TestStartStreaming(channel0_transport) != 0) return -1; if (TestStartPlaying() != 0) return -1; - ////////////// - // Video Sync - -#ifdef _TEST_VIDEO_SYNC_ - TEST_LOG("\n\n+++ Video sync tests +++\n\n"); - - unsigned int val; - TEST_MUSTPASS(voe_vsync_->GetPlayoutTimestamp(0, val)); - TEST_LOG("Playout timestamp = %lu\n", (long unsigned int) val); - - TEST_LOG("Init timestamp and sequence number manually\n"); - TEST_MUSTPASS(!voe_vsync_->SetInitTimestamp(0, 12345)); - TEST_MUSTPASS(!voe_vsync_->SetInitSequenceNumber(0, 123)); - TEST_MUSTPASS(voe_base_->StopSend(0)); - TEST_MUSTPASS(voe_vsync_->SetInitTimestamp(0, 12345)); - TEST_MUSTPASS(voe_vsync_->SetInitSequenceNumber(0, 123)); - TEST_MUSTPASS(voe_base_->StartSend(0)); - if (voe_file_) { - TEST_LOG("Start playing a file as microphone again \n"); - TEST_MUSTPASS(voe_file_->StartPlayingFileAsMicrophone(0, - AudioFilename(), - true, - true)); - } - SLEEP(3000); - - TEST_LOG("Check delay estimates during 15 seconds, verify that " - "they stabilize during this time\n"); - int valInt = -1; - for (int i = 0; i < 15; i++) { - TEST_MUSTPASS(voe_vsync_->GetDelayEstimate(0, valInt)); - TEST_LOG("Delay estimate = %d ms\n", valInt); -#if defined(MAC_IPHONE) - TEST_MUSTPASS(valInt <= 30); -#else - TEST_MUSTPASS(valInt <= 45); // 45=20+25 => can't be this low -#endif - SLEEP(1000); - } - - TEST_LOG("Setting NetEQ min delay to 500 milliseconds and repeat " - "the test above\n"); - TEST_MUSTPASS(voe_vsync_->SetMinimumPlayoutDelay(0, 500)); - for (int i = 0; i < 15; i++) { - TEST_MUSTPASS(voe_vsync_->GetDelayEstimate(0, valInt)); - TEST_LOG("Delay estimate = %d ms\n", valInt); - TEST_MUSTPASS(valInt <= 45); - SLEEP(1000); - } - - TEST_LOG("Setting NetEQ min delay to 0 milliseconds and repeat" - " the test above\n"); - TEST_MUSTPASS(voe_vsync_->SetMinimumPlayoutDelay(0, 0)); - for (int i = 0; i < 15; i++) { - TEST_MUSTPASS(voe_vsync_->GetDelayEstimate(0, valInt)); - TEST_LOG("Delay estimate = %d ms\n", valInt); - TEST_MUSTPASS(valInt <= 45); - SLEEP(1000); - } - -#if (defined (_WIN32) || (defined(WEBRTC_LINUX)) && !defined(WEBRTC_ANDROID)) - valInt = -1; - TEST_MUSTPASS(voe_vsync_->GetPlayoutBufferSize(valInt)); - TEST_LOG("Soundcard buffer size = %d ms\n", valInt); -#endif -#else - TEST_LOG("\n\n+++ Video sync tests NOT ENABLED +++\n"); -#endif // #ifdef _TEST_VIDEO_SYNC_ - ////////////////// // External media diff --git a/src/voice_engine/main/test/voice_engine_tests.gypi b/src/voice_engine/main/test/voice_engine_tests.gypi index d41809881e..80a9fe2f29 100644 --- a/src/voice_engine/main/test/voice_engine_tests.gypi +++ b/src/voice_engine/main/test/voice_engine_tests.gypi @@ -53,6 +53,7 @@ 'auto_test/standard/rtp_rtcp_before_streaming_test.cc', 'auto_test/standard/rtp_rtcp_test.cc', 'auto_test/standard/voe_base_misc_test.cc', + 'auto_test/standard/video_sync_test.cc', 'auto_test/standard/volume_test.cc', 'auto_test/resource_manager.cc', 'auto_test/voe_cpu_test.cc',