Improves threading model in AudioDeviceTest.

These changes are based on finding when using Tsan v2. More changes are
needed before usage of the THREAD_SANITIZER build flag can be removed.
Hence, all tests are still ignored when this flag is set. The changes
are still improvements.

See https://bugs.chromium.org/p/webrtc/issues/detail?id=9778#c10
for more details.

Bug: webrtc:9778
Change-Id: I1266cec48165046dcffc16f104ec5b88b41500b2
Reviewed-on: https://webrtc-review.googlesource.com/102440
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24880}
This commit is contained in:
henrika
2018-09-27 16:23:21 +02:00
committed by Commit Bot
parent 89f64d305e
commit 78e0ac1b39

View File

@ -394,7 +394,10 @@ class MockAudioTransport : public test::MockAudioTransport {
EXPECT_EQ(samples_per_channel,
record_parameters_.frames_per_10ms_buffer());
}
rec_count_++;
{
rtc::CritScope lock(&lock_);
rec_count_++;
}
// Write audio data to audio stream object if one has been injected.
if (audio_stream_) {
audio_stream_->Write(
@ -431,7 +434,10 @@ class MockAudioTransport : public test::MockAudioTransport {
EXPECT_EQ(samples_per_channel,
playout_parameters_.frames_per_10ms_buffer());
}
play_count_++;
{
rtc::CritScope lock(&lock_);
play_count_++;
}
samples_out = samples_per_channel * channels;
// Read audio data from audio stream object if one has been injected.
if (audio_stream_) {
@ -452,12 +458,14 @@ class MockAudioTransport : public test::MockAudioTransport {
bool ReceivedEnoughCallbacks() {
bool recording_done = false;
if (rec_mode()) {
rtc::CritScope lock(&lock_);
recording_done = rec_count_ >= num_callbacks_;
} else {
recording_done = true;
}
bool playout_done = false;
if (play_mode()) {
rtc::CritScope lock(&lock_);
playout_done = play_count_ >= num_callbacks_;
} else {
playout_done = true;
@ -476,6 +484,7 @@ class MockAudioTransport : public test::MockAudioTransport {
}
void ResetCallbackCounters() {
rtc::CritScope lock(&lock_);
if (play_mode()) {
play_count_ = 0;
}
@ -485,12 +494,13 @@ class MockAudioTransport : public test::MockAudioTransport {
}
private:
rtc::CriticalSection lock_;
TransportType type_ = TransportType::kInvalid;
rtc::Event* event_ = nullptr;
AudioStream* audio_stream_ = nullptr;
size_t num_callbacks_ = 0;
size_t play_count_ = 0;
size_t rec_count_ = 0;
size_t play_count_ RTC_GUARDED_BY(lock_) = 0;
size_t rec_count_ RTC_GUARDED_BY(lock_) = 0;
AudioParameters playout_parameters_;
AudioParameters record_parameters_;
};