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 24 matching lines...) Expand all Loading... |
35 #include "webrtc/modules/audio_coding/neteq/expand.h" | 35 #include "webrtc/modules/audio_coding/neteq/expand.h" |
36 #include "webrtc/modules/audio_coding/neteq/merge.h" | 36 #include "webrtc/modules/audio_coding/neteq/merge.h" |
37 #include "webrtc/modules/audio_coding/neteq/nack.h" | 37 #include "webrtc/modules/audio_coding/neteq/nack.h" |
38 #include "webrtc/modules/audio_coding/neteq/normal.h" | 38 #include "webrtc/modules/audio_coding/neteq/normal.h" |
39 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" | 39 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" |
40 #include "webrtc/modules/audio_coding/neteq/packet.h" | 40 #include "webrtc/modules/audio_coding/neteq/packet.h" |
41 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" | 41 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" |
42 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" | 42 #include "webrtc/modules/audio_coding/neteq/post_decode_vad.h" |
43 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" | 43 #include "webrtc/modules/audio_coding/neteq/preemptive_expand.h" |
44 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 44 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
| 45 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
45 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" | 46 #include "webrtc/modules/audio_coding/neteq/timestamp_scaler.h" |
46 #include "webrtc/modules/include/module_common_types.h" | 47 #include "webrtc/modules/include/module_common_types.h" |
47 | 48 |
48 // Modify the code to obtain backwards bit-exactness. Once bit-exactness is no | 49 // Modify the code to obtain backwards bit-exactness. Once bit-exactness is no |
49 // longer required, this #define should be removed (and the code that it | 50 // longer required, this #define should be removed (and the code that it |
50 // enables). | 51 // enables). |
51 #define LEGACY_BITEXACT | 52 #define LEGACY_BITEXACT |
52 | 53 |
53 namespace webrtc { | 54 namespace webrtc { |
54 | 55 |
55 NetEqImpl::NetEqImpl(const NetEq::Config& config, | 56 NetEqImpl::NetEqImpl(const NetEq::Config& config, |
| 57 std::unique_ptr<TickTimer> tick_timer, |
56 BufferLevelFilter* buffer_level_filter, | 58 BufferLevelFilter* buffer_level_filter, |
57 DecoderDatabase* decoder_database, | 59 DecoderDatabase* decoder_database, |
58 DelayManager* delay_manager, | 60 DelayManager* delay_manager, |
59 DelayPeakDetector* delay_peak_detector, | 61 DelayPeakDetector* delay_peak_detector, |
60 DtmfBuffer* dtmf_buffer, | 62 DtmfBuffer* dtmf_buffer, |
61 DtmfToneGenerator* dtmf_tone_generator, | 63 DtmfToneGenerator* dtmf_tone_generator, |
62 PacketBuffer* packet_buffer, | 64 PacketBuffer* packet_buffer, |
63 PayloadSplitter* payload_splitter, | 65 PayloadSplitter* payload_splitter, |
64 TimestampScaler* timestamp_scaler, | 66 TimestampScaler* timestamp_scaler, |
65 AccelerateFactory* accelerate_factory, | 67 AccelerateFactory* accelerate_factory, |
66 ExpandFactory* expand_factory, | 68 ExpandFactory* expand_factory, |
67 PreemptiveExpandFactory* preemptive_expand_factory, | 69 PreemptiveExpandFactory* preemptive_expand_factory, |
68 bool create_components) | 70 bool create_components) |
69 : buffer_level_filter_(buffer_level_filter), | 71 : tick_timer_(std::move(tick_timer)), |
| 72 buffer_level_filter_(buffer_level_filter), |
70 decoder_database_(decoder_database), | 73 decoder_database_(decoder_database), |
71 delay_manager_(delay_manager), | 74 delay_manager_(delay_manager), |
72 delay_peak_detector_(delay_peak_detector), | 75 delay_peak_detector_(delay_peak_detector), |
73 dtmf_buffer_(dtmf_buffer), | 76 dtmf_buffer_(dtmf_buffer), |
74 dtmf_tone_generator_(dtmf_tone_generator), | 77 dtmf_tone_generator_(dtmf_tone_generator), |
75 packet_buffer_(packet_buffer), | 78 packet_buffer_(packet_buffer), |
76 payload_splitter_(payload_splitter), | 79 payload_splitter_(payload_splitter), |
77 timestamp_scaler_(timestamp_scaler), | 80 timestamp_scaler_(timestamp_scaler), |
78 vad_(new PostDecodeVad()), | 81 vad_(new PostDecodeVad()), |
79 expand_factory_(expand_factory), | 82 expand_factory_(expand_factory), |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // is not defined outside of this block. | 528 // is not defined outside of this block. |
526 Packet* packet = new Packet; | 529 Packet* packet = new Packet; |
527 packet->header.markerBit = false; | 530 packet->header.markerBit = false; |
528 packet->header.payloadType = rtp_header.header.payloadType; | 531 packet->header.payloadType = rtp_header.header.payloadType; |
529 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; | 532 packet->header.sequenceNumber = rtp_header.header.sequenceNumber; |
530 packet->header.timestamp = rtp_header.header.timestamp; | 533 packet->header.timestamp = rtp_header.header.timestamp; |
531 packet->header.ssrc = rtp_header.header.ssrc; | 534 packet->header.ssrc = rtp_header.header.ssrc; |
532 packet->header.numCSRCs = 0; | 535 packet->header.numCSRCs = 0; |
533 packet->payload_length = payload.size(); | 536 packet->payload_length = payload.size(); |
534 packet->primary = true; | 537 packet->primary = true; |
535 packet->waiting_time = 0; | 538 // Waiting time will be set upon inserting the packet in the buffer. |
| 539 RTC_DCHECK(!packet->waiting_time); |
536 packet->payload = new uint8_t[packet->payload_length]; | 540 packet->payload = new uint8_t[packet->payload_length]; |
537 packet->sync_packet = is_sync_packet; | 541 packet->sync_packet = is_sync_packet; |
538 if (!packet->payload) { | 542 if (!packet->payload) { |
539 LOG_F(LS_ERROR) << "Payload pointer is NULL."; | 543 LOG_F(LS_ERROR) << "Payload pointer is NULL."; |
540 } | 544 } |
541 assert(!payload.empty()); // Already checked above. | 545 assert(!payload.empty()); // Already checked above. |
542 memcpy(packet->payload, payload.data(), packet->payload_length); | 546 memcpy(packet->payload, payload.data(), packet->payload_length); |
543 // Insert packet in a packet list. | 547 // Insert packet in a packet list. |
544 packet_list.push_back(packet); | 548 packet_list.push_back(packet); |
545 // Save main payloads header for later. | 549 // Save main payloads header for later. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 delay_manager_->ResetPacketIatCount(); | 785 delay_manager_->ResetPacketIatCount(); |
782 } | 786 } |
783 return 0; | 787 return 0; |
784 } | 788 } |
785 | 789 |
786 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame) { | 790 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame) { |
787 PacketList packet_list; | 791 PacketList packet_list; |
788 DtmfEvent dtmf_event; | 792 DtmfEvent dtmf_event; |
789 Operations operation; | 793 Operations operation; |
790 bool play_dtmf; | 794 bool play_dtmf; |
| 795 tick_timer_->Increment(); |
| 796 stats_.IncreaseCounter(output_size_samples_, fs_hz_); |
791 int return_value = GetDecision(&operation, &packet_list, &dtmf_event, | 797 int return_value = GetDecision(&operation, &packet_list, &dtmf_event, |
792 &play_dtmf); | 798 &play_dtmf); |
793 if (return_value != 0) { | 799 if (return_value != 0) { |
794 last_mode_ = kModeError; | 800 last_mode_ = kModeError; |
795 return return_value; | 801 return return_value; |
796 } | 802 } |
797 | 803 |
798 AudioDecoder::SpeechType speech_type; | 804 AudioDecoder::SpeechType speech_type; |
799 int length = 0; | 805 int length = 0; |
800 int decode_return_value = Decode(&packet_list, &operation, | 806 int decode_return_value = Decode(&packet_list, &operation, |
801 &length, &speech_type); | 807 &length, &speech_type); |
802 | 808 |
803 assert(vad_.get()); | 809 assert(vad_.get()); |
804 bool sid_frame_available = | 810 bool sid_frame_available = |
805 (operation == kRfc3389Cng && !packet_list.empty()); | 811 (operation == kRfc3389Cng && !packet_list.empty()); |
806 vad_->Update(decoded_buffer_.get(), static_cast<size_t>(length), speech_type, | 812 vad_->Update(decoded_buffer_.get(), static_cast<size_t>(length), speech_type, |
807 sid_frame_available, fs_hz_); | 813 sid_frame_available, fs_hz_); |
808 | 814 |
| 815 if (sid_frame_available || speech_type == AudioDecoder::kComfortNoise) { |
| 816 // Start a new stopwatch since we are decoding a new CNG packet. |
| 817 generated_noise_stopwatch_ = tick_timer_->GetNewStopwatch(); |
| 818 } |
| 819 |
809 algorithm_buffer_->Clear(); | 820 algorithm_buffer_->Clear(); |
810 switch (operation) { | 821 switch (operation) { |
811 case kNormal: { | 822 case kNormal: { |
812 DoNormal(decoded_buffer_.get(), length, speech_type, play_dtmf); | 823 DoNormal(decoded_buffer_.get(), length, speech_type, play_dtmf); |
813 break; | 824 break; |
814 } | 825 } |
815 case kMerge: { | 826 case kMerge: { |
816 DoMerge(decoded_buffer_.get(), length, speech_type, play_dtmf); | 827 DoMerge(decoded_buffer_.get(), length, speech_type, play_dtmf); |
817 break; | 828 break; |
818 } | 829 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 // Set the timestamp in the audio frame to zero before the first packet has | 982 // Set the timestamp in the audio frame to zero before the first packet has |
972 // been inserted. Otherwise, subtract the frame size in samples to get the | 983 // been inserted. Otherwise, subtract the frame size in samples to get the |
973 // timestamp of the first sample in the frame (playout_timestamp_ is the | 984 // timestamp of the first sample in the frame (playout_timestamp_ is the |
974 // last + 1). | 985 // last + 1). |
975 audio_frame->timestamp_ = | 986 audio_frame->timestamp_ = |
976 first_packet_ | 987 first_packet_ |
977 ? 0 | 988 ? 0 |
978 : timestamp_scaler_->ToExternal(playout_timestamp_) - | 989 : timestamp_scaler_->ToExternal(playout_timestamp_) - |
979 static_cast<uint32_t>(audio_frame->samples_per_channel_); | 990 static_cast<uint32_t>(audio_frame->samples_per_channel_); |
980 | 991 |
| 992 if (!(last_mode_ == kModeRfc3389Cng || |
| 993 last_mode_ == kModeCodecInternalCng || |
| 994 last_mode_ == kModeExpand)) { |
| 995 generated_noise_stopwatch_.reset(); |
| 996 } |
| 997 |
981 if (decode_return_value) return decode_return_value; | 998 if (decode_return_value) return decode_return_value; |
982 return return_value; | 999 return return_value; |
983 } | 1000 } |
984 | 1001 |
985 int NetEqImpl::GetDecision(Operations* operation, | 1002 int NetEqImpl::GetDecision(Operations* operation, |
986 PacketList* packet_list, | 1003 PacketList* packet_list, |
987 DtmfEvent* dtmf_event, | 1004 DtmfEvent* dtmf_event, |
988 bool* play_dtmf) { | 1005 bool* play_dtmf) { |
989 // Initialize output variables. | 1006 // Initialize output variables. |
990 *play_dtmf = false; | 1007 *play_dtmf = false; |
991 *operation = kUndefined; | 1008 *operation = kUndefined; |
992 | 1009 |
993 // Increment time counters. | |
994 packet_buffer_->IncrementWaitingTimes(); | |
995 stats_.IncreaseCounter(output_size_samples_, fs_hz_); | |
996 | |
997 assert(sync_buffer_.get()); | 1010 assert(sync_buffer_.get()); |
998 uint32_t end_timestamp = sync_buffer_->end_timestamp(); | 1011 uint32_t end_timestamp = sync_buffer_->end_timestamp(); |
999 if (!new_codec_) { | 1012 if (!new_codec_) { |
1000 const uint32_t five_seconds_samples = 5 * fs_hz_; | 1013 const uint32_t five_seconds_samples = 5 * fs_hz_; |
1001 packet_buffer_->DiscardOldPackets(end_timestamp, five_seconds_samples); | 1014 packet_buffer_->DiscardOldPackets(end_timestamp, five_seconds_samples); |
1002 } | 1015 } |
1003 const RTPHeader* header = packet_buffer_->NextRtpHeader(); | 1016 const RTPHeader* header = packet_buffer_->NextRtpHeader(); |
1004 | 1017 |
| 1018 RTC_DCHECK(!generated_noise_stopwatch_ || |
| 1019 generated_noise_stopwatch_->ElapsedTicks() >= 1); |
| 1020 uint64_t generated_noise_samples = |
| 1021 generated_noise_stopwatch_ |
| 1022 ? (generated_noise_stopwatch_->ElapsedTicks() - 1) * |
| 1023 output_size_samples_ + |
| 1024 decision_logic_->noise_fast_forward() |
| 1025 : 0; |
| 1026 |
1005 if (decision_logic_->CngRfc3389On() || last_mode_ == kModeRfc3389Cng) { | 1027 if (decision_logic_->CngRfc3389On() || last_mode_ == kModeRfc3389Cng) { |
1006 // Because of timestamp peculiarities, we have to "manually" disallow using | 1028 // Because of timestamp peculiarities, we have to "manually" disallow using |
1007 // a CNG packet with the same timestamp as the one that was last played. | 1029 // a CNG packet with the same timestamp as the one that was last played. |
1008 // This can happen when using redundancy and will cause the timing to shift. | 1030 // This can happen when using redundancy and will cause the timing to shift. |
1009 while (header && decoder_database_->IsComfortNoise(header->payloadType) && | 1031 while (header && decoder_database_->IsComfortNoise(header->payloadType) && |
1010 (end_timestamp >= header->timestamp || | 1032 (end_timestamp >= header->timestamp || |
1011 end_timestamp + decision_logic_->generated_noise_samples() > | 1033 end_timestamp + generated_noise_samples > header->timestamp)) { |
1012 header->timestamp)) { | |
1013 // Don't use this packet, discard it. | 1034 // Don't use this packet, discard it. |
1014 if (packet_buffer_->DiscardNextPacket() != PacketBuffer::kOK) { | 1035 if (packet_buffer_->DiscardNextPacket() != PacketBuffer::kOK) { |
1015 assert(false); // Must be ok by design. | 1036 assert(false); // Must be ok by design. |
1016 } | 1037 } |
1017 // Check buffer again. | 1038 // Check buffer again. |
1018 if (!new_codec_) { | 1039 if (!new_codec_) { |
1019 packet_buffer_->DiscardOldPackets(end_timestamp, 5 * fs_hz_); | 1040 packet_buffer_->DiscardOldPackets(end_timestamp, 5 * fs_hz_); |
1020 } | 1041 } |
1021 header = packet_buffer_->NextRtpHeader(); | 1042 header = packet_buffer_->NextRtpHeader(); |
1022 } | 1043 } |
1023 } | 1044 } |
1024 | 1045 |
1025 assert(expand_.get()); | 1046 assert(expand_.get()); |
1026 const int samples_left = static_cast<int>(sync_buffer_->FutureLength() - | 1047 const int samples_left = static_cast<int>(sync_buffer_->FutureLength() - |
1027 expand_->overlap_length()); | 1048 expand_->overlap_length()); |
1028 if (last_mode_ == kModeAccelerateSuccess || | 1049 if (last_mode_ == kModeAccelerateSuccess || |
1029 last_mode_ == kModeAccelerateLowEnergy || | 1050 last_mode_ == kModeAccelerateLowEnergy || |
1030 last_mode_ == kModePreemptiveExpandSuccess || | 1051 last_mode_ == kModePreemptiveExpandSuccess || |
1031 last_mode_ == kModePreemptiveExpandLowEnergy) { | 1052 last_mode_ == kModePreemptiveExpandLowEnergy) { |
1032 // Subtract (samples_left + output_size_samples_) from sampleMemory. | 1053 // Subtract (samples_left + output_size_samples_) from sampleMemory. |
1033 decision_logic_->AddSampleMemory( | 1054 decision_logic_->AddSampleMemory( |
1034 -(samples_left + rtc::checked_cast<int>(output_size_samples_))); | 1055 -(samples_left + rtc::checked_cast<int>(output_size_samples_))); |
1035 } | 1056 } |
1036 | 1057 |
1037 // Check if it is time to play a DTMF event. | 1058 // Check if it is time to play a DTMF event. |
1038 if (dtmf_buffer_->GetEvent( | 1059 if (dtmf_buffer_->GetEvent( |
1039 static_cast<uint32_t>( | 1060 static_cast<uint32_t>( |
1040 end_timestamp + decision_logic_->generated_noise_samples()), | 1061 end_timestamp + generated_noise_samples), |
1041 dtmf_event)) { | 1062 dtmf_event)) { |
1042 *play_dtmf = true; | 1063 *play_dtmf = true; |
1043 } | 1064 } |
1044 | 1065 |
1045 // Get instruction. | 1066 // Get instruction. |
1046 assert(sync_buffer_.get()); | 1067 assert(sync_buffer_.get()); |
1047 assert(expand_.get()); | 1068 assert(expand_.get()); |
1048 *operation = decision_logic_->GetDecision(*sync_buffer_, | 1069 generated_noise_samples = |
1049 *expand_, | 1070 generated_noise_stopwatch_ |
1050 decoder_frame_length_, | 1071 ? generated_noise_stopwatch_->ElapsedTicks() * output_size_samples_ + |
1051 header, | 1072 decision_logic_->noise_fast_forward() |
1052 last_mode_, | 1073 : 0; |
1053 *play_dtmf, | 1074 *operation = decision_logic_->GetDecision( |
1054 &reset_decoder_); | 1075 *sync_buffer_, *expand_, decoder_frame_length_, header, last_mode_, |
| 1076 *play_dtmf, generated_noise_samples, &reset_decoder_); |
1055 | 1077 |
1056 // Check if we already have enough samples in the |sync_buffer_|. If so, | 1078 // Check if we already have enough samples in the |sync_buffer_|. If so, |
1057 // change decision to normal, unless the decision was merge, accelerate, or | 1079 // change decision to normal, unless the decision was merge, accelerate, or |
1058 // preemptive expand. | 1080 // preemptive expand. |
1059 if (samples_left >= rtc::checked_cast<int>(output_size_samples_) && | 1081 if (samples_left >= rtc::checked_cast<int>(output_size_samples_) && |
1060 *operation != kMerge && | 1082 *operation != kMerge && |
1061 *operation != kAccelerate && | 1083 *operation != kAccelerate && |
1062 *operation != kFastAccelerate && | 1084 *operation != kFastAccelerate && |
1063 *operation != kPreemptiveExpand) { | 1085 *operation != kPreemptiveExpand) { |
1064 *operation = kNormal; | 1086 *operation = kNormal; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 return 0; | 1139 return 0; |
1118 } | 1140 } |
1119 case kRfc3389CngNoPacket: | 1141 case kRfc3389CngNoPacket: |
1120 case kCodecInternalCng: { | 1142 case kCodecInternalCng: { |
1121 return 0; | 1143 return 0; |
1122 } | 1144 } |
1123 case kDtmf: { | 1145 case kDtmf: { |
1124 // TODO(hlundin): Write test for this. | 1146 // TODO(hlundin): Write test for this. |
1125 // Update timestamp. | 1147 // Update timestamp. |
1126 timestamp_ = end_timestamp; | 1148 timestamp_ = end_timestamp; |
1127 if (decision_logic_->generated_noise_samples() > 0 && | 1149 const uint64_t generated_noise_samples = |
1128 last_mode_ != kModeDtmf) { | 1150 generated_noise_stopwatch_ |
| 1151 ? generated_noise_stopwatch_->ElapsedTicks() * |
| 1152 output_size_samples_ + |
| 1153 decision_logic_->noise_fast_forward() |
| 1154 : 0; |
| 1155 if (generated_noise_samples > 0 && last_mode_ != kModeDtmf) { |
1129 // Make a jump in timestamp due to the recently played comfort noise. | 1156 // Make a jump in timestamp due to the recently played comfort noise. |
1130 uint32_t timestamp_jump = | 1157 uint32_t timestamp_jump = |
1131 static_cast<uint32_t>(decision_logic_->generated_noise_samples()); | 1158 static_cast<uint32_t>(generated_noise_samples); |
1132 sync_buffer_->IncreaseEndTimestamp(timestamp_jump); | 1159 sync_buffer_->IncreaseEndTimestamp(timestamp_jump); |
1133 timestamp_ += timestamp_jump; | 1160 timestamp_ += timestamp_jump; |
1134 } | 1161 } |
1135 decision_logic_->set_generated_noise_samples(0); | |
1136 return 0; | 1162 return 0; |
1137 } | 1163 } |
1138 case kAccelerate: | 1164 case kAccelerate: |
1139 case kFastAccelerate: { | 1165 case kFastAccelerate: { |
1140 // In order to do an accelerate we need at least 30 ms of audio data. | 1166 // In order to do an accelerate we need at least 30 ms of audio data. |
1141 if (samples_left >= static_cast<int>(samples_30_ms)) { | 1167 if (samples_left >= static_cast<int>(samples_30_ms)) { |
1142 // Already have enough data, so we do not need to extract any more. | 1168 // Already have enough data, so we do not need to extract any more. |
1143 decision_logic_->set_sample_memory(samples_left); | 1169 decision_logic_->set_sample_memory(samples_left); |
1144 decision_logic_->set_prev_time_scale(true); | 1170 decision_logic_->set_prev_time_scale(true); |
1145 return 0; | 1171 return 0; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 // if comfort noise is not played. If comfort noise was just played, | 1234 // if comfort noise is not played. If comfort noise was just played, |
1209 // this adjustment of timestamp is only done to get back in sync with the | 1235 // this adjustment of timestamp is only done to get back in sync with the |
1210 // stream timestamp; no loss to report. | 1236 // stream timestamp; no loss to report. |
1211 stats_.LostSamples(header->timestamp - end_timestamp); | 1237 stats_.LostSamples(header->timestamp - end_timestamp); |
1212 } | 1238 } |
1213 | 1239 |
1214 if (*operation != kRfc3389Cng) { | 1240 if (*operation != kRfc3389Cng) { |
1215 // We are about to decode and use a non-CNG packet. | 1241 // We are about to decode and use a non-CNG packet. |
1216 decision_logic_->SetCngOff(); | 1242 decision_logic_->SetCngOff(); |
1217 } | 1243 } |
1218 // Reset CNG timestamp as a new packet will be delivered. | |
1219 // (Also if this is a CNG packet, since playedOutTS is updated.) | |
1220 decision_logic_->set_generated_noise_samples(0); | |
1221 | 1244 |
1222 extracted_samples = ExtractPackets(required_samples, packet_list); | 1245 extracted_samples = ExtractPackets(required_samples, packet_list); |
1223 if (extracted_samples < 0) { | 1246 if (extracted_samples < 0) { |
1224 return kPacketBufferCorruption; | 1247 return kPacketBufferCorruption; |
1225 } | 1248 } |
1226 } | 1249 } |
1227 | 1250 |
1228 if (*operation == kAccelerate || *operation == kFastAccelerate || | 1251 if (*operation == kAccelerate || *operation == kFastAccelerate || |
1229 *operation == kPreemptiveExpand) { | 1252 *operation == kPreemptiveExpand) { |
1230 decision_logic_->set_sample_memory(samples_left + extracted_samples); | 1253 decision_logic_->set_sample_memory(samples_left + extracted_samples); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 if (return_value < 0) { | 1566 if (return_value < 0) { |
1544 return return_value; | 1567 return return_value; |
1545 } | 1568 } |
1546 | 1569 |
1547 sync_buffer_->PushBack(*algorithm_buffer_); | 1570 sync_buffer_->PushBack(*algorithm_buffer_); |
1548 algorithm_buffer_->Clear(); | 1571 algorithm_buffer_->Clear(); |
1549 } | 1572 } |
1550 if (!play_dtmf) { | 1573 if (!play_dtmf) { |
1551 dtmf_tone_generator_->Reset(); | 1574 dtmf_tone_generator_->Reset(); |
1552 } | 1575 } |
| 1576 |
| 1577 if (!generated_noise_stopwatch_) { |
| 1578 // Start a new stopwatch since we may be covering for a lost CNG packet. |
| 1579 generated_noise_stopwatch_ = tick_timer_->GetNewStopwatch(); |
| 1580 } |
| 1581 |
1553 return 0; | 1582 return 0; |
1554 } | 1583 } |
1555 | 1584 |
1556 int NetEqImpl::DoAccelerate(int16_t* decoded_buffer, | 1585 int NetEqImpl::DoAccelerate(int16_t* decoded_buffer, |
1557 size_t decoded_length, | 1586 size_t decoded_length, |
1558 AudioDecoder::SpeechType speech_type, | 1587 AudioDecoder::SpeechType speech_type, |
1559 bool play_dtmf, | 1588 bool play_dtmf, |
1560 bool fast_accelerate) { | 1589 bool fast_accelerate) { |
1561 const size_t required_samples = | 1590 const size_t required_samples = |
1562 static_cast<size_t>(240 * fs_mult_); // Must have 30 ms. | 1591 static_cast<size_t>(240 * fs_mult_); // Must have 30 ms. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 size_t discard_count = 0; | 1942 size_t discard_count = 0; |
1914 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); | 1943 Packet* packet = packet_buffer_->GetNextPacket(&discard_count); |
1915 // |header| may be invalid after the |packet_buffer_| operation. | 1944 // |header| may be invalid after the |packet_buffer_| operation. |
1916 header = NULL; | 1945 header = NULL; |
1917 if (!packet) { | 1946 if (!packet) { |
1918 LOG(LS_ERROR) << "Should always be able to extract a packet here"; | 1947 LOG(LS_ERROR) << "Should always be able to extract a packet here"; |
1919 assert(false); // Should always be able to extract a packet here. | 1948 assert(false); // Should always be able to extract a packet here. |
1920 return -1; | 1949 return -1; |
1921 } | 1950 } |
1922 stats_.PacketsDiscarded(discard_count); | 1951 stats_.PacketsDiscarded(discard_count); |
1923 // Store waiting time in ms; packets->waiting_time is in "output blocks". | 1952 stats_.StoreWaitingTime(packet->waiting_time->ElapsedMs()); |
1924 stats_.StoreWaitingTime(packet->waiting_time * kOutputSizeMs); | |
1925 assert(packet->payload_length > 0); | 1953 assert(packet->payload_length > 0); |
1926 packet_list->push_back(packet); // Store packet in list. | 1954 packet_list->push_back(packet); // Store packet in list. |
1927 | 1955 |
1928 if (first_packet) { | 1956 if (first_packet) { |
1929 first_packet = false; | 1957 first_packet = false; |
1930 if (nack_enabled_) { | 1958 if (nack_enabled_) { |
1931 RTC_DCHECK(nack_); | 1959 RTC_DCHECK(nack_); |
1932 // TODO(henrik.lundin): Should we update this for all decoded packets? | 1960 // TODO(henrik.lundin): Should we update this for all decoded packets? |
1933 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, | 1961 nack_->UpdateLastDecodedPacket(packet->header.sequenceNumber, |
1934 packet->header.timestamp); | 1962 packet->header.timestamp); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2087 } else if (last_mode_ == kModeExpand) { | 2115 } else if (last_mode_ == kModeExpand) { |
2088 return OutputType::kPLC; | 2116 return OutputType::kPLC; |
2089 } else if (vad_->running() && !vad_->active_speech()) { | 2117 } else if (vad_->running() && !vad_->active_speech()) { |
2090 return OutputType::kVadPassive; | 2118 return OutputType::kVadPassive; |
2091 } else { | 2119 } else { |
2092 return OutputType::kNormalSpeech; | 2120 return OutputType::kNormalSpeech; |
2093 } | 2121 } |
2094 } | 2122 } |
2095 | 2123 |
2096 void NetEqImpl::CreateDecisionLogic() { | 2124 void NetEqImpl::CreateDecisionLogic() { |
2097 decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_, | 2125 decision_logic_.reset(DecisionLogic::Create( |
2098 playout_mode_, | 2126 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), |
2099 decoder_database_.get(), | 2127 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), |
2100 *packet_buffer_.get(), | 2128 *tick_timer_)); |
2101 delay_manager_.get(), | |
2102 buffer_level_filter_.get())); | |
2103 } | 2129 } |
2104 } // namespace webrtc | 2130 } // namespace webrtc |
OLD | NEW |