diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-04-23 17:10:11 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-04-23 17:10:11 +0100 |
| commit | a2c6354640f24db3484ccf486c2c0cbd08808e60 (patch) | |
| tree | 4378d8eda1f5825a626c4e2472858c4ab8b672a8 /rotord/gstvideoloader.cpp | |
| parent | 92d711e58d50a35fb7bdf59b6813c0b63fff673e (diff) | |
gst underway
Diffstat (limited to 'rotord/gstvideoloader.cpp')
| -rw-r--r-- | rotord/gstvideoloader.cpp | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/rotord/gstvideoloader.cpp b/rotord/gstvideoloader.cpp index e69de29..495181f 100644 --- a/rotord/gstvideoloader.cpp +++ b/rotord/gstvideoloader.cpp @@ -0,0 +1,167 @@ +#include "gstvideoloader.h" + +#include <gst/gst.h> +#include <gst/app/gstappsink.h> +#include <gst/video/video.h> + +#include <glib-object.h> +#include <glib.h> +#include <algorithm> + +using namespace std; + + + +void ofGstUtils::startGstMainLoop(){ + static bool initialized = false; + if(!initialized){ + g_main_loop_new (NULL, FALSE); + initialized=true; + } +} + +//------------------------------------------------- +//----------------------------------------- gstUtils +//------------------------------------------------- + +static bool plugin_registered = false; +static bool gst_inited = false; + + +// called when the appsink notifies us that there is a new buffer ready for +// processing + +static GstFlowReturn on_new_buffer_from_source (GstAppSink * elt, void * data){ + GstBuffer *buffer = gst_app_sink_pull_buffer (GST_APP_SINK (elt)); + return ((ofGstUtils*)data)->buffer_cb(buffer); +} + +static GstFlowReturn on_new_preroll_from_source (GstAppSink * elt, void * data){ + GstBuffer *buffer = gst_app_sink_pull_preroll(GST_APP_SINK (elt)); + return ((ofGstUtils*)data)->preroll_cb(buffer); +} + +static void on_eos_from_source (GstAppSink * elt, void * data){ + ((ofGstUtils*)data)->eos_cb(); +} + +static gboolean appsink_plugin_init (GstPlugin * plugin) +{ + gst_element_register (plugin, "appsink", GST_RANK_NONE, GST_TYPE_APP_SINK); + + return TRUE; +} + + +ofGstUtils::ofGstUtils() { + bLoaded = false; + speed = 1; + bPaused = false; + bIsMovieDone = false; + bPlaying = false; + loopMode = OF_LOOP_NONE; + bFrameByFrame = false; + + gstPipeline = NULL; + gstSink = NULL; + + durationNanos = 0; + + isAppSink = false; + isStream = false; + + appsink = NULL; + + if(!g_thread_supported()){ + g_thread_init(NULL); + } + if(!gst_inited){ + gst_init (NULL, NULL); + gst_inited=true; + cerr <<"ofGstUtils: gstreamer inited"<<endl; + } + if(!plugin_registered){ + gst_plugin_register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, + "appsink", (char*)"Element application sink", + appsink_plugin_init, "0.1", "LGPL", "ofVideoPlayer", "openFrameworks", + "http://openframeworks.cc/"); + plugin_registered=true; + } + +} + +ofGstUtils::~ofGstUtils() { + close(); +} + +GstFlowReturn ofGstUtils::preroll_cb(GstBuffer * buffer){ + bIsMovieDone = false; + if(appsink) return appsink->on_preroll(buffer); + else return GST_FLOW_OK; +} + +GstFlowReturn ofGstUtils::buffer_cb(GstBuffer * buffer){ + bIsMovieDone = false; + if(appsink) return appsink->on_buffer(buffer); + else return GST_FLOW_OK; +} + +void ofGstUtils::eos_cb(){ + bIsMovieDone = true; + if(appsink) appsink->on_eos(); +} + +bool ofGstUtils::setPipelineWithSink(string pipeline, string sinkname, bool isStream){ + ofGstUtils::startGstMainLoop(); + + gchar* pipeline_string = + g_strdup((pipeline).c_str()); + + GError * error = NULL; + gstPipeline = gst_parse_launch (pipeline_string, &error); + + cerr << "gstreamer pipeline: " <<pipeline_string<<endl; + if(error!=NULL){ + cerr <<"couldnt create pipeline: " << string(error->message)<<endl; + return false; + } + + gstSink = gst_bin_get_by_name(GST_BIN(gstPipeline),sinkname.c_str()); + + if(!gstSink){ + cerr << "couldn't get sink from string pipeline"<<endl; + } + + return setPipelineWithSink(gstPipeline,gstSink,isStream); +} + +bool ofGstUtils::setPipelineWithSink(GstElement * pipeline, GstElement * sink, bool isStream_){ + ofGstUtils::startGstMainLoop(); + + gstPipeline = pipeline; + gstSink = sink; + isStream = isStream_; + + if(gstSink){ + gst_base_sink_set_sync(GST_BASE_SINK(gstSink), true); + } + + if(gstSink && string(gst_plugin_feature_get_name( GST_PLUGIN_FEATURE(gst_element_get_factory(gstSink))))=="appsink"){ + isAppSink = true; + }else{ + isAppSink = false; + } + + return startPipeline(); +} + +void ofGstUtils::setFrameByFrame(bool _bFrameByFrame){ + bFrameByFrame = _bFrameByFrame; + if(gstSink){ + g_object_set (G_OBJECT (gstSink), "sync", !bFrameByFrame, (void*)NULL); + } +} + +bool ofGstUtils::isFrameByFrame(){ + return bFrameByFrame; +}
\ No newline at end of file |
