| 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 15 matching lines...) Expand all Loading... |
| 26 #include "webrtc/modules/audio_coding/neteq/comfort_noise.h" | 26 #include "webrtc/modules/audio_coding/neteq/comfort_noise.h" |
| 27 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" | 27 #include "webrtc/modules/audio_coding/neteq/decision_logic.h" |
| 28 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" | 28 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
| 29 #include "webrtc/modules/audio_coding/neteq/defines.h" | 29 #include "webrtc/modules/audio_coding/neteq/defines.h" |
| 30 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" | 30 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" |
| 31 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" | 31 #include "webrtc/modules/audio_coding/neteq/delay_peak_detector.h" |
| 32 #include "webrtc/modules/audio_coding/neteq/dtmf_buffer.h" | 32 #include "webrtc/modules/audio_coding/neteq/dtmf_buffer.h" |
| 33 #include "webrtc/modules/audio_coding/neteq/dtmf_tone_generator.h" | 33 #include "webrtc/modules/audio_coding/neteq/dtmf_tone_generator.h" |
| 34 #include "webrtc/modules/audio_coding/neteq/expand.h" | 34 #include "webrtc/modules/audio_coding/neteq/expand.h" |
| 35 #include "webrtc/modules/audio_coding/neteq/merge.h" | 35 #include "webrtc/modules/audio_coding/neteq/merge.h" |
| 36 #include "webrtc/modules/audio_coding/neteq/nack.h" |
| 36 #include "webrtc/modules/audio_coding/neteq/normal.h" | 37 #include "webrtc/modules/audio_coding/neteq/normal.h" |
| 37 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" | 38 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" |
| 38 #include "webrtc/modules/audio_coding/neteq/packet.h" | 39 #include "webrtc/modules/audio_coding/neteq/packet.h" |
| 39 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" | 40 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" |
| 40 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" | 41 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" |
| 41 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" | 42 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" |
| 42 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 43 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
| 43 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" | 44 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" |
| 44 #include "webrtc/modules/interface/module_common_types.h" | 45 #include "webrtc/modules/interface/module_common_types.h" |
| 45 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 46 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 expand_factory_(expand_factory), | 80 expand_factory_(expand_factory), |
| 80 accelerate_factory_(accelerate_factory), | 81 accelerate_factory_(accelerate_factory), |
| 81 preemptive_expand_factory_(preemptive_expand_factory), | 82 preemptive_expand_factory_(preemptive_expand_factory), |
| 82 last_mode_(kModeNormal), | 83 last_mode_(kModeNormal), |
| 83 decoded_buffer_length_(kMaxFrameSize), | 84 decoded_buffer_length_(kMaxFrameSize), |
| 84 decoded_buffer_(new int16_t[decoded_buffer_length_]), | 85 decoded_buffer_(new int16_t[decoded_buffer_length_]), |
| 85 playout_timestamp_(0), | 86 playout_timestamp_(0), |
| 86 new_codec_(false), | 87 new_codec_(false), |
| 87 timestamp_(0), | 88 timestamp_(0), |
| 88 reset_decoder_(false), | 89 reset_decoder_(false), |
| 89 current_rtp_payload_type_(0xFF), // Invalid RTP payload type. | 90 current_rtp_payload_type_(0xFF), // Invalid RTP payload type. |
| 90 current_cng_rtp_payload_type_(0xFF), // Invalid RTP payload type. | 91 current_cng_rtp_payload_type_(0xFF), // Invalid RTP payload type. |
| 91 ssrc_(0), | 92 ssrc_(0), |
| 92 first_packet_(true), | 93 first_packet_(true), |
| 93 error_code_(0), | 94 error_code_(0), |
| 94 decoder_error_code_(0), | 95 decoder_error_code_(0), |
| 95 background_noise_mode_(config.background_noise_mode), | 96 background_noise_mode_(config.background_noise_mode), |
| 96 playout_mode_(config.playout_mode), | 97 playout_mode_(config.playout_mode), |
| 97 enable_fast_accelerate_(config.enable_fast_accelerate), | 98 enable_fast_accelerate_(config.enable_fast_accelerate), |
| 98 decoded_packet_sequence_number_(-1), | 99 nack_enabled_(false) { |
| 99 decoded_packet_timestamp_(0) { | |
| 100 LOG(LS_INFO) << "NetEq config: " << config.ToString(); | 100 LOG(LS_INFO) << "NetEq config: " << config.ToString(); |
| 101 int fs = config.sample_rate_hz; | 101 int fs = config.sample_rate_hz; |
| 102 if (fs != 8000 && fs != 16000 && fs != 32000 && fs != 48000) { | 102 if (fs != 8000 && fs != 16000 && fs != 32000 && fs != 48000) { |
| 103 LOG(LS_ERROR) << "Sample rate " << fs << " Hz not supported. " << | 103 LOG(LS_ERROR) << "Sample rate " << fs << " Hz not supported. " << |
| 104 "Changing to 8000 Hz."; | 104 "Changing to 8000 Hz."; |
| 105 fs = 8000; | 105 fs = 8000; |
| 106 } | 106 } |
| 107 fs_hz_ = fs; | 107 fs_hz_ = fs; |
| 108 fs_mult_ = fs / 8000; | 108 fs_mult_ = fs / 8000; |
| 109 output_size_samples_ = static_cast<size_t>(kOutputSizeMs * 8 * fs_mult_); | 109 output_size_samples_ = static_cast<size_t>(kOutputSizeMs * 8 * fs_mult_); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Set to wait for new codec. | 398 // Set to wait for new codec. |
| 399 first_packet_ = true; | 399 first_packet_ = true; |
| 400 } | 400 } |
| 401 | 401 |
| 402 void NetEqImpl::PacketBufferStatistics(int* current_num_packets, | 402 void NetEqImpl::PacketBufferStatistics(int* current_num_packets, |
| 403 int* max_num_packets) const { | 403 int* max_num_packets) const { |
| 404 CriticalSectionScoped lock(crit_sect_.get()); | 404 CriticalSectionScoped lock(crit_sect_.get()); |
| 405 packet_buffer_->BufferStat(current_num_packets, max_num_packets); | 405 packet_buffer_->BufferStat(current_num_packets, max_num_packets); |
| 406 } | 406 } |
| 407 | 407 |
| 408 int NetEqImpl::DecodedRtpInfo(int* sequence_number, uint32_t* timestamp) const { | 408 void NetEqImpl::EnableNack(size_t max_nack_list_size) { |
| 409 CriticalSectionScoped lock(crit_sect_.get()); | 409 CriticalSectionScoped lock(crit_sect_.get()); |
| 410 if (decoded_packet_sequence_number_ < 0) | 410 if (!nack_enabled_) { |
| 411 return -1; | 411 const int kNackThresholdPackets = 2; |
| 412 *sequence_number = decoded_packet_sequence_number_; | 412 nack_.reset(Nack::Create(kNackThresholdPackets)); |
| 413 *timestamp = decoded_packet_timestamp_; | 413 nack_enabled_ = true; |
| 414 return 0; | 414 nack_->UpdateSampleRate(fs_hz_); |
| 415 } |
| 416 nack_->SetMaxNackListSize(max_nack_list_size); |
| 417 } |
| 418 |
| 419 void NetEqImpl::DisableNack() { |
| 420 CriticalSectionScoped lock(crit_sect_.get()); |
| 421 nack_.reset(); |
| 422 nack_enabled_ = false; |
| 423 } |
| 424 |
| 425 std::vector<uint16_t> NetEqImpl::GetNackList(int64_t round_trip_time_ms) const { |
| 426 CriticalSectionScoped lock(crit_sect_.get()); |
| 427 if (!nack_enabled_) { |
| 428 return std::vector<uint16_t>(); |
| 429 } |
| 430 RTC_DCHECK(nack_.get()); |
| 431 return nack_->GetNackList(round_trip_time_ms); |
| 415 } | 432 } |
| 416 | 433 |
| 417 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const { | 434 const SyncBuffer* NetEqImpl::sync_buffer_for_test() const { |
| 418 CriticalSectionScoped lock(crit_sect_.get()); | 435 CriticalSectionScoped lock(crit_sect_.get()); |
| 419 return sync_buffer_.get(); | 436 return sync_buffer_.get(); |
| 420 } | 437 } |
| 421 | 438 |
| 422 // Methods below this line are private. | 439 // Methods below this line are private. |
| 423 | 440 |
| 424 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, | 441 int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 decoder_database_->GetDecoder(main_header.payloadType); | 621 decoder_database_->GetDecoder(main_header.payloadType); |
| 605 assert(decoder); // Should always get a valid object, since we have | 622 assert(decoder); // Should always get a valid object, since we have |
| 606 // already checked that the payload types are known. | 623 // already checked that the payload types are known. |
| 607 decoder->IncomingPacket(packet_list.front()->payload, | 624 decoder->IncomingPacket(packet_list.front()->payload, |
| 608 packet_list.front()->payload_length, | 625 packet_list.front()->payload_length, |
| 609 packet_list.front()->header.sequenceNumber, | 626 packet_list.front()->header.sequenceNumber, |
| 610 packet_list.front()->header.timestamp, | 627 packet_list.front()->header.timestamp, |
| 611 receive_timestamp); | 628 receive_timestamp); |
| 612 } | 629 } |
| 613 | 630 |
| 631 if (nack_enabled_) { |
| 632 RTC_DCHECK(nack_); |
| 633 if (update_sample_rate_and_channels) { |
| 634 nack_->Reset(); |
| 635 } |
| 636 nack_->UpdateLastReceivedPacket(packet_list.front()->header.sequenceNumber, |
| 637 packet_list.front()->header.timestamp); |
| 638 } |
| 639 |
| 614 // Insert packets in buffer. | 640 // Insert packets in buffer. |
| 615 const size_t buffer_length_before_insert = | 641 const size_t buffer_length_before_insert = |
| 616 packet_buffer_->NumPacketsInBuffer(); | 642 packet_buffer_->NumPacketsInBuffer(); |
| 617 ret = packet_buffer_->InsertPacketList( | 643 ret = packet_buffer_->InsertPacketList( |
| 618 &packet_list, | 644 &packet_list, |
| 619 *decoder_database_, | 645 *decoder_database_, |
| 620 ¤t_rtp_payload_type_, | 646 ¤t_rtp_payload_type_, |
| 621 ¤t_cng_rtp_payload_type_); | 647 ¤t_cng_rtp_payload_type_); |
| 622 if (ret == PacketBuffer::kFlushed) { | 648 if (ret == PacketBuffer::kFlushed) { |
| 623 // Reset DSP timestamp etc. if packet buffer flushed. | 649 // Reset DSP timestamp etc. if packet buffer flushed. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 651 // payload type of the hypothetically new send codec is not known. | 677 // payload type of the hypothetically new send codec is not known. |
| 652 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); | 678 const RTPHeader* rtp_header = packet_buffer_->NextRtpHeader(); |
| 653 assert(rtp_header); | 679 assert(rtp_header); |
| 654 int payload_type = rtp_header->payloadType; | 680 int payload_type = rtp_header->payloadType; |
| 655 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); | 681 AudioDecoder* decoder = decoder_database_->GetDecoder(payload_type); |
| 656 assert(decoder); // Payloads are already checked to be valid. | 682 assert(decoder); // Payloads are already checked to be valid. |
| 657 const DecoderDatabase::DecoderInfo* decoder_info = | 683 const DecoderDatabase::DecoderInfo* decoder_info = |
| 658 decoder_database_->GetDecoderInfo(payload_type); | 684 decoder_database_->GetDecoderInfo(payload_type); |
| 659 assert(decoder_info); | 685 assert(decoder_info); |
| 660 if (decoder_info->fs_hz != fs_hz_ || | 686 if (decoder_info->fs_hz != fs_hz_ || |
| 661 decoder->Channels() != algorithm_buffer_->Channels()) | 687 decoder->Channels() != algorithm_buffer_->Channels()) { |
| 662 SetSampleRateAndChannels(decoder_info->fs_hz, decoder->Channels()); | 688 SetSampleRateAndChannels(decoder_info->fs_hz, decoder->Channels()); |
| 689 } |
| 690 if (nack_enabled_) { |
| 691 RTC_DCHECK(nack_); |
| 692 // Update the sample rate even if the rate is not new, because of Reset(). |
| 693 nack_->UpdateSampleRate(fs_hz_); |
| 694 } |
| 663 } | 695 } |
| 664 | 696 |
| 665 // TODO(hlundin): Move this code to DelayManager class. | 697 // TODO(hlundin): Move this code to DelayManager class. |
| 666 const DecoderDatabase::DecoderInfo* dec_info = | 698 const DecoderDatabase::DecoderInfo* dec_info = |
| 667 decoder_database_->GetDecoderInfo(main_header.payloadType); | 699 decoder_database_->GetDecoderInfo(main_header.payloadType); |
| 668 assert(dec_info); // Already checked that the payload type is known. | 700 assert(dec_info); // Already checked that the payload type is known. |
| 669 delay_manager_->LastDecoderType(dec_info->codec_type); | 701 delay_manager_->LastDecoderType(dec_info->codec_type); |
| 670 if (delay_manager_->last_pack_cng_or_dtmf() == 0) { | 702 if (delay_manager_->last_pack_cng_or_dtmf() == 0) { |
| 671 // Calculate the total speech length carried in each packet. | 703 // Calculate the total speech length carried in each packet. |
| 672 const size_t buffer_length_after_insert = | 704 const size_t buffer_length_after_insert = |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 return -1; | 1888 return -1; |
| 1857 } | 1889 } |
| 1858 stats_.PacketsDiscarded(discard_count); | 1890 stats_.PacketsDiscarded(discard_count); |
| 1859 // Store waiting time in ms; packets->waiting_time is in "output blocks". | 1891 // Store waiting time in ms; packets->waiting_time is in "output blocks". |
| 1860 stats_.StoreWaitingTime(packet->waiting_time * kOutputSizeMs); | 1892 stats_.StoreWaitingTime(packet->waiting_time * kOutputSizeMs); |
| 1861 assert(packet->payload_length > 0); | 1893 assert(packet->payload_length > 0); |
| 1862 packet_list->push_back(packet); // Store packet in list. | 1894 packet_list->push_back(packet); // Store packet in list. |
| 1863 | 1895 |
| 1864 if (first_packet) { | 1896 if (first_packet) { |
| 1865 first_packet = false; | 1897 first_packet = false; |
| 1866 decoded_packet_sequence_number_ = prev_sequence_number = | 1898 if (nack_enabled_) { |
| 1867 packet->header.sequenceNumber; | 1899 RTC_DCHECK(nack_); |
| 1868 decoded_packet_timestamp_ = prev_timestamp = packet->header.timestamp; | 1900 // TODO(henrik.lundin): Should we update this for all decoded packets? |
| 1901 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, |
| 1902 packet->header.timestamp); |
| 1903 } |
| 1904 prev_sequence_number = packet->header.sequenceNumber; |
| 1905 prev_timestamp = packet->header.timestamp; |
| 1869 prev_payload_type = packet->header.payloadType; | 1906 prev_payload_type = packet->header.payloadType; |
| 1870 } | 1907 } |
| 1871 | 1908 |
| 1872 // Store number of extracted samples. | 1909 // Store number of extracted samples. |
| 1873 int packet_duration = 0; | 1910 int packet_duration = 0; |
| 1874 AudioDecoder* decoder = decoder_database_->GetDecoder( | 1911 AudioDecoder* decoder = decoder_database_->GetDecoder( |
| 1875 packet->header.payloadType); | 1912 packet->header.payloadType); |
| 1876 if (decoder) { | 1913 if (decoder) { |
| 1877 if (packet->sync_packet) { | 1914 if (packet->sync_packet) { |
| 1878 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); | 1915 packet_duration = rtc::checked_cast<int>(decoder_frame_length_); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 | 2063 |
| 2027 void NetEqImpl::CreateDecisionLogic() { | 2064 void NetEqImpl::CreateDecisionLogic() { |
| 2028 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, | 2065 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, |
| 2029 playout_mode_, | 2066 playout_mode_, |
| 2030 decoder_database_.get(), | 2067 decoder_database_.get(), |
| 2031 *packet_buffer_.get(), | 2068 *packet_buffer_.get(), |
| 2032 delay_manager_.get(), | 2069 delay_manager_.get(), |
| 2033 buffer_level_filter_.get())); | 2070 buffer_level_filter_.get())); |
| 2034 } | 2071 } |
| 2035 } // namespace webrtc | 2072 } // namespace webrtc |
| OLD | NEW |