2015-11-06 15:34:49 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "audio/audio_state.h"
|
2015-11-06 15:34:49 -08:00
|
|
|
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2017-12-18 22:41:03 +01:00
|
|
|
#include "audio/audio_receive_stream.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_device/include/audio_device.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ref_counted_object.h"
|
2017-11-01 11:06:56 +01:00
|
|
|
#include "rtc_base/thread.h"
|
2015-11-06 15:34:49 -08:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
AudioState::AudioState(const AudioState::Config& config)
|
2016-11-17 06:28:59 -08:00
|
|
|
: config_(config),
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
audio_transport_(config_.audio_mixer, config_.audio_processing.get()) {
|
2015-11-06 15:34:49 -08:00
|
|
|
process_thread_checker_.DetachFromThread();
|
2016-11-17 06:48:48 -08:00
|
|
|
RTC_DCHECK(config_.audio_mixer);
|
2017-12-18 13:09:12 +01:00
|
|
|
RTC_DCHECK(config_.audio_device_module);
|
2015-11-06 15:34:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioState::~AudioState() {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2017-12-18 22:41:03 +01:00
|
|
|
RTC_DCHECK(receiving_streams_.empty());
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
RTC_DCHECK(sending_streams_.empty());
|
2015-11-06 15:34:49 -08:00
|
|
|
}
|
|
|
|
|
|
2018-08-28 16:30:18 +02:00
|
|
|
AudioProcessing* AudioState::audio_processing() {
|
|
|
|
|
RTC_DCHECK(config_.audio_processing);
|
|
|
|
|
return config_.audio_processing.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioTransport* AudioState::audio_transport() {
|
|
|
|
|
return &audio_transport_;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-18 22:41:03 +01:00
|
|
|
bool AudioState::typing_noise_detected() const {
|
2016-11-17 06:48:48 -08:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2017-12-18 22:41:03 +01:00
|
|
|
return audio_transport_.typing_noise_detected();
|
2016-11-17 06:28:59 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-18 22:41:03 +01:00
|
|
|
void AudioState::AddReceivingStream(webrtc::AudioReceiveStream* stream) {
|
2015-11-06 15:34:49 -08:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2017-12-18 22:41:03 +01:00
|
|
|
RTC_DCHECK_EQ(0, receiving_streams_.count(stream));
|
|
|
|
|
receiving_streams_.insert(stream);
|
|
|
|
|
if (!config_.audio_mixer->AddSource(
|
|
|
|
|
static_cast<internal::AudioReceiveStream*>(stream))) {
|
2018-01-25 10:14:29 +01:00
|
|
|
RTC_DLOG(LS_ERROR) << "Failed to add source to mixer.";
|
2017-12-18 22:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure playback is initialized; start playing if enabled.
|
|
|
|
|
auto* adm = config_.audio_device_module.get();
|
|
|
|
|
if (!adm->Playing()) {
|
|
|
|
|
if (adm->InitPlayout() == 0) {
|
|
|
|
|
if (playout_enabled_) {
|
|
|
|
|
adm->StartPlayout();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
RTC_DLOG_F(LS_ERROR) << "Failed to initialize playout.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioState::RemoveReceivingStream(webrtc::AudioReceiveStream* stream) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
auto count = receiving_streams_.erase(stream);
|
|
|
|
|
RTC_DCHECK_EQ(1, count);
|
|
|
|
|
config_.audio_mixer->RemoveSource(
|
|
|
|
|
static_cast<internal::AudioReceiveStream*>(stream));
|
|
|
|
|
if (receiving_streams_.empty()) {
|
|
|
|
|
config_.audio_device_module->StopPlayout();
|
|
|
|
|
}
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
|
|
|
|
|
int sample_rate_hz,
|
|
|
|
|
size_t num_channels) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
auto& properties = sending_streams_[stream];
|
|
|
|
|
properties.sample_rate_hz = sample_rate_hz;
|
|
|
|
|
properties.num_channels = num_channels;
|
|
|
|
|
UpdateAudioTransportWithSendingStreams();
|
2017-12-18 13:09:12 +01:00
|
|
|
|
|
|
|
|
// Make sure recording is initialized; start recording if enabled.
|
|
|
|
|
auto* adm = config_.audio_device_module.get();
|
|
|
|
|
if (!adm->Recording()) {
|
|
|
|
|
if (adm->InitRecording() == 0) {
|
|
|
|
|
if (recording_enabled_) {
|
|
|
|
|
adm->StartRecording();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
RTC_DLOG_F(LS_ERROR) << "Failed to initialize recording.";
|
|
|
|
|
}
|
|
|
|
|
}
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
auto count = sending_streams_.erase(stream);
|
|
|
|
|
RTC_DCHECK_EQ(1, count);
|
|
|
|
|
UpdateAudioTransportWithSendingStreams();
|
2017-12-18 13:09:12 +01:00
|
|
|
if (sending_streams_.empty()) {
|
|
|
|
|
config_.audio_device_module->StopRecording();
|
|
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
}
|
|
|
|
|
|
2017-11-01 11:06:56 +01:00
|
|
|
void AudioState::SetPlayout(bool enabled) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(INFO) << "SetPlayout(" << enabled << ")";
|
2017-11-01 11:06:56 +01:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2017-12-18 22:41:03 +01:00
|
|
|
if (playout_enabled_ != enabled) {
|
|
|
|
|
playout_enabled_ = enabled;
|
|
|
|
|
if (enabled) {
|
|
|
|
|
null_audio_poller_.reset();
|
|
|
|
|
if (!receiving_streams_.empty()) {
|
|
|
|
|
config_.audio_device_module->StartPlayout();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
config_.audio_device_module->StopPlayout();
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
null_audio_poller_ =
|
|
|
|
|
absl::make_unique<NullAudioPoller>(&audio_transport_);
|
2017-12-18 22:41:03 +01:00
|
|
|
}
|
2017-11-01 11:06:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioState::SetRecording(bool enabled) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(INFO) << "SetRecording(" << enabled << ")";
|
2017-11-01 11:06:56 +01:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2017-12-18 13:09:12 +01:00
|
|
|
if (recording_enabled_ != enabled) {
|
|
|
|
|
recording_enabled_ = enabled;
|
|
|
|
|
if (enabled) {
|
|
|
|
|
if (!sending_streams_.empty()) {
|
|
|
|
|
config_.audio_device_module->StartRecording();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
config_.audio_device_module->StopRecording();
|
|
|
|
|
}
|
|
|
|
|
}
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioState::Stats AudioState::GetAudioInputStats() const {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
const voe::AudioLevel& audio_level = audio_transport_.audio_level();
|
|
|
|
|
Stats result;
|
|
|
|
|
result.audio_level = audio_level.LevelFullRange();
|
|
|
|
|
RTC_DCHECK_LE(0, result.audio_level);
|
|
|
|
|
RTC_DCHECK_GE(32767, result.audio_level);
|
|
|
|
|
result.total_energy = audio_level.TotalEnergy();
|
|
|
|
|
result.total_duration = audio_level.TotalDuration();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioState::SetStereoChannelSwapping(bool enable) {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
|
|
audio_transport_.SetStereoChannelSwapping(enable);
|
2017-11-01 11:06:56 +01:00
|
|
|
}
|
|
|
|
|
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
void AudioState::UpdateAudioTransportWithSendingStreams() {
|
|
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2017-12-18 22:41:03 +01:00
|
|
|
std::vector<webrtc::AudioSendStream*> sending_streams;
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
int max_sample_rate_hz = 8000;
|
|
|
|
|
size_t max_num_channels = 1;
|
|
|
|
|
for (const auto& kv : sending_streams_) {
|
|
|
|
|
sending_streams.push_back(kv.first);
|
|
|
|
|
max_sample_rate_hz = std::max(max_sample_rate_hz, kv.second.sample_rate_hz);
|
|
|
|
|
max_num_channels = std::max(max_num_channels, kv.second.num_channels);
|
|
|
|
|
}
|
|
|
|
|
audio_transport_.UpdateSendingStreams(std::move(sending_streams),
|
|
|
|
|
max_sample_rate_hz, max_num_channels);
|
|
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
|
|
rtc::scoped_refptr<AudioState> AudioState::Create(
|
|
|
|
|
const AudioState::Config& config) {
|
2019-01-08 13:47:12 +01:00
|
|
|
return new rtc::RefCountedObject<internal::AudioState>(config);
|
2015-11-06 15:34:49 -08:00
|
|
|
}
|
|
|
|
|
} // namespace webrtc
|