Skip to content

Commit

Permalink
Don't put facts to OSD queue when OSD is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
seriyps committed Nov 6, 2024
1 parent e7084a3 commit 571b926
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ int main(int argc, char **argv)
{
int ret;
int i, j;
int enable_osd = 0;
int mavlink_thread = 0;
int dvr_autostart = 0;
int print_modelist = 0;
Expand Down
16 changes: 10 additions & 6 deletions src/osd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C" {
using json = nlohmann::json;

struct osd_vars osd_vars;
int enable_osd = 0;

extern uint32_t frames_received;
uint32_t stats_rx_bytes = 0;
Expand Down Expand Up @@ -1486,6 +1487,7 @@ void mk_tags(osd_tag *tags, int n_tags, FactTags *fact_tags) {
}

void publish(Fact fact) {
if (!enable_osd) return;
//SPDLOG_DEBUG("post fact {}({})", fact.getName(), fact.getTags());
{
std::lock_guard<std::mutex> lock(mtx);
Expand All @@ -1507,15 +1509,17 @@ void *osd_batch_init(uint n) {
}
void osd_publish_batch(void *batch) {
std::vector<Fact> *facts = static_cast<std::vector<Fact> *>(batch);
{
std::lock_guard<std::mutex> lock(mtx);
for (Fact fact : *facts) {
// SPDLOG_DEBUG("batch post fact {}({})", fact.getName(), fact.getTags());
fact_queue.push(fact);
if (enable_osd) {
{
std::lock_guard<std::mutex> lock(mtx);
for (Fact fact : *facts) {
// SPDLOG_DEBUG("batch post fact {}({})", fact.getName(), fact.getTags());
fact_queue.push(fact);
}
}
cv.notify_one();
}
delete facts;
cv.notify_one();
};

void osd_add_bool_fact(void *batch, char const *name, osd_tag *tags, int n_tags, bool value) {
Expand Down
2 changes: 1 addition & 1 deletion src/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct osd_vars {
};

extern struct osd_vars osd_vars;
extern int osd_thread_signal;
extern int enable_osd;
extern bool osd_custom_message;
extern pthread_mutex_t osd_mutex;

Expand Down
2 changes: 2 additions & 0 deletions src/osd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ typedef struct {
nlohmann::json config;
} osd_thread_params;

extern int osd_thread_signal;

void *__OSD_THREAD__(void *param);

#endif

0 comments on commit 571b926

Please sign in to comment.