-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRadar.hpp
More file actions
261 lines (217 loc) · 8.31 KB
/
Copy pathRadar.hpp
File metadata and controls
261 lines (217 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause-Clear
#ifndef QC_NODE_RADAR_HPP
#define QC_NODE_RADAR_HPP
#include "QC/Infras/Memory/TensorDescriptor.hpp"
#include "QC/Node/NodeBase.hpp"
#include "RadarIface.hpp"
#include <cinttypes>
#include <cmath>
#include <inttypes.h>
#include <memory>
#include <string>
#include <unordered_map>
#include <memory>
namespace QC
{
namespace Node
{
/** @brief Radar Processing Service Configuration */
typedef struct
{
std::string serviceName; /**< Name of the processing service */
uint32_t timeoutMs; /**< Timeout for processing in milliseconds */
bool bEnablePerformanceLog; /**< Enable performance logging */
} Radar_ServiceConfig_t;
/** @brief Radar Node Initialization Configuration */
typedef struct
{
uint32_t maxInputBufferSize; /**< Maximum expected input buffer size */
uint32_t maxOutputBufferSize; /**< Maximum expected output buffer size */
Radar_ServiceConfig_t serviceConfig; /**< Processing service configuration */
} Radar_Config_t;
/**
* @brief Radar Node Configuration Data Structure
* @param params The QC component Radar configuration data structure.
* @param bufferIds The indices of buffers in QCNodeInit::buffers provided by the user application
* for use by Radar. These buffers will be registered into Radar during the initialization stage.
* @param globalBufferIdMap The global buffer index map used to identify which buffer in
* QCFrameDescriptorNodeIfs is used for Radar input and output.
* @param deRegisterAllBuffersWhenStop When the Stop API of the Radar node is called and
* deRegisterAllBuffersWhenStop is true, deregister all buffers.
*/
typedef struct RadarConfig : public QCNodeConfigBase_t
{
Radar_Config_t params;
std::vector<uint32_t> bufferIds;
std::vector<uint32_t> inputBufferIds;
std::vector<uint32_t> outputBufferIds;
std::vector<QCNodeBufferMapEntry_t> globalBufferIdMap;
bool bDeRegisterAllBuffersWhenStop;
} RadarConfig_t;
class RadarConfigIfs : public NodeConfigIfs
{
public:
/**
* @brief RadarConfigIfs Constructor
* @param[in] logger A reference to the logger to be shared and used by RadarConfigIfs.
* @param[in] radar A reference to the QC Radar component to be used by RadarConfigIfs.
* @return None
*/
RadarConfigIfs( Logger &logger ) : NodeConfigIfs( logger ) {}
/**
* @brief RadarConfigIfs Destructor
* @return None
*/
~RadarConfigIfs() {}
/**
* @brief Verify the configuration string and set the configuration structure.
* @param[in] config The configuration string.
* @param[out] errors The error string returned if there is an error.
* @note The config is a JSON string according to the template below:
* {
* "static": {
* "name": "The Node unique name, type: string",
* "id": "The Node unique ID, type: uint32_t",
* "maxInputBufferSize": "Maximum input buffer size, type: uint32_t",
* "maxOutputBufferSize": "Maximum output buffer size, type: uint32_t",
* "serviceName": "Processing service name/path, type: string",
* "timeoutMs": "Processing timeout in milliseconds, type: uint32_t",
* "enablePerformanceLog": "Enable performance logging, type: bool",
* "bufferIds": [A list of uint32_t values representing the indices of buffers
* in QCNodeInit::buffers],
* "globalBufferIdMap": [
* {
* "name": "The buffer name, type: string",
* "id": "The index to a buffer in QCFrameDescriptorNodeIfs"
* }
* ],
* "deRegisterAllBuffersWhenStop": "Flag to deregister all buffers when stopped,
* type: bool, default: false"
* }
* }
* @return QC_STATUS_OK on success, other values on failure.
*/
virtual QCStatus_e VerifyAndSet( const std::string config, std::string &errors );
/**
* @brief Get Configuration Options
* @return A reference string to the JSON configuration options.
*/
virtual const std::string &GetOptions();
/**
* @brief Get the Configuration Structure.
* @return A reference to the Configuration Structure.
*/
virtual const QCNodeConfigBase_t &Get() { return m_config; };
private:
QCStatus_e VerifyStaticConfig( DataTree &dt, std::string &errors );
QCStatus_e ParseStaticConfig( DataTree &dt, std::string &errors );
private:
std::string m_options;
public:
RadarConfig_t m_config;
};
typedef struct RadarMonitorConfig : public QCNodeMonitoringBase_t
{
bool bPerfEnabled;
} RadarMonitorConfig_t;
class RadarMonitoringIfs : public QCNodeMonitoringIfs
{
public:
RadarMonitoringIfs() {}
~RadarMonitoringIfs() {}
virtual QCStatus_e VerifyAndSet( const std::string config, std::string &errors )
{
return QC_STATUS_UNSUPPORTED;
}
virtual const std::string &GetOptions() { return m_options; }
virtual const QCNodeMonitoringBase_t &Get() { return m_config; };
virtual uint32_t GetMaximalSize() { return UINT32_MAX; }
virtual uint32_t GetCurrentSize() { return UINT32_MAX; }
virtual QCStatus_e Place( void *ptr, uint32_t &size ) { return QC_STATUS_UNSUPPORTED; }
private:
std::string m_options;
RadarMonitorConfig_t m_config;
};
class Radar : public NodeBase
{
public:
/**
* @brief Radar Constructor
* @return None
*/
Radar() : m_configIfs( m_logger ){};
/**
* @brief Radar Destructor
* @return None
*/
~Radar(){};
/**
* @brief Initializes Node Radar.
* @param[in] config The Node Radar configuration.
* @return QC_STATUS_OK on success, or an error code on failure.
*/
virtual QCStatus_e Initialize( QCNodeInit_t &config );
/**
* @brief Get the Node Radar configuration interface.
* @return A reference to the Node Radar configuration interface.
*/
virtual QCNodeConfigIfs &GetConfigurationIfs() { return m_configIfs; }
/**
* @brief Get the Node Radar monitoring interface.
* @return A reference to the Node Radar monitoring interface.
*/
virtual QCNodeMonitoringIfs &GetMonitoringIfs() { return m_monitorIfs; }
/**
* @brief Start the Node Radar
* @return QC_STATUS_OK on success, others on failure
*/
virtual QCStatus_e Start();
/**
* @brief Processes the Frame Descriptor.
* @param[in] frameDesc The frame descriptor containing input/output buffers.
* @note The configuration globalBufferIdMap determines which buffers are input and output.
* - The globalBufferIdMap[0].globalBufferId will be input buffer.
* - The globalBufferIdMap[1].globalBufferId will be output buffer.
* @return QC_STATUS_OK on success, or an error code on failure.
*/
virtual QCStatus_e ProcessFrameDescriptor( QCFrameDescriptorNodeIfs &frameDesc );
/**
* @brief Stop the Node Radar
* @return QC_STATUS_OK on success, others on failure
*/
virtual QCStatus_e Stop();
/**
* @brief De-initialize Node Radar
* @return QC_STATUS_OK on success, others on failure
*/
virtual QCStatus_e DeInitialize();
/**
* @brief Get the current state of the Node Radar
* @return The current state of the Node Radar
*/
virtual QCObjectState_e GetState() { return m_state; }
private:
QCStatus_e SetupGlobalBufferIdMap( const RadarConfig_t &cfg );
QCStatus_e ValidateBuffer( const QCBufferDescriptorBase_t *pBuffer, bool isInput );
QCStatus_e Execute( const QCBufferDescriptorBase_t *pInput,
const QCBufferDescriptorBase_t *pOutput );
private:
Radar_Config_t m_config;
QC::Library::RadarIface m_radarIface; /**< Radar processing interface */
std::unordered_map<void *, uint64_t> m_registeredInputBuffers;
std::unordered_map<void *, uint64_t> m_registeredOutputBuffers;
RadarConfigIfs m_configIfs;
RadarMonitoringIfs m_monitorIfs;
bool m_bDeRegisterAllBuffersWhenStop = false;
uint32_t m_inputNum = 1;
uint32_t m_outputNum = 1;
QCObjectState_e m_state;
std::vector<QCNodeBufferMapEntry_t> m_globalBufferIdMap;
#ifdef QC_RADAR_FRIEND_CLASS_UT
QC_RADAR_FRIEND_CLASS_UT
#endif
};
} // namespace Node
} // namespace QC
#endif // QC_NODE_RADAR_HPP