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