X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fmain.cpp;h=79af3ec39d45aa455d25cc50e00fa32e3d2c48cf;hb=e2cfc0efeadec350376bffbe9250a27c6aa9788d;hp=ead3446fc8cc9a49353131bfd97f5216f26e8206;hpb=d75c9a6aab73eec3921cb951c3253afc4269ccb3;p=libsigrokflow.git diff --git a/src/main.cpp b/src/main.cpp index ead3446..79af3ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,59 @@ using namespace std::placeholders; void init() { + 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_output", + "Wrapper for outputs using legacy libsigrok APIs", + sigc::ptr_fun(&LegacyOutput::register_element), + "0.01", "GPL", "sigrok", "libsigrokflow", "http://sigrok.org"); +} + +Sink::Sink(GstBaseSink *gobj) : + Gst::BaseSink(gobj) +{ +} + +Device::Device(GstElement *gobj) : + Gst::Element(gobj) +{ +} + +CaptureDevice::CaptureDevice(GstElement *gobj) : + Device(gobj) +{ +} + +void LegacyCaptureDevice::class_init(Gst::ElementClass *klass) +{ + klass->set_metadata("sigrok legacy capture device", + "Source", "Wrapper for capture devices using legacy libsigrok APIs", + "Martin Ling"); + + klass->add_pad_template(Gst::PadTemplate::create( + "src", + Gst::PAD_SRC, + Gst::PAD_ALWAYS, + Gst::Caps::create_any())); +} + +bool LegacyCaptureDevice::register_element(Glib::RefPtr plugin) +{ + Gst::ElementFactory::register_element(plugin, "sigrok_legacy_capture_device", + 0, Gst::register_mm_type( + "sigrok_legacy_capture_device")); + return true; +} + +LegacyCaptureDevice::LegacyCaptureDevice(GstElement *gobj) : + Glib::ObjectBase(typeid(LegacyCaptureDevice)), + CaptureDevice(gobj) +{ + add_pad(_src_pad = Gst::Pad::create(get_pad_template("src"), "src")); } Glib::RefPtrLegacyCaptureDevice::create( @@ -39,13 +92,6 @@ Glib::RefPtrLegacyCaptureDevice::create( if (!element) throw runtime_error("Failed to create element - plugin not registered?"); auto device = Glib::RefPtr::cast_static(element); - - auto src_template = Gst::PadTemplate::create("src", - Gst::PAD_SRC, - Gst::PAD_ALWAYS, - Gst::Caps::create_any()); - device->_src_pad = Gst::Pad::create(src_template); - device->add_pad(device->_src_pad); device->_libsigrok_device = libsigrok_device; return device; } @@ -62,9 +108,6 @@ Gst::StateChangeReturn LegacyCaptureDevice::change_state_vfunc(Gst::StateChange case Gst::STATE_CHANGE_READY_TO_PAUSED: return Gst::StateChangeReturn::STATE_CHANGE_NO_PREROLL; case Gst::STATE_CHANGE_PAUSED_TO_PLAYING: - _libsigrok_device->open(); - _libsigrok_device->config_set(sigrok::ConfigKey::LIMIT_SAMPLES, - Glib::Variant::create(10)); _task = Gst::Task::create(std::bind(&LegacyCaptureDevice::_run, this)); _task->set_lock(_mutex); _src_pad->set_active(true); @@ -114,4 +157,70 @@ void LegacyCaptureDevice::_run() _task->stop(); } +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) +{ + add_pad(_sink_pad = Gst::Pad::create(get_pad_template("sink"), "sink")); +} + +Glib::RefPtrLegacyOutput::create( + shared_ptr libsigrok_output) +{ + 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 = libsigrok_output; + return output; +} + +shared_ptr LegacyOutput::libsigrok_output() +{ + return _libsigrok_output; +} + +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; +} + }