OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/audio/audio_transport_proxy.h" | 11 #include "webrtc/audio/audio_transport_proxy.h" |
12 | 12 |
13 namespace webrtc { | 13 namespace webrtc { |
14 | 14 |
15 namespace { | 15 namespace { |
16 // Resample audio in |frame| to given sample rate preserving the | 16 // Resample audio in |frame| to given sample rate preserving the |
17 // channel count and place the result in |destination|. | 17 // channel count and place the result in |destination|. |
18 int Resample(const AudioFrame& frame, | 18 int Resample(const AudioFrame& frame, |
19 const int destination_sample_rate, | 19 const int destination_sample_rate, |
20 PushResampler<int16_t>* resampler, | 20 PushResampler<int16_t>* resampler, |
21 int16_t* destination) { | 21 int16_t* destination) { |
22 const int number_of_channels = static_cast<int>(frame.num_channels_); | 22 const int number_of_channels = static_cast<int>(frame.num_channels_); |
23 const int target_number_of_samples_per_channel = | 23 const int target_number_of_samples_per_channel = |
24 destination_sample_rate / 100; | 24 destination_sample_rate / 100; |
25 resampler->InitializeIfNeeded(frame.sample_rate_hz_, destination_sample_rate, | 25 resampler->InitializeIfNeeded(frame.sample_rate_hz_, destination_sample_rate, |
26 number_of_channels); | 26 number_of_channels); |
27 | 27 |
28 // TODO(yujo): for muted input frames, don't resample. Either 1) allow | |
hlundin-webrtc
2017/03/16 14:47:48
I would suggest that this function simply writes t
yujo
2017/03/16 23:37:21
I think the correct answer is to push AudioFrame d
hlundin-webrtc
2017/03/17 14:29:38
I think the TODO now is good enough for this CL. I
| |
29 // resampler to return output length without doing the resample, so we know | |
30 // how much to zero here; or 2) make resampler accept a hint that the input is | |
31 // zeroed. | |
28 return resampler->Resample( | 32 return resampler->Resample( |
29 frame.data_, frame.samples_per_channel_ * number_of_channels, destination, | 33 frame.data(), frame.samples_per_channel_ * number_of_channels, |
30 number_of_channels * target_number_of_samples_per_channel); | 34 destination, number_of_channels * target_number_of_samples_per_channel); |
31 } | 35 } |
32 } // namespace | 36 } // namespace |
33 | 37 |
34 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, | 38 AudioTransportProxy::AudioTransportProxy(AudioTransport* voe_audio_transport, |
35 AudioProcessing* apm, | 39 AudioProcessing* apm, |
36 AudioMixer* mixer) | 40 AudioMixer* mixer) |
37 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { | 41 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { |
38 RTC_DCHECK(voe_audio_transport); | 42 RTC_DCHECK(voe_audio_transport); |
39 RTC_DCHECK(apm); | 43 RTC_DCHECK(apm); |
40 RTC_DCHECK(mixer); | 44 RTC_DCHECK(mixer); |
(...skipping 29 matching lines...) Expand all Loading... | |
70 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); | 74 RTC_DCHECK_EQ(sizeof(int16_t) * nChannels, nBytesPerSample); |
71 RTC_DCHECK_GE(nChannels, 1); | 75 RTC_DCHECK_GE(nChannels, 1); |
72 RTC_DCHECK_LE(nChannels, 2); | 76 RTC_DCHECK_LE(nChannels, 2); |
73 RTC_DCHECK_GE( | 77 RTC_DCHECK_GE( |
74 samplesPerSec, | 78 samplesPerSec, |
75 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); | 79 static_cast<uint32_t>(AudioProcessing::NativeRate::kSampleRate8kHz)); |
76 | 80 |
77 // 100 = 1 second / data duration (10 ms). | 81 // 100 = 1 second / data duration (10 ms). |
78 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); | 82 RTC_DCHECK_EQ(nSamples * 100, samplesPerSec); |
79 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, | 83 RTC_DCHECK_LE(nBytesPerSample * nSamples * nChannels, |
80 sizeof(AudioFrame::data_)); | 84 AudioFrame::kMaxDataSizeBytes); |
81 | 85 |
82 mixer_->Mix(nChannels, &mixed_frame_); | 86 mixer_->Mix(nChannels, &mixed_frame_); |
83 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_; | 87 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_; |
84 *ntp_time_ms = mixed_frame_.ntp_time_ms_; | 88 *ntp_time_ms = mixed_frame_.ntp_time_ms_; |
85 | 89 |
86 const auto error = apm_->ProcessReverseStream(&mixed_frame_); | 90 const auto error = apm_->ProcessReverseStream(&mixed_frame_); |
87 RTC_DCHECK_EQ(error, AudioProcessing::kNoError); | 91 RTC_DCHECK_EQ(error, AudioProcessing::kNoError); |
88 | 92 |
89 nSamplesOut = Resample(mixed_frame_, samplesPerSec, &resampler_, | 93 nSamplesOut = Resample(mixed_frame_, samplesPerSec, &resampler_, |
90 static_cast<int16_t*>(audioSamples)); | 94 static_cast<int16_t*>(audioSamples)); |
(...skipping 22 matching lines...) Expand all Loading... | |
113 RTC_DCHECK_EQ(bits_per_sample, 16); | 117 RTC_DCHECK_EQ(bits_per_sample, 16); |
114 RTC_DCHECK_GE(number_of_channels, 1); | 118 RTC_DCHECK_GE(number_of_channels, 1); |
115 RTC_DCHECK_LE(number_of_channels, 2); | 119 RTC_DCHECK_LE(number_of_channels, 2); |
116 RTC_DCHECK_GE(sample_rate, AudioProcessing::NativeRate::kSampleRate8kHz); | 120 RTC_DCHECK_GE(sample_rate, AudioProcessing::NativeRate::kSampleRate8kHz); |
117 | 121 |
118 // 100 = 1 second / data duration (10 ms). | 122 // 100 = 1 second / data duration (10 ms). |
119 RTC_DCHECK_EQ(number_of_frames * 100, sample_rate); | 123 RTC_DCHECK_EQ(number_of_frames * 100, sample_rate); |
120 | 124 |
121 // 8 = bits per byte. | 125 // 8 = bits per byte. |
122 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, | 126 RTC_DCHECK_LE(bits_per_sample / 8 * number_of_frames * number_of_channels, |
123 sizeof(AudioFrame::data_)); | 127 AudioFrame::kMaxDataSizeBytes); |
124 mixer_->Mix(number_of_channels, &mixed_frame_); | 128 mixer_->Mix(number_of_channels, &mixed_frame_); |
125 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_; | 129 *elapsed_time_ms = mixed_frame_.elapsed_time_ms_; |
126 *ntp_time_ms = mixed_frame_.ntp_time_ms_; | 130 *ntp_time_ms = mixed_frame_.ntp_time_ms_; |
127 | 131 |
128 const auto output_samples = Resample(mixed_frame_, sample_rate, &resampler_, | 132 const auto output_samples = Resample(mixed_frame_, sample_rate, &resampler_, |
129 static_cast<int16_t*>(audio_data)); | 133 static_cast<int16_t*>(audio_data)); |
130 RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames); | 134 RTC_DCHECK_EQ(output_samples, number_of_channels * number_of_frames); |
131 } | 135 } |
132 | 136 |
133 } // namespace webrtc | 137 } // namespace webrtc |
OLD | NEW |