23 #ifndef __DEEPSTREAM_ACTION_H__
24 #define __DEEPSTREAM_ACTION_H__
26 #include <cuda_runtime_api.h>
42 #include <unordered_map>
47 #include "nvdspreprocess_meta.h"
50 #ifndef PLATFORM_TEGRA
55 #define LOG(out, level, fmt, ...) \
56 fprintf(out, "[%s: DS_3DAR] " fmt "\n", #level, ##__VA_ARGS__)
59 #define LOG_DEBUG(fmt, ...) \
60 if (gActionConfig.debug >= kDebugEnable) { \
61 LOG(stdout, DEBUG, fmt, ##__VA_ARGS__); \
65 #define LOG_ERROR(fmt, ...) \
66 LOG(stderr, ERROR, fmt, ##__VA_ARGS__)
69 class SafePtr:
public std::unique_ptr<T, std::function<void(T*)>> {
71 SafePtr(T* p, std::function<
void(T*)> freefn):
72 std::unique_ptr<T, std::function<void(T*)>>(p, freefn)
86 uint64_t sumFrames = 0;
92 : _max_frame_nums(interval)
95 struct timeval time_now;
96 gettimeofday(&time_now,
nullptr);
97 double now = (double)time_now.tv_sec + time_now.tv_usec / (
double)1000000;
99 auto iSrc = _timestamps.find(source_id);
100 if (iSrc != _timestamps.end()) {
101 auto & tms = iSrc->second;
102 fps = tms.size() / (now - tms.front());
103 while (tms.size() >= _max_frame_nums) {
106 auto & stats = _fpsStats[source_id];
108 stats.avgFps = stats.sumFrames / (now - stats.startTime);
111 iSrc = _timestamps.emplace(source_id, std::queue<double>()).first;
112 _fpsStats.emplace(source_id, FpsStats{now, 1, 0, 0});
114 iSrc->second.push(now);
120 void getAllFps(std::vector<std::pair<float, float>>& fps) {
121 for (
auto& s: _fpsStats) {
122 fps.emplace_back(std::make_pair(s.second.curFps, s.second.avgFps));
126 std::unordered_map<uint32_t, std::queue<double>> _timestamps;
127 uint32_t _max_frame_nums = 50;
128 std::map<uint32_t, FpsStats> _fpsStats;