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 <memory>
24 #include <boost/optional.hpp>
25 
26 #include "MediaParser.h" // for inheritance
27 #include "ffmpegHeaders.h"
28 #include "Id3Info.h"
29 
30 // Forward declaration
31 namespace gnash {
32  class IOChannel;
33 }
34 
35 namespace gnash {
36 namespace media {
37 namespace ffmpeg {
38 
40 //
44 {
45 public:
46  ExtraAudioInfoFfmpeg(std::uint8_t* nData, size_t nDataSize)
47  :
48  data(nData),
49  dataSize(nDataSize)
50  {
51  }
52  std::uint8_t* data;
53  size_t dataSize;
54 };
55 
57 //
61 {
62 public:
63  ExtraVideoInfoFfmpeg(std::uint8_t* nData, size_t nDataSize)
64  :
65  data(nData),
66  dataSize(nDataSize)
67  {
68  }
69  std::uint8_t* data;
70  size_t dataSize;
71 };
72 
75 {
76 public:
77 
79  //
82  MediaParserFfmpeg(std::unique_ptr<IOChannel> stream);
83 
85 
86  // See dox in MediaParser.h
87  virtual bool seek(std::uint32_t&);
88 
89  // See dox in MediaParser.h
90  virtual bool parseNextChunk();
91 
92  // See dox in MediaParser.h
93  virtual std::uint64_t getBytesLoaded() const;
94 
95  virtual boost::optional<Id3Info> getId3Info() const;
96 
97 private:
98 
101  void initializeParser();
102 
104  //
107  bool parseNextFrame();
108 
110  int readPacket(std::uint8_t* buf, int buf_size);
111 
113  static int readPacketWrapper(void* opaque, std::uint8_t* buf, int buf_size);
114 
116  std::int64_t seekMedia(std::int64_t offset, int whence);
117 
119  static std::int64_t seekMediaWrapper(void *opaque, std::int64_t offset, int whence);
120 
122  AVInputFormat* probeStream();
123 
124  AVInputFormat* _inputFmt;
125 
127  AVFormatContext *_formatCtx;
128 
130  int _videoStreamIndex;
131 
133  AVStream* _videoStream;
134 
136  int _audioStreamIndex;
137 
138  // audio
139  AVStream* _audioStream;
140 
142  AVIOContext* _avIOCxt;
143 
145  //
149  static const size_t byteIOBufferSize = 1024;
150 
151  std::unique_ptr<unsigned char[]> _byteIOBuffer;
152 
154  std::uint64_t _lastParsedPosition;
155 
157  //
160  std::uint16_t SampleFormatToSampleSize(AVSampleFormat fmt);
161 
163  //
164  bool parseVideoFrame(AVPacket& packet);
165 
167  bool parseAudioFrame(AVPacket& packet);
168 
169  boost::optional<Id3Info> _id3Object;
170 };
171 
172 
173 } // gnash.media.ffmpeg namespace
174 } // gnash.media namespace
175 } // namespace gnash
176 
177 #endif // __MEDIAPARSER_FFMPEG_H__
Extra info about a video stream.
Definition: MediaParser.h:379
size_t dataSize
Definition: MediaParserFfmpeg.h:53
std::uint8_t * data
Definition: MediaParserFfmpeg.h:69
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Extra info about an audio stream.
Definition: MediaParser.h:304
FFMPEG based MediaParser.
Definition: MediaParserFfmpeg.h:74
The MediaParser class provides cursor-based access to encoded media frames.
Definition: MediaParser.h:472
ExtraAudioInfoFfmpeg(std::uint8_t *nData, size_t nDataSize)
Definition: MediaParserFfmpeg.h:46
Extra info found in video stream by the parser.
Definition: MediaParserFfmpeg.h:60
ExtraVideoInfoFfmpeg(std::uint8_t *nData, size_t nDataSize)
Definition: MediaParserFfmpeg.h:63
Extra info found in audio stream by the parser.
Definition: MediaParserFfmpeg.h:43
size_t dataSize
Definition: MediaParserFfmpeg.h:70
std::uint8_t * data
Definition: MediaParserFfmpeg.h:52