nx_metadata_sdk 1.0 Metadata 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
9 #include <nx/sdk/analytics/i_object_track_best_shot_packet.h>
10 #include <nx/sdk/analytics/i_object_metadata_packet.h>
11
12 #include <nx/sdk/analytics/rect.h>
13
14 namespace nx {
15 namespace vms_server_plugins {
16 namespace analytics {
17 namespace stub {
18 namespace best_shots {
19
20 class DeviceAgent: public nx::sdk::analytics::ConsumingDeviceAgent
21 {
22 public:
23 DeviceAgent(const nx::sdk::IDeviceInfo* deviceInfo);
24 virtual ~DeviceAgent() override;
25
26 protected:
27 virtual std::string manifestString() const override;
28
29 virtual bool pushCompressedVideoFrame(
30 const nx::sdk::analytics::ICompressedVideoPacket* videoFrame) override;
31
32 virtual void doSetNeededMetadataTypes(
33 nx::sdk::Result<void>* outValue,
34 const nx::sdk::analytics::IMetadataTypes* neededMetadataTypes) override;
35
36 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived() override;
37
38 private:
39 struct TrackContext
40 {
41 nx::sdk::Uuid trackId;
42 nx::sdk::analytics::Rect boundingBox;
43 };
44
45 enum class BestShotGenerationPolicy
46 {
47 fixed,
48 url,
49 image,
50 };
51
52 struct BestShotGenerationContext
53 {
54 BestShotGenerationPolicy policy;
55 int frameNumberToGenerateBestShot = 0;
56
57 std::string url;
58
59 std::string imageDataFormat;
60 std::vector<char> imageData;
61
62 nx::sdk::analytics::Rect fixedBestShotBoundingBox;
63 };
64
65 private:
66 using BestShotList = std::vector<nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket>>;
67 BestShotList generateBestShots();
68
69 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket> generateFixedBestShot(
70 nx::sdk::Uuid trackId);
71
72 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket> generateUrlBestShot(
73 nx::sdk::Uuid trackId);
74
75 nx::sdk::Ptr<nx::sdk::analytics::IObjectTrackBestShotPacket> generateImageBestShot(
76 nx::sdk::Uuid trackId);
77
78 nx::sdk::Ptr<nx::sdk::analytics::IObjectMetadataPacket> generateObjects();
79
80 static BestShotGenerationPolicy bestShotGenerationPolicyFromString(const std::string& str);
81
82 private:
83 std::vector<TrackContext> m_trackContexts;
84 BestShotGenerationContext m_bestShotGenerationContext;
85 int64_t m_lastFrameTimestampUs = 0;
86 std::map<nx::sdk::Uuid, int> m_bestShotGenerationCounterByTrackId;
87 };
88
89 } // namespace best_shots
90 } // namespace stub
91 } // namespace analytics
92 } // namespace vms_server_plugins
93 } // namespace nx
nx::vms_server_plugins::analytics::stub::best_shots::DeviceAgent
Definition: device_agent.h:20
nx::sdk::analytics::ICompressedVideoPacket
Definition: i_compressed_video_packet.h:34
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::analytics::ConsumingDeviceAgent
Definition: consuming_device_agent.h:38
nx::sdk::analytics::IMetadataTypes
Definition: i_metadata_types.h:13
nx::sdk::Result< void >
Definition: result.h:81
nx::sdk::Uuid
Definition: uuid.h:22
nx::sdk::IDeviceInfo
Definition: i_device_info.h:14
nx::sdk::Result
Definition: result.h:47
nx
Definition: apple_utils.h:6
nx::vms_server_plugins::analytics::stub::best_shots::DeviceAgent::pushCompressedVideoFrame
virtual bool pushCompressedVideoFrame(const nx::sdk::analytics::ICompressedVideoPacket *videoFrame) override
Definition: device_agent.cpp:78
nx::vms_server_plugins::analytics::stub::best_shots::DeviceAgent::settingsReceived
virtual nx::sdk::Result< const nx::sdk::ISettingsResponse * > settingsReceived() override
Definition: device_agent.cpp:98
nx::sdk::analytics::Rect
Definition: rect.h:11