]> sigrok.org Git - libsigrokflow.git/commitdiff
Fix implementation of LegacyInput.
authorMartin Ling <redacted>
Thu, 10 Jan 2019 00:16:48 +0000 (00:16 +0000)
committerUwe Hermann <redacted>
Thu, 10 Jan 2019 01:06:01 +0000 (02:06 +0100)
include/libsigrokflow/libsigrokflow.hpp
src/legacy_input.cpp

index c27ce789b89e8f0378ab6082b4cbeafd412338e2..8f188248749e6bcf6693d22b5409650349e872c9 100644 (file)
@@ -117,15 +117,13 @@ public:
                shared_ptr<sigrok::InputFormat> format,
                map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
 
-       /* Start function (not an override). */
-       bool start_vfunc();
-
        /* Chain function (not an override). */
        Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
                        const Glib::RefPtr<Gst::Buffer> &buf);
 
-       /* Stop function (not an override). */
-       bool stop_vfunc();
+       /* Event function (not an override). */
+       bool event(const Glib::RefPtr<Gst::Pad> &pad,
+                       Glib::RefPtr<Gst::Event> &event);
 
        /* Gst class init. */
        static void class_init(Gst::ElementClass<LegacyInput> *klass);
index 67d0c9b7dc6b262c592c048fac6b43928b839b4e..8a7c47ca99b7218d82e88790dcc5cba86e743ebc 100644 (file)
@@ -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> LegacyInput::create(
@@ -74,23 +75,10 @@ Glib::RefPtr<LegacyInput> LegacyInput::create(
                throw runtime_error("Failed to create element - plugin not registered?");
        auto input = Glib::RefPtr<LegacyInput>::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<sigrok::Device> device,
        shared_ptr<sigrok::Packet> packet)
@@ -126,14 +114,26 @@ Gst::FlowReturn LegacyInput::chain(const Glib::RefPtr<Gst::Pad> &,
        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<Gst::Pad>&pad, Glib::RefPtr<Gst::Event>&event)
 {
-       libsigrok_input_->end();
+       (void)pad;
+
+       if (event->get_event_type() == Gst::EVENT_EOS) {
+               libsigrok_input_->end();
+               session_->stop();
+       }
 
        return true;
 }