ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

video_decoder.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef VIDEO_DECODER_H
00024 #define VIDEO_DECODER_H
00025 
00026 #include "audio/mixer.h"
00027 #include "audio/timestamp.h"    // TODO: Move this to common/ ?
00028 #include "common/array.h"
00029 #include "common/rational.h"
00030 #include "common/str.h"
00031 #include "graphics/pixelformat.h"
00032 
00033 namespace Audio {
00034 class AudioStream;
00035 class RewindableAudioStream;
00036 class SeekableAudioStream;
00037 }
00038 
00039 namespace Common {
00040 class SeekableReadStream;
00041 }
00042 
00043 namespace Graphics {
00044 struct Surface;
00045 }
00046 
00047 namespace Video {
00048 
00052 class VideoDecoder {
00053 public:
00054     VideoDecoder();
00055     virtual ~VideoDecoder() {}
00056 
00058     // Opening/Closing a Video
00060 
00069     virtual bool loadFile(const Common::String &filename);
00070 
00082     virtual bool loadStream(Common::SeekableReadStream *stream) = 0;
00083 
00090     virtual void close();
00091 
00095     bool isVideoLoaded() const;
00096 
00097 
00099     // Playback Control
00101 
00107     void start();
00108 
00114     void stop();
00115 
00129     void setRate(const Common::Rational &rate);
00130 
00134     Common::Rational getRate() const { return _playbackRate; }
00135 
00144     bool isPlaying() const;
00145 
00150     virtual bool isRewindable() const;
00151 
00160     virtual bool rewind();
00161 
00166     virtual bool isSeekable() const;
00167 
00179     bool seek(const Audio::Timestamp &time);
00180 
00187     virtual bool seekToFrame(uint frame);
00188 
00200     void pauseVideo(bool pause);
00201 
00205     bool isPaused() const { return _pauseLevel != 0; }
00206 
00214     void setEndTime(const Audio::Timestamp &endTime);
00215 
00225     void setEndFrame(uint frame);
00226 
00230     Audio::Timestamp getEndTime() const { return _endTime; }
00231 
00232 
00234     // Playback Status
00236 
00241     bool endOfVideo() const;
00242 
00247     int getCurFrame() const;
00248 
00253     uint32 getFrameCount() const;
00254 
00269     uint32 getTime() const;
00270 
00271 
00273     // Video Info
00275 
00285     virtual uint16 getWidth() const;
00286 
00296     virtual uint16 getHeight() const;
00297 
00301     Graphics::PixelFormat getPixelFormat() const;
00302 
00309     virtual Audio::Timestamp getDuration() const;
00310 
00311 
00313     // Frame Decoding
00315 
00322     const byte *getPalette();
00323 
00327     bool hasDirtyPalette() const { return _dirtyPalette; }
00328 
00332     uint32 getTimeToNextFrame() const;
00333 
00339     bool needsUpdate() const;
00340 
00356     virtual const Graphics::Surface *decodeNextFrame();
00357 
00366     void setDefaultHighColorFormat(const Graphics::PixelFormat &format) { _defaultHighColorFormat = format; }
00367 
00378     bool setReverse(bool reverse);
00379 
00397     bool setDitheringPalette(const byte *palette);
00398 
00400     // Audio Control
00402 
00407     byte getVolume() const { return _audioVolume; }
00408 
00416     void setVolume(byte volume);
00417 
00422     int8 getBalance() const { return _audioBalance; }
00423 
00431     void setBalance(int8 balance);
00432 
00436     Audio::Mixer::SoundType getSoundType() const;
00437 
00443     void setSoundType(Audio::Mixer::SoundType soundType);
00444 
00450     bool addStreamFileTrack(const Common::String &baseName);
00451 
00460     bool setAudioTrack(int index);
00461 
00465     uint getAudioTrackCount() const;
00466 
00467 protected:
00472     class Track {
00473     public:
00474         Track();
00475         virtual ~Track() {}
00476 
00480         enum TrackType {
00481             kTrackTypeNone,
00482             kTrackTypeVideo,
00483             kTrackTypeAudio
00484         };
00485 
00489         virtual TrackType getTrackType() const = 0;
00490 
00494         virtual bool endOfTrack() const = 0;
00495 
00502         virtual bool isRewindable() const;
00503 
00512         virtual bool rewind();
00513 
00517         virtual bool isSeekable() const { return false; }
00518 
00524         virtual bool seek(const Audio::Timestamp &time) { return false; }
00525 
00529         void pause(bool shouldPause);
00530 
00534         bool isPaused() const { return _paused; }
00535 
00541         virtual Audio::Timestamp getDuration() const;
00542 
00543     protected:
00547         virtual void pauseIntern(bool shouldPause) {}
00548 
00549     private:
00550         bool _paused;
00551     };
00552 
00556     class VideoTrack : public Track {
00557     public:
00558         VideoTrack() {}
00559         virtual ~VideoTrack() {}
00560 
00561         TrackType getTrackType() const  { return kTrackTypeVideo; }
00562         virtual bool endOfTrack() const;
00563 
00567         virtual uint16 getWidth() const = 0;
00568 
00572         virtual uint16 getHeight() const = 0;
00573 
00577         virtual Graphics::PixelFormat getPixelFormat() const = 0;
00578 
00584         virtual int getCurFrame() const = 0;
00585 
00593         virtual int getFrameCount() const { return 0; }
00594 
00599         virtual uint32 getNextFrameStartTime() const = 0;
00600 
00604         virtual const Graphics::Surface *decodeNextFrame() = 0;
00605 
00609         virtual const byte *getPalette() const { return 0; }
00610 
00614         virtual bool hasDirtyPalette() const { return false; }
00615 
00622         virtual Audio::Timestamp getFrameTime(uint frame) const;
00623 
00632         virtual bool setReverse(bool reverse) { return !reverse; }
00633 
00637         virtual bool isReversed() const { return false; }
00638 
00642         virtual bool canDither() const { return false; }
00643 
00647         virtual void setDither(const byte *palette) {}
00648     };
00649 
00655     class FixedRateVideoTrack : public VideoTrack {
00656     public:
00657         FixedRateVideoTrack() {}
00658         virtual ~FixedRateVideoTrack() {}
00659 
00660         uint32 getNextFrameStartTime() const;
00661         virtual Audio::Timestamp getDuration() const;
00662         Audio::Timestamp getFrameTime(uint frame) const;
00663 
00668         uint getFrameAtTime(const Audio::Timestamp &time) const;
00669 
00670     protected:
00674         virtual Common::Rational getFrameRate() const = 0;
00675     };
00676 
00680     class AudioTrack : public Track {
00681     public:
00682         AudioTrack(Audio::Mixer::SoundType soundType);
00683         virtual ~AudioTrack() {}
00684 
00685         TrackType getTrackType() const { return kTrackTypeAudio; }
00686 
00687         virtual bool endOfTrack() const;
00688 
00692         void start();
00693 
00697         void stop();
00698 
00699         void start(const Audio::Timestamp &limit);
00700 
00704         byte getVolume() const { return _volume; }
00705 
00709         void setVolume(byte volume);
00710 
00714         int8 getBalance() const { return _balance; }
00715 
00719         void setBalance(int8 balance);
00720 
00725         uint32 getRunningTime() const;
00726 
00730         void setMute(bool mute);
00731 
00732     protected:
00733         void pauseIntern(bool shouldPause);
00734 
00738         virtual Audio::AudioStream *getAudioStream() const = 0;
00739 
00740     private:
00741         Audio::SoundHandle _handle;
00742         Audio::Mixer::SoundType _soundType;
00743         byte _volume;
00744         int8 _balance;
00745         bool _muted;
00746     };
00747 
00752     class RewindableAudioTrack : public AudioTrack {
00753     public:
00754         RewindableAudioTrack(Audio::Mixer::SoundType soundType) : AudioTrack(soundType) {}
00755         virtual ~RewindableAudioTrack() {}
00756 
00757         bool isRewindable() const { return true; }
00758         bool rewind();
00759 
00760     protected:
00761         Audio::AudioStream *getAudioStream() const;
00762 
00767         virtual Audio::RewindableAudioStream *getRewindableAudioStream() const = 0;
00768     };
00769 
00774     class SeekableAudioTrack : public AudioTrack {
00775     public:
00776         SeekableAudioTrack(Audio::Mixer::SoundType soundType) : AudioTrack(soundType) {}
00777         virtual ~SeekableAudioTrack() {}
00778 
00779         bool isSeekable() const { return true; }
00780         bool seek(const Audio::Timestamp &time);
00781 
00782         Audio::Timestamp getDuration() const;
00783 
00784     protected:
00785         Audio::AudioStream *getAudioStream() const;
00786 
00791         virtual Audio::SeekableAudioStream *getSeekableAudioStream() const = 0;
00792     };
00793 
00798     class StreamFileAudioTrack : public SeekableAudioTrack {
00799     public:
00800         StreamFileAudioTrack(Audio::Mixer::SoundType soundType);
00801         ~StreamFileAudioTrack();
00802 
00808         bool loadFromFile(const Common::String &baseName);
00809 
00810     protected:
00811         Audio::SeekableAudioStream *_stream;
00812         Audio::SeekableAudioStream *getSeekableAudioStream() const { return _stream; }
00813     };
00814 
00818     void resetPauseStartTime();
00819 
00827     virtual void readNextPacket() {}
00828 
00837     void addTrack(Track *track, bool isExternal = false);
00838 
00844     virtual bool useAudioSync() const { return true; }
00845 
00851     Track *getTrack(uint track);
00852 
00858     const Track *getTrack(uint track) const;
00859 
00866     bool endOfVideoTracks() const;
00867 
00871     Graphics::PixelFormat getDefaultHighColorFormat() const { return _defaultHighColorFormat; }
00872 
00878     VideoTrack *findNextVideoTrack();
00879 
00883     typedef Common::Array<Track *> TrackList;
00884     typedef TrackList::iterator TrackListIterator;
00885 
00889     TrackListIterator getTrackListBegin() { return _internalTracks.begin(); }
00890 
00894     TrackListIterator getTrackListEnd() { return _internalTracks.end(); }
00895 
00899     void eraseTrack(Track *track);
00900 
00908     virtual bool seekIntern(const Audio::Timestamp &time);
00909 
00917     virtual bool supportsAudioTrackSwitching() const { return false; }
00918 
00927     virtual AudioTrack *getAudioTrack(int index) { return 0; }
00928 
00929 private:
00930     // Tracks owned by this VideoDecoder
00931     TrackList _tracks;
00932     TrackList _internalTracks;
00933     TrackList _externalTracks;
00934 
00935     // Current playback status
00936     bool _needsUpdate;
00937     Audio::Timestamp _lastTimeChange, _endTime;
00938     bool _endTimeSet;
00939     Common::Rational _playbackRate;
00940     VideoTrack *_nextVideoTrack;
00941 
00942     // Palette settings from individual tracks
00943     mutable bool _dirtyPalette;
00944     const byte *_palette;
00945 
00946     // Enforcement of not being able to set dither
00947     bool _canSetDither;
00948 
00949     // Default PixelFormat settings
00950     Graphics::PixelFormat _defaultHighColorFormat;
00951 
00952     // Internal helper functions
00953     void stopAudio();
00954     void startAudio();
00955     void startAudioLimit(const Audio::Timestamp &limit);
00956     bool hasFramesLeft() const;
00957     bool hasAudio() const;
00958 
00959     int32 _startTime;
00960     uint32 _pauseLevel;
00961     uint32 _pauseStartTime;
00962     byte _audioVolume;
00963     int8 _audioBalance;
00964     Audio::Mixer::SoundType _soundType;
00965 
00966     AudioTrack *_mainAudioTrack;
00967 };
00968 
00969 } // End of namespace Video
00970 
00971 #endif


Generated on Sat Dec 14 2019 05:00:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge