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-1729 - change resolution constraints to be of type IntExact #1781

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions components/camera/videosource/webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,19 @@ type WebcamAttrs struct {
}

func makeConstraints(attrs *WebcamAttrs, debug bool, logger golog.Logger) mediadevices.MediaStreamConstraints {
minWidth := 0
maxWidth := 4096
idealWidth := 800
minHeight := 0
maxHeight := 2160
idealHeight := 600

if attrs.Width > 0 {
minWidth = 0
maxWidth = attrs.Width
idealWidth = attrs.Width
}

if attrs.Height > 0 {
minHeight = 0
maxHeight = attrs.Height
idealHeight = attrs.Height
}

return mediadevices.MediaStreamConstraints{
Video: func(constraint *mediadevices.MediaTrackConstraints) {
constraint.Width = prop.IntRanged{minWidth, maxWidth, idealWidth}
constraint.Height = prop.IntRanged{minHeight, maxHeight, idealHeight}
if attrs.Width > 0 {
constraint.Width = prop.IntExact(attrs.Width)
} else {
constraint.Width = prop.IntRanged{Min: 0, Ideal: 640, Max: 4096}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did the ideal width change from 800 to 640? Same question for height changing from 600 to 480.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is more aligned with the "default driver" (first) proposed by v4l for most webcams. Also, in the fitnessDistance algorithm of mediadevices, only min and max will matter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Mediadevices uses Ideal too in its fitnessDistance algorithm. It uses it when comparing one IntRanged to another (see IntRanged.Compare). The fitnessDistance method will compare IntRangeds (a type of IntConstraint) here.

All that being said I don't think it matters too much. This looks LGTM!

}

if attrs.Height > 0 {
constraint.Height = prop.IntExact(attrs.Height)
} else {
constraint.Height = prop.IntRanged{Min: 0, Ideal: 480, Max: 2160}
}
constraint.FrameRate = prop.FloatRanged{0, 200, 60}

if attrs.Format == "" {
Expand Down