Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_impl.cc

Issue 1965733002: NetEq: Implement muted output (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@muted-expand
Patch Set: Add new tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 reset_decoder_(false), 101 reset_decoder_(false),
102 current_rtp_payload_type_(0xFF), // Invalid RTP payload type. 102 current_rtp_payload_type_(0xFF), // Invalid RTP payload type.
103 current_cng_rtp_payload_type_(0xFF), // Invalid RTP payload type. 103 current_cng_rtp_payload_type_(0xFF), // Invalid RTP payload type.
104 ssrc_(0), 104 ssrc_(0),
105 first_packet_(true), 105 first_packet_(true),
106 error_code_(0), 106 error_code_(0),
107 decoder_error_code_(0), 107 decoder_error_code_(0),
108 background_noise_mode_(config.background_noise_mode), 108 background_noise_mode_(config.background_noise_mode),
109 playout_mode_(config.playout_mode), 109 playout_mode_(config.playout_mode),
110 enable_fast_accelerate_(config.enable_fast_accelerate), 110 enable_fast_accelerate_(config.enable_fast_accelerate),
111 nack_enabled_(false) { 111 nack_enabled_(false),
112 enable_muted_state_(config.enable_muted_state) {
112 LOG(LS_INFO) << "NetEq config: " << config.ToString(); 113 LOG(LS_INFO) << "NetEq config: " << config.ToString();
113 int fs = config.sample_rate_hz; 114 int fs = config.sample_rate_hz;
114 if (fs != 8000 && fs != 16000 && fs != 32000 && fs != 48000) { 115 if (fs != 8000 && fs != 16000 && fs != 32000 && fs != 48000) {
115 LOG(LS_ERROR) << "Sample rate " << fs << " Hz not supported. " << 116 LOG(LS_ERROR) << "Sample rate " << fs << " Hz not supported. " <<
116 "Changing to 8000 Hz."; 117 "Changing to 8000 Hz.";
117 fs = 8000; 118 fs = 8000;
118 } 119 }
119 delay_manager_->SetMaximumDelay(config.max_delay_ms); 120 delay_manager_->SetMaximumDelay(config.max_delay_ms);
120 fs_hz_ = fs; 121 fs_hz_ = fs;
121 fs_mult_ = fs / 8000; 122 fs_mult_ = fs / 8000;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 default: 199 default:
199 RTC_NOTREACHED(); 200 RTC_NOTREACHED();
200 } 201 }
201 if (!vad_enabled) { 202 if (!vad_enabled) {
202 // Always set kVadUnknown when receive VAD is inactive. 203 // Always set kVadUnknown when receive VAD is inactive.
203 audio_frame->vad_activity_ = AudioFrame::kVadUnknown; 204 audio_frame->vad_activity_ = AudioFrame::kVadUnknown;
204 } 205 }
205 } 206 }
206 } // namespace 207 } // namespace
207 208
208 int NetEqImpl::GetAudio(AudioFrame* audio_frame) { 209 int NetEqImpl::GetAudio(AudioFrame* audio_frame, bool* muted) {
209 TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio"); 210 TRACE_EVENT0("webrtc", "NetEqImpl::GetAudio");
210 rtc::CritScope lock(&crit_sect_); 211 rtc::CritScope lock(&crit_sect_);
211 int error = GetAudioInternal(audio_frame); 212 int error = GetAudioInternal(audio_frame, muted);
212 RTC_DCHECK_EQ( 213 RTC_DCHECK_EQ(
213 audio_frame->sample_rate_hz_, 214 audio_frame->sample_rate_hz_,
214 rtc::checked_cast<int>(audio_frame->samples_per_channel_ * 100)); 215 rtc::checked_cast<int>(audio_frame->samples_per_channel_ * 100));
215 if (error != 0) { 216 if (error != 0) {
216 error_code_ = error; 217 error_code_ = error;
217 return kFail; 218 return kFail;
218 } 219 }
219 SetAudioFrameActivityAndType(vad_->enabled(), LastOutputType(), 220 SetAudioFrameActivityAndType(vad_->enabled(), LastOutputType(),
220 last_vad_activity_, audio_frame); 221 last_vad_activity_, audio_frame);
221 last_vad_activity_ = audio_frame->vad_activity_; 222 last_vad_activity_ = audio_frame->vad_activity_;
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 } else if (delay_manager_->last_pack_cng_or_dtmf() == -1) { 803 } else if (delay_manager_->last_pack_cng_or_dtmf() == -1) {
803 // This is first "normal" packet after CNG or DTMF. 804 // This is first "normal" packet after CNG or DTMF.
804 // Reset packet time counter and measure time until next packet, 805 // Reset packet time counter and measure time until next packet,
805 // but don't update statistics. 806 // but don't update statistics.
806 delay_manager_->set_last_pack_cng_or_dtmf(0); 807 delay_manager_->set_last_pack_cng_or_dtmf(0);
807 delay_manager_->ResetPacketIatCount(); 808 delay_manager_->ResetPacketIatCount();
808 } 809 }
809 return 0; 810 return 0;
810 } 811 }
811 812
812 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame) { 813 int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame, bool* muted) {
813 PacketList packet_list; 814 PacketList packet_list;
814 DtmfEvent dtmf_event; 815 DtmfEvent dtmf_event;
815 Operations operation; 816 Operations operation;
816 bool play_dtmf; 817 bool play_dtmf;
818 *muted = false;
817 tick_timer_->Increment(); 819 tick_timer_->Increment();
818 stats_.IncreaseCounter(output_size_samples_, fs_hz_); 820 stats_.IncreaseCounter(output_size_samples_, fs_hz_);
821
822 // Check for muted state.
823 if (enable_muted_state_ && expand_->Muted() && packet_buffer_->Empty()) {
824 RTC_DCHECK_EQ(last_mode_, kModeExpand);
825 playout_timestamp_ += static_cast<uint32_t>(output_size_samples_);
826 audio_frame->sample_rate_hz_ = fs_hz_;
827 audio_frame->samples_per_channel_ = output_size_samples_;
828 audio_frame->timestamp_ =
829 first_packet_
830 ? 0
831 : timestamp_scaler_->ToExternal(playout_timestamp_) -
832 static_cast<uint32_t>(audio_frame->samples_per_channel_);
833 audio_frame->num_channels_ = sync_buffer_->Channels();
834 *muted = true;
835 return 0;
836 }
837
819 int return_value = GetDecision(&operation, &packet_list, &dtmf_event, 838 int return_value = GetDecision(&operation, &packet_list, &dtmf_event,
820 &play_dtmf); 839 &play_dtmf);
821 if (return_value != 0) { 840 if (return_value != 0) {
822 last_mode_ = kModeError; 841 last_mode_ = kModeError;
823 return return_value; 842 return return_value;
824 } 843 }
825 844
826 AudioDecoder::SpeechType speech_type; 845 AudioDecoder::SpeechType speech_type;
827 int length = 0; 846 int length = 0;
828 int decode_return_value = Decode(&packet_list, &operation, 847 int decode_return_value = Decode(&packet_list, &operation,
(...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2144 } 2163 }
2145 } 2164 }
2146 2165
2147 void NetEqImpl::CreateDecisionLogic() { 2166 void NetEqImpl::CreateDecisionLogic() {
2148 decision_logic_.reset(DecisionLogic::Create( 2167 decision_logic_.reset(DecisionLogic::Create(
2149 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(), 2168 fs_hz_, output_size_samples_, playout_mode_, decoder_database_.get(),
2150 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(), 2169 *packet_buffer_.get(), delay_manager_.get(), buffer_level_filter_.get(),
2151 tick_timer_.get())); 2170 tick_timer_.get()));
2152 } 2171 }
2153 } // namespace webrtc 2172 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq_impl.h ('k') | webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698