From 2e6b7e938fd93d7af4e8f913d4d5243af91b87b0 Mon Sep 17 00:00:00 2001 From: "turaj@webrtc.org" Date: Sat, 6 Apr 2013 00:08:11 +0000 Subject: [PATCH] In streaming mode it is preferable to fade to silence when sender stops sending, or long period of packet loss. test=try bots. Review URL: https://webrtc-codereview.appspot.com/1272004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3771 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/main/source/acm_neteq.cc | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/webrtc/modules/audio_coding/main/source/acm_neteq.cc b/webrtc/modules/audio_coding/main/source/acm_neteq.cc index 3bfc6e47a8..ce80184a80 100644 --- a/webrtc/modules/audio_coding/main/source/acm_neteq.cc +++ b/webrtc/modules/audio_coding/main/source/acm_neteq.cc @@ -323,38 +323,51 @@ WebRtc_Word32 ACMNetEQ::CurrentSampFreqHz() const { WebRtc_Word32 ACMNetEQ::SetPlayoutMode(const AudioPlayoutMode mode) { CriticalSectionScoped lock(neteq_crit_sect_); - if (playout_mode_ != mode) { - for (WebRtc_Word16 idx = 0; idx < num_slaves_ + 1; idx++) { - if (!is_initialized_[idx]) { - WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, - "SetPlayoutMode: NetEq is not initialized."); - return -1; - } + if (playout_mode_ == mode) + return 0; - enum WebRtcNetEQPlayoutMode playout_mode = kPlayoutOff; - switch (mode) { - case voice: - playout_mode = kPlayoutOn; - break; - case fax: - playout_mode = kPlayoutFax; - break; - case streaming: - playout_mode = kPlayoutStreaming; - break; - case off: - playout_mode = kPlayoutOff; - break; - } - if (WebRtcNetEQ_SetPlayoutMode(inst_[idx], playout_mode) < 0) { - LogError("SetPlayoutMode", idx); - return -1; - } - } - playout_mode_ = mode; + enum WebRtcNetEQPlayoutMode playout_mode = kPlayoutOff; + enum WebRtcNetEQBGNMode background_noise_mode = kBGNOn; + switch (mode) { + case voice: + playout_mode = kPlayoutOn; + background_noise_mode = kBGNOn; + break; + case fax: + playout_mode = kPlayoutFax; + WebRtcNetEQ_GetBGNMode(inst_[0], &background_noise_mode); // No change. + break; + case streaming: + playout_mode = kPlayoutStreaming; + background_noise_mode = kBGNOff; + break; + case off: + playout_mode = kPlayoutOff; + background_noise_mode = kBGNOff; + break; } - return 0; + int err = 0; + for (WebRtc_Word16 idx = 0; idx < num_slaves_ + 1; idx++) { + if (!is_initialized_[idx]) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, + "SetPlayoutMode: NetEq is not initialized."); + return -1; + } + + if (WebRtcNetEQ_SetPlayoutMode(inst_[idx], playout_mode) < 0) { + LogError("SetPlayoutMode", idx); + err = -1; + } + + if (WebRtcNetEQ_SetBGNMode(inst_[idx], kBGNOff) < 0) { + LogError("SetPlayoutMode::SetBGNMode", idx); + err = -1; + } + } + if (err == 0) + playout_mode_ = mode; + return err; } AudioPlayoutMode ACMNetEQ::playout_mode() const {