ADTF
Loading...
Searching...
No Matches
Example Demo Thread Trigger

Description

Shows how to implement a filter which is triggered by a Thread Runner.

Prebuilt Binaries

Source Code

./examples/demo_adtfplugins/demo_thread_trigger/

Filter

demo_thread_trigger_function.h

#pragma once
#include <condition_variable>
#include <mutex>
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
class cAsynchronousDataPrinter final : public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cAsynchronousDataPrinter,
"demo_thread_trigger.filter" ADTF_EXAMPLES_CID,
"Demo Thread Trigger");
public:
cAsynchronousDataPrinter();
~cAsynchronousDataPrinter() override;
adtf::streaming::ISampleReader* pReader) override;
private:
tResult PrintData();
private:
// reader for our input pin
adtf::streaming::ISampleReader* m_pReader = nullptr;
// this is used to signal the thread that executes our trigger function
std::mutex m_oSamplesAvailableMutex;
std::condition_variable m_oSamplesAvailable;
size_t m_nSampleCounter = 0;
};
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define ADTF_CLASS_ID_NAME(_class, _strcid, _strclabel)
Definition class_id.h:33
Definition filter.h:289
virtual tResult ProcessInput(base::flash::tNanoSeconds tmTrigger, streaming::flash::ISampleReader *pReader)
Definition samplestreamer_intf.h:188
A timestamp with nanosecond precision.
Definition chrono.h:23

demo_thread_trigger_function.cpp

#include "demo_thread_trigger_function.h"
using namespace adtf::util;
using namespace ddl;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::mediadescription;
using namespace adtf::filter;
// this creates the plugin entry methods and class factories
ADTF_PLUGIN("Demo Thread Trigger Plugin", cAsynchronousDataPrinter);
cAsynchronousDataPrinter::cAsynchronousDataPrinter()
{
// create our input pin with a data-in trigger that calls our overridden Process method.
m_pReader = CreateInputPin("in", stream_type_plain<float>(), true);
SetDescription("in", "Input value for printing");
// create a trigger function that can be connected to an active runner.
CreateRunner("print_data",
std::bind(&cAsynchronousDataPrinter::PrintData, this),
cThreadTriggerHint());
SetDescription("print_data", "Runner to cyclically trigger the function which prints the data");
// sets a short description for the component
SetDescription("Use this filter to print asynchronously the received values with a defined Thread Runner.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/html/page_demo_thread_trigger.html");
}
cAsynchronousDataPrinter::~cAsynchronousDataPrinter() = default;
// this is called when a data trigger is received at the input pin.
tResult cAsynchronousDataPrinter::ProcessInput(tNanoSeconds /*tmTrigger*/,
ISampleReader* /*pReader*/)
{
// all we do is notify the trigger function that there might be some samples available.
m_oSamplesAvailable.notify_all();
}
// this method is called repeatedly by an active thread runner
tResult cAsynchronousDataPrinter::PrintData()
{
// wait until a sample should be available to read.
// we use a timeout to ensure that this method finishes eventually.
std::unique_lock<std::mutex> oGuard(m_oSamplesAvailableMutex);
if (m_oSamplesAvailable.wait_for(oGuard, std::chrono::milliseconds(10), [&]
{
return IS_OK(m_pReader->GetNextSample(pSample));
}))
{
float fValue = sample_data<float>(pSample);
LOG_INFO("value number %" PRIuPTR ": %f", ++m_nSampleCounter, fValue);
}
}
#define ADTF_PLUGIN(__plugin_identifier,...)
Definition adtf_plugin.h:29
#define LOG_INFO(...)
Logs an info message.
Definition log.h:388
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
Definition sample_data.h:429
Generator template to create an instance of a ant::IStreamType class for penguin::stream_meta_type_pl...
Definition streammetatypeplain.h:315
Definition object_ptr.h:384
Namespace for the ADTF Base SDK.
Definition adtf_base_type_traits.h:13
Namespace for the ADTF Filter SDK.
Definition configurable_runner.h:18
Namespace for the ADTF Mediadescription SDK.
Definition codec_sample_streamer.h:22
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
definition of the ddl namespace
Definition codec.h:21