Gnash  0.8.11dev
MediaParserFfmpeg.h
Go to the documentation of this file.
1 // MediaParserFfmpeg.h: FFMEPG media parsers, for Gnash
2 //
3 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #ifndef GNASH_MEDIAPARSER_FFMPEG_H
21 #define GNASH_MEDIAPARSER_FFMPEG_H
22 
23 #include <boost/scoped_array.hpp>
24 #include <memory>
25 #include <boost/optional.hpp>
26 
27 #include "MediaParser.h" // for inheritance
28 #include "ffmpegHeaders.h"
29 #include "Id3Info.h"
30 
31 // Forward declaration
32 namespace gnash {
33  class IOChannel;
34 }
35 
36 namespace gnash {
37 namespace media {
38 namespace ffmpeg {
39 
41 //
45 {
46 public:
47  ExtraAudioInfoFfmpeg(boost::uint8_t* nData, size_t nDataSize)
48  :
49  data(nData),
50  dataSize(nDataSize)
51  {
52  }
53  boost::uint8_t* data;
54  size_t dataSize;
55 };
56 
58 //
62 {
63 public:
64  ExtraVideoInfoFfmpeg(boost::uint8_t* nData, size_t nDataSize)
65  :
66  data(nData),
67  dataSize(nDataSize)
68  {
69  }
70  boost::uint8_t* data;
71  size_t dataSize;
72 };
73 
76 {
77 public:
78 
80  //
83  MediaParserFfmpeg(std::auto_ptr<IOChannel> stream);
84 
86 
87  // See dox in MediaParser.h
88  virtual bool seek(boost::uint32_t&);
89 
90  // See dox in MediaParser.h
91  virtual bool parseNextChunk();
92 
93  // See dox in MediaParser.h
94  virtual boost::uint64_t getBytesLoaded() const;
95 
96  virtual boost::optional<Id3Info> getId3Info() const;
97 
98 private:
99 
102  void initializeParser();
103 
105  //
109  size_t _nextVideoFrame;
110 
112  //
116  size_t _nextAudioFrame;
117 
119  //
122  bool parseNextFrame();
123 
125  int readPacket(boost::uint8_t* buf, int buf_size);
126 
128  static int readPacketWrapper(void* opaque, boost::uint8_t* buf, int buf_size);
129 
131  boost::int64_t seekMedia(boost::int64_t offset, int whence);
132 
134  static boost::int64_t seekMediaWrapper(void *opaque, boost::int64_t offset, int whence);
135 
137  AVInputFormat* probeStream();
138 
139  AVInputFormat* _inputFmt;
140 
142  AVFormatContext *_formatCtx;
143 
145  int _videoStreamIndex;
146 
148  AVStream* _videoStream;
149 
151  int _audioStreamIndex;
152 
153  // audio
154  AVStream* _audioStream;
155 
157  ByteIOContext _byteIOCxt;
158 
160  //
164  static const size_t byteIOBufferSize = 1024;
165 
166  boost::scoped_array<unsigned char> _byteIOBuffer;
167 
169  boost::uint64_t _lastParsedPosition;
170 
172  //
175  boost::uint16_t SampleFormatToSampleSize(SampleFormat fmt);
176 
178  //
179  bool parseVideoFrame(AVPacket& packet);
180 
182  bool parseAudioFrame(AVPacket& packet);
183 
184  boost::optional<Id3Info> _id3Object;
185 };
186 
187 
188 } // gnash.media.ffmpeg namespace
189 } // gnash.media namespace
190 } // namespace gnash
191 
192 #endif // __MEDIAPARSER_FFMPEG_H__