]>
Commit | Line | Data |
---|---|---|
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> | |
22 | #include <iostream> | |
23 | #include <libsigrokflow/libsigrokflow.hpp> | |
24 | ||
25 | namespace Srf | |
26 | { | |
27 | ||
28 | using namespace std; | |
29 | ||
30 | #ifdef HAVE_LIBSIGROKCXX | |
31 | void LegacyOutput::class_init(Gst::ElementClass<LegacyOutput> *klass) | |
32 | { | |
33 | klass->set_metadata("sigrok legacy output", | |
34 | "Sink", "Wrapper for outputs using legacy libsigrok APIs", | |
35 | "Martin Ling"); | |
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 | ||
44 | bool LegacyOutput::register_element(Glib::RefPtr<Gst::Plugin> plugin) | |
45 | { | |
46 | Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output", | |
47 | 0, Gst::register_mm_type<LegacyOutput>( | |
48 | "sigrok_legacy_output")); | |
49 | ||
50 | return true; | |
51 | } | |
52 | ||
53 | LegacyOutput::LegacyOutput(GstBaseSink *gobj) : | |
54 | Glib::ObjectBase(typeid(LegacyOutput)), | |
55 | Sink(gobj) | |
56 | { | |
57 | } | |
58 | ||
59 | Glib::RefPtr<LegacyOutput>LegacyOutput::create( | |
60 | shared_ptr<sigrok::OutputFormat> libsigrok_output_format, | |
61 | shared_ptr<sigrok::Device> libsigrok_device, | |
62 | map<string, Glib::VariantBase> options) | |
63 | { | |
64 | auto element = Gst::ElementFactory::create_element("sigrok_legacy_output"); | |
65 | if (!element) | |
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 | output->libsigrok_device_ = libsigrok_device; | |
70 | output->options_ = options; | |
71 | ||
72 | return output; | |
73 | } | |
74 | ||
75 | bool LegacyOutput::start_vfunc() | |
76 | { | |
77 | libsigrok_output_ = libsigrok_output_format_->create_output( | |
78 | libsigrok_device_, options_); | |
79 | ||
80 | return true; | |
81 | } | |
82 | ||
83 | Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer) | |
84 | { | |
85 | Gst::MapInfo info; | |
86 | buffer->map(info, Gst::MAP_READ); | |
87 | auto context = libsigrok_output_format_->parent(); | |
88 | auto packet = context->create_logic_packet( | |
89 | info.get_data(), info.get_size(), 2); | |
90 | auto result = libsigrok_output_->receive(packet); | |
91 | cout << result; | |
92 | buffer->unmap(info); | |
93 | ||
94 | return Gst::FLOW_OK; | |
95 | } | |
96 | ||
97 | bool LegacyOutput::stop_vfunc() | |
98 | { | |
99 | auto context = libsigrok_output_format_->parent(); | |
100 | auto end_packet = context->create_end_packet(); | |
101 | auto result = libsigrok_output_->receive(end_packet); | |
102 | cout << result; | |
103 | ||
104 | return true; | |
105 | } | |
106 | #endif | |
107 | ||
108 | } |