From 766adcdeb845bf810045aca5cb987c056d0041e1 Mon Sep 17 00:00:00 2001 From: Jakob Ivarsson Date: Wed, 15 Mar 2023 22:40:33 +0100 Subject: [PATCH] Simplify NetEq CNG decision logic. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is in preparation of merging the PLC and CNG decision logic. Bug: webrtc:13322 Change-Id: Ica782440b0d5c43c92ad5c33631b0cb708b51b0e Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/297861 Commit-Queue: Jakob Ivarsson‎ Reviewed-by: Henrik Lundin Cr-Commit-Position: refs/heads/main@{#39580} --- modules/audio_coding/neteq/decision_logic.cc | 54 +++++++------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/modules/audio_coding/neteq/decision_logic.cc b/modules/audio_coding/neteq/decision_logic.cc index a52c3e9599..45402d9a83 100644 --- a/modules/audio_coding/neteq/decision_logic.cc +++ b/modules/audio_coding/neteq/decision_logic.cc @@ -378,51 +378,33 @@ NetEq::Operation DecisionLogic::FuturePacketAvailable( // Check if we should continue with an ongoing expand because the new packet // is too far into the future. if (IsExpand(status.last_mode) && ShouldContinueExpand(status)) { - if (status.play_dtmf) { - // Still have DTMF to play, so do not do expand. - return NetEq::Operation::kDtmf; - } else { - // Nothing to play. - return NetEq::Operation::kExpand; - } + return NoPacket(status); } - if (status.last_mode == NetEq::Mode::kCodecPlc) { - return NetEq::Operation::kNormal; - } - - // If previous was comfort noise, then no merge is needed. if (IsCng(status.last_mode)) { - uint32_t timestamp_leap = - status.next_packet->timestamp - status.target_timestamp; - const bool generated_enough_noise = - status.generated_noise_samples >= timestamp_leap; - int playout_delay_ms = GetNextPacketDelayMs(status); const bool above_target_delay = playout_delay_ms > HighThresholdCng(); const bool below_target_delay = playout_delay_ms < LowThresholdCng(); - // Keep the delay same as before CNG, but make sure that it is within the - // target window. - if ((generated_enough_noise && !below_target_delay) || above_target_delay) { - time_stretched_cn_samples_ = - timestamp_leap - status.generated_noise_samples; - return NetEq::Operation::kNormal; + if ((PacketTooEarly(status) && !above_target_delay) || below_target_delay) { + return NoPacket(status); } - - if (status.last_mode == NetEq::Mode::kRfc3389Cng) { - return NetEq::Operation::kRfc3389CngNoPacket; - } - return NetEq::Operation::kCodecInternalCng; + uint32_t timestamp_leap = + status.next_packet->timestamp - status.target_timestamp; + time_stretched_cn_samples_ = + timestamp_leap - status.generated_noise_samples; } - // Do not merge unless we have done an expand before. - if (status.last_mode == NetEq::Mode::kExpand) { - return NetEq::Operation::kMerge; - } else if (status.play_dtmf) { - // Play DTMF instead of expand. - return NetEq::Operation::kDtmf; - } else { - return NetEq::Operation::kExpand; + // Time to play the next packet. + switch (status.last_mode) { + case NetEq::Mode::kExpand: + return NetEq::Operation::kMerge; + case NetEq::Mode::kCodecPlc: + case NetEq::Mode::kRfc3389Cng: + case NetEq::Mode::kCodecInternalCng: + return NetEq::Operation::kNormal; + default: + return status.play_dtmf ? NetEq::Operation::kDtmf + : NetEq::Operation::kExpand; } }