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 |
11 #include "webrtc/modules/audio_coding/neteq/neteq_impl.h" | 11 #include "webrtc/modules/audio_coding/neteq/neteq_impl.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <memory.h> // memset | 14 #include <memory.h> // memset |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <vector> | |
17 | 18 |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/safe_conversions.h" | 21 #include "webrtc/base/safe_conversions.h" |
21 #include "webrtc/base/trace_event.h" | 22 #include "webrtc/base/trace_event.h" |
22 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" | 23 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" |
23 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 24 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
24 #include "webrtc/modules/audio_coding/neteq/accelerate.h" | 25 #include "webrtc/modules/audio_coding/neteq/accelerate.h" |
25 #include "webrtc/modules/audio_coding/neteq/background_noise.h" | 26 #include "webrtc/modules/audio_coding/neteq/background_noise.h" |
26 #include "webrtc/modules/audio_coding/neteq/buffer_level_filter.h" | 27 #include "webrtc/modules/audio_coding/neteq/buffer_level_filter.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 switch (ret) { | 658 switch (ret) { |
658 case PayloadSplitter::kUnknownPayloadType: | 659 case PayloadSplitter::kUnknownPayloadType: |
659 return kUnknownRtpPayloadType; | 660 return kUnknownRtpPayloadType; |
660 case PayloadSplitter::kFrameSplitError: | 661 case PayloadSplitter::kFrameSplitError: |
661 return kFrameSplitError; | 662 return kFrameSplitError; |
662 default: | 663 default: |
663 return kOtherError; | 664 return kOtherError; |
664 } | 665 } |
665 } | 666 } |
666 | 667 |
667 // Update bandwidth estimate, if the packet is not sync-packet. | 668 // Update bandwidth estimate, if the packet is not sync-packet nor comfort |
669 // noise. | |
kwiberg-webrtc
2016/04/12 13:35:31
Is this additional requirement because CN's Incomi
ossu
2016/04/12 13:54:50
Well, it just returned -1 before, so the call was
| |
668 if (!packet_list.empty() && !packet_list.front()->sync_packet) { | 670 if (!packet_list.empty() && !packet_list.front()->sync_packet) { |
669 // The list can be empty here if we got nothing but DTMF payloads. | 671 // The list can be empty here if we got nothing but DTMF payloads. |
670 AudioDecoder* decoder = | 672 if (!decoder_database_->IsComfortNoise(main_header.payloadType)) { |
kwiberg-webrtc
2016/04/12 13:35:31
Merge these two ifs?
ossu
2016/04/12 13:54:50
Acknowledged.
| |
671 decoder_database_->GetDecoder(main_header.payloadType); | 673 AudioDecoder* decoder = |
672 assert(decoder); // Should always get a valid object, since we have | 674 decoder_database_->GetDecoder(main_header.payloadType); |
673 // already checked that the payload types are known. | 675 assert(decoder); // Should always get a valid object, since we have |
674 decoder->IncomingPacket(packet_list.front()->payload, | 676 // already checked that the payload types are known. |
675 packet_list.front()->payload_length, | 677 decoder->IncomingPacket(packet_list.front()->payload, |
676 packet_list.front()->header.sequenceNumber, | 678 packet_list.front()->payload_length, |
677 packet_list.front()->header.timestamp, | 679 packet_list.front()->header.sequenceNumber, |
678 receive_timestamp); | 680 packet_list.front()->header.timestamp, |
681 receive_timestamp); | |
682 } | |
679 } | 683 } |
680 | 684 |
681 if (nack_enabled_) { | 685 if (nack_enabled_) { |
682 RTC_DCHECK(nack_); | 686 RTC_DCHECK(nack_); |
683 if (update_sample_rate_and_channels) { | 687 if (update_sample_rate_and_channels) { |
684 nack_->Reset(); | 688 nack_->Reset(); |
685 } | 689 } |
686 nack_->UpdateLastReceivedPacket(packet_list.front()->header.sequenceNumber, | 690 nack_->UpdateLastReceivedPacket(packet_list.front()->header.sequenceNumber, |
687 packet_list.front()->header.timestamp); | 691 packet_list.front()->header.timestamp); |
688 } | 692 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 if (update_sample_rate_and_channels && !packet_buffer_->Empty()) { | 725 if (update_sample_rate_and_channels && !packet_buffer_->Empty()) { |
722 // We do not use |current_rtp_payload_type_| to |set payload_type|, but | 726 // We do not use |current_rtp_payload_type_| to |set payload_type|, but |
723 // get the next RTP header from |packet_buffer_| to obtain the payload type. | 727 // get the next RTP header from |packet_buffer_| to obtain the payload type. |
724 // The reason for it is the following corner case. If NetEq receives a | 728 // The reason for it is the following corner case. If NetEq receives a |
725 // CNG packet with a sample rate different than the current CNG then it | 729 // CNG packet with a sample rate different than the current CNG then it |
726 // flushes its buffer, assuming send codec must have been changed. However, | 730 // flushes its buffer, assuming send codec must have been changed. However, |
727 // payload type of the hypothetically new send codec is not known. | 731 // payload type of the hypothetically new send codec is not known. |
728 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); | 732 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); |
729 assert(rtp_header); | 733 assert(rtp_header); |
730 int payload_type = rtp_header->payloadType; | 734 int payload_type = rtp_header->payloadType; |
731 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); | 735 size_t channels = 1; |
732 assert(decoder); // Payloads are already checked to be valid. | 736 if (!decoder_database_->IsComfortNoise(payload_type)) { |
737 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); | |
738 assert(decoder); // Payloads are already checked to be valid. | |
739 channels = decoder->Channels(); | |
740 } | |
733 const DecoderDatabase::DecoderInfo* decoder_info = | 741 const DecoderDatabase::DecoderInfo* decoder_info = |
734 decoder_database_->GetDecoderInfo(payload_type); | 742 decoder_database_->GetDecoderInfo(payload_type); |
735 assert(decoder_info); | 743 assert(decoder_info); |
736 if (decoder_info->fs_hz != fs_hz_ || | 744 if (decoder_info->fs_hz != fs_hz_ || |
737 decoder->Channels() != algorithm_buffer_->Channels()) { | 745 channels != algorithm_buffer_->Channels()) { |
738 SetSampleRateAndChannels(decoder_info->fs_hz, decoder->Channels()); | 746 SetSampleRateAndChannels(decoder_info->fs_hz, channels); |
739 } | 747 } |
740 if (nack_enabled_) { | 748 if (nack_enabled_) { |
741 RTC_DCHECK(nack_); | 749 RTC_DCHECK(nack_); |
742 // Update the sample rate even if the rate is not new, because of Reset(). | 750 // Update the sample rate even if the rate is not new, because of Reset(). |
743 nack_->UpdateSampleRate(fs_hz_); | 751 nack_->UpdateSampleRate(fs_hz_); |
744 } | 752 } |
745 } | 753 } |
746 | 754 |
747 // TODO(hlundin): Move this code to DelayManager class. | 755 // TODO(hlundin): Move this code to DelayManager class. |
748 const DecoderDatabase::DecoderInfo* dec_info = | 756 const DecoderDatabase::DecoderInfo* dec_info = |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 } | 1298 } |
1291 } | 1299 } |
1292 } | 1300 } |
1293 | 1301 |
1294 if (reset_decoder_) { | 1302 if (reset_decoder_) { |
1295 // TODO(hlundin): Write test for this. | 1303 // TODO(hlundin): Write test for this. |
1296 if (decoder) | 1304 if (decoder) |
1297 decoder->Reset(); | 1305 decoder->Reset(); |
1298 | 1306 |
1299 // Reset comfort noise decoder. | 1307 // Reset comfort noise decoder. |
1300 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 1308 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
1301 if (cng_decoder) | 1309 if (cng_decoder) |
1302 cng_decoder->Reset(); | 1310 cng_decoder->Reset(); |
1303 | 1311 |
1304 reset_decoder_ = false; | 1312 reset_decoder_ = false; |
1305 } | 1313 } |
1306 | 1314 |
1307 #ifdef LEGACY_BITEXACT | 1315 #ifdef LEGACY_BITEXACT |
1308 // Due to a bug in old SignalMCU, it could happen that CNG operation was | 1316 // Due to a bug in old SignalMCU, it could happen that CNG operation was |
1309 // decided, but a speech packet was provided. The speech packet will be used | 1317 // decided, but a speech packet was provided. The speech packet will be used |
1310 // to update the comfort noise decoder, as if it was a SID frame, which is | 1318 // to update the comfort noise decoder, as if it was a SID frame, which is |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1948 } else { | 1956 } else { |
1949 if (packet->primary) { | 1957 if (packet->primary) { |
1950 packet_duration = decoder->PacketDuration(packet->payload, | 1958 packet_duration = decoder->PacketDuration(packet->payload, |
1951 packet->payload_length); | 1959 packet->payload_length); |
1952 } else { | 1960 } else { |
1953 packet_duration = decoder-> | 1961 packet_duration = decoder-> |
1954 PacketDurationRedundant(packet->payload, packet->payload_length); | 1962 PacketDurationRedundant(packet->payload, packet->payload_length); |
1955 stats_.SecondaryDecodedSamples(packet_duration); | 1963 stats_.SecondaryDecodedSamples(packet_duration); |
1956 } | 1964 } |
1957 } | 1965 } |
1958 } else { | 1966 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
1959 LOG(LS_WARNING) << "Unknown payload type " | 1967 LOG(LS_WARNING) << "Unknown payload type " |
1960 << static_cast<int>(packet->header.payloadType); | 1968 << static_cast<int>(packet->header.payloadType); |
1961 assert(false); | 1969 assert(false); |
1962 } | 1970 } |
1963 if (packet_duration <= 0) { | 1971 if (packet_duration <= 0) { |
1964 // Decoder did not return a packet duration. Assume that the packet | 1972 // Decoder did not return a packet duration. Assume that the packet |
1965 // contains the same number of samples as the previous one. | 1973 // contains the same number of samples as the previous one. |
1966 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); | 1974 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); |
1967 } | 1975 } |
1968 extracted_samples = packet->header.timestamp - first_timestamp + | 1976 extracted_samples = packet->header.timestamp - first_timestamp + |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2016 decoder_frame_length_ = 3 * output_size_samples_; // Initialize to 30ms. | 2024 decoder_frame_length_ = 3 * output_size_samples_; // Initialize to 30ms. |
2017 | 2025 |
2018 last_mode_ = kModeNormal; | 2026 last_mode_ = kModeNormal; |
2019 | 2027 |
2020 // Create a new array of mute factors and set all to 1. | 2028 // Create a new array of mute factors and set all to 1. |
2021 mute_factor_array_.reset(new int16_t[channels]); | 2029 mute_factor_array_.reset(new int16_t[channels]); |
2022 for (size_t i = 0; i < channels; ++i) { | 2030 for (size_t i = 0; i < channels; ++i) { |
2023 mute_factor_array_[i] = 16384; // 1.0 in Q14. | 2031 mute_factor_array_[i] = 16384; // 1.0 in Q14. |
2024 } | 2032 } |
2025 | 2033 |
2026 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 2034 ComfortNoiseDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
2027 if (cng_decoder) | 2035 if (cng_decoder) |
2028 cng_decoder->Reset(); | 2036 cng_decoder->Reset(); |
2029 | 2037 |
2030 // Reinit post-decode VAD with new sample rate. | 2038 // Reinit post-decode VAD with new sample rate. |
2031 assert(vad_.get()); // Cannot be NULL here. | 2039 assert(vad_.get()); // Cannot be NULL here. |
2032 vad_->Init(); | 2040 vad_->Init(); |
2033 | 2041 |
2034 // Delete algorithm buffer and create a new one. | 2042 // Delete algorithm buffer and create a new one. |
2035 algorithm_buffer_.reset(new AudioMultiVector(channels)); | 2043 algorithm_buffer_.reset(new AudioMultiVector(channels)); |
2036 | 2044 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2095 | 2103 |
2096 void NetEqImpl::CreateDecisionLogic() { | 2104 void NetEqImpl::CreateDecisionLogic() { |
2097 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, | 2105 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, |
2098 playout_mode_, | 2106 playout_mode_, |
2099 decoder_database_.get(), | 2107 decoder_database_.get(), |
2100 *packet_buffer_.get(), | 2108 *packet_buffer_.get(), |
2101 delay_manager_.get(), | 2109 delay_manager_.get(), |
2102 buffer_level_filter_.get())); | 2110 buffer_level_filter_.get())); |
2103 } | 2111 } |
2104 } // namespace webrtc | 2112 } // namespace webrtc |
OLD | NEW |