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 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Operations DecisionLogicNormal::CngOperation(Modes prev_mode, | 90 Operations DecisionLogicNormal::CngOperation(Modes prev_mode, |
91 uint32_t target_timestamp, | 91 uint32_t target_timestamp, |
92 uint32_t available_timestamp, | 92 uint32_t available_timestamp, |
93 size_t generated_noise_samples) { | 93 size_t generated_noise_samples) { |
94 // Signed difference between target and available timestamp. | 94 // Signed difference between target and available timestamp. |
95 int32_t timestamp_diff = static_cast<int32_t>( | 95 int32_t timestamp_diff = static_cast<int32_t>( |
96 static_cast<uint32_t>(generated_noise_samples + target_timestamp) - | 96 static_cast<uint32_t>(generated_noise_samples + target_timestamp) - |
97 available_timestamp); | 97 available_timestamp); |
98 int32_t optimal_level_samp = static_cast<int32_t>( | 98 int32_t optimal_level_samp = static_cast<int32_t>( |
99 (delay_manager_->TargetLevel() * packet_length_samples_) >> 8); | 99 (delay_manager_->TargetLevel() * packet_length_samples_) >> 8); |
100 int32_t excess_waiting_time_samp = -timestamp_diff - optimal_level_samp; | 100 const int64_t excess_waiting_time_samp = |
| 101 -static_cast<int64_t>(timestamp_diff) - optimal_level_samp; |
101 | 102 |
102 if (excess_waiting_time_samp > optimal_level_samp / 2) { | 103 if (excess_waiting_time_samp > optimal_level_samp / 2) { |
103 // The waiting time for this packet will be longer than 1.5 | 104 // The waiting time for this packet will be longer than 1.5 |
104 // times the wanted buffer delay. Apply fast-forward to cut the | 105 // times the wanted buffer delay. Apply fast-forward to cut the |
105 // waiting time down to the optimal. | 106 // waiting time down to the optimal. |
106 noise_fast_forward_ += excess_waiting_time_samp; | 107 noise_fast_forward_ = rtc::dchecked_cast<size_t>(noise_fast_forward_ + |
107 timestamp_diff += excess_waiting_time_samp; | 108 excess_waiting_time_samp); |
| 109 timestamp_diff = |
| 110 rtc::saturated_cast<int32_t>(timestamp_diff + excess_waiting_time_samp); |
108 } | 111 } |
109 | 112 |
110 if (timestamp_diff < 0 && prev_mode == kModeRfc3389Cng) { | 113 if (timestamp_diff < 0 && prev_mode == kModeRfc3389Cng) { |
111 // Not time to play this packet yet. Wait another round before using this | 114 // Not time to play this packet yet. Wait another round before using this |
112 // packet. Keep on playing CNG from previous CNG parameters. | 115 // packet. Keep on playing CNG from previous CNG parameters. |
113 return kRfc3389CngNoPacket; | 116 return kRfc3389CngNoPacket; |
114 } else { | 117 } else { |
115 // Otherwise, go for the CNG packet now. | 118 // Otherwise, go for the CNG packet now. |
116 noise_fast_forward_ = 0; | 119 noise_fast_forward_ = 0; |
117 return kRfc3389Cng; | 120 return kRfc3389Cng; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const { | 233 bool DecisionLogicNormal::PacketTooEarly(uint32_t timestamp_leap) const { |
231 return timestamp_leap > | 234 return timestamp_leap > |
232 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); | 235 static_cast<uint32_t>(output_size_samples_ * num_consecutive_expands_); |
233 } | 236 } |
234 | 237 |
235 bool DecisionLogicNormal::MaxWaitForPacket() const { | 238 bool DecisionLogicNormal::MaxWaitForPacket() const { |
236 return num_consecutive_expands_ >= kMaxWaitForPacket; | 239 return num_consecutive_expands_ >= kMaxWaitForPacket; |
237 } | 240 } |
238 | 241 |
239 } // namespace webrtc | 242 } // namespace webrtc |
OLD | NEW |