]> sigrok.org Git - libsigrokflow.git/blob - include/libsigrokflow/libsigrokflow.hpp
6bd159fe5cd912d5b13df895a966fb69eb6124fd
[libsigrokflow.git] / include / libsigrokflow / libsigrokflow.hpp
1 /*
2  * This file is part of the libsigrokflow project.
3  *
4  * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
5  * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #ifndef LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
22 #define LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
23
24 /* Temporary workaround, will be dropped later. */
25 #define HAVE_LIBSIGROKCXX 1
26 #define HAVE_LIBSIGROKDECODE 1
27
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>
33 #endif
34 #ifdef HAVE_LIBSIGROKDECODE
35 #include <libsigrokdecode/libsigrokdecode.h>
36 #endif
37
38 #include <libsigrokflow/main.hpp>
39 #include <libsigrokflow/init.hpp>
40
41 namespace Srf
42 {
43
44 using namespace std;
45
46 #ifdef HAVE_LIBSIGROKCXX
47 class LegacyCaptureDevice :
48         public CaptureDevice
49 {
50 public:
51         /* Create from libsigrok device object. */
52         static Glib::RefPtr<LegacyCaptureDevice> create(
53                 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
54
55         /* Retrieve libsigrok device object. */
56         shared_ptr<sigrok::HardwareDevice> libsigrok_device();
57
58         /* Override state change. */
59         Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition) override;
60
61         /* Gst class init. */
62         static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
63
64         /* Register class with plugin. */
65         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
66
67         /* Constructor used by element factory. */
68         explicit LegacyCaptureDevice(GstElement *gobj);
69
70 private:
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_;
76
77         void datafeed_callback(shared_ptr<sigrok::Device> device,
78                         shared_ptr<sigrok::Packet> packet);
79         void run();
80 };
81
82 class LegacyInput :
83         public Gst::Element
84 {
85 public:
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>());
90
91         /* Chain function (not an override). */
92         Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
93                         const Glib::RefPtr<Gst::Buffer> &buf);
94
95         /* Event function (not an override). */
96         bool event(const Glib::RefPtr<Gst::Pad> &pad,
97                         Glib::RefPtr<Gst::Event> &event);
98
99         /* Gst class init. */
100         static void class_init(Gst::ElementClass<LegacyInput> *klass);
101
102         /* Register class with plugin. */
103         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
104
105         /* Constructor used by element factory. */
106         explicit LegacyInput(GstElement *gobj);
107
108 private:
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_;
115
116         void datafeed_callback(shared_ptr<sigrok::Device> device,
117                         shared_ptr<sigrok::Packet> packet);
118 };
119
120 class LegacyOutput :
121         public Sink
122 {
123 public:
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>());
128
129         /* Override start. */
130         bool start_vfunc() override;
131
132         /* Override render. */
133         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
134
135         /* Override stop. */
136         bool stop_vfunc() override;
137
138         /* Gst class init. */
139         static void class_init(Gst::ElementClass<LegacyOutput> *klass);
140
141         /* Register class with plugin. */
142         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
143
144         /* Constructor used by element factory. */
145         explicit LegacyOutput(GstBaseSink *gobj);
146
147 private:
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_;
152 };
153 #endif
154
155 #ifdef HAVE_LIBSIGROKDECODE
156 class LegacyDecoder :
157         public Sink
158 {
159 public:
160         static Glib::RefPtr<LegacyDecoder> create(
161                 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
162
163         /* Retrieve libsigrokdecode session. */
164         struct srd_session *libsigrokdecode_session();
165
166         /* Override start. */
167         bool start_vfunc() override;
168
169         /* Override render. */
170         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override;
171
172         /* Override stop. */
173         bool stop_vfunc() override;
174
175         /* Gst class init. */
176         static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
177
178         /* Register class with plugin. */
179         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
180
181         /* Constructor used by element factory. */
182         explicit LegacyDecoder(GstBaseSink *gobj);
183
184 private:
185         struct srd_session *session_;
186         uint64_t abs_ss_;
187         uint64_t unitsite_;
188 };
189 #endif
190
191 }
192 #endif