gstreamer
Loading...
Searching...
No Matches
stream.cc
Go to the documentation of this file.
1// gstreamer
4
5// Implementation summary:
6// Assemble one frame JSON object incrementally across the frame publish sequence.
7
8bool GstreamerJsonFactory::startStreamImpl(const GFrameDataCollection* frameRunData) {
9 if (!ofile.is_open()) { log->error(ERR_CANTOPENOUTPUT, SFUNCTION_NAME, "Error: can't access ", filename()); }
10 if (!frameRunData) { log->error(ERR_PUBLISH_ERROR, "frameRunData is null in GstreamerJsonFactory::startStreamImpl"); }
11
12 // Ensure the top-level JSON document is initialized for frame output.
13 ensureFileInitializedForType("stream");
14
15 // Reset per-frame assembly state.
16 is_building_frame = true;
17 current_frame.str(std::string());
18 current_frame.clear();
19 current_frame_has_header = false;
20 current_frame_has_payload = false;
21
22 current_frame << "{";
23 return true;
24}
25
26bool GstreamerJsonFactory::endStreamImpl(const GFrameDataCollection* frameRunData) {
27 if (!is_building_frame) {
28 log->error(ERR_PUBLISH_ERROR, "endStreamImpl called without an active frame in GstreamerJsonFactory");
29 return false;
30 }
31
32 // Keep the schema predictable even if the caller omitted header or payload publication.
33 if (!current_frame_has_header) {
34 if (current_frame.str().size() > 1) current_frame << ", ";
35 current_frame << "\"header\": {}";
36 }
37 if (!current_frame_has_payload) {
38 if (current_frame.str().size() > 1) current_frame << ", ";
39 current_frame << "\"payload\": []";
40 }
41
42 current_frame << "}";
43
44 writeTopLevelEntry(current_frame.str());
45
46 is_building_frame = false;
47
48 (void)frameRunData;
49 return true;
50}
std::shared_ptr< GLogger > log
void error(int exit_code, Args &&... args) const
Shared constants and error codes for the gstreamer module.
#define ERR_PUBLISH_ERROR
Publish sequence encountered invalid state or invalid input data.
#define ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.
JSON streamer plugin declarations.