]> sigrok.org Git - libsigrokflow.git/blob - include/libsigrokflow/libsigrokflow.hpp
31cbd0126aa51ab7211a31709d2ccc2c4b7739eb
[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 #include <gstreamermm.h>
25 #include <gstreamermm/private/element_p.h>
26 #include <gstreamermm/private/basesink_p.h>
27 #ifdef HAVE_LIBSIGROKCXX
28 #include <libsigrokcxx/libsigrokcxx.hpp>
29 #endif
30 #ifdef HAVE_LIBSIGROKDECODE
31 #include <libsigrokdecode/libsigrokdecode.h>
32 #endif
33
34 namespace Srf
35 {
36
37 using namespace std;
38
39 void init();
40
41 class Block
42 {
43         /* Config API etc goes here */
44 };
45
46 class Sink :
47         public Gst::BaseSink
48 {
49 protected:
50         explicit Sink(GstBaseSink *gobj);
51 };
52
53 class Device :
54         public Gst::Element
55 {
56         /* Operations specific to hardware devices go here */
57 protected:
58         explicit Device(GstElement *gobj);
59 };
60
61 class CaptureDevice :
62         public Device
63 {
64         /* Operations specific to capture (source) devices go here */
65 protected:
66         explicit CaptureDevice(GstElement *gobj);
67 };
68
69 #ifdef HAVE_LIBSIGROKCXX
70 class LegacyCaptureDevice :
71         public CaptureDevice
72 {
73 public:
74         /* Create from libsigrok device object */
75         static Glib::RefPtr<LegacyCaptureDevice> create(
76                 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
77
78         /* Retrieve libsigrok device object */
79         shared_ptr<sigrok::HardwareDevice> libsigrok_device();
80
81         /* Override state change */
82         Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
83
84         /* Gst class init */
85         static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
86
87         /* Register class with plugin */
88         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
89
90         /* Construcor used by element factory */
91         explicit LegacyCaptureDevice(GstElement *gobj);
92 private:
93         shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
94         Glib::RefPtr<Gst::Pad> _src_pad;
95         Glib::Threads::RecMutex _mutex;
96         Glib::RefPtr<Gst::Task> _task;
97         shared_ptr<sigrok::Session> _session;
98
99         void _datafeed_callback(shared_ptr<sigrok::Device> device,
100                         shared_ptr<sigrok::Packet> packet);
101         void _run();
102 };
103
104 class LegacyInput :
105         public Gst::Element
106 {
107 public:
108         /* Create from libsigrok input */
109         static Glib::RefPtr<LegacyInput> create(
110                 shared_ptr<sigrok::InputFormat> format,
111                 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
112
113         /* Override start */
114         bool start_vfunc();
115
116         /* Chain function */
117         Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
118                         const Glib::RefPtr<Gst::Buffer> &buf);
119
120         /* Override stop */
121         bool stop_vfunc();
122
123         /* Gst class init */
124         static void class_init(Gst::ElementClass<LegacyInput> *klass);
125
126         /* Register class with plugin */
127         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
128
129         /* Construcor used by element factory */
130         explicit LegacyInput(GstElement *gobj);
131 private:
132         shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
133         shared_ptr<sigrok::Input> _libsigrok_input;
134         shared_ptr<sigrok::Session> _session;
135         map<string, Glib::VariantBase> _options;
136         Glib::RefPtr<Gst::Pad> _sink_pad;
137         Glib::RefPtr<Gst::Pad> _src_pad;
138
139         void _datafeed_callback(shared_ptr<sigrok::Device> device,
140                         shared_ptr<sigrok::Packet> packet);
141 };
142
143 class LegacyOutput :
144         public Sink
145 {
146 public:
147         /* Create from libsigrok output object */
148         static Glib::RefPtr<LegacyOutput> create(
149                 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
150                 shared_ptr<sigrok::Device> libsigrok_device,
151                 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
152
153         /* Override start */
154         bool start_vfunc();
155
156         /* Override render */
157         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
158
159         /* Override stop */
160         bool stop_vfunc();
161
162         /* Gst class init */
163         static void class_init(Gst::ElementClass<LegacyOutput> *klass);
164
165         /* Register class with plugin */
166         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
167
168         /* Constructor used by element factory */
169         explicit LegacyOutput(GstBaseSink *gobj);
170 private:
171         shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
172         shared_ptr<sigrok::Device> _libsigrok_device;
173         shared_ptr<sigrok::Output> _libsigrok_output;
174         map<string, Glib::VariantBase> _options;
175 };
176 #endif
177
178 #ifdef HAVE_LIBSIGROKDECODE
179 class LegacyDecoder :
180         public Sink
181 {
182 public:
183         static Glib::RefPtr<LegacyDecoder> create(
184                 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
185
186         /* Retrieve libsigrokdecode session */
187         struct srd_session *libsigrokdecode_session();
188
189         /* Override start */
190         bool start_vfunc();
191
192         /* Override render */
193         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
194
195         /* Override stop */
196         bool stop_vfunc();
197
198         /* Gst class init */
199         static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
200
201         /* Register class with plugin */
202         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
203
204         /* Constructor used by element factory */
205         explicit LegacyDecoder(GstBaseSink *gobj);
206 private:
207         struct srd_session *_session;
208         uint64_t _abs_ss;
209         uint64_t _unitsize;
210 };
211 #endif
212
213 }
214 #endif