aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/audio/audio_transport_proxy.h" |
| 12 | |
| 13 | namespace webrtc { |
| 14 | |
| 15 | AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, |
| 16 | AudioProcessing* apm, |
| 17 | AudioMixer* mixer) |
| 18 | : voe_audio_transport_(voe_audio_transport) { |
| 19 | RTC_DCHECK(voe_audio_transport); |
| 20 | RTC_DCHECK(apm); |
| 21 | } |
| 22 | |
| 23 | AudioTransportProxy::~AudioTransportProxy() {} |
| 24 | |
| 25 | int32_t AudioTransportProxy::RecordedDataIsAvailable( |
| 26 | const void* audioSamples, |
| 27 | const size_t nSamples, |
| 28 | const size_t nBytesPerSample, |
| 29 | const size_t nChannels, |
| 30 | const uint32_t samplesPerSec, |
| 31 | const uint32_t totalDelayMS, |
| 32 | const int32_t clockDrift, |
| 33 | const uint32_t currentMicLevel, |
| 34 | const bool keyPressed, |
| 35 | uint32_t& newMicLevel) { |
| 36 | // Pass call through to original audio transport instance. |
| 37 | return voe_audio_transport_->RecordedDataIsAvailable( |
| 38 | audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec, |
| 39 | totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel); |
| 40 | } |
| 41 | |
| 42 | int32_t AudioTransportProxy::NeedMorePlayData(const size_t nSamples, |
| 43 | const size_t nBytesPerSample, |
| 44 | const size_t nChannels, |
| 45 | const uint32_t samplesPerSec, |
| 46 | void* audioSamples, |
| 47 | size_t& nSamplesOut, |
| 48 | int64_t* elapsed_time_ms, |
| 49 | int64_t* ntp_time_ms) { |
| 50 | RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); |
| 51 | RTC_DCHECK_GE(nChannels, 1u); |
| 52 | RTC_DCHECK_LE(nChannels, 2u); |
| 53 | RTC_DCHECK_GE( |
| 54 | samplesPerSec, |
| 55 | static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); |
| 56 | RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); |
| 57 | RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, |
| 58 | sizeof(AudioFrame::data_)); |
| 59 | |
| 60 | // Pass call through to original audio transport instance. |
| 61 | return voe_audio_transport_->NeedMorePlayData( |
| 62 | nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples, |
| 63 | nSamplesOut, elapsed_time_ms, ntp_time_ms); |
| 64 | } |
| 65 | |
| 66 | void AudioTransportProxy::PushCaptureData(int voe_channel, |
| 67 | const void* audio_data, |
| 68 | int bits_per_sample, |
| 69 | int sample_rate, |
| 70 | size_t number_of_channels, |
| 71 | size_t number_of_frames) { |
| 72 | // This is part of deprecated VoE interface operating on specific |
| 73 | // VoE channels. It should not be used. |
| 74 | RTC_NOTREACHED(); |
| 75 | } |
| 76 | |
| 77 | void AudioTransportProxy::PullRenderData(int bits_per_sample, |
| 78 | int sample_rate, |
| 79 | size_t number_of_channels, |
| 80 | size_t number_of_frames, |
| 81 | void* audio_data, |
| 82 | int64_t* elapsed_time_ms, |
| 83 | int64_t* ntp_time_ms) { |
| 84 | RTC_DCHECK_EQ(static_cast<size_t>(bits_per_sample), 8 * sizeof(int16_t)); |
| 85 | RTC_DCHECK_GE(number_of_channels, 1u); |
| 86 | RTC_DCHECK_LE(number_of_channels, 2u); |
| 87 | RTC_DCHECK_GE(static_cast<int>(sample_rate), |
| 88 | AudioProcessing::NativeRate::kSampleRate8kHz); |
| 89 | RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate); |
| 90 | RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, |
| 91 | sizeof(AudioFrame::data_)); |
| 92 | voe_audio_transport_->PullRenderData( |
| 93 | bits_per_sample, sample_rate, number_of_channels, number_of_frames, |
| 94 | audio_data, elapsed_time_ms, ntp_time_ms); |
| 95 | } |
| 96 | |
| 97 | } // namespace webrtc |