Skip to content

Commit

Permalink
Use flag to indicate new frame arrived
Browse files Browse the repository at this point in the history
  • Loading branch information
peckto committed Apr 18, 2021
1 parent 4daf069 commit e523688
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions deepseg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ typedef struct {
timinginfo_t *pti;
pthread_mutex_t lock_raw;
pthread_mutex_t lock_mask;
pthread_cond_t condition_new_frame;
bool new_frame;
bool running;
} calcinfo_t;

Expand Down Expand Up @@ -212,7 +212,7 @@ void init_tensorflow(calcinfo_t &info) {

info.lock_raw = PTHREAD_MUTEX_INITIALIZER;
info.lock_mask = PTHREAD_MUTEX_INITIALIZER;
info.condition_new_frame = PTHREAD_COND_INITIALIZER;
info.new_frame = false;
info.running = false;

info.raw_next = &info.buf1;
Expand All @@ -223,12 +223,16 @@ void calc_mask(calcinfo_t &info) {
timestamp_t t = timestamp();
cv::Mat *raw_tmp;

// change frame buffer pointer
pthread_mutex_lock(&info.lock_raw);
// wait for new frame to arrive
timestamp_t t0 = timestamp();
pthread_cond_wait(&info.condition_new_frame, &info.lock_raw); // wait for new frame to arrive
while (!info.new_frame) {
usleep(1000);
}
info.pti->ai_condns = diffnanosecs(timestamp(), t0);
t0 = timestamp();
// change frame buffer pointer
pthread_mutex_lock(&info.lock_raw);
info.new_frame = false;
raw_tmp = info.raw_next;
info.raw_next = info.raw_current;
info.raw_current = raw_tmp;
Expand Down Expand Up @@ -525,7 +529,7 @@ int main(int argc, char* argv[]) {
pthread_mutex_lock(&calcinfo.lock_raw);
ti.lockns=timestamp();
*calcinfo.raw_next = raw.clone();
pthread_cond_signal(&calcinfo.condition_new_frame);
calcinfo.new_frame = true;
pthread_mutex_unlock(&calcinfo.lock_raw);
ti.copyns=timestamp();

Expand Down

0 comments on commit e523688

Please sign in to comment.