2015-06-03 11:11:09 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-06-03 11:11:09 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-06-03 11:11:09 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/stream.h"
|
|
|
|
#include "common/textconsole.h"
|
|
|
|
|
|
|
|
#include "audio/audiostream.h"
|
2015-06-04 13:53:54 +00:00
|
|
|
#include "audio/decoders/3do.h"
|
2015-06-03 11:11:09 +00:00
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
#include "video/3do_decoder.h"
|
2015-06-03 11:11:09 +00:00
|
|
|
#include "image/codecs/cinepak.h"
|
|
|
|
|
|
|
|
// for Test-Code
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/keyboard.h"
|
|
|
|
#include "engines/engine.h"
|
|
|
|
#include "engines/util.h"
|
|
|
|
#include "graphics/palette.h"
|
|
|
|
#include "graphics/pixelformat.h"
|
|
|
|
#include "graphics/surface.h"
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
namespace Video {
|
2015-06-03 11:11:09 +00:00
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
ThreeDOMovieDecoder::ThreeDOMovieDecoder()
|
2020-10-20 22:12:10 +00:00
|
|
|
: _stream(0), _videoTrack(0) {
|
2015-06-04 13:53:54 +00:00
|
|
|
_streamVideoOffset = 0;
|
|
|
|
_streamAudioOffset = 0;
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
ThreeDOMovieDecoder::~ThreeDOMovieDecoder() {
|
2015-06-03 11:11:09 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2020-10-20 22:12:10 +00:00
|
|
|
VideoDecoder::AudioTrack* ThreeDOMovieDecoder::getAudioTrack(int index) {
|
|
|
|
return _audioTracks[index];
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
bool ThreeDOMovieDecoder::loadStream(Common::SeekableReadStream *stream) {
|
2015-06-03 11:11:09 +00:00
|
|
|
uint32 videoSubType = 0;
|
|
|
|
uint32 videoCodecTag = 0;
|
|
|
|
uint32 videoHeight = 0;
|
|
|
|
uint32 videoWidth = 0;
|
|
|
|
uint32 videoFrameCount = 0;
|
|
|
|
uint32 audioSubType = 0;
|
|
|
|
uint32 audioCodecTag = 0;
|
|
|
|
uint32 audioChannels = 0;
|
|
|
|
uint32 audioSampleRate = 0;
|
2020-10-20 22:12:10 +00:00
|
|
|
uint32 audioTrackId = 0;
|
2015-06-03 11:11:09 +00:00
|
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
_stream = stream;
|
2015-06-04 13:53:54 +00:00
|
|
|
_streamVideoOffset = 0;
|
|
|
|
_streamAudioOffset = 0;
|
2015-06-03 11:11:09 +00:00
|
|
|
|
|
|
|
// Look for packets that we care about
|
2015-06-04 13:53:54 +00:00
|
|
|
static const int maxPacketCheckCount = 20;
|
2015-06-03 11:11:09 +00:00
|
|
|
for (int i = 0; i < maxPacketCheckCount; i++) {
|
2015-06-04 15:54:13 +00:00
|
|
|
uint32 chunkTag = _stream->readUint32BE();
|
2015-06-03 11:11:09 +00:00
|
|
|
uint32 chunkSize = _stream->readUint32BE() - 8;
|
|
|
|
|
|
|
|
// Bail out if done
|
|
|
|
if (_stream->eos())
|
|
|
|
break;
|
|
|
|
|
|
|
|
uint32 dataStartOffset = _stream->pos();
|
|
|
|
|
2015-06-04 15:54:13 +00:00
|
|
|
switch (chunkTag) {
|
2015-06-03 11:11:09 +00:00
|
|
|
case MKTAG('F','I','L','M'): {
|
|
|
|
// See if this is a FILM header
|
2015-06-03 17:47:01 +00:00
|
|
|
_stream->skip(4); // time stamp (based on 240 per second)
|
2015-06-03 11:11:09 +00:00
|
|
|
_stream->skip(4); // Unknown 0x00000000
|
|
|
|
videoSubType = _stream->readUint32BE();
|
|
|
|
|
|
|
|
switch (videoSubType) {
|
|
|
|
case MKTAG('F', 'H', 'D', 'R'):
|
|
|
|
// FILM header found
|
2015-06-03 17:47:01 +00:00
|
|
|
if (_videoTrack) {
|
2020-10-20 21:12:11 +00:00
|
|
|
warning("3DO movie: Multiple FILM headers found");
|
2015-06-03 11:11:09 +00:00
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_stream->readUint32BE();
|
|
|
|
videoCodecTag = _stream->readUint32BE();
|
|
|
|
videoHeight = _stream->readUint32BE();
|
|
|
|
videoWidth = _stream->readUint32BE();
|
|
|
|
_stream->skip(4); // time scale
|
|
|
|
videoFrameCount = _stream->readUint32BE();
|
2015-06-03 17:47:01 +00:00
|
|
|
|
|
|
|
_videoTrack = new StreamVideoTrack(videoWidth, videoHeight, videoCodecTag, videoFrameCount);
|
|
|
|
addTrack(_videoTrack);
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('F', 'R', 'M', 'E'):
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
warning("3DO movie: Unknown subtype inside FILM packet");
|
2015-06-04 13:53:54 +00:00
|
|
|
close();
|
|
|
|
return false;
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MKTAG('S','N','D','S'): {
|
2020-10-20 22:12:10 +00:00
|
|
|
_stream->readUint32BE(); // Unknown
|
|
|
|
audioTrackId = _stream->readUint32BE();
|
2015-06-03 11:11:09 +00:00
|
|
|
audioSubType = _stream->readUint32BE();
|
|
|
|
|
|
|
|
switch (audioSubType) {
|
2020-10-20 22:12:10 +00:00
|
|
|
case MKTAG('S', 'H', 'D', 'R'): {
|
2015-06-03 11:11:09 +00:00
|
|
|
// Audio header
|
|
|
|
|
|
|
|
// OK, this is the start of a audio stream
|
|
|
|
_stream->readUint32BE(); // Version, always 0x00000000
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00000008 ?!
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00007500
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00004000
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00000000
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00000010
|
2016-10-09 12:59:58 +00:00
|
|
|
audioSampleRate = _stream->readUint32BE();
|
2015-06-03 11:11:09 +00:00
|
|
|
audioChannels = _stream->readUint32BE();
|
|
|
|
audioCodecTag = _stream->readUint32BE();
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00000004 compression ratio?
|
|
|
|
_stream->readUint32BE(); // Unknown 0x00000A2C
|
|
|
|
|
2020-10-20 22:12:10 +00:00
|
|
|
StreamAudioTrack *track = new StreamAudioTrack(audioCodecTag, audioSampleRate, audioChannels,
|
|
|
|
getSoundType(), audioTrackId);
|
|
|
|
addTrack(track);
|
|
|
|
_audioTracks.push_back(track);
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
2020-10-20 22:12:10 +00:00
|
|
|
}
|
2015-06-03 11:11:09 +00:00
|
|
|
|
|
|
|
case MKTAG('S', 'S', 'M', 'P'):
|
|
|
|
// Audio data
|
|
|
|
break;
|
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
warning("3DO movie: Unknown subtype inside FILM packet");
|
2015-06-04 13:53:54 +00:00
|
|
|
close();
|
|
|
|
return false;
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MKTAG('C','T','R','L'):
|
2015-06-04 15:54:13 +00:00
|
|
|
case MKTAG('F','I','L','L'): // filler chunk, fills to certain boundary
|
|
|
|
case MKTAG('D','A','C','Q'):
|
|
|
|
case MKTAG('J','O','I','N'): // add cel data (not used in sherlock)
|
|
|
|
// Ignore these chunks
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
case MKTAG('S','H','D','R'):
|
|
|
|
// Happens for EA logo, seems to be garbage data right at the start of the file
|
|
|
|
break;
|
|
|
|
|
2015-06-03 11:11:09 +00:00
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
warning("Unknown chunk-tag '%s' inside 3DO movie", tag2str(chunkTag));
|
2015-06-03 11:11:09 +00:00
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-20 22:12:10 +00:00
|
|
|
if ((_videoTrack) && (!_audioTracks.empty()))
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Seek to next chunk
|
|
|
|
_stream->seek(dataStartOffset + chunkSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bail if we didn't find video + audio
|
2020-10-20 22:12:10 +00:00
|
|
|
if ((!_videoTrack) || (_audioTracks.empty())) {
|
2015-06-03 11:11:09 +00:00
|
|
|
close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewind back to the beginning
|
|
|
|
_stream->seek(0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
void ThreeDOMovieDecoder::close() {
|
2015-06-03 11:11:09 +00:00
|
|
|
Video::VideoDecoder::close();
|
|
|
|
|
|
|
|
delete _stream; _stream = 0;
|
|
|
|
_videoTrack = 0;
|
|
|
|
}
|
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
// We try to at least decode 1 frame
|
|
|
|
// and also try to get at least 0.5 seconds of audio queued up
|
2020-10-20 21:12:11 +00:00
|
|
|
void ThreeDOMovieDecoder::readNextPacket() {
|
2015-06-04 13:53:54 +00:00
|
|
|
uint32 currentMovieTime = getTime();
|
|
|
|
uint32 wantedAudioQueued = currentMovieTime + 500; // always try to be 0.500 seconds in front of movie time
|
|
|
|
|
|
|
|
int32 chunkOffset = 0;
|
|
|
|
int32 dataStartOffset = 0;
|
|
|
|
int32 nextChunkOffset = 0;
|
|
|
|
uint32 chunkTag = 0;
|
|
|
|
uint32 chunkSize = 0;
|
|
|
|
|
|
|
|
uint32 videoSubType = 0;
|
2015-06-03 17:47:01 +00:00
|
|
|
uint32 videoTimeStamp = 0;
|
2015-06-03 11:11:09 +00:00
|
|
|
uint32 videoFrameSize = 0;
|
2015-06-04 13:53:54 +00:00
|
|
|
uint32 audioSubType = 0;
|
|
|
|
uint32 audioBytes = 0;
|
2020-10-20 22:12:10 +00:00
|
|
|
uint32 audioTrackId = 0;
|
2015-06-04 13:53:54 +00:00
|
|
|
bool videoGotFrame = false;
|
|
|
|
bool videoDone = false;
|
|
|
|
bool audioDone = false;
|
|
|
|
|
|
|
|
// Seek to smallest stream offset
|
|
|
|
if (_streamVideoOffset <= _streamAudioOffset) {
|
|
|
|
_stream->seek(_streamVideoOffset);
|
|
|
|
} else {
|
|
|
|
_stream->seek(_streamAudioOffset);
|
|
|
|
}
|
2015-06-03 11:11:09 +00:00
|
|
|
|
2020-10-20 22:12:10 +00:00
|
|
|
if (wantedAudioQueued <= _audioTracks[0]->getTotalAudioQueued()) {
|
2015-06-04 13:53:54 +00:00
|
|
|
// already got enough audio queued up
|
|
|
|
audioDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
chunkOffset = _stream->pos();
|
|
|
|
assert(chunkOffset >= 0);
|
|
|
|
|
|
|
|
// Read chunk header
|
|
|
|
chunkTag = _stream->readUint32BE();
|
|
|
|
chunkSize = _stream->readUint32BE() - 8;
|
|
|
|
|
|
|
|
// Calculate offsets
|
|
|
|
dataStartOffset = _stream->pos();
|
|
|
|
assert(dataStartOffset >= 0);
|
|
|
|
nextChunkOffset = dataStartOffset + chunkSize;
|
2015-06-03 11:11:09 +00:00
|
|
|
|
|
|
|
//warning("offset %lx - tag %lx", dataStartOffset, tag);
|
|
|
|
|
|
|
|
if (_stream->eos())
|
|
|
|
break;
|
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
switch (chunkTag) {
|
2015-06-03 11:11:09 +00:00
|
|
|
case MKTAG('F','I','L','M'):
|
2015-06-03 17:47:01 +00:00
|
|
|
videoTimeStamp = _stream->readUint32BE();
|
2015-06-03 11:11:09 +00:00
|
|
|
_stream->skip(4); // Unknown
|
|
|
|
videoSubType = _stream->readUint32BE();
|
|
|
|
|
|
|
|
switch (videoSubType) {
|
|
|
|
case MKTAG('F', 'H', 'D', 'R'):
|
|
|
|
// Ignore video header
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('F', 'R', 'M', 'E'):
|
2015-06-04 13:53:54 +00:00
|
|
|
// Found frame data
|
|
|
|
if (_streamVideoOffset <= chunkOffset) {
|
2015-06-04 14:01:43 +00:00
|
|
|
// We are at an offset that is still relevant to video decoding
|
2015-06-04 13:53:54 +00:00
|
|
|
if (!videoDone) {
|
|
|
|
if (!videoGotFrame) {
|
2015-06-04 14:01:43 +00:00
|
|
|
// We haven't decoded any frame yet, so do so now
|
2015-06-04 13:53:54 +00:00
|
|
|
_stream->readUint32BE();
|
|
|
|
videoFrameSize = _stream->readUint32BE();
|
|
|
|
_videoTrack->decodeFrame(_stream->readStream(videoFrameSize), videoTimeStamp);
|
|
|
|
|
|
|
|
_streamVideoOffset = nextChunkOffset;
|
|
|
|
videoGotFrame = true;
|
|
|
|
|
|
|
|
} else {
|
2015-06-04 14:01:43 +00:00
|
|
|
// Already decoded a frame, so get timestamp of follow-up frame
|
|
|
|
// and then we are done with video
|
2015-06-04 13:53:54 +00:00
|
|
|
|
|
|
|
// Calculate next frame time
|
|
|
|
// 3DO clock time for movies runs at 240Hh, that's why timestamps are based on 240.
|
|
|
|
uint32 currentFrameStartTime = _videoTrack->getNextFrameStartTime();
|
|
|
|
uint32 nextFrameStartTime = videoTimeStamp * 1000 / 240;
|
|
|
|
assert(currentFrameStartTime <= nextFrameStartTime);
|
|
|
|
_videoTrack->setNextFrameStartTime(nextFrameStartTime);
|
|
|
|
|
|
|
|
// next time we want to start at the current chunk
|
|
|
|
_streamVideoOffset = chunkOffset;
|
|
|
|
videoDone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
error("3DO movie: Unknown subtype inside FILM packet");
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('S','N','D','S'):
|
2020-10-20 22:12:10 +00:00
|
|
|
_stream->readUint32BE();
|
|
|
|
audioTrackId = _stream->readUint32BE();
|
2015-06-03 11:11:09 +00:00
|
|
|
audioSubType = _stream->readUint32BE();
|
|
|
|
|
|
|
|
switch (audioSubType) {
|
|
|
|
case MKTAG('S', 'H', 'D', 'R'):
|
|
|
|
// Ignore the audio header
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('S', 'S', 'M', 'P'):
|
|
|
|
// Got audio chunk
|
2015-06-04 13:53:54 +00:00
|
|
|
if (_streamAudioOffset <= chunkOffset) {
|
2015-06-04 14:01:43 +00:00
|
|
|
// We are at an offset that is still relevant to audio decoding
|
2015-06-04 13:53:54 +00:00
|
|
|
if (!audioDone) {
|
2020-10-20 22:12:10 +00:00
|
|
|
uint queued = 0;
|
2015-06-04 13:53:54 +00:00
|
|
|
audioBytes = _stream->readUint32BE();
|
2020-10-20 22:12:10 +00:00
|
|
|
for (uint i = 0; i < _audioTracks.size(); i++)
|
|
|
|
if (_audioTracks[i]->matchesId(audioTrackId)) {
|
|
|
|
_audioTracks[i]->queueAudio(_stream, audioBytes);
|
|
|
|
queued = _audioTracks[i]->getTotalAudioQueued();
|
|
|
|
}
|
2015-06-04 13:53:54 +00:00
|
|
|
|
|
|
|
_streamAudioOffset = nextChunkOffset;
|
2020-10-20 22:12:10 +00:00
|
|
|
if (wantedAudioQueued <= queued) {
|
2015-06-04 13:53:54 +00:00
|
|
|
// Got enough audio
|
|
|
|
audioDone = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
error("3DO movie: Unknown subtype inside SNDS packet");
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MKTAG('C','T','R','L'):
|
2015-06-04 15:54:13 +00:00
|
|
|
case MKTAG('F','I','L','L'): // filler chunk, fills to certain boundary
|
|
|
|
case MKTAG('D','A','C','Q'):
|
|
|
|
case MKTAG('J','O','I','N'): // add cel data (not used in sherlock)
|
|
|
|
// Ignore these chunks
|
2015-06-03 11:11:09 +00:00
|
|
|
break;
|
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
case MKTAG('S','H','D','R'):
|
|
|
|
// Happens for EA logo, seems to be garbage data right at the start of the file
|
|
|
|
break;
|
|
|
|
|
2015-06-03 11:11:09 +00:00
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
error("Unknown chunk-tag '%s' inside 3DO movie", tag2str(chunkTag));
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Always seek to end of chunk
|
|
|
|
// Sometimes not all of the chunk is filled with audio
|
2015-06-04 13:53:54 +00:00
|
|
|
_stream->seek(nextChunkOffset);
|
2015-06-03 11:11:09 +00:00
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
if ((videoDone) && (audioDone)) {
|
2015-06-03 11:11:09 +00:00
|
|
|
return;
|
2015-06-04 13:53:54 +00:00
|
|
|
}
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
ThreeDOMovieDecoder::StreamVideoTrack::StreamVideoTrack(uint32 width, uint32 height, uint32 codecTag, uint32 frameCount) {
|
2015-06-03 11:11:09 +00:00
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
_frameCount = frameCount;
|
|
|
|
_curFrame = -1;
|
2015-06-03 17:47:01 +00:00
|
|
|
_nextFrameStartTime = 0;
|
2015-06-03 11:11:09 +00:00
|
|
|
|
|
|
|
// Create the Cinepak decoder, if we're using it
|
|
|
|
if (codecTag == MKTAG('c', 'v', 'i', 'd'))
|
|
|
|
_codec = new Image::CinepakDecoder();
|
|
|
|
else
|
2020-10-20 21:12:11 +00:00
|
|
|
error("Unsupported 3DO movie video codec tag '%s'", tag2str(codecTag));
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
ThreeDOMovieDecoder::StreamVideoTrack::~StreamVideoTrack() {
|
2015-06-03 11:11:09 +00:00
|
|
|
delete _codec;
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
bool ThreeDOMovieDecoder::StreamVideoTrack::endOfTrack() const {
|
2015-06-03 17:47:01 +00:00
|
|
|
return getCurFrame() >= getFrameCount() - 1;
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
Graphics::PixelFormat ThreeDOMovieDecoder::StreamVideoTrack::getPixelFormat() const {
|
2015-06-03 11:11:09 +00:00
|
|
|
return _codec->getPixelFormat();
|
|
|
|
}
|
|
|
|
|
2023-02-23 00:14:01 +00:00
|
|
|
bool ThreeDOMovieDecoder::StreamVideoTrack::setOutputPixelFormat(const Graphics::PixelFormat &format) {
|
|
|
|
return _codec->setOutputPixelFormat(format);
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
void ThreeDOMovieDecoder::StreamVideoTrack::decodeFrame(Common::SeekableReadStream *stream, uint32 videoTimeStamp) {
|
2015-06-03 11:11:09 +00:00
|
|
|
_surface = _codec->decodeFrame(*stream);
|
|
|
|
_curFrame++;
|
|
|
|
}
|
|
|
|
|
2020-10-20 22:12:10 +00:00
|
|
|
ThreeDOMovieDecoder::StreamAudioTrack::StreamAudioTrack(uint32 codecTag, uint32 sampleRate, uint32 channels, Audio::Mixer::SoundType soundType, uint32 trackId) :
|
2017-07-10 19:36:19 +00:00
|
|
|
AudioTrack(soundType) {
|
2015-06-04 13:53:54 +00:00
|
|
|
switch (codecTag) {
|
|
|
|
case MKTAG('A','D','P','4'):
|
|
|
|
case MKTAG('S','D','X','2'):
|
|
|
|
// ADP4 + SDX2 are both allowed
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
error("Unsupported 3DO movie audio codec tag '%s'", tag2str(codecTag));
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
_totalAudioQueued = 0; // currently 0 milliseconds queued
|
2015-06-03 11:11:09 +00:00
|
|
|
|
2015-06-04 13:53:54 +00:00
|
|
|
_codecTag = codecTag;
|
|
|
|
_sampleRate = sampleRate;
|
2020-10-20 22:12:10 +00:00
|
|
|
_trackId = trackId;
|
2015-06-06 20:50:36 +00:00
|
|
|
switch (channels) {
|
|
|
|
case 1:
|
|
|
|
_stereo = false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_stereo = true;
|
|
|
|
break;
|
|
|
|
default:
|
2020-10-20 21:12:11 +00:00
|
|
|
error("Unsupported 3DO movie audio channels %d", channels);
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
2015-06-06 20:50:36 +00:00
|
|
|
_audioStream = Audio::makeQueuingAudioStream(sampleRate, _stereo);
|
|
|
|
|
|
|
|
// reset audio decoder persistent spaces
|
2015-06-04 13:53:54 +00:00
|
|
|
memset(&_ADP4_PersistentSpace, 0, sizeof(_ADP4_PersistentSpace));
|
|
|
|
memset(&_SDX2_PersistentSpace, 0, sizeof(_SDX2_PersistentSpace));
|
|
|
|
}
|
2015-06-03 11:11:09 +00:00
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
ThreeDOMovieDecoder::StreamAudioTrack::~StreamAudioTrack() {
|
2015-06-04 13:53:54 +00:00
|
|
|
delete _audioStream;
|
2015-06-06 20:50:36 +00:00
|
|
|
// free(_ADP4_PersistentSpace);
|
|
|
|
// free(_SDX2_PersistentSpace);
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 22:12:10 +00:00
|
|
|
bool ThreeDOMovieDecoder::StreamAudioTrack::matchesId(uint tid) {
|
|
|
|
return _trackId == tid;
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
void ThreeDOMovieDecoder::StreamAudioTrack::queueAudio(Common::SeekableReadStream *stream, uint32 size) {
|
2015-06-06 20:50:36 +00:00
|
|
|
Common::SeekableReadStream *compressedAudioStream = 0;
|
|
|
|
Audio::RewindableAudioStream *audioStream = 0;
|
|
|
|
uint32 audioLengthMSecs = 0;
|
|
|
|
|
|
|
|
// Read the specified chunk into memory
|
|
|
|
compressedAudioStream = stream->readStream(size);
|
2015-06-04 13:53:54 +00:00
|
|
|
|
|
|
|
switch(_codecTag) {
|
|
|
|
case MKTAG('A','D','P','4'):
|
2015-06-06 20:50:36 +00:00
|
|
|
audioStream = Audio::make3DO_ADP4AudioStream(compressedAudioStream, _sampleRate, _stereo, &audioLengthMSecs, DisposeAfterUse::YES, &_ADP4_PersistentSpace);
|
2015-06-04 13:53:54 +00:00
|
|
|
break;
|
|
|
|
case MKTAG('S','D','X','2'):
|
2015-06-06 20:50:36 +00:00
|
|
|
audioStream = Audio::make3DO_SDX2AudioStream(compressedAudioStream, _sampleRate, _stereo, &audioLengthMSecs, DisposeAfterUse::YES, &_SDX2_PersistentSpace);
|
2015-06-04 13:53:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (audioStream) {
|
2015-06-06 20:50:36 +00:00
|
|
|
_totalAudioQueued += audioLengthMSecs;
|
2015-06-04 13:53:54 +00:00
|
|
|
_audioStream->queueAudioStream(audioStream, DisposeAfterUse::YES);
|
2015-06-15 21:41:59 +00:00
|
|
|
} else {
|
|
|
|
// in case there was an error
|
|
|
|
delete compressedAudioStream;
|
2015-06-03 11:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
Audio::AudioStream *ThreeDOMovieDecoder::StreamAudioTrack::getAudioStream() const {
|
2015-06-03 11:11:09 +00:00
|
|
|
return _audioStream;
|
|
|
|
}
|
|
|
|
|
2020-10-20 21:12:11 +00:00
|
|
|
} // End of namespace Video
|