Skip to content

Commit

Permalink
[RSDK-1171] - Add error message when requested resolution is not avai…
Browse files Browse the repository at this point in the history
…lable for webcam (#1696)
  • Loading branch information
Rob1in authored Dec 20, 2022
1 parent ded5919 commit 584cf1c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions components/camera/videosource/webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ func tryWebcamOpen(ctx context.Context,
if err != nil {
return nil, err
}

if attrs.Width != 0 && attrs.Height != 0 {
img, release, err := gostream.ReadMedia(ctx, source)
if release != nil {
defer release()
}
if err != nil {
return nil, err
}
if img.Bounds().Dx() != attrs.Width || img.Bounds().Dy() != attrs.Height {
return nil, errors.Errorf("requested width and height (%dx%d) are not available for this webcam"+
" (closest driver found by gostream supports resolution %dx%d)",
attrs.Width, attrs.Height, img.Bounds().Dx(), img.Bounds().Dy())
}
}
return makeCameraFromSource(ctx, source, attrs)
}

Expand Down

0 comments on commit 584cf1c

Please sign in to comment.