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 11 matching lines...) Expand all Loading... | |
22 #include "webrtc/system_wrappers/include/logging.h" | 22 #include "webrtc/system_wrappers/include/logging.h" |
23 | 23 |
24 namespace webrtc { | 24 namespace webrtc { |
25 | 25 |
26 DecisionLogic* DecisionLogic::Create(int fs_hz, | 26 DecisionLogic* DecisionLogic::Create(int fs_hz, |
27 size_t output_size_samples, | 27 size_t output_size_samples, |
28 NetEqPlayoutMode playout_mode, | 28 NetEqPlayoutMode playout_mode, |
29 DecoderDatabase* decoder_database, | 29 DecoderDatabase* decoder_database, |
30 const PacketBuffer& packet_buffer, | 30 const PacketBuffer& packet_buffer, |
31 DelayManager* delay_manager, | 31 DelayManager* delay_manager, |
32 BufferLevelFilter* buffer_level_filter) { | 32 BufferLevelFilter* buffer_level_filter, |
33 const TickTimer* tick_timer) { | |
33 switch (playout_mode) { | 34 switch (playout_mode) { |
34 case kPlayoutOn: | 35 case kPlayoutOn: |
35 case kPlayoutStreaming: | 36 case kPlayoutStreaming: |
36 return new DecisionLogicNormal(fs_hz, | 37 return new DecisionLogicNormal( |
37 output_size_samples, | 38 fs_hz, output_size_samples, playout_mode, decoder_database, |
38 playout_mode, | 39 packet_buffer, delay_manager, buffer_level_filter, tick_timer); |
39 decoder_database, | |
40 packet_buffer, | |
41 delay_manager, | |
42 buffer_level_filter); | |
43 case kPlayoutFax: | 40 case kPlayoutFax: |
44 case kPlayoutOff: | 41 case kPlayoutOff: |
45 return new DecisionLogicFax(fs_hz, | 42 return new DecisionLogicFax( |
46 output_size_samples, | 43 fs_hz, output_size_samples, playout_mode, decoder_database, |
47 playout_mode, | 44 packet_buffer, delay_manager, buffer_level_filter, tick_timer); |
48 decoder_database, | |
49 packet_buffer, | |
50 delay_manager, | |
51 buffer_level_filter); | |
52 } | 45 } |
53 // This line cannot be reached, but must be here to avoid compiler errors. | 46 // This line cannot be reached, but must be here to avoid compiler errors. |
54 assert(false); | 47 assert(false); |
55 return NULL; | 48 return NULL; |
56 } | 49 } |
57 | 50 |
58 DecisionLogic::DecisionLogic(int fs_hz, | 51 DecisionLogic::DecisionLogic(int fs_hz, |
59 size_t output_size_samples, | 52 size_t output_size_samples, |
60 NetEqPlayoutMode playout_mode, | 53 NetEqPlayoutMode playout_mode, |
61 DecoderDatabase* decoder_database, | 54 DecoderDatabase* decoder_database, |
62 const PacketBuffer& packet_buffer, | 55 const PacketBuffer& packet_buffer, |
63 DelayManager* delay_manager, | 56 DelayManager* delay_manager, |
64 BufferLevelFilter* buffer_level_filter) | 57 BufferLevelFilter* buffer_level_filter, |
58 const TickTimer* tick_timer) | |
65 : decoder_database_(decoder_database), | 59 : decoder_database_(decoder_database), |
66 packet_buffer_(packet_buffer), | 60 packet_buffer_(packet_buffer), |
67 delay_manager_(delay_manager), | 61 delay_manager_(delay_manager), |
68 buffer_level_filter_(buffer_level_filter), | 62 buffer_level_filter_(buffer_level_filter), |
63 tick_timer_(tick_timer), | |
69 cng_state_(kCngOff), | 64 cng_state_(kCngOff), |
70 packet_length_samples_(0), | 65 packet_length_samples_(0), |
71 sample_memory_(0), | 66 sample_memory_(0), |
72 prev_time_scale_(false), | 67 prev_time_scale_(false), |
73 timescale_hold_off_(kMinTimescaleInterval), | 68 timescale_countdown_( |
69 tick_timer_->GetNewCountdown(kMinTimescaleInterval + 1)), | |
74 num_consecutive_expands_(0), | 70 num_consecutive_expands_(0), |
75 playout_mode_(playout_mode) { | 71 playout_mode_(playout_mode) { |
76 delay_manager_->set_streaming_mode(playout_mode_ == kPlayoutStreaming); | 72 delay_manager_->set_streaming_mode(playout_mode_ == kPlayoutStreaming); |
77 SetSampleRate(fs_hz, output_size_samples); | 73 SetSampleRate(fs_hz, output_size_samples); |
78 } | 74 } |
79 | 75 |
76 DecisionLogic::~DecisionLogic() = default; | |
77 | |
80 void DecisionLogic::Reset() { | 78 void DecisionLogic::Reset() { |
81 cng_state_ = kCngOff; | 79 cng_state_ = kCngOff; |
82 noise_fast_forward_ = 0; | 80 noise_fast_forward_ = 0; |
83 packet_length_samples_ = 0; | 81 packet_length_samples_ = 0; |
84 sample_memory_ = 0; | 82 sample_memory_ = 0; |
85 prev_time_scale_ = false; | 83 prev_time_scale_ = false; |
86 timescale_hold_off_ = 0; | 84 timescale_countdown_.reset(); |
87 num_consecutive_expands_ = 0; | 85 num_consecutive_expands_ = 0; |
88 } | 86 } |
89 | 87 |
90 void DecisionLogic::SoftReset() { | 88 void DecisionLogic::SoftReset() { |
91 packet_length_samples_ = 0; | 89 packet_length_samples_ = 0; |
92 sample_memory_ = 0; | 90 sample_memory_ = 0; |
93 prev_time_scale_ = false; | 91 prev_time_scale_ = false; |
94 timescale_hold_off_ = kMinTimescaleInterval; | 92 timescale_countdown_ = |
93 tick_timer_->GetNewCountdown(kMinTimescaleInterval + 1); | |
hlundin-webrtc
2016/05/03 19:09:10
The +1 here is for bit-exactness with the old code
tlegrand-webrtc
2016/05/10 05:55:33
Acknowledged.
| |
95 } | 94 } |
96 | 95 |
97 void DecisionLogic::SetSampleRate(int fs_hz, size_t output_size_samples) { | 96 void DecisionLogic::SetSampleRate(int fs_hz, size_t output_size_samples) { |
98 // TODO(hlundin): Change to an enumerator and skip assert. | 97 // TODO(hlundin): Change to an enumerator and skip assert. |
99 assert(fs_hz == 8000 || fs_hz == 16000 || fs_hz == 32000 || fs_hz == 48000); | 98 assert(fs_hz == 8000 || fs_hz == 16000 || fs_hz == 32000 || fs_hz == 48000); |
100 fs_mult_ = fs_hz / 8000; | 99 fs_mult_ = fs_hz / 8000; |
101 output_size_samples_ = output_size_samples; | 100 output_size_samples_ = output_size_samples; |
102 } | 101 } |
103 | 102 |
104 Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer, | 103 Operations DecisionLogic::GetDecision(const SyncBuffer& sync_buffer, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 delay_manager_->base_target_level()); | 157 delay_manager_->base_target_level()); |
159 | 158 |
160 size_t buffer_size_packets = 0; | 159 size_t buffer_size_packets = 0; |
161 if (packet_length_samples_ > 0) { | 160 if (packet_length_samples_ > 0) { |
162 // Calculate size in packets. | 161 // Calculate size in packets. |
163 buffer_size_packets = buffer_size_samples / packet_length_samples_; | 162 buffer_size_packets = buffer_size_samples / packet_length_samples_; |
164 } | 163 } |
165 int sample_memory_local = 0; | 164 int sample_memory_local = 0; |
166 if (prev_time_scale_) { | 165 if (prev_time_scale_) { |
167 sample_memory_local = sample_memory_; | 166 sample_memory_local = sample_memory_; |
168 timescale_hold_off_ = kMinTimescaleInterval; | 167 timescale_countdown_ = |
168 tick_timer_->GetNewCountdown(kMinTimescaleInterval); | |
169 } | 169 } |
170 buffer_level_filter_->Update(buffer_size_packets, sample_memory_local, | 170 buffer_level_filter_->Update(buffer_size_packets, sample_memory_local, |
171 packet_length_samples_); | 171 packet_length_samples_); |
172 prev_time_scale_ = false; | 172 prev_time_scale_ = false; |
173 } | 173 } |
174 | |
175 timescale_hold_off_ = std::max(timescale_hold_off_ - 1, 0); | |
176 } | 174 } |
177 | 175 |
178 } // namespace webrtc | 176 } // namespace webrtc |
OLD | NEW |