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

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

Issue 1334303005: Returning correct duration estimate on Opus DTX packets. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fixing a silly mistake in unittest Created 5 years, 2 months 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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 758 }
759 case kRfc3389Cng: 759 case kRfc3389Cng:
760 case kRfc3389CngNoPacket: { 760 case kRfc3389CngNoPacket: {
761 return_value = DoRfc3389Cng(&packet_list, play_dtmf); 761 return_value = DoRfc3389Cng(&packet_list, play_dtmf);
762 break; 762 break;
763 } 763 }
764 case kCodecInternalCng: { 764 case kCodecInternalCng: {
765 // This handles the case when there is no transmission and the decoder 765 // This handles the case when there is no transmission and the decoder
766 // should produce internal comfort noise. 766 // should produce internal comfort noise.
767 // TODO(hlundin): Write test for codec-internal CNG. 767 // TODO(hlundin): Write test for codec-internal CNG.
768 DoCodecInternalCng(); 768 DoCodecInternalCng(decoded_buffer_.get(), length);
769 break; 769 break;
770 } 770 }
771 case kDtmf: { 771 case kDtmf: {
772 // TODO(hlundin): Write test for this. 772 // TODO(hlundin): Write test for this.
773 return_value = DoDtmf(dtmf_event, &play_dtmf); 773 return_value = DoDtmf(dtmf_event, &play_dtmf);
774 break; 774 break;
775 } 775 }
776 case kAlternativePlc: { 776 case kAlternativePlc: {
777 // TODO(hlundin): Write test for this. 777 // TODO(hlundin): Write test for this.
778 DoAlternativePlc(false); 778 DoAlternativePlc(false);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 } 1156 }
1157 1157
1158 timestamp_ = end_timestamp; 1158 timestamp_ = end_timestamp;
1159 return 0; 1159 return 0;
1160 } 1160 }
1161 1161
1162 int NetEqImpl::Decode(PacketList* packet_list, Operations* operation, 1162 int NetEqImpl::Decode(PacketList* packet_list, Operations* operation,
1163 int* decoded_length, 1163 int* decoded_length,
1164 AudioDecoder::SpeechType* speech_type) { 1164 AudioDecoder::SpeechType* speech_type) {
1165 *speech_type = AudioDecoder::kSpeech; 1165 *speech_type = AudioDecoder::kSpeech;
1166 AudioDecoder* decoder = NULL; 1166
1167 // When packet_list is empty, we may be in kCodecInternalCng mode, and for
1168 // that we use current active decoder.
1169 AudioDecoder* decoder = decoder_database_->GetActiveDecoder();
1170
1167 if (!packet_list->empty()) { 1171 if (!packet_list->empty()) {
1168 const Packet* packet = packet_list->front(); 1172 const Packet* packet = packet_list->front();
1169 uint8_t payload_type = packet->header.payloadType; 1173 uint8_t payload_type = packet->header.payloadType;
1170 if (!decoder_database_->IsComfortNoise(payload_type)) { 1174 if (!decoder_database_->IsComfortNoise(payload_type)) {
1171 decoder = decoder_database_->GetDecoder(payload_type); 1175 decoder = decoder_database_->GetDecoder(payload_type);
1172 assert(decoder); 1176 assert(decoder);
1173 if (!decoder) { 1177 if (!decoder) {
1174 LOG(LS_WARNING) << "Unknown payload type " 1178 LOG(LS_WARNING) << "Unknown payload type "
1175 << static_cast<int>(payload_type); 1179 << static_cast<int>(payload_type);
1176 PacketBuffer::DeleteAllPackets(packet_list); 1180 PacketBuffer::DeleteAllPackets(packet_list);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 return 0; 1228 return 0;
1225 } 1229 }
1226 #endif 1230 #endif
1227 1231
1228 *decoded_length = 0; 1232 *decoded_length = 0;
1229 // Update codec-internal PLC state. 1233 // Update codec-internal PLC state.
1230 if ((*operation == kMerge) && decoder && decoder->HasDecodePlc()) { 1234 if ((*operation == kMerge) && decoder && decoder->HasDecodePlc()) {
1231 decoder->DecodePlc(1, &decoded_buffer_[*decoded_length]); 1235 decoder->DecodePlc(1, &decoded_buffer_[*decoded_length]);
1232 } 1236 }
1233 1237
1234 int return_value = DecodeLoop(packet_list, operation, decoder, 1238 int return_value;
1235 decoded_length, speech_type); 1239 if (*operation == kCodecInternalCng) {
1240 RTC_DCHECK(packet_list->empty());
1241 return_value = DecodeCng(decoder, decoded_length, speech_type);
1242 } else {
1243 return_value = DecodeLoop(packet_list, *operation, decoder,
1244 decoded_length, speech_type);
1245 }
1236 1246
1237 if (*decoded_length < 0) { 1247 if (*decoded_length < 0) {
1238 // Error returned from the decoder. 1248 // Error returned from the decoder.
1239 *decoded_length = 0; 1249 *decoded_length = 0;
1240 sync_buffer_->IncreaseEndTimestamp( 1250 sync_buffer_->IncreaseEndTimestamp(
1241 static_cast<uint32_t>(decoder_frame_length_)); 1251 static_cast<uint32_t>(decoder_frame_length_));
1242 int error_code = 0; 1252 int error_code = 0;
1243 if (decoder) 1253 if (decoder)
1244 error_code = decoder->ErrorCode(); 1254 error_code = decoder->ErrorCode();
1245 if (error_code != 0) { 1255 if (error_code != 0) {
(...skipping 13 matching lines...) Expand all
1259 // since in this case, the we will increment the CNGplayedTS counter. 1269 // since in this case, the we will increment the CNGplayedTS counter.
1260 // Increase with number of samples per channel. 1270 // Increase with number of samples per channel.
1261 assert(*decoded_length == 0 || 1271 assert(*decoded_length == 0 ||
1262 (decoder && decoder->Channels() == sync_buffer_->Channels())); 1272 (decoder && decoder->Channels() == sync_buffer_->Channels()));
1263 sync_buffer_->IncreaseEndTimestamp( 1273 sync_buffer_->IncreaseEndTimestamp(
1264 *decoded_length / static_cast<int>(sync_buffer_->Channels())); 1274 *decoded_length / static_cast<int>(sync_buffer_->Channels()));
1265 } 1275 }
1266 return return_value; 1276 return return_value;
1267 } 1277 }
1268 1278
1269 int NetEqImpl::DecodeLoop(PacketList* packet_list, Operations* operation, 1279 int NetEqImpl::DecodeCng(AudioDecoder* decoder, int* decoded_length,
1280 AudioDecoder::SpeechType* speech_type) {
1281 if (!decoder) {
1282 // This happens when active decoder is not defined.
1283 *decoded_length = -1;
1284 return 0;
1285 }
1286
1287 while (*decoded_length < rtc::checked_cast<int>(output_size_samples_)) {
1288 const int length = decoder->Decode(
1289 nullptr, 0, fs_hz_,
1290 (decoded_buffer_length_ - *decoded_length) * sizeof(int16_t),
1291 &decoded_buffer_[*decoded_length], speech_type);
1292 if (length > 0) {
1293 *decoded_length += length;
1294 LOG(LS_VERBOSE) << "Decoded " << length << " CNG samples";
1295 } else {
1296 // Error.
1297 LOG(LS_WARNING) << "Failed to decode CNG";
1298 *decoded_length = -1;
1299 break;
1300 }
1301 if (*decoded_length > static_cast<int>(decoded_buffer_length_)) {
1302 // Guard against overflow.
1303 LOG(LS_WARNING) << "Decoded too much CNG.";
1304 return kDecodedTooMuch;
1305 }
1306 }
1307 return 0;
1308 }
1309
1310 int NetEqImpl::DecodeLoop(PacketList* packet_list, const Operations& operation,
1270 AudioDecoder* decoder, int* decoded_length, 1311 AudioDecoder* decoder, int* decoded_length,
1271 AudioDecoder::SpeechType* speech_type) { 1312 AudioDecoder::SpeechType* speech_type) {
1272 Packet* packet = NULL; 1313 Packet* packet = NULL;
1273 if (!packet_list->empty()) { 1314 if (!packet_list->empty()) {
1274 packet = packet_list->front(); 1315 packet = packet_list->front();
1275 } 1316 }
1317
1276 // Do decoding. 1318 // Do decoding.
1277 while (packet && 1319 while (packet &&
1278 !decoder_database_->IsComfortNoise(packet->header.payloadType)) { 1320 !decoder_database_->IsComfortNoise(packet->header.payloadType)) {
1279 assert(decoder); // At this point, we must have a decoder object. 1321 assert(decoder); // At this point, we must have a decoder object.
1280 // The number of channels in the |sync_buffer_| should be the same as the 1322 // The number of channels in the |sync_buffer_| should be the same as the
1281 // number decoder channels. 1323 // number decoder channels.
1282 assert(sync_buffer_->Channels() == decoder->Channels()); 1324 assert(sync_buffer_->Channels() == decoder->Channels());
1283 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels()); 1325 assert(decoded_buffer_length_ >= kMaxFrameSize * decoder->Channels());
1284 assert(*operation == kNormal || *operation == kAccelerate || 1326 assert(operation == kNormal || operation == kAccelerate ||
1285 *operation == kFastAccelerate || *operation == kMerge || 1327 operation == kFastAccelerate || operation == kMerge ||
1286 *operation == kPreemptiveExpand); 1328 operation == kPreemptiveExpand);
1287 packet_list->pop_front(); 1329 packet_list->pop_front();
1288 size_t payload_length = packet->payload_length; 1330 size_t payload_length = packet->payload_length;
1289 int decode_length; 1331 int decode_length;
1290 if (packet->sync_packet) { 1332 if (packet->sync_packet) {
1291 // Decode to silence with the same frame size as the last decode. 1333 // Decode to silence with the same frame size as the last decode.
1292 LOG(LS_VERBOSE) << "Decoding sync-packet: " << 1334 LOG(LS_VERBOSE) << "Decoding sync-packet: " <<
1293 " ts=" << packet->header.timestamp << 1335 " ts=" << packet->header.timestamp <<
1294 ", sn=" << packet->header.sequenceNumber << 1336 ", sn=" << packet->header.sequenceNumber <<
1295 ", pt=" << static_cast<int>(packet->header.payloadType) << 1337 ", pt=" << static_cast<int>(packet->header.payloadType) <<
1296 ", ssrc=" << packet->header.ssrc << 1338 ", ssrc=" << packet->header.ssrc <<
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 } 1678 }
1637 if (cn_return == ComfortNoise::kInternalError) { 1679 if (cn_return == ComfortNoise::kInternalError) {
1638 decoder_error_code_ = comfort_noise_->internal_error_code(); 1680 decoder_error_code_ = comfort_noise_->internal_error_code();
1639 return kComfortNoiseErrorCode; 1681 return kComfortNoiseErrorCode;
1640 } else if (cn_return == ComfortNoise::kUnknownPayloadType) { 1682 } else if (cn_return == ComfortNoise::kUnknownPayloadType) {
1641 return kUnknownRtpPayloadType; 1683 return kUnknownRtpPayloadType;
1642 } 1684 }
1643 return 0; 1685 return 0;
1644 } 1686 }
1645 1687
1646 void NetEqImpl::DoCodecInternalCng() { 1688 void NetEqImpl::DoCodecInternalCng(const int16_t* decoded_buffer,
1647 int length = 0; 1689 size_t decoded_length) {
1648 // TODO(hlundin): Will probably need a longer buffer for multi-channel. 1690 RTC_DCHECK(normal_.get());
1649 int16_t decoded_buffer[kMaxFrameSize]; 1691 RTC_DCHECK(mute_factor_array_.get());
1650 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); 1692 normal_->Process(decoded_buffer, decoded_length, last_mode_,
1651 if (decoder) { 1693 mute_factor_array_.get(), algorithm_buffer_.get());
1652 const uint8_t* dummy_payload = NULL;
1653 AudioDecoder::SpeechType speech_type;
1654 length = decoder->Decode(
1655 dummy_payload, 0, fs_hz_, kMaxFrameSize * sizeof(int16_t),
1656 decoded_buffer, &speech_type);
1657 }
1658 assert(mute_factor_array_.get());
1659 normal_->Process(decoded_buffer, length, last_mode_, mute_factor_array_.get(),
1660 algorithm_buffer_.get());
1661 last_mode_ = kModeCodecInternalCng; 1694 last_mode_ = kModeCodecInternalCng;
1662 expand_->Reset(); 1695 expand_->Reset();
1663 } 1696 }
1664 1697
1665 int NetEqImpl::DoDtmf(const DtmfEvent& dtmf_event, bool* play_dtmf) { 1698 int NetEqImpl::DoDtmf(const DtmfEvent& dtmf_event, bool* play_dtmf) {
1666 // This block of the code and the block further down, handling |dtmf_switch| 1699 // This block of the code and the block further down, handling |dtmf_switch|
1667 // are commented out. Otherwise playing out-of-band DTMF would fail in VoE 1700 // are commented out. Otherwise playing out-of-band DTMF would fail in VoE
1668 // test, DtmfTest.ManualSuccessfullySendsOutOfBandTelephoneEvents. This is 1701 // test, DtmfTest.ManualSuccessfullySendsOutOfBandTelephoneEvents. This is
1669 // equivalent to |dtmf_switch| always be false. 1702 // equivalent to |dtmf_switch| always be false.
1670 // 1703 //
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1993 2026
1994 void NetEqImpl::CreateDecisionLogic() { 2027 void NetEqImpl::CreateDecisionLogic() {
1995 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, 2028 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_,
1996 playout_mode_, 2029 playout_mode_,
1997 decoder_database_.get(), 2030 decoder_database_.get(),
1998 *packet_buffer_.get(), 2031 *packet_buffer_.get(),
1999 delay_manager_.get(), 2032 delay_manager_.get(),
2000 buffer_level_filter_.get())); 2033 buffer_level_filter_.get()));
2001 } 2034 }
2002 } // namespace webrtc 2035 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.h ('k') | webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698