Gnash
0.8.10
|
00001 // MediaParserGst.h: gstreamer media parsers, for Gnash 00002 // 00003 // Copyright (C) 2008, 2009, 2010, 2011, 2012 00004 // Free Software Foundation, Inc. 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 #ifndef GNASH_MEDIAPARSER_GST_H 00021 #define GNASH_MEDIAPARSER_GST_H 00022 00023 #include <deque> 00024 #include <boost/scoped_array.hpp> 00025 #include <memory> 00026 #include <queue> 00027 #include <gst/gst.h> 00028 #include <boost/optional.hpp> 00029 00030 #include "MediaParser.h" // for inheritance 00031 #include "ClockTime.h" 00032 #include "Id3Info.h" 00033 00034 // Forward declaration 00035 namespace gnash { 00036 class IOChannel; 00037 } 00038 00039 namespace gnash { 00040 namespace media { 00041 namespace gst { 00042 00044 struct ExtraInfoGst : public AudioInfo::ExtraInfo, VideoInfo::ExtraInfo, 00045 boost::noncopyable 00046 { 00047 ExtraInfoGst(GstCaps* gstcaps) 00048 : 00049 caps(gstcaps) 00050 { 00051 gst_caps_ref(caps); 00052 } 00053 00054 ~ExtraInfoGst() 00055 { 00056 gst_caps_unref(caps); 00057 } 00058 00059 GstCaps* caps; 00060 }; 00061 00063 struct EncodedExtraGstData : public EncodedExtraData, boost::noncopyable 00064 { 00065 EncodedExtraGstData(GstBuffer* buf) 00066 : buffer(buf) 00067 { 00068 gst_buffer_ref(buffer); 00069 } 00070 ~EncodedExtraGstData() 00071 { 00072 gst_buffer_unref(buffer); 00073 } 00074 00075 GstBuffer* buffer; 00076 }; 00077 00078 00080 // 00084 class SimpleTimer : public boost::noncopyable 00085 { 00086 public: 00087 SimpleTimer() 00088 : _start_time(clocktime::getTicks()) 00089 { 00090 } 00091 00092 bool expired() const 00093 { 00094 return (clocktime::getTicks() - _start_time) > 1000; 00095 } 00096 00097 private: 00098 boost::uint64_t _start_time; 00099 }; 00100 00101 00102 00104 class MediaParserGst: public MediaParser 00105 { 00106 public: 00107 00109 // 00112 MediaParserGst(std::auto_ptr<IOChannel> stream); 00113 00114 ~MediaParserGst(); 00115 00116 // See dox in MediaParser.h 00117 bool seek(boost::uint32_t&); 00118 00119 // See dox in MediaParser.h 00120 bool parseNextChunk(); 00121 00122 // See dox in MediaParser.h 00123 virtual boost::uint64_t getBytesLoaded() const; 00124 00125 virtual boost::optional<Id3Info> getId3Info() const; 00126 00127 void rememberAudioFrame(EncodedAudioFrame* frame); 00128 void rememberVideoFrame(EncodedVideoFrame* frame); 00129 00130 private: 00131 bool foundAllStreams(); 00132 00133 bool probingConditionsMet(const SimpleTimer& timer); 00134 00135 void link_to_fakesink(GstPad* pad); 00136 00137 static void cb_typefound (GstElement *typefind, guint probability, 00138 GstCaps *caps, gpointer data); 00139 00140 static void cb_pad_added(GstElement* element, 00141 GstPad* new_pad, gpointer user_data); 00142 static void cb_no_more_pads (GstElement* element, gpointer data); 00143 00144 static GstFlowReturn cb_chain_func_audio (GstPad *pad, GstBuffer *buffer); 00145 static GstFlowReturn cb_chain_func_video (GstPad *pad, GstBuffer *buffer); 00146 00147 bool pushGstBuffer(); 00148 bool emitEncodedFrames(); 00149 00150 00151 GstElement* _bin; 00152 GstPad* _srcpad; 00153 GstPad* _audiosink; 00154 GstPad* _videosink; 00155 00156 bool _demux_probe_ended; 00157 00158 std::deque<EncodedAudioFrame*> _enc_audio_frames; 00159 std::deque<EncodedVideoFrame*> _enc_video_frames; 00160 }; 00161 00162 00163 } // gnash.media.gst namespace 00164 } // gnash.media namespace 00165 } // namespace gnash 00166 00167 #endif // __MEDIAPARSER_GST_H__