Skip to content

Commit

Permalink
libcamera-still: --autofocus-on-capture: add a timeout for AfStateSca…
Browse files Browse the repository at this point in the history
…nning

This avoids lockup in case libcamera's reported AF state skips directly to
Focused or Failed without passing through Scanning for at least one frame.
  • Loading branch information
njhollinghurst authored and naushir committed Dec 1, 2022
1 parent 5a8926a commit 4068771
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/libcamera_still.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static void event_loop(LibcameraStillApp &app)
AF_WAIT_SCANNING,
AF_WAIT_FINISHED
} af_wait_state = AF_WAIT_NONE;
int af_wait_timeout = 0;

for (unsigned int count = 0;; count++)
{
Expand Down Expand Up @@ -248,7 +249,7 @@ static void event_loop(LibcameraStillApp &app)
{
FrameInfo fi(completed_request->metadata);
bool scanning = fi.af_state == libcamera::controls::AfStateScanning;
if (scanning)
if (scanning || (af_wait_state == AF_WAIT_SCANNING && ++af_wait_timeout >= 16))
af_wait_state = AF_WAIT_FINISHED;
else if (af_wait_state == AF_WAIT_FINISHED)
want_capture = true;
Expand All @@ -267,6 +268,7 @@ static void event_loop(LibcameraStillApp &app)
cl.set(libcamera::controls::AfTrigger, libcamera::controls::AfTriggerStart);
app.SetControls(cl);
af_wait_state = AF_WAIT_SCANNING;
af_wait_timeout = 0;
}
else
want_capture = true;
Expand Down

0 comments on commit 4068771

Please sign in to comment.