OLD | NEW |
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 if (neteq_->SetMaximumDelay(delay_ms)) | 149 if (neteq_->SetMaximumDelay(delay_ms)) |
150 return 0; | 150 return 0; |
151 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; | 151 LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; |
152 return -1; | 152 return -1; |
153 } | 153 } |
154 | 154 |
155 int AcmReceiver::LeastRequiredDelayMs() const { | 155 int AcmReceiver::LeastRequiredDelayMs() const { |
156 return neteq_->LeastRequiredDelayMs(); | 156 return neteq_->LeastRequiredDelayMs(); |
157 } | 157 } |
158 | 158 |
| 159 rtc::Optional<int> AcmReceiver::last_packet_sample_rate_hz() const { |
| 160 CriticalSectionScoped lock(crit_sect_.get()); |
| 161 return last_packet_sample_rate_hz_; |
| 162 } |
| 163 |
159 int AcmReceiver::last_output_sample_rate_hz() const { | 164 int AcmReceiver::last_output_sample_rate_hz() const { |
160 return neteq_->last_output_sample_rate_hz(); | 165 return neteq_->last_output_sample_rate_hz(); |
161 } | 166 } |
162 | 167 |
163 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header, | 168 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header, |
164 rtc::ArrayView<const uint8_t> incoming_payload) { | 169 rtc::ArrayView<const uint8_t> incoming_payload) { |
165 uint32_t receive_timestamp = 0; | 170 uint32_t receive_timestamp = 0; |
166 const RTPHeader* header = &rtp_header.header; // Just a shorthand. | 171 const RTPHeader* header = &rtp_header.header; // Just a shorthand. |
167 | 172 |
168 { | 173 { |
(...skipping 14 matching lines...) Expand all Loading... |
183 | 188 |
184 // If this is a CNG while the audio codec is not mono, skip pushing in | 189 // If this is a CNG while the audio codec is not mono, skip pushing in |
185 // packets into NetEq. | 190 // packets into NetEq. |
186 if (IsCng(decoder->acm_codec_id) && last_audio_decoder_ && | 191 if (IsCng(decoder->acm_codec_id) && last_audio_decoder_ && |
187 last_audio_decoder_->channels > 1) | 192 last_audio_decoder_->channels > 1) |
188 return 0; | 193 return 0; |
189 if (!IsCng(decoder->acm_codec_id) && | 194 if (!IsCng(decoder->acm_codec_id) && |
190 decoder->acm_codec_id != | 195 decoder->acm_codec_id != |
191 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) { | 196 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) { |
192 last_audio_decoder_ = decoder; | 197 last_audio_decoder_ = decoder; |
| 198 last_packet_sample_rate_hz_ = rtc::Optional<int>(decoder->sample_rate_hz); |
193 } | 199 } |
194 | 200 |
195 } // |crit_sect_| is released. | 201 } // |crit_sect_| is released. |
196 | 202 |
197 if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) < | 203 if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) < |
198 0) { | 204 0) { |
199 LOG(LERROR) << "AcmReceiver::InsertPacket " | 205 LOG(LERROR) << "AcmReceiver::InsertPacket " |
200 << static_cast<int>(header->payloadType) | 206 << static_cast<int>(header->payloadType) |
201 << " Failed to insert packet"; | 207 << " Failed to insert packet"; |
202 return -1; | 208 return -1; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 decoders_.erase(cur); | 391 decoders_.erase(cur); |
386 } else { | 392 } else { |
387 LOG_F(LS_ERROR) << "Cannot remove payload " | 393 LOG_F(LS_ERROR) << "Cannot remove payload " |
388 << static_cast<int>(cur->second.payload_type); | 394 << static_cast<int>(cur->second.payload_type); |
389 ret_val = -1; | 395 ret_val = -1; |
390 } | 396 } |
391 } | 397 } |
392 | 398 |
393 // No codec is registered, invalidate last audio decoder. | 399 // No codec is registered, invalidate last audio decoder. |
394 last_audio_decoder_ = nullptr; | 400 last_audio_decoder_ = nullptr; |
| 401 last_packet_sample_rate_hz_ = rtc::Optional<int>(); |
395 return ret_val; | 402 return ret_val; |
396 } | 403 } |
397 | 404 |
398 int AcmReceiver::RemoveCodec(uint8_t payload_type) { | 405 int AcmReceiver::RemoveCodec(uint8_t payload_type) { |
399 CriticalSectionScoped lock(crit_sect_.get()); | 406 CriticalSectionScoped lock(crit_sect_.get()); |
400 auto it = decoders_.find(payload_type); | 407 auto it = decoders_.find(payload_type); |
401 if (it == decoders_.end()) { // Such a payload-type is not registered. | 408 if (it == decoders_.end()) { // Such a payload-type is not registered. |
402 return 0; | 409 return 0; |
403 } | 410 } |
404 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) { | 411 if (neteq_->RemovePayloadType(payload_type) != NetEq::kOK) { |
405 LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type); | 412 LOG(LERROR) << "AcmReceiver::RemoveCodec" << static_cast<int>(payload_type); |
406 return -1; | 413 return -1; |
407 } | 414 } |
408 if (last_audio_decoder_ == &it->second) | 415 if (last_audio_decoder_ == &it->second) { |
409 last_audio_decoder_ = nullptr; | 416 last_audio_decoder_ = nullptr; |
| 417 last_packet_sample_rate_hz_ = rtc::Optional<int>(); |
| 418 } |
410 decoders_.erase(it); | 419 decoders_.erase(it); |
411 return 0; | 420 return 0; |
412 } | 421 } |
413 | 422 |
414 void AcmReceiver::set_id(int id) { | 423 void AcmReceiver::set_id(int id) { |
415 CriticalSectionScoped lock(crit_sect_.get()); | 424 CriticalSectionScoped lock(crit_sect_.get()); |
416 id_ = id; | 425 id_ = id; |
417 } | 426 } |
418 | 427 |
419 bool AcmReceiver::GetPlayoutTimestamp(uint32_t* timestamp) { | 428 bool AcmReceiver::GetPlayoutTimestamp(uint32_t* timestamp) { |
420 return neteq_->GetPlayoutTimestamp(timestamp); | 429 return neteq_->GetPlayoutTimestamp(timestamp); |
421 } | 430 } |
422 | 431 |
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 { | 432 int AcmReceiver::LastAudioCodec(CodecInst* codec) const { |
429 CriticalSectionScoped lock(crit_sect_.get()); | 433 CriticalSectionScoped lock(crit_sect_.get()); |
430 if (!last_audio_decoder_) { | 434 if (!last_audio_decoder_) { |
431 return -1; | 435 return -1; |
432 } | 436 } |
433 *codec = *RentACodec::CodecInstById( | 437 *codec = *RentACodec::CodecInstById( |
434 *RentACodec::CodecIdFromIndex(last_audio_decoder_->acm_codec_id)); | 438 *RentACodec::CodecIdFromIndex(last_audio_decoder_->acm_codec_id)); |
435 codec->pltype = last_audio_decoder_->payload_type; | 439 codec->pltype = last_audio_decoder_->payload_type; |
436 codec->channels = last_audio_decoder_->channels; | 440 codec->channels = last_audio_decoder_->channels; |
437 codec->plfreq = last_audio_decoder_->sample_rate_hz; | 441 codec->plfreq = last_audio_decoder_->sample_rate_hz; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 | 531 |
528 void AcmReceiver::GetDecodingCallStatistics( | 532 void AcmReceiver::GetDecodingCallStatistics( |
529 AudioDecodingCallStats* stats) const { | 533 AudioDecodingCallStats* stats) const { |
530 CriticalSectionScoped lock(crit_sect_.get()); | 534 CriticalSectionScoped lock(crit_sect_.get()); |
531 *stats = call_stats_.GetDecodingStatistics(); | 535 *stats = call_stats_.GetDecodingStatistics(); |
532 } | 536 } |
533 | 537 |
534 } // namespace acm2 | 538 } // namespace acm2 |
535 | 539 |
536 } // namespace webrtc | 540 } // namespace webrtc |
OLD | NEW |