ADTF  v2.14.3
Demo Non Gui KeyEvent Filter

Implements an filter, which registers for global keyevents while running

Build Environment
To see how to set up the build environment have a look at this page ADTF CMake Build System
This example shows:
The Header for this Filter
#define OID_ADTF_DEMO_KEYEVENT "adtf.example.demo_keyevent"
class cDemoKeyEventFilter : public adtf::cFilter,
public: //common implementation
cDemoKeyEventFilter(const tChar* __info);
virtual ~cDemoKeyEventFilter();
private: //private members
cOutputPin m_oOutput;
IGlobalKeyEventManager* m_pKeyEventManager;
cObjectPtr<IMediaTypeDescription> m_pCoderDesc;
tUInt16 m_ui16MessageId;
private: //private functions
tResult ProcessKeyEvent(tUInt32 nKeyPressed);
public: // overwrites cFilter
tResult Init(tInitStage eStage, __exception = NULL);
tResult Start(__exception = NULL);
tResult Stop(__exception = NULL);
tResult Shutdown(tInitStage eStage, __exception = NULL);
public: //implement the IKeyEVentHandler
tResult OnKeyEvent(tKeyEventCode eCode,
tInt nParam1 = 0,
tInt nParam2 = 0,
tInt nFlags = 0,
tVoid* pEventData = NULL);
The Implementation for this Filter
#include "stdafx.h"
#include "./demo_nongui_keyevent_filter.h"
ADTF_FILTER_PLUGIN("Demo Key Event Filter", OID_ADTF_DEMO_KEYEVENT, cDemoKeyEventFilter)
cDemoKeyEventFilter::cDemoKeyEventFilter(const tChar* __info) : cFilter(__info)
m_ui16MessageId = 120;
SetPropertyInt("message_id", (tInt)m_ui16MessageId);
tResult cDemoKeyEventFilter::ProcessKeyEvent(tUInt32 nKeyPressed)
if (nKeyPressed != 0)
// create a Media Sample of type "tMyADTFMessage" and transmit the key code within this Sample
cObjectPtr<IMediaSample> pMediaSample;
cObjectPtr<IMediaSerializer> pSerializer;
tInt nSize = pSerializer->GetDeserializedSize();
// to allocate the buffer, you have to know the exact size of DDL-Type-Description for this Pin:
// either count by yourself the values within the .description file, or use the "De-SerializedSize"
cObjectPtr<IMediaCoder> pCoder;
RETURN_IF_FAILED(m_pCoderDesc->WriteLock(pMediaSample, &pCoder));
// to fill the buffer, you have to know the exact data-types!
// DON'T forget to initialize the whole memory, e.g. fill-in ALL values!
tUInt8 ui8Value = tUInt8(0);
tUInt16 ui16Value = m_ui16MessageId;
tUInt32 ui32Value = tUInt32(nKeyPressed);
tInt32 i32Value = tInt32(0);
tInt64 i64Value = tInt64(0);
tFloat64 f64Value = tFloat64(0);
tFloat32 f32Value = tFloat32(0);
//we access the elements element by element
//the coder can handle the point-operator.
pCoder->Set("sHeaderStruct.ui32HeaderVal", (tVoid*)&ui32Value);
pCoder->Set("sHeaderStruct.f64HeaderVal", (tVoid*)&f64Value);
pCoder->Set("sSimpleStruct.ui8Val", (tVoid*)&ui8Value);
pCoder->Set("sSimpleStruct.ui16Val", (tVoid*)&ui16Value);
pCoder->Set("sSimpleStruct.ui32Val", (tVoid*)&ui32Value);
pCoder->Set("sSimpleStruct.i32Val", (tVoid*)&i32Value);
pCoder->Set("sSimpleStruct.i64Val", (tVoid*)&i64Value);
pCoder->Set("sSimpleStruct.f64Val", (tVoid*)&f64Value);
pCoder->Set("sSimpleStruct.f32Val", (tVoid*)&f32Value);
LOG_INFO(cString::Format("Demo Key Event Filter : Sent the Key Code %d via message %d", (tInt)nKeyPressed, (tInt) m_ui16MessageId).GetPtr());
tResult cDemoKeyEventFilter::Init(tInitStage eStage, __exception)
RETURN_IF_FAILED(cFilter::Init(eStage, __exception_ptr));
if (eStage == StageFirst)
// create a pin, that can send data of the type "tMyADTFMessage"
cObjectPtr<IMediaDescriptionManager> pDescManager;
* the MediaDescription for <struct ... name="tMyADTFMessage" .../> has to exist in a description file in $ADTF_DIR\description\
* before (!) you start adtf_devenv !! if not: the Filter-Plugin will not loaded because cPin.Create() and so ::Init() failes !
tChar const * strDesc = pDescManager->GetMediaDescription("tMyADTFMessage");
cObjectPtr<IMediaType> pOutputType = new cMediaType(0, 0, 0, "tMyADTFMessage", strDesc, IMediaDescription::MDF_DDL020000);
RETURN_IF_FAILED(m_oOutput.Create("tMyADTFMessage", pOutputType, NULL));
RETURN_IF_FAILED(pOutputType->GetInterface(IID_ADTF_MEDIA_TYPE_DESCRIPTION, (tVoid**)&m_pCoderDesc));
else if (eStage == StageNormal)
m_ui16MessageId = GetPropertyInt("message_id", 120);
// log information how to use the example
LOG_INFO("demo_nongui_keyevent: Press the control key + another key to send a Media Sample with this Filter.");
else if (eStage == StageGraphReady)
cObjectPtr<IApplication> pApplication;
tHandle hKeyEventManager = NULL;
cException oLocalEx;
tResult nResult = pApplication->GetInternalHandle(ADTF_APPLICATION_KEYEVENTMANAGER_HANDLE, &hKeyEventManager, &oLocalEx);
if (IS_OK(nResult))
m_pKeyEventManager = static_cast<IGlobalKeyEventManager*>(hKeyEventManager);
//error occured, but we dont break up here
tResult cDemoKeyEventFilter::Start(__exception)
if (m_pKeyEventManager)
ucom::cException oLocalEx;
if (IS_FAILED(m_pKeyEventManager->RegisterKeyEventHandler(this, 0, &oLocalEx)))
//error occured, but we dont break up here
//if everything is ok !! DO NOT FORGET TO UNREGISTER !!
return cFilter::Start(__exception_ptr);
tResult cDemoKeyEventFilter::Stop(__exception)
if (m_pKeyEventManager)
return cFilter::Stop(__exception_ptr);
tResult cDemoKeyEventFilter::Shutdown(tInitStage eStage, __exception)
if (eStage == StageGraphReady && m_pKeyEventManager != NULL)
//this is not a IObject no reference counting provided
m_pKeyEventManager = NULL;
return cFilter::Shutdown(eStage, __exception_ptr);
tResult cDemoKeyEventFilter::OnKeyEvent(tKeyEventCode eCode,
tInt nParam1/* =0 */,
tInt nParam2/* =0 */,
tInt nFlags/* =0 */,
tVoid* pEventData/* =NULL */)
//a input event will be send alway if you pressed a key, also if you keep pressing
if (eCode == IKeyEventHandler::EC_KeyInput)
// check here if control key is pressed also
if (nParam2 & IKeyEventHandler::KS_CtrlKeyDown &&
nParam1 != IKeyEventHandler::KEY_CTRL)

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Fri Mar 22 2019 by doxygen 1.8.10)