From fd5df6887258222f1be7ffb15fb1479b13d35aba Mon Sep 17 00:00:00 2001 From: Andrey Logvin Date: Mon, 20 Jul 2020 08:39:36 +0000 Subject: [PATCH] Reduce time that video analyzer holds the frame in pc level framework Bug: None Change-Id: Ie669f3d8ff4f9f5b7900bcb11d13a5f7f579ce44 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/179526 Reviewed-by: Artem Titov Commit-Queue: Andrey Logvin Cr-Commit-Position: refs/heads/master@{#31765} --- .../analyzer/video/default_video_quality_analyzer.cc | 10 ++-------- .../video/video_quality_analyzer_injection_helper.cc | 11 +++++++++-- .../video/video_quality_analyzer_injection_helper.h | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc index db866077e7..000d1654a6 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc @@ -390,11 +390,11 @@ void DefaultVideoQualityAnalyzer::OnFrameDecoded( void DefaultVideoQualityAnalyzer::OnFrameRendered( absl::string_view peer_name, - const webrtc::VideoFrame& raw_frame) { + const webrtc::VideoFrame& frame) { MutexLock lock(&lock_); size_t peer_index = peers_->index(peer_name); - auto frame_it = captured_frames_in_flight_.find(raw_frame.id()); + auto frame_it = captured_frames_in_flight_.find(frame.id()); if (frame_it == captured_frames_in_flight_.end() || frame_it->second.HasRenderedTime(peer_index)) { // It means this frame was rendered before, so we can skip it. It may happen @@ -405,12 +405,6 @@ void DefaultVideoQualityAnalyzer::OnFrameRendered( return; } - // Copy entire video frame including video buffer to ensure that analyzer - // won't hold any WebRTC internal buffers. - VideoFrame frame = raw_frame; - frame.set_video_frame_buffer( - I420Buffer::Copy(*raw_frame.video_frame_buffer()->ToI420())); - // Find corresponding captured frame. FrameInFlight* frame_in_flight = &frame_it->second; absl::optional captured_frame = frame_in_flight->frame(); diff --git a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc index dfd6a8db4a..48e65ef686 100644 --- a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc +++ b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.cc @@ -184,11 +184,18 @@ VideoQualityAnalyzerInjectionHelper::MaybeCreateVideoWriter( void VideoQualityAnalyzerInjectionHelper::OnFrame(absl::string_view peer_name, const VideoFrame& frame) { - if (IsDummyFrameBuffer(frame.video_frame_buffer()->ToI420())) { + rtc::scoped_refptr i420_buffer = + frame.video_frame_buffer()->ToI420(); + if (IsDummyFrameBuffer(i420_buffer)) { // This is dummy frame, so we don't need to process it further. return; } - analyzer_->OnFrameRendered(peer_name, frame); + // Copy entire video frame including video buffer to ensure that analyzer + // won't hold any WebRTC internal buffers. + VideoFrame frame_copy = frame; + frame_copy.set_video_frame_buffer(I420Buffer::Copy(*i420_buffer)); + analyzer_->OnFrameRendered(peer_name, frame_copy); + std::string stream_label = analyzer_->GetStreamLabel(frame.id()); std::vector>>* sinks = PopulateSinks(stream_label); diff --git a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h index 6139cfd46a..d741288345 100644 --- a/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h +++ b/test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h @@ -107,6 +107,8 @@ class VideoQualityAnalyzerInjectionHelper : public StatsObserverInterface { test::VideoFrameWriter* MaybeCreateVideoWriter( absl::optional file_name, const PeerConnectionE2EQualityTestFixture::VideoConfig& config); + // Creates a deep copy of the frame and passes it to the video analyzer, while + // passing real frame to the sinks void OnFrame(absl::string_view peer_name, const VideoFrame& frame); std::vector>>* PopulateSinks(const std::string& stream_label);