| OLD | NEW |
| 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 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_ |
| 13 | 13 |
| 14 #include <string.h> // Provide access to size_t. | 14 #include <string.h> // Provide access to size_t. |
| 15 | 15 |
| 16 #include <memory> |
| 16 #include <vector> | 17 #include <vector> |
| 17 | 18 |
| 18 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" | 20 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" |
| 21 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
| 20 #include "webrtc/typedefs.h" | 22 #include "webrtc/typedefs.h" |
| 21 | 23 |
| 22 namespace webrtc { | 24 namespace webrtc { |
| 23 | 25 |
| 24 // Forward declaration. | 26 // Forward declaration. |
| 25 class DelayPeakDetector; | 27 class DelayPeakDetector; |
| 26 | 28 |
| 27 class DelayManager { | 29 class DelayManager { |
| 28 public: | 30 public: |
| 29 typedef std::vector<int> IATVector; | 31 typedef std::vector<int> IATVector; |
| 30 | 32 |
| 31 // Create a DelayManager object. Notify the delay manager that the packet | 33 // Create a DelayManager object. Notify the delay manager that the packet |
| 32 // buffer can hold no more than |max_packets_in_buffer| packets (i.e., this | 34 // buffer can hold no more than |max_packets_in_buffer| packets (i.e., this |
| 33 // is the number of packet slots in the buffer). Supply a PeakDetector | 35 // is the number of packet slots in the buffer). Supply a PeakDetector |
| 34 // object to the DelayManager. | 36 // object to the DelayManager. |
| 35 DelayManager(size_t max_packets_in_buffer, DelayPeakDetector* peak_detector); | 37 DelayManager(size_t max_packets_in_buffer, |
| 38 DelayPeakDetector* peak_detector, |
| 39 const TickTimer* tick_timer); |
| 36 | 40 |
| 37 virtual ~DelayManager(); | 41 virtual ~DelayManager(); |
| 38 | 42 |
| 39 // Read the inter-arrival time histogram. Mainly for testing purposes. | 43 // Read the inter-arrival time histogram. Mainly for testing purposes. |
| 40 virtual const IATVector& iat_vector() const; | 44 virtual const IATVector& iat_vector() const; |
| 41 | 45 |
| 42 // Updates the delay manager with a new incoming packet, with | 46 // Updates the delay manager with a new incoming packet, with |
| 43 // |sequence_number| and |timestamp| from the RTP header. This updates the | 47 // |sequence_number| and |timestamp| from the RTP header. This updates the |
| 44 // inter-arrival time histogram and other statistics, as well as the | 48 // inter-arrival time histogram and other statistics, as well as the |
| 45 // associated DelayPeakDetector. A new target buffer level is calculated. | 49 // associated DelayPeakDetector. A new target buffer level is calculated. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 68 // the nominal frame time, the return value is zero. A positive value | 72 // the nominal frame time, the return value is zero. A positive value |
| 69 // corresponds to packet spacing being too large, while a negative value means | 73 // corresponds to packet spacing being too large, while a negative value means |
| 70 // that the packets arrive with less spacing than expected. | 74 // that the packets arrive with less spacing than expected. |
| 71 virtual int AverageIAT() const; | 75 virtual int AverageIAT() const; |
| 72 | 76 |
| 73 // Returns true if peak-mode is active. That is, delay peaks were observed | 77 // Returns true if peak-mode is active. That is, delay peaks were observed |
| 74 // recently. This method simply asks for the same information from the | 78 // recently. This method simply asks for the same information from the |
| 75 // DelayPeakDetector object. | 79 // DelayPeakDetector object. |
| 76 virtual bool PeakFound() const; | 80 virtual bool PeakFound() const; |
| 77 | 81 |
| 78 // Notifies the counters in DelayManager and DelayPeakDetector that | |
| 79 // |elapsed_time_ms| have elapsed. | |
| 80 virtual void UpdateCounters(int elapsed_time_ms); | |
| 81 | |
| 82 // Reset the inter-arrival time counter to 0. | 82 // Reset the inter-arrival time counter to 0. |
| 83 virtual void ResetPacketIatCount(); | 83 virtual void ResetPacketIatCount(); |
| 84 | 84 |
| 85 // Writes the lower and higher limits which the buffer level should stay | 85 // Writes the lower and higher limits which the buffer level should stay |
| 86 // within to the corresponding pointers. The values are in (fractions of) | 86 // within to the corresponding pointers. The values are in (fractions of) |
| 87 // packets in Q8. | 87 // packets in Q8. |
| 88 virtual void BufferLimits(int* lower_limit, int* higher_limit) const; | 88 virtual void BufferLimits(int* lower_limit, int* higher_limit) const; |
| 89 | 89 |
| 90 // Gets the target buffer level, in (fractions of) packets in Q8. This value | 90 // Gets the target buffer level, in (fractions of) packets in Q8. This value |
| 91 // includes any extra delay set through the set_extra_delay_ms() method. | 91 // includes any extra delay set through the set_extra_delay_ms() method. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // Makes sure that |target_level_| is not too large, taking | 129 // Makes sure that |target_level_| is not too large, taking |
| 130 // |max_packets_in_buffer_| and |extra_delay_ms_| into account. This method is | 130 // |max_packets_in_buffer_| and |extra_delay_ms_| into account. This method is |
| 131 // called by Update(). | 131 // called by Update(). |
| 132 void LimitTargetLevel(); | 132 void LimitTargetLevel(); |
| 133 | 133 |
| 134 bool first_packet_received_; | 134 bool first_packet_received_; |
| 135 const size_t max_packets_in_buffer_; // Capacity of the packet buffer. | 135 const size_t max_packets_in_buffer_; // Capacity of the packet buffer. |
| 136 IATVector iat_vector_; // Histogram of inter-arrival times. | 136 IATVector iat_vector_; // Histogram of inter-arrival times. |
| 137 int iat_factor_; // Forgetting factor for updating the IAT histogram (Q15). | 137 int iat_factor_; // Forgetting factor for updating the IAT histogram (Q15). |
| 138 int packet_iat_count_ms_; // Milliseconds elapsed since last packet. | 138 const TickTimer* tick_timer_; |
| 139 // Time elapsed since last packet. |
| 140 std::unique_ptr<TickTimer::Stopwatch> packet_iat_stopwatch_; |
| 139 int base_target_level_; // Currently preferred buffer level before peak | 141 int base_target_level_; // Currently preferred buffer level before peak |
| 140 // detection and streaming mode (Q0). | 142 // detection and streaming mode (Q0). |
| 141 // TODO(turajs) change the comment according to the implementation of | 143 // TODO(turajs) change the comment according to the implementation of |
| 142 // minimum-delay. | 144 // minimum-delay. |
| 143 int target_level_; // Currently preferred buffer level in (fractions) | 145 int target_level_; // Currently preferred buffer level in (fractions) |
| 144 // of packets (Q8), before adding any extra delay. | 146 // of packets (Q8), before adding any extra delay. |
| 145 int packet_len_ms_; // Length of audio in each incoming packet [ms]. | 147 int packet_len_ms_; // Length of audio in each incoming packet [ms]. |
| 146 bool streaming_mode_; | 148 bool streaming_mode_; |
| 147 uint16_t last_seq_no_; // Sequence number for last received packet. | 149 uint16_t last_seq_no_; // Sequence number for last received packet. |
| 148 uint32_t last_timestamp_; // Timestamp for the last received packet. | 150 uint32_t last_timestamp_; // Timestamp for the last received packet. |
| 149 int minimum_delay_ms_; // Externally set minimum delay. | 151 int minimum_delay_ms_; // Externally set minimum delay. |
| 150 int least_required_delay_ms_; // Smallest preferred buffer level (same unit | 152 int least_required_delay_ms_; // Smallest preferred buffer level (same unit |
| 151 // as |target_level_|), before applying | 153 // as |target_level_|), before applying |
| 152 // |minimum_delay_ms_| and/or |maximum_delay_ms_|. | 154 // |minimum_delay_ms_| and/or |maximum_delay_ms_|. |
| 153 int maximum_delay_ms_; // Externally set maximum allowed delay. | 155 int maximum_delay_ms_; // Externally set maximum allowed delay. |
| 154 int iat_cumulative_sum_; // Cumulative sum of delta inter-arrival times. | 156 int iat_cumulative_sum_; // Cumulative sum of delta inter-arrival times. |
| 155 int max_iat_cumulative_sum_; // Max of |iat_cumulative_sum_|. | 157 int max_iat_cumulative_sum_; // Max of |iat_cumulative_sum_|. |
| 156 int max_timer_ms_; // Time elapsed since maximum was observed. | 158 // Time elapsed since maximum was observed. |
| 159 std::unique_ptr<TickTimer::Stopwatch> max_iat_stopwatch_; |
| 157 DelayPeakDetector& peak_detector_; | 160 DelayPeakDetector& peak_detector_; |
| 158 int last_pack_cng_or_dtmf_; | 161 int last_pack_cng_or_dtmf_; |
| 159 | 162 |
| 160 RTC_DISALLOW_COPY_AND_ASSIGN(DelayManager); | 163 RTC_DISALLOW_COPY_AND_ASSIGN(DelayManager); |
| 161 }; | 164 }; |
| 162 | 165 |
| 163 } // namespace webrtc | 166 } // namespace webrtc |
| 164 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_ | 167 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_MANAGER_H_ |
| OLD | NEW |