gstreamer
Loading...
Searching...
No Matches
publishPayload.cc
Go to the documentation of this file.
1// gstreamer
4
5bool GstreamerJsonFactory::publishPayloadImpl(const std::vector<GIntegralPayload*>* payload) {
6 if (!is_building_frame) {
7 log->error(ERR_PUBLISH_ERROR, "publishPayloadImpl called without an active frame in GstreamerJsonFactory");
8 return false;
9 }
10 if (!payload) {
11 log->error(ERR_PUBLISH_ERROR, "payload is null in GstreamerJsonFactory::publishPayloadImpl");
12 return false;
13 }
14
15 // Separate header from payload if header was written.
16 if (current_frame_has_header) current_frame << ", ";
17
18 current_frame << "\"payload\": [";
19
20 bool wrote_first = false;
21 for (const auto* pl : *payload) {
22 if (!pl) continue;
23
24 if (wrote_first) current_frame << ", ";
25 wrote_first = true;
26
27 // Payload is a vector<int>. Encode as JSON array.
28 current_frame << "[";
29 const auto vec = pl->getPayload();
30
31 for (size_t i = 0; i < vec.size(); i++) {
32 current_frame << vec[i];
33 if (i + 1 < vec.size()) current_frame << ", ";
34 }
35 current_frame << "]";
36 }
37
38 current_frame << "]";
39
40 current_frame_has_payload = true;
41 return true;
42}
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
Generic publish-time error (null pointers, invalid state).