|  | /* | 
|  | *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 
|  | * | 
|  | *  Use of this source code is governed by a BSD-style license | 
|  | *  that can be found in the LICENSE file in the root of the source | 
|  | *  tree. An additional intellectual property rights grant can be found | 
|  | *  in the file PATENTS.  All contributing project authors may | 
|  | *  be found in the AUTHORS file in the root of the source tree. | 
|  | */ | 
|  |  | 
|  | #ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_JITTER_ESTIMATE_TEST_H_ | 
|  | #define WEBRTC_MODULES_VIDEO_CODING_TEST_JITTER_ESTIMATE_TEST_H_ | 
|  |  | 
|  | #include "webrtc/typedefs.h" | 
|  | #include "jitter_buffer.h" | 
|  | #include "jitter_estimator.h" | 
|  | #include <stdlib.h> | 
|  | #include <math.h> | 
|  |  | 
|  | double const pi = 4 * atan(1.0); | 
|  |  | 
|  | class GaussDist | 
|  | { | 
|  | public: | 
|  | GaussDist(double m, double v): _mu(m), _sigma(sqrt(v)) {} | 
|  |  | 
|  | double RandValue() // returns a single normally distributed number | 
|  | { | 
|  | double r1 = (rand() + 1.0) / | 
|  | (RAND_MAX + 1.0);  // gives equal distribution in (0, 1] | 
|  | double r2 = (rand() + 1.0) / (RAND_MAX + 1.0); | 
|  | return _mu + _sigma * sqrt(-2 * log(r1)) * cos(2 * pi * r2); | 
|  | } | 
|  |  | 
|  | double GetAverage() | 
|  | { | 
|  | return _mu; | 
|  | } | 
|  |  | 
|  | double GetVariance() | 
|  | { | 
|  | return _sigma*_sigma; | 
|  | } | 
|  |  | 
|  | void SetParams(double m, double v) | 
|  | { | 
|  | _mu = m; | 
|  | _sigma = sqrt(v); | 
|  | } | 
|  |  | 
|  | private: | 
|  | double _mu, _sigma; | 
|  | }; | 
|  |  | 
|  | class JitterEstimateTestWrapper : public webrtc::VCMJitterEstimator | 
|  | { | 
|  | public: | 
|  | JitterEstimateTestWrapper() : VCMJitterEstimator() {} | 
|  | double GetTheta() { return _theta[0]; } | 
|  | double GetVarNoise() { return _varNoise; } | 
|  | }; | 
|  |  | 
|  | class FrameSample | 
|  | { | 
|  | public: | 
|  | FrameSample() {FrameSample(0, 0, 0, false, false);} | 
|  | FrameSample(unsigned int ts, int64_t wallClk, unsigned int fs, bool _keyFrame, bool _resent): | 
|  | timestamp90Khz(ts), wallClockMs(wallClk), frameSize(fs), keyFrame(_keyFrame), resent(_resent) {} | 
|  |  | 
|  | unsigned int timestamp90Khz; | 
|  | int64_t wallClockMs; | 
|  | unsigned int frameSize; | 
|  | bool keyFrame; | 
|  | bool resent; | 
|  | }; | 
|  |  | 
|  | class JitterEstimateTest | 
|  | { | 
|  | public: | 
|  | JitterEstimateTest(unsigned int frameRate); | 
|  | FrameSample GenerateFrameSample(); | 
|  | void SetCapacity(unsigned int c); | 
|  | void SetRate(unsigned int r); | 
|  | void SetJitter(double m, double v); | 
|  | void SetFrameSizeStats(double m, double v); | 
|  | void SetKeyFrameRate(int rate); | 
|  | void SetLossRate(double rate); | 
|  |  | 
|  | private: | 
|  | double RandUniform() { return (rand() + 1.0)/(RAND_MAX + 1.0); } | 
|  | unsigned int _frameRate; | 
|  | unsigned int _capacity; | 
|  | unsigned int _rate; | 
|  | GaussDist _jitter; | 
|  | //GaussDist _noResend; | 
|  | GaussDist _deltaFrameSize; | 
|  | unsigned int _prevTimestamp; | 
|  | int64_t _prevWallClock; | 
|  | unsigned int _nextDelay; | 
|  | double _keyFrameRate; | 
|  | unsigned int _counter; | 
|  | unsigned int _seed; | 
|  | double _lossrate; | 
|  | }; | 
|  |  | 
|  | #endif // WEBRTC_MODULES_VIDEO_CODING_TEST_JITTER_ESTIMATE_TEST_H_ |