]>
Commit | Line | Data |
---|---|---|
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 | namespace Srf | |
39 | { | |
40 | ||
41 | using namespace std; | |
42 | ||
43 | void init(); | |
44 | ||
45 | void deinit(); | |
46 | ||
47 | class Block | |
48 | { | |
49 | /* Config API etc. goes here. */ | |
50 | }; | |
51 | ||
52 | class Sink : | |
53 | public Gst::BaseSink | |
54 | { | |
55 | protected: | |
56 | explicit Sink(GstBaseSink *gobj); | |
57 | }; | |
58 | ||
59 | class Device : | |
60 | public Gst::Element | |
61 | { | |
62 | /* Operations specific to hardware devices go here. */ | |
63 | protected: | |
64 | explicit Device(GstElement *gobj); | |
65 | }; | |
66 | ||
67 | class CaptureDevice : | |
68 | public Device | |
69 | { | |
70 | /* Operations specific to capture (source) devices go here. */ | |
71 | protected: | |
72 | explicit CaptureDevice(GstElement *gobj); | |
73 | }; | |
74 | ||
75 | #ifdef HAVE_LIBSIGROKCXX | |
76 | class LegacyCaptureDevice : | |
77 | public CaptureDevice | |
78 | { | |
79 | public: | |
80 | /* Create from libsigrok device object. */ | |
81 | static Glib::RefPtr<LegacyCaptureDevice> create( | |
82 | shared_ptr<sigrok::HardwareDevice> libsigrok_device); | |
83 | ||
84 | /* Retrieve libsigrok device object. */ | |
85 | shared_ptr<sigrok::HardwareDevice> libsigrok_device(); | |
86 | ||
87 | /* Override state change. */ | |
88 | Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition); | |
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 | /* Constructor used by element factory. */ | |
97 | explicit LegacyCaptureDevice(GstElement *gobj); | |
98 | ||
99 | private: | |
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_; | |
105 | ||
106 | void datafeed_callback(shared_ptr<sigrok::Device> device, | |
107 | shared_ptr<sigrok::Packet> packet); | |
108 | void run(); | |
109 | }; | |
110 | ||
111 | class LegacyInput : | |
112 | public Gst::Element | |
113 | { | |
114 | public: | |
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(); | |
122 | ||
123 | /* Chain function. */ | |
124 | Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad, | |
125 | const Glib::RefPtr<Gst::Buffer> &buf); | |
126 | ||
127 | /* Override stop. */ | |
128 | bool stop_vfunc(); | |
129 | ||
130 | /* Gst class init. */ | |
131 | static void class_init(Gst::ElementClass<LegacyInput> *klass); | |
132 | ||
133 | /* Register class with plugin. */ | |
134 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
135 | ||
136 | /* Constructor used by element factory. */ | |
137 | explicit LegacyInput(GstElement *gobj); | |
138 | ||
139 | private: | |
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 | ||
147 | void datafeed_callback(shared_ptr<sigrok::Device> device, | |
148 | shared_ptr<sigrok::Packet> packet); | |
149 | }; | |
150 | ||
151 | class LegacyOutput : | |
152 | public Sink | |
153 | { | |
154 | public: | |
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>()); | |
160 | ||
161 | /* Override start. */ | |
162 | bool start_vfunc(); | |
163 | ||
164 | /* Override render. */ | |
165 | Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer); | |
166 | ||
167 | /* Override stop. */ | |
168 | bool stop_vfunc(); | |
169 | ||
170 | /* Gst class init. */ | |
171 | static void class_init(Gst::ElementClass<LegacyOutput> *klass); | |
172 | ||
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); | |
178 | ||
179 | private: | |
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_; | |
184 | }; | |
185 | #endif | |
186 | ||
187 | #ifdef HAVE_LIBSIGROKDECODE | |
188 | class LegacyDecoder : | |
189 | public Sink | |
190 | { | |
191 | public: | |
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(); | |
197 | ||
198 | /* Override start. */ | |
199 | bool start_vfunc(); | |
200 | ||
201 | /* Override render. */ | |
202 | Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer); | |
203 | ||
204 | /* Override stop. */ | |
205 | bool stop_vfunc(); | |
206 | ||
207 | /* Gst class init. */ | |
208 | static void class_init(Gst::ElementClass<LegacyDecoder> *klass); | |
209 | ||
210 | /* Register class with plugin. */ | |
211 | static bool register_element(Glib::RefPtr<Gst::Plugin> plugin); | |
212 | ||
213 | /* Constructor used by element factory. */ | |
214 | explicit LegacyDecoder(GstBaseSink *gobj); | |
215 | ||
216 | private: | |
217 | struct srd_session *session_; | |
218 | uint64_t abs_ss_; | |
219 | uint64_t unitsite_; | |
220 | }; | |
221 | #endif | |
222 | ||
223 | } | |
224 | #endif |