~alanbell/dasher/ircfix-lp579181

« back to all changes in this revision

Viewing changes to Src/DasherCore/FrameRate.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-11-14 12:03:42 UTC
  • mfrom: (1.2.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114120342-pebcosas78lczcgz
Tags: 4.3.1-0ubuntu1
* New upstream release:
  - 4.3.1:
    - Bugfixes
    - Translation updates
  - 4.3.0:
    - Mainly work on two button dynamic mode to provide a platform for 
      user tests
* debian/patches/10_remove-extra-qualifier.patch:
  - fix FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
class CFrameRate {
23
23
public:
24
24
  CFrameRate();
25
 
  ~CFrameRate() {
26
 
  };
27
25
  void Initialise();
28
 
  double Rxmax() const {
29
 
    return m_dRXmax;
30
 
  }
 
26
 
31
27
  /// Get the minimum size of the target viewport
32
28
  ////// TODO: Eventually fix this so that it uses integer maths internally. 
33
 
  myint MinSize(myint t) const {
34
 
    return static_cast < myint > (t / m_dRXmax);
 
29
 
 
30
  // dFactor is a temporary change to the frame rate, allowing for
 
31
  // slow start and the like
 
32
  myint MinSize(myint t, double dFactor = 1.0) const {
 
33
    if(dFactor == 1.0)
 
34
      return static_cast < myint > (t / m_dRXmax);
 
35
    else
 
36
      return static_cast < myint > (t / pow(m_dRXmax, dFactor));
35
37
  };
36
38
 
37
39
  int Steps() const {
38
40
    return m_iSteps;
39
 
  } double Framerate() const {
 
41
  }; 
 
42
 
 
43
  double Framerate() const {
40
44
    return m_dFr;
41
 
  } void Reset(unsigned long Time);
 
45
  };
 
46
 
 
47
  void Reset(unsigned long Time);
42
48
  void NewFrame(unsigned long Time);
43
 
 
44
 
  // TODO: These two shouldn't be the same thing:
45
49
  void SetBitrate(double TargetRate);
46
50
  void SetMaxBitrate(double MaxRate);
 
51
 
47
52
private:
48
53
  double m_dFr;
49
54
  double m_dMaxbitrate;         // the maximum rate of entering information
53
58
};
54
59
 
55
60
inline CFrameRate::CFrameRate() {
56
 
 
 
61
  // TODO: This looks obsolete - need to rationalise this
57
62
  // maxbitrate should be user-defined and/or adaptive. Currently it is not.
58
63
#if defined(_WIN32_WCE)
59
64
  m_dMaxbitrate = 5;
61
66
  m_dMaxbitrate = 5.5;
62
67
#endif
63
68
 
64
 
  m_dRXmax = 2;                 // only a transient effect
65
 
  m_iFrames = 0;
66
 
  m_iSamples = 1;
67
 
 
68
 
  // we dont know the framerate yet - play it safe by setting it high
69
 
  m_dFr = 1 << 5;
70
 
 
71
 
  // start off very slow until we have sampled framerate adequately
72
 
  m_iSteps = 2000;
73
 
  m_iTime = 0;                  // Hmmm, User must reset framerate before starting.
 
69
  Initialise();
74
70
}
75
71
 
76
72
inline void CFrameRate::Initialise(void) {
87
83
}
88
84
 
89
85
inline void CFrameRate::NewFrame(unsigned long Time)
90
 
        // compute framerate if we have sampled enough frames
91
86
{
92
87
  m_iFrames++;
93
88
 
 
89
  // Update values once enough samples have been collected
94
90
  if(m_iFrames == m_iSamples) {
95
91
    m_iTime2 = Time;
 
92
 
 
93
    // If samples are collected in < 50ms, collect more
96
94
    if(m_iTime2 - m_iTime < 50)
97
 
      m_iSamples++;             // increase sample size
 
95
      m_iSamples++; 
 
96
    // And if it's taking longer than > 80ms, collect fewer, down to a
 
97
    // limit of 2
98
98
    else if(m_iTime2 - m_iTime > 80) {
99
99
      m_iSamples--;
100
100
      if(m_iSamples < 2)
101
101
        m_iSamples = 2;
102
102
    }
 
103
 
 
104
    // Calculate the framerate and reset framerate statistics for next
 
105
    // sampleing period
103
106
    if(m_iTime2 - m_iTime) {
104
107
      m_dFr = m_iFrames * 1000.0 / (m_iTime2 - m_iTime);
105
108
      m_iTime = m_iTime2;
106
109
      m_iFrames = 0;
 
110
    }
107
111
 
108
 
    }
 
112
    // Update auxiliary variablesq
109
113
    m_dRXmax = exp(m_dMaxbitrate * LN2 / m_dFr);
 
114
    
 
115
    // Note that m_iSteps is smoothed here - 50:50 interpolation with
 
116
    // previous value
110
117
    m_iSteps = m_iSteps / 2 + (int)(-log(0.2) * m_dFr / LN2 / m_dMaxbitrate) / 2;
111
118
 
112
119
    // If the framerate slows to < 4 then we end up with steps < 1 ! 
114
121
      m_iSteps = 1;
115
122
 
116
123
    DASHER_TRACEOUTPUT("Fr %f Steps %d Samples %d Time2 %d rxmax %f\n", m_dFr, m_iSteps, m_iSamples, m_iTime2, m_dRXmax);
117
 
 
118
124
  }
119
 
 
120
125
}
121
126
 
122
127
inline void CFrameRate::Reset(unsigned long Time) {
124
129
  m_iTime = Time;
125
130
}
126
131
 
 
132
// TODO: Need to clarify the exact relation between these two values -
 
133
// at the moment the max bitrate is all that is used
127
134
inline void CFrameRate::SetBitrate(double TargetRate) {
128
135
  m_dMaxbitrate = TargetRate;
129
136
}