From f4ff3f34e0f9daaffc99330e35d36f9533f3988d Mon Sep 17 00:00:00 2001 From: Per K Date: Wed, 29 May 2024 08:41:34 +0000 Subject: [PATCH] Ensure test capturer does not set ntp time This aligns with chromium capturer. https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/peerconnection/webrtc_video_track_source.cc;l=390-401;drc=c0265133106c7647e90f9aaa4377d28190b1a6a9?q=webrtc_video_track_source.cc&ss=chromium Bug: webrtc:42223979 Change-Id: Ibc60297e49e44b1d55a3869d68b20feba7aa38f8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/352660 Reviewed-by: Mirko Bonadei Commit-Queue: Per Kjellander Cr-Commit-Position: refs/heads/main@{#42401} --- call/call_perf_tests.cc | 156 ------------------------------- test/frame_generator_capturer.cc | 6 -- test/frame_generator_capturer.h | 4 - 3 files changed, 166 deletions(-) diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc index 15aaaa44aa..452d62cf43 100644 --- a/call/call_perf_tests.cc +++ b/call/call_perf_tests.cc @@ -405,162 +405,6 @@ TEST_F(CallPerfTest, DriftingClock::PercentsSlower(30.0f), "_video_faster"); } -void CallPerfTest::TestCaptureNtpTime( - const BuiltInNetworkBehaviorConfig& net_config, - int threshold_ms, - int start_time_ms, - int run_time_ms) { - class CaptureNtpTimeObserver : public test::EndToEndTest, - public rtc::VideoSinkInterface { - public: - CaptureNtpTimeObserver(const BuiltInNetworkBehaviorConfig& net_config, - int threshold_ms, - int start_time_ms, - int run_time_ms) - : EndToEndTest(test::VideoTestConstants::kLongTimeout), - net_config_(net_config), - clock_(Clock::GetRealTimeClock()), - threshold_ms_(threshold_ms), - start_time_ms_(start_time_ms), - run_time_ms_(run_time_ms), - creation_time_ms_(clock_->TimeInMilliseconds()), - capturer_(nullptr), - rtp_start_timestamp_set_(false), - rtp_start_timestamp_(0) {} - - private: - BuiltInNetworkBehaviorConfig GetSendTransportConfig() const override { - return net_config_; - } - - BuiltInNetworkBehaviorConfig GetReceiveTransportConfig() const override { - return net_config_; - } - - void OnFrame(const VideoFrame& video_frame) override { - MutexLock lock(&mutex_); - if (video_frame.ntp_time_ms() <= 0) { - // Haven't got enough RTCP SR in order to calculate the capture ntp - // time. - return; - } - - int64_t now_ms = clock_->TimeInMilliseconds(); - int64_t time_since_creation = now_ms - creation_time_ms_; - if (time_since_creation < start_time_ms_) { - // Wait for `start_time_ms_` before start measuring. - return; - } - - if (time_since_creation > run_time_ms_) { - observation_complete_.Set(); - } - - FrameCaptureTimeList::iterator iter = - capture_time_list_.find(video_frame.rtp_timestamp()); - EXPECT_TRUE(iter != capture_time_list_.end()); - - // The real capture time has been wrapped to uint32_t before converted - // to rtp timestamp in the sender side. So here we convert the estimated - // capture time to a uint32_t 90k timestamp also for comparing. - uint32_t estimated_capture_timestamp = - 90 * static_cast(video_frame.ntp_time_ms()); - uint32_t real_capture_timestamp = iter->second; - int time_offset_ms = real_capture_timestamp - estimated_capture_timestamp; - time_offset_ms = time_offset_ms / 90; - time_offset_ms_list_.AddSample(time_offset_ms); - - EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_); - } - - Action OnSendRtp(rtc::ArrayView packet) override { - MutexLock lock(&mutex_); - RtpPacket rtp_packet; - EXPECT_TRUE(rtp_packet.Parse(packet)); - - if (!rtp_start_timestamp_set_) { - // Calculate the rtp timestamp offset in order to calculate the real - // capture time. - uint32_t first_capture_timestamp = - 90 * static_cast(capturer_->first_frame_capture_time()); - rtp_start_timestamp_ = rtp_packet.Timestamp() - first_capture_timestamp; - rtp_start_timestamp_set_ = true; - } - - uint32_t capture_timestamp = - rtp_packet.Timestamp() - rtp_start_timestamp_; - capture_time_list_.insert( - capture_time_list_.end(), - std::make_pair(rtp_packet.Timestamp(), capture_timestamp)); - return SEND_PACKET; - } - - void OnFrameGeneratorCapturerCreated( - test::FrameGeneratorCapturer* frame_generator_capturer) override { - capturer_ = frame_generator_capturer; - } - - void ModifyVideoConfigs( - VideoSendStream::Config* send_config, - std::vector* receive_configs, - VideoEncoderConfig* encoder_config) override { - (*receive_configs)[0].renderer = this; - // Enable the receiver side rtt calculation. - (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true; - } - - void PerformTest() override { - EXPECT_TRUE(Wait()) << "Timed out while waiting for estimated capture " - "NTP time to be within bounds."; - GetGlobalMetricsLogger()->LogMetric( - "capture_ntp_time", "real - estimated", time_offset_ms_list_, - Unit::kMilliseconds, ImprovementDirection::kNeitherIsBetter); - } - - Mutex mutex_; - const BuiltInNetworkBehaviorConfig net_config_; - Clock* const clock_; - const int threshold_ms_; - const int start_time_ms_; - const int run_time_ms_; - const int64_t creation_time_ms_; - test::FrameGeneratorCapturer* capturer_; - bool rtp_start_timestamp_set_; - uint32_t rtp_start_timestamp_; - typedef std::map FrameCaptureTimeList; - FrameCaptureTimeList capture_time_list_ RTC_GUARDED_BY(&mutex_); - SamplesStatsCounter time_offset_ms_list_; - } test(net_config, threshold_ms, start_time_ms, run_time_ms); - - RunBaseTest(&test); -} - -// Flaky tests, disabled on Mac and Windows due to webrtc:8291. -#if !(defined(WEBRTC_MAC) || defined(WEBRTC_WIN)) -TEST_F(CallPerfTest, Real_Estimated_CaptureNtpTimeWithNetworkDelay) { - BuiltInNetworkBehaviorConfig net_config; - net_config.queue_delay_ms = 100; - // TODO(wu): lower the threshold as the calculation/estimation becomes more - // accurate. - const int kThresholdMs = 100; - const int kStartTimeMs = 10000; - const int kRunTimeMs = 20000; - TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); -} - -TEST_F(CallPerfTest, Real_Estimated_CaptureNtpTimeWithNetworkJitter) { - BuiltInNetworkBehaviorConfig net_config; - net_config.queue_delay_ms = 100; - net_config.delay_standard_deviation_ms = 10; - // TODO(wu): lower the threshold as the calculation/estimation becomes more - // accurate. - const int kThresholdMs = 100; - const int kStartTimeMs = 10000; - const int kRunTimeMs = 20000; - TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); -} -#endif - TEST_F(CallPerfTest, ReceivesCpuOveruseAndUnderuse) { // Minimal normal usage at the start, then 30s overuse to allow filter to // settle, and then 80s underuse to allow plenty of time for rampup again. diff --git a/test/frame_generator_capturer.cc b/test/frame_generator_capturer.cc index 7cdfec2cc2..d30909d8ed 100644 --- a/test/frame_generator_capturer.cc +++ b/test/frame_generator_capturer.cc @@ -47,7 +47,6 @@ FrameGeneratorCapturer::FrameGeneratorCapturer( frame_generator_(std::move(frame_generator)), source_fps_(target_fps), target_capture_fps_(target_fps), - first_frame_capture_time_(-1), task_queue_(task_queue_factory.CreateTaskQueue( "FrameGenCapQ", TaskQueueFactory::Priority::HIGH)) { @@ -106,14 +105,9 @@ void FrameGeneratorCapturer::InsertFrame() { .set_video_frame_buffer(frame_data.buffer) .set_rotation(fake_rotation_) .set_timestamp_us(clock_->TimeInMicroseconds()) - .set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()) .set_update_rect(frame_data.update_rect) .set_color_space(fake_color_space_) .build(); - if (first_frame_capture_time_ == -1) { - first_frame_capture_time_ = frame.ntp_time_ms(); - } - TestVideoCapturer::OnFrame(frame); } } diff --git a/test/frame_generator_capturer.h b/test/frame_generator_capturer.h index bb0c445c53..0a46a2f283 100644 --- a/test/frame_generator_capturer.h +++ b/test/frame_generator_capturer.h @@ -80,8 +80,6 @@ class FrameGeneratorCapturer : public TestVideoCapturer { void SetFakeRotation(VideoRotation rotation); void SetFakeColorSpace(absl::optional color_space); - int64_t first_frame_capture_time() const { return first_frame_capture_time_; } - bool Init(); private: @@ -104,8 +102,6 @@ class FrameGeneratorCapturer : public TestVideoCapturer { VideoRotation fake_rotation_ = kVideoRotation_0; absl::optional fake_color_space_ RTC_GUARDED_BY(&lock_); - int64_t first_frame_capture_time_; - std::unique_ptr task_queue_; }; } // namespace test