PageRenderTime 76ms CodeModel.GetById 19ms RepoModel.GetById 7ms app.codeStats 0ms

/CSipSimple/jni/webrtc/sources/modules/video_coding/main/source/jitter_estimator.h

https://bitbucket.org/bohlooli/csipsimple
C Header | 154 lines | 65 code | 27 blank | 62 comment | 0 complexity | dc7f3c78a94c43d597291daed5130045 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-3.0, GPL-3.0, GPL-2.0
  1. /*
  2. * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_
  11. #define WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_
  12. #include "typedefs.h"
  13. #include "rtt_filter.h"
  14. namespace webrtc
  15. {
  16. class VCMJitterEstimator
  17. {
  18. public:
  19. VCMJitterEstimator(WebRtc_Word32 vcmId = 0, WebRtc_Word32 receiverId = 0);
  20. VCMJitterEstimator& operator=(const VCMJitterEstimator& rhs);
  21. // Resets the estimate to the initial state
  22. void Reset();
  23. void ResetNackCount();
  24. // Updates the jitter estimate with the new data.
  25. //
  26. // Input:
  27. // - frameDelay : Delay-delta calculated by UTILDelayEstimate in milliseconds
  28. // - frameSize : Frame size of the current frame.
  29. // - incompleteFrame : Flags if the frame is used to update the estimate before it
  30. // was complete. Default is false.
  31. void UpdateEstimate(WebRtc_Word64 frameDelayMS,
  32. WebRtc_UWord32 frameSizeBytes,
  33. bool incompleteFrame = false);
  34. // Returns the current jitter estimate in milliseconds and adds
  35. // also adds an RTT dependent term in cases of retransmission.
  36. // Input:
  37. // - rttMultiplier : RTT param multiplier (when applicable).
  38. //
  39. // Return value : Jitter estimate in milliseconds
  40. double GetJitterEstimate(double rttMultiplier);
  41. // Updates the nack counter.
  42. void FrameNacked();
  43. // Updates the RTT filter.
  44. //
  45. // Input:
  46. // - rttMs : RTT in ms
  47. void UpdateRtt(WebRtc_UWord32 rttMs);
  48. void UpdateMaxFrameSize(WebRtc_UWord32 frameSizeBytes);
  49. // A constant describing the delay from the jitter buffer
  50. // to the delay on the receiving side which is not accounted
  51. // for by the jitter buffer nor the decoding delay estimate.
  52. static const WebRtc_UWord32 OPERATING_SYSTEM_JITTER = 10;
  53. protected:
  54. // These are protected for better testing possibilities
  55. double _theta[2]; // Estimated line parameters (slope, offset)
  56. double _varNoise; // Variance of the time-deviation from the line
  57. private:
  58. // Updates the Kalman filter for the line describing
  59. // the frame size dependent jitter.
  60. //
  61. // Input:
  62. // - frameDelayMS : Delay-delta calculated by UTILDelayEstimate in milliseconds
  63. // - deltaFSBytes : Frame size delta, i.e.
  64. // : frame size at time T minus frame size at time T-1
  65. void KalmanEstimateChannel(WebRtc_Word64 frameDelayMS, WebRtc_Word32 deltaFSBytes);
  66. // Updates the random jitter estimate, i.e. the variance
  67. // of the time deviations from the line given by the Kalman filter.
  68. //
  69. // Input:
  70. // - d_dT : The deviation from the kalman estimate
  71. // - incompleteFrame : True if the frame used to update the estimate
  72. // with was incomplete
  73. void EstimateRandomJitter(double d_dT, bool incompleteFrame);
  74. double NoiseThreshold() const;
  75. // Calculates the current jitter estimate.
  76. //
  77. // Return value : The current jitter estimate in milliseconds
  78. double CalculateEstimate();
  79. // Post process the calculated estimate
  80. void PostProcessEstimate();
  81. // Calculates the difference in delay between a sample and the
  82. // expected delay estimated by the Kalman filter.
  83. //
  84. // Input:
  85. // - frameDelayMS : Delay-delta calculated by UTILDelayEstimate in milliseconds
  86. // - deltaFS : Frame size delta, i.e. frame size at time
  87. // T minus frame size at time T-1
  88. //
  89. // Return value : The difference in milliseconds
  90. double DeviationFromExpectedDelay(WebRtc_Word64 frameDelayMS,
  91. WebRtc_Word32 deltaFSBytes) const;
  92. // Constants, filter parameters
  93. WebRtc_Word32 _vcmId;
  94. WebRtc_Word32 _receiverId;
  95. const double _phi;
  96. const double _psi;
  97. const WebRtc_UWord32 _alphaCountMax;
  98. const double _thetaLow;
  99. const WebRtc_UWord32 _nackLimit;
  100. const WebRtc_Word32 _numStdDevDelayOutlier;
  101. const WebRtc_Word32 _numStdDevFrameSizeOutlier;
  102. const double _noiseStdDevs;
  103. const double _noiseStdDevOffset;
  104. double _thetaCov[2][2]; // Estimate covariance
  105. double _Qcov[2][2]; // Process noise covariance
  106. double _avgFrameSize; // Average frame size
  107. double _varFrameSize; // Frame size variance
  108. double _maxFrameSize; // Largest frame size received (descending
  109. // with a factor _psi)
  110. WebRtc_UWord32 _fsSum;
  111. WebRtc_UWord32 _fsCount;
  112. WebRtc_Word64 _lastUpdateT;
  113. double _prevEstimate; // The previously returned jitter estimate
  114. WebRtc_UWord32 _prevFrameSize; // Frame size of the previous frame
  115. double _avgNoise; // Average of the random jitter
  116. WebRtc_UWord32 _alphaCount;
  117. double _filterJitterEstimate; // The filtered sum of jitter estimates
  118. WebRtc_UWord32 _startupCount;
  119. WebRtc_Word64 _latestNackTimestamp; // Timestamp in ms when the latest nack was seen
  120. WebRtc_UWord32 _nackCount; // Keeps track of the number of nacks received,
  121. // but never goes above _nackLimit
  122. VCMRttFilter _rttFilter;
  123. enum { kStartupDelaySamples = 30 };
  124. enum { kFsAccuStartupSamples = 5 };
  125. };
  126. } // namespace webrtc
  127. #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_ESTIMATOR_H_