X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fmain.cpp;h=080ef64376e5fe69d66dcbfc5402f909cb6debc1;hb=1060e9b5f80cde2c6b6cb18ded1fdbe0862c7796;hp=b80d203c804e77853dbe0da7cb19a0cfda5d880a;hpb=b1322000ef157ecc1a2716a3b89e967a1e0ce97a;p=libsigrokflow.git diff --git a/src/main.cpp b/src/main.cpp index b80d203..080ef64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ /* * 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 @@ -32,16 +33,23 @@ using namespace std::placeholders; void init() { +#ifdef HAVE_LIBSIGROKCXX Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "sigrok_legacy_capture_device", "Wrapper for capture devices using legacy libsigrok APIs", sigc::ptr_fun(&LegacyCaptureDevice::register_element), "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); + Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, + "sigrok_legacy_input", + "Wrapper for inputs using legacy libsigrok APIs", + sigc::ptr_fun(&LegacyInput::register_element), + "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "sigrok_legacy_output", "Wrapper for outputs using legacy libsigrok APIs", sigc::ptr_fun(&LegacyOutput::register_element), "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); +#endif Gst::Plugin::register_static(GST_VERSION_MAJOR, GST_VERSION_MINOR, "sigrok_legacy_decoder", "Wrapper for protocol decoders using legacy libsigrokdecode APIs", @@ -64,6 +72,7 @@ CaptureDevice::CaptureDevice(GstElement *gobj) : { } +#ifdef HAVE_LIBSIGROKCXX void LegacyCaptureDevice::class_init(Gst::ElementClass *klass) { klass->set_metadata("sigrok legacy capture device", @@ -164,6 +173,111 @@ void LegacyCaptureDevice::_run() _task->stop(); } +void LegacyInput::class_init(Gst::ElementClass *klass) +{ + klass->set_metadata("sigrok legacy input", + "Transform", "Wrapper for inputs using legacy libsigrok APIs", + "Martin Ling"); + + klass->add_pad_template(Gst::PadTemplate::create( + "sink", + Gst::PAD_SINK, + Gst::PAD_ALWAYS, + Gst::Caps::create_any())); + + klass->add_pad_template(Gst::PadTemplate::create( + "src", + Gst::PAD_SRC, + Gst::PAD_ALWAYS, + Gst::Caps::create_any())); +} + +bool LegacyInput::register_element(Glib::RefPtr plugin) +{ + Gst::ElementFactory::register_element(plugin, "sigrok_legacy_input", + 0, Gst::register_mm_type( + "sigrok_legacy_input")); + return true; +} + +LegacyInput::LegacyInput(GstElement *gobj) : + Glib::ObjectBase(typeid(LegacyInput)), + Gst::Element(gobj) +{ + add_pad(_sink_pad = Gst::Pad::create(get_pad_template("sink"), "sink")); + add_pad(_src_pad = Gst::Pad::create(get_pad_template("src"), "src")); + _sink_pad->set_chain_function(sigc::mem_fun(*this, &LegacyInput::chain)); +} + +Glib::RefPtr LegacyInput::create( + shared_ptr libsigrok_input_format, + map options) +{ + auto element = Gst::ElementFactory::create_element("sigrok_legacy_input"); + if (!element) + throw runtime_error("Failed to create element - plugin not registered?"); + auto input = Glib::RefPtr::cast_static(element); + input->_libsigrok_input_format = libsigrok_input_format; + input->_options = options; + return input; +} + +bool LegacyInput::start_vfunc() +{ + _libsigrok_input = _libsigrok_input_format->create_input(_options); + auto context = _libsigrok_input_format->parent(); + _session = context->create_session(); + _session->add_device(_libsigrok_input->device()); + _session->add_datafeed_callback(bind(&LegacyInput::_datafeed_callback, this, _1, _2)); + _session->start(); + return true; +} + +void LegacyInput::_datafeed_callback( + shared_ptr device, + shared_ptr packet) +{ + (void) device; + switch (packet->type()->id()) { + case SR_DF_LOGIC: + { + auto logic = static_pointer_cast(packet->payload()); + auto mem = Gst::Memory::create( + Gst::MEMORY_FLAG_READONLY, + logic->data_pointer(), + logic->data_length(), + 0, + logic->data_length()); + auto buf = Gst::Buffer::create(); + buf->append_memory(move(mem)); + _src_pad->push(move(buf)); + break; + } + case SR_DF_END: + _session->stop(); + _src_pad->push_event(Gst::EventEos::create()); + break; + default: + break; + } +} + +Gst::FlowReturn LegacyInput::chain(const Glib::RefPtr &, + const Glib::RefPtr &buf) +{ + Gst::MapInfo info; + buf->map(info, Gst::MAP_READ); + _libsigrok_input->send(info.get_data(), info.get_size()); + buf->unmap(info); + return Gst::FLOW_OK; +} + +bool LegacyInput::stop_vfunc() +{ + _libsigrok_input->end(); + return true; +} + void LegacyOutput::class_init(Gst::ElementClass *klass) { klass->set_metadata("sigrok legacy output", @@ -234,6 +348,7 @@ bool LegacyOutput::stop_vfunc() cout << result; return true; } +#endif void LegacyDecoder::class_init(Gst::ElementClass *klass) {