VIDEO: Separate external and internal tracks

Prevents subclasses from having access to any audio track added from another file
This commit is contained in:
Matthew Hoops 2013-08-25 22:18:15 -04:00
parent 2d8d80177e
commit 85614b0de4
2 changed files with 27 additions and 10 deletions

View File

@ -62,6 +62,8 @@ void VideoDecoder::close() {
delete *it;
_tracks.clear();
_internalTracks.clear();
_externalTracks.clear();
_dirtyPalette = false;
_palette = 0;
_startTime = 0;
@ -340,6 +342,11 @@ bool VideoDecoder::seek(const Audio::Timestamp &time) {
if (!seekIntern(time))
return false;
// Seek any external track too
for (TrackListIterator it = _externalTracks.begin(); it != _externalTracks.end(); it++)
if (!(*it)->seek(time))
return false;
_lastTimeChange = time;
// Now that we've seeked, start all tracks again
@ -472,7 +479,7 @@ Audio::Timestamp VideoDecoder::getDuration() const {
}
bool VideoDecoder::seekIntern(const Audio::Timestamp &time) {
for (TrackList::iterator it = _tracks.begin(); it != _tracks.end(); it++)
for (TrackList::iterator it = _internalTracks.begin(); it != _internalTracks.end(); it++)
if (!(*it)->seek(time))
return false;
@ -649,9 +656,14 @@ bool VideoDecoder::StreamFileAudioTrack::loadFromFile(const Common::String &base
return _stream != 0;
}
void VideoDecoder::addTrack(Track *track) {
void VideoDecoder::addTrack(Track *track, bool isExternal) {
_tracks.push_back(track);
if (isExternal)
_externalTracks.push_back(track);
else
_internalTracks.push_back(track);
if (track->getTrackType() == Track::kTrackTypeAudio) {
// Update volume settings if it's an audio track
((AudioTrack *)track)->setVolume(_audioVolume);
@ -681,7 +693,7 @@ bool VideoDecoder::addStreamFileTrack(const Common::String &baseName) {
bool result = track->loadFromFile(baseName);
if (result)
addTrack(track);
addTrack(track, true);
else
delete track;
@ -712,17 +724,17 @@ void VideoDecoder::setEndTime(const Audio::Timestamp &endTime) {
}
VideoDecoder::Track *VideoDecoder::getTrack(uint track) {
if (track > _tracks.size())
if (track > _internalTracks.size())
return 0;
return _tracks[track];
return _internalTracks[track];
}
const VideoDecoder::Track *VideoDecoder::getTrack(uint track) const {
if (track > _tracks.size())
if (track > _internalTracks.size())
return 0;
return _tracks[track];
return _internalTracks[track];
}
bool VideoDecoder::endOfVideoTracks() const {

View File

@ -761,8 +761,11 @@ protected:
* Define a track to be used by this class.
*
* The pointer is then owned by this base class.
*
* @param track The track to add
* @param isExternal Is this an external track not found by loadStream()?
*/
void addTrack(Track *track);
void addTrack(Track *track, bool isExternal = false);
/**
* Whether or not getTime() will sync with a playing audio track.
@ -814,12 +817,12 @@ protected:
/**
* Get the begin iterator of the tracks
*/
TrackListIterator getTrackListBegin() { return _tracks.begin(); }
TrackListIterator getTrackListBegin() { return _internalTracks.begin(); }
/**
* Get the end iterator of the tracks
*/
TrackListIterator getTrackListEnd() { return _tracks.end(); }
TrackListIterator getTrackListEnd() { return _internalTracks.end(); }
/**
* The internal seek function that does the actual seeking.
@ -833,6 +836,8 @@ protected:
private:
// Tracks owned by this VideoDecoder
TrackList _tracks;
TrackList _internalTracks;
TrackList _externalTracks;
// Current playback status
bool _needsUpdate;