NVIDIA DeepStream SDK API Reference

9.1 Release
sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DS3D_DATALOADER_LIDARSOURCE_CONFIG_H
19 #define _DS3D_DATALOADER_LIDARSOURCE_CONFIG_H
20 
21 #include <ds3d/common/common.h>
22 #include <ds3d/common/func_utils.h>
23 
24 #include "ds3d/common/hpp/yaml_config.hpp"
25 #include "ds3d/common/idatatype.h"
26 
27 #define _PATH_MAX 4096
28 
29 namespace ds3d { namespace impl { namespace lidarsource {
30 
31 struct DataParas {
32  std::string location;
33  uint64_t pts;
34 };
35 
36 struct Config {
38  std::string dataConfigFilePath = "";
39  std::string realPath = "";
41  int gpuId = 0;
42  std::vector<std::string> datamapKey;
43  uint32_t pointNums = 0;
44  uint32_t elementSize = 4;
45  uint32_t elementStride = 0;
46  bool fixedPointsNum = true;
48  std::vector<std::deque<std::map<uint64_t, std::string>>> dataParas;
49  uint64_t lastFileTimestamp = 0;
50  uint32_t memPoolSize = 4;
51  bool fileLoop = false;
52  uint64_t frameDuration = 0;
53  uint32_t sourceId = 0;
54 };
55 
56 inline DataType getDataType(const std::string& dataType)
57 {
59  if(dataType == "FP32") {
60  ret = DataType::kFp32;
61  } else {
62  LOG_WARNING("unsupported datatype: %s, fallback to FP32", dataType.c_str());
63  }
64 
65  return ret;
66 }
67 
69 {
70  char absRealFilePath[_PATH_MAX + 1];
71  std::map<uint64_t, std::string> dataParas;
72  std::deque<std::map<uint64_t, std::string>> dataParasQueue;
73  YAML::Node node = YAML::LoadFile(config.realPath);
74  const YAML::Node& listNode = node["source-list"];
75  uint64_t timestampPrev = 0;
76  for (std::size_t i = 0; i < listNode.size(); i++) {
77  const YAML::Node& kvs = listNode[i];
78  for (const auto& kv : kvs) {
79  uint64_t timestamp = kv.first.as<uint64_t>();
80  std::string filename = kv.second.as<std::string>();
81  std::string absFilepath = "";
82  if (filename[0] == '/') {
83  absFilepath = filename;
84  } else {
85  int pos = config.realPath.find_last_of("/");
86  std::string tmpPath = config.realPath.substr(0, pos+1);
87  tmpPath = tmpPath + filename;
88  if (!realpath(tmpPath.c_str(), absRealFilePath)) {
89  if (errno != ENOENT) {
90  LOG_WARNING("Your config file path is not right!");
91  return ErrCode::kNotFound;
92  }
93  }
94  absFilepath = absRealFilePath;
95  LOG_DEBUG("lidar data path %s",absFilepath.c_str());
96  }
97  dataParas[timestamp] = absFilepath;
98  timestampPrev = config.lastFileTimestamp;
99  config.lastFileTimestamp = timestamp;
100  }
101  dataParasQueue.push_back(dataParas);
102  }
103 
104  config.dataParas.push_back(dataParasQueue);
105 
106  if (listNode.size() > 1) {
107  config.frameDuration = config.lastFileTimestamp - timestampPrev;
108  } else {
109  // default to 100ms
110  config.frameDuration = 100;
111  }
112 
113  return ErrCode::kGood;
114 }
115 
116 inline ErrCode
117 parseConfig(const std::string& content, const std::string& path, Config& config)
118 {
120  config::parseComponentConfig(content, path, config.compConfig),
121  "parse lidarsource component content failed");
122  char absRealFilePath[_PATH_MAX + 1];
123  YAML::Node node = YAML::Load(config.compConfig.configBody);
124 
125  if (node["data_config_file"]) {
126  auto lidarDataNode = node["data_config_file"];
127  std::vector<std::string> lidarDataPaths;
128  if (lidarDataNode.IsSequence()) {
129  lidarDataPaths = lidarDataNode.as<std::vector<std::string>>();
130  } else {
131  // There is only one lidar data
132  lidarDataPaths.resize(1);
133  lidarDataPaths[0] = lidarDataNode.as<std::string>();
134  }
135  for (const auto& item : lidarDataPaths) {
136  config.dataConfigFilePath = item;
137  if (config.dataConfigFilePath[0] == '/') {
138  config.realPath = config.dataConfigFilePath;
139  LOG_DEBUG("config path %s",config.realPath.c_str());
140  } else {
141  if (!realpath(path.c_str(), absRealFilePath)) {
142  if (errno != ENOENT) {
143  LOG_WARNING("Your config file path is not right!");
144  return ErrCode::kNotFound;
145  }
146  }
147  config.realPath = absRealFilePath;
148  int pos = config.realPath.find_last_of("/");
149  std::string tmpPath = config.realPath.substr(0, pos+1);
150  config.realPath = tmpPath + config.dataConfigFilePath;
151  LOG_DEBUG("config path %s",config.realPath.c_str());
152  }
153  parseDataConfig(config);
154  }
155  }
156 
157  if (node["mem_type"]) {
158  auto strType = node["mem_type"].as<std::string>();
159  if (strncasecmp(strType.c_str(), "cpu", strType.size()) == 0) {
160  config.memType = MemType::kCpu;
161  } else if (strncasecmp(strType.c_str(), "gpu", strType.size()) == 0) {
162  config.memType = MemType::kGpuCuda;
163  } else {
164  LOG_WARNING(
165  "unknown mem_type: %s in lidar_file_source config parsing", strType.c_str());
166  }
167  }
168  if (node["gpu_id"]) {
169  config.gpuId = node["gpu_id"].as<int32_t>();
170  }
171  if (node["fixed_points_num"]) {
172  config.fixedPointsNum = node["fixed_points_num"].as<bool>();
173  }
174  if (node["mem_pool_size"]) {
175  config.memPoolSize = node["mem_pool_size"].as<uint32_t>();
176  }
177  if (node["data_type"]) {
178  std::string dataType = node["data_type"].as<std::string>();
179  config.dataType = getDataType(dataType);
180  }
181  if (node["points_num"]) {
182  config.pointNums = node["points_num"].as<uint32_t>();
183  }
184  if (node["element_stride"]) {
185  config.elementStride = node["element_stride"].as<uint32_t>();
186  }
187  if (node["element_size"]) {
188  config.elementSize = node["element_size"].as<uint32_t>();
189  }
190  if (node["output_datamap_key"]) {
191  auto keyNode = node["output_datamap_key"];
192  if (keyNode.IsSequence()) {
193  config.datamapKey = keyNode.as<std::vector<std::string>>();
194  } else {
195  config.datamapKey.resize(1);
196  config.datamapKey[0] = keyNode.as<std::string>();
197  }
198  }
199  if (node["file_loop"]) {
200  config.fileLoop = node["file_loop"].as<bool>();
201  }
202 
203  if (node["source_id"]) {
204  config.sourceId = node["source_id"].as<uint32_t>();
205  }
206 
207  if (config.elementStride == 0) {
208  config.elementStride = config.elementSize;
209  }
210 
212  config.elementSize == 3 || config.elementSize == 4, ErrCode::kConfig,
213  "lidar data config element_size: %d must be [3, 4].", config.elementSize);
214  assert(config.elementStride >= config.elementSize);
215 
216  return ErrCode::kGood;
217 }
218 
219 }}} // namespace ds3d::impl::lidarsource
220 
221 #endif // _DS3D_DATALOADER_LIDARSOURCE_CONFIG_H
ds3d::impl::lidarsource::Config::memPoolSize
uint32_t memPoolSize
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:50
ds3d::impl::lidarsource::Config::gpuId
int gpuId
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:41
ds3d::ErrCode::kNotFound
@ kNotFound
ds3d::MemType::kCpu
@ kCpu
ds3d::impl::lidarsource::Config::realPath
std::string realPath
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:39
ds3d::DataType::kFp32
@ kFp32
ds3d::impl::lidarsource::Config::dataConfigFilePath
std::string dataConfigFilePath
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:38
ds3d::DataType
DataType
Definition: sources/includes/ds3d/common/idatatype.h:82
DS3D_FAILED_RETURN
#define DS3D_FAILED_RETURN(condition, ret, fmt,...)
Definition: sources/includes/ds3d/common/defines.h:69
_PATH_MAX
#define _PATH_MAX
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:27
ds3d::ErrCode::kGood
@ kGood
ds3d::impl::lidarsource::parseConfig
ErrCode parseConfig(const std::string &content, const std::string &path, Config &config)
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:117
ds3d::impl::lidarsource::Config::fileLoop
bool fileLoop
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:51
ds3d::impl::lidarsource::Config::lastFileTimestamp
uint64_t lastFileTimestamp
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:49
ds3d::config::parseComponentConfig
ErrCode parseComponentConfig(const std::string &yamlComp, const std::string &path, ComponentConfig &config)
Definition: sources/includes/ds3d/common/hpp/yaml_config.hpp:57
ds3d::impl::lidarsource::Config::pointNums
uint32_t pointNums
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:43
ds3d::ErrCode
ErrCode
Definition: sources/includes/ds3d/common/common.h:47
LOG_DEBUG
#define LOG_DEBUG(fmt,...)
Definition: sources/apps/sample_apps/deepstream-3d-action-recognition/deepstream_action.h:54
ds3d::impl::lidarsource::DataParas::pts
uint64_t pts
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:33
ds3d::impl::lidarsource::DataParas::location
std::string location
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:32
ds3d::impl::lidarsource::Config::memType
MemType memType
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:40
ds3d::impl::lidarsource::Config::datamapKey
std::vector< std::string > datamapKey
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:42
ds3d::impl::lidarsource::Config::elementSize
uint32_t elementSize
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:44
LOG_WARNING
#define LOG_WARNING
Definition: sources/gst-plugins/gst-nvtracker/logging.h:24
ds3d::impl::lidarsource::DataParas
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:31
ds3d::MemType::kGpuCuda
@ kGpuCuda
ds3d::ErrCode::kConfig
@ kConfig
ds3d::impl::lidarsource::Config::sourceId
uint32_t sourceId
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:53
ds3d::config::ComponentConfig::configBody
std::string configBody
Definition: sources/includes/ds3d/common/config.h:48
ds3d::impl::lidarsource::parseDataConfig
ErrCode parseDataConfig(Config &config)
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:68
ds3d::impl::lidarsource::Config::elementStride
uint32_t elementStride
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:45
ds3d::impl::lidarsource::Config
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:36
ds3d::config::ComponentConfig
Definition: sources/includes/ds3d/common/config.h:38
ds3d::impl::lidarsource::Config::fixedPointsNum
bool fixedPointsNum
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:46
DS3D_ERROR_RETURN
#define DS3D_ERROR_RETURN(code, fmt,...)
Definition: sources/includes/ds3d/common/defines.h:77
ds3d::impl::lidarsource::getDataType
DataType getDataType(const std::string &dataType)
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:56
ds3d::impl::lidarsource::Config::dataType
DataType dataType
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:47
ds3d
Definition: sources/includes/ds3d/common/abi_dataprocess.h:25
ds3d::impl::lidarsource::Config::compConfig
config::ComponentConfig compConfig
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:37
ds3d::MemType
MemType
Definition: sources/includes/ds3d/common/idatatype.h:106
ds3d::impl::lidarsource::Config::frameDuration
uint64_t frameDuration
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:52
ds3d::impl::lidarsource::Config::dataParas
std::vector< std::deque< std::map< uint64_t, std::string > > > dataParas
Definition: sources/libs/ds3d/dataloader/lidarsource/lidar_file_config.h:48