]>
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 | |
8ab86460 UH |
38 | #include <libsigrokflow/init.hpp> |
39 | ||
b903bb0a UH |
40 | namespace Srf |
41 | { | |
42 | ||
f7363af1 ML |
43 | using namespace std; |
44 | ||
f7363af1 ML |
45 | class Block |
46 | { | |
31b3babd | 47 | /* Config API etc. goes here. */ |
f7363af1 ML |
48 | }; |
49 | ||
e2cfc0ef | 50 | class Sink : |
31b3babd | 51 | public Gst::BaseSink |
f7363af1 | 52 | { |
6d71d36a | 53 | protected: |
31b3babd | 54 | explicit Sink(GstBaseSink *gobj); |
f7363af1 ML |
55 | }; |
56 | ||
57 | class Device : | |
31b3babd | 58 | public Gst::Element |
f7363af1 | 59 | { |
31b3babd | 60 | /* Operations specific to hardware devices go here. */ |
6d71d36a | 61 | protected: |
31b3babd | 62 | explicit Device(GstElement *gobj); |
f7363af1 | 63 | }; |
b903bb0a | 64 | |
f7363af1 | 65 | class CaptureDevice : |
31b3babd | 66 | public Device |
f7363af1 | 67 | { |
31b3babd | 68 | /* Operations specific to capture (source) devices go here. */ |
6d71d36a | 69 | protected: |
31b3babd | 70 | explicit CaptureDevice(GstElement *gobj); |
f7363af1 ML |
71 | }; |
72 | ||
1060e9b5 | 73 | #ifdef HAVE_LIBSIGROKCXX |
f7363af1 | 74 | class LegacyCaptureDevice : |
31b3babd | 75 | public CaptureDevice |
f7363af1 ML |
76 | { |
77 | public: | |
31b3babd UH |
78 | /* Create from libsigrok device object. */ |
79 | static Glib::RefPtr<LegacyCaptureDevice> create( | |
80 | shared_ptr<sigrok::HardwareDevice> libsigrok_device); | |
f7363af1 | 81 | |
31b3babd UH |
82 | /* Retrieve libsigrok device object. */ |
83 | shared_ptr<sigrok::HardwareDevice> libsigrok_device(); | |
d03b3a98 | 84 | |
31b3babd | 85 | /* Override state change. */ |
8ddc0b74 | 86 | Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition) override; |
6d71d36a | 87 | |
31b3babd UH |
88 | /* Gst class init. */ |
89 | static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass); | |
6d71d36a | 90 | |
31b3babd UH |
91 | /* Register class with plugin. */ |
92 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
93 | ||
94 | /* Constructor used by element factory. */ | |
95 | explicit LegacyCaptureDevice(GstElement *gobj); | |
6d71d36a | 96 | |
f7363af1 | 97 | private: |
b37c14d6 UH |
98 | shared_ptr<sigrok::HardwareDevice> libsigrok_device_; |
99 | Glib::RefPtr<Gst::Pad> src_pad_; | |
100 | Glib::Threads::RecMutex mutex_; | |
101 | Glib::RefPtr<Gst::Task> task_; | |
102 | shared_ptr<sigrok::Session> session_; | |
31b3babd | 103 | |
897cb509 | 104 | void datafeed_callback(shared_ptr<sigrok::Device> device, |
31b3babd | 105 | shared_ptr<sigrok::Packet> packet); |
897cb509 | 106 | void run(); |
f7363af1 ML |
107 | }; |
108 | ||
92d521e7 | 109 | class LegacyInput : |
31b3babd | 110 | public Gst::Element |
92d521e7 ML |
111 | { |
112 | public: | |
31b3babd UH |
113 | /* Create from libsigrok input. */ |
114 | static Glib::RefPtr<LegacyInput> create( | |
115 | shared_ptr<sigrok::InputFormat> format, | |
116 | map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>()); | |
117 | ||
8ddc0b74 | 118 | /* Chain function (not an override). */ |
31b3babd UH |
119 | Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, |
120 | const Glib::RefPtr<Gst::Buffer> &buf); | |
92d521e7 | 121 | |
fce9342e ML |
122 | /* Event function (not an override). */ |
123 | bool event(const Glib::RefPtr<Gst::Pad> &pad, | |
124 | Glib::RefPtr<Gst::Event> &event); | |
92d521e7 | 125 | |
31b3babd UH |
126 | /* Gst class init. */ |
127 | static void class_init(Gst::ElementClass<LegacyInput> *klass); | |
92d521e7 | 128 | |
31b3babd UH |
129 | /* Register class with plugin. */ |
130 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
92d521e7 | 131 | |
31b3babd UH |
132 | /* Constructor used by element factory. */ |
133 | explicit LegacyInput(GstElement *gobj); | |
92d521e7 | 134 | |
92d521e7 | 135 | private: |
b37c14d6 UH |
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_; | |
142 | ||
897cb509 | 143 | void datafeed_callback(shared_ptr<sigrok::Device> device, |
31b3babd | 144 | shared_ptr<sigrok::Packet> packet); |
92d521e7 ML |
145 | }; |
146 | ||
e2cfc0ef | 147 | class LegacyOutput : |
31b3babd | 148 | public Sink |
e2cfc0ef ML |
149 | { |
150 | public: | |
31b3babd UH |
151 | /* Create from libsigrok output object. */ |
152 | static Glib::RefPtr<LegacyOutput> create( | |
153 | shared_ptr<sigrok::OutputFormat> libsigrok_output_format, | |
31b3babd | 154 | map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>()); |
e2cfc0ef | 155 | |
31b3babd | 156 | /* Override start. */ |
8ddc0b74 | 157 | bool start_vfunc() override; |
e2cfc0ef | 158 | |
31b3babd | 159 | /* Override render. */ |
8ddc0b74 | 160 | Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override; |
e2cfc0ef | 161 | |
31b3babd | 162 | /* Override stop. */ |
8ddc0b74 | 163 | bool stop_vfunc() override; |
e2cfc0ef | 164 | |
31b3babd UH |
165 | /* Gst class init. */ |
166 | static void class_init(Gst::ElementClass<LegacyOutput> *klass); | |
e2cfc0ef | 167 | |
31b3babd UH |
168 | /* Register class with plugin. */ |
169 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
170 | ||
171 | /* Constructor used by element factory. */ | |
172 | explicit LegacyOutput(GstBaseSink *gobj); | |
e2cfc0ef | 173 | |
e2cfc0ef | 174 | private: |
b37c14d6 | 175 | shared_ptr<sigrok::OutputFormat> libsigrok_output_format_; |
9710a16a | 176 | shared_ptr<sigrok::UserDevice> libsigrok_device_; |
b37c14d6 UH |
177 | shared_ptr<sigrok::Output> libsigrok_output_; |
178 | map<string, Glib::VariantBase> options_; | |
e2cfc0ef | 179 | }; |
1060e9b5 | 180 | #endif |
e2cfc0ef | 181 | |
45e6e688 | 182 | #ifdef HAVE_LIBSIGROKDECODE |
b1322000 | 183 | class LegacyDecoder : |
31b3babd | 184 | public Sink |
b1322000 UH |
185 | { |
186 | public: | |
31b3babd UH |
187 | static Glib::RefPtr<LegacyDecoder> create( |
188 | struct srd_session *libsigrokdecode_session, uint64_t unitsize); | |
189 | ||
190 | /* Retrieve libsigrokdecode session. */ | |
191 | struct srd_session *libsigrokdecode_session(); | |
b1322000 | 192 | |
31b3babd | 193 | /* Override start. */ |
8ddc0b74 | 194 | bool start_vfunc() override; |
b1322000 | 195 | |
31b3babd | 196 | /* Override render. */ |
8ddc0b74 | 197 | Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) override; |
b1322000 | 198 | |
31b3babd | 199 | /* Override stop. */ |
8ddc0b74 | 200 | bool stop_vfunc() override; |
b1322000 | 201 | |
31b3babd UH |
202 | /* Gst class init. */ |
203 | static void class_init(Gst::ElementClass<LegacyDecoder> *klass); | |
b1322000 | 204 | |
31b3babd UH |
205 | /* Register class with plugin. */ |
206 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
b1322000 | 207 | |
31b3babd UH |
208 | /* Constructor used by element factory. */ |
209 | explicit LegacyDecoder(GstBaseSink *gobj); | |
b1322000 | 210 | |
b1322000 | 211 | private: |
b37c14d6 UH |
212 | struct srd_session *session_; |
213 | uint64_t abs_ss_; | |
214 | uint64_t unitsite_; | |
b1322000 | 215 | }; |
45e6e688 | 216 | #endif |
f7363af1 ML |
217 | |
218 | } | |
572e76fe | 219 | #endif |