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__
gnash::media::ffmpeg::ExtraVideoInfoFfmpeg::dataSize
size_t dataSize
Definition: MediaParserFfmpeg.h:70
ffmpegHeaders.h
height
@ height
Definition: klash_part.cpp:329
gnash::media::MediaParser::_audioInfo
std::unique_ptr< AudioInfo > _audioInfo
Info about the audio stream (if any)
Definition: MediaParser.h:659
gnash::media::ffmpeg::ExtraAudioInfoFfmpeg::dataSize
size_t dataSize
Definition: MediaParserFfmpeg.h:53
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::key::i
@ i
Definition: GnashKey.h:155
LOG_ONCE
#define LOG_ONCE(x)
Definition: log.h:49
gnash::media::MediaParser::_parsingComplete
bool _parsingComplete
Whether the parsing is complete or not.
Definition: MediaParser.h:662
gnash::media::MediaParser::startParserThread
void startParserThread()
}@
Definition: MediaParser.cpp:50
gnash::media::ffmpeg::MediaParserFfmpeg
FFMPEG based MediaParser.
Definition: MediaParserFfmpeg.h:75
_
#define _(String)
Definition: log.h:44
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::media::MediaParser
The MediaParser class provides cursor-based access to encoded media frames.
Definition: MediaParser.h:473
gnash::media::ffmpeg::ExtraVideoInfoFfmpeg
Extra info found in video stream by the parser.
Definition: MediaParserFfmpeg.h:61
__FUNCTION__
#define __FUNCTION__
Definition: log.h:437
gnash::media::ffmpeg::MediaParserFfmpeg::parseNextChunk
virtual bool parseNextChunk()
Parse next chunk of input.
Definition: MediaParserFfmpeg.cpp:312
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
Id3Info.h
gnash::media::MediaParser::pushEncodedVideoFrame
void pushEncodedVideoFrame(std::unique_ptr< EncodedVideoFrame > frame)
Push an encoded video frame to buffer.
Definition: MediaParser.cpp:339
fill
VGPaint fill
Definition: testr_gtk.cpp:86
gnash::media::ffmpeg::MediaParserFfmpeg::seek
virtual bool seek(std::uint32_t &)
Seeks to the closest possible position the given position, and returns the new position.
Definition: MediaParserFfmpeg.cpp:98
gnash::media::MediaParser::_stream
std::unique_ptr< IOChannel > _stream
The stream used to access the file.
Definition: MediaParser.h:697
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::media::VideoInfo::ExtraInfo
Extra info about a video stream.
Definition: MediaParser.h:379
gnash::media::ffmpeg::ExtraVideoInfoFfmpeg::data
std::uint8_t * data
Definition: MediaParserFfmpeg.h:69
MediaParser.h
gnash::media::MediaParser::_videoInfo
std::unique_ptr< VideoInfo > _videoInfo
Subclasses must set the following variables:
Definition: MediaParser.h:656
gnash::media::ffmpeg::ExtraAudioInfoFfmpeg::ExtraAudioInfoFfmpeg
ExtraAudioInfoFfmpeg(std::uint8_t *nData, size_t nDataSize)
Definition: MediaParserFfmpeg.h:46
__PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__
Definition: log.h:444
gnash::media::ffmpeg::MediaParserFfmpeg::getBytesLoaded
virtual std::uint64_t getBytesLoaded() const
Return number of bytes parsed so far.
Definition: MediaParserFfmpeg.cpp:319
MediaParserFfmpeg.h
gnash::media::EncodedVideoFrame
An encoded video frame.
Definition: MediaParser.h:403
gnash::media::MediaParser::clearBuffers
void clearBuffers()
Clear the a/v buffers.
Definition: MediaParser.cpp:286
log.h
gnash::media::ffmpeg::MediaParserFfmpeg::MediaParserFfmpeg
MediaParserFfmpeg(std::unique_ptr< IOChannel > stream)
Construct a ffmpeg-based media parser for given stream.
Definition: MediaParserFfmpeg.cpp:324
gnash::media::Id3Info::album
boost::optional< std::string > album
Definition: Id3Info.h:35
gnash::media::ffmpeg::MediaParserFfmpeg::getId3Info
virtual boost::optional< Id3Info > getId3Info() const
Get ID3 data from the parsed stream if it exists.
Definition: MediaParserFfmpeg.cpp:540
gnash::media::ffmpeg::ExtraAudioInfoFfmpeg::data
std::uint8_t * data
Definition: MediaParserFfmpeg.h:52
gnash::media::ffmpeg::MediaParserFfmpeg::~MediaParserFfmpeg
~MediaParserFfmpeg()
Definition: MediaParserFfmpeg.cpp:506
gnash::media::ffmpeg::ExtraAudioInfoFfmpeg
Extra info found in audio stream by the parser.
Definition: MediaParserFfmpeg.h:44
gnash::media::setId3Info
void setId3Info(boost::optional< T > Id3Info::*member, T const &val, boost::optional< Id3Info > &obj)
Set a field of the optional Id3Info.
Definition: Id3Info.h:48
width
@ width
Definition: klash_part.cpp:329
gnash::media::CODEC_TYPE_CUSTOM
@ CODEC_TYPE_CUSTOM
Custom codecs ids.
Definition: MediaParser.h:71
gnash::media::MediaParser::_streamMutex
std::mutex _streamMutex
Definition: MediaParser.h:698
gnash::log_unimpl
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
gnash::media::ffmpeg::ExtraVideoInfoFfmpeg::ExtraVideoInfoFfmpeg
ExtraVideoInfoFfmpeg(std::uint8_t *nData, size_t nDataSize)
Definition: MediaParserFfmpeg.h:63
GnashException.h
gnash::MediaException
An exception from MediaHandler subsystem.
Definition: GnashException.h:50
data
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
IOChannel.h
gnash::media::MediaParser::pushEncodedAudioFrame
void pushEncodedAudioFrame(std::unique_ptr< EncodedAudioFrame > frame)
Push an encoded audio frame to buffer.
Definition: MediaParser.cpp:299
gnash::media::MediaParser::stopParserThread
void stopParserThread()
Stop the parser thread.
Definition: MediaParser.cpp:271
gnash::media::AudioInfo::ExtraInfo
Extra info about an audio stream.
Definition: MediaParser.h:304