Skip to content

Fix infinite loop when trying to change state of the busy camera - #15973

Merged
alalek merged 2 commits into
opencv:3.4from
VadimLevin:dev/vlevin/video_capture_inf_loop
Nov 22, 2019
Merged

alalek merged 2 commits into
opencv:3.4from
VadimLevin:dev/vlevin/video_capture_inf_loop

Conversation

@VadimLevin

@VadimLevin VadimLevin commented Nov 22, 2019 •

Copy link
Copy Markdown
Contributor

According to the paragraph about multiple opens of the video device, filehandle becomes the owner of the device only after buffers allocations. Simple call to open does not affect theirs state, so it falls down to capture initialization, which will stuck on palette setup.

resolves #15782

This pullrequest changes

Add finite number of attempts in tryIoctl functions (10 by default).
First function that tries to change state of the camera is VIDIOC_S_FMT and it fails with errno EBUSY.

  - Add finite number of attempts in tryIoctl functions
    10 by default.

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Looks like it is broken since #12893 (OpenCV 3.4.4)

Comment thread modules/videoio/src/cap_v4l.cpp Outdated
form.fmt.pix.height = height;

if (!tryIoctl(VIDIOC_S_FMT, &form))
if (!tryIoctl(VIDIOC_S_FMT, &form, 2))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is about adding parameter to handle "EBUSY" case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will add it as additional argument, before attempts count.
I would like to keep limited attempts to ensure that loop is finite.

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated 👍

@alalek
alalek merged commit 373160c into opencv:3.4 Nov 22, 2019
@alalek alalek mentioned this pull request Nov 22, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
…ure_inf_loop

* Fix infinite loop when trying to change state of the busy camera

  - Add finite number of attempts in tryIoctl functions
    10 by default.

* Introduced new flag for ioctl call to handle EBUSY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants