]> sigrok.org Git - libsigrokflow.git/blobdiff - include/libsigrokflow/libsigrokflow.hpp
Fix implementation of LegacyInput.
[libsigrokflow.git] / include / libsigrokflow / libsigrokflow.hpp
index e9a725ec431bc9ce8eaaacd945d86ba5d23de6b0..8f188248749e6bcf6693d22b5409650349e872c9 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * This file is part of the libsigrokflow project.
  *
+ * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
  * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
  *
  * This program is free software: you can redistribute it and/or modify
 #ifndef LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
 #define LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
 
+/* Temporary workaround, will be dropped later. */
+#define HAVE_LIBSIGROKCXX 1
+#define HAVE_LIBSIGROKDECODE 1
+
 #include <gstreamermm.h>
 #include <gstreamermm/private/element_p.h>
 #include <gstreamermm/private/basesink_p.h>
+#ifdef HAVE_LIBSIGROKCXX
 #include <libsigrokcxx/libsigrokcxx.hpp>
+#endif
+#ifdef HAVE_LIBSIGROKDECODE
+#include <libsigrokdecode/libsigrokdecode.h>
+#endif
 
 namespace Srf
 {
@@ -32,98 +42,180 @@ using namespace std;
 
 void init();
 
+void deinit();
+
 class Block
 {
-        /* Config API etc goes here */
+       /* Config API etc. goes here. */
 };
 
 class Sink :
-        public Gst::BaseSink
+       public Gst::BaseSink
 {
 protected:
-        explicit Sink(GstBaseSink *gobj);
+       explicit Sink(GstBaseSink *gobj);
 };
 
 class Device :
-        public Gst::Element
+       public Gst::Element
 {
-        /* Operations specific to hardware devices go here */
+       /* Operations specific to hardware devices go here. */
 protected:
-        explicit Device(GstElement *gobj);
+       explicit Device(GstElement *gobj);
 };
 
 class CaptureDevice :
-        public Device
+       public Device
 {
-        /* Operations specific to capture (source) devices go here */
+       /* Operations specific to capture (source) devices go here. */
 protected:
-        explicit CaptureDevice(GstElement *gobj);
+       explicit CaptureDevice(GstElement *gobj);
 };
 
+#ifdef HAVE_LIBSIGROKCXX
 class LegacyCaptureDevice :
-        public CaptureDevice
+       public CaptureDevice
+{
+public:
+       /* Create from libsigrok device object. */
+       static Glib::RefPtr<LegacyCaptureDevice> create(
+               shared_ptr<sigrok::HardwareDevice> libsigrok_device);
+
+       /* Retrieve libsigrok device object. */
+       shared_ptr<sigrok::HardwareDevice> libsigrok_device();
+
+       /* Override state change. */
+       Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition) override;
+
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
+
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+       /* Constructor used by element factory. */
+       explicit LegacyCaptureDevice(GstElement *gobj);
+
+private:
+       shared_ptr<sigrok::HardwareDevice> libsigrok_device_;
+       Glib::RefPtr<Gst::Pad> src_pad_;
+       Glib::Threads::RecMutex mutex_;
+       Glib::RefPtr<Gst::Task> task_;
+       shared_ptr<sigrok::Session> session_;
+
+       void datafeed_callback(shared_ptr<sigrok::Device> device,
+                       shared_ptr<sigrok::Packet> packet);
+       void run();
+};
+
+class LegacyInput :
+       public Gst::Element
 {
 public:
-        /* Create from libsigrok device object */
-        static Glib::RefPtr<LegacyCaptureDevice> create(
-                shared_ptr<sigrok::HardwareDevice> libsigrok_device);
+       /* Create from libsigrok input. */
+       static Glib::RefPtr<LegacyInput> create(
+               shared_ptr<sigrok::InputFormat> format,
+               map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+
+       /* Chain function (not an override). */
+       Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
+                       const Glib::RefPtr<Gst::Buffer> &buf);
 
-        /* Retrieve libsigrok device object */
-        shared_ptr<sigrok::HardwareDevice> libsigrok_device();
+       /* Event function (not an override). */
+       bool event(const Glib::RefPtr<Gst::Pad> &pad,
+                       Glib::RefPtr<Gst::Event> &event);
 
-        /* Override state change */
-        Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyInput> *klass);
 
