Chromium Code Reviews| Index: webrtc/audio/audio_transport_proxy.h |
| diff --git a/webrtc/audio/audio_transport_proxy.h b/webrtc/audio/audio_transport_proxy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..12576bd2f7ed4ab8511e38d1cf474f489515b476 |
| --- /dev/null |
| +++ b/webrtc/audio/audio_transport_proxy.h |
| @@ -0,0 +1,119 @@ |
| +/* |
| + * Copyright (c) 2016 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. |
| + */ |
| + |
| +#ifndef WEBRTC_AUDIO_AUDIO_TRANSPORT_PROXY_H_ |
| +#define WEBRTC_AUDIO_AUDIO_TRANSPORT_PROXY_H_ |
| + |
| +#include <algorithm> |
| + |
| +#include "webrtc/api/audio/audio_mixer.h" |
| +#include "webrtc/base/logging.h" |
| +#include "webrtc/modules/audio_device/include/audio_device_defines.h" |
| +#include "webrtc/modules/audio_processing/include/audio_processing.h" |
| + |
| +namespace webrtc { |
| + |
| +class AudioTransportProxy : public AudioTransport { |
| + public: |
| + AudioTransportProxy(AudioTransport* voe_audio_transport, |
| + AudioProcessing* apm, |
| + AudioMixer* mixer) |
| + : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { |
| + RTC_DCHECK(mixer_); |
| + } |
| + |
| + virtual ~AudioTransportProxy() {} |
|
the sun
2016/10/27 10:06:46
override
|
| + |
| + 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 { |
| + // Pass call through to original audio transport instance. |
| + if (voe_audio_transport_) { |
| + return voe_audio_transport_->RecordedDataIsAvailable( |
| + audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec, |
| + totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel); |
| + } else { |
| + LOG(LS_ERROR) |
| + << "AudioTransport proxy doesn't know where to send recorded data: " |
| + "no Audio Transport provided."; |
| + } |
| + |
| + return -1; |
| + } |
| + 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 { |
|
the sun
2016/10/27 10:06:46
RTC_DCHECK_EQ(2u, nBytesPerSample);
RTC_DCHECK(aud
|
| + mixer_->Mix(static_cast<int>(samplesPerSec), static_cast<int>(nChannels), |
| + &frame_for_mixing_); |
| + *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; |
| + *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; |
| + |
| + if (apm_) { |
| + apm_->ProcessReverseStream(&frame_for_mixing_); |
| + } else { |
| + LOG(LS_ERROR) << "NeedMorePlayData called, but no APM provided."; |
|
the sun
2016/10/27 10:06:46
In what context does this happen? Is the right way
|
| + } |
| + |
| + // Deliver audio (PCM) samples to the ADM. |
| + std::copy(frame_for_mixing_.data_, |
| + frame_for_mixing_.data_ + nSamples * nChannels, |
| + static_cast<int16_t*>(audioSamples)); |
| + nSamplesOut = frame_for_mixing_.samples_per_channel_; |
| + |
| + return 0; |
| + } |
| + |
| + 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 { |
|
the sun
2016/10/27 10:06:46
Add comment here why this path is unreachable.
|
| + 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 { |
| + mixer_->Mix(static_cast<int>(sample_rate), |
| + static_cast<int>(number_of_channels), &frame_for_mixing_); |
| + *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; |
| + *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; |
| + |
| + // Deliver audio (PCM) samples to the ADM. |
| + std::copy(frame_for_mixing_.data_, |
| + frame_for_mixing_.data_ + number_of_frames * number_of_channels, |
| + static_cast<int16_t*>(audio_data)); |
| + } |
| + |
| + private: |
| + AudioTransport* voe_audio_transport_; |
| + AudioProcessing* apm_; |
| + AudioMixer* mixer_; |
| + AudioFrame frame_for_mixing_; |
|
the sun
2016/10/27 10:06:46
DISALLOW_IMPLICIT...
|
| +}; |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_AUDIO_AUDIO_TRANSPORT_PROXY_H_ |