Skip to content

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

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

Fix infinite loop when trying to change state of the busy camera#15973
alalek merged 2 commits intoopencv:3.4from
VadimLevin:dev/vlevin/video_capture_inf_loop

Conversation

@VadimLevin
Copy link
Copy Markdown
Contributor

@VadimLevin VadimLevin commented Nov 22, 2019

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.
Copy link
Copy Markdown
Member

@alalek alalek left a comment

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)

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.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Validated 👍

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