NVIDIA DeepStream SDK API Reference

9.1 Release
service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-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 #include <string>
19 #include <unordered_map>
20 #include <vector>
21 #include <chrono>
22 #include <mutex>
23 #include <condition_variable>
24 
25 #include "signal_emitter.hpp"
26 #include "lib/msgbroker_c2d_receiver.hpp"
27 
28 // static bool flag = false;
30 
31 namespace deepstream {
32 
36 
37  public:
39 
40  virtual ~SmartRecordingAction () {}
41 
42  virtual std::vector<std::string> list() {
43  std::vector<std::string> actions;
44  actions.push_back("start-sr");
45  actions.push_back("stop-sr");
46  return actions;
47  }
48 
49  virtual void onAttached(SignalEmitter* emitter,
50  const std::string& action,
51  const std::string& object_name
52  ) {
53  emitter_ = emitter;
54 
55  if (!receiver.hasHandler(this)) {
56  receiver.addHandler(this);
57  }
58  if (!receiver.isConnected()) {
60  emitter->getProperty("proto-lib", config.proto_lib);
61  emitter->getProperty("conn-str", config.conn_str);
62  emitter->getProperty("msgconv-config-file", config.sensor_list_file);
63  emitter->getProperty("proto-config-file", config.config_file_path);
64  emitter->getProperty("topic-list", config.topicList);
65  receiver.connect(config);
66  }
67  // to maintain a map from the source id to object, we assume the object name
68  // be formatted as something like "name_id"
69  auto pos = object_name.rfind('_');
70  int64_t source_id = std::stoll(object_name.substr(pos+1));
71  if (object_map_.find(source_id) == object_map_.end()) {
72  object_map_.insert({source_id, object_name});
73  }
74  }
75 
76  virtual void startSmartRecord(int64_t camera_id, uint32_t *sessionId,
77  unsigned int startTime, unsigned int duration,
78  void *userData) {
79  if (!emitter_) {
80  throw std::runtime_error("Signal Emitter empty");
81  }
82  if (object_map_.find(camera_id) == object_map_.end()) {
83  // error
84  return;
85  }
86  emitter_->emit("start-sr", object_map_[camera_id],
87  sessionId, startTime, duration, userData, nullptr);
88  }
89 
90  virtual void stopSmartRecord(int64_t camera_id, uint32_t sessionId) {
91  if (!emitter_) {
92  throw std::runtime_error("Signal Emitter empty");
93  }
94  if (object_map_.find(camera_id) == object_map_.end()) {
95  // error
96  return;
97  }
98  emitter_->emit("stop-sr", object_map_[camera_id],
99  sessionId, nullptr);
100  }
101 
102  private:
103  SignalEmitter* emitter_ = nullptr;
104  std::map<int64_t, std::string> object_map_;
105 };
106 
107 }
deepstream::Cloud2DeviceReceiver::addHandler
void addHandler(IHandler *handler)
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:63
deepstream::SmartRecordingAction::~SmartRecordingAction
virtual ~SmartRecordingAction()
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:40
deepstream::SmartRecordingAction::list
virtual std::vector< std::string > list()
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:42
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: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:35
deepstream::Cloud2DeviceReceiver::Config::config_file_path
std::string config_file_path
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:36
deepstream::SmartRecordingAction::SmartRecordingAction
SmartRecordingAction()
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:38
deepstream::Cloud2DeviceReceiver::Config::sensor_list_file
std::string sensor_list_file
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:38
deepstream::Cloud2DeviceReceiver::Config::proto_lib
std::string proto_lib
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:34
deepstream
Definition: service-maker/includes/buffer.hpp:38
deepstream::Cloud2DeviceReceiver::ISmartRecordingController
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:46
deepstream::SignalEmitter::IActionOwner
required interface for a signal emitter
Definition: service-maker/includes/signal_emitter.hpp:50
deepstream::Cloud2DeviceReceiver::connect
void connect(Config &config)
deepstream::Cloud2DeviceReceiver::Config
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:33
deepstream::Cloud2DeviceReceiver::isConnected
bool isConnected()
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:59
deepstream::Cloud2DeviceReceiver
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:31
deepstream::SmartRecordingAction::startSmartRecord
virtual void startSmartRecord(int64_t camera_id, uint32_t *sessionId, unsigned int startTime, unsigned int duration, void *userData)
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:76
deepstream::Cloud2DeviceReceiver::hasHandler
bool hasHandler(IHandler *handler)
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:60
deepstream::SmartRecordingAction::onAttached
virtual void onAttached(SignalEmitter *emitter, const std::string &action, const std::string &object_name)
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:49
deepstream::Cloud2DeviceReceiver::Config::topicList
std::string topicList
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:37
deepstream::SmartRecordingAction::stopSmartRecord
virtual void stopSmartRecord(int64_t camera_id, uint32_t sessionId)
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:90
deepstream::SmartRecordingAction
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:33
receiver
static deepstream::Cloud2DeviceReceiver receiver
Definition: service-maker/sources/modules/smart_recording_action/smart_recording_action.hpp:29
deepstream::SignalEmitter
SignalEmitter class.
Definition: service-maker/includes/signal_emitter.hpp:47
deepstream::Object::getProperty
Object & getProperty(const std::string &name, T &value, Args &... args)
Template for getting multiple properties.
Definition: service-maker/includes/object.hpp:176