nx_metadata_sdk 1.0 Metadata SDK

engine.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 <atomic>
6 #include <thread>
7 #include <memory>
8 #include <mutex>
9 #include <condition_variable>
10
11 #include <nx/sdk/uuid.h>
12 #include <nx/sdk/analytics/helpers/plugin.h>
13 #include <nx/sdk/analytics/helpers/engine.h>
14 #include <nx/sdk/analytics/i_uncompressed_video_frame.h>
15
16 namespace nx {
17 namespace vms_server_plugins {
18 namespace analytics {
19 namespace stub {
20
21 class Engine: public nx::sdk::analytics::Engine
22 {
23 public:
24 using PixelFormat = nx::sdk::analytics::IUncompressedVideoFrame::PixelFormat;
25
26 Engine(nx::sdk::analytics::Plugin* plugin);
27
28 virtual ~Engine() override;
29
30 // Capabilities.
31 bool needUncompressedVideoFrames() const { return m_needUncompressedVideoFrames; }
32 PixelFormat pixelFormat() const { return m_pixelFormat; }
33
34 protected:
35 virtual std::string manifestString() const override;
36
37 virtual nx::sdk::Result<const nx::sdk::IStringMap*> settingsReceived() override;
38
39 protected:
40 virtual void doObtainDeviceAgent(
41 nx::sdk::Result<nx::sdk::analytics::IDeviceAgent*>* outResult,
42 const nx::sdk::IDeviceInfo* deviceInfo) override;
43
44 virtual nx::sdk::Result<sdk::analytics::IAction::Result> executeAction(
45 const std::string& actionId,
46 nx::sdk::Uuid trackId,
47 nx::sdk::Uuid deviceId,
48 int64_t timestampUs,
49 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackInfo> objectTrackInfo,
50 const std::map<std::string, std::string>& params) override;
51
52 private:
53 void obtainPluginHomeDir();
54 void initCapabilities();
55 void generatePluginDiagnosticEvents();
56
57 private:
58 nx::sdk::analytics::Plugin* const m_plugin;
59
60 mutable std::mutex m_pluginDiagnosticEventGenerationLoopMutex;
61 mutable std::condition_variable m_pluginDiagnosticEventGenerationLoopCondition;
62 std::unique_ptr<std::thread> m_pluginDiagnosticEventThread;
63 std::atomic<bool> m_terminated{false};
64 std::atomic<bool> m_needToThrowPluginDiagnosticEvents{false};
65
66 std::string m_pluginHomeDir;
67 std::string m_capabilities;
68 bool m_needUncompressedVideoFrames = false;
69 PixelFormat m_pixelFormat = PixelFormat::yuv420;
70 };
71
72 const std::string kGenerateEventsSetting{"generateEvents"};
73 const std::string kGenerateCarsSetting{"generateCars"};
74 const std::string kGenerateTrucksSetting{"generateTrucks"};
75 const std::string kGeneratePedestriansSetting{"generatePedestrians"};
76 const std::string kGenerateHumanFacesSetting{"generateHumanFaces"};
77 const std::string kGenerateBicyclesSetting{"generateBicycles"};
78
79 const std::string kGenerateObjectsEveryNFramesSetting{"generateObjectsEveryNFrames"};
80 const std::string kNumberOfObjectsToGenerateSetting{"numberOfObjectsToGenerate"};
81 const std::string kGeneratePreviewPacketSetting{"generatePreviewPacket"};
82 const std::string kGeneratePreviewAfterNFramesSetting("generatePreviewAfterNFrames");
83 const std::string kThrowPluginDiagnosticEventsFromDeviceAgentSetting{
84 "throwPluginDiagnosticEventsFromDeviceAgent"};
85
86 const std::string kThrowPluginDiagnosticEventsFromEngineSetting{
87 "throwPluginDiagnosticEventsFromDeviceAgent"};
88 const std::string kLeakFrames{"leakFrames"};
89 const std::string kAdditionalFrameProcessingDelayMs{"additionalFrameProcessingDelayMs"};
90 const std::string kOverallMetadataDelayMsSetting{"overallMetadataDelayMs"};
91
92 } // namespace stub
93 } // namespace analytics
94 } // namespace vms_server_plugins
95 } // namespace nx
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::Uuid
Definition: uuid.h:21
nx::sdk::IDeviceInfo
Definition: i_device_info.h:14
nx::vms_server_plugins::analytics::stub::Engine
Definition: engine.h:21
nx::sdk::Result
Definition: result.h:47
nx
Definition: apple_utils.h:6
nx::vms_server_plugins::analytics::stub::Engine::settingsReceived
virtual nx::sdk::Result< const nx::sdk::IStringMap * > settingsReceived() override
Definition: engine.cpp:403
nx::vms_server_plugins::analytics::stub::Engine::executeAction
virtual nx::sdk::Result< sdk::analytics::IAction::Result > executeAction(const std::string &actionId, nx::sdk::Uuid trackId, nx::sdk::Uuid deviceId, int64_t timestampUs, nx::sdk::Ptr< nx::sdk::analytics::IObjectTrackInfo > objectTrackInfo, const std::map< std::string, std::string > &params) override
Definition: engine.cpp:517
nx::sdk::analytics::Engine
Definition: engine.h:34
nx::sdk::analytics::Plugin
Definition: plugin.h:23