ADTF
Loading...
Searching...
No Matches
Example Media Description Data Generator

Description

Shows how to create samples provided by a DDL description file.

Prebuilt Binaries

Source Code

./examples/demo_adtfplugins/media_description_data_generator/

Filter

demo_md_data_generator.h

#pragma once
#include <random>
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
class cMediaDescriptionDataGenerator final : public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cMediaDescriptionDataGenerator,
"demo_media_description_data_generator.filter" ADTF_EXAMPLES_CID,
"Media Description Data Generator");
cMediaDescriptionDataGenerator();
~cMediaDescriptionDataGenerator() override;
tResult Init(tInitStage eStage) override;
private:
adtf::base::property_variable<adtf::util::cString> m_strMediaDescriptionStructName;
adtf::base::property_variable<bool> m_bMarkSamplesAsDeserialized{true};
std::mt19937 m_oRandomGenerator;
std::uniform_real_distribution<double> m_oDistribution;
};
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
Property Variable template for the given T. A Property Variable will store a copy of a property value...
Definition configuration.h:808
Definition filter.h:289
tResult Init(tInitStage eStage) override
virtual tResult Process(base::flash::tNanoSeconds tmTrigger, streaming::ant::IRunner *pRunner)
Definition codec_sample_streamer.h:214
Definition runner_intf.h:24
A timestamp with nanosecond precision.
Definition chrono.h:23

demo_md_data_generator.cpp

#include "demo_md_data_generator.h"
#include <adtfddl/pkg_ddl.h>
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::mediadescription;
using namespace adtf::ucom;
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);
m_strDescriptionFile.SetDescription(
"A description file containing the DDL description for the samples to generate.");
RegisterPropertyVariable("description_file", m_strDescriptionFile);
m_bMarkSamplesAsDeserialized.SetDescription(
"Determines whether the data representation of the configured DDL description file is deserialized.");
RegisterPropertyVariable("mark_samples_as_deserialized", m_bMarkSamplesAsDeserialized);
// 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/html/page_media_description_data_generator.html");
}
cMediaDescriptionDataGenerator::~cMediaDescriptionDataGenerator() = default;
tResult cMediaDescriptionDataGenerator::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cFilter::Init(eStage));
if (eStage == StageNormal)
{
try
{
// import data definition from description file ..
const auto oDataDefinition = ddl::DDFile::fromXMLFile(m_strDescriptionFile->GetPtr());
// .. and create streamtype for configured struct type and data representation
m_strMediaDescriptionStructName->GetPtr(), oDataDefinition,
m_bMarkSamplesAsDeserialized ? ddl::tDataRepresentation::Deserialized :
RETURN_IF_FAILED(m_pWriter->ChangeType(pType));
}
catch (...)
{
}
}
}
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,...)
Definition adtf_plugin.h:29
#define RETURN_CURRENT_EXCEPTION()
returns the current exception as a tResult, use it in a catch block.
Definition result.h:111
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
Definition object_ptr.h:384
static dd::DataDefinition fromXMLFile(const std::string &xml_filepath, bool strict=false)
Read a file containing a data definiton in XML.
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
void for_each_leaf_element(ElementsType &oElements, const element_callback< ElementsType > &fnCallback)
Iterates ALL leaf elements within ALL array elements.
Definition sample_codec.h:1414
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324
object_ptr< Implementation > make_object_ptr(Args &&... args)
Alias always bringing the latest version of ant::make_object_ptr() into scope.
Definition object_ptr_utilities.h:129
@ Deserialized
alias names for legacy reasons
Definition data_representation.h:29
@ Serialized
alias names for legacy reasons
Definition data_representation.h:28