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

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl.cc

Issue 1429943004: AcmReceiver::InsertPacket and NetEq::InsertPacket: Take ArrayView arguments (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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 RTC_DCHECK(!vad_->enabled()); 115 RTC_DCHECK(!vad_->enabled());
116 if (config.enable_post_decode_vad) { 116 if (config.enable_post_decode_vad) {
117 vad_->Enable(); 117 vad_->Enable();
118 } 118 }
119 } 119 }
120 120
121 NetEqImpl::~NetEqImpl() = default; 121 NetEqImpl::~NetEqImpl() = default;
122 122
123 int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header, 123 int NetEqImpl::InsertPacket(const WebRtcRTPHeader& rtp_header,
124 const uint8_t* payload, 124 rtc::ArrayView<const uint8_t> payload,
125 size_t length_bytes,
126 uint32_t receive_timestamp) { 125 uint32_t receive_timestamp) {
127 CriticalSectionScoped lock(crit_sect_.get()); 126 CriticalSectionScoped lock(crit_sect_.get());
128 LOG(LS_VERBOSE) << "InsertPacket: ts=" << rtp_header.header.timestamp << 127 LOG(LS_VERBOSE) << "InsertPacket: ts=" << rtp_header.header.timestamp
129 ", sn=" << rtp_header.header.sequenceNumber << 128 << ", sn=" << rtp_header.header.sequenceNumber
130 ", pt=" << static_cast<int>(rtp_header.header.payloadType) << 129 << ", pt=" << static_cast<int>(rtp_header.header.payloadType)
131 ", ssrc=" << rtp_header.header.ssrc << 130 << ", ssrc=" << rtp_header.header.ssrc
132 ", len=" << length_bytes; 131 << ", len=" << payload.size();
133 int error = InsertPacketInternal(rtp_header, payload, length_bytes, 132 int error =
134 receive_timestamp, false); 133 InsertPacketInternal(rtp_header, payload, receive_timestamp, false);
135 if (error != 0) { 134 if (error != 0) {
136 error_code_ = error; 135 error_code_ = error;
137 return kFail; 136 return kFail;
138 } 137 }
139 return kOK; 138 return kOK;
140 } 139 }
141 140
142 int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header, 141 int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header,
143 uint32_t receive_timestamp) { 142 uint32_t receive_timestamp) {
144 CriticalSectionScoped lock(crit_sect_.get()); 143 CriticalSectionScoped lock(crit_sect_.get());
145 LOG(LS_VERBOSE) << "InsertPacket-Sync: ts=" 144 LOG(LS_VERBOSE) << "InsertPacket-Sync: ts="
146 << rtp_header.header.timestamp << 145 << rtp_header.header.timestamp <<
147 ", sn=" << rtp_header.header.sequenceNumber << 146 ", sn=" << rtp_header.header.sequenceNumber <<
148 ", pt=" << static_cast<int>(rtp_header.header.payloadType) << 147 ", pt=" << static_cast<int>(rtp_header.header.payloadType) <<
149 ", ssrc=" << rtp_header.header.ssrc; 148 ", ssrc=" << rtp_header.header.ssrc;
150 149
151 const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' }; 150 const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' };
152 int error = InsertPacketInternal( 151 int error =
153 rtp_header, kSyncPayload, sizeof(kSyncPayload), receive_timestamp, true); 152 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true);
154 153
155 if (error != 0) { 154 if (error != 0) {
156 error_code_ = error; 155 error_code_ = error;
157 return kFail; 156 return kFail;
158 } 157 }
159 return kOK; 158 return kOK;
160 } 159 }
161 160
162 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio, 161 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio,
163 size_t* samples_per_channel, int* num_channels, 162 size_t* samples_per_channel, int* num_channels,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 437 }
439 438
440 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const { 439 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const {
441 CriticalSectionScoped lock(crit_sect_.get()); 440 CriticalSectionScoped lock(crit_sect_.get());
442 return sync_buffer_.get(); 441 return sync_buffer_.get();
443 } 442 }
444 443
445 // Methods below this line are private. 444 // Methods below this line are private.
446 445
447 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, 446 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header,
448 const uint8_t* payload, 447 rtc::ArrayView<const uint8_t> payload,
449 size_t length_bytes,
450 uint32_t receive_timestamp, 448 uint32_t receive_timestamp,
451 bool is_sync_packet) { 449 bool is_sync_packet) {
452 if (!payload) { 450 if (payload.empty()) {
453 LOG_F(LS_ERROR) << "payload == NULL"; 451 LOG_F(LS_ERROR) << "payload == NULL";
hlundin-webrtc 2015/11/10 10:14:35 "payload == NULL" is not as correct as it used to
kwiberg-webrtc 2015/11/10 10:27:59 Done.
454 return kInvalidPointer; 452 return kInvalidPointer;
455 } 453 }
456 // Sanity checks for sync-packets. 454 // Sanity checks for sync-packets.
457 if (is_sync_packet) { 455 if (is_sync_packet) {
458 if (decoder_database_->IsDtmf(rtp_header.header.payloadType) || 456 if (decoder_database_->IsDtmf(rtp_header.header.payloadType) ||
459 decoder_database_->IsRed(rtp_header.header.payloadType) || 457 decoder_database_->IsRed(rtp_header.header.payloadType) ||
460 decoder_database_->IsComfortNoise(rtp_header.header.payloadType)) { 458 decoder_database_->IsComfortNoise(rtp_header.header.payloadType)) {
461 LOG_F(LS_ERROR) << "Sync-packet with an unacceptable payload type " 459 LOG_F(LS_ERROR) << "Sync-packet with an unacceptable payload type "
462 << static_cast<int>(rtp_header.header.payloadType); 460 << static_cast<int>(rtp_header.header.payloadType);
463 return kSyncPacketNotAccepted; 461 return kSyncPacketNotAccepted;
(...skipping 15 matching lines...) Expand all
479 // Create |packet| within this separate scope, since it should not be used 477 // Create |packet| within this separate scope, since it should not be used
480 // directly once it's been inserted in the packet list. This way, |packet| 478 // directly once it's been inserted in the packet list. This way, |packet|
481 // is not defined outside of this block. 479 // is not defined outside of this block.
482 Packet* packet = new Packet; 480 Packet* packet = new Packet;
483 packet->header.markerBit = false; 481 packet->header.markerBit = false;
484 packet->header.payloadType = rtp_header.header.payloadType; 482 packet->header.payloadType = rtp_header.header.payloadType;
485 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; 483 packet->header.sequenceNumber = rtp_header.header.sequenceNumber;
486 packet->header.timestamp = rtp_header.header.timestamp; 484 packet->header.timestamp = rtp_header.header.timestamp;
487 packet->header.ssrc = rtp_header.header.ssrc; 485 packet->header.ssrc = rtp_header.header.ssrc;
488 packet->header.numCSRCs = 0; 486 packet->header.numCSRCs = 0;
489 packet->payload_length = length_bytes; 487 packet->payload_length = payload.size();
490 packet->primary = true; 488 packet->primary = true;
491 packet->waiting_time = 0; 489 packet->waiting_time = 0;
492 packet->payload = new uint8_t[packet->payload_length]; 490 packet->payload = new uint8_t[packet->payload_length];
493 packet->sync_packet = is_sync_packet; 491 packet->sync_packet = is_sync_packet;
494 if (!packet->payload) { 492 if (!packet->payload) {
495 LOG_F(LS_ERROR) << "Payload pointer is NULL."; 493 LOG_F(LS_ERROR) << "Payload pointer is NULL.";
496 } 494 }
497 assert(payload); // Already checked above. 495 assert(!payload.empty()); // Already checked above.
498 memcpy(packet->payload, payload, packet->payload_length); 496 memcpy(packet->payload, payload.data(), packet->payload_length);
499 // Insert packet in a packet list. 497 // Insert packet in a packet list.
500 packet_list.push_back(packet); 498 packet_list.push_back(packet);
501 // Save main payloads header for later. 499 // Save main payloads header for later.
502 memcpy(&main_header, &packet->header, sizeof(main_header)); 500 memcpy(&main_header, &packet->header, sizeof(main_header));
503 } 501 }
504 502
505 bool update_sample_rate_and_channels = false; 503 bool update_sample_rate_and_channels = false;
506 // Reinitialize NetEq if it's needed (changed SSRC or first call). 504 // Reinitialize NetEq if it's needed (changed SSRC or first call).
507 if ((main_header.ssrc != ssrc_) || first_packet_) { 505 if ((main_header.ssrc != ssrc_) || first_packet_) {
508 // Note: |first_packet_| will be cleared further down in this method, once 506 // Note: |first_packet_| will be cleared further down in this method, once
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 2067
2070 void NetEqImpl::CreateDecisionLogic() { 2068 void NetEqImpl::CreateDecisionLogic() {
2071 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, 2069 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_,
2072 playout_mode_, 2070 playout_mode_,
2073 decoder_database_.get(), 2071 decoder_database_.get(),
2074 *packet_buffer_.get(), 2072 *packet_buffer_.get(),
2075 delay_manager_.get(), 2073 delay_manager_.get(),
2076 buffer_level_filter_.get())); 2074 buffer_level_filter_.get()));
2077 } 2075 }
2078 } // namespace webrtc 2076 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698