henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/neteq/decision_logic.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 12 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 13 | #include <assert.h> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 14 | #include <algorithm> |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 15 | #include <limits> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_coding/neteq/buffer_level_filter.h" |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 18 | #include "modules/audio_coding/neteq/decoder_database.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/audio_coding/neteq/delay_manager.h" |
| 20 | #include "modules/audio_coding/neteq/expand.h" |
| 21 | #include "modules/audio_coding/neteq/packet_buffer.h" |
| 22 | #include "modules/audio_coding/neteq/sync_buffer.h" |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 23 | #include "modules/include/module_common_types.h" |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 24 | #include "system_wrappers/include/field_trial.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | DecisionLogic* DecisionLogic::Create(int fs_hz, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 29 | size_t output_size_samples, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 30 | bool disallow_time_stretching, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 31 | DecoderDatabase* decoder_database, |
| 32 | const PacketBuffer& packet_buffer, |
| 33 | DelayManager* delay_manager, |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 34 | BufferLevelFilter* buffer_level_filter, |
| 35 | const TickTimer* tick_timer) { |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 36 | return new DecisionLogic(fs_hz, output_size_samples, disallow_time_stretching, |
| 37 | decoder_database, packet_buffer, delay_manager, |
| 38 | buffer_level_filter, tick_timer); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | DecisionLogic::DecisionLogic(int fs_hz, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 42 | size_t output_size_samples, |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 43 | bool disallow_time_stretching, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 44 | DecoderDatabase* decoder_database, |
| 45 | const PacketBuffer& packet_buffer, |
| 46 | DelayManager* delay_manager, |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 47 | BufferLevelFilter* buffer_level_filter, |
| 48 | const TickTimer* tick_timer) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 49 | : decoder_database_(decoder_database), |
| 50 | packet_buffer_(packet_buffer), |
| 51 | delay_manager_(delay_manager), |
| 52 | buffer_level_filter_(buffer_level_filter), |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 53 | tick_timer_(tick_timer), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 54 | cng_state_(kCngOff), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 55 | packet_length_samples_(0), |
| 56 | sample_memory_(0), |
| 57 | prev_time_scale_(false), |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 58 | disallow_time_stretching_(disallow_time_stretching), |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 59 | timescale_countdown_( |
| 60 | tick_timer_->GetNewCountdown(kMinTimescaleInterval + 1)), |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 61 | num_consecutive_expands_(0), |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 62 | postpone_decoding_after_expand_(field_trial::IsEnabled( |
| 63 | "WebRTC-Audio-NetEqPostponeDecodingAfterExpand")) { |
| 64 | delay_manager_->set_streaming_mode(false); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 65 | SetSampleRate(fs_hz, output_size_samples); |
| 66 | } |
| 67 | |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 68 | DecisionLogic::~DecisionLogic() = default; |
| 69 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 70 | void DecisionLogic::Reset() { |
| 71 | cng_state_ = kCngOff; |
henrik.lundin | b1fb72b | 2016-05-03 08:18:47 -0700 | [diff] [blame] | 72 | noise_fast_forward_ = 0; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 73 | packet_length_samples_ = 0; |
| 74 | sample_memory_ = 0; |
| 75 | prev_time_scale_ = false; |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 76 | timescale_countdown_.reset(); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 77 | num_consecutive_expands_ = 0; |
| 78 | } |
| 79 | |
| 80 | void DecisionLogic::SoftReset() { |
| 81 | packet_length_samples_ = 0; |
| 82 | sample_memory_ = 0; |
| 83 | prev_time_scale_ = false; |
Henrik Lundin | 47b17dc | 2016-05-10 10:20:59 +0200 | [diff] [blame] | 84 | timescale_countdown_ = |
| 85 | tick_timer_->GetNewCountdown(kMinTimescaleInterval + 1); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 88 | void DecisionLogic::SetSampleRate(int fs_hz, size_t output_size_samples) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 89 | // TODO(hlundin): Change to an enumerator and skip assert. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 90 | assert(fs_hz == 8000 || fs_hz == 16000 || fs_hz == 32000 || fs_hz == 48000); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 91 | fs_mult_ = fs_hz / 8000; |
| 92 | output_size_samples_ = output_size_samples; |
| 93 | } |
| 94 | |
| 95 | Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer, |
| 96 | const Expand& expand, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 97 | size_t decoder_frame_length, |
ossu | 7a37761 | 2016-10-18 04:06:13 -0700 | [diff] [blame] | 98 | const Packet* next_packet, |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 99 | Modes prev_mode, |
henrik.lundin | b1fb72b | 2016-05-03 08:18:47 -0700 | [diff] [blame] | 100 | bool play_dtmf, |
| 101 | size_t generated_noise_samples, |
| 102 | bool* reset_decoder) { |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 103 | // If last mode was CNG (or Expand, since this could be covering up for |
| 104 | // a lost CNG packet), remember that CNG is on. This is needed if comfort |
| 105 | // noise is interrupted by DTMF. |
| 106 | if (prev_mode == kModeRfc3389Cng) { |
| 107 | cng_state_ = kCngRfc3389On; |
| 108 | } else if (prev_mode == kModeCodecInternalCng) { |
| 109 | cng_state_ = kCngInternalOn; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 112 | const size_t samples_left = |
| 113 | sync_buffer.FutureLength() - expand.overlap_length(); |
| 114 | const size_t cur_size_samples = |
ossu | 61a208b | 2016-09-20 01:38:00 -0700 | [diff] [blame] | 115 | samples_left + packet_buffer_.NumSamplesInBuffer(decoder_frame_length); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 116 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 117 | prev_time_scale_ = |
| 118 | prev_time_scale_ && (prev_mode == kModeAccelerateSuccess || |
| 119 | prev_mode == kModeAccelerateLowEnergy || |
| 120 | prev_mode == kModePreemptiveExpandSuccess || |
| 121 | prev_mode == kModePreemptiveExpandLowEnergy); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 122 | |
| 123 | FilterBufferLevel(cur_size_samples, prev_mode); |
| 124 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 125 | // Guard for errors, to avoid getting stuck in error mode. |
| 126 | if (prev_mode == kModeError) { |
| 127 | if (!next_packet) { |
| 128 | return kExpand; |
| 129 | } else { |
| 130 | return kUndefined; // Use kUndefined to flag for a reset. |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | uint32_t target_timestamp = sync_buffer.end_timestamp(); |
| 135 | uint32_t available_timestamp = 0; |
| 136 | bool is_cng_packet = false; |
| 137 | if (next_packet) { |
| 138 | available_timestamp = next_packet->timestamp; |
| 139 | is_cng_packet = |
| 140 | decoder_database_->IsComfortNoise(next_packet->payload_type); |
| 141 | } |
| 142 | |
| 143 | if (is_cng_packet) { |
| 144 | return CngOperation(prev_mode, target_timestamp, available_timestamp, |
| 145 | generated_noise_samples); |
| 146 | } |
| 147 | |
| 148 | // Handle the case with no packet at all available (except maybe DTMF). |
| 149 | if (!next_packet) { |
| 150 | return NoPacket(play_dtmf); |
| 151 | } |
| 152 | |
| 153 | // If the expand period was very long, reset NetEQ since it is likely that the |
| 154 | // sender was restarted. |
| 155 | if (num_consecutive_expands_ > kReinitAfterExpands) { |
| 156 | *reset_decoder = true; |
| 157 | return kNormal; |
| 158 | } |
| 159 | |
| 160 | // Make sure we don't restart audio too soon after an expansion to avoid |
| 161 | // running out of data right away again. We should only wait if there are no |
| 162 | // DTX or CNG packets in the buffer (otherwise we should just play out what we |
| 163 | // have, since we cannot know the exact duration of DTX or CNG packets), and |
| 164 | // if the mute factor is low enough (otherwise the expansion was short enough |
| 165 | // to not be noticable). |
| 166 | // Note that the MuteFactor is in Q14, so a value of 16384 corresponds to 1. |
Henrik Lundin | 00eb12a | 2018-09-05 18:14:52 +0200 | [diff] [blame] | 167 | if (postpone_decoding_after_expand_ && |
| 168 | (prev_mode == kModeExpand || prev_mode == kModeCodecPlc) && |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 169 | !packet_buffer_.ContainsDtxOrCngPacket(decoder_database_) && |
| 170 | cur_size_samples<static_cast<size_t>(delay_manager_->TargetLevel() * |
| 171 | packet_length_samples_)>> 8 && |
| 172 | expand.MuteFactor(0) < 16384 / 2) { |
| 173 | return kExpand; |
| 174 | } |
| 175 | |
| 176 | const uint32_t five_seconds_samples = |
| 177 | static_cast<uint32_t>(5 * 8000 * fs_mult_); |
| 178 | // Check if the required packet is available. |
| 179 | if (target_timestamp == available_timestamp) { |
| 180 | return ExpectedPacketAvailable(prev_mode, play_dtmf); |
| 181 | } else if (!PacketBuffer::IsObsoleteTimestamp( |
| 182 | available_timestamp, target_timestamp, five_seconds_samples)) { |
| 183 | return FuturePacketAvailable( |
| 184 | sync_buffer, expand, decoder_frame_length, prev_mode, target_timestamp, |
| 185 | available_timestamp, play_dtmf, generated_noise_samples); |
| 186 | } else { |
| 187 | // This implies that available_timestamp < target_timestamp, which can |
| 188 | // happen when a new stream or codec is received. Signal for a reset. |
| 189 | return kUndefined; |
| 190 | } |
| 191 | } |
| 192 | |
Henrik Lundin | 5afa61c | 2018-07-02 14:53:24 +0200 | [diff] [blame] | 193 | void DecisionLogic::ExpandDecision(Operations operation) { |
| 194 | if (operation == kExpand) { |
| 195 | num_consecutive_expands_++; |
| 196 | } else { |
| 197 | num_consecutive_expands_ = 0; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void DecisionLogic::FilterBufferLevel(size_t buffer_size_samples, |
| 202 | Modes prev_mode) { |
| 203 | // Do not update buffer history if currently playing CNG since it will bias |
| 204 | // the filtered buffer level. |
| 205 | if ((prev_mode != kModeRfc3389Cng) && (prev_mode != kModeCodecInternalCng)) { |
| 206 | buffer_level_filter_->SetTargetBufferLevel( |
| 207 | delay_manager_->base_target_level()); |
| 208 | |
| 209 | size_t buffer_size_packets = 0; |
| 210 | if (packet_length_samples_ > 0) { |
| 211 | // Calculate size in packets. |
| 212 | buffer_size_packets = buffer_size_samples / packet_length_samples_; |
| 213 | } |
| 214 | int sample_memory_local = 0; |
| 215 | if (prev_time_scale_) { |
| 216 | sample_memory_local = sample_memory_; |
| 217 | timescale_countdown_ = |
| 218 | tick_timer_->GetNewCountdown(kMinTimescaleInterval); |
| 219 | } |
| 220 | buffer_level_filter_->Update(buffer_size_packets, sample_memory_local, |
| 221 | packet_length_samples_); |
| 222 | prev_time_scale_ = false; |
| 223 | } |
| 224 | } |
| 225 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 226 | Operations DecisionLogic::CngOperation(Modes prev_mode, |
| 227 | uint32_t target_timestamp, |
| 228 | uint32_t available_timestamp, |
| 229 | size_t generated_noise_samples) { |
| 230 | // Signed difference between target and available timestamp. |
| 231 | int32_t timestamp_diff = static_cast<int32_t>( |
| 232 | static_cast<uint32_t>(generated_noise_samples + target_timestamp) - |
| 233 | available_timestamp); |
| 234 | int32_t optimal_level_samp = static_cast<int32_t>( |
| 235 | (delay_manager_->TargetLevel() * packet_length_samples_) >> 8); |
| 236 | const int64_t excess_waiting_time_samp = |
| 237 | -static_cast<int64_t>(timestamp_diff) - optimal_level_samp; |
| 238 | |
| 239 | if (excess_waiting_time_samp > optimal_level_samp / 2) { |
| 240 | // The waiting time for this packet will be longer than 1.5 |
| 241 | // times the wanted buffer delay. Apply fast-forward to cut the |
| 242 | // waiting time down to the optimal. |
| 243 | noise_fast_forward_ = rtc::dchecked_cast<size_t>(noise_fast_forward_ + |
| 244 | excess_waiting_time_samp); |
| 245 | timestamp_diff = |
| 246 | rtc::saturated_cast<int32_t>(timestamp_diff + excess_waiting_time_samp); |
| 247 | } |
| 248 | |
| 249 | if (timestamp_diff < 0 && prev_mode == kModeRfc3389Cng) { |
| 250 | // Not time to play this packet yet. Wait another round before using this |
| 251 | // packet. Keep on playing CNG from previous CNG parameters. |
| 252 | return kRfc3389CngNoPacket; |
| 253 | } else { |
| 254 | // Otherwise, go for the CNG packet now. |
| 255 | noise_fast_forward_ = 0; |
| 256 | return kRfc3389Cng; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | Operations DecisionLogic::NoPacket(bool play_dtmf) { |
| 261 | if (cng_state_ == kCngRfc3389On) { |
| 262 | // Keep on playing comfort noise. |
| 263 | return kRfc3389CngNoPacket; |
| 264 | } else if (cng_state_ == kCngInternalOn) { |
| 265 | // Keep on playing codec internal comfort noise. |
| 266 | return kCodecInternalCng; |
| 267 | } else if (play_dtmf) { |
| 268 | return kDtmf; |
| 269 | } else { |
| 270 | // Nothing to play, do expand. |
| 271 | return kExpand; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | Operations DecisionLogic::ExpectedPacketAvailable(Modes prev_mode, |
| 276 | bool play_dtmf) { |
| 277 | if (!disallow_time_stretching_ && prev_mode != kModeExpand && !play_dtmf) { |
| 278 | // Check criterion for time-stretching. |
| 279 | int low_limit, high_limit; |
| 280 | delay_manager_->BufferLimits(&low_limit, &high_limit); |
| 281 | if (buffer_level_filter_->filtered_current_level() >= high_limit << 2) |
| 282 | return kFastAccelerate; |
| 283 | if (TimescaleAllowed()) { |
| 284 | if (buffer_level_filter_->filtered_current_level() >= high_limit) |
| 285 | return kAccelerate; |
| 286 | if (buffer_level_filter_->filtered_current_level() < low_limit) |
| 287 | return kPreemptiveExpand; |
| 288 | } |
| 289 | } |
| 290 | return kNormal; |
| 291 | } |
| 292 | |
| 293 | Operations DecisionLogic::FuturePacketAvailable( |
| 294 | const SyncBuffer& sync_buffer, |
| 295 | const Expand& expand, |
| 296 | size_t decoder_frame_length, |
| 297 | Modes prev_mode, |
| 298 | uint32_t target_timestamp, |
| 299 | uint32_t available_timestamp, |
| 300 | bool play_dtmf, |
| 301 | size_t generated_noise_samples) { |
| 302 | // Required packet is not available, but a future packet is. |
| 303 | // Check if we should continue with an ongoing expand because the new packet |
| 304 | // is too far into the future. |
| 305 | uint32_t timestamp_leap = available_timestamp - target_timestamp; |
Henrik Lundin | 00eb12a | 2018-09-05 18:14:52 +0200 | [diff] [blame] | 306 | if ((prev_mode == kModeExpand || prev_mode == kModeCodecPlc) && |
| 307 | !ReinitAfterExpands(timestamp_leap) && !MaxWaitForPacket() && |
| 308 | PacketTooEarly(timestamp_leap) && UnderTargetLevel()) { |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 309 | if (play_dtmf) { |
| 310 | // Still have DTMF to play, so do not do expand. |
| 311 | return kDtmf; |
| 312 | } else { |
| 313 | // Nothing to play. |
| 314 | return kExpand; |
| 315 | } |
| 316 | } |
| 317 | |
Henrik Lundin | 00eb12a | 2018-09-05 18:14:52 +0200 | [diff] [blame] | 318 | if (prev_mode == kModeCodecPlc) { |
| 319 | return kNormal; |
| 320 | } |
| 321 | |
Henrik Lundin | 7687ad5 | 2018-07-02 10:14:46 +0200 | [diff] [blame] | 322 | const size_t samples_left = |
| 323 | sync_buffer.FutureLength() - expand.overlap_length(); |
| 324 | const size_t cur_size_samples = |
| 325 | samples_left + packet_buffer_.NumPacketsInBuffer() * decoder_frame_length; |
| 326 | |
| 327 | // If previous was comfort noise, then no merge is needed. |
| 328 | if (prev_mode == kModeRfc3389Cng || prev_mode == kModeCodecInternalCng) { |
| 329 | // Keep the same delay as before the CNG, but make sure that the number of |
| 330 | // samples in buffer is no higher than 4 times the optimal level. (Note that |
| 331 | // TargetLevel() is in Q8.) |
| 332 | if (static_cast<uint32_t>(generated_noise_samples + target_timestamp) >= |
| 333 | available_timestamp || |
| 334 | cur_size_samples > |
| 335 | ((delay_manager_->TargetLevel() * packet_length_samples_) >> 8) * |
| 336 | 4) { |
| 337 | // Time to play this new packet. |
| 338 | return kNormal; |
| 339 | } else { |
| 340 | // Too early to play this new packet; keep on playing comfort noise. |
| 341 | if (prev_mode == kModeRfc3389Cng) { |
| 342 | return kRfc3389CngNoPacket; |
| 343 | } else { // prevPlayMode == kModeCodecInternalCng. |
| 344 | return kCodecInternalCng; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | // Do not merge unless we have done an expand before. |
| 349 | if (prev_mode == kModeExpand) { |
| 350 | return kMerge; |
| 351 | } else if (play_dtmf) { |
| 352 | // Play DTMF instead of expand. |
| 353 | return kDtmf; |
| 354 | } else { |
| 355 | return kExpand; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | bool DecisionLogic::UnderTargetLevel() const { |
| 360 | return buffer_level_filter_->filtered_current_level() <= |
| 361 | delay_manager_->TargetLevel(); |
| 362 | } |
| 363 | |
| 364 | bool DecisionLogic::ReinitAfterExpands(uint32_t timestamp_leap) const { |
| 365 | return timestamp_leap >= |
| 366 | static_cast<uint32_t>(output_size_samples_ * kReinitAfterExpands); |
| 367 | } |
| 368 | |
| 369 | bool DecisionLogic::PacketTooEarly(uint32_t timestamp_leap) const { |
| 370 | return timestamp_leap > |
| 371 | static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); |
| 372 | } |
| 373 | |
| 374 | bool DecisionLogic::MaxWaitForPacket() const { |
| 375 | return num_consecutive_expands_ >= kMaxWaitForPacket; |
| 376 | } |
| 377 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 378 | } // namespace webrtc |