gstreamer
Loading...
Searching...
No Matches
gstreamerJSONFactory.h
Go to the documentation of this file.
1#pragma once
2
3// gstreamer
4#include "gstreamer.h"
6
7// c++
8#include <fstream>
9#include <sstream>
10#include <string>
11#include <vector>
12
41public:
44
49
50private:
59 bool openConnection() override;
60
66 bool closeConnectionImpl() override;
67
76 bool startEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) override;
77
84 bool endEventImpl(const std::shared_ptr<GEventDataCollection>& event_data) override;
85
92 bool publishEventHeaderImpl(const std::unique_ptr<GEventHeader>& gevent_header) override;
93
101 bool publishEventTrueInfoDataImpl(const std::string& detectorName,
102 const std::vector<const GTrueInfoData*>& trueInfoData) override;
103
111 bool publishEventDigitizedDataImpl(const std::string& detectorName,
112 const std::vector<const GDigitizedData*>& digitizedData) override;
113
120 bool startStreamImpl(const GFrameDataCollection* frameRunData) override;
121
128 bool endStreamImpl(const GFrameDataCollection* frameRunData) override;
129
136 bool publishFrameHeaderImpl(const GFrameHeader* gframeHeader) override;
137
144 bool publishPayloadImpl(const std::vector<GIntegralPayload*>* payload) override;
145
146private:
148 std::ofstream ofile;
149
151 bool is_file_initialized = false;
152
154 bool wrote_first_top_level_entry = false;
155
157 std::string top_level_type;
158
160 bool is_building_event = false;
161
163 std::ostringstream current_event;
164
166 bool current_event_has_header = false;
167
169 bool current_event_has_any_detector = false;
170
172 bool is_building_frame = false;
173
175 std::ostringstream current_frame;
176
178 bool current_frame_has_header = false;
179
181 bool current_frame_has_payload = false;
182
184 std::string timestamp;
185
187 int event_number = -1;
188
190 int thread_id = -1;
191
192private:
198 [[nodiscard]] std::string filename() const override { return gstreamer_definitions.rootname + ".json"; }
199
200private:
201 // Private helper utilities. These remain undocumented by cross-reference on purpose.
202 static std::string jsonEscape(const std::string& s);
203 void ensureFileInitializedForType(const std::string& type);
204 void writeTopLevelEntry(const std::string& entry_json);
205 void closeTopLevelObjectIfNeeded();
206};
Abstract base class for all gstreamer output plugins.
Definition gstreamer.h:77
GStreamer(const std::shared_ptr< GOptions > &g)
Construct the streamer base and initialize module logging.
Definition gstreamer.h:84
GStreamerDefinition gstreamer_definitions
Output definition currently bound to this streamer instance.
Definition gstreamer.h:206
JSON plugin writing structured event or frame output into a single JSON document.
GstreamerJsonFactory(GstreamerJsonFactory &&)=delete
GstreamerJsonFactory(const GstreamerJsonFactory &)=delete
GstreamerJsonFactory & operator=(GstreamerJsonFactory &&)=delete
GstreamerJsonFactory & operator=(const GstreamerJsonFactory &)=delete
Shared constants and error codes for the gstreamer module.
Core streaming interface and helper utilities for the gstreamer module.
std::string rootname
Base output filename without extension, optionally specialized by thread id.