#include "demo_sample_data_reference_source.h"
namespace {
unsigned char generator()
{
return static_cast<unsigned char>(std::rand());
}
}
cDemoSampleDataReferenceSource);
cDemoSampleDataReferenceSource::cDemoSampleDataReferenceSource()
{
m_nWidth.SetDescription("Specified width for Sample dimension.");
RegisterPropertyVariable("width", m_nWidth);
m_nHeight.SetDescription("Specified height for Sample dimension.");
RegisterPropertyVariable("height", m_nHeight);
m_nFrameDelay.SetDescription("Update interval in microseconds for Sample creation. This is only used when no Timer Runner is connected to the 'generate_frames' runner.");
RegisterPropertyVariable("frame_delay", m_nFrameDelay);
m_pOutputWriter = CreateOutputPin("output", GetStreamTypeFromProperties());
SetDescription("output", "Provides the generated referenced samples");
SetDescription("generate_frames",
"Connect a Timer Runner that will trigger the frame generation. In this case the property `frame_delay` has no effect."
"If this is not connected, the source will create a timer on its own.");
SetDescription("Use this Streaming Source to to generate samples that reference external data.");
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_sample_data_reference.html");
}
tResult cDemoSampleDataReferenceSource::Init()
{
m_oBuffer.resize(m_nWidth * m_nHeight);
m_pOutputWriter->ChangeType(GetStreamTypeFromProperties());
}
object_ptr<IStreamType> cDemoSampleDataReferenceSource::GetStreamTypeFromProperties()
{
tStreamImageFormat sFormat;
sFormat.m_ui32Width = m_nWidth;
sFormat.m_ui32Height = m_nHeight;
sFormat.m_szMaxByteSize = m_nWidth * m_nHeight;
object_ptr<IStreamType> pType = make_object_ptr<cStreamType>(stream_meta_type_image());
return pType;
}
tResult cDemoSampleDataReferenceSource::StartStreaming()
{
}
tResult cDemoSampleDataReferenceSource::StopStreaming()
{
m_oTimer.Deactivate();
return cSampleStreamingSource::StopStreaming();
}
void cDemoSampleDataReferenceSource::TimerFunc()
{
auto tmNow = m_pClock->GetStreamTimeNs();
object_ptr<ISample> pLockedLastSample(m_pLastSentSample);
if (pLockedLastSample)
{
LOG_WARNING(
"The last sample is still referenced, cannot update buffer!");
return;
}
std::generate(m_oBuffer.begin(), m_oBuffer.end(), generator);
auto pNewSample = make_object_ptr<cReferenceSample>();
pNewSample->SetTime(tmNow);
{
object_ptr_locked<ISampleBuffer> pSampleBuffer;
auto oResult = pNewSample->WriteLock(pSampleBuffer, 0);
{
m_pOutputWriter->SetStreamError(oResult);
return;
}
oResult = pSampleBuffer->Write(adtf_memory_buffer<uint8_t>(m_oBuffer.data(),
m_oBuffer.size()));
{
m_pOutputWriter->SetStreamError(oResult);
return;
}
}
m_pLastSentSample = pNewSample;
m_pOutputWriter->Write(ucom_object_ptr_cast<ISample>(pNewSample));
m_pOutputWriter->ManualTrigger(tmNow);
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
#define LOG_WARNING(...)
Logs a warning message.
#define IS_FAILED(s)
Check if result is failed.
#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.
virtual tResult GetObject(iobject_ptr< IObject > &pObject, const char *strNameOID) const =0
Get registered object from object registry.
#define PLATFORM_BYTEORDER
defines a link to __get_platform_byteorder.
tResult set_stream_type_image_format(IStreamType &oType, const tStreamImageFormat &oFormat)
Helper function to set the properties of a IStreamType for a stream_meta_type_image.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.