13 #ifndef __DEEPSTREAM_ACTION_H__
14 #define __DEEPSTREAM_ACTION_H__
16 #include <cuda_runtime_api.h>
32 #include <unordered_map>
37 #include "nvdspreprocess_meta.h"
40 #ifndef PLATFORM_TEGRA
45 #define LOG(out, level, fmt, ...) \
46 fprintf(out, "[%s: DS_3DAR] " fmt "\n", #level, ##__VA_ARGS__)
49 #define LOG_DEBUG(fmt, ...) \
50 if (gActionConfig.debug >= kDebugEnable) { \
51 LOG(stdout, DEBUG, fmt, ##__VA_ARGS__); \
55 #define LOG_ERROR(fmt, ...) \
56 LOG(stderr, ERROR, fmt, ##__VA_ARGS__)
59 class SafePtr:
public std::unique_ptr<T, std::function<void(T*)>> {
61 SafePtr(T* p, std::function<
void(T*)> freefn):
62 std::unique_ptr<T, std::function<void(T*)>>(p, freefn)
76 uint64_t sumFrames = 0;
82 : _max_frame_nums(interval)
85 struct timeval time_now;
86 gettimeofday(&time_now,
nullptr);
87 double now = (double)time_now.tv_sec + time_now.tv_usec / (
double)1000000;
89 auto iSrc = _timestamps.find(source_id);
90 if (iSrc != _timestamps.end()) {
91 auto & tms = iSrc->second;
92 fps = tms.size() / (now - tms.front());
93 while (tms.size() >= _max_frame_nums) {
96 auto & stats = _fpsStats[source_id];
98 stats.avgFps = stats.sumFrames / (now - stats.startTime);
101 iSrc = _timestamps.emplace(source_id, std::queue<double>()).first;
102 _fpsStats.emplace(source_id, FpsStats{now, 1, 0, 0});
104 iSrc->second.push(now);
110 void getAllFps(std::vector<std::pair<float, float>>& fps) {
111 for (
auto& s: _fpsStats) {
112 fps.emplace_back(std::make_pair(s.second.curFps, s.second.avgFps));
116 std::unordered_map<uint32_t, std::queue<double>> _timestamps;
117 uint32_t _max_frame_nums = 50;
118 std::map<uint32_t, FpsStats> _fpsStats;