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