1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 /** 24 * Internal interface to the QuickTime audio decoder. 25 * 26 * This is available so that the QuickTimeVideoDecoder can use 27 * this directly. 28 */ 29 30 #ifndef AUDIO_QUICKTIME_INTERN_H 31 #define AUDIO_QUICKTIME_INTERN_H 32 33 #include "common/quicktime.h" 34 #include "common/scummsys.h" 35 #include "common/types.h" 36 37 #include "audio/audiostream.h" 38 39 namespace Common { 40 class SeekableReadStream; 41 class String; 42 } 43 44 namespace Audio { 45 46 class Codec; 47 48 class QuickTimeAudioDecoder : public Common::QuickTimeParser { 49 public: 50 QuickTimeAudioDecoder(); 51 virtual ~QuickTimeAudioDecoder(); 52 53 /** 54 * Load a QuickTime audio file 55 * @param filename the filename to load 56 */ 57 bool loadAudioFile(const Common::String &filename); 58 59 /** 60 * Load a QuickTime audio file from a SeekableReadStream 61 * @param stream the stream to load 62 */ 63 bool loadAudioStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle); 64 65 protected: 66 class QuickTimeAudioTrack : public SeekableAudioStream { 67 public: 68 QuickTimeAudioTrack(QuickTimeAudioDecoder *decoder, Track *parentTrack); 69 ~QuickTimeAudioTrack(); 70 71 // AudioStream API 72 int readBuffer(int16 *buffer, const int numSamples); isStereo()73 bool isStereo() const { return _queue->isStereo(); } getRate()74 int getRate() const { return _queue->getRate(); } 75 bool endOfData() const; 76 77 // SeekableAudioStream API 78 bool seek(const Timestamp &where); 79 Timestamp getLength() const; 80 81 // Queue *at least* "length" audio 82 // If length is zero, it queues the next logical block of audio whether 83 // that be a whole edit or just one chunk within an edit 84 void queueAudio(const Timestamp &length = Timestamp()); getParent()85 Track *getParent() const { return _parentTrack; } 86 void queueRemainingAudio(); hasDataInQueue()87 bool hasDataInQueue() const { return _samplesQueued != 0; } 88 89 private: 90 QuickTimeAudioDecoder *_decoder; 91 Track *_parentTrack; 92 QueuingAudioStream *_queue; 93 uint _curChunk; 94 Timestamp _curMediaPos, _skipSamples; 95 uint32 _curEdit, _samplesQueued; 96 bool _skipAACPrimer; 97 98 QueuingAudioStream *createStream() const; 99 AudioStream *readAudioChunk(uint chunk); 100 bool isOldDemuxing() const; 101 void skipSamples(const Timestamp &length, AudioStream *stream); 102 void findEdit(const Timestamp &position); 103 bool allDataRead() const; 104 void enterNewEdit(const Timestamp &position); 105 void queueStream(AudioStream *stream, const Timestamp &length); 106 uint32 getAudioChunkSampleCount(uint chunk) const; 107 Timestamp getChunkLength(uint chunk, bool skipAACPrimer = false) const; 108 uint32 getAACSampleTime(uint32 totalSampleCount, bool skipAACPrimer = false) const; 109 Timestamp getCurrentTrackTime() const; 110 }; 111 112 class AudioSampleDesc : public Common::QuickTimeParser::SampleDesc { 113 public: 114 AudioSampleDesc(Common::QuickTimeParser::Track *parentTrack, uint32 codecTag); 115 ~AudioSampleDesc(); 116 117 bool isAudioCodecSupported() const; 118 119 AudioStream *createAudioStream(Common::SeekableReadStream *stream) const; 120 void initCodec(); 121 122 // TODO: Make private in the long run 123 uint16 _bitsPerSample; 124 uint16 _channels; 125 uint32 _sampleRate; 126 uint32 _samplesPerFrame; 127 uint32 _bytesPerFrame; 128 129 private: 130 Codec *_codec; 131 }; 132 133 // Common::QuickTimeParser API 134 virtual Common::QuickTimeParser::SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize); 135 136 void init(); 137 138 Common::Array<QuickTimeAudioTrack *> _audioTracks; 139 }; 140 141 } // End of namespace Audio 142 143 #endif 144