ADTF  3.18.2
Source Code for Demo Data Trigger Plugin
Location
./src/examples/src/adtf/filters/standard_filters/data_triggered_filter/
Namespace for entire ADTF SDK.
Build Environment
To see how to set up the build environment have a look at ADTF CMake Environment
this implementation shows:
Header
#pragma once
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;
class cSimpleDataCalculator : public cFilter
{
public:
ADTF_CLASS_ID_NAME(cSimpleDataCalculator,
"demo_data_trigger.filter.adtf.cid",
"Demo Data Trigger");
public:
enum tOperator : uint32_t
{
ePLUS = 0,
eMINUS = 1,
eMULTI = 2,
eDIVIDE = 3
};
public:
cSimpleDataCalculator();
tResult Init(tInitStage eStage) override;
tResult ProcessInput(tNanoSeconds tmTrigger,
ISampleReader* pReader) override;
private:
// reader for our first input pin
ISampleReader* m_pReader1 = nullptr;
// reader for our second input pin
ISampleReader* m_pReader2 = nullptr;
// writer for our output pin
ISampleWriter* m_pWriter = nullptr;
// the selected calculation method
std::function<float(float, float)> m_fnCalculator;
// this will reflect any property changes.
property_variable<tOperator> m_eOperator = ePLUS;
};
#define ADTF_CLASS_ID_NAME(_class, _strcid, _strclabel)
Common macro to enable correct treatment of class identifier AND Class Name by IClassInfo.
Definition: class_id.h:33
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Namespace for the ADTF Base SDK.
Namespace for the ADTF Filter SDK.
Namespace for the ADTF Media Description SDK.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF uCOM3 SDK.
alias namespace for the A_UTILS Library.
Implementation
#include "demo_data_trigger_function.h"
#include <functional>
// this creates the plugin entry methods and class factories
ADTF_PLUGIN("Demo Data Trigger Plugin", cSimpleDataCalculator);
cSimpleDataCalculator::cSimpleDataCalculator()
{
// create our input pins with data-in triggers that call our overridden Process method.
m_pReader1 = CreateInputPin("in1", stream_type_plain<float>(), true);
SetDescription("in1", "First input value for calculation (in1 <operator> in2)");
m_pReader2 = CreateInputPin("in2", stream_type_plain<float>(), true);
SetDescription("in2", "Second input value for calculation (in1 <operator> in2)");
m_pWriter = CreateOutputPin("out", stream_type_plain<float>());
SetDescription("out", "Provides the calculated output (in1 <operator> in2)");
// setup and register our property variable which will reflect any property change.
// for compatibility with previous implementations we use the "data_generator_function" prefix.
m_eOperator.SetValueList({{ePLUS, "PLUS"},
{eMINUS, "MINUS"},
{eMULTI, "MULTI"},
{eDIVIDE, "DIVIDE"}});
m_eOperator.SetDescription("Chooses the arithmetic operation used to calculate the output values.");
RegisterPropertyVariable("calculator_function/operator", m_eOperator);
// sets a short description for the component
SetDescription("Use this filter to calculate two input values while choosing the arithmetic operation with the property 'operator'.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_data_triggered_filter.html");
}
// in this method all property related and/or long running initialization can be done
tResult cSimpleDataCalculator::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cFilter::Init(eStage));
if (eStage == StageNormal)
{
switch (m_eOperator)
{
case ePLUS:
{
LOG_INFO("Current operation is Addition");
m_fnCalculator = std::plus<float>();
break;
}
case eMINUS:
{
LOG_INFO("Current operation is Subtraction");
m_fnCalculator = std::minus<float>();
break;
}
case eMULTI:
{
LOG_INFO("Current operation is Multiplication");
m_fnCalculator = std::multiplies<float>();
break;
}
case eDIVIDE:
{
LOG_INFO("Current operation is Division");
m_fnCalculator = std::divides<float>();
break;
}
default:
{
RETURN_ERROR_DESC(ERR_INVALID_ARG, "Invalid property value for 'operator'");
}
}
}
}
tResult cSimpleDataCalculator::ProcessInput(tNanoSeconds /*tmTrigger*/,
ISampleReader* /*pReader*/)
{
object_ptr<const ISample> pSample1;
object_ptr<const ISample> pSample2;
if (IS_OK(m_pReader1->GetLastSample(pSample1)) &&
IS_OK(m_pReader2->GetLastSample(pSample2)))
{
auto tmSampleTimeStamp = std::max(get_sample_time(pSample1),
get_sample_time(pSample2));
output_sample_data<float> oOutput(tmSampleTimeStamp);
oOutput = m_fnCalculator(sample_data<float>(pSample1),
sample_data<float>(pSample2));
m_pWriter->Write(oOutput.Release());
}
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
Definition: adtf_plugin.h:22
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
base::flash::tNanoSeconds get_sample_time(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
Returns the sample time stamp with nanosecond precision.