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>
47 /* Config API etc goes here */
54 explicit Sink(GstBaseSink *gobj);
60 /* Operations specific to hardware devices go here */
62 explicit Device(GstElement *gobj);
68 /* Operations specific to capture (source) devices go here */
70 explicit CaptureDevice(GstElement *gobj);
73 #ifdef HAVE_LIBSIGROKCXX
74 class LegacyCaptureDevice :
78 /* Create from libsigrok device object */
79 static Glib::RefPtr<LegacyCaptureDevice> create(
80 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
82 /* Retrieve libsigrok device object */
83 shared_ptr<sigrok::HardwareDevice> libsigrok_device();
85 /* Override state change */
86 Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
89 static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
91 /* Register class with plugin */
92 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
94 /* Construcor used by element factory */
95 explicit LegacyCaptureDevice(GstElement *gobj);
97 shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
98 Glib::RefPtr<Gst::Pad> _src_pad;
99 Glib::Threads::RecMutex _mutex;
100 Glib::RefPtr<Gst::Task> _task;
101 shared_ptr<sigrok::Session> _session;
103 void _datafeed_callback(shared_ptr<sigrok::Device> device,
104 shared_ptr<sigrok::Packet> packet);
112 /* Create from libsigrok input */
113 static Glib::RefPtr<LegacyInput> create(
114 shared_ptr<sigrok::InputFormat> format,
115 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
121 Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
122 const Glib::RefPtr<Gst::Buffer> &buf);
128 static void class_init(Gst::ElementClass<LegacyInput> *klass);
130 /* Register class with plugin */
131 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
133 /* Construcor used by element factory */
134 explicit LegacyInput(GstElement *gobj);
136 shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
137 shared_ptr<sigrok::Input> _libsigrok_input;
138 shared_ptr<sigrok::Session> _session;
139 map<string, Glib::VariantBase> _options;
140 Glib::RefPtr<Gst::Pad> _sink_pad;
141 Glib::RefPtr<Gst::Pad> _src_pad;
143 void _datafeed_callback(shared_ptr<sigrok::Device> device,
144 shared_ptr<sigrok::Packet> packet);
151 /* Create from libsigrok output object */
152 static Glib::RefPtr<LegacyOutput> create(
153 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
154 shared_ptr<sigrok::Device> libsigrok_device,
155 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
160 /* Override render */
161 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
167 static void class_init(Gst::ElementClass<LegacyOutput> *klass);
169 /* Register class with plugin */
170 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
172 /* Constructor used by element factory */
173 explicit LegacyOutput(GstBaseSink *gobj);
175 shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
176 shared_ptr<sigrok::Device> _libsigrok_device;
177 shared_ptr<sigrok::Output> _libsigrok_output;
178 map<string, Glib::VariantBase> _options;
182 #ifdef HAVE_LIBSIGROKDECODE
183 class LegacyDecoder :
187 static Glib::RefPtr<LegacyDecoder> create(
188 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
190 /* Retrieve libsigrokdecode session */
191 struct srd_session *libsigrokdecode_session();
196 /* Override render */
197 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
203 static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
205 /* Register class with plugin */
206 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
208 /* Constructor used by element factory */
209 explicit LegacyDecoder(GstBaseSink *gobj);
211 struct srd_session *_session;