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 646 matching lines...) Loading... | |
657 switch (ret) { | 657 switch (ret) { |
658 case PayloadSplitter::kUnknownPayloadType: | 658 case PayloadSplitter::kUnknownPayloadType: |
659 return kUnknownRtpPayloadType; | 659 return kUnknownRtpPayloadType; |
660 case PayloadSplitter::kFrameSplitError: | 660 case PayloadSplitter::kFrameSplitError: |
661 return kFrameSplitError; | 661 return kFrameSplitError; |
662 default: | 662 default: |
663 return kOtherError; | 663 return kOtherError; |
664 } | 664 } |
665 } | 665 } |
666 | 666 |
667 // Update bandwidth estimate, if the packet is not sync-packet. | 667 // Update bandwidth estimate, if the packet is not sync-packet. |
hlundin-webrtc
2016/04/11 11:33:00
Update the comment to mention that CNG packets are
ossu
2016/04/11 12:59:57
Acknowledged.
| |
668 if (!packet_list.empty() && !packet_list.front()->sync_packet) { | 668 if (!packet_list.empty() && !packet_list.front()->sync_packet) { |
669 // The list can be empty here if we got nothing but DTMF payloads. | 669 // The list can be empty here if we got nothing but DTMF payloads. |
670 AudioDecoder* decoder = | 670 if (!decoder_database_->IsComfortNoise(main_header.payloadType)) { |
671 decoder_database_->GetDecoder(main_header.payloadType); | 671 AudioDecoder* decoder = |
672 assert(decoder); // Should always get a valid object, since we have | 672 decoder_database_->GetDecoder(main_header.payloadType); |
673 // already checked that the payload types are known. | 673 assert(decoder); // Should always get a valid object, since we have |
674 decoder->IncomingPacket(packet_list.front()->payload, | 674 // already checked that the payload types are known. |
675 packet_list.front()->payload_length, | 675 decoder->IncomingPacket(packet_list.front()->payload, |
676 packet_list.front()->header.sequenceNumber, | 676 packet_list.front()->payload_length, |
677 packet_list.front()->header.timestamp, | 677 packet_list.front()->header.sequenceNumber, |
678 receive_timestamp); | 678 packet_list.front()->header.timestamp, |
679 receive_timestamp); | |
680 } | |
679 } | 681 } |
680 | 682 |
681 if (nack_enabled_) { | 683 if (nack_enabled_) { |
682 RTC_DCHECK(nack_); | 684 RTC_DCHECK(nack_); |
683 if (update_sample_rate_and_channels) { | 685 if (update_sample_rate_and_channels) { |
684 nack_->Reset(); | 686 nack_->Reset(); |
685 } | 687 } |
686 nack_->UpdateLastReceivedPacket(packet_list.front()->header.sequenceNumber, | 688 nack_->UpdateLastReceivedPacket(packet_list.front()->header.sequenceNumber, |
687 packet_list.front()->header.timestamp); | 689 packet_list.front()->header.timestamp); |
688 } | 690 } |
(...skipping 32 matching lines...) Loading... | |
721 if (update_sample_rate_and_channels && !packet_buffer_->Empty()) { | 723 if (update_sample_rate_and_channels && !packet_buffer_->Empty()) { |
722 // We do not use |current_rtp_payload_type_| to |set payload_type|, but | 724 // 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. | 725 // 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 | 726 // 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 | 727 // 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, | 728 // flushes its buffer, assuming send codec must have been changed. However, |
727 // payload type of the hypothetically new send codec is not known. | 729 // payload type of the hypothetically new send codec is not known. |
728 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); | 730 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); |
729 assert(rtp_header); | 731 assert(rtp_header); |
730 int payload_type = rtp_header->payloadType; | 732 int payload_type = rtp_header->payloadType; |
731 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); | 733 size_t channels = 1; |
732 assert(decoder); // Payloads are already checked to be valid. | 734 if (!decoder_database_->IsComfortNoise(payload_type)) { |
735 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); | |
736 assert(decoder); // Payloads are already checked to be valid. | |
737 channels = decoder->Channels(); | |
738 } | |
733 const DecoderDatabase::DecoderInfo* decoder_info = | 739 const DecoderDatabase::DecoderInfo* decoder_info = |
734 decoder_database_->GetDecoderInfo(payload_type); | 740 decoder_database_->GetDecoderInfo(payload_type); |
735 assert(decoder_info); | 741 assert(decoder_info); |
736 if (decoder_info->fs_hz != fs_hz_ || | 742 if (decoder_info->fs_hz != fs_hz_ || |
737 decoder->Channels() != algorithm_buffer_->Channels()) { | 743 channels != algorithm_buffer_->Channels()) { |
738 SetSampleRateAndChannels(decoder_info->fs_hz, decoder->Channels()); | 744 SetSampleRateAndChannels(decoder_info->fs_hz, channels); |
739 } | 745 } |
740 if (nack_enabled_) { | 746 if (nack_enabled_) { |
741 RTC_DCHECK(nack_); | 747 RTC_DCHECK(nack_); |
742 // Update the sample rate even if the rate is not new, because of Reset(). | 748 // Update the sample rate even if the rate is not new, because of Reset(). |
743 nack_->UpdateSampleRate(fs_hz_); | 749 nack_->UpdateSampleRate(fs_hz_); |
744 } | 750 } |
745 } | 751 } |
746 | 752 |
747 // TODO(hlundin): Move this code to DelayManager class. | 753 // TODO(hlundin): Move this code to DelayManager class. |
748 const DecoderDatabase::DecoderInfo* dec_info = | 754 const DecoderDatabase::DecoderInfo* dec_info = |
(...skipping 541 matching lines...) Loading... | |
1290 } | 1296 } |
1291 } | 1297 } |
1292 } | 1298 } |
1293 | 1299 |
1294 if (reset_decoder_) { | 1300 if (reset_decoder_) { |
1295 // TODO(hlundin): Write test for this. | 1301 // TODO(hlundin): Write test for this. |
1296 if (decoder) | 1302 if (decoder) |
1297 decoder->Reset(); | 1303 decoder->Reset(); |
1298 | 1304 |
1299 // Reset comfort noise decoder. | 1305 // Reset comfort noise decoder. |
1300 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 1306 CNG_dec_inst* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
1301 if (cng_decoder) | 1307 if (cng_decoder) |
1302 cng_decoder->Reset(); | 1308 WebRtcCng_InitDec(cng_decoder); |
1303 | 1309 |
1304 reset_decoder_ = false; | 1310 reset_decoder_ = false; |
1305 } | 1311 } |
1306 | 1312 |
1307 #ifdef LEGACY_BITEXACT | 1313 #ifdef LEGACY_BITEXACT |
1308 // Due to a bug in old SignalMCU, it could happen that CNG operation was | 1314 // 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 | 1315 // 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 | 1316 // to update the comfort noise decoder, as if it was a SID frame, which is |
1311 // clearly wrong. | 1317 // clearly wrong. |
1312 if (*operation == kRfc3389Cng) { | 1318 if (*operation == kRfc3389Cng) { |
(...skipping 635 matching lines...) Loading... | |
1948 } else { | 1954 } else { |
1949 if (packet->primary) { | 1955 if (packet->primary) { |
1950 packet_duration = decoder->PacketDuration(packet->payload, | 1956 packet_duration = decoder->PacketDuration(packet->payload, |
1951 packet->payload_length); | 1957 packet->payload_length); |
1952 } else { | 1958 } else { |
1953 packet_duration = decoder-> | 1959 packet_duration = decoder-> |
1954 PacketDurationRedundant(packet->payload, packet->payload_length); | 1960 PacketDurationRedundant(packet->payload, packet->payload_length); |
1955 stats_.SecondaryDecodedSamples(packet_duration); | 1961 stats_.SecondaryDecodedSamples(packet_duration); |
1956 } | 1962 } |
1957 } | 1963 } |
1958 } else { | 1964 } else if (!decoder_database_->IsComfortNoise(packet->header.payloadType)) { |
1959 LOG(LS_WARNING) << "Unknown payload type " | 1965 LOG(LS_WARNING) << "Unknown payload type " |
1960 << static_cast<int>(packet->header.payloadType); | 1966 << static_cast<int>(packet->header.payloadType); |
1961 assert(false); | 1967 assert(false); |
1962 } | 1968 } |
1963 if (packet_duration <= 0) { | 1969 if (packet_duration <= 0) { |
1964 // Decoder did not return a packet duration. Assume that the packet | 1970 // Decoder did not return a packet duration. Assume that the packet |
1965 // contains the same number of samples as the previous one. | 1971 // contains the same number of samples as the previous one. |
1966 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); | 1972 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); |
1967 } | 1973 } |
1968 extracted_samples = packet->header.timestamp - first_timestamp + | 1974 extracted_samples = packet->header.timestamp - first_timestamp + |
(...skipping 47 matching lines...) Loading... | |
2016 decoder_frame_length_ = 3 * output_size_samples_; // Initialize to 30ms. | 2022 decoder_frame_length_ = 3 * output_size_samples_; // Initialize to 30ms. |
2017 | 2023 |
2018 last_mode_ = kModeNormal; | 2024 last_mode_ = kModeNormal; |
2019 | 2025 |
2020 // Create a new array of mute factors and set all to 1. | 2026 // Create a new array of mute factors and set all to 1. |
2021 mute_factor_array_.reset(new int16_t[channels]); | 2027 mute_factor_array_.reset(new int16_t[channels]); |
2022 for (size_t i = 0; i < channels; ++i) { | 2028 for (size_t i = 0; i < channels; ++i) { |
2023 mute_factor_array_[i] = 16384; // 1.0 in Q14. | 2029 mute_factor_array_[i] = 16384; // 1.0 in Q14. |
2024 } | 2030 } |
2025 | 2031 |
2026 AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); | 2032 CNG_dec_inst* cng_decoder = decoder_database_->GetActiveCngDecoder(); |
2027 if (cng_decoder) | 2033 if (cng_decoder) |
2028 cng_decoder->Reset(); | 2034 WebRtcCng_InitDec(cng_decoder); |
2029 | 2035 |
2030 // Reinit post-decode VAD with new sample rate. | 2036 // Reinit post-decode VAD with new sample rate. |
2031 assert(vad_.get()); // Cannot be NULL here. | 2037 assert(vad_.get()); // Cannot be NULL here. |
2032 vad_->Init(); | 2038 vad_->Init(); |
2033 | 2039 |
2034 // Delete algorithm buffer and create a new one. | 2040 // Delete algorithm buffer and create a new one. |
2035 algorithm_buffer_.reset(new AudioMultiVector(channels)); | 2041 algorithm_buffer_.reset(new AudioMultiVector(channels)); |
2036 | 2042 |
2037 // Delete sync buffer and create a new one. | 2043 // Delete sync buffer and create a new one. |
2038 sync_buffer_.reset(new SyncBuffer(channels, kSyncBufferSize * fs_mult_)); | 2044 sync_buffer_.reset(new SyncBuffer(channels, kSyncBufferSize * fs_mult_)); |
(...skipping 56 matching lines...) Loading... | |
2095 | 2101 |
2096 void NetEqImpl::CreateDecisionLogic() { | 2102 void NetEqImpl::CreateDecisionLogic() { |
2097 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, | 2103 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, |
2098 playout_mode_, | 2104 playout_mode_, |
2099 decoder_database_.get(), | 2105 decoder_database_.get(), |
2100 *packet_buffer_.get(), | 2106 *packet_buffer_.get(), |
2101 delay_manager_.get(), | 2107 delay_manager_.get(), |
2102 buffer_level_filter_.get())); | 2108 buffer_level_filter_.get())); |
2103 } | 2109 } |
2104 } // namespace webrtc | 2110 } // namespace webrtc |
OLD | NEW |