]> sigrok.org Git - libsigrokflow.git/blame - include/libsigrokflow/libsigrokflow.hpp
Implement LegacyInput.
[libsigrokflow.git] / include / libsigrokflow / libsigrokflow.hpp
CommitLineData
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
f7363af1 24#include <gstreamermm.h>
37469b3d 25#include <gstreamermm/private/element_p.h>
e2cfc0ef 26#include <gstreamermm/private/basesink_p.h>
f7363af1 27#include <libsigrokcxx/libsigrokcxx.hpp>
b1322000 28#include <libsigrokdecode/libsigrokdecode.h>
f7363af1 29
b903bb0a
UH
30namespace Srf
31{
32
f7363af1
ML
33using namespace std;
34
b903bb0a
UH
35void init();
36
f7363af1
ML
37class Block
38{
39 /* Config API etc goes here */
40};
41
e2cfc0ef
ML
42class Sink :
43 public Gst::BaseSink
f7363af1 44{
6d71d36a 45protected:
e2cfc0ef 46 explicit Sink(GstBaseSink *gobj);
f7363af1
ML
47};
48
49class Device :
e2cfc0ef 50 public Gst::Element
f7363af1
ML
51{
52 /* Operations specific to hardware devices go here */
6d71d36a
ML
53protected:
54 explicit Device(GstElement *gobj);
f7363af1 55};
b903bb0a 56
f7363af1
ML
57class CaptureDevice :
58 public Device
59{
60 /* Operations specific to capture (source) devices go here */
6d71d36a
ML
61protected:
62 explicit CaptureDevice(GstElement *gobj);
f7363af1
ML
63};
64
65class LegacyCaptureDevice :
66 public CaptureDevice
67{
68public:
64b0db03
ML
69 /* Create from libsigrok device object */
70 static Glib::RefPtr<LegacyCaptureDevice> create(
71 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
f7363af1
ML
72
73 /* Retrieve libsigrok device object */
d03b3a98
ML
74 shared_ptr<sigrok::HardwareDevice> libsigrok_device();
75
76 /* Override state change */
77 Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
6d71d36a
ML
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);
f7363af1 87private:
64b0db03 88 shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
d03b3a98
ML
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();
f7363af1
ML
97};
98
92d521e7
ML
99class LegacyInput :
100 public Gst::Element
101{
102public:
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);
126private:
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
e2cfc0ef
ML
138class LegacyOutput :
139 public Sink
140{
141public:
142 /* Create from libsigrok output object */
143 static Glib::RefPtr<LegacyOutput> create(
726122c2
ML
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>());
e2cfc0ef 147
726122c2
ML
148 /* Override start */
149 bool start_vfunc();
e2cfc0ef
ML
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);
165private:
726122c2
ML
166 shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
167 shared_ptr<sigrok::Device> _libsigrok_device;
e2cfc0ef 168 shared_ptr<sigrok::Output> _libsigrok_output;
726122c2 169 map<string, Glib::VariantBase> _options;
e2cfc0ef
ML
170};
171
b1322000
UH
172class LegacyDecoder :
173 public Sink
174{
175public:
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);
199private:
200 struct srd_session *_session;
201 uint64_t _abs_ss;
202 uint64_t _unitsize;
203};
f7363af1
ML
204
205}
572e76fe 206#endif