2 * This file is part of the libsigrokflow project.
4 * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
5 * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
22 #define LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
24 /* Temporary workaround, will be dropped later. */
25 #define HAVE_LIBSIGROKCXX 1
26 #define HAVE_LIBSIGROKDECODE 1
28 #include <gstreamermm.h>
29 #include <gstreamermm/private/element_p.h>
30 #include <gstreamermm/private/basesink_p.h>
31 #ifdef HAVE_LIBSIGROKCXX
32 #include <libsigrokcxx/libsigrokcxx.hpp>
34 #ifdef HAVE_LIBSIGROKDECODE
35 #include <libsigrokdecode/libsigrokdecode.h>
38 #include <libsigrokflow/main.hpp>
39 #include <libsigrokflow/init.hpp>
46 #ifdef HAVE_LIBSIGROKCXX
47 class LegacyCaptureDevice :
51 /* Create from libsigrok device object. */
52 static Glib::RefPtr<LegacyCaptureDevice> create(
53 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
55 /* Retrieve libsigrok device object. */
56 shared_ptr<sigrok::HardwareDevice> libsigrok_device();
58 /* Override state change. */
59 Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition) override;
62 static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
64 /* Register class with plugin. */
65 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
67 /* Constructor used by element factory. */
68 explicit LegacyCaptureDevice(GstElement *gobj);
71 shared_ptr<sigrok::HardwareDevice> libsigrok_device_;
72 Glib::RefPtr<Gst::Pad> src_pad_;
73 Glib::Threads::RecMutex mutex_;
74 Glib::RefPtr<Gst::Task> task_;
75 shared_ptr<sigrok::Session> session_;
77 void datafeed_callback(shared_ptr<sigrok::Device> device,
78 shared_ptr<sigrok::Packet> packet);
86 /* Create from libsigrok input. */
87 static Glib::RefPtr<LegacyInput> create(
88 shared_ptr<sigrok::InputFormat> format,
89 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
91 /* Chain function (not an override). */
92 Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
93 const Glib::RefPtr<Gst::Buffer> &buf);
95 /* Event function (not an override). */
96 bool event(const Glib::RefPtr<Gst::Pad> &pad,
97 Glib::RefPtr<Gst::Event> &event);
100 static void class_init(Gst::ElementClass<LegacyInput> *klass);
102 /* Register class with plugin. */
103 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
105 /* Constructor used by element factory. */
106 explicit LegacyInput(GstElement *gobj);
109 shared_ptr<sigrok::InputFormat> libsigrok_input_format_;
110 shared_ptr<sigrok::Input> libsigrok_input_;
111 shared_ptr<sigrok::Session> session_;
112 map<string, Glib::VariantBase> options_;
113 Glib::RefPtr<Gst::Pad> sink_pad_;
114 Glib::RefPtr<Gst::Pad> src_pad_;
116 void datafeed_callback(shared_ptr<sigrok::Device> device,
117 shared_ptr<sigrok::Packet> packet);
124 /* Create from libsigrok output object. */
125 static Glib::RefPtr<LegacyOutput> create(
126 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
127 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
129 /* Override start. */
130 bool start_vfunc() override;
132 /* Override render. */
133 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
136 bool stop_vfunc() override;
138 /* Gst class init. */
139 static void class_init(Gst::ElementClass<LegacyOutput> *klass);
141 /* Register class with plugin. */
142 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
144 /* Constructor used by element factory. */
145 explicit LegacyOutput(GstBaseSink *gobj);
148 shared_ptr<sigrok::OutputFormat> libsigrok_output_format_;
149 shared_ptr<sigrok::UserDevice> libsigrok_device_;
150 shared_ptr<sigrok::Output> libsigrok_output_;
151 map<string, Glib::VariantBase> options_;
155 #ifdef HAVE_LIBSIGROKDECODE
156 class LegacyDecoder :
160 static Glib::RefPtr<LegacyDecoder> create(
161 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
163 /* Retrieve libsigrokdecode session. */
164 struct srd_session *libsigrokdecode_session();
166 /* Override start. */
167 bool start_vfunc() override;
169 /* Override render. */
170 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
173 bool stop_vfunc() override;
175 /* Gst class init. */
176 static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
178 /* Register class with plugin. */
179 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
181 /* Constructor used by element factory. */
182 explicit LegacyDecoder(GstBaseSink *gobj);
185 struct srd_session *session_;