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