Home | History | Annotate | Download | only in test
      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 
     11 #ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_JITTER_ESTIMATE_TEST_H_
     12 #define WEBRTC_MODULES_VIDEO_CODING_TEST_JITTER_ESTIMATE_TEST_H_
     13 
     14 #include "webrtc/typedefs.h"
     15 #include "jitter_buffer.h"
     16 #include "jitter_estimator.h"
     17 #include <stdlib.h>
     18 #include <math.h>
     19 
     20 double const pi = 4 * atan(1.0);
     21 
     22 class GaussDist
     23 {
     24 public:
     25     GaussDist(double m, double v): _mu(m), _sigma(sqrt(v)) {}
     26 
     27     double RandValue() // returns a single normally distributed number
     28     {
     29         double r1 = (rand() + 1.0) /
     30                     (RAND_MAX + 1.0);  // gives equal distribution in (0, 1]
     31         double r2 = (rand() + 1.0) / (RAND_MAX + 1.0);
     32         return _mu + _sigma * sqrt(-2 * log(r1)) * cos(2 * pi * r2);
     33     }
     34 
     35     double GetAverage()
     36     {
     37         return _mu;
     38     }
     39 
     40     double GetVariance()
     41     {
     42         return _sigma*_sigma;
     43     }
     44 
     45     void SetParams(double m, double v)
     46     {
     47         _mu = m;
     48         _sigma = sqrt(v);
     49     }
     50 
     51 private:
     52     double _mu, _sigma;
     53 };
     54 
     55 class JitterEstimateTestWrapper : public webrtc::VCMJitterEstimator
     56 {
     57 public:
     58     JitterEstimateTestWrapper() : VCMJitterEstimator() {}
     59     double GetTheta() { return _theta[0]; }
     60     double GetVarNoise() { return _varNoise; }
     61 };
     62 
     63 class FrameSample
     64 {
     65 public:
     66     FrameSample() {FrameSample(0, 0, 0, false, false);}
     67     FrameSample(unsigned int ts, int64_t wallClk, unsigned int fs, bool _keyFrame, bool _resent):
     68       timestamp90Khz(ts), wallClockMs(wallClk), frameSize(fs), keyFrame(_keyFrame), resent(_resent) {}
     69 
     70     unsigned int timestamp90Khz;
     71     int64_t wallClockMs;
     72     unsigned int frameSize;
     73     bool keyFrame;
     74     bool resent;
     75 };
     76 
     77 class JitterEstimateTest
     78 {
     79 public:
     80     JitterEstimateTest(unsigned int frameRate);
     81     FrameSample GenerateFrameSample();
     82     void SetCapacity(unsigned int c);
     83     void SetRate(unsigned int r);
     84     void SetJitter(double m, double v);
     85     void SetFrameSizeStats(double m, double v);
     86     void SetKeyFrameRate(int rate);
     87     void SetLossRate(double rate);
     88 
     89 private:
     90     double RandUniform() { return (rand() + 1.0)/(RAND_MAX + 1.0); }
     91     unsigned int _frameRate;
     92     unsigned int _capacity;
     93     unsigned int _rate;
     94     GaussDist _jitter;
     95     //GaussDist _noResend;
     96     GaussDist _deltaFrameSize;
     97     unsigned int _prevTimestamp;
     98     int64_t _prevWallClock;
     99     unsigned int _nextDelay;
    100     double _keyFrameRate;
    101     unsigned int _counter;
    102     unsigned int _seed;
    103     double _lossrate;
    104 };
    105 
    106 #endif // WEBRTC_MODULES_VIDEO_CODING_TEST_JITTER_ESTIMATE_TEST_H_
    107