ADTF  3.18.2
Source Code for Media Description Data Generator Filter Plugin
Location
./src/examples/src/adtf/filters/standard_filters/demo_md_data_generator_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
#include <random>
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::mediadescription;
class cMediaDescriptionDataGenerator : public cFilter
{
public:
ADTF_CLASS_ID_NAME(cMediaDescriptionDataGenerator,
"demo_media_description_data_generator.filter.adtf.cid",
"Media Description Data Generator");
cMediaDescriptionDataGenerator();
tResult Init(tInitStage eStage) override;
tResult Process(tNanoSeconds tmTimeOfTrigger,
IRunner* pRunner) override;
private:
property_variable<adtf::util::cString> m_strMediaDescriptionStructName;
encoding_sample_writer<>* m_pWriter;
std::mt19937 m_oRandomGenerator;
std::uniform_real_distribution<double> m_oDistribution;
};
#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.
Implementation
#include "demo_md_data_generator.h"
ADTF_PLUGIN("Media Description Data Generator Plugin",
cMediaDescriptionDataGenerator);
cMediaDescriptionDataGenerator::cMediaDescriptionDataGenerator():
m_oDistribution(0.0, 100.0)
{
m_pWriter = CreateOutputPin<encoding_sample_writer<>>("data");
SetDescription("data", "Provides the generated data based on the configured media description structure");
CreateRunner("data_generator_function", cTimerTriggerHint(std::chrono::seconds{1}));
SetDescription("data_generator_function", "Runner to periodically trigger the function which generates the output samples");
// for compatibility resons with older implementations we use the "data_generator_function" prefix.
m_strMediaDescriptionStructName.SetDescription("The name of the DDL structure to generate.");
RegisterPropertyVariable("data_generator_function/media_description_struct_name", m_strMediaDescriptionStructName);
// sets a short description for the component
SetDescription("Use this filter to generate random values for a specified Media Description structure configured by property 'media_description_struct_name'.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_md_data_generator_filter.html");
}
tResult cMediaDescriptionDataGenerator::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cFilter::Init(eStage));
if (eStage == StageNormal)
{
const adtf::ucom::object_ptr<IStreamType> pType = adtf::ucom::make_object_ptr<stream_type_default<>>(m_strMediaDescriptionStructName->GetPtr());
RETURN_IF_FAILED(m_pWriter->ChangeType(pType));
}
}
tResult cMediaDescriptionDataGenerator::Process(tNanoSeconds tmTimeOfTrigger,
IRunner* /*pRunner*/)
{
// we use the same random value for all elements of the structure
double fRandomValue = m_oDistribution(m_oRandomGenerator);
auto oSample = m_pWriter->MakeSample(tmTimeOfTrigger);
for_each_leaf_element(oSample.GetElements(),
[&fRandomValue](auto& oElement) {
oElement.setValue(fRandomValue);
});
m_pWriter->Write(oSample);
}
#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_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.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
void for_each_leaf_element(ElementsType &oElements, const element_callback< ElementsType > &fnCallback)
Iterates ALL leaf elements within ALL array elements.