]> sigrok.org Git - libsigrokflow.git/commitdiff
Implement LegacyOutput.
authorMartin Ling <redacted>
Sun, 30 Dec 2018 03:02:35 +0000 (04:02 +0100)
committerUwe Hermann <redacted>
Tue, 8 Jan 2019 18:41:58 +0000 (19:41 +0100)
include/libsigrokflow/libsigrokflow.hpp
src/main.cpp

index 72fdc9d3ee9e9b6b0ad1368112ad6b4d4ab0fd31..e9a725ec431bc9ce8eaaacd945d86ba5d23de6b0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <gstreamermm.h>
 #include <gstreamermm/private/element_p.h>
+#include <gstreamermm/private/basesink_p.h>
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
 namespace Srf
@@ -36,16 +37,15 @@ class Block
         /* Config API etc goes here */
 };
 
-class GstBlock :
-        public Gst::Element
+class Sink :
+        public Gst::BaseSink
 {
-        /* Operations specific to sigrok GStreamer blocks go here. */
 protected:
-        explicit GstBlock(GstElement *gobj);
+        explicit Sink(GstBaseSink *gobj);
 };
 
 class Device :
-        public GstBlock
+        public Gst::Element
 {
         /* Operations specific to hardware devices go here */
 protected:
@@ -94,6 +94,36 @@ private:
         void _run();
 };
 
+class LegacyOutput :
+        public Sink
+{
+public:
+        /* Create from libsigrok output object */
+        static Glib::RefPtr<LegacyOutput> create(
+                shared_ptr<sigrok::Output> libsigrok_output);
+
+        /* Retrieve libsigrok output object */
+        shared_ptr<sigrok::Output> libsigrok_output();
+
+        /* Override render */
+        Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
+
+        /* Override stop */
+        bool stop_vfunc();
+
+        /* Gst class init */
+        static void class_init(Gst::ElementClass<LegacyOutput> *klass);
+
+        /* Register class with plugin */
+        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+        /* Constructor used by element factory */
+        explicit LegacyOutput(GstBaseSink *gobj);
+private:
+        shared_ptr<sigrok::Output> _libsigrok_output;
+        Glib::RefPtr<Gst::Pad> _sink_pad;
+};
+
 
 }
 #endif
index 1601d868528f143f459d125228c06523d7c43996..79af3ec39d45aa455d25cc50e00fa32e3d2c48cf 100644 (file)
@@ -35,15 +35,20 @@ void init()
                        "Wrapper for capture devices using legacy libsigrok APIs",
                        sigc::ptr_fun(&LegacyCaptureDevice::register_element),
                        "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org");
+       Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR,
+                       "sigrok_legacy_output",
+                       "Wrapper for outputs using legacy libsigrok APIs",
+                       sigc::ptr_fun(&LegacyOutput::register_element),
+                       "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org");
 }
 
-GstBlock::GstBlock(GstElement *gobj) :
-       Gst::Element(gobj)
+Sink::Sink(GstBaseSink *gobj) :
+       Gst::BaseSink(gobj)
 {
 }
 
 Device::Device(GstElement *gobj) :
-       GstBlock(gobj)
+       Gst::Element(gobj)
 {
 }
 
@@ -152,4 +157,70 @@ void LegacyCaptureDevice::_run()
        _task->stop();
 }
 
+void LegacyOutput::class_init(Gst::ElementClass<LegacyOutput> *klass)
+{
+       klass->set_metadata("sigrok legacy output",
+                       "Sink", "Wrapper for outputs using legacy libsigrok APIs",
+                       "Martin Ling");
+
+       klass->add_pad_template(Gst::PadTemplate::create(
+                       "sink",
+                       Gst::PAD_SINK,
+                       Gst::PAD_ALWAYS,
+                       Gst::Caps::create_any()));
+}
+
+bool LegacyOutput::register_element(Glib::RefPtr<Gst::Plugin> plugin)
+{
+       Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output",
+                       0, Gst::register_mm_type<LegacyOutput>(
+                               "sigrok_legacy_output"));
+       return true;
+}
+
+LegacyOutput::LegacyOutput(GstBaseSink *gobj) :
+       Glib::ObjectBase(typeid(LegacyOutput)),
+       Sink(gobj)
+{
+       add_pad(_sink_pad = Gst::Pad::create(get_pad_template("sink"), "sink"));
+}
+
+Glib::RefPtr<LegacyOutput>LegacyOutput::create(
+       shared_ptr<sigrok::Output> libsigrok_output)
+{
+       auto element = Gst::ElementFactory::create_element("sigrok_legacy_output");
+       if (!element)
+               throw runtime_error("Failed to create element - plugin not registered?");
+       auto output = Glib::RefPtr<LegacyOutput>::cast_static(element);
+       output->_libsigrok_output = libsigrok_output;
+       return output;
+}
+
+shared_ptr<sigrok::Output> LegacyOutput::libsigrok_output()
+{
+       return _libsigrok_output;
+}
+
+Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer)
+{
+       Gst::MapInfo info;
+       buffer->map(info, Gst::MAP_READ);
+       auto context = _libsigrok_output->format()->parent();
+       auto packet = context->create_logic_packet(
+                       info.get_data(), info.get_size(), 2);
+       auto result = _libsigrok_output->receive(packet);
+       cout << result;
+       buffer->unmap(info);
+       return Gst::FLOW_OK;
+}
+
+bool LegacyOutput::stop_vfunc()
+{
+       auto context = _libsigrok_output->format()->parent();
+       auto end_packet = context->create_end_packet();
+       auto result = _libsigrok_output->receive(end_packet);
+       cout << result;
+       return true;
+}
+
 }