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

mpegps_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_MPEGPS_DECODER_H
00024 #define VIDEO_MPEGPS_DECODER_H
00025 
00026 #include "common/inttypes.h"
00027 #include "common/hashmap.h"
00028 #include "common/queue.h"
00029 #include "graphics/surface.h"
00030 #include "video/video_decoder.h"
00031 
00032 namespace Audio {
00033 class PacketizedAudioStream;
00034 }
00035 
00036 namespace Common {
00037 class SeekableReadStream;
00038 }
00039 
00040 namespace Graphics {
00041 struct PixelFormat;
00042 }
00043 
00044 namespace Image {
00045 class MPEGDecoder;
00046 }
00047 
00048 namespace Video {
00049 
00055 class MPEGPSDecoder : public VideoDecoder {
00056 public:
00057     MPEGPSDecoder();
00058     virtual ~MPEGPSDecoder();
00059 
00060     bool loadStream(Common::SeekableReadStream *stream);
00061     void close();
00062 
00063 protected:
00064     void readNextPacket();
00065     bool useAudioSync() const { return false; }
00066 
00067 private:
00068     class MPEGPSDemuxer {
00069     public:
00070         MPEGPSDemuxer();
00071         ~MPEGPSDemuxer();
00072 
00073         bool loadStream(Common::SeekableReadStream *stream);
00074         void close();
00075 
00076         Common::SeekableReadStream *getFirstVideoPacket(int32 &startCode, uint32 &pts, uint32 &dts);
00077         Common::SeekableReadStream *getNextPacket(uint32 currentTime, int32 &startCode, uint32 &pts, uint32 &dts);
00078 
00079     private:
00080         class Packet {
00081         public:
00082             Packet(Common::SeekableReadStream *stream, int32 startCode, uint32 pts, uint32 dts) : _stream(stream), _startCode(startCode), _pts(pts), _dts(dts) {}
00083 
00084             Common::SeekableReadStream *_stream;
00085             int32 _startCode;
00086             uint32 _pts;
00087             uint32 _dts;
00088         };
00089         bool queueNextPacket();
00090         bool fillQueues();
00091         int readNextPacketHeader(int32 &startCode, uint32 &pts, uint32 &dts);
00092         int findNextStartCode(uint32 &size);
00093         uint32 readPTS(int c);
00094         void parseProgramStreamMap(int length);
00095 
00096         Common::SeekableReadStream *_stream;
00097         Common::Queue<Packet> _videoQueue;
00098         Common::Queue<Packet> _audioQueue;
00099     };
00100 
00101     // Base class for handling MPEG streams
00102     class MPEGStream {
00103     public:
00104         virtual ~MPEGStream() {}
00105 
00106         enum StreamType {
00107             kStreamTypeVideo,
00108             kStreamTypeAudio
00109         };
00110 
00111         virtual bool sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts) = 0;
00112         virtual StreamType getStreamType() const = 0;
00113     };
00114 
00115     // An MPEG 1/2 video track
00116     class MPEGVideoTrack : public VideoTrack, public MPEGStream {
00117     public:
00118         MPEGVideoTrack(Common::SeekableReadStream *firstPacket, const Graphics::PixelFormat &format);
00119         ~MPEGVideoTrack();
00120 
00121         bool endOfTrack() const { return _endOfTrack; }
00122         uint16 getWidth() const;
00123         uint16 getHeight() const;
00124         Graphics::PixelFormat getPixelFormat() const;
00125         int getCurFrame() const { return _curFrame; }
00126         uint32 getNextFrameStartTime() const { return _nextFrameStartTime.msecs(); }
00127         const Graphics::Surface *decodeNextFrame();
00128 
00129         bool sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts);
00130         StreamType getStreamType() const { return kStreamTypeVideo; }
00131 
00132         void setEndOfTrack() { _endOfTrack = true; }
00133 
00134     private:
00135         bool _endOfTrack;
00136         int _curFrame;
00137         uint32 _framePts;
00138         Audio::Timestamp _nextFrameStartTime;
00139         Graphics::Surface *_surface;
00140 
00141         void findDimensions(Common::SeekableReadStream *firstPacket, const Graphics::PixelFormat &format);
00142 
00143 #ifdef USE_MPEG2
00144         Image::MPEGDecoder *_mpegDecoder;
00145 #endif
00146     };
00147 
00148 #ifdef USE_MAD
00149     // An MPEG audio track
00150     class MPEGAudioTrack : public AudioTrack, public MPEGStream {
00151     public:
00152         MPEGAudioTrack(Common::SeekableReadStream &firstPacket, Audio::Mixer::SoundType soundType);
00153         ~MPEGAudioTrack();
00154 
00155         bool sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts);
00156         StreamType getStreamType() const { return kStreamTypeAudio; }
00157 
00158     protected:
00159         Audio::AudioStream *getAudioStream() const;
00160 
00161     private:
00162         Audio::PacketizedAudioStream *_audStream;
00163     };
00164 #endif
00165 
00166 #ifdef USE_A52
00167     class AC3AudioTrack : public AudioTrack, public MPEGStream {
00168     public:
00169         AC3AudioTrack(Common::SeekableReadStream &firstPacket, Audio::Mixer::SoundType soundType);
00170         ~AC3AudioTrack();
00171 
00172         bool sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts);
00173         StreamType getStreamType() const { return kStreamTypeAudio; }
00174 
00175     protected:
00176         Audio::AudioStream *getAudioStream() const;
00177 
00178     private:
00179         Audio::PacketizedAudioStream *_audStream;
00180     };
00181 #endif
00182 
00183 // ResidualVM specific start
00184     class PS2AudioTrack : public AudioTrack, public MPEGStream {
00185     public:
00186         PS2AudioTrack(Common::SeekableReadStream *firstPacket, Audio::Mixer::SoundType soundType);
00187         ~PS2AudioTrack();
00188 
00189         bool sendPacket(Common::SeekableReadStream *packet, uint32 pts, uint32 dts);
00190         StreamType getStreamType() const { return kStreamTypeAudio; }
00191 
00192     protected:
00193         Audio::AudioStream *getAudioStream() const;
00194 
00195     private:
00196         Audio::PacketizedAudioStream *_audStream;
00197 
00198         enum {
00199             PS2_PCM = 0x01,
00200             PS2_ADPCM = 0x10
00201         };
00202 
00203         uint32 _channels;
00204         uint32 _soundType;
00205         uint32 _interleave;
00206         bool _isFirstPacket;
00207 
00208         byte *_blockBuffer;
00209         uint32 _blockPos, _blockUsed;
00210 
00211         uint32 calculateSampleCount(uint32 packetSize) const;
00212     };
00213 // ResidualVM specific end
00214 
00215     // The different types of private streams we can detect at the moment
00216     enum PrivateStreamType {
00217         kPrivateStreamUnknown,
00218         kPrivateStreamAC3,
00219         kPrivateStreamDTS,
00220         kPrivateStreamDVDPCM,
00221         kPrivateStreamPS2Audio
00222     };
00223 
00224     PrivateStreamType detectPrivateStreamType(Common::SeekableReadStream *packet);
00225 
00226     bool addFirstVideoTrack();
00227     MPEGStream *getStream(uint32 startCode, Common::SeekableReadStream *packet);
00228 
00229     MPEGPSDemuxer *_demuxer;
00230 
00231     // A map from stream types to stream handlers
00232     typedef Common::HashMap<int, MPEGStream *> StreamMap;
00233     StreamMap _streamMap;
00234 };
00235 
00236 } // End of namespace Video
00237 
00238 #endif


Generated on Sat Mar 16 2019 05:01:47 for ResidualVM by doxygen 1.7.1
curved edge   curved edge