1
|
#include <adtffiltersdk/adtf_filtersdk.h>
|
2
|
#include <adtfmediadescription/adtf_mediadescription.h>
|
3
|
|
4
|
using namespace adtf::util;
|
5
|
using namespace adtf::ucom;
|
6
|
using namespace adtf::base;
|
7
|
using namespace adtf::streaming;
|
8
|
using namespace adtf::filter;
|
9
|
using namespace adtf::mediadescription;
|
10
|
|
11
|
class cElementExtractorFilter: public cFilter
|
12
|
{
|
13
|
public:
|
14
|
ADTF_CLASS_ID_NAME(cElementExtractorFilter,
|
15
|
"element_extractor.filter.adtf.cid",
|
16
|
"Element Extractor");
|
17
|
public:
|
18
|
cElementExtractorFilter()
|
19
|
{
|
20
|
m_strElementName.SetDescription("The name of the structure element that should be extracted and forwarded.");
|
21
|
RegisterPropertyVariable("element_name", m_strElementName);
|
22
|
|
23
|
m_eTargetType.SetValueList(
|
24
|
{
|
25
|
{VT_Int8, "Int8"},
|
26
|
{VT_UInt8, "UInt8"},
|
27
|
{VT_Int16, "Int16"},
|
28
|
{VT_UInt16, "UInt16"},
|
29
|
{VT_Int32, "Int32"},
|
30
|
{VT_UInt32, "UInt32"},
|
31
|
{VT_Int64, "Int64"},
|
32
|
{VT_UInt64, "UInt64"},
|
33
|
{VT_Float32, "Float32"},
|
34
|
{VT_Float64, "Float64"}
|
35
|
});
|
36
|
RegisterPropertyVariable("output_type", m_eTargetType);
|
37
|
|
38
|
m_pReader = CreateInputPin<decoding_sample_reader<>>("input");
|
39
|
SetDescription("input", "The data of which the given element should be extracted.");
|
40
|
m_pWriter = CreateOutputPin("output");
|
41
|
SetDescription("output", "The element data will be forwarded here");
|
42
|
|
43
|
// sets a short description for the component
|
44
|
SetDescription("Use this filter to extract an element from complex input data (i.e. structures).");
|
45
|
|
46
|
// set help link to jump to documentation from ADTF Configuration Editor
|
47
|
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_element_extractor_filter.html");
|
48
|
}
|
49
|
|
50
|
tResult AcceptType(ISampleReader* pReader,
|
51
|
const adtf::ucom::iobject_ptr<const IStreamType>& pType) override
|
52
|
{
|
53
|
RETURN_IF_FAILED(cFilter::AcceptType(pReader, pType));
|
54
|
|
55
|
RETURN_IF_FAILED_DESC(ddl::access_element::find_index(*m_pReader, m_strElementName->c_str(), m_nElementIndex),
|
56
|
"Unable to find element '%s' in source stream type", m_strElementName->c_str());
|
57
|
|
58
|
object_ptr<IStreamType> pNewType;
|
59
|
switch (m_eTargetType)
|
60
|
{
|
61
|
case VT_Int8: pNewType = make_object_ptr<stream_type_plain<tInt8>>(); break;
|
62
|
case VT_UInt8: pNewType = make_object_ptr<stream_type_plain<tUInt8>>(); break;
|
63
|
case VT_Int16: pNewType = make_object_ptr<stream_type_plain<tInt16>>(); break;
|
64
|
case VT_UInt16: pNewType = make_object_ptr<stream_type_plain<tUInt16>>(); break;
|
65
|
case VT_Int32: pNewType = make_object_ptr<stream_type_plain<tInt32>>(); break;
|
66
|
case VT_UInt32: pNewType = make_object_ptr<stream_type_plain<tUInt32>>(); break;
|
67
|
case VT_Int64: pNewType = make_object_ptr<stream_type_plain<tInt64>>(); break;
|
68
|
case VT_UInt64: pNewType = make_object_ptr<stream_type_plain<tUInt64>>(); break;
|
69
|
case VT_Float32: pNewType = make_object_ptr<stream_type_plain<tFloat32>>(); break;
|
70
|
case VT_Float64: pNewType = make_object_ptr<stream_type_plain<tFloat64>>(); break;
|
71
|
default:
|
72
|
RETURN_ERROR_DESC(ERR_NOT_SUPPORTED, "Unsupported element type '%d'", *m_eTargetType);
|
73
|
}
|
74
|
|
75
|
m_pWriter->ChangeType(pNewType);
|
76
|
|
77
|
RETURN_NOERROR;
|
78
|
}
|
79
|
|
80
|
/// this function will be executed each time a trigger occured on one of the input pins.
|
81
|
/// it is possible that more than one sample is available at the reader.
|
82
|
tResult ProcessInput(tNanoSeconds, ISampleReader*) override
|
83
|
{
|
84
|
cSampleDecoder oDecoder;
|
85
|
tNanoSeconds tmSampleTime;
|
86
|
|
87
|
while (m_pReader->GetNextDecoder(oDecoder, tmSampleTime))
|
88
|
{
|
89
|
const auto oValue = oDecoder.GetElementValue(m_nElementIndex);
|
90
|
object_ptr<ISample> pSample;
|
91
|
switch (m_eTargetType)
|
92
|
{
|
93
|
case VT_Int8: pSample = output_sample_data<tInt8>(tmSampleTime, oValue.GetInt8()).Release(); break;
|
94
|
case VT_UInt8: pSample = output_sample_data<tUInt8>(tmSampleTime, oValue.GetUInt8()).Release(); break;
|
95
|
case VT_Int16: pSample = output_sample_data<tInt16>(tmSampleTime, oValue.GetInt16()).Release(); break;
|
96
|
case VT_UInt16: pSample = output_sample_data<tUInt16>(tmSampleTime, oValue.GetUInt16()).Release(); break;
|
97
|
case VT_Int32: pSample = output_sample_data<tInt32>(tmSampleTime, oValue.GetInt32()).Release(); break;
|
98
|
case VT_UInt32: pSample = output_sample_data<tUInt32>(tmSampleTime, oValue.GetUInt32()).Release(); break;
|
99
|
case VT_Int64: pSample = output_sample_data<tInt64>(tmSampleTime, oValue.GetInt64()).Release(); break;
|
100
|
case VT_UInt64: pSample = output_sample_data<tUInt64>(tmSampleTime, oValue.GetUInt64()).Release(); break;
|
101
|
case VT_Float32: pSample = output_sample_data<tFloat32>(tmSampleTime, oValue.GetFloat32()).Release(); break;
|
102
|
case VT_Float64: pSample = output_sample_data<tFloat64>(tmSampleTime, oValue.GetFloat64()).Release(); break;
|
103
|
default:
|
104
|
RETURN_ERROR(ERR_UNEXPECTED);
|
105
|
}
|
106
|
|
107
|
m_pWriter->Write(pSample);
|
108
|
}
|
109
|
|
110
|
RETURN_NOERROR;
|
111
|
}
|
112
|
private:
|
113
|
property_variable<std::string> m_strElementName;
|
114
|
decoding_sample_reader<>* m_pReader = nullptr;
|
115
|
ISampleWriter* m_pWriter = nullptr;
|
116
|
tSize m_nElementIndex = 0;
|
117
|
property_variable<tVariantType> m_eTargetType = VT_Float64;
|
118
|
};
|
119
|
|
120
|
// this creates the plugin entry methods and class factories
|
121
|
ADTF_PLUGIN("Demo Element Extractor Filter Plugin", cElementExtractorFilter);
|