]> sigrok.org Git - libsigrokflow.git/blame - src/legacy_output.cpp
Add some missing #includes.
[libsigrokflow.git] / src / legacy_output.cpp
CommitLineData
36801352
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>
bf71e84f 22#include <libsigrokflow/legacy_output.hpp>
4f0c2351
UH
23#include <glib.h>
24#include <iostream>
25#include <map>
26#include <memory>
27#include <stdexcept>
28#include <string>
bf71e84f 29#include <gstreamermm/private/basesink_p.h>
36801352
UH
30
31namespace Srf
32{
33
34using namespace std;
35
36#ifdef HAVE_LIBSIGROKCXX
37void LegacyOutput::class_init(Gst::ElementClass<LegacyOutput> *klass)
38{
39 klass->set_metadata("sigrok legacy output",
40 "Sink", "Wrapper for outputs using legacy libsigrok APIs",
41 "Martin Ling");
42
43 klass->add_pad_template(Gst::PadTemplate::create(
44 "sink",
45 Gst::PAD_SINK,
46 Gst::PAD_ALWAYS,
47 Gst::Caps::create_any()));
48}
49
50bool LegacyOutput::register_element(Glib::RefPtr<Gst::Plugin> plugin)
51{
52 Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output",
53 0, Gst::register_mm_type<LegacyOutput>(
54 "sigrok_legacy_output"));
55
56 return true;
57}
58
59LegacyOutput::LegacyOutput(GstBaseSink *gobj) :
60 Glib::ObjectBase(typeid(LegacyOutput)),
61 Sink(gobj)
62{
63}
64
65Glib::RefPtr<LegacyOutput>LegacyOutput::create(
66 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
36801352
UH
67 map<string, Glib::VariantBase> options)
68{
69 auto element = Gst::ElementFactory::create_element("sigrok_legacy_output");
70 if (!element)
71 throw runtime_error("Failed to create element - plugin not registered?");
72 auto output = Glib::RefPtr<LegacyOutput>::cast_static(element);
73 output->libsigrok_output_format_ = libsigrok_output_format;
107a0d0c
ML
74 auto context = libsigrok_output_format->parent();
75 output->libsigrok_device_ = context->create_user_device("Vendor", "Model", "Version");
9710a16a
ML
76 for (int i = 0; i < 8; ++i) {
77 gchar *name = g_strdup_printf("D%d", i);
78 output->libsigrok_device_->add_channel(i, sigrok::ChannelType::LOGIC, name);
79 g_free(name);
80 }
36801352
UH
81 output->options_ = options;
82
83 return output;
84}
85
86bool LegacyOutput::start_vfunc()
87{
88 libsigrok_output_ = libsigrok_output_format_->create_output(
89 libsigrok_device_, options_);
90
91 return true;
92}
93
94Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer)
95{
96 Gst::MapInfo info;
97 buffer->map(info, Gst::MAP_READ);
98 auto context = libsigrok_output_format_->parent();
99 auto packet = context->create_logic_packet(
100 info.get_data(), info.get_size(), 2);
101 auto result = libsigrok_output_->receive(packet);
102 cout << result;
103 buffer->unmap(info);
104
105 return Gst::FLOW_OK;
106}
107
108bool LegacyOutput::stop_vfunc()
109{
110 auto context = libsigrok_output_format_->parent();
111 auto end_packet = context->create_end_packet();
112 auto result = libsigrok_output_->receive(end_packet);
113 cout << result;
114
115 return true;
116}
117#endif
118
119}