Skip to content

Commit

Permalink
[DVQA] Enforce state checks before any API calls
Browse files Browse the repository at this point in the history
Bug: b/199244618
Change-Id: I356cc95688f9a46b943e51585583927b01d8cd0f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/231461
Reviewed-by: Mirko Bonadei <[email protected]>
Commit-Queue: Artem Titov <[email protected]>
Cr-Commit-Position: refs/heads/main@{#34948}
  • Loading branch information
titov-artem authored and WebRTC LUCI CQ committed Sep 8, 2021
1 parent 7d0203c commit 034abc9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void DefaultVideoQualityAnalyzer::Start(
peers_ = std::make_unique<NamesCollection>(peer_names);
RTC_CHECK(start_time_.IsMinusInfinity());

RTC_CHECK_EQ(state_, State::kNew)
<< "DefaultVideoQualityAnalyzer is already started";
state_ = State::kActive;
start_time_ = Now();
}
Expand All @@ -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_`.
Expand Down Expand Up @@ -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";
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 034abc9

Please sign in to comment.