diff options
author | Eugene Sandulenko | 2011-01-23 17:14:43 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2011-01-23 17:14:43 +0000 |
commit | 806ccf5d25ebe337103942cdb6b5cf8800de115a (patch) | |
tree | ead210f06163f97521b2ae26b06b450be8bf10a3 /video/qt_decoder.h | |
parent | 36ed9be335217ef6fcf8e07b257fb6a1ee1ed8f2 (diff) | |
download | scummvm-rg350-806ccf5d25ebe337103942cdb6b5cf8800de115a.tar.gz scummvm-rg350-806ccf5d25ebe337103942cdb6b5cf8800de115a.tar.bz2 scummvm-rg350-806ccf5d25ebe337103942cdb6b5cf8800de115a.zip |
GRAPHICS: Move graphics/video/ to video/. Step 1/2
svn-id: r55473
Diffstat (limited to 'video/qt_decoder.h')
-rw-r--r-- | video/qt_decoder.h | 278 |
1 files changed, 278 insertions, 0 deletions
diff --git a/video/qt_decoder.h b/video/qt_decoder.h new file mode 100644 index 0000000000..186e257553 --- /dev/null +++ b/video/qt_decoder.h @@ -0,0 +1,278 @@ +/* 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. + * + * 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 2 + * of the License, or (at your option) any later version. + + * 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 + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +// +// Heavily based on ffmpeg code. +// +// Copyright (c) 2001 Fabrice Bellard. +// First version by Francois Revol revol@free.fr +// Seek function by Gael Chardon gael.dev@4now.net +// + +#ifndef GRAPHICS_QT_DECODER_H +#define GRAPHICS_QT_DECODER_H + +#include "common/scummsys.h" +#include "common/queue.h" +#include "common/rational.h" + +#include "graphics/video/video_decoder.h" +#include "graphics/video/codecs/codec.h" + +#include "sound/audiostream.h" +#include "sound/mixer.h" + +namespace Common { + class File; + class MacResManager; +} + +namespace Graphics { + +/** + * Decoder for QuickTime videos. + * + * Video decoder used in engines: + * - mohawk + * - sci + */ +class QuickTimeDecoder : public SeekableVideoDecoder { +public: + QuickTimeDecoder(); + virtual ~QuickTimeDecoder(); + + /** + * Returns the width of the video + * @return the width of the video + */ + uint16 getWidth() const; + + /** + * Returns the height of the video + * @return the height of the video + */ + uint16 getHeight() const; + + /** + * Returns the amount of frames in the video + * @return the amount of frames in the video + */ + uint32 getFrameCount() const; + + /** + * Load a video file + * @param filename the filename to load + */ + bool loadFile(const Common::String &filename); + + /** + * Load a QuickTime video file from a SeekableReadStream + * @param stream the stream to load + */ + bool load(Common::SeekableReadStream *stream); + + /** + * Close a QuickTime encoded video file + */ + void close(); + + /** + * Returns the palette of the video + * @return the palette of the video + */ + const byte *getPalette() { _dirtyPalette = false; return _palette; } + bool hasDirtyPalette() const { return _dirtyPalette; } + + /** + * Set the beginning offset of the video so we can modify the offsets in the stco + * atom of videos inside the Mohawk archives + * @param the beginning offset of the video + */ + void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; } + + bool isVideoLoaded() const { return _fd != 0; } + const Surface *decodeNextFrame(); + bool endOfVideo() const; + uint32 getElapsedTime() const; + uint32 getTimeToNextFrame() const; + PixelFormat getPixelFormat() const; + + // SeekableVideoDecoder API + void seekToFrame(uint32 frame); + void seekToTime(VideoTimestamp time); + +private: + // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream. + Common::SeekableReadStream *_fd; + + struct MOVatom { + uint32 type; + uint32 offset; + uint32 size; + }; + + struct ParseTable { + int (QuickTimeDecoder::*func)(MOVatom atom); + uint32 type; + }; + + struct MOVstts { + int count; + int duration; + }; + + struct MOVstsc { + uint32 first; + uint32 count; + uint32 id; + }; + + struct STSDEntry { + STSDEntry(); + ~STSDEntry(); + + uint32 codecTag; + uint16 bitsPerSample; + + // Video + char codecName[32]; + uint16 colorTableId; + byte *palette; + Codec *videoCodec; + + // Audio + uint16 channels; + uint32 sampleRate; + uint32 samplesPerFrame; + uint32 bytesPerFrame; + }; + + enum CodecType { + CODEC_TYPE_MOV_OTHER, + CODEC_TYPE_VIDEO, + CODEC_TYPE_AUDIO + }; + + struct MOVStreamContext { + MOVStreamContext(); + ~MOVStreamContext(); + + uint32 chunk_count; + uint32 *chunk_offsets; + int stts_count; + MOVstts *stts_data; + int edit_count; /* number of 'edit' (elst atom) */ + uint32 sample_to_chunk_sz; + MOVstsc *sample_to_chunk; + uint32 sample_size; + uint32 sample_count; + uint32 *sample_sizes; + uint32 keyframe_count; + uint32 *keyframes; + int32 time_scale; + int time_rate; + + uint16 width; + uint16 height; + CodecType codec_type; + + uint32 stsdEntryCount; + STSDEntry *stsdEntries; + + Common::SeekableReadStream *extradata; + + uint32 nb_frames; + uint32 duration; + uint32 start_time; + Common::Rational scaleFactorX; + Common::Rational scaleFactorY; + }; + + const ParseTable *_parseTable; + bool _foundMOOV; + uint32 _timeScale; + uint32 _duration; + uint32 _numStreams; + Common::Rational _scaleFactorX; + Common::Rational _scaleFactorY; + MOVStreamContext *_streams[20]; + const byte *_palette; + bool _dirtyPalette; + uint32 _beginOffset; + Common::MacResManager *_resFork; + + void initParseTable(); + Audio::AudioStream *createAudioStream(Common::SeekableReadStream *stream); + bool checkAudioCodecSupport(uint32 tag); + Common::SeekableReadStream *getNextFramePacket(uint32 &descId); + uint32 getFrameDuration(); + void init(); + + Audio::QueuingAudioStream *_audStream; + void startAudio(); + void stopAudio(); + void updateAudioBuffer(); + void readNextAudioChunk(); + uint32 getAudioChunkSampleCount(uint chunk); + int8 _audioStreamIndex; + uint _curAudioChunk; + Audio::SoundHandle _audHandle; + VideoTimestamp _audioStartOffset; + + Codec *createCodec(uint32 codecTag, byte bitsPerPixel); + Codec *findDefaultVideoCodec() const; + uint32 _nextFrameStartTime; + int8 _videoStreamIndex; + uint32 findKeyFrame(uint32 frame) const; + + Surface *_scaledSurface; + const Surface *scaleSurface(const Surface *frame); + Common::Rational getScaleFactorX() const; + Common::Rational getScaleFactorY() const; + + void pauseVideoIntern(bool pause); + + int readDefault(MOVatom atom); + int readLeaf(MOVatom atom); + int readELST(MOVatom atom); + int readHDLR(MOVatom atom); + int readMDHD(MOVatom atom); + int readMOOV(MOVatom atom); + int readMVHD(MOVatom atom); + int readTKHD(MOVatom atom); + int readTRAK(MOVatom atom); + int readSTCO(MOVatom atom); + int readSTSC(MOVatom atom); + int readSTSD(MOVatom atom); + int readSTSS(MOVatom atom); + int readSTSZ(MOVatom atom); + int readSTTS(MOVatom atom); + int readCMOV(MOVatom atom); + int readWAVE(MOVatom atom); +}; + +} // End of namespace Graphics + +#endif |