]> sigrok.org Git - libsigrokflow.git/blob - src/legacy_decoder.cpp
Add contrib/libsigrokflow_112x112.png.
[libsigrokflow.git] / src / legacy_decoder.cpp
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 #include <config.h>
22 #include <libsigrokflow/libsigrokflow.hpp>
23
24 namespace Srf
25 {
26
27 using namespace std;
28
29 #ifdef HAVE_LIBSIGROKDECODE
30 void LegacyDecoder::class_init(Gst::ElementClass<LegacyDecoder> *klass)
31 {
32         klass->set_metadata("sigrok legacy decoder",
33                         "Sink", "Wrapper for protocol decoders using legacy libsigrokdecode APIs",
34                         "Uwe Hermann");
35
36         klass->add_pad_template(Gst::PadTemplate::create(
37                         "sink",
38                         Gst::PAD_SINK,
39                         Gst::PAD_ALWAYS,
40                         Gst::Caps::create_any()));
41 }
42
43 bool LegacyDecoder::register_element(Glib::RefPtr<Gst::Plugin> plugin)
44 {
45         Gst::ElementFactory::register_element(plugin, "sigrok_legacy_decoder",
46                         0, Gst::register_mm_type<LegacyDecoder>(
47                                 "sigrok_legacy_decoder"));
48
49         return true;
50 }
51
52 LegacyDecoder::LegacyDecoder(GstBaseSink *gobj) :
53         Glib::ObjectBase(typeid(LegacyDecoder)),
54         Sink(gobj)
55 {
56 }
57
58 Glib::RefPtr<LegacyDecoder>LegacyDecoder::create(
59         struct srd_session *libsigrokdecode_session, uint64_t unitsize)
60 {
61         auto element = Gst::ElementFactory::create_element("sigrok_legacy_decoder");
62         if (!element)
63                 throw runtime_error("Failed to create element - plugin not registered?");
64         auto decoder = Glib::RefPtr<LegacyDecoder>::cast_static(element);
65         decoder->session_ = libsigrokdecode_session;
66         decoder->unitsite_ = unitsize;
67
68         return decoder;
69 }
70
71 struct srd_session *LegacyDecoder::libsigrokdecode_session()
72 {
73         return session_;
74 }
75
76 Gst::FlowReturn LegacyDecoder::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer)
77 {
78         Gst::MapInfo info;
79         buffer->map(info, Gst::MAP_READ);
80         uint64_t num_samples = info.get_size() / unitsite_;
81         srd_session_send(session_, abs_ss_, abs_ss_ + num_samples,
82                 info.get_data(), info.get_size(), unitsite_);
83         abs_ss_ += num_samples;
84         buffer->unmap(info);
85
86         return Gst::FLOW_OK;
87 }
88
89 bool LegacyDecoder::start_vfunc()
90 {
91         abs_ss_ = 0;
92         srd_session_start(session_);
93
94         return true;
95 }
96
97 bool LegacyDecoder::stop_vfunc()
98 {
99         srd_session_terminate_reset(session_);
100
101         return true;
102 }
103 #endif
104
105 }