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

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

Issue 1429943004: AcmReceiver::InsertPacket and NetEq::InsertPacket: Take ArrayView arguments (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix log message 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 int AcmReceiver::LeastRequiredDelayMs() const { 156 int AcmReceiver::LeastRequiredDelayMs() const {
157 return neteq_->LeastRequiredDelayMs(); 157 return neteq_->LeastRequiredDelayMs();
158 } 158 }
159 159
160 int AcmReceiver::current_sample_rate_hz() const { 160 int AcmReceiver::current_sample_rate_hz() const {
161 CriticalSectionScoped lock(crit_sect_.get()); 161 CriticalSectionScoped lock(crit_sect_.get());
162 return current_sample_rate_hz_; 162 return current_sample_rate_hz_;
163 } 163 }
164 164
165 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header, 165 int AcmReceiver::InsertPacket(const WebRtcRTPHeader& rtp_header,
166 const uint8_t* incoming_payload, 166 rtc::ArrayView<const uint8_t> incoming_payload) {
167 size_t length_payload) {
168 uint32_t receive_timestamp = 0; 167 uint32_t receive_timestamp = 0;
169 const RTPHeader* header = &rtp_header.header; // Just a shorthand. 168 const RTPHeader* header = &rtp_header.header; // Just a shorthand.
170 169
171 { 170 {
172 CriticalSectionScoped lock(crit_sect_.get()); 171 CriticalSectionScoped lock(crit_sect_.get());
173 172
174 const Decoder* decoder = RtpHeaderToDecoder(*header, incoming_payload); 173 const Decoder* decoder = RtpHeaderToDecoder(*header, incoming_payload[0]);
175 if (!decoder) { 174 if (!decoder) {
176 LOG_F(LS_ERROR) << "Payload-type " 175 LOG_F(LS_ERROR) << "Payload-type "
177 << static_cast<int>(header->payloadType) 176 << static_cast<int>(header->payloadType)
178 << " is not registered."; 177 << " is not registered.";
179 return -1; 178 return -1;
180 } 179 }
181 const int sample_rate_hz = [&decoder] { 180 const int sample_rate_hz = [&decoder] {
182 const auto ci = RentACodec::CodecIdFromIndex(decoder->acm_codec_id); 181 const auto ci = RentACodec::CodecIdFromIndex(decoder->acm_codec_id);
183 return ci ? RentACodec::CodecInstById(*ci)->plfreq : -1; 182 return ci ? RentACodec::CodecInstById(*ci)->plfreq : -1;
184 }(); 183 }();
185 receive_timestamp = NowInTimestamp(sample_rate_hz); 184 receive_timestamp = NowInTimestamp(sample_rate_hz);
186 185
187 // If this is a CNG while the audio codec is not mono, skip pushing in 186 // If this is a CNG while the audio codec is not mono, skip pushing in
188 // packets into NetEq. 187 // packets into NetEq.
189 if (IsCng(decoder->acm_codec_id) && last_audio_decoder_ && 188 if (IsCng(decoder->acm_codec_id) && last_audio_decoder_ &&
190 last_audio_decoder_->channels > 1) 189 last_audio_decoder_->channels > 1)
191 return 0; 190 return 0;
192 if (!IsCng(decoder->acm_codec_id) && 191 if (!IsCng(decoder->acm_codec_id) &&
193 decoder->acm_codec_id != 192 decoder->acm_codec_id !=
194 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) { 193 *RentACodec::CodecIndexFromId(RentACodec::CodecId::kAVT)) {
195 last_audio_decoder_ = decoder; 194 last_audio_decoder_ = decoder;
196 } 195 }
197 196
198 } // |crit_sect_| is released. 197 } // |crit_sect_| is released.
199 198
200 if (neteq_->InsertPacket(rtp_header, incoming_payload, length_payload, 199 if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) <
201 receive_timestamp) < 0) { 200 0) {
202 LOG(LERROR) << "AcmReceiver::InsertPacket " 201 LOG(LERROR) << "AcmReceiver::InsertPacket "
203 << static_cast<int>(header->payloadType) 202 << static_cast<int>(header->payloadType)
204 << " Failed to insert packet"; 203 << " Failed to insert packet";
205 return -1; 204 return -1;
206 } 205 }
207 return 0; 206 return 0;
208 } 207 }
209 208
210 int AcmReceiver::GetAudio(int desired_freq_hz, AudioFrame* audio_frame) { 209 int AcmReceiver::GetAudio(int desired_freq_hz, AudioFrame* audio_frame) {
211 enum NetEqOutputType type; 210 enum NetEqOutputType type;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 return neteq_->GetNackList(round_trip_time_ms); 504 return neteq_->GetNackList(round_trip_time_ms);
506 } 505 }
507 506
508 void AcmReceiver::ResetInitialDelay() { 507 void AcmReceiver::ResetInitialDelay() {
509 neteq_->SetMinimumDelay(0); 508 neteq_->SetMinimumDelay(0);
510 // TODO(turajs): Should NetEq Buffer be flushed? 509 // TODO(turajs): Should NetEq Buffer be flushed?
511 } 510 }
512 511
513 const AcmReceiver::Decoder* AcmReceiver::RtpHeaderToDecoder( 512 const AcmReceiver::Decoder* AcmReceiver::RtpHeaderToDecoder(
514 const RTPHeader& rtp_header, 513 const RTPHeader& rtp_header,
515 const uint8_t* payload) const { 514 uint8_t payload_type) const {
516 auto it = decoders_.find(rtp_header.payloadType); 515 auto it = decoders_.find(rtp_header.payloadType);
517 const auto red_index = 516 const auto red_index =
518 RentACodec::CodecIndexFromId(RentACodec::CodecId::kRED); 517 RentACodec::CodecIndexFromId(RentACodec::CodecId::kRED);
519 if (red_index && // This ensures that RED is defined in WebRTC. 518 if (red_index && // This ensures that RED is defined in WebRTC.
520 it != decoders_.end() && it->second.acm_codec_id == *red_index) { 519 it != decoders_.end() && it->second.acm_codec_id == *red_index) {
521 // This is a RED packet, get the payload of the audio codec. 520 // This is a RED packet, get the payload of the audio codec.
522 it = decoders_.find(payload[0] & 0x7F); 521 it = decoders_.find(payload_type & 0x7F);
523 } 522 }
524 523
525 // Check if the payload is registered. 524 // Check if the payload is registered.
526 return it != decoders_.end() ? &it->second : nullptr; 525 return it != decoders_.end() ? &it->second : nullptr;
527 } 526 }
528 527
529 uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const { 528 uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const {
530 // Down-cast the time to (32-6)-bit since we only care about 529 // Down-cast the time to (32-6)-bit since we only care about
531 // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms. 530 // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms.
532 // We masked 6 most significant bits of 32-bit so there is no overflow in 531 // We masked 6 most significant bits of 32-bit so there is no overflow in
533 // the conversion from milliseconds to timestamp. 532 // the conversion from milliseconds to timestamp.
534 const uint32_t now_in_ms = static_cast<uint32_t>( 533 const uint32_t now_in_ms = static_cast<uint32_t>(
535 clock_->TimeInMilliseconds() & 0x03ffffff); 534 clock_->TimeInMilliseconds() & 0x03ffffff);
536 return static_cast<uint32_t>( 535 return static_cast<uint32_t>(
537 (decoder_sampling_rate / 1000) * now_in_ms); 536 (decoder_sampling_rate / 1000) * now_in_ms);
538 } 537 }
539 538
540 void AcmReceiver::GetDecodingCallStatistics( 539 void AcmReceiver::GetDecodingCallStatistics(
541 AudioDecodingCallStats* stats) const { 540 AudioDecodingCallStats* stats) const {
542 CriticalSectionScoped lock(crit_sect_.get()); 541 CriticalSectionScoped lock(crit_sect_.get());
543 *stats = call_stats_.GetDecodingStatistics(); 542 *stats = call_stats_.GetDecodingStatistics();
544 } 543 }
545 544
546 } // namespace acm2 545 } // namespace acm2
547 546
548 } // namespace webrtc 547 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698