OLD | NEW |
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 |
11 #include "webrtc/modules/audio_coding/neteq/decision_logic_normal.h" | 11 #include "webrtc/modules/audio_coding/neteq/decision_logic_normal.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "webrtc/modules/audio_coding/neteq/buffer_level_filter.h" | 17 #include "webrtc/modules/audio_coding/neteq/buffer_level_filter.h" |
18 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" | 18 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
19 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" | 19 #include "webrtc/modules/audio_coding/neteq/delay_manager.h" |
20 #include "webrtc/modules/audio_coding/neteq/expand.h" | 20 #include "webrtc/modules/audio_coding/neteq/expand.h" |
21 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" | 21 #include "webrtc/modules/audio_coding/neteq/packet_buffer.h" |
22 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" | 22 #include "webrtc/modules/audio_coding/neteq/sync_buffer.h" |
23 #include "webrtc/modules/interface/module_common_types.h" | 23 #include "webrtc/modules/interface/module_common_types.h" |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 | 26 |
27 Operations DecisionLogicNormal::GetDecisionSpecialized( | 27 Operations DecisionLogicNormal::GetDecisionSpecialized( |
28 const SyncBuffer& sync_buffer, | 28 const SyncBuffer& sync_buffer, |
29 const Expand& expand, | 29 const Expand& expand, |
30 int decoder_frame_length, | 30 size_t decoder_frame_length, |
31 const RTPHeader* packet_header, | 31 const RTPHeader* packet_header, |
32 Modes prev_mode, | 32 Modes prev_mode, |
33 bool play_dtmf, | 33 bool play_dtmf, |
34 bool* reset_decoder) { | 34 bool* reset_decoder) { |
35 assert(playout_mode_ == kPlayoutOn || playout_mode_ == kPlayoutStreaming); | 35 assert(playout_mode_ == kPlayoutOn || playout_mode_ == kPlayoutStreaming); |
36 // Guard for errors, to avoid getting stuck in error mode. | 36 // Guard for errors, to avoid getting stuck in error mode. |
37 if (prev_mode == kModeError) { | 37 if (prev_mode == kModeError) { |
38 if (!packet_header) { | 38 if (!packet_header) { |
39 return kExpand; | 39 return kExpand; |
40 } else { | 40 } else { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (buffer_level_filter_->filtered_current_level() < low_limit) | 142 if (buffer_level_filter_->filtered_current_level() < low_limit) |
143 return kPreemptiveExpand; | 143 return kPreemptiveExpand; |
144 } | 144 } |
145 } | 145 } |
146 return kNormal; | 146 return kNormal; |
147 } | 147 } |
148 | 148 |
149 Operations DecisionLogicNormal::FuturePacketAvailable( | 149 Operations DecisionLogicNormal::FuturePacketAvailable( |
150 const SyncBuffer& sync_buffer, | 150 const SyncBuffer& sync_buffer, |
151 const Expand& expand, | 151 const Expand& expand, |
152 int decoder_frame_length, | 152 size_t decoder_frame_length, |
153 Modes prev_mode, | 153 Modes prev_mode, |
154 uint32_t target_timestamp, | 154 uint32_t target_timestamp, |
155 uint32_t available_timestamp, | 155 uint32_t available_timestamp, |
156 bool play_dtmf) { | 156 bool play_dtmf) { |
157 // Required packet is not available, but a future packet is. | 157 // Required packet is not available, but a future packet is. |
158 // Check if we should continue with an ongoing expand because the new packet | 158 // Check if we should continue with an ongoing expand because the new packet |
159 // is too far into the future. | 159 // is too far into the future. |
160 uint32_t timestamp_leap = available_timestamp - target_timestamp; | 160 uint32_t timestamp_leap = available_timestamp - target_timestamp; |
161 if ((prev_mode == kModeExpand) && | 161 if ((prev_mode == kModeExpand) && |
162 !ReinitAfterExpands(timestamp_leap) && | 162 !ReinitAfterExpands(timestamp_leap) && |
163 !MaxWaitForPacket() && | 163 !MaxWaitForPacket() && |
164 PacketTooEarly(timestamp_leap) && | 164 PacketTooEarly(timestamp_leap) && |
165 UnderTargetLevel()) { | 165 UnderTargetLevel()) { |
166 if (play_dtmf) { | 166 if (play_dtmf) { |
167 // Still have DTMF to play, so do not do expand. | 167 // Still have DTMF to play, so do not do expand. |
168 return kDtmf; | 168 return kDtmf; |
169 } else { | 169 } else { |
170 // Nothing to play. | 170 // Nothing to play. |
171 return kExpand; | 171 return kExpand; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 const int samples_left = static_cast<int>(sync_buffer.FutureLength() - | 175 const size_t samples_left = |
176 expand.overlap_length()); | 176 sync_buffer.FutureLength() - expand.overlap_length(); |
177 const int cur_size_samples = samples_left + | 177 const size_t cur_size_samples = samples_left + |
178 packet_buffer_.NumPacketsInBuffer() * decoder_frame_length; | 178 packet_buffer_.NumPacketsInBuffer() * decoder_frame_length; |
179 | 179 |
180 // If previous was comfort noise, then no merge is needed. | 180 // If previous was comfort noise, then no merge is needed. |
181 if (prev_mode == kModeRfc3389Cng || | 181 if (prev_mode == kModeRfc3389Cng || |
182 prev_mode == kModeCodecInternalCng) { | 182 prev_mode == kModeCodecInternalCng) { |
183 // Keep the same delay as before the CNG (or maximum 70 ms in buffer as | 183 // Keep the same delay as before the CNG (or maximum 70 ms in buffer as |
184 // safety precaution), but make sure that the number of samples in buffer | 184 // safety precaution), but make sure that the number of samples in buffer |
185 // is no higher than 4 times the optimal level. (Note that TargetLevel() | 185 // is no higher than 4 times the optimal level. (Note that TargetLevel() |
186 // is in Q8.) | 186 // is in Q8.) |
187 if (static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) >= | 187 if (static_cast<uint32_t>(generated_noise_samples_ + target_timestamp) >= |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const { | 228 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const { |
229 return timestamp_leap > | 229 return timestamp_leap > |
230 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); | 230 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); |
231 } | 231 } |
232 | 232 |
233 bool DecisionLogicNormal::MaxWaitForPacket() const { | 233 bool DecisionLogicNormal::MaxWaitForPacket() const { |
234 return num_consecutive_expands_ >= kMaxWaitForPacket; | 234 return num_consecutive_expands_ >= kMaxWaitForPacket; |
235 } | 235 } |
236 | 236 |
237 } // namespace webrtc | 237 } // namespace webrtc |
OLD | NEW |