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

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

Issue 1467183002: Add new method AcmReceiver::last_packet_sample_rate_hz() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@neteq-last-output-rate
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]), 126 audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
127 last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]), 127 last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
128 neteq_(NetEq::Create(config.neteq_config)), 128 neteq_(NetEq::Create(config.neteq_config)),
129 vad_enabled_(config.neteq_config.enable_post_decode_vad), 129 vad_enabled_(config.neteq_config.enable_post_decode_vad),
130 clock_(config.clock), 130 clock_(config.clock),
131 resampled_last_output_frame_(true) { 131 resampled_last_output_frame_(true),
132 last_packet_sample_rate_hz_() {
kwiberg-webrtc 2015/11/23 13:03:50 No need to call the default constructor explicitly
hlundin-webrtc 2015/11/23 13:50:45 Done.
132 assert(clock_); 133 assert(clock_);
133 memset(audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples); 134 memset(audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples);
134 memset(last_audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples); 135 memset(last_audio_buffer_.get(), 0, AudioFrame::kMaxDataSizeSamples);
135 } 136 }
136 137
137 AcmReceiver::~AcmReceiver() { 138 AcmReceiver::~AcmReceiver() {
138 delete neteq_; 139 delete neteq_;
139 } 140 }
140 141
141 int AcmReceiver::SetMinimumDelay(int delay_ms) { 142 int AcmReceiver::SetMinimumDelay(int delay_ms) {
142 if (neteq_->SetMinimumDelay(delay_ms)) 143 if (neteq_->SetMinimumDelay(delay_ms))
143 return 0; 144 return 0;
144 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; 145 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
145 return -1; 146 return -1;
146 } 147 }
147 148
148 int AcmReceiver::SetMaximumDelay(int delay_ms) { 149 int AcmReceiver::SetMaximumDelay(int delay_ms) {
149 if (neteq_->SetMaximumDelay(delay_ms)) 150 if (neteq_->SetMaximumDelay(delay_ms))
150 return 0; 151 return 0;
151 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; 152 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
152 return -1; 153 return -1;
153 } 154 }
154 155
155 int AcmReceiver::LeastRequiredDelayMs() const { 156 int AcmReceiver::LeastRequiredDelayMs() const {
156 return neteq_->LeastRequiredDelayMs(); 157 return neteq_->LeastRequiredDelayMs();
157 } 158 }
158 159
160 rtc::Optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
161 CriticalSectionScoped lock(crit_sect_.get());
162 return last_packet_sample_rate_hz_;
163 }
164
159 int AcmReceiver::last_output_sample_rate_hz() const { 165 int AcmReceiver::last_output_sample_rate_hz() const {
160 return neteq_->last_output_sample_rate_hz(); 166 return neteq_->last_output_sample_rate_hz();
161 } 167 }
162 168
163 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header, 169 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
164 rtc::ArrayView<const uint8_t> incoming_payload) { 170 rtc::ArrayView<const uint8_t> incoming_payload) {
165 uint32_t receive_timestamp = 0; 171 uint32_t receive_timestamp = 0;
166 const RTPHeader* header = &rtp_header.header; // Just a shorthand. 172 const RTPHeader* header = &rtp_header.header; // Just a shorthand.
167 173
168 { 174 {
(...skipping 14 matching lines...) Expand all
183 189
184 // If this is a CNG while the audio codec is not mono, skip pushing in 190 // If this is a CNG while the audio codec is not mono, skip pushing in
185 // packets into NetEq. 191 // packets into NetEq.
186 if (IsCng(decoder->acm_codec_id) && last_audio_decoder_ && 192 if (IsCng(decoder->acm_codec_id) && last_audio_decoder_ &&
187 last_audio_decoder_->channels > 1) 193 last_audio_decoder_->channels > 1)
188 return 0; 194 return 0;
189 if (!IsCng(decoder->acm_codec_id) && 195 if (!IsCng(decoder->acm_codec_id) &&
190 decoder->acm_codec_id != 196 decoder->acm_codec_id !=
191 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) { 197 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) {
192 last_audio_decoder_ = decoder; 198 last_audio_decoder_ = decoder;
199 last_packet_sample_rate_hz_ = rtc::Optional<int>(decoder->sample_rate_hz);
193 } 200 }
194 201
195 } // |crit_sect_| is released. 202 } // |crit_sect_| is released.
196 203
197 if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) < 204 if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) <
198 0) { 205 0) {
199 LOG(LERROR) << "AcmReceiver::InsertPacket " 206 LOG(LERROR) << "AcmReceiver::InsertPacket "
200 << static_cast<int>(header->payloadType) 207 << static_cast<int>(header->payloadType)
201 << " Failed to insert packet"; 208 << " Failed to insert packet";
202 return -1; 209 return -1;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 decoders_.erase(cur); 392 decoders_.erase(cur);
386 } else { 393 } else {
387 LOG_F(LS_ERROR) << "Cannot remove payload " 394 LOG_F(LS_ERROR) << "Cannot remove payload "
388 << static_cast<int>(cur->second.payload_type); 395 << static_cast<int>(cur->second.payload_type);
389 ret_val = -1; 396 ret_val = -1;
390 } 397 }
391 } 398 }
392 399
393 // No codec is registered, invalidate last audio decoder. 400 // No codec is registered, invalidate last audio decoder.
394 last_audio_decoder_ = nullptr; 401 last_audio_decoder_ = nullptr;
402 last_packet_sample_rate_hz_ = rtc::Optional<int>();
395 return ret_val; 403 return ret_val;
396 } 404 }
397 405
398 int AcmReceiver::RemoveCodec(uint8_t payload_type) { 406 int AcmReceiver::RemoveCodec(uint8_t payload_type) {
399 CriticalSectionScoped lock(crit_sect_.get()); 407 CriticalSectionScoped lock(crit_sect_.get());
400 auto it = decoders_.find(payload_type); 408 auto it = decoders_.find(payload_type);
401 if (it == decoders_.end()) { // Such a payload-type is not registered. 409 if (it == decoders_.end()) { // Such a payload-type is not registered.
402 return 0; 410 return 0;
403 } 411 }
404 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) { 412 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) {
405 LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type); 413 LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type);
406 return -1; 414 return -1;
407 } 415 }
408 if (last_audio_decoder_ == &it->second) 416 if (last_audio_decoder_ == &it->second) {
409 last_audio_decoder_ = nullptr; 417 last_audio_decoder_ = nullptr;
418 last_packet_sample_rate_hz_ = rtc::Optional<int>();
419 }
410 decoders_.erase(it); 420 decoders_.erase(it);
411 return 0; 421 return 0;
412 } 422 }
413 423
414 void AcmReceiver::set_id(int id) { 424 void AcmReceiver::set_id(int id) {
415 CriticalSectionScoped lock(crit_sect_.get()); 425 CriticalSectionScoped lock(crit_sect_.get());
416 id_ = id; 426 id_ = id;
417 } 427 }
418 428
419 bool AcmReceiver::GetPlayoutTimestamp(uint32_t* timestamp) { 429 bool AcmReceiver::GetPlayoutTimestamp(uint32_t* timestamp) {
420 return neteq_->GetPlayoutTimestamp(timestamp); 430 return neteq_->GetPlayoutTimestamp(timestamp);
421 } 431 }
422 432
423 int AcmReceiver::last_audio_codec_id() const {
424 CriticalSectionScoped lock(crit_sect_.get());
425 return last_audio_decoder_ ? last_audio_decoder_->acm_codec_id : -1;
426 }
427
428 int AcmReceiver::LastAudioCodec(CodecInst* codec) const { 433 int AcmReceiver::LastAudioCodec(CodecInst* codec) const {
429 CriticalSectionScoped lock(crit_sect_.get()); 434 CriticalSectionScoped lock(crit_sect_.get());
430 if (!last_audio_decoder_) { 435 if (!last_audio_decoder_) {
431 return -1; 436 return -1;
432 } 437 }
433 *codec = *RentACodec::CodecInstById( 438 *codec = *RentACodec::CodecInstById(
434 *RentACodec::CodecIdFromIndex(last_audio_decoder_->acm_codec_id)); 439 *RentACodec::CodecIdFromIndex(last_audio_decoder_->acm_codec_id));
435 codec->pltype = last_audio_decoder_->payload_type; 440 codec->pltype = last_audio_decoder_->payload_type;
436 codec->channels = last_audio_decoder_->channels; 441 codec->channels = last_audio_decoder_->channels;
437 codec->plfreq = last_audio_decoder_->sample_rate_hz; 442 codec->plfreq = last_audio_decoder_->sample_rate_hz;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 532
528 void AcmReceiver::GetDecodingCallStatistics( 533 void AcmReceiver::GetDecodingCallStatistics(
529 AudioDecodingCallStats* stats) const { 534 AudioDecodingCallStats* stats) const {
530 CriticalSectionScoped lock(crit_sect_.get()); 535 CriticalSectionScoped lock(crit_sect_.get());
531 *stats = call_stats_.GetDecodingStatistics(); 536 *stats = call_stats_.GetDecodingStatistics();
532 } 537 }
533 538
534 } // namespace acm2 539 } // namespace acm2
535 540
536 } // namespace webrtc 541 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698