From a2c6354640f24db3484ccf486c2c0cbd08808e60 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 23 Apr 2013 17:10:11 +0100 Subject: gst underway --- rotord/gstvideoloader.cpp | 167 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) (limited to 'rotord/gstvideoloader.cpp') 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 +#include +#include + +#include +#include +#include + +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"<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: " <message)<