]> sigrok.org Git - libsigrokflow.git/blame - include/libsigrokflow/libsigrokflow.hpp
Initial LegacyDecoder implementation.
[libsigrokflow.git] / include / libsigrokflow / libsigrokflow.hpp
CommitLineData
572e76fe
UH
1/*
2 * This file is part of the libsigrokflow project.
3 *
4 * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
21#define LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
22
f7363af1 23#include <gstreamermm.h>
37469b3d 24#include <gstreamermm/private/element_p.h>
e2cfc0ef 25#include <gstreamermm/private/basesink_p.h>
f7363af1 26#include <libsigrokcxx/libsigrokcxx.hpp>
b1322000 27#include <libsigrokdecode/libsigrokdecode.h>
f7363af1 28
b903bb0a
UH
29namespace Srf
30{
31
f7363af1
ML
32using namespace std;
33
b903bb0a
UH
34void init();
35
f7363af1
ML
36class Block
37{
38 /* Config API etc goes here */
39};
40
e2cfc0ef
ML
41class Sink :
42 public Gst::BaseSink
f7363af1 43{
6d71d36a 44protected:
e2cfc0ef 45 explicit Sink(GstBaseSink *gobj);
f7363af1
ML
46};
47
48class Device :
e2cfc0ef 49 public Gst::Element
f7363af1
ML
50{
51 /* Operations specific to hardware devices go here */
6d71d36a
ML
52protected:
53 explicit Device(GstElement *gobj);
f7363af1 54};
b903bb0a 55
f7363af1
ML
56class CaptureDevice :
57 public Device
58{
59 /* Operations specific to capture (source) devices go here */
6d71d36a
ML
60protected:
61 explicit CaptureDevice(GstElement *gobj);
f7363af1
ML
62};
63
64class LegacyCaptureDevice :
65 public CaptureDevice
66{
67public:
64b0db03
ML
68 /* Create from libsigrok device object */
69 static Glib::RefPtr<LegacyCaptureDevice> create(
70 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
f7363af1
ML
71
72 /* Retrieve libsigrok device object */
d03b3a98
ML
73 shared_ptr<sigrok::HardwareDevice> libsigrok_device();
74
75 /* Override state change */
76 Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
6d71d36a
ML
77
78 /* Gst class init */
79 static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
80
81 /* Register class with plugin */
82 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
83
84 /* Construcor used by element factory */
85 explicit LegacyCaptureDevice(GstElement *gobj);
f7363af1 86private:
64b0db03 87 shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
d03b3a98
ML
88 Glib::RefPtr<Gst::Pad> _src_pad;
89 Glib::Threads::RecMutex _mutex;
90 Glib::RefPtr<Gst::Task> _task;
91 shared_ptr<sigrok::Session> _session;
92
93 void _datafeed_callback(shared_ptr<sigrok::Device> device,
94 shared_ptr<sigrok::Packet> packet);
95 void _run();
f7363af1
ML
96};
97
e2cfc0ef
ML
98class LegacyOutput :
99 public Sink
100{
101public:
102 /* Create from libsigrok output object */
103 static Glib::RefPtr<LegacyOutput> create(
726122c2
ML
104 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
105 shared_ptr<sigrok::Device> libsigrok_device,
106 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
e2cfc0ef 107
726122c2
ML
108 /* Override start */
109 bool start_vfunc();
e2cfc0ef
ML
110
111 /* Override render */
112 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
113
114 /* Override stop */
115 bool stop_vfunc();
116
117 /* Gst class init */
118 static void class_init(Gst::ElementClass<LegacyOutput> *klass);
119
120 /* Register class with plugin */
121 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
122
123 /* Constructor used by element factory */
124 explicit LegacyOutput(GstBaseSink *gobj);
125private:
726122c2
ML
126 shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
127 shared_ptr<sigrok::Device> _libsigrok_device;
e2cfc0ef 128 shared_ptr<sigrok::Output> _libsigrok_output;
726122c2 129 map<string, Glib::VariantBase> _options;
e2cfc0ef
ML
130};
131
b1322000
UH
132class LegacyDecoder :
133 public Sink
134{
135public:
136 static Glib::RefPtr<LegacyDecoder> create(
137 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
138
139 /* Retrieve libsigrokdecode session */
140 struct srd_session *libsigrokdecode_session();
141
142 /* Override start */
143 bool start_vfunc();
144
145 /* Override render */
146 Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
147
148 /* Override stop */
149 bool stop_vfunc();
150
151 /* Gst class init */
152 static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
153
154 /* Register class with plugin */
155 static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
156
157 /* Constructor used by element factory */
158 explicit LegacyDecoder(GstBaseSink *gobj);
159private:
160 struct srd_session *_session;
161 uint64_t _abs_ss;
162 uint64_t _unitsize;
163};
f7363af1
ML
164
165}
572e76fe 166#endif