#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)<