8bool GstreamerJsonFactory::openConnection() {
15 ofile.open(filename(), std::ios::out | std::ios::trunc);
17 if (!ofile.is_open() || !ofile) {
22 log->
info(0,
"GstreamerJsonFactory: opened file " + filename());
25 is_file_initialized =
false;
26 wrote_first_top_level_entry =
false;
27 top_level_type.clear();
32bool GstreamerJsonFactory::closeConnectionImpl() {
37 closeTopLevelObjectIfNeeded();
39 if (ofile.is_open()) ofile.close();
40 if (ofile.is_open()) {
48void GstreamerJsonFactory::ensureFileInitializedForType(
const std::string& type) {
49 if (is_file_initialized)
return;
51 top_level_type = type;
56 ofile <<
" \"type\": \"" << jsonEscape(type) <<
"\",\n";
58 if (type ==
"event") {
59 ofile <<
" \"events\": [\n";
62 ofile <<
" \"frames\": [\n";
65 is_file_initialized =
true;
66 wrote_first_top_level_entry =
false;
69void GstreamerJsonFactory::writeTopLevelEntry(
const std::string& entry_json) {
71 if (!is_file_initialized) {
77 if (wrote_first_top_level_entry) {
80 wrote_first_top_level_entry =
true;
83 ofile <<
" " << entry_json;
86void GstreamerJsonFactory::closeTopLevelObjectIfNeeded() {
87 if (!is_file_initialized)
return;
92 is_file_initialized =
false;
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
void flushEventBuffer()
Flush the internal event buffer, writing all buffered events to the output medium.
Shared constants and error codes for the gstreamer module.
#define ERR_CANTCLOSEOUTPUT
Output medium could not be closed cleanly.
#define ERR_PUBLISH_ERROR
Generic publish-time error (null pointers, invalid state).
#define ERR_CANTOPENOUTPUT
Output medium could not be opened (file/device not accessible).