| Index: webrtc/audio/audio_state.cc
|
| diff --git a/webrtc/audio/audio_state.cc b/webrtc/audio/audio_state.cc
|
| index e63f97af2d4fb9fd3123f37532f0553382715984..1efcf35a11f68ab450c4f1d5e6e66293c7481a33 100644
|
| --- a/webrtc/audio/audio_state.cc
|
| +++ b/webrtc/audio/audio_state.cc
|
| @@ -14,8 +14,75 @@
|
| #include "webrtc/base/checks.h"
|
| #include "webrtc/base/logging.h"
|
| #include "webrtc/voice_engine/include/voe_errors.h"
|
| +#include "webrtc/modules/audio_device/include/audio_device.h"
|
| +#include "webrtc/modules/audio_device/include/audio_device_defines.h"
|
|
|
| namespace webrtc {
|
| +
|
| +namespace {
|
| +class MiMAudioTransport : public AudioTransport {
|
| + public:
|
| + MiMAudioTransport(AudioTransport* voe_audio_transport)
|
| + : voe_audio_transport_(voe_audio_transport) {}
|
| +
|
| + virtual ~MiMAudioTransport() {}
|
| +
|
| + int32_t RecordedDataIsAvailable(const void* audioSamples,
|
| + const size_t nSamples,
|
| + const size_t nBytesPerSample,
|
| + const size_t nChannels,
|
| + const uint32_t samplesPerSec,
|
| + const uint32_t totalDelayMS,
|
| + const int32_t clockDrift,
|
| + const uint32_t currentMicLevel,
|
| + const bool keyPressed,
|
| + uint32_t& newMicLevel) override {
|
| + // Used by native apps to PUSH data to VoE (those that do not
|
| + // supply their own ADM).
|
| +
|
| + // Just pass through.
|
| + return voe_audio_transport_->RecordedDataIsAvailable(
|
| + audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec,
|
| + totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel);
|
| + }
|
| + int32_t NeedMorePlayData(const size_t nSamples,
|
| + const size_t nBytesPerSample,
|
| + const size_t nChannels,
|
| + const uint32_t samplesPerSec,
|
| + void* audioSamples,
|
| + size_t& nSamplesOut,
|
| + int64_t* elapsed_time_ms,
|
| + int64_t* ntp_time_ms) override {
|
| + return voe_audio_transport_->NeedMorePlayData(
|
| + nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples,
|
| + nSamplesOut, elapsed_time_ms, ntp_time_ms);
|
| + }
|
| +
|
| + void PushCaptureData(int voe_channel,
|
| + const void* audio_data,
|
| + int bits_per_sample,
|
| + int sample_rate,
|
| + size_t number_of_channels,
|
| + size_t number_of_frames) override {
|
| + RTC_NOTREACHED();
|
| + }
|
| + void PullRenderData(int bits_per_sample,
|
| + int sample_rate,
|
| + size_t number_of_channels,
|
| + size_t number_of_frames,
|
| + void* audio_data,
|
| + int64_t* elapsed_time_ms,
|
| + int64_t* ntp_time_ms) override {
|
| + return voe_audio_transport_->PullRenderData(
|
| + bits_per_sample, sample_rate, number_of_channels, number_of_frames,
|
| + audio_data, elapsed_time_ms, ntp_time_ms);
|
| + }
|
| +
|
| + private:
|
| + AudioTransport* voe_audio_transport_;
|
| +};
|
| +} // namespace
|
| +
|
| namespace internal {
|
|
|
| AudioState::AudioState(const AudioState::Config& config)
|
| @@ -23,11 +90,25 @@ AudioState::AudioState(const AudioState::Config& config)
|
| process_thread_checker_.DetachFromThread();
|
| // Only one AudioState should be created per VoiceEngine.
|
| RTC_CHECK(voe_base_->RegisterVoiceEngineObserver(*this) != -1);
|
| +
|
| + if (voe_base_->audio_transport()) {
|
| + mim_transport_ = new MiMAudioTransport(voe_base_->audio_transport());
|
| +
|
| + // first reset the old one (which is VoE->audio_transport())
|
| + audio_device()->RegisterAudioCallback(nullptr);
|
| + audio_device()->RegisterAudioCallback(mim_transport_);
|
| + } else {
|
| + LOG(LS_INFO) << "fail fail fail!";
|
| + }
|
| }
|
|
|
| AudioState::~AudioState() {
|
| RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| + // voe_base_->audio_device_module()->RegisterAudioCallback(nullptr);
|
| voe_base_->DeRegisterVoiceEngineObserver();
|
| + if (mim_transport_) {
|
| + delete static_cast<MiMAudioTransport*>(mim_transport_);
|
| + }
|
| }
|
|
|
| VoiceEngine* AudioState::voice_engine() {
|
| @@ -35,6 +116,15 @@ VoiceEngine* AudioState::voice_engine() {
|
| return config_.voice_engine;
|
| }
|
|
|
| +AudioDeviceModule* AudioState::audio_device() {
|
| + RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| + // if (config_.audio_device_module) {
|
| + // return config_.audio_device_module;
|
| + // }
|
| + RTC_CHECK(voe_base_->audio_device_module());
|
| + return voe_base_->audio_device_module();
|
| +}
|
| +
|
| bool AudioState::typing_noise_detected() const {
|
| RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| rtc::CritScope lock(&crit_sect_);
|
|
|