nx_server_plugin_sdk 1.0 Server Plugin SDK

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 <vector>
6
7 #include <nx/sdk/analytics/helpers/consuming_device_agent.h>
8 #include <nx/sdk/analytics/i_object_metadata_packet.h>
9 #include <nx/sdk/analytics/i_object_track_best_shot_packet.h>
10 #include <nx/sdk/analytics/i_object_track_title_packet.h>
11 #include <nx/sdk/analytics/rect.h>
12
13 namespace nx {
14 namespace vms_server_plugins {
15 namespace analytics {
16 namespace stub {
17 namespace best_shots {
18
19 class DeviceAgent: public nx::sdk::analytics::ConsumingDeviceAgent
20 {
21 public:
22 DeviceAgent(const nx::sdk::IDeviceInfo* deviceInfo);
23 virtual ~DeviceAgent() override;
24
25 protected:
26 virtual std::string manifestString() const override;
27
28 virtual bool pushCompressedVideoFrame(
29 nx::sdk::Ptr<const nx::sdk::analytics::ICompressedVideoPacket> videoFrame) override;
30
31 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived() override;
32
33 private:
34 struct TrackContext
35 {
36 nx::sdk::Uuid trackId;
37 nx::sdk::analytics::Rect boundingBox;
38 };
39
40 enum class BestShotGenerationPolicy
41 {
42 fixed,
43 url,
44 image,
45 };
46
47 enum class TitleGenerationPolicy
48 {
49 fixed,
50 url,
51 image,
52 };
53
54 struct BestShotGenerationContext
55 {
56 BestShotGenerationPolicy policy;
57 int frameNumberToGenerateBestShot = 0;
58
59 std::string url;
60
61 std::string imageDataFormat;
62 std::vector<char> imageData;
63
64 nx::sdk::analytics::Rect fixedBestShotBoundingBox;
65 };
66
67 struct TitleGenerationConext
68 {
69 TitleGenerationPolicy policy;
70 int frameNumberToGenerateTitle = 0;
71
72 std::string url;
73
74 std::string imageDataFormat;
75 std::vector<char> imageData;
76
77 std::string text;
78
79 nx::sdk::analytics::Rect fixedTitleBoundingBox;
80 };
81
82 private:
83 using BestShotList = std::vector<nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket>>;
84 BestShotList generateBestShots();
85
86 using TitleList = std::vector<nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackTitlePacket>>;
87 TitleList generateTitles();
88
89 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket> generateFixedBestShot(
90 nx::sdk::Uuid trackId);
91
92 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket> generateUrlBestShot(
93 nx::sdk::Uuid trackId);
94
95 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket> generateImageBestShot(
96 nx::sdk::Uuid trackId);
97
98 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackTitlePacket> generateFixedTitle(
99 nx::sdk::Uuid trackId);
100
101 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackTitlePacket> generateUrlTitle(
102 nx::sdk::Uuid trackId);
103
104 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackTitlePacket> generateImageTitle(
105 nx::sdk::Uuid trackId);
106
107 void maybeGenerateBestShotAndTitle();
108 void generateBestShotObject();
109 void generateTitleObject();
110
111 void configureBestShots(std::map<std::string, std::string>& settings);
112 void configureTitles(std::map<std::string, std::string>& settings);
113
114 static BestShotGenerationPolicy bestShotGenerationPolicyFromString(const std::string& str);
115 static TitleGenerationPolicy titleGenerationPolicyFromString(const std::string& str);
116
117 private:
118 std::vector<TrackContext> m_bestShotTrackContexts;
119 BestShotGenerationContext m_bestShotGenerationContext;
120 std::map<nx::sdk::Uuid, int> m_bestShotGenerationCounterByTrackId;
121
122 std::vector<TrackContext> m_titleTrackContexts;
123 TitleGenerationConext m_titleGenerationContext;
124 std::map<nx::sdk::Uuid, int> m_titleGenerationCounterByTrackId;
125
126 int64_t m_lastFrameTimestampUs = 0;
127 bool m_generateBestShot = true;
128 bool m_generateTitle = true;
129 };
130
131 } // namespace best_shots
132 } // namespace stub
133 } // namespace analytics
134 } // namespace vms_server_plugins
135 } // namespace nx
nx::vms_server_plugins::analytics::stub::best_shots::DeviceAgent
Definition: device_agent.h:19
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::analytics::ConsumingDeviceAgent
Definition: consuming_device_agent.h:36
nx::sdk::Uuid
Definition: uuid.h:22
nx::sdk::IDeviceInfo
Definition: i_device_info.h:13
nx::sdk::Result
Definition: result.h:52
nx
Definition: apple_utils.h:6
nx::vms_server_plugins::analytics::stub::best_shots::DeviceAgent::pushCompressedVideoFrame
virtual bool pushCompressedVideoFrame(nx::sdk::Ptr< const nx::sdk::analytics::ICompressedVideoPacket > videoFrame) override
Definition: device_agent.cpp:167
nx::vms_server_plugins::analytics::stub::best_shots::DeviceAgent::settingsReceived
virtual nx::sdk::Result< const nx::sdk::ISettingsResponse * > settingsReceived() override
Definition: device_agent.cpp:303
nx::sdk::analytics::Rect
Definition: rect.h:9