18 #ifndef __DEEPSTREAM_ACTION_H__
19 #define __DEEPSTREAM_ACTION_H__
21 #include <cuda_runtime_api.h>
37 #include <unordered_map>
41 #include "gstnvdsmeta.h"
42 #include "nvdspreprocess_meta.h"
43 #include "gstnvdsinfer.h"
45 #ifndef PLATFORM_TEGRA
46 #include "gst-nvmessage.h"
50 #define LOG(out, level, fmt, ...) \
51 fprintf(out, "[%s: DS_3DAR] " fmt "\n", #level, ##__VA_ARGS__)
54 #define LOG_DEBUG(fmt, ...) \
55 if (gActionConfig.debug >= kDebugEnable) { \
56 LOG(stdout, DEBUG, fmt, ##__VA_ARGS__); \
60 #define LOG_ERROR(fmt, ...) \
61 LOG(stderr, ERROR, fmt, ##__VA_ARGS__)
64 class SafePtr:
public std::unique_ptr<T, std::function<void(T*)>> {
66 SafePtr(T* p, std::function<
void(T*)> freefn):
67 std::unique_ptr<T, std::function<void(T*)>>(p, freefn)
81 uint64_t sumFrames = 0;
87 : _max_frame_nums(interval)
90 struct timeval time_now;
91 gettimeofday(&time_now,
nullptr);
92 double now = (double)time_now.tv_sec + time_now.tv_usec / (
double)1000000;
94 auto iSrc = _timestamps.find(source_id);
95 if (iSrc != _timestamps.end()) {
96 auto & tms = iSrc->second;
97 fps = tms.size() / (now - tms.front());
98 while (tms.size() >= _max_frame_nums) {
101 auto & stats = _fpsStats[source_id];
103 stats.avgFps = stats.sumFrames / (now - stats.startTime);
106 iSrc = _timestamps.emplace(source_id, std::queue<double>()).first;
107 _fpsStats.emplace(source_id, FpsStats{now, 1, 0, 0});
109 iSrc->second.push(now);
115 void getAllFps(std::vector<std::pair<float, float>>& fps) {
116 for (
auto& s: _fpsStats) {
117 fps.emplace_back(std::make_pair(s.second.curFps, s.second.avgFps));
121 std::unordered_map<uint32_t, std::queue<double>> _timestamps;
122 uint32_t _max_frame_nums = 50;
123 std::map<uint32_t, FpsStats> _fpsStats;