-        /* Gst class init */
-        static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
 
-        /* Register class with plugin */
-        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+       /* Constructor used by element factory. */
+       explicit LegacyInput(GstElement *gobj);
 
-        /* Construcor used by element factory */
-        explicit LegacyCaptureDevice(GstElement *gobj);
 private:
-        shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
-        Glib::RefPtr<Gst::Pad> _src_pad;
-        Glib::Threads::RecMutex _mutex;
-        Glib::RefPtr<Gst::Task> _task;
-        shared_ptr<sigrok::Session> _session;
-
-        void _datafeed_callback(shared_ptr<sigrok::Device> device,
-                        shared_ptr<sigrok::Packet> packet);
-        void _run();
+       shared_ptr<sigrok::InputFormat> libsigrok_input_format_;
+       shared_ptr<sigrok::Input> libsigrok_input_;
+       shared_ptr<sigrok::Session> session_;
+       map<string, Glib::VariantBase> options_;
+       Glib::RefPtr<Gst::Pad> sink_pad_;
+       Glib::RefPtr<Gst::Pad> src_pad_;
+
+       void datafeed_callback(shared_ptr<sigrok::Device> device,
+                       shared_ptr<sigrok::Packet> packet);
 };
 
 class LegacyOutput :
-        public Sink
+       public Sink
 {
 public:
-        /* Create from libsigrok output object */
-        static Glib::RefPtr<LegacyOutput> create(
-                shared_ptr<sigrok::Output> libsigrok_output);
+       /* Create from libsigrok output object. */
+       static Glib::RefPtr<LegacyOutput> create(
+               shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
+               map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
 
-        /* Retrieve libsigrok output object */
-        shared_ptr<sigrok::Output> libsigrok_output();
+       /* Override start. */
+       bool start_vfunc() override;
 
-        /* Override render */
-        Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
+       /* Override render. */
+       Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
 
-        /* Override stop */
-        bool stop_vfunc();
+       /* Override stop. */
+       bool stop_vfunc() override;
 
-        /* Gst class init */
-        static void class_init(Gst::ElementClass<LegacyOutput> *klass);
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyOutput> *klass);
 
-        /* Register class with plugin */
-        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+       /* Constructor used by element factory. */
+       explicit LegacyOutput(GstBaseSink *gobj);
 
-        /* Constructor used by element factory */
-        explicit LegacyOutput(GstBaseSink *gobj);
 private:
-        shared_ptr<sigrok::Output> _libsigrok_output;
-        Glib::RefPtr<Gst::Pad> _sink_pad;
+       shared_ptr<sigrok::OutputFormat> libsigrok_output_format_;
+       shared_ptr<sigrok::Device> libsigrok_device_;
+       shared_ptr<sigrok::Output> libsigrok_output_;
+       map<string, Glib::VariantBase> options_;
 };
+#endif
+
+#ifdef HAVE_LIBSIGROKDECODE
+class LegacyDecoder :
+       public Sink
+{
+public:
+       static Glib::RefPtr<LegacyDecoder> create(
+               struct srd_session *libsigrokdecode_session, uint64_t unitsize);
+
+       /* Retrieve libsigrokdecode session. */
+       struct srd_session *libsigrokdecode_session();
+
+       /* Override start. */
+       bool start_vfunc() override;
+
+       /* Override render. */
+       Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
 
+       /* Override stop. */
+       bool stop_vfunc() override;
+
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
+
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+       /* Constructor used by element factory. */
+       explicit LegacyDecoder(GstBaseSink *gobj);
+
+private:
+       struct srd_session *session_;
+       uint64_t abs_ss_;
+       uint64_t unitsite_;
+};
+#endif
 
 }
 #endif