From faee277978c54ccb3dcccfedc75ddb31f44e630f Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 8 Apr 2011 17:04:29 -0400 Subject: COMMON: Add a DisposeAfterUse flag to QuickTimeParser --- audio/decoders/quicktime.cpp | 29 ++++++++++++++++++++++------- audio/decoders/quicktime.h | 14 ++++++++++++-- 2 files changed, 34 insertions(+), 9 deletions(-) (limited to 'audio/decoders') diff --git a/audio/decoders/quicktime.cpp b/audio/decoders/quicktime.cpp index 53cce30125..62a6f6e404 100644 --- a/audio/decoders/quicktime.cpp +++ b/audio/decoders/quicktime.cpp @@ -46,16 +46,16 @@ QuickTimeAudioDecoder::~QuickTimeAudioDecoder() { delete _audStream; } -bool QuickTimeAudioDecoder::loadFile(const Common::String &filename) { - if (!Common::QuickTimeParser::loadFile(filename)) +bool QuickTimeAudioDecoder::loadAudioFile(const Common::String &filename) { + if (!Common::QuickTimeParser::parseFile(filename)) return false; init(); return true; } -bool QuickTimeAudioDecoder::loadStream(Common::SeekableReadStream *stream) { - if (!Common::QuickTimeParser::loadStream(stream)) +bool QuickTimeAudioDecoder::loadAudioStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle) { + if (!Common::QuickTimeParser::parseStream(stream, disposeFileHandle)) return false; init(); @@ -319,8 +319,12 @@ public: QuickTimeAudioStream() {} ~QuickTimeAudioStream() {} - bool loadFile(const Common::String &filename) { - return QuickTimeAudioDecoder::loadFile(filename) && _audioStreamIndex >= 0 && _audStream; + bool openFromFile(const Common::String &filename) { + return QuickTimeAudioDecoder::loadAudioFile(filename) && _audioStreamIndex >= 0 && _audStream; + } + + bool openFromStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle) { + return QuickTimeAudioDecoder::loadAudioStream(stream, disposeFileHandle) && _audioStreamIndex >= 0 && _audStream; } // AudioStream API @@ -358,7 +362,18 @@ public: SeekableAudioStream *makeQuickTimeStream(const Common::String &filename) { QuickTimeAudioStream *audioStream = new QuickTimeAudioStream(); - if (!audioStream->loadFile(filename)) { + if (!audioStream->openFromFile(filename)) { + delete audioStream; + return 0; + } + + return audioStream; +} + +SeekableAudioStream *makeQuickTimeStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse) { + QuickTimeAudioStream *audioStream = new QuickTimeAudioStream(); + + if (!audioStream->openFromStream(stream, disposeAfterUse)) { delete audioStream; return 0; } diff --git a/audio/decoders/quicktime.h b/audio/decoders/quicktime.h index 9e2e95b705..be4d1097da 100644 --- a/audio/decoders/quicktime.h +++ b/audio/decoders/quicktime.h @@ -50,13 +50,13 @@ public: * Load a QuickTime audio file * @param filename the filename to load */ - bool loadFile(const Common::String &filename); + bool loadAudioFile(const Common::String &filename); /** * Load a QuickTime audio file from a SeekableReadStream * @param stream the stream to load */ - bool loadStream(Common::SeekableReadStream *stream); + bool loadAudioStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle); protected: struct AudioSampleDesc : public Common::QuickTimeParser::SampleDesc { @@ -93,6 +93,16 @@ protected: */ SeekableAudioStream *makeQuickTimeStream(const Common::String &filename); +/** + * Try to load a QuickTime sound file from the given seekable stream and create a SeekableAudioStream + * from that data. + * + * @param stream the SeekableReadStream from which to read the data + * @param disposeAfterUse whether to delete the stream after use + * @return a new SeekableAudioStream, or NULL, if an error occurred + */ +SeekableAudioStream *makeQuickTimeStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES); + } // End of namespace Audio #endif -- cgit v1.2.3