11bool GstreamerJsonFactory::openConnection() {
12 if (ofile.is_open()) {
18 ofile.open(filename(), std::ios::out | std::ios::trunc);
20 if (!ofile.is_open() || !ofile) {
25 log->
info(1, SFUNCTION_NAME,
"GstreamerJsonFactory: opened file " + filename());
29 is_file_initialized =
false;
30 wrote_first_top_level_entry =
false;
31 top_level_type.clear();
36bool GstreamerJsonFactory::closeConnectionImpl() {
40 closeTopLevelObjectIfNeeded();
42 if (ofile.is_open()) ofile.close();
43 if (ofile.is_open()) {
47 log->
info(1, SFUNCTION_NAME,
"GstreamerJsonFactory: closed file " + filename());
52void GstreamerJsonFactory::ensureFileInitializedForType(
const std::string& type) {
53 if (is_file_initialized)
return;
55 top_level_type = type;
62 ofile <<
" \"type\": \"" << jsonEscape(type) <<
"\",\n";
64 if (type ==
"event") {
65 ofile <<
" \"events\": [\n";
68 ofile <<
" \"frames\": [\n";
71 is_file_initialized =
true;
72 wrote_first_top_level_entry =
false;
75void GstreamerJsonFactory::writeTopLevelEntry(
const std::string& entry_json) {
77 if (!is_file_initialized) {
83 if (wrote_first_top_level_entry) {
86 wrote_first_top_level_entry =
true;
89 ofile <<
" " << entry_json;
92void GstreamerJsonFactory::closeTopLevelObjectIfNeeded() {
93 if (!is_file_initialized)
return;
98 is_file_initialized =
false;
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Shared constants and error codes for the gstreamer module.
#define ERR_CANTCLOSEOUTPUT
Output medium could not be closed cleanly.
#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.