Avoid running NullAudioPoller without receiving streams

Fixes an issue with NullAudioPoller calling the mixer every 10 ms when
no call is ongoing.

Bug: b/142775365
Change-Id: I77eeddadaf08b358cce2b389c70e4f2baf1d5627
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/157176
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29508}
This commit is contained in:
Gustaf Ullberg 2019-10-17 11:32:10 +02:00 committed by Commit Bot
parent 5f01bf6c8b
commit dabdde6273
2 changed files with 16 additions and 2 deletions

View File

@ -63,6 +63,7 @@ void AudioState::AddReceivingStream(webrtc::AudioReceiveStream* stream) {
}
// Make sure playback is initialized; start playing if enabled.
UpdateNullAudioPollerState();
auto* adm = config_.audio_device_module.get();
if (!adm->Playing()) {
if (adm->InitPlayout() == 0) {
@ -81,6 +82,7 @@ void AudioState::RemoveReceivingStream(webrtc::AudioReceiveStream* stream) {
RTC_DCHECK_EQ(1, count);
config_.audio_mixer->RemoveSource(
static_cast<internal::AudioReceiveStream*>(stream));
UpdateNullAudioPollerState();
if (receiving_streams_.empty()) {
config_.audio_device_module->StopPlayout();
}
@ -124,13 +126,13 @@ void AudioState::SetPlayout(bool enabled) {
if (playout_enabled_ != enabled) {
playout_enabled_ = enabled;
if (enabled) {
null_audio_poller_.reset();
UpdateNullAudioPollerState();
if (!receiving_streams_.empty()) {
config_.audio_device_module->StartPlayout();
}
} else {
config_.audio_device_module->StopPlayout();
null_audio_poller_ = std::make_unique<NullAudioPoller>(&audio_transport_);
UpdateNullAudioPollerState();
}
}
}
@ -168,6 +170,17 @@ void AudioState::UpdateAudioTransportWithSendingStreams() {
audio_transport_.UpdateSendingStreams(std::move(sending_streams),
max_sample_rate_hz, max_num_channels);
}
void AudioState::UpdateNullAudioPollerState() {
// Run NullAudioPoller when there are receiving streams and playout is
// disabled.
if (!receiving_streams_.empty() && !playout_enabled_) {
if (!null_audio_poller_)
null_audio_poller_ = std::make_unique<NullAudioPoller>(&audio_transport_);
} else {
null_audio_poller_.reset();
}
}
} // namespace internal
rtc::scoped_refptr<AudioState> AudioState::Create(

View File

@ -60,6 +60,7 @@ class AudioState : public webrtc::AudioState {
private:
void UpdateAudioTransportWithSendingStreams();
void UpdateNullAudioPollerState();
rtc::ThreadChecker thread_checker_;
rtc::ThreadChecker process_thread_checker_;