Gnash  0.8.11dev
MediaParserGst.h
Go to the documentation of this file.
1 // MediaParserGst.h: gstreamer media parsers, for Gnash
2 //
3 // Copyright (C) 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_GST_H
21 #define GNASH_MEDIAPARSER_GST_H
22 
23 #include <deque>
24 #include <memory>
25 #include <queue>
26 #include <gst/gst.h>
27 #include <boost/optional.hpp>
28 #include <boost/utility.hpp> // noncopyable
29 
30 #include "MediaParser.h" // for inheritance
31 #include "ClockTime.h"
32 #include "Id3Info.h"
33 
34 // Forward declaration
35 namespace gnash {
36  class IOChannel;
37 }
38 
39 namespace gnash {
40 namespace media {
41 namespace gst {
42 
45  boost::noncopyable
46 {
47  ExtraInfoGst(GstCaps* gstcaps)
48  :
49  caps(gstcaps)
50  {
51  gst_caps_ref(caps);
52  }
53 
55  {
56  gst_caps_unref(caps);
57  }
58 
59  GstCaps* caps;
60 };
61 
63 struct EncodedExtraGstData : public EncodedExtraData, boost::noncopyable
64 {
65  EncodedExtraGstData(GstBuffer* buf)
66  : buffer(buf)
67  {
68  gst_buffer_ref(buffer);
69  }
71  {
72  gst_buffer_unref(buffer);
73  }
74 
75  GstBuffer* buffer;
76 };
77 
78 
80 //
84 class SimpleTimer : public boost::noncopyable
85 {
86 public:
88  : _start_time(clocktime::getTicks())
89  {
90  }
91 
92  bool expired() const
93  {
94  return (clocktime::getTicks() - _start_time) > 1000;
95  }
96 
97 private:
98  std::uint64_t _start_time;
99 };
100 
101 
102 
105 {
106 public:
107 
109  //
112  MediaParserGst(std::unique_ptr<IOChannel> stream);
113 
114  ~MediaParserGst();
115 
116  // See dox in MediaParser.h
117  bool seek(std::uint32_t&);
118 
119  // See dox in MediaParser.h
120  bool parseNextChunk();
121 
122  // See dox in MediaParser.h
123  virtual std::uint64_t getBytesLoaded() const;
124 
125  virtual boost::optional<Id3Info> getId3Info() const;
126 
129 
130 private:
131  void link_to_fakesink(GstPad* pad);
132 
133  static void cb_typefound (GstElement *typefind, guint probability,
134  GstCaps *caps, gpointer data);
135 
136  static void cb_pad_added(GstElement* element,
137  GstPad* new_pad, gpointer user_data);
138  static void cb_no_more_pads (GstElement* element, gpointer data);
139 
140  static GstFlowReturn cb_chain_func_audio (GstPad *pad, GstBuffer *buffer);
141  static GstFlowReturn cb_chain_func_video (GstPad *pad, GstBuffer *buffer);
142 
143  bool pushGstBuffer();
144  bool emitEncodedFrames();
145 
146 
147  GstElement* _bin;
148  GstPad* _srcpad;
149  GstPad* _audiosink;
150  GstPad* _videosink;
151 
152  bool _demux_probe_ended;
153 
154  std::deque<EncodedAudioFrame*> _enc_audio_frames;
155  std::deque<EncodedVideoFrame*> _enc_video_frames;
156 };
157 
158 
159 } // gnash.media.gst namespace
160 } // gnash.media namespace
161 } // namespace gnash
162 
163 #endif // __MEDIAPARSER_GST_H__
swfdec_gst_connect_sinkpad_by_pad
GstPad * swfdec_gst_connect_sinkpad_by_pad(GstPad *srcpad, GstCaps *caps)
Definition: swfdec_codec_gst.c:199
gnash::media::gst::EncodedExtraGstData::buffer
GstBuffer * buffer
Definition: MediaParserGst.h:75
gnash::media::gst::ExtraInfoGst::caps
GstCaps * caps
Definition: MediaParserGst.h:59
gnash::GnashException
Top-level gnash exception.
Definition: GnashException.h:31
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::media::gst::ExtraInfoGst::~ExtraInfoGst
~ExtraInfoGst()
Definition: MediaParserGst.h:54
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::gst::EncodedExtraGstData::EncodedExtraGstData
EncodedExtraGstData(GstBuffer *buf)
Definition: MediaParserGst.h:65
_
#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::EncodedExtraData
Definition: MediaParser.h:394
gnash::media::gst::MediaParserGst::~MediaParserGst
~MediaParserGst()
Definition: MediaParserGst.cpp:82
gnash::media::EncodedAudioFrame
An encoded audio frame.
Definition: MediaParser.h:454
gnash::media::MediaParser::_bytesLoaded
std::atomic< std::uint_fast64_t > _bytesLoaded
Number of bytes loaded.
Definition: MediaParser.h:665
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
Id3Info.h
swfdec_gst_get_parser_factory
GstElementFactory * swfdec_gst_get_parser_factory(GstCaps *caps)
Definition: swfdec_codec_gst.c:163
gnash::media::gst::MediaParserGst
Gstreamer based MediaParser.
Definition: MediaParserGst.h:105
gnash::media::MediaParser::pushEncodedVideoFrame
void pushEncodedVideoFrame(std::unique_ptr< EncodedVideoFrame > frame)
Push an encoded video frame to buffer.
Definition: MediaParser.cpp:339
gnash::clocktime::getTicks
DSOEXPORT std::uint64_t getTicks()
Wall clock timer, returns current POSIX time in milliseconds.
Definition: ClockTime.cpp:61
ClockTime.h
gnash::media::gst::EncodedExtraGstData
Class to hold GstBuffer. Takes ownership.
Definition: MediaParserGst.h:64
gnash::media::gst::MediaParserGst::seek
bool seek(std::uint32_t &)
Seeks to the closest possible position the given position, and returns the new position.
Definition: MediaParserGst.cpp:109
gnash::media::gst::SimpleTimer::expired
bool expired() const
Definition: MediaParserGst.h:92
PUSHBUF_SIZE
#define PUSHBUF_SIZE
Definition: MediaParserGst.cpp:33
gnash::media::gst::MediaParserGst::MediaParserGst
MediaParserGst(std::unique_ptr< IOChannel > stream)
Construct a Gstreamer-based media parser for given stream.
Definition: MediaParserGst.cpp:42
gnash::media::gst::ExtraInfoGst
Class to hold extra info found in any stream by the parser.
Definition: MediaParserGst.h:46
MediaParserGst.h
gnash::media::gst::SimpleTimer::SimpleTimer
SimpleTimer()
Definition: MediaParserGst.h:87
gnash::media::gst::MediaParserGst::getBytesLoaded
virtual std::uint64_t getBytesLoaded() const
Return number of bytes parsed so far.
Definition: MediaParserGst.cpp:150
gnash::media::MediaParser::_stream
std::unique_ptr< IOChannel > _stream
The stream used to access the file.
Definition: MediaParser.h:697
gnash::media::VideoInfo::ExtraInfo
Extra info about a video stream.
Definition: MediaParser.h:379
MediaParser.h
gnash::media::gst::MediaParserGst::parseNextChunk
bool parseNextChunk()
Parse next chunk of input.
Definition: MediaParserGst.cpp:123
swfdec_gst_connect_srcpad
GstPad * swfdec_gst_connect_srcpad(GstElement *element, GstCaps *caps)
Definition: swfdec_codec_gst.c:172
gnash::media::EncodedVideoFrame
An encoded video frame.
Definition: MediaParser.h:403
gst
gnash::media::gst::EncodedExtraGstData::~EncodedExtraGstData
~EncodedExtraGstData()
Definition: MediaParserGst.h:70
log.h
gnash::media::gst::MediaParserGst::getId3Info
virtual boost::optional< Id3Info > getId3Info() const
Get ID3 data from the parsed stream if it exists.
Definition: MediaParserGst.cpp:117
swfdec_gst_get_demuxer_factory
GstElementFactory * swfdec_gst_get_demuxer_factory(GstCaps *caps)
Definition: swfdec_codec_gst.c:157
swfdec_codec_gst.h
gnash::equal
bool equal(string_table &st, string_table::key a, string_table::key b, bool caseless)
Check whether two keys are equivalent.
Definition: string_table.cpp:174
gnash::media::gst::SimpleTimer
Simple timer used for probe timeout (deprecated)
Definition: MediaParserGst.h:85
GstUtil.h
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
GST_TIME_AS_MSECONDS
#define GST_TIME_AS_MSECONDS(time)
Definition: GstUtil.h:29
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::gst::MediaParserGst::rememberAudioFrame
void rememberAudioFrame(EncodedAudioFrame *frame)
Definition: MediaParserGst.cpp:211
gnash::media::gst::MediaParserGst::rememberVideoFrame
void rememberVideoFrame(EncodedVideoFrame *frame)
Definition: MediaParserGst.cpp:217
gnash::media::AudioInfo::ExtraInfo
Extra info about an audio stream.
Definition: MediaParser.h:304
gnash::media::gst::ExtraInfoGst::ExtraInfoGst
ExtraInfoGst(GstCaps *gstcaps)
Definition: MediaParserGst.h:47