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()) {
10 log->error(gstreamer::ERR_CANTOPENOUTPUT, "%1Error: can't access %2", SFUNCTION_NAME, filename());
11 }
12 if (!frameRunData) {
13 log->error(
14 gstreamer::ERR_PUBLISH_ERROR, "frameRunData is null in GstreamerJsonFactory::startStreamImpl");
15 }
16
17 // Ensure the top-level JSON document is initialized for frame output.
18 ensureFileInitializedForType("stream");
19
20 // Reset per-frame assembly state.
21 is_building_frame = true;
22 current_frame.str(std::string());
23 current_frame.clear();
24 current_frame_has_header = false;
25 current_frame_has_payload = false;
26
27 current_frame << "{";
28 return true;
29}
30
31bool GstreamerJsonFactory::endStreamImpl(const GFrameDataCollection* frameRunData) {
32 if (!is_building_frame) {
33 log->error(
35 "endStreamImpl called without an active frame in GstreamerJsonFactory");
36 return false;
37 }
38
39 // Keep the schema predictable even if the caller omitted header or payload publication.
40 if (!current_frame_has_header) {
41 if (current_frame.str().size() > 1) current_frame << ", ";
42 current_frame << "\"header\": {}";
43 }
44 if (!current_frame_has_payload) {
45 if (current_frame.str().size() > 1) current_frame << ", ";
46 current_frame << "\"payload\": []";
47 }
48
49 current_frame << "}";
50
51 writeTopLevelEntry(current_frame.str());
52
53 is_building_frame = false;
54
55 (void)frameRunData;
56 return true;
57}
std::shared_ptr< GLogger > log
Shared constants and error codes for the gstreamer module.
JSON streamer plugin declarations.
constexpr int ERR_PUBLISH_ERROR
Publish sequence encountered invalid state or invalid input data.
constexpr int ERR_CANTOPENOUTPUT
Output medium could not be opened successfully.