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

theora_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 #include "common/scummsys.h"    // for USE_THEORADEC
00024 
00025 #ifdef USE_THEORADEC
00026 
00027 #ifndef VIDEO_THEORA_DECODER_H
00028 #define VIDEO_THEORA_DECODER_H
00029 
00030 #include "common/rational.h"
00031 #include "video/video_decoder.h"
00032 #include "audio/mixer.h"
00033 #include "graphics/surface.h"
00034 
00035 #include <theora/theoradec.h>
00036 
00037 #ifdef USE_TREMOR
00038 #include <tremor/ivorbiscodec.h>
00039 #else
00040 #include <vorbis/codec.h>
00041 #endif
00042 
00043 namespace Common {
00044 class SeekableReadStream;
00045 }
00046 
00047 namespace Audio {
00048 class AudioStream;
00049 class QueuingAudioStream;
00050 }
00051 
00052 namespace Video {
00053 
00062 class TheoraDecoder : public VideoDecoder {
00063 public:
00064     TheoraDecoder();
00065     virtual ~TheoraDecoder();
00066 
00071     bool loadStream(Common::SeekableReadStream *stream);
00072     void close();
00073 
00074 protected:
00075     void readNextPacket();
00076 
00077 private:
00078     class TheoraVideoTrack : public VideoTrack {
00079     public:
00080         TheoraVideoTrack(const Graphics::PixelFormat &format, th_info &theoraInfo, th_setup_info *theoraSetup);
00081         ~TheoraVideoTrack();
00082 
00083         bool endOfTrack() const { return _endOfVideo; }
00084         uint16 getWidth() const { return _displaySurface.w; }
00085         uint16 getHeight() const { return _displaySurface.h; }
00086         Graphics::PixelFormat getPixelFormat() const { return _displaySurface.format; }
00087         int getCurFrame() const { return _curFrame; }
00088         uint32 getNextFrameStartTime() const { return (uint32)(_nextFrameStartTime * 1000); }
00089         const Graphics::Surface *decodeNextFrame() { return &_displaySurface; }
00090 
00091         bool decodePacket(ogg_packet &oggPacket);
00092         void setEndOfVideo() { _endOfVideo = true; }
00093 
00094     private:
00095         int _curFrame;
00096         bool _endOfVideo;
00097         Common::Rational _frameRate;
00098         double _nextFrameStartTime;
00099 
00100         Graphics::Surface _surface;
00101         Graphics::Surface _displaySurface;
00102 
00103         th_dec_ctx *_theoraDecode;
00104 
00105         void translateYUVtoRGBA(th_ycbcr_buffer &YUVBuffer);
00106     };
00107 
00108     class VorbisAudioTrack : public AudioTrack {
00109     public:
00110         VorbisAudioTrack(Audio::Mixer::SoundType soundType, vorbis_info &vorbisInfo);
00111         ~VorbisAudioTrack();
00112 
00113         bool decodeSamples();
00114         bool hasAudio() const;
00115         bool needsAudio() const;
00116         void synthesizePacket(ogg_packet &oggPacket);
00117         void setEndOfAudio() { _endOfAudio = true; }
00118 
00119     protected:
00120         Audio::AudioStream *getAudioStream() const;
00121 
00122     private:
00123         // single audio fragment audio buffering
00124         int _audioBufferFill;
00125         ogg_int16_t *_audioBuffer;
00126 
00127         Audio::QueuingAudioStream *_audStream;
00128 
00129         vorbis_block _vorbisBlock;
00130         vorbis_dsp_state _vorbisDSP;
00131 
00132         bool _endOfAudio;
00133     };
00134 
00135     void queuePage(ogg_page *page);
00136     int bufferData();
00137     bool queueAudio();
00138     void ensureAudioBufferSize();
00139 
00140     Common::SeekableReadStream *_fileStream;
00141 
00142     ogg_sync_state _oggSync;
00143     ogg_page _oggPage;
00144     ogg_packet _oggPacket;
00145 
00146     ogg_stream_state _theoraOut, _vorbisOut;
00147     bool _hasVideo, _hasAudio;
00148 
00149     vorbis_info _vorbisInfo;
00150 
00151     TheoraVideoTrack *_videoTrack;
00152     VorbisAudioTrack *_audioTrack;
00153 };
00154 
00155 } // End of namespace Video
00156 
00157 #endif
00158 
00159 #endif


Generated on Sat Feb 16 2019 05:01:09 for ResidualVM by doxygen 1.7.1
curved edge   curved edge