From 885a79f62d804229aba46822590a2a948a5aaf4e Mon Sep 17 00:00:00 2001 From: Martin Koppehel Date: Thu, 1 Apr 2021 17:58:26 +0200 Subject: [PATCH] Add go modules, add possibility to query device caps --- device_cap.go | 45 +++++++++++++++++++++++++++++++++++++++++++-- go.mod | 5 +++++ go.sum | 2 ++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/device_cap.go b/device_cap.go index 44b324f..ed63c96 100644 --- a/device_cap.go +++ b/device_cap.go @@ -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 { @@ -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 +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..523557d --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/reiver/go-v4l2 + +go 1.16 + +require golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a9c9b7f --- /dev/null +++ b/go.sum @@ -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=