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

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

Issue 1412683006: RentACodec: New class that takes over part of ACMCodecDB's job (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 << "labeled VAD-passive"; 104 << "labeled VAD-passive";
105 break; 105 break;
106 } 106 }
107 default: 107 default:
108 assert(false); 108 assert(false);
109 } 109 }
110 } 110 }
111 } 111 }
112 112
113 // Is the given codec a CNG codec? 113 // Is the given codec a CNG codec?
114 // TODO(kwiberg): Move to RentACodec.
114 bool IsCng(int codec_id) { 115 bool IsCng(int codec_id) {
115 return (codec_id == ACMCodecDB::kCNNB || codec_id == ACMCodecDB::kCNWB || 116 auto i = RentACodec::CodecIdFromIndex(codec_id);
116 codec_id == ACMCodecDB::kCNSWB || codec_id == ACMCodecDB::kCNFB); 117 return (i && (*i == RentACodec::CodecId::kCNNB ||
118 *i == RentACodec::CodecId::kCNWB ||
119 *i == RentACodec::CodecId::kCNSWB ||
120 *i == RentACodec::CodecId::kCNFB));
117 } 121 }
118 122
119 } // namespace 123 } // namespace
120 124
121 AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config) 125 AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config)
122 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 126 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
123 id_(config.id), 127 id_(config.id),
124 last_audio_decoder_(nullptr), 128 last_audio_decoder_(nullptr),
125 previous_audio_activity_(AudioFrame::kVadPassive), 129 previous_audio_activity_(AudioFrame::kVadPassive),
126 current_sample_rate_hz_(config.neteq_config.sample_rate_hz), 130 current_sample_rate_hz_(config.neteq_config.sample_rate_hz),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 238 }
235 const int sample_rate_hz = ACMCodecDB::CodecFreq(decoder->acm_codec_id); 239 const int sample_rate_hz = ACMCodecDB::CodecFreq(decoder->acm_codec_id);
236 receive_timestamp = NowInTimestamp(sample_rate_hz); 240 receive_timestamp = NowInTimestamp(sample_rate_hz);
237 241
238 if (IsCng(decoder->acm_codec_id)) { 242 if (IsCng(decoder->acm_codec_id)) {
239 // If this is a CNG while the audio codec is not mono skip pushing in 243 // If this is a CNG while the audio codec is not mono skip pushing in
240 // packets into NetEq. 244 // packets into NetEq.
241 if (last_audio_decoder_ && last_audio_decoder_->channels > 1) 245 if (last_audio_decoder_ && last_audio_decoder_->channels > 1)
242 return 0; 246 return 0;
243 packet_type = InitialDelayManager::kCngPacket; 247 packet_type = InitialDelayManager::kCngPacket;
244 } else if (decoder->acm_codec_id == ACMCodecDB::kAVT) { 248 } else if (decoder->acm_codec_id ==
249 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) {
245 packet_type = InitialDelayManager::kAvtPacket; 250 packet_type = InitialDelayManager::kAvtPacket;
246 } else { 251 } else {
247 if (decoder != last_audio_decoder_) { 252 if (decoder != last_audio_decoder_) {
248 // This is either the first audio packet or send codec is changed. 253 // This is either the first audio packet or send codec is changed.
249 // Therefore, either NetEq buffer is empty or will be flushed when this 254 // Therefore, either NetEq buffer is empty or will be flushed when this
250 // packet is inserted. 255 // packet is inserted.
251 new_codec = true; 256 new_codec = true;
252 257
253 // Updating NACK'sampling rate is required, either first packet is 258 // Updating NACK'sampling rate is required, either first packet is
254 // received or codec is changed. Furthermore, reset is required if codec 259 // received or codec is changed. Furthermore, reset is required if codec
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 564 }
560 return neteq_->GetPlayoutTimestamp(timestamp); 565 return neteq_->GetPlayoutTimestamp(timestamp);
561 } 566 }
562 567
563 int AcmReceiver::last_audio_codec_id() const { 568 int AcmReceiver::last_audio_codec_id() const {
564 CriticalSectionScoped lock(crit_sect_.get()); 569 CriticalSectionScoped lock(crit_sect_.get());
565 return last_audio_decoder_ ? last_audio_decoder_->acm_codec_id : -1; 570 return last_audio_decoder_ ? last_audio_decoder_->acm_codec_id : -1;
566 } 571 }
567 572
568 int AcmReceiver::RedPayloadType() const { 573 int AcmReceiver::RedPayloadType() const {
569 if (ACMCodecDB::kRED >= 0) { // This ensures that RED is defined in WebRTC. 574 const auto red_index =
575 RentACodec::CodecIndexFromId(RentACodec::CodecId::kRED);
576 if (red_index) {
570 CriticalSectionScoped lock(crit_sect_.get()); 577 CriticalSectionScoped lock(crit_sect_.get());
571 for (const auto& decoder_pair : decoders_) { 578 for (const auto& decoder_pair : decoders_) {
572 const Decoder& decoder = decoder_pair.second; 579 const Decoder& decoder = decoder_pair.second;
573 if (decoder.acm_codec_id == ACMCodecDB::kRED) 580 if (decoder.acm_codec_id == *red_index)
574 return decoder.payload_type; 581 return decoder.payload_type;
575 } 582 }
576 } 583 }
577 LOG(WARNING) << "RED is not registered."; 584 LOG(WARNING) << "RED is not registered.";
578 return -1; 585 return -1;
579 } 586 }
580 587
581 int AcmReceiver::LastAudioCodec(CodecInst* codec) const { 588 int AcmReceiver::LastAudioCodec(CodecInst* codec) const {
582 CriticalSectionScoped lock(crit_sect_.get()); 589 CriticalSectionScoped lock(crit_sect_.get());
583 if (!last_audio_decoder_) { 590 if (!last_audio_decoder_) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 frame->vad_activity_ = AudioFrame::kVadPassive; 737 frame->vad_activity_ = AudioFrame::kVadPassive;
731 size_t samples = frame->samples_per_channel_ * frame->num_channels_; 738 size_t samples = frame->samples_per_channel_ * frame->num_channels_;
732 memset(frame->data_, 0, samples * sizeof(int16_t)); 739 memset(frame->data_, 0, samples * sizeof(int16_t));
733 return true; 740 return true;
734 } 741 }
735 742
736 const AcmReceiver::Decoder* AcmReceiver::RtpHeaderToDecoder( 743 const AcmReceiver::Decoder* AcmReceiver::RtpHeaderToDecoder(
737 const RTPHeader& rtp_header, 744 const RTPHeader& rtp_header,
738 const uint8_t* payload) const { 745 const uint8_t* payload) const {
739 auto it = decoders_.find(rtp_header.payloadType); 746 auto it = decoders_.find(rtp_header.payloadType);
740 if (ACMCodecDB::kRED >= 0 && // This ensures that RED is defined in WebRTC. 747 const auto red_index =
741 it != decoders_.end() && ACMCodecDB::kRED == it->second.acm_codec_id) { 748 RentACodec::CodecIndexFromId(RentACodec::CodecId::kRED);
749 if (red_index && // This ensures that RED is defined in WebRTC.
750 it != decoders_.end() &&
751 it->second.acm_codec_id == *red_index) {
742 // This is a RED packet, get the payload of the audio codec. 752 // This is a RED packet, get the payload of the audio codec.
743 it = decoders_.find(payload[0] & 0x7F); 753 it = decoders_.find(payload[0] & 0x7F);
744 } 754 }
745 755
746 // Check if the payload is registered. 756 // Check if the payload is registered.
747 return it != decoders_.end() ? &it->second : nullptr; 757 return it != decoders_.end() ? &it->second : nullptr;
748 } 758 }
749 759
750 uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const { 760 uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const {
751 // Down-cast the time to (32-6)-bit since we only care about 761 // Down-cast the time to (32-6)-bit since we only care about
(...skipping 25 matching lines...) Expand all
777 787
778 void AcmReceiver::GetDecodingCallStatistics( 788 void AcmReceiver::GetDecodingCallStatistics(
779 AudioDecodingCallStats* stats) const { 789 AudioDecodingCallStats* stats) const {
780 CriticalSectionScoped lock(crit_sect_.get()); 790 CriticalSectionScoped lock(crit_sect_.get());
781 *stats = call_stats_.GetDecodingStatistics(); 791 *stats = call_stats_.GetDecodingStatistics();
782 } 792 }
783 793
784 } // namespace acm2 794 } // namespace acm2
785 795
786 } // namespace webrtc 796 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698