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