Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-8858 Add frame_rate to webcam driver #4393

Merged
merged 7 commits into from
Sep 27, 2024

Conversation

jckras
Copy link
Member

@jckras jckras commented Sep 25, 2024

  • Added frame_rate to monitoredWebCam properties
  • Added a test in webcam_test.go to check that frame_rate was assigned properly

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Sep 25, 2024
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

Thank you for adding the tests!

Stretch goal: look at fake camera's and image_file camera's tests and see if we can mock out the stream source to better test some of webcam's code now! I'm okay with not testing stream, there are other APIs like PointCloud that may be easier to mock up.

components/camera/videosource/webcam_test.go Outdated Show resolved Hide resolved
@randhid randhid changed the title RSDK-8858: Add frame_rate to webcam driver RSDK-8858 Add frame_rate to webcam driver Sep 25, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 25, 2024
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

one nit! lgtm!

components/camera/videosource/webcam_test.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 26, 2024
@jckras
Copy link
Member Author

jckras commented Sep 26, 2024

Q: The comment above the Validate function states that it ensures all parts of the config are valid, but the current implementation only checks constraints on the Width and Height fields. Should we also validate the other properties like Format, Path, and FrameRate...or if not why don't we care about them?

@hexbabe
Copy link
Member

hexbabe commented Sep 26, 2024

Q: The comment above the Validate function states that it ensures all parts of the config are valid, but the current implementation only checks constraints on the Width and Height fields. Should we also validate the other properties like Format, Path, and FrameRate...or if not why don't we care about them?

Maybe I'm lacking context but in 99% cases we certainly should

@randhid
Copy link
Member

randhid commented Sep 26, 2024

Q: The comment above the Validate function states that it ensures all parts of the config are valid, but the current implementation only checks constraints on the Width and Height fields. Should we also validate the other properties like Format, Path, and FrameRate...or if not why don't we care about them?

Good question, I believe those checks are done in the constructor, and I do believe we try to use media devices to find the best parameters in the constructor, so we allow you to try to create the camera with fewer configured attributes, @seanavery will know more about how mediadeivces is operating.

@seanavery
Copy link
Member

seanavery commented Sep 26, 2024

Q: The comment above the Validate function states that it ensures all parts of the config are valid, but the current implementation only checks constraints on the Width and Height fields. Should we also validate the other properties like Format, Path, and FrameRate...or if not why don't we care about them?

For format, our mediadevices backend can only parse a certain set of pixel formats. See here.

We also have a hardcoded list of available width/height resolutions in mediadevices. See here.

The mediadevices matcher will attempt to find a driver for the given properties. It is strict, so that if a width/height/format/frame_rate combination is not found then the webcam will fail to initialize.

Copy link
Member

@seanavery seanavery left a comment

Choose a reason for hiding this comment

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

LGTM.

It may be worth adding a simple validation to frame_rate in the Validate function as a part of this PR.

@randhid
Copy link
Member

randhid commented Sep 26, 2024

LGTM.

It may be worth adding a simple validation to frame_rate in the Validate function as a part of this PR.

The only non-breaking validation would be checking if it's less than zero which we should add. If we make something required the user has to know to add it now. Normally I'm okay with doing this on the fly with other components that have lower useage, but webcam is one of the ones on the viam rover fragment and has that scary component count.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 26, 2024
@jckras
Copy link
Member Author

jckras commented Sep 26, 2024

Q: The comment above the Validate function states that it ensures all parts of the config are valid, but the current implementation only checks constraints on the Width and Height fields. Should we also validate the other properties like Format, Path, and FrameRate...or if not why don't we care about them?

For format, our mediadevices backend can only parse a certain set of pixel formats. See here.

We also have a hardcoded list of available width/height resolutions in mediadevices. See here.

The mediadevices matcher will attempt to find a driver for the given properties. It is strict, so that if a width/height/format/frame_rate combination is not found then the webcam will fail to initialize.

Q: The comment above the Validate function states that it ensures all parts of the config are valid, but the current implementation only checks constraints on the Width and Height fields. Should we also validate the other properties like Format, Path, and FrameRate...or if not why don't we care about them?

For format, our mediadevices backend can only parse a certain set of pixel formats. See here.

We also have a hardcoded list of available width/height resolutions in mediadevices. See here.

The mediadevices matcher will attempt to find a driver for the given properties. It is strict, so that if a width/height/format/frame_rate combination is not found then the webcam will fail to initialize.

this might not be the best way to ask this question, but when are those packages being used to validate the properties? I have been clicking through the repo but still don't see where the calls in webcam connect back to those files you linked

nevermind: I see now in makeConstraints

Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

Sorry, now I need the check to change in Validate, in the constructor, it would have been fine to add a less than or equal to zero, but not in Validate

components/camera/videosource/webcam.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Sep 26, 2024
@jckras jckras requested a review from randhid September 26, 2024 20:32
@jckras
Copy link
Member Author

jckras commented Sep 27, 2024

Tested webcam locally with a negative frame rate and got the correct error:
Screenshot 2024-09-27 at 1 21 47 PM

@jckras jckras merged commit 214cdcf into viamrobotics:main Sep 27, 2024
19 checks passed
@jckras jckras deleted the driver_changes branch September 27, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants