ADTF  v2.14.3
Demo Marker Event Filter

Implements an filter, which sends marker events to the harddisk recorder which sets the marker.

Load the project Marker.prj from configuration folder in this example and start. While playing the video press keys A-Z together with shift or the standard marker keys 0-9. After stopping the configuration and pressing F5 in project tree, you can see and edit the recorded markers.

Location
./src/examples/src/filters/demo_marker_event/
Build Environment
To see how to set up the build environment have a look at this page ADTF CMake Build System
This example shows:
  • how to implement a common adtf filter
  • how to create and send marker events
  • how to receive marker events while playing recorded files containing marker
  • how to implement the adtf::IKeyEventHandler to receive global Key Events
  • how to register within the adtf::IGlobalKeyEventManager to receive KeyEvents in non gui filters
The Header for this Filter
#ifndef _DEMO_MARKER_EVENT_FILTER_HEADER_
#define _DEMO_MARKER_EVENT_FILTER_HEADER_
#define OID_ADTF_DEMO_MARKER_EVENT "adtf.example.demo_marker_event"
class cDemoMarkerEventFilter
: public adtf::cFilter
{
ADTF_FILTER(OID_ADTF_DEMO_MARKER_EVENT, "Demo Marker Event Filter", OBJCAT_DataFilter)
public:
cDemoMarkerEventFilter(const tChar* __info);
virtual ~cDemoMarkerEventFilter();
// overwrites cFilter
tResult Init(tInitStage eStage, __exception = NULL);
tResult Start(__exception = NULL);
tResult Stop(__exception = NULL);
tResult Shutdown(tInitStage eStage, __exception = NULL);
//implement the IKeyEVentHandler
tResult OnKeyEvent(tKeyEventCode eCode,
tInt nParam1 = 0,
tInt nParam2 = 0,
tInt nFlags = 0,
tVoid* pEventData = NULL);
tResult Run(tInt nActivationType,
const tVoid* pvUserData,
tInt nUserDataSize,
__exception);
protected:
// Demonstrates how to send marker events
tResult SendMarkerEvent(const tChar* strName, tInt nKey);
private:
IGlobalKeyEventManager* m_pKeyEventManager;
};
#endif // _DEMO_MARKER_EVENT_FILTER_HEADER_
The Implementation for this Filter
#include "stdafx.h"
#include "./demo_marker_event_filter.h"
ADTF_FILTER_PLUGIN("Demo Marker Event Filter", OID_ADTF_DEMO_MARKER_EVENT, cDemoMarkerEventFilter)
cDemoMarkerEventFilter::cDemoMarkerEventFilter(const tChar* __info)
: cFilter(__info)
{
}
cDemoMarkerEventFilter::~cDemoMarkerEventFilter()
{
}
tResult cDemoMarkerEventFilter::SendMarkerEvent(const tChar* strName, tInt nKey)
{
// Use the cMarkerItem class to create the marker information
cMarkerItem oMarkerItem;
// Create a name which is shown in the project tree (type of marker)
oMarkerItem.SetName(cString::Format("%s_%c", strName, (tChar)nKey));
// Add any comment to describe the reason and purpose for the marker
oMarkerItem.SetComment(cString::Format("Key pressed: %c (%d)", (tChar)nKey, nKey));
// Describes which application sets the marker and which type are the application
// specific information
oMarkerItem.SetAppId("ADTF");
// If the application specific data contains just properties, then they can be edited
// with the standard marker dialog.
// to create the property xml representation a helper method is provided which returns a
// cString object
oMarkerItem.SetAppSpecific(
cMarkerItem::GetPropertyXml("key", cString::Format("%d", nKey)) +
cMarkerItem::GetPropertyXml("test", "value")
);
// The time field will be set automatically
// The XML representation of this cMarkerItem object is putted into the cEventInfo structure
cString strText = oMarkerItem.GetXml();
cEventInfo oEvent(0,
IEvent::CLASS_APPLICATION,
IEvent::EC_SetMarker,
0,
0,
(tVoid*) strText.GetPtr(),
strText.GetLength() + 1,
IEvent::FLAG_ASYNC);
// Get the Kernel interface
cObjectPtr<IKernel> pKernel;
(tVoid**) &pKernel));
// send this event
return pKernel->SignalSendAsync(&oEvent);
}
tResult cDemoMarkerEventFilter::Init(tInitStage eStage, __exception)
{
RETURN_IF_FAILED(cFilter::Init(eStage, __exception_ptr));
switch (eStage)
{
case StageFirst:
break;
case StageNormal:
{
_kernel->SignalRegister(static_cast<IRunnable*>(this));
}
break;
case StageGraphReady:
{
cObjectPtr<IApplication> pApplication;
IID_ADTF_APPLICATION,
(tVoid**)&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);
}
else
{
{
//error occured, but we dont break up here
LOG_EXCEPTION(oLocalEx);
}
}
}
}
break;
}
}
tResult cDemoMarkerEventFilter::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
LOG_EXCEPTION(oLocalEx);
}
}
else
{
//if everything is ok !! DO NOT FORGET TO UNREGISTER !!
}
}
return cFilter::Start(__exception_ptr);
}
tResult cDemoMarkerEventFilter::Stop(__exception)
{
if (m_pKeyEventManager)
{
m_pKeyEventManager->UnregisterKeyEventHandler(this);
}
return cFilter::Stop(__exception_ptr);
}
tResult cDemoMarkerEventFilter::Shutdown(tInitStage eStage, __exception)
{
switch (eStage)
{
case StageFirst:
break;
case StageNormal:
{
_kernel->SignalUnregister(static_cast<IRunnable*>(this));
}
break;
case StageGraphReady:
{
if (m_pKeyEventManager != NULL)
{
//this is not a IObject no reference counting provided
m_pKeyEventManager = NULL;
}
}
break;
}
return cFilter::Shutdown(eStage, __exception_ptr);
}
tResult cDemoMarkerEventFilter::OnKeyEvent(tKeyEventCode eCode,
tInt nParam1/* =0 */, // tKey
tInt nParam2/* =0 */, // tKeyState
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)
{
// Any key from A-Z sets a marker if shift is pressed also
if (nParam2 & IKeyEventHandler::KS_ShiftKeyDown &&
nParam1 >= IKeyEventHandler::KEY_A &&
nParam1 <= IKeyEventHandler::KEY_Z)
{
SendMarkerEvent("test", nParam1);
}
}
}
tResult cDemoMarkerEventFilter::Run(tInt nActivationType,
const tVoid* pvUserData,
tInt nUserDataSize,
__exception)
{
// we are only interested in signals which contain userdata with the size of tEventInfo
if (nActivationType == IRunnable::RUN_SIGNAL &&
pvUserData != NULL &&
nUserDataSize == sizeof(tEventInfo))
{
const tEventInfo* psEventInfo = (const tEventInfo*) pvUserData;
// Filter this events for EC_ReachedMarker events
if (psEventInfo->i32EventClass == IEvent::CLASS_APPLICATION &&
psEventInfo->i32EventCode == IEvent::EC_ReachedMarker)
{
// put the user data into a string
cString strMarkerText;
strMarkerText.Set((const tChar*) psEventInfo->pvData,
static_cast<tInt>(psEventInfo->szDataLength));
// create a marker item from this string which should be a XML string
cMarkerItem oItem;
oItem.FromXml(strMarkerText);
// just log the content.
LOG_INFO(strMarkerText);
LOG_INFO(cString::Format("Marker event received! %s (%s) \"%s\"", oItem.GetName(), oItem.GetTimeString().GetPtr(), oItem.GetComment()));
}
}
}

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