]>
Commit | Line | Data |
---|---|---|
572e76fe UH |
1 | /* |
2 | * This file is part of the libsigrokflow project. | |
3 | * | |
f1eaad84 | 4 | * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li> |
572e76fe UH |
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 | ||
15c57e97 UH |
24 | /* Temporary workaround, will be dropped later. */ |
25 | #define HAVE_LIBSIGROKCXX 1 | |
26 | #define HAVE_LIBSIGROKDECODE 1 | |
27 | ||
f7363af1 | 28 | #include <gstreamermm.h> |
37469b3d | 29 | #include <gstreamermm/private/element_p.h> |
e2cfc0ef | 30 | #include <gstreamermm/private/basesink_p.h> |
1060e9b5 | 31 | #ifdef HAVE_LIBSIGROKCXX |
f7363af1 | 32 | #include <libsigrokcxx/libsigrokcxx.hpp> |
1060e9b5 | 33 | #endif |
45e6e688 | 34 | #ifdef HAVE_LIBSIGROKDECODE |
b1322000 | 35 | #include <libsigrokdecode/libsigrokdecode.h> |
45e6e688 | 36 | #endif |
f7363af1 | 37 | |
b903bb0a UH |
38 | namespace Srf |
39 | { | |
40 | ||
f7363af1 ML |
41 | using namespace std; |
42 | ||
b903bb0a UH |
43 | void init(); |
44 | ||
870da4f2 UH |
45 | void deinit(); |
46 | ||
f7363af1 ML |
47 | class Block |
48 | { | |
31b3babd | 49 | /* Config API etc. goes here. */ |
f7363af1 ML |
50 | }; |
51 | ||
e2cfc0ef | 52 | class Sink : |
31b3babd | 53 | public Gst::BaseSink |
f7363af1 | 54 | { |
6d71d36a | 55 | protected: |
31b3babd | 56 | explicit Sink(GstBaseSink *gobj); |
f7363af1 ML |
57 | }; |
58 | ||
59 | class Device : | |
31b3babd | 60 | public Gst::Element |
f7363af1 | 61 | { |
31b3babd | 62 | /* Operations specific to hardware devices go here. */ |
6d71d36a | 63 | protected: |
31b3babd | 64 | explicit Device(GstElement *gobj); |
f7363af1 | 65 | }; |
b903bb0a | 66 | |
f7363af1 | 67 | class CaptureDevice : |
31b3babd | 68 | public Device |
f7363af1 | 69 | { |
31b3babd | 70 | /* Operations specific to capture (source) devices go here. */ |
6d71d36a | 71 | protected: |
31b3babd | 72 | explicit CaptureDevice(GstElement *gobj); |
f7363af1 ML |
73 | }; |
74 | ||
1060e9b5 | 75 | #ifdef HAVE_LIBSIGROKCXX |
f7363af1 | 76 | class LegacyCaptureDevice : |
31b3babd | 77 | public CaptureDevice |
f7363af1 ML |
78 | { |
79 | public: | |
31b3babd UH |
80 | /* Create from libsigrok device object. */ |
81 | static Glib::RefPtr<LegacyCaptureDevice> create( | |
82 | shared_ptr<sigrok::HardwareDevice> libsigrok_device); | |
f7363af1 | 83 | |
31b3babd UH |
84 | /* Retrieve libsigrok device object. */ |
85 | shared_ptr<sigrok::HardwareDevice> libsigrok_device(); | |
d03b3a98 | 86 | |
31b3babd UH |
87 | /* Override state change. */ |
88 | Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition); | |
6d71d36a | 89 | |
31b3babd UH |
90 | /* Gst class init. */ |
91 | static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass); | |
6d71d36a | 92 | |
31b3babd UH |
93 | /* Register class with plugin. */ |
94 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
95 | ||
96 | /* Constructor used by element factory. */ | |
97 | explicit LegacyCaptureDevice(GstElement *gobj); | |
6d71d36a | 98 | |
f7363af1 | 99 | private: |
b37c14d6 UH |
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_; | |
31b3babd | 105 | |
897cb509 | 106 | void datafeed_callback(shared_ptr<sigrok::Device> device, |
31b3babd | 107 | shared_ptr<sigrok::Packet> packet); |
897cb509 | 108 | void run(); |
f7363af1 ML |
109 | }; |
110 | ||
92d521e7 | 111 | class LegacyInput : |
31b3babd | 112 | public Gst::Element |
92d521e7 ML |
113 | { |
114 | public: | |
31b3babd UH |
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>()); | |
119 | ||
120 | /* Override start. */ | |
121 | bool start_vfunc(); | |
92d521e7 | 122 | |
31b3babd UH |
123 | /* Chain function. */ |
124 | Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, | |
125 | const Glib::RefPtr<Gst::Buffer> &buf); | |
92d521e7 | 126 | |
31b3babd UH |
127 | /* Override stop. */ |
128 | bool stop_vfunc(); | |
92d521e7 | 129 | |
31b3babd UH |
130 | /* Gst class init. */ |
131 | static void class_init(Gst::ElementClass<LegacyInput> *klass); | |
92d521e7 | 132 | |
31b3babd UH |
133 | /* Register class with plugin. */ |
134 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
92d521e7 | 135 | |
31b3babd UH |
136 | /* Constructor used by element factory. */ |
137 | explicit LegacyInput(GstElement *gobj); | |
92d521e7 | 138 | |
92d521e7 | 139 | private: |
b37c14d6 UH |
140 | shared_ptr<sigrok::InputFormat> libsigrok_input_format_; |
141 | shared_ptr<sigrok::Input> libsigrok_input_; | |
142 | shared_ptr<sigrok::Session> session_; | |
143 | map<string, Glib::VariantBase> options_; | |
144 | Glib::RefPtr<Gst::Pad> sink_pad_; | |
145 | Glib::RefPtr<Gst::Pad> src_pad_; | |
146 | ||
897cb509 | 147 | void datafeed_callback(shared_ptr<sigrok::Device> device, |
31b3babd | 148 | shared_ptr<sigrok::Packet> packet); |
92d521e7 ML |
149 | }; |
150 | ||
e2cfc0ef | 151 | class LegacyOutput : |
31b3babd | 152 | public Sink |
e2cfc0ef ML |
153 | { |
154 | public: | |
31b3babd UH |
155 | /* Create from libsigrok output object. */ |
156 | static Glib::RefPtr<LegacyOutput> create( | |
157 | shared_ptr<sigrok::OutputFormat> libsigrok_output_format, | |
158 | shared_ptr<sigrok::Device> libsigrok_device, | |
159 | map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>()); | |
e2cfc0ef | 160 | |
31b3babd | 161 | /* Override start. */ |
b37c14d6 | 162 | bool start_vfunc(); |
e2cfc0ef | 163 | |
31b3babd UH |
164 | /* Override render. */ |
165 | Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer); | |
e2cfc0ef | 166 | |
31b3babd UH |
167 | /* Override stop. */ |
168 | bool stop_vfunc(); | |
e2cfc0ef | 169 | |
31b3babd UH |
170 | /* Gst class init. */ |
171 | static void class_init(Gst::ElementClass<LegacyOutput> *klass); | |
e2cfc0ef | 172 | |
31b3babd UH |
173 | /* Register class with plugin. */ |
174 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
175 | ||
176 | /* Constructor used by element factory. */ | |
177 | explicit LegacyOutput(GstBaseSink *gobj); | |
e2cfc0ef | 178 | |
e2cfc0ef | 179 | private: |
b37c14d6 UH |
180 | shared_ptr<sigrok::OutputFormat> libsigrok_output_format_; |
181 | shared_ptr<sigrok::Device> libsigrok_device_; | |
182 | shared_ptr<sigrok::Output> libsigrok_output_; | |
183 | map<string, Glib::VariantBase> options_; | |
e2cfc0ef | 184 | }; |
1060e9b5 | 185 | #endif |
e2cfc0ef | 186 | |
45e6e688 | 187 | #ifdef HAVE_LIBSIGROKDECODE |
b1322000 | 188 | class LegacyDecoder : |
31b3babd | 189 | public Sink |
b1322000 UH |
190 | { |
191 | public: | |
31b3babd UH |
192 | static Glib::RefPtr<LegacyDecoder> create( |
193 | struct srd_session *libsigrokdecode_session, uint64_t unitsize); | |
194 | ||
195 | /* Retrieve libsigrokdecode session. */ | |
196 | struct srd_session *libsigrokdecode_session(); | |
b1322000 | 197 | |
31b3babd UH |
198 | /* Override start. */ |
199 | bool start_vfunc(); | |
b1322000 | 200 | |
31b3babd UH |
201 | /* Override render. */ |
202 | Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer); | |
b1322000 | 203 | |
31b3babd UH |
204 | /* Override stop. */ |
205 | bool stop_vfunc(); | |
b1322000 | 206 | |
31b3babd UH |
207 | /* Gst class init. */ |
208 | static void class_init(Gst::ElementClass<LegacyDecoder> *klass); | |
b1322000 | 209 | |
31b3babd UH |
210 | /* Register class with plugin. */ |
211 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
b1322000 | 212 | |
31b3babd UH |
213 | /* Constructor used by element factory. */ |
214 | explicit LegacyDecoder(GstBaseSink *gobj); | |
b1322000 | 215 | |
b1322000 | 216 | private: |
b37c14d6 UH |
217 | struct srd_session *session_; |
218 | uint64_t abs_ss_; | |
219 | uint64_t unitsite_; | |
b1322000 | 220 | }; |
45e6e688 | 221 | #endif |
f7363af1 ML |
222 | |
223 | } | |
572e76fe | 224 | #endif |