| 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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 DoAlternativePlc(false); | 781 DoAlternativePlc(false); |
| 782 break; | 782 break; |
| 783 } | 783 } |
| 784 case kAlternativePlcIncreaseTimestamp: { | 784 case kAlternativePlcIncreaseTimestamp: { |
| 785 // TODO(hlundin): Write test for this. | 785 // TODO(hlundin): Write test for this. |
| 786 DoAlternativePlc(true); | 786 DoAlternativePlc(true); |
| 787 break; | 787 break; |
| 788 } | 788 } |
| 789 case kAudioRepetitionIncreaseTimestamp: { | 789 case kAudioRepetitionIncreaseTimestamp: { |
| 790 // TODO(hlundin): Write test for this. | 790 // TODO(hlundin): Write test for this. |
| 791 sync_buffer_->IncreaseEndTimestamp(output_size_samples_); | 791 sync_buffer_->IncreaseEndTimestamp( |
| 792 static_cast<uint32_t>(output_size_samples_)); |
| 792 // Skipping break on purpose. Execution should move on into the | 793 // Skipping break on purpose. Execution should move on into the |
| 793 // next case. | 794 // next case. |
| 794 FALLTHROUGH(); | 795 FALLTHROUGH(); |
| 795 } | 796 } |
| 796 case kAudioRepetition: { | 797 case kAudioRepetition: { |
| 797 // TODO(hlundin): Write test for this. | 798 // TODO(hlundin): Write test for this. |
| 798 // Copy last |output_size_samples_| from |sync_buffer_| to | 799 // Copy last |output_size_samples_| from |sync_buffer_| to |
| 799 // |algorithm_buffer|. | 800 // |algorithm_buffer|. |
| 800 algorithm_buffer_->PushBackFromIndex( | 801 algorithm_buffer_->PushBackFromIndex( |
| 801 *sync_buffer_, sync_buffer_->Size() - output_size_samples_); | 802 *sync_buffer_, sync_buffer_->Size() - output_size_samples_); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 // If last operation was not expand, calculate the |playout_timestamp_| from | 875 // If last operation was not expand, calculate the |playout_timestamp_| from |
| 875 // the |sync_buffer_|. However, do not update the |playout_timestamp_| if it | 876 // the |sync_buffer_|. However, do not update the |playout_timestamp_| if it |
| 876 // would be moved "backwards". | 877 // would be moved "backwards". |
| 877 uint32_t temp_timestamp = sync_buffer_->end_timestamp() - | 878 uint32_t temp_timestamp = sync_buffer_->end_timestamp() - |
| 878 static_cast<uint32_t>(sync_buffer_->FutureLength()); | 879 static_cast<uint32_t>(sync_buffer_->FutureLength()); |
| 879 if (static_cast<int32_t>(temp_timestamp - playout_timestamp_) > 0) { | 880 if (static_cast<int32_t>(temp_timestamp - playout_timestamp_) > 0) { |
| 880 playout_timestamp_ = temp_timestamp; | 881 playout_timestamp_ = temp_timestamp; |
| 881 } | 882 } |
| 882 } else { | 883 } else { |
| 883 // Use dead reckoning to estimate the |playout_timestamp_|. | 884 // Use dead reckoning to estimate the |playout_timestamp_|. |
| 884 playout_timestamp_ += output_size_samples_; | 885 playout_timestamp_ += static_cast<uint32_t>(output_size_samples_); |
| 885 } | 886 } |
| 886 | 887 |
| 887 if (decode_return_value) return decode_return_value; | 888 if (decode_return_value) return decode_return_value; |
| 888 return return_value; | 889 return return_value; |
| 889 } | 890 } |
| 890 | 891 |
| 891 int NetEqImpl::GetDecision(Operations* operation, | 892 int NetEqImpl::GetDecision(Operations* operation, |
| 892 PacketList* packet_list, | 893 PacketList* packet_list, |
| 893 DtmfEvent* dtmf_event, | 894 DtmfEvent* dtmf_event, |
| 894 bool* play_dtmf) { | 895 bool* play_dtmf) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 expand_->overlap_length()); | 934 expand_->overlap_length()); |
| 934 if (last_mode_ == kModeAccelerateSuccess || | 935 if (last_mode_ == kModeAccelerateSuccess || |
| 935 last_mode_ == kModeAccelerateLowEnergy || | 936 last_mode_ == kModeAccelerateLowEnergy || |
| 936 last_mode_ == kModePreemptiveExpandSuccess || | 937 last_mode_ == kModePreemptiveExpandSuccess || |
| 937 last_mode_ == kModePreemptiveExpandLowEnergy) { | 938 last_mode_ == kModePreemptiveExpandLowEnergy) { |
| 938 // Subtract (samples_left + output_size_samples_) from sampleMemory. | 939 // Subtract (samples_left + output_size_samples_) from sampleMemory. |
| 939 decision_logic_->AddSampleMemory(-(samples_left + output_size_samples_)); | 940 decision_logic_->AddSampleMemory(-(samples_left + output_size_samples_)); |
| 940 } | 941 } |
| 941 | 942 |
| 942 // Check if it is time to play a DTMF event. | 943 // Check if it is time to play a DTMF event. |
| 943 if (dtmf_buffer_->GetEvent(end_timestamp + | 944 if (dtmf_buffer_->GetEvent( |
| 944 decision_logic_->generated_noise_samples(), | 945 static_cast<uint32_t>( |
| 945 dtmf_event)) { | 946 end_timestamp + decision_logic_->generated_noise_samples()), |
| 947 dtmf_event)) { |
| 946 *play_dtmf = true; | 948 *play_dtmf = true; |
| 947 } | 949 } |
| 948 | 950 |
| 949 // Get instruction. | 951 // Get instruction. |
| 950 assert(sync_buffer_.get()); | 952 assert(sync_buffer_.get()); |
| 951 assert(expand_.get()); | 953 assert(expand_.get()); |
| 952 *operation = decision_logic_->GetDecision(*sync_buffer_, | 954 *operation = decision_logic_->GetDecision(*sync_buffer_, |
| 953 *expand_, | 955 *expand_, |
| 954 decoder_frame_length_, | 956 decoder_frame_length_, |
| 955 header, | 957 header, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 case kCodecInternalCng: { | 1025 case kCodecInternalCng: { |
| 1024 return 0; | 1026 return 0; |
| 1025 } | 1027 } |
| 1026 case kDtmf: { | 1028 case kDtmf: { |
| 1027 // TODO(hlundin): Write test for this. | 1029 // TODO(hlundin): Write test for this. |
| 1028 // Update timestamp. | 1030 // Update timestamp. |
| 1029 timestamp_ = end_timestamp; | 1031 timestamp_ = end_timestamp; |
| 1030 if (decision_logic_->generated_noise_samples() > 0 && | 1032 if (decision_logic_->generated_noise_samples() > 0 && |
| 1031 last_mode_ != kModeDtmf) { | 1033 last_mode_ != kModeDtmf) { |
| 1032 // Make a jump in timestamp due to the recently played comfort noise. | 1034 // Make a jump in timestamp due to the recently played comfort noise. |
| 1033 uint32_t timestamp_jump = decision_logic_->generated_noise_samples(); | 1035 uint32_t timestamp_jump = |
| 1036 static_cast<uint32_t>(decision_logic_->generated_noise_samples()); |
| 1034 sync_buffer_->IncreaseEndTimestamp(timestamp_jump); | 1037 sync_buffer_->IncreaseEndTimestamp(timestamp_jump); |
| 1035 timestamp_ += timestamp_jump; | 1038 timestamp_ += timestamp_jump; |
| 1036 } | 1039 } |
| 1037 decision_logic_->set_generated_noise_samples(0); | 1040 decision_logic_->set_generated_noise_samples(0); |
| 1038 return 0; | 1041 return 0; |
| 1039 } | 1042 } |
| 1040 case kAccelerate: | 1043 case kAccelerate: |
| 1041 case kFastAccelerate: { | 1044 case kFastAccelerate: { |
| 1042 // In order to do an accelerate we need at least 30 ms of audio data. | 1045 // In order to do an accelerate we need at least 30 ms of audio data. |
| 1043 if (samples_left >= samples_30_ms) { | 1046 if (samples_left >= samples_30_ms) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 if ((*operation == kMerge) && decoder && decoder->HasDecodePlc()) { | 1220 if ((*operation == kMerge) && decoder && decoder->HasDecodePlc()) { |
| 1218 decoder->DecodePlc(1, &decoded_buffer_[*decoded_length]); | 1221 decoder->DecodePlc(1, &decoded_buffer_[*decoded_length]); |
| 1219 } | 1222 } |
| 1220 | 1223 |
| 1221 int return_value = DecodeLoop(packet_list, operation, decoder, | 1224 int return_value = DecodeLoop(packet_list, operation, decoder, |
| 1222 decoded_length, speech_type); | 1225 decoded_length, speech_type); |
| 1223 | 1226 |
| 1224 if (*decoded_length < 0) { | 1227 if (*decoded_length < 0) { |
| 1225 // Error returned from the decoder. | 1228 // Error returned from the decoder. |
| 1226 *decoded_length = 0; | 1229 *decoded_length = 0; |
| 1227 sync_buffer_->IncreaseEndTimestamp(decoder_frame_length_); | 1230 sync_buffer_->IncreaseEndTimestamp( |
| 1231 static_cast<uint32_t>(decoder_frame_length_)); |
| 1228 int error_code = 0; | 1232 int error_code = 0; |
| 1229 if (decoder) | 1233 if (decoder) |
| 1230 error_code = decoder->ErrorCode(); | 1234 error_code = decoder->ErrorCode(); |
| 1231 if (error_code != 0) { | 1235 if (error_code != 0) { |
| 1232 // Got some error code from the decoder. | 1236 // Got some error code from the decoder. |
| 1233 decoder_error_code_ = error_code; | 1237 decoder_error_code_ = error_code; |
| 1234 return_value = kDecoderErrorCode; | 1238 return_value = kDecoderErrorCode; |
| 1235 } else { | 1239 } else { |
| 1236 // Decoder does not implement error codes. Return generic error. | 1240 // Decoder does not implement error codes. Return generic error. |
| 1237 return_value = kOtherDecoderError; | 1241 return_value = kOtherDecoderError; |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 // // Not adapted for multi-channel yet. | 1716 // // Not adapted for multi-channel yet. |
| 1713 // assert(algorithm_buffer_->Channels() == 1); | 1717 // assert(algorithm_buffer_->Channels() == 1); |
| 1714 // if (algorithm_buffer_->Channels() != 1) { | 1718 // if (algorithm_buffer_->Channels() != 1) { |
| 1715 // LOG(LS_WARNING) << "DTMF not supported for more than one channel"; | 1719 // LOG(LS_WARNING) << "DTMF not supported for more than one channel"; |
| 1716 // return kStereoNotSupported; | 1720 // return kStereoNotSupported; |
| 1717 // } | 1721 // } |
| 1718 // // Shuffle the remaining data to the beginning of algorithm buffer. | 1722 // // Shuffle the remaining data to the beginning of algorithm buffer. |
| 1719 // algorithm_buffer_->PopFront(sync_buffer_->FutureLength()); | 1723 // algorithm_buffer_->PopFront(sync_buffer_->FutureLength()); |
| 1720 // } | 1724 // } |
| 1721 | 1725 |
| 1722 sync_buffer_->IncreaseEndTimestamp(output_size_samples_); | 1726 sync_buffer_->IncreaseEndTimestamp( |
| 1727 static_cast<uint32_t>(output_size_samples_)); |
| 1723 expand_->Reset(); | 1728 expand_->Reset(); |
| 1724 last_mode_ = kModeDtmf; | 1729 last_mode_ = kModeDtmf; |
| 1725 | 1730 |
| 1726 // Set to false because the DTMF is already in the algorithm buffer. | 1731 // Set to false because the DTMF is already in the algorithm buffer. |
| 1727 *play_dtmf = false; | 1732 *play_dtmf = false; |
| 1728 return 0; | 1733 return 0; |
| 1729 } | 1734 } |
| 1730 | 1735 |
| 1731 void NetEqImpl::DoAlternativePlc(bool increase_timestamp) { | 1736 void NetEqImpl::DoAlternativePlc(bool increase_timestamp) { |
| 1732 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); | 1737 AudioDecoder* decoder = decoder_database_->GetActiveDecoder(); |
| 1733 int length; | 1738 int length; |
| 1734 if (decoder && decoder->HasDecodePlc()) { | 1739 if (decoder && decoder->HasDecodePlc()) { |
| 1735 // Use the decoder's packet-loss concealment. | 1740 // Use the decoder's packet-loss concealment. |
| 1736 // TODO(hlundin): Will probably need a longer buffer for multi-channel. | 1741 // TODO(hlundin): Will probably need a longer buffer for multi-channel. |
| 1737 int16_t decoded_buffer[kMaxFrameSize]; | 1742 int16_t decoded_buffer[kMaxFrameSize]; |
| 1738 length = decoder->DecodePlc(1, decoded_buffer); | 1743 length = decoder->DecodePlc(1, decoded_buffer); |
| 1739 if (length > 0) { | 1744 if (length > 0) { |
| 1740 algorithm_buffer_->PushBackInterleaved(decoded_buffer, length); | 1745 algorithm_buffer_->PushBackInterleaved(decoded_buffer, length); |
| 1741 } else { | 1746 } else { |
| 1742 length = 0; | 1747 length = 0; |
| 1743 } | 1748 } |
| 1744 } else { | 1749 } else { |
| 1745 // Do simple zero-stuffing. | 1750 // Do simple zero-stuffing. |
| 1746 length = output_size_samples_; | 1751 length = output_size_samples_; |
| 1747 algorithm_buffer_->Zeros(length); | 1752 algorithm_buffer_->Zeros(length); |
| 1748 // By not advancing the timestamp, NetEq inserts samples. | 1753 // By not advancing the timestamp, NetEq inserts samples. |
| 1749 stats_.AddZeros(length); | 1754 stats_.AddZeros(length); |
| 1750 } | 1755 } |
| 1751 if (increase_timestamp) { | 1756 if (increase_timestamp) { |
| 1752 sync_buffer_->IncreaseEndTimestamp(length); | 1757 sync_buffer_->IncreaseEndTimestamp(static_cast<uint32_t>(length)); |
| 1753 } | 1758 } |
| 1754 expand_->Reset(); | 1759 expand_->Reset(); |
| 1755 } | 1760 } |
| 1756 | 1761 |
| 1757 int NetEqImpl::DtmfOverdub(const DtmfEvent& dtmf_event, size_t num_channels, | 1762 int NetEqImpl::DtmfOverdub(const DtmfEvent& dtmf_event, size_t num_channels, |
| 1758 int16_t* output) const { | 1763 int16_t* output) const { |
| 1759 size_t out_index = 0; | 1764 size_t out_index = 0; |
| 1760 int overdub_length = output_size_samples_; // Default value. | 1765 int overdub_length = output_size_samples_; // Default value. |
| 1761 | 1766 |
| 1762 if (sync_buffer_->dtmf_index() > sync_buffer_->next_index()) { | 1767 if (sync_buffer_->dtmf_index() > sync_buffer_->next_index()) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 | 1990 |
| 1986 void NetEqImpl::CreateDecisionLogic() { | 1991 void NetEqImpl::CreateDecisionLogic() { |
| 1987 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, | 1992 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, |
| 1988 playout_mode_, | 1993 playout_mode_, |
| 1989 decoder_database_.get(), | 1994 decoder_database_.get(), |
| 1990 *packet_buffer_.get(), | 1995 *packet_buffer_.get(), |
| 1991 delay_manager_.get(), | 1996 delay_manager_.get(), |
| 1992 buffer_level_filter_.get())); | 1997 buffer_level_filter_.get())); |
| 1993 } | 1998 } |
| 1994 } // namespace webrtc | 1999 } // namespace webrtc |
| OLD | NEW |