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

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

Issue 1914303004: NetEq: Move counting of generated CNG samples from DecisionLogic (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@delay-mgr-tick-timer
Patch Set: Renaming parameter to generated_noise_samples 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 NetEqPlayoutMode playout_mode, 60 NetEqPlayoutMode playout_mode,
61 DecoderDatabase* decoder_database, 61 DecoderDatabase* decoder_database,
62 const PacketBuffer& packet_buffer, 62 const PacketBuffer& packet_buffer,
63 DelayManager* delay_manager, 63 DelayManager* delay_manager,
64 BufferLevelFilter* buffer_level_filter) 64 BufferLevelFilter* buffer_level_filter)
65 : decoder_database_(decoder_database), 65 : decoder_database_(decoder_database),
66 packet_buffer_(packet_buffer), 66 packet_buffer_(packet_buffer),
67 delay_manager_(delay_manager), 67 delay_manager_(delay_manager),
68 buffer_level_filter_(buffer_level_filter), 68 buffer_level_filter_(buffer_level_filter),
69 cng_state_(kCngOff), 69 cng_state_(kCngOff),
70 generated_noise_samples_(0),
71 packet_length_samples_(0), 70 packet_length_samples_(0),
72 sample_memory_(0), 71 sample_memory_(0),
73 prev_time_scale_(false), 72 prev_time_scale_(false),
74 timescale_hold_off_(kMinTimescaleInterval), 73 timescale_hold_off_(kMinTimescaleInterval),
75 num_consecutive_expands_(0), 74 num_consecutive_expands_(0),
76 playout_mode_(playout_mode) { 75 playout_mode_(playout_mode) {
77 delay_manager_->set_streaming_mode(playout_mode_ == kPlayoutStreaming); 76 delay_manager_->set_streaming_mode(playout_mode_ == kPlayoutStreaming);
78 SetSampleRate(fs_hz, output_size_samples); 77 SetSampleRate(fs_hz, output_size_samples);
79 } 78 }
80 79
81 void DecisionLogic::Reset() { 80 void DecisionLogic::Reset() {
82 cng_state_ = kCngOff; 81 cng_state_ = kCngOff;
83 generated_noise_samples_ = 0; 82 noise_fast_forward_ = 0;
84 packet_length_samples_ = 0; 83 packet_length_samples_ = 0;
85 sample_memory_ = 0; 84 sample_memory_ = 0;
86 prev_time_scale_ = false; 85 prev_time_scale_ = false;
87 timescale_hold_off_ = 0; 86 timescale_hold_off_ = 0;
88 num_consecutive_expands_ = 0; 87 num_consecutive_expands_ = 0;
89 } 88 }
90 89
91 void DecisionLogic::SoftReset() { 90 void DecisionLogic::SoftReset() {
92 packet_length_samples_ = 0; 91 packet_length_samples_ = 0;
93 sample_memory_ = 0; 92 sample_memory_ = 0;
94 prev_time_scale_ = false; 93 prev_time_scale_ = false;
95 timescale_hold_off_ = kMinTimescaleInterval; 94 timescale_hold_off_ = kMinTimescaleInterval;
96 } 95 }
97 96
98 void DecisionLogic::SetSampleRate(int fs_hz, size_t output_size_samples) { 97 void DecisionLogic::SetSampleRate(int fs_hz, size_t output_size_samples) {
99 // TODO(hlundin): Change to an enumerator and skip assert. 98 // TODO(hlundin): Change to an enumerator and skip assert.
100 assert(fs_hz == 8000 || fs_hz == 16000 || fs_hz == 32000 || fs_hz == 48000); 99 assert(fs_hz == 8000 || fs_hz == 16000 || fs_hz == 32000 || fs_hz == 48000);
101 fs_mult_ = fs_hz / 8000; 100 fs_mult_ = fs_hz / 8000;
102 output_size_samples_ = output_size_samples; 101 output_size_samples_ = output_size_samples;
103 } 102 }
104 103
105 Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer, 104 Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer,
106 const Expand& expand, 105 const Expand& expand,
107 size_t decoder_frame_length, 106 size_t decoder_frame_length,
108 const RTPHeader* packet_header, 107 const RTPHeader* packet_header,
109 Modes prev_mode, 108 Modes prev_mode,
110 bool play_dtmf, bool* reset_decoder) { 109 bool play_dtmf,
110 size_t generated_noise_samples,
111 bool* reset_decoder) {
111 if (prev_mode == kModeRfc3389Cng || 112 if (prev_mode == kModeRfc3389Cng ||
112 prev_mode == kModeCodecInternalCng || 113 prev_mode == kModeCodecInternalCng ||
113 prev_mode == kModeExpand) { 114 prev_mode == kModeExpand) {
114 // If last mode was CNG (or Expand, since this could be covering up for 115 // If last mode was CNG (or Expand, since this could be covering up for
115 // a lost CNG packet), increase the |generated_noise_samples_| counter. 116 // a lost CNG packet), remember that CNG is on. This is needed if comfort
116 generated_noise_samples_ += output_size_samples_; 117 // noise is interrupted by DTMF.
117 // Remember that CNG is on. This is needed if comfort noise is interrupted
118 // by DTMF.
119 if (prev_mode == kModeRfc3389Cng) { 118 if (prev_mode == kModeRfc3389Cng) {
120 cng_state_ = kCngRfc3389On; 119 cng_state_ = kCngRfc3389On;
121 } else if (prev_mode == kModeCodecInternalCng) { 120 } else if (prev_mode == kModeCodecInternalCng) {
122 cng_state_ = kCngInternalOn; 121 cng_state_ = kCngInternalOn;
123 } 122 }
124 } 123 }
125 124
126 const size_t samples_left = 125 const size_t samples_left =
127 sync_buffer.FutureLength() - expand.overlap_length(); 126 sync_buffer.FutureLength() - expand.overlap_length();
128 const size_t cur_size_samples = 127 const size_t cur_size_samples =
129 samples_left + packet_buffer_.NumSamplesInBuffer(decoder_database_, 128 samples_left + packet_buffer_.NumSamplesInBuffer(decoder_database_,
130 decoder_frame_length); 129 decoder_frame_length);
131 130
132 prev_time_scale_ = prev_time_scale_ && 131 prev_time_scale_ = prev_time_scale_ &&
133 (prev_mode == kModeAccelerateSuccess || 132 (prev_mode == kModeAccelerateSuccess ||
134 prev_mode == kModeAccelerateLowEnergy || 133 prev_mode == kModeAccelerateLowEnergy ||
135 prev_mode == kModePreemptiveExpandSuccess || 134 prev_mode == kModePreemptiveExpandSuccess ||
136 prev_mode == kModePreemptiveExpandLowEnergy); 135 prev_mode == kModePreemptiveExpandLowEnergy);
137 136
138 FilterBufferLevel(cur_size_samples, prev_mode); 137 FilterBufferLevel(cur_size_samples, prev_mode);
139 138
140 return GetDecisionSpecialized(sync_buffer, expand, decoder_frame_length, 139 return GetDecisionSpecialized(sync_buffer, expand, decoder_frame_length,
141 packet_header, prev_mode, play_dtmf, 140 packet_header, prev_mode, play_dtmf,
142 reset_decoder); 141 reset_decoder, generated_noise_samples);
143 } 142 }
144 143
145 void DecisionLogic::ExpandDecision(Operations operation) { 144 void DecisionLogic::ExpandDecision(Operations operation) {
146 if (operation == kExpand) { 145 if (operation == kExpand) {
147 num_consecutive_expands_++; 146 num_consecutive_expands_++;
148 } else { 147 } else {
149 num_consecutive_expands_ = 0; 148 num_consecutive_expands_ = 0;
150 } 149 }
151 } 150 }
152 151
(...skipping 17 matching lines...) Expand all
170 } 169 }
171 buffer_level_filter_->Update(buffer_size_packets, sample_memory_local, 170 buffer_level_filter_->Update(buffer_size_packets, sample_memory_local,
172 packet_length_samples_); 171 packet_length_samples_);
173 prev_time_scale_ = false; 172 prev_time_scale_ = false;
174 } 173 }
175 174
176 timescale_hold_off_ = std::max(timescale_hold_off_ - 1, 0); 175 timescale_hold_off_ = std::max(timescale_hold_off_ - 1, 0);
177 } 176 }
178 177
179 } // namespace webrtc 178 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/decision_logic.h ('k') | webrtc/modules/audio_coding/neteq/decision_logic_fax.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698