OLD | NEW |
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 rtc::ArrayView<const uint8_t> payload, | 124 rtc::ArrayView<const uint8_t> payload, |
125 uint32_t receive_timestamp) { | 125 uint32_t receive_timestamp) { |
126 CriticalSectionScoped lock(crit_sect_.get()); | 126 CriticalSectionScoped lock(crit_sect_.get()); |
127 LOG(LS_VERBOSE) << "InsertPacket: ts=" << rtp_header.header.timestamp | |
128 << ", sn=" << rtp_header.header.sequenceNumber | |
129 << ", pt=" << static_cast<int>(rtp_header.header.payloadType) | |
130 << ", ssrc=" << rtp_header.header.ssrc | |
131 << ", len=" << payload.size(); | |
132 int error = | 127 int error = |
133 InsertPacketInternal(rtp_header, payload, receive_timestamp, false); | 128 InsertPacketInternal(rtp_header, payload, receive_timestamp, false); |
134 if (error != 0) { | 129 if (error != 0) { |
135 error_code_ = error; | 130 error_code_ = error; |
136 return kFail; | 131 return kFail; |
137 } | 132 } |
138 return kOK; | 133 return kOK; |
139 } | 134 } |
140 | 135 |
141 int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header, | 136 int NetEqImpl::InsertSyncPacket(const WebRtcRTPHeader& rtp_header, |
142 uint32_t receive_timestamp) { | 137 uint32_t receive_timestamp) { |
143 CriticalSectionScoped lock(crit_sect_.get()); | 138 CriticalSectionScoped lock(crit_sect_.get()); |
144 LOG(LS_VERBOSE) << "InsertPacket-Sync: ts=" | |
145 << rtp_header.header.timestamp << | |
146 ", sn=" << rtp_header.header.sequenceNumber << | |
147 ", pt=" << static_cast<int>(rtp_header.header.payloadType) << | |
148 ", ssrc=" << rtp_header.header.ssrc; | |
149 | |
150 const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' }; | 139 const uint8_t kSyncPayload[] = { 's', 'y', 'n', 'c' }; |
151 int error = | 140 int error = |
152 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true); | 141 InsertPacketInternal(rtp_header, kSyncPayload, receive_timestamp, true); |
153 | 142 |
154 if (error != 0) { | 143 if (error != 0) { |
155 error_code_ = error; | 144 error_code_ = error; |
156 return kFail; | 145 return kFail; |
157 } | 146 } |
158 return kOK; | 147 return kOK; |
159 } | 148 } |
160 | 149 |
161 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio, | 150 int NetEqImpl::GetAudio(size_t max_length, int16_t* output_audio, |
162 size_t* samples_per_channel, int* num_channels, | 151 size_t* samples_per_channel, int* num_channels, |
163 NetEqOutputType* type) { | 152 NetEqOutputType* type) { |
164 CriticalSectionScoped lock(crit_sect_.get()); | 153 CriticalSectionScoped lock(crit_sect_.get()); |
165 LOG(LS_VERBOSE) << "GetAudio"; | |
166 int error = GetAudioInternal(max_length, output_audio, samples_per_channel, | 154 int error = GetAudioInternal(max_length, output_audio, samples_per_channel, |
167 num_channels); | 155 num_channels); |
168 LOG(LS_VERBOSE) << "Produced " << *samples_per_channel << | |
169 " samples/channel for " << *num_channels << " channel(s)"; | |
170 if (error != 0) { | 156 if (error != 0) { |
171 error_code_ = error; | 157 error_code_ = error; |
172 return kFail; | 158 return kFail; |
173 } | 159 } |
174 if (type) { | 160 if (type) { |
175 *type = LastOutputType(); | 161 *type = LastOutputType(); |
176 } | 162 } |
177 return kOK; | 163 return kOK; |
178 } | 164 } |
179 | 165 |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 PacketList packet_list; | 730 PacketList packet_list; |
745 DtmfEvent dtmf_event; | 731 DtmfEvent dtmf_event; |
746 Operations operation; | 732 Operations operation; |
747 bool play_dtmf; | 733 bool play_dtmf; |
748 int return_value = GetDecision(&operation, &packet_list, &dtmf_event, | 734 int return_value = GetDecision(&operation, &packet_list, &dtmf_event, |
749 &play_dtmf); | 735 &play_dtmf); |
750 if (return_value != 0) { | 736 if (return_value != 0) { |
751 last_mode_ = kModeError; | 737 last_mode_ = kModeError; |
752 return return_value; | 738 return return_value; |
753 } | 739 } |
754 LOG(LS_VERBOSE) << "GetDecision returned operation=" << operation << | |
755 " and " << packet_list.size() << " packet(s)"; | |
756 | 740 |
757 AudioDecoder::SpeechType speech_type; | 741 AudioDecoder::SpeechType speech_type; |
758 int length = 0; | 742 int length = 0; |
759 int decode_return_value = Decode(&packet_list, &operation, | 743 int decode_return_value = Decode(&packet_list, &operation, |
760 &length, &speech_type); | 744 &length, &speech_type); |
761 | 745 |
762 assert(vad_.get()); | 746 assert(vad_.get()); |
763 bool sid_frame_available = | 747 bool sid_frame_available = |
764 (operation == kRfc3389Cng && !packet_list.empty()); | 748 (operation == kRfc3389Cng && !packet_list.empty()); |
765 vad_->Update(decoded_buffer_.get(), static_cast<size_t>(length), speech_type, | 749 vad_->Update(decoded_buffer_.get(), static_cast<size_t>(length), speech_type, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 if (num_output_samples > max_length) { | 844 if (num_output_samples > max_length) { |
861 LOG(LS_WARNING) << "Output array is too short. " << max_length << " < " << | 845 LOG(LS_WARNING) << "Output array is too short. " << max_length << " < " << |
862 output_size_samples_ << " * " << sync_buffer_->Channels(); | 846 output_size_samples_ << " * " << sync_buffer_->Channels(); |
863 num_output_samples = max_length; | 847 num_output_samples = max_length; |
864 num_output_samples_per_channel = max_length / sync_buffer_->Channels(); | 848 num_output_samples_per_channel = max_length / sync_buffer_->Channels(); |
865 } | 849 } |
866 const size_t samples_from_sync = | 850 const size_t samples_from_sync = |
867 sync_buffer_->GetNextAudioInterleaved(num_output_samples_per_channel, | 851 sync_buffer_->GetNextAudioInterleaved(num_output_samples_per_channel, |
868 output); | 852 output); |
869 *num_channels = static_cast<int>(sync_buffer_->Channels()); | 853 *num_channels = static_cast<int>(sync_buffer_->Channels()); |
870 LOG(LS_VERBOSE) << "Sync buffer (" << *num_channels << " channel(s)):" << | |
871 " insert " << algorithm_buffer_->Size() << " samples, extract " << | |
872 samples_from_sync << " samples"; | |
873 if (sync_buffer_->FutureLength() < expand_->overlap_length()) { | 854 if (sync_buffer_->FutureLength() < expand_->overlap_length()) { |
874 // The sync buffer should always contain |overlap_length| samples, but now | 855 // The sync buffer should always contain |overlap_length| samples, but now |
875 // too many samples have been extracted. Reinstall the |overlap_length| | 856 // too many samples have been extracted. Reinstall the |overlap_length| |
876 // lookahead by moving the index. | 857 // lookahead by moving the index. |
877 const size_t missing_lookahead_samples = | 858 const size_t missing_lookahead_samples = |
878 expand_->overlap_length() - sync_buffer_->FutureLength(); | 859 expand_->overlap_length() - sync_buffer_->FutureLength(); |
879 RTC_DCHECK_GE(sync_buffer_->next_index(), missing_lookahead_samples); | 860 RTC_DCHECK_GE(sync_buffer_->next_index(), missing_lookahead_samples); |
880 sync_buffer_->set_next_index(sync_buffer_->next_index() - | 861 sync_buffer_->set_next_index(sync_buffer_->next_index() - |
881 missing_lookahead_samples); | 862 missing_lookahead_samples); |
882 } | 863 } |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 return 0; | 1301 return 0; |
1321 } | 1302 } |
1322 | 1303 |
1323 while (*decoded_length < rtc::checked_cast<int>(output_size_samples_)) { | 1304 while (*decoded_length < rtc::checked_cast<int>(output_size_samples_)) { |
1324 const int length = decoder->Decode( | 1305 const int length = decoder->Decode( |
1325 nullptr, 0, fs_hz_, | 1306 nullptr, 0, fs_hz_, |
1326 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | 1307 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), |
1327 &decoded_buffer_[*decoded_length], speech_type); | 1308 &decoded_buffer_[*decoded_length], speech_type); |
1328 if (length > 0) { | 1309 if (length > 0) { |
1329 *decoded_length += length; | 1310 *decoded_length += length; |
1330 LOG(LS_VERBOSE) << "Decoded " << length << " CNG samples"; | |
1331 } else { | 1311 } else { |
1332 // Error. | 1312 // Error. |
1333 LOG(LS_WARNING) << "Failed to decode CNG"; | 1313 LOG(LS_WARNING) << "Failed to decode CNG"; |
1334 *decoded_length = -1; | 1314 *decoded_length = -1; |
1335 break; | 1315 break; |
1336 } | 1316 } |
1337 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) { | 1317 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) { |
1338 // Guard against overflow. | 1318 // Guard against overflow. |
1339 LOG(LS_WARNING) << "Decoded too much CNG."; | 1319 LOG(LS_WARNING) << "Decoded too much CNG."; |
1340 return kDecodedTooMuch; | 1320 return kDecodedTooMuch; |
(...skipping 19 matching lines...) Expand all Loading... |
1360 assert(sync_buffer_->Channels() == decoder->Channels()); | 1340 assert(sync_buffer_->Channels() == decoder->Channels()); |
1361 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); | 1341 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); |
1362 assert(operation == kNormal || operation == kAccelerate || | 1342 assert(operation == kNormal || operation == kAccelerate || |
1363 operation == kFastAccelerate || operation == kMerge || | 1343 operation == kFastAccelerate || operation == kMerge || |
1364 operation == kPreemptiveExpand); | 1344 operation == kPreemptiveExpand); |
1365 packet_list->pop_front(); | 1345 packet_list->pop_front(); |
1366 size_t payload_length = packet->payload_length; | 1346 size_t payload_length = packet->payload_length; |
1367 int decode_length; | 1347 int decode_length; |
1368 if (packet->sync_packet) { | 1348 if (packet->sync_packet) { |
1369 // Decode to silence with the same frame size as the last decode. | 1349 // Decode to silence with the same frame size as the last decode. |
1370 LOG(LS_VERBOSE) << "Decoding sync-packet: " << | |
1371 " ts=" << packet->header.timestamp << | |
1372 ", sn=" << packet->header.sequenceNumber << | |
1373 ", pt=" << static_cast<int>(packet->header.payloadType) << | |
1374 ", ssrc=" << packet->header.ssrc << | |
1375 ", len=" << packet->payload_length; | |
1376 memset(&decoded_buffer_[*decoded_length], 0, | 1350 memset(&decoded_buffer_[*decoded_length], 0, |
1377 decoder_frame_length_ * decoder->Channels() * | 1351 decoder_frame_length_ * decoder->Channels() * |
1378 sizeof(decoded_buffer_[0])); | 1352 sizeof(decoded_buffer_[0])); |
1379 decode_length = rtc::checked_cast<int>(decoder_frame_length_); | 1353 decode_length = rtc::checked_cast<int>(decoder_frame_length_); |
1380 } else if (!packet->primary) { | 1354 } else if (!packet->primary) { |
1381 // This is a redundant payload; call the special decoder method. | 1355 // This is a redundant payload; call the special decoder method. |
1382 LOG(LS_VERBOSE) << "Decoding packet (redundant):" << | |
1383 " ts=" << packet->header.timestamp << | |
1384 ", sn=" << packet->header.sequenceNumber << | |
1385 ", pt=" << static_cast<int>(packet->header.payloadType) << | |
1386 ", ssrc=" << packet->header.ssrc << | |
1387 ", len=" << packet->payload_length; | |
1388 decode_length = decoder->DecodeRedundant( | 1356 decode_length = decoder->DecodeRedundant( |
1389 packet->payload, packet->payload_length, fs_hz_, | 1357 packet->payload, packet->payload_length, fs_hz_, |
1390 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | 1358 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), |
1391 &decoded_buffer_[*decoded_length], speech_type); | 1359 &decoded_buffer_[*decoded_length], speech_type); |
1392 } else { | 1360 } else { |
1393 LOG(LS_VERBOSE) << "Decoding packet: ts=" << packet->header.timestamp << | |
1394 ", sn=" << packet->header.sequenceNumber << | |
1395 ", pt=" << static_cast<int>(packet->header.payloadType) << | |
1396 ", ssrc=" << packet->header.ssrc << | |
1397 ", len=" << packet->payload_length; | |
1398 decode_length = | 1361 decode_length = |
1399 decoder->Decode( | 1362 decoder->Decode( |
1400 packet->payload, packet->payload_length, fs_hz_, | 1363 packet->payload, packet->payload_length, fs_hz_, |
1401 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), | 1364 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t), |
1402 &decoded_buffer_[*decoded_length], speech_type); | 1365 &decoded_buffer_[*decoded_length], speech_type); |
1403 } | 1366 } |
1404 | 1367 |
1405 delete[] packet->payload; | 1368 delete[] packet->payload; |
1406 delete packet; | 1369 delete packet; |
1407 packet = NULL; | 1370 packet = NULL; |
1408 if (decode_length > 0) { | 1371 if (decode_length > 0) { |
1409 *decoded_length += decode_length; | 1372 *decoded_length += decode_length; |
1410 // Update |decoder_frame_length_| with number of samples per channel. | 1373 // Update |decoder_frame_length_| with number of samples per channel. |
1411 decoder_frame_length_ = | 1374 decoder_frame_length_ = |
1412 static_cast<size_t>(decode_length) / decoder->Channels(); | 1375 static_cast<size_t>(decode_length) / decoder->Channels(); |
1413 LOG(LS_VERBOSE) << "Decoded " << decode_length << " samples (" | |
1414 << decoder->Channels() << " channel(s) -> " | |
1415 << decoder_frame_length_ << " samples per channel)"; | |
1416 } else if (decode_length < 0) { | 1376 } else if (decode_length < 0) { |
1417 // Error. | 1377 // Error. |
1418 LOG(LS_WARNING) << "Decode " << decode_length << " " << payload_length; | 1378 LOG(LS_WARNING) << "Decode " << decode_length << " " << payload_length; |
1419 *decoded_length = -1; | 1379 *decoded_length = -1; |
1420 PacketBuffer::DeleteAllPackets(packet_list); | 1380 PacketBuffer::DeleteAllPackets(packet_list); |
1421 break; | 1381 break; |
1422 } | 1382 } |
1423 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) { | 1383 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) { |
1424 // Guard against overflow. | 1384 // Guard against overflow. |
1425 LOG(LS_WARNING) << "Decoded too much."; | 1385 LOG(LS_WARNING) << "Decoded too much."; |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2067 | 2027 |
2068 void NetEqImpl::CreateDecisionLogic() { | 2028 void NetEqImpl::CreateDecisionLogic() { |
2069 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, | 2029 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, |
2070 playout_mode_, | 2030 playout_mode_, |
2071 decoder_database_.get(), | 2031 decoder_database_.get(), |
2072 *packet_buffer_.get(), | 2032 *packet_buffer_.get(), |
2073 delay_manager_.get(), | 2033 delay_manager_.get(), |
2074 buffer_level_filter_.get())); | 2034 buffer_level_filter_.get())); |
2075 } | 2035 } |
2076 } // namespace webrtc | 2036 } // namespace webrtc |
OLD | NEW |