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, SFUNCTION_NAME, "Error: can't access ", filename());
11 }
12 if (!frameRunData) {
14 "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) {
34 "endStreamImpl called without an active frame in GstreamerJsonFactory");
35 return false;
36 }
37
38 // Keep the schema predictable even if the caller omitted header or payload publication.
39 if (!current_frame_has_header) {
40 if (current_frame.str().size() > 1) current_frame << ", ";
41 current_frame << "\"header\": {}";
42 }
43 if (!current_frame_has_payload) {
44 if (current_frame.str().size() > 1) current_frame << ", ";
45 current_frame << "\"payload\": []";
46 }
47
48 current_frame << "}";
49
50 writeTopLevelEntry(current_frame.str());
51
52 is_building_frame = false;
53
54 (void)frameRunData;
55 return true;
56}
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.