2 * This file is part of the libsigrokflow project.
4 * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
5 * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
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.
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.
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/>.
23 #include <libsigrokflow/legacy_output.hpp>
24 #include <gstreamermm/private/basesink_p.h>
31 #ifdef HAVE_LIBSIGROKCXX
32 void LegacyOutput::class_init(Gst::ElementClass<LegacyOutput> *klass)
34 klass->set_metadata("sigrok legacy output",
35 "Sink", "Wrapper for outputs using legacy libsigrok APIs",
38 klass->add_pad_template(Gst::PadTemplate::create(
42 Gst::Caps::create_any()));
45 bool LegacyOutput::register_element(Glib::RefPtr<Gst::Plugin> plugin)
47 Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output",
48 0, Gst::register_mm_type<LegacyOutput>(
49 "sigrok_legacy_output"));
54 LegacyOutput::LegacyOutput(GstBaseSink *gobj) :
55 Glib::ObjectBase(typeid(LegacyOutput)),
60 Glib::RefPtr<LegacyOutput>LegacyOutput::create(
61 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
62 map<string, Glib::VariantBase> options)
64 auto element = Gst::ElementFactory::create_element("sigrok_legacy_output");
66 throw runtime_error("Failed to create element - plugin not registered?");
67 auto output = Glib::RefPtr<LegacyOutput>::cast_static(element);
68 output->libsigrok_output_format_ = libsigrok_output_format;
69 auto context = libsigrok_output_format->parent();
70 output->libsigrok_device_ = context->create_user_device("Vendor", "Model", "Version");
71 for (int i = 0; i < 8; ++i) {
72 gchar *name = g_strdup_printf("D%d", i);
73 output->libsigrok_device_->add_channel(i, sigrok::ChannelType::LOGIC, name);
76 output->options_ = options;
81 bool LegacyOutput::start_vfunc()
83 libsigrok_output_ = libsigrok_output_format_->create_output(
84 libsigrok_device_, options_);
89 Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer)
92 buffer->map(info, Gst::MAP_READ);
93 auto context = libsigrok_output_format_->parent();
94 auto packet = context->create_logic_packet(
95 info.get_data(), info.get_size(), 2);
96 auto result = libsigrok_output_->receive(packet);
103 bool LegacyOutput::stop_vfunc()
105 auto context = libsigrok_output_format_->parent();
106 auto end_packet = context->create_end_packet();
107 auto result = libsigrok_output_->receive(end_packet);