Index: webrtc/audio/audio_transport_proxy.cc |
diff --git a/webrtc/audio/audio_transport_proxy.cc b/webrtc/audio/audio_transport_proxy.cc |
index ed72200379d1d07fab29e04482b761ea732cb6e2..1b4d876837476d37d99f75e747dec2131c9eee68 100644 |
--- a/webrtc/audio/audio_transport_proxy.cc |
+++ b/webrtc/audio/audio_transport_proxy.cc |
@@ -12,12 +12,33 @@ |
namespace webrtc { |
+namespace { |
+// Resample audio in |frame| to given sample rate preserving the |
+// channel count and place the result in |destination|. |
+int Resample(const AudioFrame& frame, |
the sun
2016/11/14 20:03:47
I'd find this order more intuitive:
source_frame,
aleloi
2016/11/15 16:56:54
I was trying to follow the style guide for paramet
the sun
2016/11/16 20:22:57
Uhm, ok. Thanks for educating me.
|
+ const int target_sample_rate, |
+ PushResampler<int16_t>* resampler, |
+ int16_t* destination) { |
+ const int frame_sample_rate = frame.sample_rate_hz_; |
the sun
2016/11/14 20:03:46
Remove this local
aleloi
2016/11/15 16:56:54
Done.
|
+ const int number_of_channels = frame.num_channels_; |
+ const int target_number_of_samples_per_channel = target_sample_rate / 100; |
+ resampler->InitializeIfNeeded(frame_sample_rate, target_sample_rate, |
+ number_of_channels); |
+ |
+ return resampler->Resample( |
+ frame.data_, frame.samples_per_channel_ * number_of_channels, |
+ static_cast<int16_t*>(destination), |
the sun
2016/11/14 20:03:47
cast not needed
aleloi
2016/11/15 16:56:54
Acknowledged.
|
+ number_of_channels * target_number_of_samples_per_channel); |
+} |
+} // namespace |
+ |
AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, |
AudioProcessing* apm, |
AudioMixer* mixer) |
- : voe_audio_transport_(voe_audio_transport) { |
- RTC_DCHECK(voe_audio_transport); |
+ : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { |
RTC_DCHECK(apm); |
the sun
2016/11/14 20:03:46
nit: use same order as ctor init list
aleloi
2016/11/15 16:56:54
Done.
|
+ RTC_DCHECK(mixer); |
+ RTC_DCHECK(voe_audio_transport); |
} |
AudioTransportProxy::~AudioTransportProxy() {} |
@@ -57,10 +78,16 @@ int32_t AudioTransportProxy::NeedMorePlayData(const size_t nSamples, |
RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, |
sizeof(AudioFrame::data_)); |
- // Pass call through to original audio transport instance. |
- return voe_audio_transport_->NeedMorePlayData( |
- nSamples, nBytesPerSample, nChannels, samplesPerSec, audioSamples, |
- nSamplesOut, elapsed_time_ms, ntp_time_ms); |
+ mixer_->Mix(static_cast<int>(nChannels), &frame_for_mixing_); |
the sun
2016/11/14 20:03:46
Cast should be unnecessary here.
|
+ *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; |
+ *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; |
+ |
+ const auto error = apm_->ProcessReverseStream(&frame_for_mixing_); |
+ RTC_DCHECK_EQ(error, AudioProcessing::kNoError); |
+ |
+ nSamplesOut = Resample(frame_for_mixing_, samplesPerSec, &resampler_, |
+ static_cast<int16_t*>(audioSamples)); |
the sun
2016/11/14 20:03:46
DCHECK that nSamplesOut is nSamples?
aleloi
2016/11/15 16:56:54
Done.
|
+ return 0; |
} |
void AudioTransportProxy::PushCaptureData(int voe_channel, |
@@ -89,9 +116,12 @@ void AudioTransportProxy::PullRenderData(int bits_per_sample, |
RTC_DCHECK_EQ(static_cast<int>(number_of_frames * 100), sample_rate); |
RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, |
sizeof(AudioFrame::data_)); |
- voe_audio_transport_->PullRenderData( |
- bits_per_sample, sample_rate, number_of_channels, number_of_frames, |
- audio_data, elapsed_time_ms, ntp_time_ms); |
+ mixer_->Mix(number_of_channels, &frame_for_mixing_); |
+ *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; |
+ *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; |
+ |
+ Resample(frame_for_mixing_, sample_rate, &resampler_, |
the sun
2016/11/14 20:03:47
Check return value?
aleloi
2016/11/15 16:56:54
Done.
|
+ static_cast<int16_t*>(audio_data)); |
} |
} // namespace webrtc |