nx_server_plugin_sdk 1.0 Server Plugin SDK

consuming_device_agent.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <map>
6 #include <mutex>
7 #include <string>
8 #include <vector>
9
10 #include <nx/sdk/analytics/i_compound_metadata_packet.h>
11 #include <nx/sdk/analytics/i_compressed_video_packet.h>
12 #include <nx/sdk/analytics/i_consuming_device_agent.h>
13 #include <nx/sdk/analytics/i_custom_metadata_packet.h>
14 #include <nx/sdk/analytics/i_engine.h>
15 #include <nx/sdk/analytics/i_metadata_types.h>
16 #include <nx/sdk/analytics/i_uncompressed_video_frame.h>
17 #include <nx/sdk/helpers/log_utils.h>
18 #include <nx/sdk/helpers/ref_countable.h>
19 #include <nx/sdk/ptr.h>
20
21 namespace nx::sdk::analytics {
22
36 class ConsumingDeviceAgent: public RefCountable<IConsumingDeviceAgent>
37 {
38 protected:
39 const LogUtils logUtils;
40
41 protected:
50 ConsumingDeviceAgent(
51 const IDeviceInfo* deviceInfo,
52 bool enableOutput,
53 const std::string& integrationInstanceId = "");
54
55 virtual std::string manifestString() const = 0;
56
63 virtual bool pushCompressedVideoFrame(Ptr<const ICompressedVideoPacket> /*videoFrame*/)
64 {
65 return true;
66 }
67
72 virtual bool pushUncompressedVideoFrame(Ptr<const IUncompressedVideoFrame> /*videoFrame*/)
73 {
74 return true;
75 }
76
81 virtual bool pushCustomMetadataPacket(
82 Ptr<const ICustomMetadataPacket> /*customMetadataPacket*/)
83 {
84 return true;
85 }
86
93 virtual bool pullMetadataPackets(std::vector<Ptr<IMetadataPacket>>* /*metadataPackets*/)
94 {
95 return true;
96 }
97
102 void pushMetadataPacket(Ptr<IMetadataPacket> metadataPacket);
103
109 void pushIntegrationDiagnosticEvent(
110 IIntegrationDiagnosticEvent::Level level,
111 std::string caption,
112 std::string description) const;
113
119 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived()
120 {
121 return nullptr;
122 }
123
133 std::string settingValue(const std::string& settingName) const;
134
135 std::map<std::string, std::string> currentSettings() const;
136
137 void pushManifest(const std::string& pushManifest);
138
139 virtual void finalize() override;
140
141 virtual void doGetSettingsOnActiveSettingChange(
142 Result<const IActiveSettingChangedResponse*>* /*outResult*/,
143 const IActiveSettingChangedAction* /*activeSettingChangedAction*/) override
144 {
145 }
146
147 public:
148 virtual ~ConsumingDeviceAgent() override;
149
150 //-------------------------------------------------------------------------------------------------
151 // Not intended to be used by the descendant.
152
153 public:
154 virtual void setHandler(IHandler* handler) override;
155
156 protected:
157 virtual void doPushDataPacket(Result<void>* outResult, IDataPacket* dataPacket) override;
158
159 virtual void doSetSettings(
160 Result<const ISettingsResponse*>* outResult, const IStringMap* settings) override;
161
162 virtual void getIntegrationSideSettings(
163 Result<const ISettingsResponse*>* /*outResult*/) const override
164 {
165 }
166
167 virtual void getManifest(Result<const IString*>* outResult) const override;
168
169 virtual void doSetNeededMetadataTypes(
170 Result<void>* /*outResult*/, const IMetadataTypes* /*neededMetadataTypes*/) override
171 {
172 }
173
174 private:
175 void logMetadataPacketIfNeeded(
176 Ptr<const IMetadataPacket> metadataPacket,
177 int packetIndex) const;
178
179 void processMetadataPackets(const std::vector<Ptr<IMetadataPacket>>& metadataPackets);
180 void processMetadataPacket(Ptr<IMetadataPacket> metadataPacket, int packetIndex = -1);
181
182 private:
183 mutable std::mutex m_mutex;
184 Ptr<IDeviceAgent::IHandler> m_handler;
185 std::map<std::string, std::string> m_settings;
186 };
187
188 } // namespace nx::sdk::analytics
nx::sdk::IStringMap
Definition: i_string_map.h:9
nx::sdk::IActiveSettingChangedAction
Definition: i_active_setting_changed_action.h:14
nx::sdk::analytics::ConsumingDeviceAgent::pushIntegrationDiagnosticEvent
void pushIntegrationDiagnosticEvent(IIntegrationDiagnosticEvent::Level level, std::string caption, std::string description) const
Definition: consuming_device_agent.cpp:186
nx::sdk::analytics::ConsumingDeviceAgent::pushCustomMetadataPacket
virtual bool pushCustomMetadataPacket(Ptr< const ICustomMetadataPacket >)
Definition: consuming_device_agent.h:81
nx::sdk::analytics::ConsumingDeviceAgent::pullMetadataPackets
virtual bool pullMetadataPackets(std::vector< Ptr< IMetadataPacket >> *)
Definition: consuming_device_agent.h:93
nx::sdk::analytics::ConsumingDeviceAgent::settingValue
std::string settingValue(const std::string &settingName) const
Definition: consuming_device_agent.cpp:208
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::analytics::ConsumingDeviceAgent
Definition: consuming_device_agent.h:36
nx::sdk::analytics
Definition: consuming_device_agent.cpp:25
nx::sdk::Result< void >
Definition: result.h:86
nx::sdk::IDeviceInfo
Definition: i_device_info.h:13
nx::sdk::analytics::ConsumingDeviceAgent::pushMetadataPacket
void pushMetadataPacket(Ptr< IMetadataPacket > metadataPacket)
Definition: consuming_device_agent.cpp:179
nx::sdk::Result
Definition: result.h:52
nx::sdk::LogUtils
Definition: log_utils.h:27
nx::sdk::analytics::ConsumingDeviceAgent::pushUncompressedVideoFrame
virtual bool pushUncompressedVideoFrame(Ptr< const IUncompressedVideoFrame >)
Definition: consuming_device_agent.h:72
nx::sdk::analytics::ConsumingDeviceAgent::ConsumingDeviceAgent
ConsumingDeviceAgent(const IDeviceInfo *deviceInfo, bool enableOutput, const std::string &integrationInstanceId="")
Definition: consuming_device_agent.cpp:37
nx::sdk::analytics::ConsumingDeviceAgent::pushCompressedVideoFrame
virtual bool pushCompressedVideoFrame(Ptr< const ICompressedVideoPacket >)
Definition: consuming_device_agent.h:63
nx::sdk::analytics::ConsumingDeviceAgent::settingsReceived
virtual nx::sdk::Result< const nx::sdk::ISettingsResponse * > settingsReceived()
Definition: consuming_device_agent.h:119
nx::sdk::RefCountable
Definition: ref_countable.h:83