From: Martin Ling Date: Thu, 10 Jan 2019 00:16:48 +0000 (+0000) Subject: Fix implementation of LegacyInput. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fce9342ebac11cc96e702d74c82f3455469ce8fb;p=libsigrokflow.git Fix implementation of LegacyInput. --- diff --git a/include/libsigrokflow/libsigrokflow.hpp b/include/libsigrokflow/libsigrokflow.hpp index c27ce78..8f18824 100644 --- a/include/libsigrokflow/libsigrokflow.hpp +++ b/include/libsigrokflow/libsigrokflow.hpp @@ -117,15 +117,13 @@ public: shared_ptr format, map options = map()); - /* Start function (not an override). */ - bool start_vfunc(); - /* Chain function (not an override). */ Gst::FlowReturn chain(const Glib::RefPtr &pad, const Glib::RefPtr &buf); - /* Stop function (not an override). */ - bool stop_vfunc(); + /* Event function (not an override). */ + bool event(const Glib::RefPtr &pad, + Glib::RefPtr &event); /* Gst class init. */ static void class_init(Gst::ElementClass *klass); diff --git a/src/legacy_input.cpp b/src/legacy_input.cpp index 67d0c9b..8a7c47c 100644 --- a/src/legacy_input.cpp +++ b/src/legacy_input.cpp @@ -63,6 +63,7 @@ LegacyInput::LegacyInput(GstElement *gobj) : add_pad(sink_pad_ = Gst::Pad::create(get_pad_template("sink"), "sink")); add_pad(src_pad_ = Gst::Pad::create(get_pad_template("src"), "src")); sink_pad_->set_chain_function(sigc::mem_fun(*this, &LegacyInput::chain)); + sink_pad_->set_event_function(sigc::mem_fun(*this, &LegacyInput::event)); } Glib::RefPtr LegacyInput::create( @@ -74,23 +75,10 @@ Glib::RefPtr LegacyInput::create( throw runtime_error("Failed to create element - plugin not registered?"); auto input = Glib::RefPtr::cast_static(element); input->libsigrok_input_format_ = libsigrok_input_format; - input->options_ = options; - + input->libsigrok_input_ = libsigrok_input_format->create_input(options); return input; } -bool LegacyInput::start_vfunc() -{ - libsigrok_input_ = libsigrok_input_format_->create_input(options_); - auto context = libsigrok_input_format_->parent(); - session_ = context->create_session(); - session_->add_device(libsigrok_input_->device()); - session_->add_datafeed_callback(bind(&LegacyInput::datafeed_callback, this, _1, _2)); - session_->start(); - - return true; -} - void LegacyInput::datafeed_callback( shared_ptr device, shared_ptr packet) @@ -126,14 +114,26 @@ Gst::FlowReturn LegacyInput::chain(const Glib::RefPtr &, Gst::MapInfo info; buf->map(info, Gst::MAP_READ); libsigrok_input_->send(info.get_data(), info.get_size()); + auto device = libsigrok_input_->device(); + if (!session_ && device) { + auto context = libsigrok_input_format_->parent(); + session_ = context->create_session(); + session_->add_device(device); + session_->add_datafeed_callback(bind(&LegacyInput::datafeed_callback, this, _1, _2)); + } buf->unmap(info); return Gst::FLOW_OK; } -bool LegacyInput::stop_vfunc() +bool LegacyInput::event(const Glib::RefPtr&pad, Glib::RefPtr&event) { - libsigrok_input_->end(); + (void)pad; + + if (event->get_event_type() == Gst::EVENT_EOS) { + libsigrok_input_->end(); + session_->stop(); + } return true; }