From: Uwe Hermann Date: Wed, 9 Jan 2019 01:28:15 +0000 (+0100) Subject: Factor out src/legacy_output.cpp. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3680135232d54e7acde8d093d2901f23ce166d92;p=libsigrokflow.git Factor out src/legacy_output.cpp. --- diff --git a/Makefile.am b/Makefile.am index 2f2c418..7fe4fc4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,8 @@ libsigrokflow_la_SOURCES = \ src/main.cpp \ src/init.cpp \ src/legacy_capture_device.cpp \ - src/legacy_input.cpp + src/legacy_input.cpp \ + src/legacy_output.cpp libsigrokflow_la_LIBADD = $(LIBSIGROKFLOW_LIBS) libsigrokflow_la_LDFLAGS = -version-info $(SRF_LIB_VERSION) -no-undefined diff --git a/src/legacy_output.cpp b/src/legacy_output.cpp new file mode 100644 index 0000000..95e9320 --- /dev/null +++ b/src/legacy_output.cpp @@ -0,0 +1,108 @@ +/* + * This file is part of the libsigrokflow project. + * + * Copyright (C) 2018 Martin Ling + * Copyright (C) 2018 Uwe Hermann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +namespace Srf +{ + +using namespace std; + +#ifdef HAVE_LIBSIGROKCXX +void LegacyOutput::class_init(Gst::ElementClass *klass) +{ + klass->set_metadata("sigrok legacy output", + "Sink", "Wrapper for outputs using legacy libsigrok APIs", + "Martin Ling"); + + klass->add_pad_template(Gst::PadTemplate::create( + "sink", + Gst::PAD_SINK, + Gst::PAD_ALWAYS, + Gst::Caps::create_any())); +} + +bool LegacyOutput::register_element(Glib::RefPtr plugin) +{ + Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output", + 0, Gst::register_mm_type( + "sigrok_legacy_output")); + + return true; +} + +LegacyOutput::LegacyOutput(GstBaseSink *gobj) : + Glib::ObjectBase(typeid(LegacyOutput)), + Sink(gobj) +{ +} + +Glib::RefPtrLegacyOutput::create( + shared_ptr libsigrok_output_format, + shared_ptr libsigrok_device, + map options) +{ + auto element = Gst::ElementFactory::create_element("sigrok_legacy_output"); + if (!element) + throw runtime_error("Failed to create element - plugin not registered?"); + auto output = Glib::RefPtr::cast_static(element); + output->libsigrok_output_format_ = libsigrok_output_format; + output->libsigrok_device_ = libsigrok_device; + output->options_ = options; + + return output; +} + +bool LegacyOutput::start_vfunc() +{ + libsigrok_output_ = libsigrok_output_format_->create_output( + libsigrok_device_, options_); + + return true; +} + +Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr &buffer) +{ + Gst::MapInfo info; + buffer->map(info, Gst::MAP_READ); + auto context = libsigrok_output_format_->parent(); + auto packet = context->create_logic_packet( + info.get_data(), info.get_size(), 2); + auto result = libsigrok_output_->receive(packet); + cout << result; + buffer->unmap(info); + + return Gst::FLOW_OK; +} + +bool LegacyOutput::stop_vfunc() +{ + auto context = libsigrok_output_format_->parent(); + auto end_packet = context->create_end_packet(); + auto result = libsigrok_output_->receive(end_packet); + cout << result; + + return true; +} +#endif + +} diff --git a/src/main.cpp b/src/main.cpp index 15c968e..208af49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,14 +19,12 @@ */ #include -#include #include namespace Srf { using namespace std; -using namespace std::placeholders; Sink::Sink(GstBaseSink *gobj) : Gst::BaseSink(gobj) @@ -43,84 +41,6 @@ CaptureDevice::CaptureDevice(GstElement *gobj) : { } -#ifdef HAVE_LIBSIGROKCXX -void LegacyOutput::class_init(Gst::ElementClass *klass) -{ - klass->set_metadata("sigrok legacy output", - "Sink", "Wrapper for outputs using legacy libsigrok APIs", - "Martin Ling"); - - klass->add_pad_template(Gst::PadTemplate::create( - "sink", - Gst::PAD_SINK, - Gst::PAD_ALWAYS, - Gst::Caps::create_any())); -} - -bool LegacyOutput::register_element(Glib::RefPtr plugin) -{ - Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output", - 0, Gst::register_mm_type( - "sigrok_legacy_output")); - - return true; -} - -LegacyOutput::LegacyOutput(GstBaseSink *gobj) : - Glib::ObjectBase(typeid(LegacyOutput)), - Sink(gobj) -{ -} - -Glib::RefPtrLegacyOutput::create( - shared_ptr libsigrok_output_format, - shared_ptr libsigrok_device, - map options) -{ - auto element = Gst::ElementFactory::create_element("sigrok_legacy_output"); - if (!element) - throw runtime_error("Failed to create element - plugin not registered?"); - auto output = Glib::RefPtr::cast_static(element); - output->libsigrok_output_format_ = libsigrok_output_format; - output->libsigrok_device_ = libsigrok_device; - output->options_ = options; - - return output; -} - -bool LegacyOutput::start_vfunc() -{ - libsigrok_output_ = libsigrok_output_format_->create_output( - libsigrok_device_, options_); - - return true; -} - -Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr &buffer) -{ - Gst::MapInfo info; - buffer->map(info, Gst::MAP_READ); - auto context = libsigrok_output_format_->parent(); - auto packet = context->create_logic_packet( - info.get_data(), info.get_size(), 2); - auto result = libsigrok_output_->receive(packet); - cout << result; - buffer->unmap(info); - - return Gst::FLOW_OK; -} - -bool LegacyOutput::stop_vfunc() -{ - auto context = libsigrok_output_format_->parent(); - auto end_packet = context->create_end_packet(); - auto result = libsigrok_output_->receive(end_packet); - cout << result; - - return true; -} -#endif - #ifdef HAVE_LIBSIGROKDECODE void LegacyDecoder::class_init(Gst::ElementClass *klass) {