Gnash 0.8.10dev
MediaParserFfmpeg.h
Go to the documentation of this file.
00001 // MediaParserFfmpeg.h: FFMEPG media parsers, for Gnash
00002 // 
00003 //   Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_MEDIAPARSER_FFMPEG_H
00020 #define GNASH_MEDIAPARSER_FFMPEG_H
00021 
00022 #include "MediaParser.h" // for inheritance
00023 #include "ffmpegHeaders.h"
00024 
00025 #include <boost/scoped_array.hpp>
00026 #include <memory>
00027 
00028 // Forward declaration
00029 namespace gnash {
00030         class IOChannel;
00031 }
00032 
00033 namespace gnash {
00034 namespace media {
00035 namespace ffmpeg {
00036 
00038 //
00041 class ExtraAudioInfoFfmpeg : public AudioInfo::ExtraInfo
00042 {
00043 public:
00044         ExtraAudioInfoFfmpeg(boost::uint8_t* nData, size_t nDataSize)
00045                 :
00046                 data(nData),
00047                 dataSize(nDataSize)
00048         {
00049         }
00050         boost::uint8_t* data;
00051         size_t dataSize;
00052 };
00053 
00055 //
00058 class ExtraVideoInfoFfmpeg : public VideoInfo::ExtraInfo
00059 {
00060 public:
00061         ExtraVideoInfoFfmpeg(boost::uint8_t* nData, size_t nDataSize)
00062                 :
00063                 data(nData),
00064                 dataSize(nDataSize)
00065         {
00066         }
00067         boost::uint8_t* data;
00068         size_t dataSize;
00069 };
00070 
00072 class MediaParserFfmpeg: public MediaParser
00073 {
00074 public:
00075 
00077         //
00080         MediaParserFfmpeg(std::auto_ptr<IOChannel> stream);
00081 
00082         ~MediaParserFfmpeg();
00083 
00084         // See dox in MediaParser.h
00085         virtual bool seek(boost::uint32_t&);
00086 
00087         // See dox in MediaParser.h
00088         virtual bool parseNextChunk();
00089 
00090         // See dox in MediaParser.h
00091         virtual boost::uint64_t getBytesLoaded() const;
00092 
00093 private:
00094 
00095 #if defined (LIBAVFORMAT_VERSION_INT) && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT( 52, 31, 0 )
00096 
00097         void logMetadataEntry(const char *format, const char* key);
00098 #endif
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 #if !defined (LIBAVFORMAT_VERSION_MAJOR) || LIBAVFORMAT_VERSION_MAJOR < 53
00158         ByteIOContext _byteIOCxt;
00159 #endif
00160 
00162         //
00166         static const size_t byteIOBufferSize = 1024;
00167 
00168         boost::scoped_array<unsigned char> _byteIOBuffer;
00169 
00171         boost::uint64_t _lastParsedPosition;
00172 
00174         //
00177         boost::uint16_t SampleFormatToSampleSize(SampleFormat fmt);
00178 
00180         //
00181         bool parseVideoFrame(AVPacket& packet);
00182 
00184         bool parseAudioFrame(AVPacket& packet);
00185 };
00186 
00187 
00188 } // gnash.media.ffmpeg namespace 
00189 } // gnash.media namespace 
00190 } // namespace gnash
00191 
00192 #endif // __MEDIAPARSER_FFMPEG_H__