NVIDIA DeepStream SDK API Reference

8.0 Release
smart_recording_action.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #include <string>
14 #include <unordered_map>
15 #include <vector>
16 #include <chrono>
17 #include <mutex>
18 #include <condition_variable>
19 
20 #include "signal_emitter.hpp"
22 
23 // static bool flag = false;
25 
26 namespace deepstream {
27 
31 
32  public:
34 
35  virtual ~SmartRecordingAction () {}
36 
37  virtual std::vector<std::string> list() {
38  std::vector<std::string> actions;
39  actions.push_back("start-sr");
40  actions.push_back("stop-sr");
41  return actions;
42  }
43 
44  virtual void onAttached(SignalEmitter* emitter,
45  const std::string& action,
46  const std::string& object_name
47  ) {
48  emitter_ = emitter;
49 
50  if (!receiver.hasHandler(this)) {
51  receiver.addHandler(this);
52  }
53  if (!receiver.isConnected()) {
55  emitter->getProperty("proto-lib", config.proto_lib);
56  emitter->getProperty("conn-str", config.conn_str);
57  emitter->getProperty("msgconv-config-file", config.sensor_list_file);
58  emitter->getProperty("proto-config-file", config.config_file_path);
59  emitter->getProperty("topic-list", config.topicList);
60  receiver.connect(config);
61  }
62  // to maintain a map from the source id to object, we assume the object name
63  // be formatted as something like "name_id"
64  auto pos = object_name.rfind('_');
65  int64_t source_id = std::stoll(object_name.substr(pos+1));
66  if (object_map_.find(source_id) == object_map_.end()) {
67  object_map_.insert({source_id, object_name});
68  }
69  }
70 
71  virtual void startSmartRecord(int64_t camera_id, uint32_t *sessionId,
72  unsigned int startTime, unsigned int duration,
73  void *userData) {
74  if (!emitter_) {
75  throw std::runtime_error("Signal Emitter empty");
76  }
77  if (object_map_.find(camera_id) == object_map_.end()) {
78  // error
79  return;
80  }
81  emitter_->emit("start-sr", object_map_[camera_id],
82  sessionId, startTime, duration, userData, nullptr);
83  }
84 
85  virtual void stopSmartRecord(int64_t camera_id, uint32_t sessionId) {
86  if (!emitter_) {
87  throw std::runtime_error("Signal Emitter empty");
88  }
89  if (object_map_.find(camera_id) == object_map_.end()) {
90  // error
91  return;
92  }
93  emitter_->emit("stop-sr", object_map_[camera_id],
94  sessionId, nullptr);
95  }
96 
97  private:
98  SignalEmitter* emitter_ = nullptr;
99  std::map<int64_t, std::string> object_map_;
100 };
101 
102 }
deepstream::Cloud2DeviceReceiver::addHandler
void addHandler(IHandler *handler)
Definition: msgbroker_c2d_receiver.hpp:58
deepstream::SmartRecordingAction::~SmartRecordingAction
virtual ~SmartRecordingAction()
Definition: smart_recording_action.hpp:35
deepstream::SmartRecordingAction::list
virtual std::vector< std::string > list()
Definition: smart_recording_action.hpp:37
deepstream::SignalEmitter::emit
SignalEmitter & emit(const std::string &action_name, const std::string &object_name,...)
Emit the action by name.
deepstream::Cloud2DeviceReceiver::Config::conn_str
std::string conn_str
Definition: msgbroker_c2d_receiver.hpp:30
deepstream::Cloud2DeviceReceiver::Config::config_file_path
std::string config_file_path
Definition: msgbroker_c2d_receiver.hpp:31
receiver
static deepstream::Cloud2DeviceReceiver receiver
Definition: smart_recording_action.hpp:24
deepstream::SmartRecordingAction::SmartRecordingAction
SmartRecordingAction()
Definition: smart_recording_action.hpp:33
deepstream::Cloud2DeviceReceiver::Config::sensor_list_file
std::string sensor_list_file
Definition: msgbroker_c2d_receiver.hpp:33
deepstream::Cloud2DeviceReceiver::Config::proto_lib
std::string proto_lib
Definition: msgbroker_c2d_receiver.hpp:29
deepstream
Definition: buffer.hpp:33
deepstream::Cloud2DeviceReceiver::ISmartRecordingController
Definition: msgbroker_c2d_receiver.hpp:41
deepstream::SignalEmitter::IActionOwner
required interface for a signal emitter
Definition: signal_emitter.hpp:45
deepstream::Cloud2DeviceReceiver::connect
void connect(Config &config)
deepstream::Cloud2DeviceReceiver::Config
Definition: msgbroker_c2d_receiver.hpp:28
deepstream::Cloud2DeviceReceiver::isConnected
bool isConnected()
Definition: msgbroker_c2d_receiver.hpp:54
deepstream::Cloud2DeviceReceiver
Definition: msgbroker_c2d_receiver.hpp:26
deepstream::SmartRecordingAction::startSmartRecord
virtual void startSmartRecord(int64_t camera_id, uint32_t *sessionId, unsigned int startTime, unsigned int duration, void *userData)
Definition: smart_recording_action.hpp:71
deepstream::Cloud2DeviceReceiver::hasHandler
bool hasHandler(IHandler *handler)
Definition: msgbroker_c2d_receiver.hpp:55
deepstream::SmartRecordingAction::onAttached
virtual void onAttached(SignalEmitter *emitter, const std::string &action, const std::string &object_name)
Definition: smart_recording_action.hpp:44
deepstream::Cloud2DeviceReceiver::Config::topicList
std::string topicList
Definition: msgbroker_c2d_receiver.hpp:32
deepstream::SmartRecordingAction::stopSmartRecord
virtual void stopSmartRecord(int64_t camera_id, uint32_t sessionId)
Definition: smart_recording_action.hpp:85
msgbroker_c2d_receiver.hpp
signal_emitter.hpp
deepstream::SmartRecordingAction
Definition: smart_recording_action.hpp:28
deepstream::SignalEmitter
SignalEmitter class.
Definition: signal_emitter.hpp:42
deepstream::Object::getProperty
Object & getProperty(const std::string &name, T &value, Args &... args)
Template for getting multiple properties.
Definition: object.hpp:171