From 034abc9581f1d4ee79b1b515432ffbfdf8060f8e Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Wed, 8 Sep 2021 12:10:44 +0200 Subject: [PATCH] [DVQA] Enforce state checks before any API calls Bug: b/199244618 Change-Id: I356cc95688f9a46b943e51585583927b01d8cd0f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/231461 Reviewed-by: Mirko Bonadei Commit-Queue: Artem Titov Cr-Commit-Position: refs/heads/main@{#34948} --- .../video/default_video_quality_analyzer.cc | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 da4a81a1fe..e7b7f3f4c7 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc @@ -143,6 +143,8 @@ void DefaultVideoQualityAnalyzer::Start( peers_ = std::make_unique(peer_names); RTC_CHECK(start_time_.IsMinusInfinity()); + RTC_CHECK_EQ(state_, State::kNew) + << "DefaultVideoQualityAnalyzer is already started"; state_ = State::kActive; start_time_ = Now(); } @@ -161,6 +163,8 @@ uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured( size_t stream_index; { MutexLock lock(&mutex_); + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; // Create a local copy of `start_time_`, peer's index and total peers count // to access it without holding a `mutex_` during access to // `frames_comparator_`. @@ -256,6 +260,9 @@ void DefaultVideoQualityAnalyzer::OnFramePreEncode( absl::string_view peer_name, const webrtc::VideoFrame& frame) { MutexLock lock(&mutex_); + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; + auto it = captured_frames_in_flight_.find(frame.id()); RTC_DCHECK(it != captured_frames_in_flight_.end()) << "Frame id=" << frame.id() << " not found"; @@ -276,6 +283,9 @@ void DefaultVideoQualityAnalyzer::OnFrameEncoded( const webrtc::EncodedImage& encoded_image, const EncoderStats& stats) { MutexLock lock(&mutex_); + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; + auto it = captured_frames_in_flight_.find(frame_id); if (it == captured_frames_in_flight_.end()) { RTC_LOG(WARNING) @@ -321,6 +331,9 @@ void DefaultVideoQualityAnalyzer::OnFramePreDecode( uint16_t frame_id, const webrtc::EncodedImage& input_image) { MutexLock lock(&mutex_); + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; + size_t peer_index = peers_->index(peer_name); auto it = captured_frames_in_flight_.find(frame_id); @@ -357,6 +370,9 @@ void DefaultVideoQualityAnalyzer::OnFrameDecoded( const webrtc::VideoFrame& frame, const DecoderStats& stats) { MutexLock lock(&mutex_); + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; + size_t peer_index = peers_->index(peer_name); auto it = captured_frames_in_flight_.find(frame.id()); @@ -387,6 +403,9 @@ void DefaultVideoQualityAnalyzer::OnFrameRendered( absl::string_view peer_name, const webrtc::VideoFrame& frame) { MutexLock lock(&mutex_); + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; + size_t peer_index = peers_->index(peer_name); auto frame_it = captured_frames_in_flight_.find(frame.id()); @@ -559,6 +578,9 @@ void DefaultVideoQualityAnalyzer::Stop() { if (state_ == State::kStopped) { return; } + RTC_CHECK_EQ(state_, State::kActive) + << "DefaultVideoQualityAnalyzer has to be started before use"; + state_ = State::kStopped; // Add the amount of frames in flight to the analyzer stats before all left