Add SetAudioPlayout and SetAudioRecording methods to the PeerConnection API (II)
Second attempt to land https://webrtc-review.googlesource.com/c/src/+/16180
Now removes voice_engine dependency from peerconnection and fixes a minor
const issue in NullAudioPoller.
TBR=solenberg
Bug: webrtc:7313
Change-Id: Ibfddbdc76118581e4a4dc64575203f84c1659e5c
Reviewed-on: https://webrtc-review.googlesource.com/17784
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20526}diff --git a/audio/audio_state.cc b/audio/audio_state.cc
index 2a84f5c..9b5f74f 100644
--- a/audio/audio_state.cc
+++ b/audio/audio_state.cc
@@ -12,8 +12,11 @@
#include "modules/audio_device/include/audio_device.h"
#include "rtc_base/atomicops.h"
+#include "rtc_base/bind.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
+#include "rtc_base/ptr_util.h"
+#include "rtc_base/thread.h"
#include "voice_engine/transmit_mixer.h"
namespace webrtc {
@@ -59,6 +62,40 @@
return transmit_mixer->typing_noise_detected();
}
+void AudioState::SetPlayout(bool enabled) {
+ LOG(INFO) << "SetPlayout(" << enabled << ")";
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ const bool currently_enabled = (null_audio_poller_ == nullptr);
+ if (enabled == currently_enabled) {
+ return;
+ }
+ VoEBase* const voe = VoEBase::GetInterface(voice_engine());
+ RTC_DCHECK(voe);
+ if (enabled) {
+ null_audio_poller_.reset();
+ }
+ // Will stop/start playout of the underlying device, if necessary, and
+ // remember the setting for when it receives subsequent calls of
+ // StartPlayout.
+ voe->SetPlayout(enabled);
+ if (!enabled) {
+ null_audio_poller_ =
+ rtc::MakeUnique<NullAudioPoller>(&audio_transport_proxy_);
+ }
+}
+
+void AudioState::SetRecording(bool enabled) {
+ LOG(INFO) << "SetRecording(" << enabled << ")";
+ RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ // TODO(henrika): keep track of state as in SetPlayout().
+ VoEBase* const voe = VoEBase::GetInterface(voice_engine());
+ RTC_DCHECK(voe);
+ // Will stop/start recording of the underlying device, if necessary, and
+ // remember the setting for when it receives subsequent calls of
+ // StartPlayout.
+ voe->SetRecording(enabled);
+}
+
// Reference count; implementation copied from rtc::RefCountedObject.
void AudioState::AddRef() const {
rtc::AtomicOps::Increment(&ref_count_);