VIDEO: Improve support for multiple AVI audio tracks

This commit is contained in:
Matthew Hoops 2014-01-09 21:27:52 -05:00
parent da604b530b
commit d2e31c8d67
2 changed files with 29 additions and 18 deletions

View file

@ -441,12 +441,10 @@ bool AVIDecoder::seekIntern(const Audio::Timestamp &time) {
if (time > getDuration()) if (time > getDuration())
return false; return false;
// Track down our video track (optionally audio too). // Track down our video track.
// We only support seeking with one track right now. // We only support seeking with one video track right now.
AVIVideoTrack *videoTrack = 0; AVIVideoTrack *videoTrack = 0;
AVIAudioTrack *audioTrack = 0;
int videoIndex = -1; int videoIndex = -1;
int audioIndex = -1;
uint trackID = 0; uint trackID = 0;
for (TrackListIterator it = getTrackListBegin(); it != getTrackListEnd(); it++, trackID++) { for (TrackListIterator it = getTrackListBegin(); it != getTrackListEnd(); it++, trackID++) {
@ -459,15 +457,6 @@ bool AVIDecoder::seekIntern(const Audio::Timestamp &time) {
videoTrack = (AVIVideoTrack *)*it; videoTrack = (AVIVideoTrack *)*it;
videoIndex = trackID; videoIndex = trackID;
} else if ((*it)->getTrackType() == Track::kTrackTypeAudio) {
if (audioTrack) {
// Already have one
// -> Not supported
return false;
}
audioTrack = (AVIAudioTrack *)*it;
audioIndex = trackID;
} }
} }
@ -480,8 +469,9 @@ bool AVIDecoder::seekIntern(const Audio::Timestamp &time) {
if (time == getDuration()) { if (time == getDuration()) {
videoTrack->setCurFrame(videoTrack->getFrameCount() - 1); videoTrack->setCurFrame(videoTrack->getFrameCount() - 1);
if (audioTrack) for (TrackListIterator it = getTrackListBegin(); it != getTrackListEnd(); it++)
audioTrack->resetStream(); if ((*it)->getTrackType() == Track::kTrackTypeAudio)
((AVIAudioTrack *)*it)->resetStream();
return true; return true;
} }
@ -542,7 +532,15 @@ bool AVIDecoder::seekIntern(const Audio::Timestamp &time) {
if (frameIndex < 0) // This shouldn't happen. if (frameIndex < 0) // This shouldn't happen.
return false; return false;
if (audioTrack) { // Update all the audio tracks
uint audioIndex = 0;
for (TrackListIterator it = getTrackListBegin(); it != getTrackListEnd(); it++, audioIndex++) {
if ((*it)->getTrackType() != Track::kTrackTypeAudio)
continue;
AVIAudioTrack *audioTrack = (AVIAudioTrack *)*it;
// We need to find where the start of audio should be. // We need to find where the start of audio should be.
// Which is exactly 'initialFrames' audio chunks back from where // Which is exactly 'initialFrames' audio chunks back from where
// our found frame is. // our found frame is.
@ -683,6 +681,16 @@ void AVIDecoder::forceVideoEnd() {
((AVIVideoTrack *)*it)->forceTrackEnd(); ((AVIVideoTrack *)*it)->forceTrackEnd();
} }
VideoDecoder::AudioTrack *AVIDecoder::getAudioTrack(int index) {
// AVI audio track indexes are relative to the first track
Track *track = getTrack(index);
if (!track || track->getTrackType() != Track::kTrackTypeAudio)
return 0;
return (AudioTrack *)track;
}
AVIDecoder::AVIVideoTrack::AVIVideoTrack(int frameCount, const AVIStreamHeader &streamHeader, const BitmapInfoHeader &bitmapInfoHeader, byte *initialPalette) AVIDecoder::AVIVideoTrack::AVIVideoTrack(int frameCount, const AVIStreamHeader &streamHeader, const BitmapInfoHeader &bitmapInfoHeader, byte *initialPalette)
: _frameCount(frameCount), _vidsHeader(streamHeader), _bmInfo(bitmapInfoHeader), _initialPalette(initialPalette) { : _frameCount(frameCount), _vidsHeader(streamHeader), _bmInfo(bitmapInfoHeader), _initialPalette(initialPalette) {
_videoCodec = createCodec(); _videoCodec = createCodec();

View file

@ -72,8 +72,11 @@ public:
bool isSeekable() const; bool isSeekable() const;
protected: protected:
// VideoDecoder API
void readNextPacket(); void readNextPacket();
bool seekIntern(const Audio::Timestamp &time); bool seekIntern(const Audio::Timestamp &time);
bool supportsAudioTrackSwitching() const { return true; }
AudioTrack *getAudioTrack(int index);
struct BitmapInfoHeader { struct BitmapInfoHeader {
uint32 size; uint32 size;