ADTF
Loading...
Searching...
No Matches
Example Demo Code Generation

Description

Shows how to create samples from a media description file.

Prebuilt Binaries

Source Code

./examples/demo_adtfplugins/demo_code_generation/

Description

nested_struct.description

<adtf:ddl>
<enums>
</enums>
<structs>
<struct name="tHeaderStruct" alignment="1" version="1">
<element name="ui32HeaderVal" type="tUInt32" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="0" byteorder="LE"/>
</element>
<element name="f64HeaderVal" type="tFloat64" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="4" byteorder="LE"/>
</element>
</struct>
<struct name="tSimpleStruct" alignment="1" version="1">
<element name="ui8Val" type="tUInt8" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="0" byteorder="LE"/>
</element>
<element name="ui16Val" type="tUInt16" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="1" byteorder="LE"/>
</element>
<element name="ui32Val" type="tUInt32" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="3" byteorder="LE"/>
</element>
<element name="i32Val" type="tInt32" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="7" byteorder="LE"/>
</element>
<element name="i64Val" type="tInt64" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="11" byteorder="LE"/>
</element>
<element name="f64Val" type="tFloat64" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="19" byteorder="LE"/>
</element>
<element name="f32Val" type="tFloat32" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="27" byteorder="LE"/>
</element>
</struct>
<struct name="tNestedStruct" alignment="1" version="1">
<element name="sHeaderStruct" type="tHeaderStruct" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="0" byteorder="LE"/>
</element>
<element name="sSimpleStruct" type="tSimpleStruct" arraysize="1">
<deserialized alignment="1"/>
<serialized bytepos="12" byteorder="LE"/>
</element>
</struct>
</structs>
</adtf:ddl>

Access

demo_code_generation_access_filter.h

#pragma once
// this file is auto-generated from nested_struct.description
#include <nested_struct.h>
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
class cCodeGenerationDataAccess final : public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cCodeGenerationDataAccess,
"demo_code_generation_access.filter" ADTF_EXAMPLES_CID,
"Demo Code Generation Data Access");
cCodeGenerationDataAccess();
~cCodeGenerationDataAccess() override;
private:
// This will create data access objects for our samples. The specialization for
// tNestedStruct is generated into the nested_struct.h header.
};
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)
virtual tResult AcceptType(streaming::flash::ISampleReader *pReader, const ucom::ant::iobject_ptr< const streaming::ant::IStreamType > &pType)
Definition samplestreamer_intf.h:188
ant::iobject_ptr< T > iobject_ptr
Alias always bringing the latest version of ant::iobject_ptr into scope.
Definition object_ptr_intf.h:437

demo_code_generation_access_filter.cpp

#include "demo_code_generation_access_filter.h"
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::mediadescription;
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/html/page_demo_md_code_generation_filters.html");
}
cCodeGenerationDataAccess::~cCodeGenerationDataAccess() = default;
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());
}
#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
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
Definition md_sample_data.h:54

Generator

demo_code_generation_generator_filter.h

#pragma once
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
class cCodeGenerationDataGenerator final : public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cCodeGenerationDataGenerator,
"demo_code_generation_generator.filter" ADTF_EXAMPLES_CID,
"Demo Code Generation Data Generator");
cCodeGenerationDataGenerator();
~cCodeGenerationDataGenerator() override;
private:
};
virtual tResult Process(base::flash::tNanoSeconds tmTrigger, streaming::ant::IRunner *pRunner)
Definition runner_intf.h:24
Definition samplestreamer_intf.h:234
A timestamp with nanosecond precision.
Definition chrono.h:23

demo_code_generation_generator_filter.cpp

#include "demo_code_generation_generator_filter.h"
// 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;
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/html/page_demo_code_generation_data_generator.html");
}
cCodeGenerationDataGenerator::~cCodeGenerationDataGenerator() = default;
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());
}

Plugin

plugin.cpp

#include "demo_string_sending_filter.h"
#include "demo_string_receiving_filter.h"
ADTF_PLUGIN("Demo String Handling Filters Plugin",
cDemoStringSending,
cDemoStringReceiving);
#define ADTF_PLUGIN(__plugin_identifier,...)
Definition adtf_plugin.h:29