ADTF  3.18.2
Source Code for SDL Video Display Plugin
Location
./src/examples/src/adtf/streaming_services/sinks/demo_sdl_display_sink/
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:
  • how to implement a Streaming Sink
  • how to create a simple graphics application based on the SDL library (Simple DirectMedia Layer, see Example Build Dependencies)
  • how to initialize and use the adtf/ucom runtime environment
  • how to implement a local service within a standalone application
  • how to register and access a service and service instances
  • how to implement a basic processing loop using the adtf::services::ant::IApplication interface
Remarks
  • Linux:
    1. set SDLDIR as an environment variable. This variable must point to your sdl directory
  • Windows:
    1. add the path of your SDL include directory to the include paths of your Visual Studio (project)
    2. add the path of your SDL lib directory to the lib paths of your Visual Studio (project)
    3. to run this app you have to make sure that the dll can be found from this app. Extend your Path variable or use the CMake Variable SDL_SHARED_LIB to add the SDL.dll as install-target.
  • Call Sequence:
    1. For better understanding the sequence of calls while using base device classes of ADTF SDK the device implementations are added to the installation as cpp-file.
    2. So you can debug through sequence.
Header
#pragma once
#include <SDL.h>
#include <adtf_filtersdk.h>
#include <adtf_systemsdk.h>
#include "./../../../system_services/gui/demo_sdl_application_service/sdl_application_intf.h"
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::system;
class cSDLVideoSink : public adtf::filter::cSampleStreamingSink,
public ISDLApplication::ISDLDrawer
{
public:
ADTF_CLASS_ID_NAME(cSDLVideoSink,
"demo_sdl_video_display.streaming_sink.adtf.cid",
"SDL Video Display");
REQUIRE_INTERFACE(ISDLApplication));
protected:
std::recursive_mutex m_oPaintingSync;
cSingleSampleReader* m_pReader = nullptr;
tStreamImageFormat m_sCurrentFormat;
public:
cSDLVideoSink();
tResult OnPaint(ISDLApplication::ISDLCanvas& oCanvas) override;
tResult RequestDynamicInputPin(const char *strName, const iobject_ptr<const IStreamType> &pType) override;
tResult Init() override;
tResult Shutdown() override;
};
#define REQUIRE_INTERFACE(_interface)
Macro usable with ADTF_CLASS_DEPENDENCIES() to require mandatory interfaces.
#define ADTF_CLASS_DEPENDENCIES(...)
Add interface ids (string literals,.
#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
Base class for ADTF sample streaming sinks.
Kernel interface for thread, timer and signal handling.
Definition: kernel_intf.h:388
Namespace for the ADTF Base SDK.
Namespace for the ADTF Filter SDK.
size_limited_sample_reader< 1 > cSingleSampleReader
The cSingleSampleReader will create a sample reader which will create a internal sample queue with on...
Definition: samplereader.h:841
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF System SDK.
Namespace for the ADTF uCOM3 SDK.
Implementation
#include "sdl_display.h"
ADTF_PLUGIN("SDL Display Sink",
cSDLVideoSink);
cSDLVideoSink::cSDLVideoSink()
{
// sets a short description for the component
SetDescription("Use this Streaming Sink to visualize data based on a simple SDL Application.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_sdl_display.html");
}
tResult cSDLVideoSink::RequestDynamicInputPin(const char *strName, const iobject_ptr<const IStreamType> &pType)
{
if (m_pReader)
{
RETURN_ERROR_DESC(ERR_INVALID_ARG, "Only one Connection is possible!!");
}
m_pReader = CreateInputPin<cSingleSampleReader>(strName, pType, false, false);
if (pType.Get())
{
get_stream_type_image_format(m_sCurrentFormat, *pType.Get());
}
m_pReader->SetAcceptTypeCallback([this](const adtf::ucom::ant::iobject_ptr<const IStreamType>& pType) -> tResult
{
return get_stream_type_image_format(m_sCurrentFormat, *pType.Get());
});
}
tResult cSDLVideoSink::Init()
{
RETURN_IF_FAILED(cSampleStreamingSink::Init());
object_ptr<ISDLApplication> pApp;
return pApp->RegisterSDLDrawer(*this);
}
tResult cSDLVideoSink::Shutdown()
{
object_ptr<ISDLApplication> pApp;
pApp->UnregisterSDLDrawer(*this);
return cSampleStreamingSink::Shutdown();
}
tResult cSDLVideoSink::OnPaint(ISDLApplication::ISDLCanvas& oCanvas)
{
object_ptr<const ISample> pSample;
if (IS_OK(m_pReader->GetLastSample(pSample)))
{
object_ptr_shared_locked<const ISampleBuffer> pBuffer;
RETURN_IF_FAILED(pSample->Lock(pBuffer));
RETURN_IF_FAILED(oCanvas.DrawImage(m_sCurrentFormat, pBuffer->GetPtr(), pBuffer->GetSize()));
}
}
#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_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#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.
virtual T * Get() const =0
Get raw pointer to shared object.
Base object pointer to realize binary compatible reference counting in interface methods.
tResult get_stream_type_image_format(tStreamImageFormat &oFormat, const IStreamType &oType)
Helper function to retrieve the oFormat (tStreamImageFormat) out of the of a IStreamType for a stream...
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.