Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_MEDIAPARSER_GST_H
00020 #define GNASH_MEDIAPARSER_GST_H
00021
00022 #include "MediaParser.h"
00023
00024 #include <deque>
00025 #include <boost/scoped_array.hpp>
00026 #include <memory>
00027 #include <queue>
00028
00029 #include <gst/gst.h>
00030 #include "ClockTime.h"
00031
00032
00033
00034 namespace gnash {
00035 class IOChannel;
00036 }
00037
00038 namespace gnash {
00039 namespace media {
00040 namespace gst {
00041
00043 struct ExtraInfoGst : public AudioInfo::ExtraInfo, VideoInfo::ExtraInfo,
00044 boost::noncopyable
00045 {
00046 ExtraInfoGst(GstCaps* gstcaps)
00047 :
00048 caps(gstcaps)
00049 {
00050 gst_caps_ref(caps);
00051 }
00052
00053 ~ExtraInfoGst()
00054 {
00055 gst_caps_unref(caps);
00056 }
00057
00058 GstCaps* caps;
00059 };
00060
00062 struct EncodedExtraGstData : public EncodedExtraData, boost::noncopyable
00063 {
00064 EncodedExtraGstData(GstBuffer* buf)
00065 : buffer(buf)
00066 {
00067 gst_buffer_ref(buffer);
00068 }
00069 ~EncodedExtraGstData()
00070 {
00071 gst_buffer_unref(buffer);
00072 }
00073
00074 GstBuffer* buffer;
00075 };
00076
00077
00079
00083 class SimpleTimer : public boost::noncopyable
00084 {
00085 public:
00086 SimpleTimer()
00087 : _start_time(clocktime::getTicks())
00088 {
00089 }
00090
00091 bool expired() const
00092 {
00093 return (clocktime::getTicks() - _start_time) > 1000;
00094 }
00095
00096 private:
00097 boost::uint64_t _start_time;
00098 };
00099
00100
00101
00103 class MediaParserGst: public MediaParser
00104 {
00105 public:
00106
00108
00111 MediaParserGst(std::auto_ptr<IOChannel> stream);
00112
00113 ~MediaParserGst();
00114
00115
00116 bool seek(boost::uint32_t&);
00117
00118
00119 bool parseNextChunk();
00120
00121
00122 boost::uint64_t getBytesLoaded() const;
00123
00124 void rememberAudioFrame(EncodedAudioFrame* frame);
00125 void rememberVideoFrame(EncodedVideoFrame* frame);
00126
00127 private:
00128 bool foundAllStreams();
00129
00130 bool probingConditionsMet(const SimpleTimer& timer);
00131
00132 void link_to_fakesink(GstPad* pad);
00133
00134 static void cb_typefound (GstElement *typefind, guint probability,
00135 GstCaps *caps, gpointer data);
00136
00137 static void cb_pad_added(GstElement* element,
00138 GstPad* new_pad, gpointer user_data);
00139 static void cb_no_more_pads (GstElement* element, gpointer data);
00140
00141 static GstFlowReturn cb_chain_func_audio (GstPad *pad, GstBuffer *buffer);
00142 static GstFlowReturn cb_chain_func_video (GstPad *pad, GstBuffer *buffer);
00143
00144 bool pushGstBuffer();
00145 void emitEncodedFrames();
00146
00147
00148 GstElement* _bin;
00149 GstPad* _srcpad;
00150 GstPad* _audiosink;
00151 GstPad* _videosink;
00152
00153 bool _demux_probe_ended;
00154
00155 std::deque<EncodedAudioFrame*> _enc_audio_frames;
00156 std::deque<EncodedVideoFrame*> _enc_video_frames;
00157 };
00158
00159
00160 }
00161 }
00162 }
00163
00164 #endif // __MEDIAPARSER_GST_H__