From ce459c24ce50d82054926b0eb49b6f9685905f7c Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 12 Jul 2021 17:30:06 +1000 Subject: [PATCH] [host] app: wait for space in the frame queue We must always wait for space in the frame queue so that we do not overwrite memory that is already queued and may be in use by a client. --- host/src/app.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/host/src/app.c b/host/src/app.c index f67f562b..97c61e80 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -146,6 +146,18 @@ static bool sendFrame(void) { CaptureFrame frame = { 0 }; bool repeatFrame = false; + + //wait until there is room in the queue + while(app.state == APP_STATE_RUNNING) + if(lgmpHostQueuePending(app.frameQueue) == LGMP_Q_FRAME_LEN) + { + usleep(1); + continue; + } + + if (app.state != APP_STATE_RUNNING) + return false; + switch(app.iface->waitFrame(&frame, app.maxFrameSize)) { case CAPTURE_RESULT_OK: @@ -249,13 +261,6 @@ static int frameThread(void * opaque) while(app.state == APP_STATE_RUNNING) { - //wait until there is room in the queue - if(lgmpHostQueuePending(app.frameQueue) == LGMP_Q_FRAME_LEN) - { - usleep(1); - continue; - } - if (!sendFrame()) break; }