nx_server_plugin_sdk  1.0
Server Plugin SDK
stream_parser.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 <map>
6 #include <set>
7 #include <string>
8 #include <vector>
9 
10 #include <nx/kit/json.h>
11 #include <nx/sdk/analytics/rect.h>
12 #include <nx/sdk/uuid.h>
13 
14 namespace nx {
15 namespace vms_server_plugins {
16 namespace analytics {
17 namespace stub {
18 namespace object_streamer {
19 
20 std::string readFileToString(const std::string& filePath);
21 
22 struct Object
23 {
24  enum class EntryType
25  {
26  regular,
27  bestShot,
28  title
29  };
30 
31  std::string typeId;
32  nx::sdk::Uuid trackId;
33  std::string trackIdRef;
34  nx::sdk::analytics::Rect boundingBox;
35  std::map<std::string, std::string> attributes;
36  int frameNumberToGenerateObject = 0;
37  int64_t timestampUs = -1;
38  EntryType entryType = EntryType::regular;
39  std::string imageSource;
40  std::string titleText;
41 };
42 
43 enum class Issue
44 {
45  objectStreamIsNotAValidJson,
46  objectStreamIsNotAJsonArray,
47  objectItemIsNotAJsonObject,
48  trackIdIsNotAString,
49  trackIdIsNotAUuid,
50  typeIdIsNotAString,
51  frameNumberIsNotANumber,
52  boundingBoxIsNotAJsonObject,
53  topLeftXIsNotANumber,
54  topLeftYIsNotANumber,
55  widthIsNotANumber,
56  heightIsNotANumber,
57  objectIsOutOfBounds,
58  attributesFieldIsNotAJsonObject,
59  attributeValueIsNotAString,
60  timestampIsNotANumber,
61  objectEntryTypeIsNotAString,
62  objectEntryTypeIsUnknown,
63  imageSourceIsNotAString,
64  titleTextIsNotAString
65 };
66 
67 struct Issues
68 {
69  std::set<Issue> errors;
70  std::set<Issue> warnings;
71 };
72 
73 struct StreamInfo
74 {
75  std::map<int, std::vector<Object>> objectsByFrameNumber;
76  std::set<std::string> objectTypeIds;
77 };
78 
79 StreamInfo parseObjectStreamFile(const std::string& filePath, Issues* issues);
80 
81 bool parseTrackId(
82  const nx::kit::Json& objectDescription,
83  Object* outObject,
84  Issues* issues);
85 
86 bool parseCommonFields(
87  const nx::kit::Json& objectDescription,
88  Object* outObject,
89  Issues* issues);
90 
91 bool parseBoundingBox(
92  const nx::kit::Json& objectDescription,
93  nx::sdk::analytics::Rect* outBoundingBox,
94  Issues* issues);
95 
96 bool parseAttributes(
97  const nx::kit::Json& objectDescription,
98  std::map<std::string, std::string>* outAttributes,
99  Issues* issues);
100 
101 bool parseTimestamp(
102  const nx::kit::Json& objectDescription,
103  int64_t* outTimestamp,
104  Issues* issues);
105 
106 bool parseImageSource(
107  const nx::kit::Json& objectDescription,
108  std::string* outImageSource,
109  Issues* issues);
110 
111 bool parseTitleText(
112  const nx::kit::Json& objectDescription,
113  std::string* outTitleText,
114  Issues* issues);
115 
116 std::string issueToString(Issue issue);
117 
118 } // namespace object_streamer
119 } // namespace stub
120 } // namespace analytics
121 } // namespace vms_server_plugins
122 } // namespace nx
Definition: json.cpp:80
Definition: uuid.h:22
Definition: apple_utils.h:6
Definition: rect.h:9