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 <atomic>
6 #include <condition_variable>
7 #include <deque>
8 #include <memory>
9 #include <string>
10 #include <thread>
11 #include <vector>
12
13 #include <nx/sdk/analytics/helpers/consuming_device_agent.h>
14 #include <nx/sdk/analytics/helpers/object_metadata_packet.h>
15 #include <nx/sdk/analytics/helpers/pixel_format.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 std::string manifestString() const override;
38
39 virtual nx::sdk::Result<const nx::sdk::ISettingsResponse*> settingsReceived() override;
40
41 virtual bool pushCompressedVideoFrame(
42 nx::sdk::Ptr<const nx::sdk::analytics::ICompressedVideoPacket> videoFrame) override;
43
44 virtual bool pushUncompressedVideoFrame(
45 nx::sdk::Ptr<const nx::sdk::analytics::IUncompressedVideoFrame> videoFrame) override;
46
47 private:
48 void processVideoFrame(
49 nx::sdk::Ptr<const nx::sdk::analytics::IDataPacket> videoFrame, const char* func);
50
51 bool checkVideoFrame(
52 nx::sdk::Ptr<const nx::sdk::analytics::IUncompressedVideoFrame> frame) const;
53
54 bool checkVideoFramePlane(
55 nx::sdk::Ptr<const nx::sdk::analytics::IUncompressedVideoFrame> frame,
56 const nx::sdk::analytics::PixelFormatDescriptor* pixelFormatDescriptor,
57 int plane) const;
58
59 void dumpSomeFrameBytes(
60 nx::sdk::Ptr<const nx::sdk::analytics::IUncompressedVideoFrame> frame,
61 int plane) const;
62
63 private:
64 Engine* const m_engine;
65
66 int m_frameCounter = 0;
67
68 struct DeviceAgentSettings
69 {
70 std::atomic<bool> leakFrames{false};
71
72 std::atomic<std::chrono::milliseconds> additionalFrameProcessingDelayMs{
73 std::chrono::milliseconds::zero()};
74 };
75
76 DeviceAgentSettings m_deviceAgentSettings;
77 };
78
79 } // namespace video_frames
80 } // namespace stub
81 } // namespace analytics
82 } // namespace vms_server_plugins
83 } // namespace nx
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent::pushUncompressedVideoFrame
virtual bool pushUncompressedVideoFrame(nx::sdk::Ptr< const nx::sdk::analytics::IUncompressedVideoFrame > videoFrame) override
Definition: device_agent.cpp:147
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:58
nx::sdk::Ptr
Definition: ptr.h:18
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent::pushCompressedVideoFrame
virtual bool pushCompressedVideoFrame(nx::sdk::Ptr< const nx::sdk::analytics::ICompressedVideoPacket > videoFrame) override
Definition: device_agent.cpp:132
nx::sdk::analytics::ConsumingDeviceAgent
Definition: consuming_device_agent.h:36
nx::vms_server_plugins::analytics::stub::video_frames::DeviceAgent
Definition: device_agent.h:30
nx::sdk::IDeviceInfo
Definition: i_device_info.h:13
nx::sdk::Result
Definition: result.h:52
nx
Definition: apple_utils.h:6
nx::sdk::analytics::PixelFormatDescriptor
Definition: pixel_format.h:24