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 <thread>
6 #include <atomic>
7 #include <memory>
8 #include <condition_variable>
9 #include <vector>
10 #include <string>
11 #include <deque>
12
13 #include <nx/sdk/analytics/helpers/consuming_device_agent.h>
14 #include <nx/sdk/analytics/helpers/pixel_format.h>
15 #include <nx/sdk/analytics/helpers/object_metadata_packet.h>
16
17 #include "engine.h"
18 #include "stub_analytics_plugin_video_frames_ini.h"
19
20 namespace nx {
21 namespace vms_server_plugins {
22 namespace analytics {
23 namespace stub {
24 namespace video_frames {
25
26 const std::string kMotionVisualizationObjectType = "nx.stub.motionVisualization";
27 const std::string kAdditionalFrameProcessingDelayMsSetting = "additionalFrameProcessingDelayMs";
28 const std::string kLeakFramesSetting = "leakFrames";
29
30 class DeviceAgent: public nx::sdk::analytics::ConsumingDeviceAgent
31 {
32 public:
33 DeviceAgent(Engine* engine, const nx::sdk::IDeviceInfo* deviceInfo);
34 virtual ~DeviceAgent() override;
35
36 protected:
37 virtual void doSetNeededMetadataTypes(
38 nx::sdk::Result<void>* outValue,
39 const nx::sdk::analytics::IMetadataTypes* neededMetadataTypes) override;
40
41 virtual std::string manifestString() const override;
42
43 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived() override;
44
45 virtual bool pushCompressedVideoFrame(
46 const nx::sdk::analytics::ICompressedVideoPacket* videoFrame) override;
47
48 virtual bool pushUncompressedVideoFrame(
49 const nx::sdk::analytics::IUncompressedVideoFrame* videoFrame) override;
50
51 private:
52 void processVideoFrame(const nx::sdk::analytics::IDataPacket* videoFrame, const char* func);
53
54 bool checkVideoFrame(const nx::sdk::analytics::IUncompressedVideoFrame* frame) const;
55
56 bool checkVideoFramePlane(
57 const nx::sdk::analytics::IUncompressedVideoFrame* frame,
58 const nx::sdk::analytics::PixelFormatDescriptor* pixelFormatDescriptor,
59 int plane) const;
60
61 void dumpSomeFrameBytes(
62 const nx::sdk::analytics::IUncompressedVideoFrame* frame,
63 int plane) const;
64
65 private:
66 Engine* const m_engine;
67
68 int m_frameCounter = 0;
69
70 struct DeviceAgentSettings
71 {
72 std::atomic<bool> leakFrames{false};
73
74 std::atomic<std::chrono::milliseconds> additionalFrameProcessingDelayMs{
75 std::chrono::milliseconds::zero()};
76 };
77
78 DeviceAgentSettings m_deviceAgentSettings;
79 };
80
81 } // namespace video_frames
82 } // namespace stub
83 } // namespace analytics
84 } // namespace vms_server_plugins
85 } // namespace nx
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent::pushCompressedVideoFrame
virtual bool pushCompressedVideoFrame(const nx::sdk::analytics::ICompressedVideoPacket *videoFrame) override
Definition: device_agent.cpp:131
nx::vms_server_plugins::analytics::stub::video_frames::Engine
Definition: engine.h:18
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent::settingsReceived
virtual nx::sdk::Result< const nx::sdk::ISettingsResponse * > settingsReceived() override
Definition: device_agent.cpp:57
nx::sdk::analytics::ICompressedVideoPacket
Definition: i_compressed_video_packet.h:34
nx::sdk::analytics::ConsumingDeviceAgent
Definition: consuming_device_agent.h:38
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent
Definition: device_agent.h:30
nx::sdk::analytics::IMetadataTypes
Definition: i_metadata_types.h:13
nx::sdk::Result< void >
Definition: result.h:81
nx::sdk::IDeviceInfo
Definition: i_device_info.h:14
nx::sdk::Result
Definition: result.h:47
nx
Definition: apple_utils.h:6
nx::sdk::analytics::PixelFormatDescriptor
Definition: pixel_format.h:26
nx::sdk::analytics::IUncompressedVideoFrame
Definition: i_uncompressed_video_frame.h:73
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent::pushUncompressedVideoFrame
virtual bool pushUncompressedVideoFrame(const nx::sdk::analytics::IUncompressedVideoFrame *videoFrame) override
Definition: device_agent.cpp:146
nx::sdk::analytics::IDataPacket
Definition: i_data_packet.h:17