Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/acm_receiver.cc

Issue 1467163002: NetEq: Add new method last_output_sample_rate_hz (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 *i == RentACodec::CodecId::kCNFB)); 116 *i == RentACodec::CodecId::kCNFB));
117 } 117 }
118 118
119 } // namespace 119 } // namespace
120 120
121 AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config) 121 AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config)
122 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 122 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
123 id_(config.id), 123 id_(config.id),
124 last_audio_decoder_(nullptr), 124 last_audio_decoder_(nullptr),
125 previous_audio_activity_(AudioFrame::kVadPassive), 125 previous_audio_activity_(AudioFrame::kVadPassive),
126 current_sample_rate_hz_(config.neteq_config.sample_rate_hz),
127 audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]), 126 audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
128 last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]), 127 last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
129 neteq_(NetEq::Create(config.neteq_config)), 128 neteq_(NetEq::Create(config.neteq_config)),
130 vad_enabled_(config.neteq_config.enable_post_decode_vad), 129 vad_enabled_(config.neteq_config.enable_post_decode_vad),
131 clock_(config.clock), 130 clock_(config.clock),
132 resampled_last_output_frame_(true) { 131 resampled_last_output_frame_(true) {
133 assert(clock_); 132 assert(clock_);
134 memset(audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples); 133 memset(audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples);
135 memset(last_audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples); 134 memset(last_audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples);
136 } 135 }
(...skipping 13 matching lines...) Expand all
150 if (neteq_->SetMaximumDelay(delay_ms)) 149 if (neteq_->SetMaximumDelay(delay_ms))
151 return 0; 150 return 0;
152 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; 151 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
153 return -1; 152 return -1;
154 } 153 }
155 154
156 int AcmReceiver::LeastRequiredDelayMs() const { 155 int AcmReceiver::LeastRequiredDelayMs() const {
157 return neteq_->LeastRequiredDelayMs(); 156 return neteq_->LeastRequiredDelayMs();
158 } 157 }
159 158
160 int AcmReceiver::current_sample_rate_hz() const { 159 int AcmReceiver::last_output_sample_rate_hz() const {
161 CriticalSectionScoped lock(crit_sect_.get()); 160 return neteq_->last_output_sample_rate_hz();
162 return current_sample_rate_hz_;
163 } 161 }
164 162
165 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header, 163 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
166 rtc::ArrayView<const uint8_t> incoming_payload) { 164 rtc::ArrayView<const uint8_t> incoming_payload) {
167 uint32_t receive_timestamp = 0; 165 uint32_t receive_timestamp = 0;
168 const RTPHeader* header = &rtp_header.header; // Just a shorthand. 166 const RTPHeader* header = &rtp_header.header; // Just a shorthand.
169 167
170 { 168 {
171 CriticalSectionScoped lock(crit_sect_.get()); 169 CriticalSectionScoped lock(crit_sect_.get());
172 170
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Always write the output to |audio_buffer_| first. 215 // Always write the output to |audio_buffer_| first.
218 if (neteq_->GetAudio(AudioFrame::kMaxDataSizeSamples, 216 if (neteq_->GetAudio(AudioFrame::kMaxDataSizeSamples,
219 audio_buffer_.get(), 217 audio_buffer_.get(),
220 &samples_per_channel, 218 &samples_per_channel,
221 &num_channels, 219 &num_channels,
222 &type) != NetEq::kOK) { 220 &type) != NetEq::kOK) {
223 LOG(LERROR) << "AcmReceiver::GetAudio - NetEq Failed."; 221 LOG(LERROR) << "AcmReceiver::GetAudio - NetEq Failed.";
224 return -1; 222 return -1;
225 } 223 }
226 224
227 // NetEq always returns 10 ms of audio. 225 const int current_sample_rate_hz = neteq_->last_output_sample_rate_hz();
kwiberg-webrtc 2015/11/23 13:11:51 Excellent idea to use const here.
228 current_sample_rate_hz_ = static_cast<int>(samples_per_channel * 100);
229 226
230 // Update if resampling is required. 227 // Update if resampling is required.
231 bool need_resampling = (desired_freq_hz != -1) && 228 const bool need_resampling =
232 (current_sample_rate_hz_ != desired_freq_hz); 229 (desired_freq_hz != -1) && (current_sample_rate_hz != desired_freq_hz);
233 230
234 if (need_resampling && !resampled_last_output_frame_) { 231 if (need_resampling && !resampled_last_output_frame_) {
235 // Prime the resampler with the last frame. 232 // Prime the resampler with the last frame.
236 int16_t temp_output[AudioFrame::kMaxDataSizeSamples]; 233 int16_t temp_output[AudioFrame::kMaxDataSizeSamples];
237 int samples_per_channel_int = 234 int samples_per_channel_int = resampler_.Resample10Msec(
hlundin-webrtc 2015/11/23 11:54:33 The only actual change in this block is that the l
kwiberg-webrtc 2015/11/23 13:11:51 Acknowledged.
238 resampler_.Resample10Msec(last_audio_buffer_.get(), 235 last_audio_buffer_.get(), current_sample_rate_hz, desired_freq_hz,
239 current_sample_rate_hz_, 236 num_channels, AudioFrame::kMaxDataSizeSamples, temp_output);
240 desired_freq_hz,
241 num_channels,
242 AudioFrame::kMaxDataSizeSamples,
243 temp_output);
244 if (samples_per_channel_int < 0) { 237 if (samples_per_channel_int < 0) {
245 LOG(LERROR) << "AcmReceiver::GetAudio - " 238 LOG(LERROR) << "AcmReceiver::GetAudio - "
246 "Resampling last_audio_buffer_ failed."; 239 "Resampling last_audio_buffer_ failed.";
247 return -1; 240 return -1;
248 } 241 }
249 samples_per_channel = static_cast<size_t>(samples_per_channel_int); 242 samples_per_channel = static_cast<size_t>(samples_per_channel_int);
250 } 243 }
251 244
252 // The audio in |audio_buffer_| is tansferred to |audio_frame_| below, either 245 // The audio in |audio_buffer_| is tansferred to |audio_frame_| below, either
253 // through resampling, or through straight memcpy. 246 // through resampling, or through straight memcpy.
254 // TODO(henrik.lundin) Glitches in the output may appear if the output rate 247 // TODO(henrik.lundin) Glitches in the output may appear if the output rate
255 // from NetEq changes. See WebRTC issue 3923. 248 // from NetEq changes. See WebRTC issue 3923.
256 if (need_resampling) { 249 if (need_resampling) {
257 int samples_per_channel_int = 250 int samples_per_channel_int = resampler_.Resample10Msec(
hlundin-webrtc 2015/11/23 11:54:33 The only actual change in this block is that the l
kwiberg-webrtc 2015/11/23 13:11:51 Acknowledged.
258 resampler_.Resample10Msec(audio_buffer_.get(), 251 audio_buffer_.get(), current_sample_rate_hz, desired_freq_hz,
259 current_sample_rate_hz_, 252 num_channels, AudioFrame::kMaxDataSizeSamples, audio_frame->data_);
260 desired_freq_hz,
261 num_channels,
262 AudioFrame::kMaxDataSizeSamples,
263 audio_frame->data_);
264 if (samples_per_channel_int < 0) { 253 if (samples_per_channel_int < 0) {
265 LOG(LERROR) << "AcmReceiver::GetAudio - Resampling audio_buffer_ failed."; 254 LOG(LERROR) << "AcmReceiver::GetAudio - Resampling audio_buffer_ failed.";
266 return -1; 255 return -1;
267 } 256 }
268 samples_per_channel = static_cast<size_t>(samples_per_channel_int); 257 samples_per_channel = static_cast<size_t>(samples_per_channel_int);
269 resampled_last_output_frame_ = true; 258 resampled_last_output_frame_ = true;
270 } else { 259 } else {
271 resampled_last_output_frame_ = false; 260 resampled_last_output_frame_ = false;
272 // We might end up here ONLY if codec is changed. 261 // We might end up here ONLY if codec is changed.
273 memcpy(audio_frame->data_, 262 memcpy(audio_frame->data_,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 527
539 void AcmReceiver::GetDecodingCallStatistics( 528 void AcmReceiver::GetDecodingCallStatistics(
540 AudioDecodingCallStats* stats) const { 529 AudioDecodingCallStats* stats) const {
541 CriticalSectionScoped lock(crit_sect_.get()); 530 CriticalSectionScoped lock(crit_sect_.get());
542 *stats = call_stats_.GetDecodingStatistics(); 531 *stats = call_stats_.GetDecodingStatistics();
543 } 532 }
544 533
545 } // namespace acm2 534 } // namespace acm2
546 535
547 } // namespace webrtc 536 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698