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