distinguish between end of stream and end of data

svn-id: r11756
This commit is contained in:
Max Horn 2003-12-19 01:30:19 +00:00
parent 0cddca5f43
commit d8903123b0
8 changed files with 34 additions and 13 deletions

View file

@ -82,7 +82,7 @@ public:
return val;
}
bool isStereo() const { return stereo; }
bool eos() const { return eosIntern(); }
bool endOfData() const { return eosIntern(); }
int getRate() const { return _rate; }
};
@ -131,7 +131,8 @@ public:
int16 read();
bool isStereo() const { return stereo; }
bool eos() const { return _finalized && eosIntern(); }
bool endOfStream() const { return _finalized && eosIntern(); }
bool endOfData() const { return eosIntern(); }
int getRate() const { return _rate; }
@ -276,7 +277,7 @@ public:
return *_pos++;
}
bool isStereo() const { return _isStereo; }
bool eos() const { return false; }
bool endOfData() const { return false; }
int getRate() const { return _rate; }
};

View file

@ -53,8 +53,24 @@ public:
/** Is this a stereo stream? */
virtual bool isStereo() const = 0;
/** End of stream reached? */
virtual bool eos() const = 0;
/**
* End of data reached? If this returns true, it means that at this
* time there is no data available in the stream. However there may be
* more data in the future.
* This is used by e.g. a rate converter to decide whether to keep on
* converting data or stop.
*/
virtual bool endOfData() const = 0;
/**
* End of stream reached? If this returns true, it means that all data
* in this stream is used up and no additional data will appear in it
* in the future.
* This is used by the mixer to decide whether a given stream shall be
* removed from the list of active streams (and thus be destroyed).
* By default this maps to endOfData()
*/
virtual bool endOfStream() const { return endOfData(); }
/** Sample rate of the stream. */
virtual int getRate() const = 0;

View file

@ -485,9 +485,11 @@ void Channel::destroy() {
*/
void Channel::mix(int16 *data, uint len) {
assert(_input);
if (_input->eos()) {
// TODO: call drain method
if (_input->endOfStream()) {
destroy();
} else if (_input->endOfData()) {
// TODO: call drain method
} else {
assert(_converter);

View file

@ -152,7 +152,7 @@ public:
int readBuffer(int16 *buffer, const int numSamples);
int16 read();
bool eos() const { return eosIntern(); }
bool endOfData() const { return eosIntern(); }
bool isStereo() const { return _isStereo; }
int getRate() const { return _frame.header.samplerate; }

View file

@ -200,7 +200,7 @@ public:
int16 tmp[2];
st_size_t len = osamp;
assert(input.isStereo() == stereo);
while (!input.eos() && len--) {
while (!input.endOfData() && len--) {
tmp[0] = tmp[1] = input.read();
if (stereo)
tmp[reverseStereo ? 0 : 1] = input.read();

View file

@ -166,7 +166,7 @@ public:
int readBuffer(int16 *buffer, const int numSamples);
int16 read();
bool eos() const { return eosIntern(); }
bool endOfData() const { return eosIntern(); }
bool isStereo() const { return _numChannels >= 2; }
int getRate() const { return ov_info(_ov_file, -1)->rate; }

View file

@ -105,7 +105,7 @@ int16 MusicHandle::read() {
return out;
}
bool MusicHandle::eos() const {
bool MusicHandle::endOfData() const {
return (!_streaming || _filePos >= _fileEnd);
}

View file

@ -61,14 +61,16 @@ public:
virtual int readBuffer(int16 *buffer, const int numSamples) {
int samples;
for (samples = 0; samples < numSamples && !eos(); samples++) {
for (samples = 0; samples < numSamples && !endOfData(); samples++) {
*buffer++ = read();
}
return samples;
}
int16 read();
bool eos() const;
bool endOfData() const;
// This stream never 'ends'
bool endOfStream() const { return false; }
MusicHandle() : _firstTime(false),
_streaming(false), _paused(false), _looping(false),