AUDIO: Forbid adding timestamps with differing framerate

We used to allow this, but the result is a timestamp with a framerate
potentially different from that of both original timestamps, which can
lead to completely unexpected behavior. For example, consider this code
snippet:
  a = a + b;
  a = a.addFrames(1);  // frame rate changed!

svn-id: r55840
This commit is contained in:
Max Horn 2011-02-09 00:12:22 +00:00
parent 97bfd60e61
commit 633b8ed277
2 changed files with 11 additions and 35 deletions

View File

@ -148,21 +148,9 @@ Timestamp Timestamp::addMsecs(int ms) const {
}
void Timestamp::addIntern(const Timestamp &ts) {
assert(_framerate == ts._framerate);
_secs += ts._secs;
if (_framerate == ts._framerate) {
_numFrames += ts._numFrames;
} else {
// We need to multiply by the quotient of the two framerates.
// We cancel the GCD in this fraction to reduce the risk of
// overflows.
const uint g = Common::gcd(_framerate, ts._framerate);
const uint p = _framerate / g;
const uint q = ts._framerate / g;
_framerate *= q;
_numFrames = _numFrames * q + ts._numFrames * p;
}
_numFrames += ts._numFrames;
normalize();
}
@ -187,24 +175,6 @@ Timestamp Timestamp::operator-(const Timestamp &ts) const {
return result;
}
/*
Timestamp &Timestamp::operator+=(const Timestamp &ts) {
addIntern(ts);
return *this;
}
Timestamp &Timestamp::operator-=(const Timestamp &ts) {
addIntern(-ts);
return *this;
}
*/
/*
int Timestamp::frameDiff(const Timestamp &ts) const {
return (*this - ts).totalNumberOfFrames();
}
*/
int Timestamp::frameDiff(const Timestamp &ts) const {
int delta = 0;

View File

@ -126,11 +126,17 @@ public:
// unary minus
Timestamp operator-() const;
/**
* Compute the sum of two timestamps. This is only
* allowed if they use the same framerate.
*/
Timestamp operator+(const Timestamp &ts) const;
Timestamp operator-(const Timestamp &ts) const;
// Timestamp &operator+=(const Timestamp &ts);
// Timestamp &operator-=(const Timestamp &ts);
/**
* Compute the difference between two timestamps. This is only
* allowed if they use the same framerate.
*/
Timestamp operator-(const Timestamp &ts) const;
/**
* Computes the number of frames between this timestamp and ts.