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();
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) {
79 "JSON file is not initialized in GstreamerJsonFactory::writeTopLevelEntry");
84 if (wrote_first_top_level_entry) {
87 wrote_first_top_level_entry =
true;
90 ofile <<
" " << entry_json;
93void GstreamerJsonFactory::closeTopLevelObjectIfNeeded() {
94 if (!is_file_initialized)
return;
99 is_file_initialized =
false;
std::shared_ptr< GLogger > log
virtual bool closeConnectionImpl()
Plugin-specific close implementation hook.
virtual bool openConnection()
Open the output medium used by this streamer.
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.
constexpr int ERR_CANTCLOSEOUTPUT
Output medium could not be closed cleanly.