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