9#define GST_DISABLE_DEPRECATED
11#include <gst/gstpad.h>
12#include <gst/video/video.h>
14#include <condition_variable>
19#define GST_USE_UNSTABLE_API
76#if GST_VERSION_MAJOR==0
77 virtual GstFlowReturn
preroll_cb(std::shared_ptr<GstBuffer> buffer);
78 virtual GstFlowReturn
buffer_cb(std::shared_ptr<GstBuffer> buffer);
80 virtual GstFlowReturn
preroll_cb(std::shared_ptr<GstSample> buffer);
81 virtual GstFlowReturn
buffer_cb(std::shared_ptr<GstSample> buffer);
95 bool gstHandleMessage(GstBus * bus,
GstMessage * message);
108 mutable gint64 durationNanos;
110 std::condition_variable eosCondition;
114 class ofGstMainLoopThread:
public ofThread{
116 ofGstMainLoopThread()
121 virtual ~ofGstMainLoopThread(){};
124 main_loop = g_main_loop_new (NULL, FALSE);
127 void threadedFunction(){
128 g_main_loop_run (main_loop);
131 GMainLoop * getMainLoop(){
137 g_main_loop_quit(main_loop);
142 GMainLoop *main_loop =
nullptr;
145 static ofGstMainLoopThread * mainLoop;
180#if GST_VERSION_MAJOR>0
199#if GST_VERSION_MAJOR==0
201 GstFlowReturn
preroll_cb(std::shared_ptr<GstBuffer> buffer);
202 GstFlowReturn
buffer_cb(std::shared_ptr<GstBuffer> buffer);
204 GstFlowReturn process_sample(std::shared_ptr<GstSample> sample);
205 GstFlowReturn
preroll_cb(std::shared_ptr<GstSample> buffer);
206 GstFlowReturn
buffer_cb(std::shared_ptr<GstSample> buffer);
215 static gboolean sync_bus_call (GstBus * bus,
GstMessage * msg, gpointer data);
217 bool bHavePixelsChanged;
218 bool bBackPixelsChanged;
220#if GST_VERSION_MAJOR==0
221 std::shared_ptr<GstBuffer> frontBuffer, backBuffer;
223 std::shared_ptr<GstSample> frontBuffer, backBuffer;
224 std::queue<std::shared_ptr<GstSample> > bufferQueue;
234 GstGLDisplay * glDisplay;
235 GstGLContext * glContext;
247#if GST_VERSION_MAJOR==0
248 virtual GstFlowReturn
on_preroll(std::shared_ptr<GstBuffer> buffer){
251 virtual GstFlowReturn
on_buffer(std::shared_ptr<GstBuffer> buffer){
255 virtual GstFlowReturn
on_preroll(std::shared_ptr<GstSample> buffer){
258 virtual GstFlowReturn
on_buffer(std::shared_ptr<GstSample> buffer){
A base class representing a video source.
Definition ofVideoBaseTypes.h:69
Definition ofGstUtils.h:244
virtual void on_eos()
Definition ofGstUtils.h:262
virtual ~ofGstAppSink()
Definition ofGstUtils.h:246
virtual void on_stream_prepared()
Definition ofGstUtils.h:268
virtual bool on_message(GstMessage *msg)
Definition ofGstUtils.h:265
virtual GstFlowReturn on_preroll(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.h:248
virtual GstFlowReturn on_buffer(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.h:251
Definition ofGstUtils.h:33
void setLoopState(ofLoopType state)
Definition ofGstUtils.cpp:503
virtual GstFlowReturn buffer_cb(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.cpp:179
void setVolume(float volume)
Definition ofGstUtils.cpp:498
void setSpeed(float speed)
Definition ofGstUtils.cpp:507
void setFrameByFrame(bool bFrameByFrame)
Definition ofGstUtils.cpp:241
uint64_t getMinLatencyNanos() const
Definition ofGstUtils.cpp:816
ofGstUtils()
Definition ofGstUtils.cpp:100
int64_t getDurationNanos() const
Definition ofGstUtils.cpp:440
ofLoopType getLoopState() const
Definition ofGstUtils.h:59
ofGstAppSink * appsink
Definition ofGstUtils.h:89
float getPosition() const
Definition ofGstUtils.cpp:389
float getDuration() const
Definition ofGstUtils.cpp:436
static GMainLoop * getGstMainLoop()
Definition ofGstUtils.cpp:44
bool isFrameByFrame() const
Definition ofGstUtils.cpp:248
static void startGstMainLoop()
Definition ofGstUtils.cpp:35
virtual ~ofGstUtils()
Definition ofGstUtils.cpp:163
void play()
Definition ofGstUtils.cpp:343
GstElement * getPipeline() const
Definition ofGstUtils.cpp:800
float getSpeed() const
Definition ofGstUtils.cpp:432
static void quitGstMainLoop()
Definition ofGstUtils.cpp:48
bool isPaused() const
Definition ofGstUtils.h:45
virtual void eos_cb()
Definition ofGstUtils.cpp:188
void setSinkListener(ofGstAppSink *appsink)
Definition ofGstUtils.cpp:812
bool setPipelineWithSink(std::string pipeline, std::string sinkname="sink", bool isStream=false)
int64_t getPositionNanos() const
Definition ofGstUtils.cpp:410
bool startPipeline()
Definition ofGstUtils.cpp:252
bool isPlaying() const
Definition ofGstUtils.h:47
virtual GstFlowReturn preroll_cb(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.cpp:168
bool getIsMovieDone() const
Definition ofGstUtils.cpp:454
bool isStream
Definition ofGstUtils.h:90
void stop()
Definition ofGstUtils.cpp:372
void setPosition(float pct)
Definition ofGstUtils.cpp:462
virtual void close()
Definition ofGstUtils.cpp:574
GstElement * getSink() const
Definition ofGstUtils.cpp:804
bool isLoaded() const
Definition ofGstUtils.h:46
GstElement * getGstElementByName(const std::string &name) const
Definition ofGstUtils.cpp:808
bool closing
Definition ofGstUtils.h:91
void setPaused(bool bPause)
Definition ofGstUtils.cpp:350
uint64_t getMaxLatencyNanos() const
Definition ofGstUtils.cpp:827
Definition ofGstUtils.h:156
virtual ~ofGstVideoUtils()
Definition ofGstUtils.cpp:862
ofPixels eventPixels
Definition ofGstUtils.h:213
bool allocate(int w, int h, ofPixelFormat pixelFormat)
Definition ofGstUtils.cpp:1231
GstFlowReturn preroll_cb(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.cpp:1412
ofTexture * getTexture()
Definition ofGstUtils.cpp:899
ofGstVideoUtils()
Definition ofGstUtils.cpp:846
GstFlowReturn process_buffer(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.cpp:1265
void update()
Update the object's state.
Definition ofGstUtils.cpp:911
void reallocateOnNextFrame()
Definition ofGstUtils.cpp:1250
ofEvent< ofEventArgs > eosEvent
Definition ofGstUtils.h:196
float getWidth() const
Definition ofGstUtils.cpp:968
void setCopyPixels(bool copy)
Definition ofGstUtils.cpp:1127
void eos_cb()
Definition ofGstUtils.cpp:1451
ofPixels backPixels
Definition ofGstUtils.h:212
void close()
Close the video source.
Definition ofGstUtils.cpp:866
ofEvent< ofPixels > bufferEvent
Definition ofGstUtils.h:195
bool setPipeline(std::string pipeline, ofPixelFormat pixelFormat=OF_PIXELS_RGB, bool isStream=false, int w=-1, int h=-1)
Definition ofGstUtils.cpp:1131
ofPixels & getPixels()
Get a reference to the underlying ofPixels.
Definition ofGstUtils.cpp:891
ofEvent< ofPixels > prerollEvent
Definition ofGstUtils.h:194
ofPixels pixels
Definition ofGstUtils.h:211
float getHeight() const
Definition ofGstUtils.cpp:964
bool setPixelFormat(ofPixelFormat pixelFormat)
Set the requested ofPixelFormat.
Definition ofGstUtils.cpp:1222
bool isInitialized() const
Determine if the video source is initialized.
Definition ofGstUtils.cpp:883
GstFlowReturn buffer_cb(std::shared_ptr< GstBuffer > buffer)
Definition ofGstUtils.cpp:1432
ofPixelFormat getPixelFormat() const
Definition ofGstUtils.cpp:1227
bool isFrameNew() const
Definition ofGstUtils.cpp:887
A wrapper class for an OpenGL texture.
Definition ofTexture.h:253
A threaded base class with a built in mutex for convenience.
Definition ofThread.h:70
void startThread()
Start the thread.
Definition ofThread.cpp:38
void waitForThread(bool callStopThread=true, long milliseconds=INFINITE_JOIN_TIMEOUT)
Wait for the thread to exit (aka "joining" the thread).
Definition ofThread.cpp:95
struct _GstElement GstElement
Definition ofGstUtils.h:25
struct _GstBuffer GstBuffer
Definition ofGstUtils.h:26
struct _GstMessage GstMessage
Definition ofGstUtils.h:27
ofPixelFormat
Used to represent the available pixel formats.
Definition ofPixels.h:68
@ OF_PIXELS_RGB
An RGB pixel with no alpha channel.
Definition ofPixels.h:83
ofLoopType
Used to represent the available video looping modes.
Definition ofVideoBaseTypes.h:11