|
TobiiGlasses2SDK
|
00001 /****************************************************** 00002 * This is a wrapper for GStreamer-0.10 * 00003 * This will ensure an easy access to the GStreamer * 00004 * API * 00005 * Author: Pierre-Marie Plans * 00006 * E-mail: pierre.plans@gmail.com * 00007 ******************************************************/ 00008 00009 #ifndef STREAMER_H_ 00010 #define STREAMER_H_ 00011 00012 #include <string> 00013 #include <functional> 00014 #include <string.h> 00015 #include <opencv2/opencv.hpp> 00016 #include <gst/gst.h> 00017 #include <gst/app/gstappsink.h> 00018 00027 // GSTREAMER 00028 // http://blog.nicolargo.com/2009/03/gstreamer-la-theorie.html 00029 // http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/index.html 00030 // http://benow.ca/docs/gstreamer-manual.pdf 00031 // http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-programs.html 00032 // http://gstreamer-devel.966125.n4.nabble.com/udpsrc-performance-td4655463.html 00040 typedef struct _CustomData { 00041 gboolean is_live; 00042 GstElement *pipeline; 00043 GstElement *appsink; 00044 GMainLoop *loop; 00045 GstMapInfo *info; 00046 IplImage *frame; 00047 std::function< void(cv::Mat &, const int64_t) > 00048 videoCallback; 00050 std::function< void(const int64_t, cv::Mat &) > onFrameArrived; 00051 } CustomData; 00052 00061 class Streamer { 00062 GstElement * m_pipeline; 00063 CustomData m_data; 00064 bool m_isRunning; 00065 public: 00069 Streamer(); 00073 ~Streamer(); 00083 void init(int argc, char ** argv); 00092 int setupPipeline(const std::string & pipeline); 00100 void configureSrcSockFD(int sockfd); 00108 void setVideoCallback(std::function< void(cv::Mat &, const int64_t) >); 00116 void setOnFrameArrived(std::function< void(const int64_t, cv::Mat &) > func); 00123 void run(); 00131 void runCV(); 00137 void stop(); 00145 bool isRunning(); 00146 }; 00147 /* The appsink has received a buffer */ 00159 static GstFlowReturn cb_new_sample(GstElement *sink, CustomData *data); 00160 00173 void cb_message(GstBus *bus, GstMessage *msg, CustomData *data); 00174 00175 #endif
1.7.6.1