| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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_VIDEO_CODING_JITTER_ESTIMATOR_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_ |
| 12 #define WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_ |
| 13 | 13 |
| 14 #include "webrtc/base/rollingaccumulator.h" | 14 #include "webrtc/base/rollingaccumulator.h" |
| 15 #include "webrtc/modules/video_coding/rtt_filter.h" | 15 #include "webrtc/modules/video_coding/rtt_filter.h" |
| 16 #include "webrtc/typedefs.h" | 16 #include "webrtc/typedefs.h" |
| 17 | 17 |
| 18 namespace webrtc | 18 namespace webrtc { |
| 19 { | |
| 20 | 19 |
| 21 class Clock; | 20 class Clock; |
| 22 | 21 |
| 23 class VCMJitterEstimator | 22 class VCMJitterEstimator { |
| 24 { | 23 public: |
| 25 public: | 24 VCMJitterEstimator(const Clock* clock, |
| 26 VCMJitterEstimator(const Clock* clock, | 25 int32_t vcmId = 0, |
| 27 int32_t vcmId = 0, | 26 int32_t receiverId = 0); |
| 28 int32_t receiverId = 0); | 27 virtual ~VCMJitterEstimator(); |
| 29 virtual ~VCMJitterEstimator(); | 28 VCMJitterEstimator& operator=(const VCMJitterEstimator& rhs); |
| 30 VCMJitterEstimator& operator=(const VCMJitterEstimator& rhs); | |
| 31 | 29 |
| 32 // Resets the estimate to the initial state | 30 // Resets the estimate to the initial state |
| 33 void Reset(); | 31 void Reset(); |
| 34 void ResetNackCount(); | 32 void ResetNackCount(); |
| 35 | 33 |
| 36 // Updates the jitter estimate with the new data. | 34 // Updates the jitter estimate with the new data. |
| 37 // | 35 // |
| 38 // Input: | 36 // Input: |
| 39 // - frameDelay : Delay-delta calculated by UTILDelayEstimate
in milliseconds | 37 // - frameDelay : Delay-delta calculated by UTILDelayEstimate in |
| 40 // - frameSize : Frame size of the current frame. | 38 // milliseconds |
| 41 // - incompleteFrame : Flags if the frame is used to update the est
imate before it | 39 // - frameSize : Frame size of the current frame. |
| 42 // was complete. Default is false. | 40 // - incompleteFrame : Flags if the frame is used to update the |
| 43 void UpdateEstimate(int64_t frameDelayMS, | 41 // estimate before it |
| 44 uint32_t frameSizeBytes, | 42 // was complete. Default is false. |
| 45 bool incompleteFrame = false); | 43 void UpdateEstimate(int64_t frameDelayMS, |
| 44 uint32_t frameSizeBytes, |
| 45 bool incompleteFrame = false); |
| 46 | 46 |
| 47 // Returns the current jitter estimate in milliseconds and adds | 47 // Returns the current jitter estimate in milliseconds and adds |
| 48 // also adds an RTT dependent term in cases of retransmission. | 48 // also adds an RTT dependent term in cases of retransmission. |
| 49 // Input: | 49 // Input: |
| 50 // - rttMultiplier : RTT param multiplier (when applicable). | 50 // - rttMultiplier : RTT param multiplier (when applicable). |
| 51 // | 51 // |
| 52 // Return value : Jitter estimate in milliseconds | 52 // Return value : Jitter estimate in milliseconds |
| 53 int GetJitterEstimate(double rttMultiplier); | 53 int GetJitterEstimate(double rttMultiplier); |
| 54 | 54 |
| 55 // Updates the nack counter. | 55 // Updates the nack counter. |
| 56 void FrameNacked(); | 56 void FrameNacked(); |
| 57 | 57 |
| 58 // Updates the RTT filter. | 58 // Updates the RTT filter. |
| 59 // | 59 // |
| 60 // Input: | 60 // Input: |
| 61 // - rttMs : RTT in ms | 61 // - rttMs : RTT in ms |
| 62 void UpdateRtt(int64_t rttMs); | 62 void UpdateRtt(int64_t rttMs); |
| 63 | 63 |
| 64 void UpdateMaxFrameSize(uint32_t frameSizeBytes); | 64 void UpdateMaxFrameSize(uint32_t frameSizeBytes); |
| 65 | 65 |
| 66 // A constant describing the delay from the jitter buffer | 66 // A constant describing the delay from the jitter buffer |
| 67 // to the delay on the receiving side which is not accounted | 67 // to the delay on the receiving side which is not accounted |
| 68 // for by the jitter buffer nor the decoding delay estimate. | 68 // for by the jitter buffer nor the decoding delay estimate. |
| 69 static const uint32_t OPERATING_SYSTEM_JITTER = 10; | 69 static const uint32_t OPERATING_SYSTEM_JITTER = 10; |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 // These are protected for better testing possibilities | 72 // These are protected for better testing possibilities |
| 73 double _theta[2]; // Estimated line parameters (slope, offset) | 73 double _theta[2]; // Estimated line parameters (slope, offset) |
| 74 double _varNoise; // Variance of the time-deviation from the li
ne | 74 double _varNoise; // Variance of the time-deviation from the line |
| 75 | 75 |
| 76 virtual bool LowRateExperimentEnabled(); | 76 virtual bool LowRateExperimentEnabled(); |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 // Updates the Kalman filter for the line describing | 79 // Updates the Kalman filter for the line describing |
| 80 // the frame size dependent jitter. | 80 // the frame size dependent jitter. |
| 81 // | 81 // |
| 82 // Input: | 82 // Input: |
| 83 // - frameDelayMS : Delay-delta calculated by UTILDelayEstimate
in milliseconds | 83 // - frameDelayMS : Delay-delta calculated by UTILDelayEstimate in |
| 84 // - deltaFSBytes : Frame size delta, i.e. | 84 // milliseconds |
| 85 // : frame size at time T minus frame size at tim
e T-1 | 85 // - deltaFSBytes : Frame size delta, i.e. |
| 86 void KalmanEstimateChannel(int64_t frameDelayMS, int32_t deltaFSBytes); | 86 // : frame size at time T minus frame size at time |
| 87 // T-1 |
| 88 void KalmanEstimateChannel(int64_t frameDelayMS, int32_t deltaFSBytes); |
| 87 | 89 |
| 88 // Updates the random jitter estimate, i.e. the variance | 90 // Updates the random jitter estimate, i.e. the variance |
| 89 // of the time deviations from the line given by the Kalman filter. | 91 // of the time deviations from the line given by the Kalman filter. |
| 90 // | 92 // |
| 91 // Input: | 93 // Input: |
| 92 // - d_dT : The deviation from the kalman estimate | 94 // - d_dT : The deviation from the kalman estimate |
| 93 // - incompleteFrame : True if the frame used to update the estim
ate | 95 // - incompleteFrame : True if the frame used to update the |
| 94 // with was incomplete | 96 // estimate |
| 95 void EstimateRandomJitter(double d_dT, bool incompleteFrame); | 97 // with was incomplete |
| 98 void EstimateRandomJitter(double d_dT, bool incompleteFrame); |
| 96 | 99 |
| 97 double NoiseThreshold() const; | 100 double NoiseThreshold() const; |
| 98 | 101 |
| 99 // Calculates the current jitter estimate. | 102 // Calculates the current jitter estimate. |
| 100 // | 103 // |
| 101 // Return value : The current jitter estimate in millisecond
s | 104 // Return value : The current jitter estimate in milliseconds |
| 102 double CalculateEstimate(); | 105 double CalculateEstimate(); |
| 103 | 106 |
| 104 // Post process the calculated estimate | 107 // Post process the calculated estimate |
| 105 void PostProcessEstimate(); | 108 void PostProcessEstimate(); |
| 106 | 109 |
| 107 // Calculates the difference in delay between a sample and the | 110 // Calculates the difference in delay between a sample and the |
| 108 // expected delay estimated by the Kalman filter. | 111 // expected delay estimated by the Kalman filter. |
| 109 // | 112 // |
| 110 // Input: | 113 // Input: |
| 111 // - frameDelayMS : Delay-delta calculated by UTILDelayEstimate
in milliseconds | 114 // - frameDelayMS : Delay-delta calculated by UTILDelayEstimate in |
| 112 // - deltaFS : Frame size delta, i.e. frame size at time | 115 // milliseconds |
| 113 // T minus frame size at time T-1 | 116 // - deltaFS : Frame size delta, i.e. frame size at time |
| 114 // | 117 // T minus frame size at time T-1 |
| 115 // Return value : The difference in milliseconds | 118 // |
| 116 double DeviationFromExpectedDelay(int64_t frameDelayMS, | 119 // Return value : The difference in milliseconds |
| 117 int32_t deltaFSBytes) const; | 120 double DeviationFromExpectedDelay(int64_t frameDelayMS, |
| 121 int32_t deltaFSBytes) const; |
| 118 | 122 |
| 119 double GetFrameRate() const; | 123 double GetFrameRate() const; |
| 120 | 124 |
| 121 // Constants, filter parameters | 125 // Constants, filter parameters |
| 122 int32_t _vcmId; | 126 int32_t _vcmId; |
| 123 int32_t _receiverId; | 127 int32_t _receiverId; |
| 124 const double _phi; | 128 const double _phi; |
| 125 const double _psi; | 129 const double _psi; |
| 126 const uint32_t _alphaCountMax; | 130 const uint32_t _alphaCountMax; |
| 127 const double _thetaLow; | 131 const double _thetaLow; |
| 128 const uint32_t _nackLimit; | 132 const uint32_t _nackLimit; |
| 129 const int32_t _numStdDevDelayOutlier; | 133 const int32_t _numStdDevDelayOutlier; |
| 130 const int32_t _numStdDevFrameSizeOutlier; | 134 const int32_t _numStdDevFrameSizeOutlier; |
| 131 const double _noiseStdDevs; | 135 const double _noiseStdDevs; |
| 132 const double _noiseStdDevOffset; | 136 const double _noiseStdDevOffset; |
| 133 | 137 |
| 134 double _thetaCov[2][2]; // Estimate covariance | 138 double _thetaCov[2][2]; // Estimate covariance |
| 135 double _Qcov[2][2]; // Process noise covariance | 139 double _Qcov[2][2]; // Process noise covariance |
| 136 double _avgFrameSize; // Average frame size | 140 double _avgFrameSize; // Average frame size |
| 137 double _varFrameSize; // Frame size variance | 141 double _varFrameSize; // Frame size variance |
| 138 double _maxFrameSize; // Largest frame size received (desce
nding | 142 double _maxFrameSize; // Largest frame size received (descending |
| 139 // with a factor _psi) | 143 // with a factor _psi) |
| 140 uint32_t _fsSum; | 144 uint32_t _fsSum; |
| 141 uint32_t _fsCount; | 145 uint32_t _fsCount; |
| 142 | 146 |
| 143 int64_t _lastUpdateT; | 147 int64_t _lastUpdateT; |
| 144 double _prevEstimate; // The previously returned jitt
er estimate | 148 double _prevEstimate; // The previously returned jitter estimate |
| 145 uint32_t _prevFrameSize; // Frame size of the previous frame | 149 uint32_t _prevFrameSize; // Frame size of the previous frame |
| 146 double _avgNoise; // Average of the random jitter | 150 double _avgNoise; // Average of the random jitter |
| 147 uint32_t _alphaCount; | 151 uint32_t _alphaCount; |
| 148 double _filterJitterEstimate; // The filtered sum of jitter e
stimates | 152 double _filterJitterEstimate; // The filtered sum of jitter estimates |
| 149 | 153 |
| 150 uint32_t _startupCount; | 154 uint32_t _startupCount; |
| 151 | 155 |
| 152 int64_t _latestNackTimestamp; // Timestamp in ms when the latest na
ck was seen | 156 int64_t |
| 153 uint32_t _nackCount; // Keeps track of the number of nacks
received, | 157 _latestNackTimestamp; // Timestamp in ms when the latest nack was seen |
| 154 // but never goes above _nackLi
mit | 158 uint32_t _nackCount; // Keeps track of the number of nacks received, |
| 155 VCMRttFilter _rttFilter; | 159 // but never goes above _nackLimit |
| 160 VCMRttFilter _rttFilter; |
| 156 | 161 |
| 157 rtc::RollingAccumulator<uint64_t> fps_counter_; | 162 rtc::RollingAccumulator<uint64_t> fps_counter_; |
| 158 enum ExperimentFlag { kInit, kEnabled, kDisabled }; | 163 enum ExperimentFlag { kInit, kEnabled, kDisabled }; |
| 159 ExperimentFlag low_rate_experiment_; | 164 ExperimentFlag low_rate_experiment_; |
| 160 const Clock* clock_; | 165 const Clock* clock_; |
| 161 }; | 166 }; |
| 162 | 167 |
| 163 } // namespace webrtc | 168 } // namespace webrtc |
| 164 | 169 |
| 165 #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_ | 170 #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_ |
| OLD | NEW |