ADTF  3.18.2
Source Code for Demo Media Description Code Generation Filters Plugin
Location
./src/examples/src/adtf/filters/standard_filters/code_generation_filters/
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:
Generator Header
#pragma once
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::mediadescription;
class cCodeGenerationDataGenerator: public cFilter
{
public:
ADTF_CLASS_ID_NAME(cCodeGenerationDataGenerator,
"demo_code_generation_generator.filter.adtf.cid",
"Demo Code Generation Data Generator");
cCodeGenerationDataGenerator();
tResult Process(tNanoSeconds tmTrigger, IRunner* pRunner) override;
private:
ISampleWriter* m_pWriter;
};
#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.
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.
Generator Implementation
#include "demo_code_generation_generator_filter.h"
// this file is auto-generated from nested_struct.description
#include <nested_struct.h>
cCodeGenerationDataGenerator::cCodeGenerationDataGenerator()
{
// the generated header contains a specialization of adtf::mediadescription::description for tNestedStruct
m_pWriter = CreateOutputPin("output", description<tNestedStruct>());
SetDescription("output", "Provides the generated samples based on tNestedStruct");
CreateRunner("generate_data", cTimerTriggerHint(std::chrono::seconds{1}));
SetDescription("generate_data", "Runner to periodically trigger the function which generates the output samples");
// sets a short description for the component
SetDescription("Use this filter to generate increasing data with the structure of tNestedStruct.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_md_code_generation_filters.html");
}
tResult cCodeGenerationDataGenerator::Process(tNanoSeconds tmTrigger, IRunner* /*pRunner*/)
{
output_sample_data<tNestedStruct> oGeneratedData(tmTrigger);
oGeneratedData->sHeaderStruct.ui32HeaderVal = static_cast<uint32_t>(tmTrigger.nCount);
oGeneratedData->sHeaderStruct.f64HeaderVal = static_cast<double>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.ui8Val = static_cast<uint8_t>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.ui16Val = static_cast<uint16_t>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.ui32Val = static_cast<uint32_t>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.i32Val = static_cast<int32_t>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.i64Val = static_cast<int64_t>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.f64Val = static_cast<double>(tmTrigger.nCount);
oGeneratedData->sSimpleStruct.f32Val = static_cast<float>(tmTrigger.nCount);
m_pWriter->Write(oGeneratedData.Release());
}
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Accessor Header
#pragma once
// this file is auto-generated from nested_struct.description
#include <nested_struct.h>
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::mediadescription;
class cCodeGenerationDataAccess: public cFilter
{
public:
ADTF_CLASS_ID_NAME(cCodeGenerationDataAccess,
"demo_code_generation_access.filter.adtf.cid",
"Demo Code Generation Data Access");
cCodeGenerationDataAccess();
tResult AcceptType(ISampleReader* pReader, const iobject_ptr<const IStreamType>& pType) override;
tResult ProcessInput(ISampleReader* pReader, const iobject_ptr<const ISample>& pSample) override;
private:
// This will create data access objects for our samples. The specialization for
// tNestedStruct is generated into the nested_struct.h header.
md_sample_data_factory<tNestedStruct> m_oSampleDataFactory;
};
Accessor Implementation
#include "demo_code_generation_access_filter.h"
cCodeGenerationDataAccess::cCodeGenerationDataAccess()
{
// the generated header contains a specialization of adtf::mediadescription::description for tNestedStruct
CreateInputPin("input", description<tNestedStruct>());
SetDescription("input", "Input data based on tNestedStruct");
// sets a short description for the component
SetDescription("Use this filter to print the received members 'ui32HeaderVal' and 'ui32Val' of a stream with the structure of tNestedStruct, e.g. written by 'Demo Code Generation Data Generator'.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_md_code_generation_filters.html");
}
tResult cCodeGenerationDataAccess::AcceptType(ISampleReader* /*pReader*/, const iobject_ptr<const IStreamType>& pType)
{
// Here we update our factory each time we receive a new stream type.
// This will throw an error if the stream type is not compatible.
m_oSampleDataFactory = md_sample_data_factory<tNestedStruct>(pType);
}
tResult cCodeGenerationDataAccess::ProcessInput(ISampleReader* /*pReader*/, const iobject_ptr<const ISample>& pSample)
{
// this returns a specialization of adtf::mediadescription::md_sample_data for tNestedStruct
auto oSampleData = m_oSampleDataFactory.Make(pSample);
LOG_INFO("ui32HeaderVal = %u\n"
"ui32Val = %u",
oSampleData.sHeaderStruct().ui32HeaderVal(),
oSampleData.sSimpleStruct().ui32Val());
}