class Block
{
- /* Config API etc goes here */
+ /* Config API etc. goes here. */
};
class Sink :
- public Gst::BaseSink
+ public Gst::BaseSink
{
protected:
- explicit Sink(GstBaseSink *gobj);
+ explicit Sink(GstBaseSink *gobj);
};
class Device :
- public Gst::Element
+ public Gst::Element
{
- /* Operations specific to hardware devices go here */
+ /* Operations specific to hardware devices go here. */
protected:
- explicit Device(GstElement *gobj);
+ explicit Device(GstElement *gobj);
};
class CaptureDevice :
- public Device
+ public Device
{
- /* Operations specific to capture (source) devices go here */
+ /* Operations specific to capture (source) devices go here. */
protected:
- explicit CaptureDevice(GstElement *gobj);
+ explicit CaptureDevice(GstElement *gobj);
};
#ifdef HAVE_LIBSIGROKCXX
class LegacyCaptureDevice :
- public CaptureDevice
+ public CaptureDevice
{
public:
- /* Create from libsigrok device object */
- static Glib::RefPtr<LegacyCaptureDevice> create(
- shared_ptr<sigrok::HardwareDevice> libsigrok_device);
+ /* Create from libsigrok device object. */
+ static Glib::RefPtr<LegacyCaptureDevice> create(
+ shared_ptr<sigrok::HardwareDevice> libsigrok_device);
- /* Retrieve libsigrok device object */
- shared_ptr<sigrok::HardwareDevice> libsigrok_device();
+ /* Retrieve libsigrok device object. */
+ shared_ptr<sigrok::HardwareDevice> libsigrok_device();
- /* Override state change */
- Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
+ /* Override state change. */
+ Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
- /* Gst class init */
- static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
+ /* Gst class init. */
+ static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
- /* Register class with plugin */
- static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+ /* Register class with plugin. */
+ static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+ /* Constructor used by element factory. */
+ explicit LegacyCaptureDevice(GstElement *gobj);
- /* Construcor used by element factory */
- explicit LegacyCaptureDevice(GstElement *gobj);
private:
- shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
- Glib::RefPtr<Gst::Pad> _src_pad;
- Glib::Threads::RecMutex _mutex;
- Glib::RefPtr<Gst::Task> _task;
- shared_ptr<sigrok::Session> _session;
-
- void _datafeed_callback(shared_ptr<sigrok::Device> device,
- shared_ptr<sigrok::Packet> packet);
- void _run();
+ shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
+ Glib::RefPtr<Gst::Pad> _src_pad;
+ Glib::Threads::RecMutex _mutex;
+ Glib::RefPtr<Gst::Task> _task;
+ shared_ptr<sigrok::Session> _session;
+
+ void _datafeed_callback(shared_ptr<sigrok::Device> device,
+ shared_ptr<sigrok::Packet> packet);
+ void _run();
};
class LegacyInput :
- public Gst::Element
+ public Gst::Element
{
public:
- /* Create from libsigrok input */
- static Glib::RefPtr<LegacyInput> create(
- shared_ptr<sigrok::InputFormat> format,
- map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+ /* Create from libsigrok input. */
+ static Glib::RefPtr<LegacyInput> create(
+ shared_ptr<sigrok::InputFormat> format,
+ map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+
+ /* Override start. */
+ bool start_vfunc();
- /* Override start */
- bool start_vfunc();
+ /* Chain function. */
+ Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
+ const Glib::RefPtr<Gst::Buffer> &buf);
- /* Chain function */
- Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
- const Glib::RefPtr<Gst::Buffer> &buf);
+ /* Override stop. */
+ bool stop_vfunc();
- /* Override stop */
- bool stop_vfunc();
+ /* Gst class init. */
+ static void class_init(Gst::ElementClass<LegacyInput> *klass);
- /* Gst class init */
- static void class_init(Gst::ElementClass<LegacyInput> *klass);
+ /* Register class with plugin. */
+ static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
- /* Register class with plugin */
- static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+ /* Constructor used by element factory. */
+ explicit LegacyInput(GstElement *gobj);
- /* Construcor used by element factory */
- explicit LegacyInput(GstElement *gobj);
private:
- shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
- shared_ptr<sigrok::Input> _libsigrok_input;
- shared_ptr<sigrok::Session> _session;
- map<string, Glib::VariantBase> _options;
- Glib::RefPtr<Gst::Pad> _sink_pad;
- Glib::RefPtr<Gst::Pad> _src_pad;
-
- void _datafeed_callback(shared_ptr<sigrok::Device> device,
- shared_ptr<sigrok::Packet> packet);
+ shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
+ shared_ptr<sigrok::Input> _libsigrok_input;
+ shared_ptr<sigrok::Session> _session;
+ map<string, Glib::VariantBase> _options;
+ Glib::RefPtr<Gst::Pad> _sink_pad;
+ Glib::RefPtr<Gst::Pad> _src_pad;
+
+ void _datafeed_callback(shared_ptr<sigrok::Device> device,
+ shared_ptr<sigrok::Packet> packet);
};
class LegacyOutput :
- public Sink
+ public Sink
{
public:
- /* Create from libsigrok output object */
- static Glib::RefPtr<LegacyOutput> create(
- shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
- shared_ptr<sigrok::Device> libsigrok_device,
- map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+ /* Create from libsigrok output object. */
+ static Glib::RefPtr<LegacyOutput> create(
+ shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
+ shared_ptr<sigrok::Device> libsigrok_device,
+ map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
- /* Override start */
- bool start_vfunc();
+ /* Override start. */
+ bool start_vfunc().;
- /* Override render */
- Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
+ /* Override render. */
+ Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
- /* Override stop */
- bool stop_vfunc();
+ /* Override stop. */
+ bool stop_vfunc();
- /* Gst class init */
- static void class_init(Gst::ElementClass<LegacyOutput> *klass);
+ /* Gst class init. */
+ static void class_init(Gst::ElementClass<LegacyOutput> *klass);
- /* Register class with plugin */
- static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+ /* Register class with plugin. */
+ static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+ /* Constructor used by element factory. */
+ explicit LegacyOutput(GstBaseSink *gobj);
- /* Constructor used by element factory */
- explicit LegacyOutput(GstBaseSink *gobj);
private:
- shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
- shared_ptr<sigrok::Device> _libsigrok_device;
- shared_ptr<sigrok::Output> _libsigrok_output;
- map<string, Glib::VariantBase> _options;
+ shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
+ shared_ptr<sigrok::Device> _libsigrok_device;
+ shared_ptr<sigrok::Output> _libsigrok_output;
+ map<string, Glib::VariantBase> _options;
};
#endif
#ifdef HAVE_LIBSIGROKDECODE
class LegacyDecoder :
- public Sink
+ public Sink
{
public:
- static Glib::RefPtr<LegacyDecoder> create(
- struct srd_session *libsigrokdecode_session, uint64_t unitsize);
+ static Glib::RefPtr<LegacyDecoder> create(
+ struct srd_session *libsigrokdecode_session, uint64_t unitsize);
+
+ /* Retrieve libsigrokdecode session. */
+ struct srd_session *libsigrokdecode_session();
- /* Retrieve libsigrokdecode session */
- struct srd_session *libsigrokdecode_session();
+ /* Override start. */
+ bool start_vfunc();
- /* Override start */
- bool start_vfunc();
+ /* Override render. */
+ Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
- /* Override render */
- Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
+ /* Override stop. */
+ bool stop_vfunc();
- /* Override stop */
- bool stop_vfunc();
+ /* Gst class init. */
+ static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
- /* Gst class init */
- static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
+ /* Register class with plugin. */
+ static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
- /* Register class with plugin */
- static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+ /* Constructor used by element factory. */
+ explicit LegacyDecoder(GstBaseSink *gobj);
- /* Constructor used by element factory */
- explicit LegacyDecoder(GstBaseSink *gobj);
private:
- struct srd_session *_session;
- uint64_t _abs_ss;
- uint64_t _unitsize;
+ struct srd_session *_session;
+ uint64_t _abs_ss;
+ uint64_t _unitsize;
};
#endif
{
if (!srf_initialized_)
throw runtime_error("libsigrokflow is not initialized");
-
+
srf_initialized_ = false;
}
Gst::ElementFactory::register_element(plugin, "sigrok_legacy_capture_device",
0, Gst::register_mm_type<LegacyCaptureDevice>(
"sigrok_legacy_capture_device"));
+
return true;
}
throw runtime_error("Failed to create element - plugin not registered?");
auto device = Glib::RefPtr<LegacyCaptureDevice>::cast_static(element);
device->_libsigrok_device = libsigrok_device;
+
return device;
}
Gst::StateChangeReturn LegacyCaptureDevice::change_state_vfunc(Gst::StateChange transition)
{
- switch (transition)
- {
- case Gst::STATE_CHANGE_READY_TO_PAUSED:
- return Gst::StateChangeReturn::STATE_CHANGE_NO_PREROLL;
- case Gst::STATE_CHANGE_PAUSED_TO_PLAYING:
- _task = Gst::Task::create(std::bind(&LegacyCaptureDevice::_run, this));
- _task->set_lock(_mutex);
- _src_pad->set_active(true);
- _task->start();
- return Gst::STATE_CHANGE_SUCCESS;
- default:
- return Gst::STATE_CHANGE_SUCCESS;
+ switch (transition) {
+ case Gst::STATE_CHANGE_READY_TO_PAUSED:
+ return Gst::StateChangeReturn::STATE_CHANGE_NO_PREROLL;
+ case Gst::STATE_CHANGE_PAUSED_TO_PLAYING:
+ _task = Gst::Task::create(std::bind(&LegacyCaptureDevice::_run, this));
+ _task->set_lock(_mutex);
+ _src_pad->set_active(true);
+ _task->start();
+ return Gst::STATE_CHANGE_SUCCESS;
+ default:
+ return Gst::STATE_CHANGE_SUCCESS;
}
}
shared_ptr<sigrok::Device> device,
shared_ptr<sigrok::Packet> packet)
{
- (void) device;
+ (void)device;
+
switch (packet->type()->id()) {
- case SR_DF_LOGIC:
- {
- auto logic = static_pointer_cast<sigrok::Logic>(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;
+ case SR_DF_LOGIC: {
+ auto logic = static_pointer_cast<sigrok::Logic>(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::ElementFactory::register_element(plugin, "sigrok_legacy_input",
0, Gst::register_mm_type<LegacyInput>(
"sigrok_legacy_input"));
+
return true;
}
auto input = Glib::RefPtr<LegacyInput>::cast_static(element);
input->_libsigrok_input_format = libsigrok_input_format;
input->_options = options;
+
return input;
}
_session->add_device(_libsigrok_input->device());
_session->add_datafeed_callback(bind(&LegacyInput::_datafeed_callback, this, _1, _2));
_session->start();
+
return true;
}
shared_ptr<sigrok::Device> device,
shared_ptr<sigrok::Packet> packet)
{
- (void) device;
+ (void)device;
+
switch (packet->type()->id()) {
- case SR_DF_LOGIC:
- {
- auto logic = static_pointer_cast<sigrok::Logic>(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;
+ case SR_DF_LOGIC: {
+ auto logic = static_pointer_cast<sigrok::Logic>(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<Gst::Pad> &,
- const Glib::RefPtr<Gst::Buffer> &buf)
+ const Glib::RefPtr<Gst::Buffer> &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;
}
Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output",
0, Gst::register_mm_type<LegacyOutput>(
"sigrok_legacy_output"));
+
return true;
}
output->_libsigrok_output_format = libsigrok_output_format;
output->_libsigrok_device = libsigrok_device;
output->_options = options;
+
return output;
}
{
_libsigrok_output = _libsigrok_output_format->create_output(
_libsigrok_device, _options);
+
return true;
}
auto result = _libsigrok_output->receive(packet);
cout << result;
buffer->unmap(info);
+
return Gst::FLOW_OK;
}
auto end_packet = context->create_end_packet();
auto result = _libsigrok_output->receive(end_packet);
cout << result;
+
return true;
}
#endif
Gst::ElementFactory::register_element(plugin, "sigrok_legacy_decoder",
0, Gst::register_mm_type<LegacyDecoder>(
"sigrok_legacy_decoder"));
+
return true;
}
auto decoder = Glib::RefPtr<LegacyDecoder>::cast_static(element);
decoder->_session = libsigrokdecode_session;
decoder->_unitsize = unitsize;
+
return decoder;
}
info.get_data(), info.get_size(), _unitsize);
_abs_ss += num_samples;
buffer->unmap(info);
+
return Gst::FLOW_OK;
}
{
_abs_ss = 0;
srd_session_start(_session);
+
return true;
}
bool LegacyDecoder::stop_vfunc()
{
srd_session_terminate_reset(_session);
+
return true;
}
#endif