Skip to content

Add go modules, add possibility to query device caps #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
45 changes: 43 additions & 2 deletions device_cap.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package v4l2

import "errors"

// HasCapability return whether the device has a capability a particular capability.
//
// Example:
//
// device, err := v4l2.Open(v4l2.Video17)
//
//
// // ...
//
//
// hasVideoCaptureCapability, err := device.HasCapability(CapabilityVideoCapture)
func (receiver Device) HasCapability(cap uint32) (bool, error) {
if err := receiver.unfit(); nil != err {
Expand All @@ -33,3 +35,42 @@ func (receiver Device) MustHasCapability(cap uint32) bool {

return datum
}


// HasDeviceCapability return whether the device has a particular device capability.
//
// Example:
//
// device, err := v4l2.Open(v4l2.Video17)
//
// // ...
//
// hasVideoCaptureCapability, err := device.HasDeviceCapability(CapabilityVideoCapture)
func (receiver Device) HasDeviceCapability(cap uint32) (bool, error) {
if hasDeviceCaps, err := receiver.HasCapability(CapabilityDeviceCaps); err != nil {
return false, err
} else if !hasDeviceCaps {
return false, errors.New("No device caps available")
}

has := 0 != (receiver.cap.deviceCaps & cap)
return has, nil
}

// MustHasDeviceCapability return whether the device has a particular device capability.
//
// Example:
//
// device, err := v4l2.Open(v4l2.Video17)
//
// // ...
//
// hasVideoCaptureCapability, err := device.MustHasDeviceCapability(CapabilityVideoCapture)
func (receiver Device) MustHasDeviceCapability(cap uint32) bool {
if hasDeviceCaps := receiver.MustHasCapability(CapabilityDeviceCaps); !hasDeviceCaps {
panic(errors.New("No device caps available"))
}

has := 0 != (receiver.cap.deviceCaps & cap)
return has
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/reiver/go-v4l2

go 1.16

require golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54 h1:rF3Ohx8DRyl8h2zw9qojyLHLhrJpEMgyPOImREEryf0=
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=