Gnash
0.8.10
|
00001 // MediaParserFfmpeg.h: FFMEPG media parsers, for Gnash 00002 // 00003 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 00004 // Free Software Foundation, Inc. 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 #ifndef GNASH_MEDIAPARSER_FFMPEG_H 00021 #define GNASH_MEDIAPARSER_FFMPEG_H 00022 00023 #include <boost/scoped_array.hpp> 00024 #include <memory> 00025 #include <boost/optional.hpp> 00026 00027 #include "MediaParser.h" // for inheritance 00028 #include "ffmpegHeaders.h" 00029 #include "Id3Info.h" 00030 00031 // Forward declaration 00032 namespace gnash { 00033 class IOChannel; 00034 } 00035 00036 namespace gnash { 00037 namespace media { 00038 namespace ffmpeg { 00039 00041 // 00044 class ExtraAudioInfoFfmpeg : public AudioInfo::ExtraInfo 00045 { 00046 public: 00047 ExtraAudioInfoFfmpeg(boost::uint8_t* nData, size_t nDataSize) 00048 : 00049 data(nData), 00050 dataSize(nDataSize) 00051 { 00052 } 00053 boost::uint8_t* data; 00054 size_t dataSize; 00055 }; 00056 00058 // 00061 class ExtraVideoInfoFfmpeg : public VideoInfo::ExtraInfo 00062 { 00063 public: 00064 ExtraVideoInfoFfmpeg(boost::uint8_t* nData, size_t nDataSize) 00065 : 00066 data(nData), 00067 dataSize(nDataSize) 00068 { 00069 } 00070 boost::uint8_t* data; 00071 size_t dataSize; 00072 }; 00073 00075 class MediaParserFfmpeg: public MediaParser 00076 { 00077 public: 00078 00080 // 00083 MediaParserFfmpeg(std::auto_ptr<IOChannel> stream); 00084 00085 ~MediaParserFfmpeg(); 00086 00087 // See dox in MediaParser.h 00088 virtual bool seek(boost::uint32_t&); 00089 00090 // See dox in MediaParser.h 00091 virtual bool parseNextChunk(); 00092 00093 // See dox in MediaParser.h 00094 virtual boost::uint64_t getBytesLoaded() const; 00095 00096 virtual boost::optional<Id3Info> getId3Info() const; 00097 00098 private: 00099 00102 void initializeParser(); 00103 00105 // 00109 size_t _nextVideoFrame; 00110 00112 // 00116 size_t _nextAudioFrame; 00117 00119 // 00122 bool parseNextFrame(); 00123 00125 int readPacket(boost::uint8_t* buf, int buf_size); 00126 00128 static int readPacketWrapper(void* opaque, boost::uint8_t* buf, int buf_size); 00129 00131 boost::int64_t seekMedia(boost::int64_t offset, int whence); 00132 00134 static boost::int64_t seekMediaWrapper(void *opaque, boost::int64_t offset, int whence); 00135 00137 AVInputFormat* probeStream(); 00138 00139 AVInputFormat* _inputFmt; 00140 00142 AVFormatContext *_formatCtx; 00143 00145 int _videoStreamIndex; 00146 00148 AVStream* _videoStream; 00149 00151 int _audioStreamIndex; 00152 00153 // audio 00154 AVStream* _audioStream; 00155 00157 ByteIOContext _byteIOCxt; 00158 00160 // 00164 static const size_t byteIOBufferSize = 1024; 00165 00166 boost::scoped_array<unsigned char> _byteIOBuffer; 00167 00169 boost::uint64_t _lastParsedPosition; 00170 00172 // 00175 boost::uint16_t SampleFormatToSampleSize(SampleFormat fmt); 00176 00178 // 00179 bool parseVideoFrame(AVPacket& packet); 00180 00182 bool parseAudioFrame(AVPacket& packet); 00183 00184 boost::optional<Id3Info> _id3Object; 00185 }; 00186 00187 00188 } // gnash.media.ffmpeg namespace 00189 } // gnash.media namespace 00190 } // namespace gnash 00191 00192 #endif // __MEDIAPARSER_FFMPEG_H__