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>
49 /* Config API etc. goes here. */
56 explicit Sink(GstBaseSink *gobj);
62 /* Operations specific to hardware devices go here. */
64 explicit Device(GstElement *gobj);
70 /* Operations specific to capture (source) devices go here. */
72 explicit CaptureDevice(GstElement *gobj);
75 #ifdef HAVE_LIBSIGROKCXX
76 class LegacyCaptureDevice :
80 /* Create from libsigrok device object. */
81 static Glib::RefPtr<LegacyCaptureDevice> create(
82 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
84 /* Retrieve libsigrok device object. */
85 shared_ptr<sigrok::HardwareDevice> libsigrok_device();
87 /* Override state change. */
88 Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition) override;
91 static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
93 /* Register class with plugin. */
94 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
96 /* Constructor used by element factory. */
97 explicit LegacyCaptureDevice(GstElement *gobj);
100 shared_ptr<sigrok::HardwareDevice> libsigrok_device_;
101 Glib::RefPtr<Gst::Pad> src_pad_;
102 Glib::Threads::RecMutex mutex_;
103 Glib::RefPtr<Gst::Task> task_;
104 shared_ptr<sigrok::Session> session_;
106 void datafeed_callback(shared_ptr<sigrok::Device> device,
107 shared_ptr<sigrok::Packet> packet);
115 /* Create from libsigrok input. */
116 static Glib::RefPtr<LegacyInput> create(
117 shared_ptr<sigrok::InputFormat> format,
118 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
120 /* Chain function (not an override). */
121 Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
122 const Glib::RefPtr<Gst::Buffer> &buf);
124 /* Event function (not an override). */
125 bool event(const Glib::RefPtr<Gst::Pad> &pad,
126 Glib::RefPtr<Gst::Event> &event);
128 /* Gst class init. */
129 static void class_init(Gst::ElementClass<LegacyInput> *klass);
131 /* Register class with plugin. */
132 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
134 /* Constructor used by element factory. */
135 explicit LegacyInput(GstElement *gobj);
138 shared_ptr<sigrok::InputFormat> libsigrok_input_format_;
139 shared_ptr<sigrok::Input> libsigrok_input_;
140 shared_ptr<sigrok::Session> session_;
141 map<string, Glib::VariantBase> options_;
142 Glib::RefPtr<Gst::Pad> sink_pad_;
143 Glib::RefPtr<Gst::Pad> src_pad_;
145 void datafeed_callback(shared_ptr<sigrok::Device> device,
146 shared_ptr<sigrok::Packet> packet);
153 /* Create from libsigrok output object. */
154 static Glib::RefPtr<LegacyOutput> create(
155 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
156 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
158 /* Override start. */
159 bool start_vfunc() override;
161 /* Override render. */
162 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
165 bool stop_vfunc() override;
167 /* Gst class init. */
168 static void class_init(Gst::ElementClass<LegacyOutput> *klass);
170 /* Register class with plugin. */
171 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
173 /* Constructor used by element factory. */
174 explicit LegacyOutput(GstBaseSink *gobj);
177 shared_ptr<sigrok::OutputFormat> libsigrok_output_format_;
178 shared_ptr<sigrok::Device> libsigrok_device_;
179 shared_ptr<sigrok::Output> libsigrok_output_;
180 map<string, Glib::VariantBase> options_;
184 #ifdef HAVE_LIBSIGROKDECODE
185 class LegacyDecoder :
189 static Glib::RefPtr<LegacyDecoder> create(
190 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
192 /* Retrieve libsigrokdecode session. */
193 struct srd_session *libsigrokdecode_session();
195 /* Override start. */
196 bool start_vfunc() override;
198 /* Override render. */
199 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
202 bool stop_vfunc() override;
204 /* Gst class init. */
205 static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
207 /* Register class with plugin. */
208 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
210 /* Constructor used by element factory. */
211 explicit LegacyDecoder(GstBaseSink *gobj);
214 struct srd_session *session_;