summaryrefslogtreecommitdiff
path: root/rotord/gstvideoloader.h
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-04-23 17:10:11 +0100
committerTim Redfern <tim@herge.(none)>2013-04-23 17:10:11 +0100
commita2c6354640f24db3484ccf486c2c0cbd08808e60 (patch)
tree4378d8eda1f5825a626c4e2472858c4ab8b672a8 /rotord/gstvideoloader.h
parent92d711e58d50a35fb7bdf59b6813c0b63fff673e (diff)
gst underway
Diffstat (limited to 'rotord/gstvideoloader.h')
-rw-r--r--rotord/gstvideoloader.h147
1 files changed, 146 insertions, 1 deletions
diff --git a/rotord/gstvideoloader.h b/rotord/gstvideoloader.h
index 411fe6e..a2dc086 100644
--- a/rotord/gstvideoloader.h
+++ b/rotord/gstvideoloader.h
@@ -1 +1,146 @@
-#include <gst/gstpad.h> \ No newline at end of file
+#include <string>
+#include <iostream>
+
+#include <gst/gstpad.h>
+
+enum ofLoopType{
+ OF_LOOP_NONE=0x01,
+ OF_LOOP_PALINDROME=0x02,
+ OF_LOOP_NORMAL=0x03
+};
+
+class ofGstAppSink;
+typedef struct _GstElement GstElement;
+typedef struct _GstBuffer GstBuffer;
+typedef struct _GstMessage GstMessage;
+
+class ofGstUtils{
+public:
+ ofGstUtils();
+ virtual ~ofGstUtils();
+
+ bool setPipelineWithSink(std::string pipeline, std::string sinkname="sink", bool isStream=false);
+ bool setPipelineWithSink(GstElement * pipeline, GstElement * sink, bool isStream=false);
+
+ void play();
+ void stop();
+ void setPaused(bool bPause);
+ bool isPaused(){return bPaused;}
+ bool isLoaded(){return bLoaded;}
+ bool isPlaying(){return bPlaying;}
+
+ float getPosition();
+ float getSpeed();
+ float getDuration();
+ int64_t getDurationNanos();
+ bool getIsMovieDone();
+
+ void setPosition(float pct);
+ void setVolume(float volume);
+ void setLoopState(ofLoopType state);
+ ofLoopType getLoopState(){return loopMode;}
+ void setSpeed(float speed);
+
+ void setFrameByFrame(bool bFrameByFrame);
+ bool isFrameByFrame();
+
+ GstElement * getPipeline();
+ GstElement * getSink();
+ unsigned long getMinLatencyNanos();
+ unsigned long getMaxLatencyNanos();
+
+ virtual void close();
+
+ void setSinkListener(ofGstAppSink * appsink);
+
+ // callbacks to get called from gstreamer
+ virtual GstFlowReturn preroll_cb(GstBuffer * buffer);
+ virtual GstFlowReturn buffer_cb(GstBuffer * buffer);
+ virtual void eos_cb();
+
+ static void startGstMainLoop();
+protected:
+ ofGstAppSink * appsink;
+ bool isStream;
+
+private:
+ void gstHandleMessage();
+ //void update(ofEventArgs & args);
+ bool startPipeline();
+
+ bool bPlaying;
+ bool bPaused;
+ bool bIsMovieDone;
+ bool bLoaded;
+ bool bFrameByFrame;
+ ofLoopType loopMode;
+
+ GstElement * gstSink;
+ GstElement * gstPipeline;
+
+ float speed;
+ int64_t durationNanos;
+ bool isAppSink;
+};
+
+class ofGstVideoUtils: public ofGstUtils{
+public:
+
+ ofGstVideoUtils();
+ virtual ~ofGstVideoUtils();
+
+ bool setPipeline(std::string pipeline, int bpp=24, bool isStream=false, int w=-1, int h=-1);
+
+ bool allocate(int w, int h, int bpp);
+
+ bool isFrameNew();
+ unsigned char * getPixels();
+ //ofPixelsRef getPixelsRef();
+ void update();
+
+ float getHeight();
+ float getWidth();
+
+ void close();
+
+
+protected:
+ GstFlowReturn preroll_cb(GstBuffer * buffer);
+ GstFlowReturn buffer_cb(GstBuffer * buffer);
+ void eos_cb();
+
+
+ //ofPixels pixels; // 24 bit: rgb
+ //ofPixels backPixels;
+ //ofPixels eventPixels;
+private:
+ bool bIsFrameNew; // if we are new
+ bool bHavePixelsChanged;
+ bool bBackPixelsChanged;
+ //ofMutex mutex;
+ GstBuffer * buffer, *prevBuffer;
+};
+
+
+//-------------------------------------------------
+//----------------------------------------- appsink listener
+//-------------------------------------------------
+
+class ofGstAppSink{
+public:
+ virtual GstFlowReturn on_preroll(GstBuffer * buffer){
+ return GST_FLOW_OK;
+ }
+ virtual GstFlowReturn on_buffer(GstBuffer * buffer){
+ return GST_FLOW_OK;
+ }
+ virtual void on_eos(){}
+
+ // return true to set the message as attended so upstream doesn't try to process it
+ virtual bool on_message(GstMessage* msg){return false;};
+
+ // pings when enough data has arrived to be able to get sink properties
+ virtual void on_stream_prepared(){};
+};
+
+