瀏覽代碼

gofmt project

Vladimir Vivien 3 年之前
父節點
當前提交
a5c5263141

+ 2 - 0
README.md

@@ -1,3 +1,5 @@
+[![Go Report Card](https://goreportcard.com/badge/github.com/vladimirvivien/go4vl)](https://goreportcard.com/report/github.com/vladimirvivien/go4vl)
+
 # go4vl
 A Go library for the `Video for Linux 2`  (v4l2) user API.
 

+ 5 - 7
device/device.go

@@ -21,7 +21,7 @@ type Device struct {
 	buffers      [][]byte
 	requestedBuf v4l2.RequestBuffers
 	streaming    bool
-	output chan []byte
+	output       chan []byte
 }
 
 // Open creates opens the underlying device at specified path for streaming.
@@ -108,7 +108,6 @@ func Open(path string, options ...Option) (*Device, error) {
 		}
 	}
 
-
 	return dev, nil
 }
 
@@ -321,7 +320,7 @@ func (d *Device) GetMediaInfo() (v4l2.MediaDeviceInfo, error) {
 	return v4l2.GetMediaDeviceInfo(d.fd)
 }
 
-func (d *Device) Start(ctx context.Context)  error {
+func (d *Device) Start(ctx context.Context) error {
 	if ctx.Err() != nil {
 		return ctx.Err()
 	}
@@ -383,7 +382,6 @@ func (d *Device) startStreamLoop(ctx context.Context) error {
 		return fmt.Errorf("stream loop: stream on: %w", err)
 	}
 
-
 	go func() {
 		defer close(d.output)
 
@@ -396,12 +394,12 @@ func (d *Device) startStreamLoop(ctx context.Context) error {
 			// handle stream capture (read from driver)
 			case <-v4l2.WaitForRead(d):
 				//TODO add better error-handling, for now just panic
-				buff, err  := v4l2.CaptureBuffer(fd, ioMemType, bufType)
+				buff, err := v4l2.CaptureBuffer(fd, ioMemType, bufType)
 				if err != nil {
 					panic(fmt.Errorf("stream loop: capture buffer: %s", err).Error())
 				}
 
-				d.output <-d.Buffers()[buff.Index][:buff.BytesUsed]
+				d.output <- d.Buffers()[buff.Index][:buff.BytesUsed]
 
 			case <-ctx.Done():
 				d.Stop()
@@ -411,4 +409,4 @@ func (d *Device) startStreamLoop(ctx context.Context) error {
 	}()
 
 	return nil
-}
+}

+ 5 - 5
device/device_config.go

@@ -5,11 +5,11 @@ import (
 )
 
 type config struct {
-	ioType v4l2.IOType
+	ioType    v4l2.IOType
 	pixFormat v4l2.PixFormat
-	bufSize uint32
-	fps uint32
-	bufType uint32
+	bufSize   uint32
+	fps       uint32
+	bufType   uint32
 }
 
 type Option func(*config)
@@ -48,4 +48,4 @@ func WithVideoOutputEnabled() Option {
 	return func(o *config) {
 		o.bufType = v4l2.BufTypeVideoOutput
 	}
-}
+}

+ 1 - 1
device/doc.go

@@ -1,2 +1,2 @@
 // Package device provides a device abstraction that supports video streaming.
-package device
+package device

+ 2 - 2
device/list.go

@@ -52,5 +52,5 @@ func GetAllDevicePaths() ([]string, error) {
 			result = append(result, dev)
 		}
 	}
-	return result,  nil
-}
+	return result, nil
+}

+ 1 - 1
device/list_test.go

@@ -4,7 +4,7 @@ import (
 	"testing"
 )
 
-func TestList(t *testing.T){
+func TestList(t *testing.T) {
 	devices, err := GetAllDevicePaths()
 	if err != nil {
 		t.Error(err)

+ 4 - 5
examples/capture1/capture1.go

@@ -31,7 +31,7 @@ func main() {
 	// helper function to search for format descriptions
 	findPreferredFmt := func(fmts []v4l2.FormatDescription, pixEncoding v4l2.FourCCType) *v4l2.FormatDescription {
 		for _, desc := range fmts {
-			if desc.PixelFormat == pixEncoding{
+			if desc.PixelFormat == pixEncoding {
 				return &desc
 			}
 		}
@@ -40,14 +40,14 @@ func main() {
 
 	// get supported format descriptions
 	fmtDescs, err := device.GetFormatDescriptions()
-	if err != nil{
+	if err != nil {
 		log.Fatal("failed to get format desc:", err)
 	}
 
 	// search for preferred formats
 	preferredFmts := []v4l2.FourCCType{v4l2.PixelFmtMPEG, v4l2.PixelFmtMJPEG, v4l2.PixelFmtJPEG, v4l2.PixelFmtYUYV}
 	var fmtDesc *v4l2.FormatDescription
-	for _, preferredFmt := range preferredFmts{
+	for _, preferredFmt := range preferredFmts {
 		fmtDesc = findPreferredFmt(fmtDescs, preferredFmt)
 		if fmtDesc != nil {
 			break
@@ -60,7 +60,7 @@ func main() {
 	}
 	log.Printf("Found preferred fmt: %s", fmtDesc)
 	frameSizes, err := v4l2.GetFormatFrameSizes(device.Fd(), fmtDesc.PixelFormat)
-	if err!=nil{
+	if err != nil {
 		log.Fatalf("failed to get framesize info: %s", err)
 	}
 
@@ -100,7 +100,6 @@ func main() {
 		log.Fatalf("failed to stream: %s", err)
 	}
 
-
 	// process frames from capture channel
 	totalFrames := 10
 	count := 0

+ 3 - 3
examples/cgo_types/cgo_capture.go

@@ -78,7 +78,7 @@ func setFormat(fd uintptr, pixFmt PixFormat) error {
 	return nil
 }
 
-func getFormat(fd uintptr) (PixFormat, error){
+func getFormat(fd uintptr) (PixFormat, error) {
 	var v4l2Fmt C.struct_v4l2_format
 	v4l2Fmt._type = C.uint(BufTypeVideoCapture)
 
@@ -88,7 +88,7 @@ func getFormat(fd uintptr) (PixFormat, error){
 	}
 
 	var pixFmt PixFormat
-	*(*C.struct_v4l2_pix_format)(unsafe.Pointer(&pixFmt))= *(*C.struct_v4l2_pix_format)(unsafe.Pointer(&v4l2Fmt.fmt[0]))
+	*(*C.struct_v4l2_pix_format)(unsafe.Pointer(&pixFmt)) = *(*C.struct_v4l2_pix_format)(unsafe.Pointer(&v4l2Fmt.fmt[0]))
 
 	return pixFmt, nil
 
@@ -99,7 +99,7 @@ func getFormat(fd uintptr) (PixFormat, error){
 // Memory buffer types
 // https://elixir.bootlin.com/linux/v5.13-rc6/source/include/uapi/linux/videodev2.h#L188
 const (
-	StreamMemoryTypeMMAP    uint32 = C.V4L2_MEMORY_MMAP
+	StreamMemoryTypeMMAP uint32 = C.V4L2_MEMORY_MMAP
 )
 
 // reqBuffers requests that the device allocates a `count`

+ 0 - 1
examples/device_info/devinfo.go

@@ -266,7 +266,6 @@ func printCaptureParam(dev *device2.Device) error {
 	return nil
 }
 
-
 func printOutputParam(dev *device2.Device) error {
 	params, err := dev.GetStreamParam()
 	if err != nil {

+ 2 - 2
examples/format/devfmt.go

@@ -55,7 +55,7 @@ func main() {
 	log.Printf("current frame rate: %d fps", fps)
 	// update fps
 	if fps < 30 {
-		if err := device.SetFrameRate(30); err != nil{
+		if err := device.SetFrameRate(30); err != nil {
 			log.Fatalf("failed to set frame rate: %s", err)
 		}
 	}
@@ -64,4 +64,4 @@ func main() {
 		log.Fatalf("failed to get fps: %s", err)
 	}
 	log.Printf("updated frame rate: %d fps", fps)
-}
+}

+ 11 - 11
v4l2/capability.go

@@ -107,7 +107,7 @@ type Capability struct {
 	Card string
 
 	// BusInfo is the name of the device bus
-	BusInfo string 
+	BusInfo string
 
 	// Version is the kernel version
 	Version uint32
@@ -116,7 +116,7 @@ type Capability struct {
 	Capabilities uint32
 
 	// DeviceCapabilities is the capability for this particular (opened) device or node
-	DeviceCapabilities uint32 
+	DeviceCapabilities uint32
 }
 
 // GetCapability retrieves capability info for device
@@ -145,42 +145,42 @@ func (c Capability) GetCapabilities() uint32 {
 
 // IsVideoCaptureSupported returns caps & CapVideoCapture
 func (c Capability) IsVideoCaptureSupported() bool {
-	return c.Capabilities & CapVideoCapture != 0
+	return c.Capabilities&CapVideoCapture != 0
 }
 
 // IsVideoOutputSupported returns caps & CapVideoOutput
 func (c Capability) IsVideoOutputSupported() bool {
-	return c.Capabilities & CapVideoOutput != 0
+	return c.Capabilities&CapVideoOutput != 0
 }
 
 // IsVideoOverlaySupported returns caps & CapVideoOverlay
 func (c Capability) IsVideoOverlaySupported() bool {
-	return c.Capabilities & CapVideoOverlay != 0
+	return c.Capabilities&CapVideoOverlay != 0
 }
 
 // IsVideoOutputOverlaySupported returns caps & CapVideoOutputOverlay
 func (c Capability) IsVideoOutputOverlaySupported() bool {
-	return c.Capabilities & CapVideoOutputOverlay != 0
+	return c.Capabilities&CapVideoOutputOverlay != 0
 }
 
 // IsVideoCaptureMultiplanarSupported returns caps & CapVideoCaptureMPlane
 func (c Capability) IsVideoCaptureMultiplanarSupported() bool {
-	return c.Capabilities & CapVideoCaptureMPlane != 0
+	return c.Capabilities&CapVideoCaptureMPlane != 0
 }
 
 // IsVideoOutputMultiplanerSupported returns caps & CapVideoOutputMPlane
 func (c Capability) IsVideoOutputMultiplanerSupported() bool {
-	return c.Capabilities & CapVideoOutputMPlane != 0
+	return c.Capabilities&CapVideoOutputMPlane != 0
 }
 
 // IsReadWriteSupported returns caps & CapReadWrite
 func (c Capability) IsReadWriteSupported() bool {
-	return c.Capabilities & CapReadWrite != 0
+	return c.Capabilities&CapReadWrite != 0
 }
 
 // IsStreamingSupported returns caps & CapStreaming
 func (c Capability) IsStreamingSupported() bool {
-	return c.Capabilities & CapStreaming != 0
+	return c.Capabilities&CapStreaming != 0
 }
 
 // IsDeviceCapabilitiesProvided returns true if the device returns
@@ -188,7 +188,7 @@ func (c Capability) IsStreamingSupported() bool {
 // See notes on VL42_CAP_DEVICE_CAPS:
 // https://linuxtv.org/downloads/v4l-dvb-apis/userspace-api/v4l/vidioc-querycap.html?highlight=v4l2_cap_device_caps
 func (c Capability) IsDeviceCapabilitiesProvided() bool {
-	return c.Capabilities & CapDeviceCapabilities != 0
+	return c.Capabilities&CapDeviceCapabilities != 0
 }
 
 // GetDriverCapDescriptions return textual descriptions of driver capabilities

+ 3 - 3
v4l2/controls.go

@@ -64,7 +64,7 @@ func GetExtControls(fd uintptr, controls []ExtControl) (ExtControls, error) {
 
 	// prepare control requests
 	var Cctrls []C.struct_v4l2_ext_control
-	for _, control := range controls{
+	for _, control := range controls {
 		var Cctrl C.struct_v4l2_ext_control
 		Cctrl.id = C.uint(control.ID)
 		Cctrl.size = C.uint(control.Size)
@@ -86,7 +86,7 @@ func GetExtControls(fd uintptr, controls []ExtControl) (ExtControls, error) {
 	Cctrls = *(*[]C.struct_v4l2_ext_control)(unsafe.Pointer(&ctrls.controls))
 	for _, Cctrl := range Cctrls {
 		extCtrl := ExtControl{
-			ID: uint32(Cctrl.id),
+			ID:   uint32(Cctrl.id),
 			Size: uint32(Cctrl.size),
 			Ctrl: *(*ExtControlUnion)(unsafe.Pointer(&Cctrl.anon0[0])),
 		}
@@ -94,4 +94,4 @@ func GetExtControls(fd uintptr, controls []ExtControl) (ExtControls, error) {
 	}
 
 	return retCtrls, nil
-}
+}

+ 4 - 4
v4l2/controls_mpeg2.go

@@ -27,8 +27,8 @@ type ControlMPEG2Picture struct {
 // ControlMPEG2Quantization (v4l2_ctrl_mpeg2_quantisation)
 // See https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/v4l2-controls.h#L1972
 type ControlMPEG2Quantization struct {
-	IntraQuantizerMatrix [64]uint8
-	NonIntraQuantizerMatrix [64]uint8
-	ChromaIntraQuantizerMatrix [64]uint8
+	IntraQuantizerMatrix          [64]uint8
+	NonIntraQuantizerMatrix       [64]uint8
+	ChromaIntraQuantizerMatrix    [64]uint8
 	ChromaNonIntraQuantizerMatrix [64]uint8
-}
+}

+ 1 - 2
v4l2/dimension.go

@@ -3,7 +3,7 @@ package v4l2
 // Area (v4l2_area)
 // See https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/videodev2.h#L424
 type Area struct {
-	Width uint32
+	Width  uint32
 	Height uint32
 }
 
@@ -24,4 +24,3 @@ type Rect struct {
 	Width  uint32
 	Height uint32
 }
-

+ 1 - 1
v4l2/format_frameintervals.go

@@ -46,7 +46,7 @@ type FrameInterval struct {
 //	}
 
 // See https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-enum-frameintervals.html
-func getFrameInterval(interval C.struct_v4l2_frmivalenum) (FrameIntervalEnum,error) {
+func getFrameInterval(interval C.struct_v4l2_frmivalenum) (FrameIntervalEnum, error) {
 	frmInterval := FrameIntervalEnum{
 		Index:       uint32(interval.index),
 		Type:        FrameIntervalType(interval._type),

+ 4 - 4
v4l2/format_framesizes.go

@@ -22,10 +22,10 @@ const (
 // https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/videodev2.h#L829
 // https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-enum-framesizes.html
 type FrameSizeEnum struct {
-	Index     uint32
-	Type      FrameSizeType
+	Index       uint32
+	Type        FrameSizeType
 	PixelFormat FourCCType
-	Size      FrameSize
+	Size        FrameSize
 }
 
 // FrameSizeDiscrete (v4l2_frmsize_discrete)
@@ -66,7 +66,7 @@ func getFrameSize(frmSizeEnum C.struct_v4l2_frmsizeenum) FrameSizeEnum {
 		frameSize.Size.MaxHeight = fsDiscrete.Height
 	case FrameSizeTypeStepwise, FrameSizeTypeContinuous:
 		// Calculate pointer to access stepwise member
-		frameSize.Size = *(*FrameSize)(unsafe.Pointer(uintptr(unsafe.Pointer(&frmSizeEnum.anon0[0]))+unsafe.Sizeof(FrameSizeDiscrete{})))
+		frameSize.Size = *(*FrameSize)(unsafe.Pointer(uintptr(unsafe.Pointer(&frmSizeEnum.anon0[0])) + unsafe.Sizeof(FrameSizeDiscrete{})))
 	default:
 	}
 	return frameSize

+ 3 - 3
v4l2/stream_param.go

@@ -24,7 +24,7 @@ const (
 type StreamParam struct {
 	Type    IOType
 	Capture CaptureParam
-	Output OutputParam
+	Output  OutputParam
 }
 
 // CaptureParam (v4l2_captureparm)
@@ -47,7 +47,7 @@ type OutputParam struct {
 	CaptureMode  StreamParamFlag
 	TimePerFrame Fract
 	ExtendedMode uint32
-	WriteBuffers  uint32
+	WriteBuffers uint32
 	_            [4]uint32
 }
 
@@ -88,4 +88,4 @@ func SetStreamParam(fd uintptr, bufType BufType, param StreamParam) error {
 	}
 
 	return nil
-}
+}

+ 1 - 1
v4l2/streaming.go

@@ -186,7 +186,7 @@ func mapMemoryBuffer(fd uintptr, offset int64, len int) ([]byte, error) {
 }
 
 // MapMemoryBuffers creates mapped memory buffers for specified buffer count of device.
-func MapMemoryBuffers(dev StreamingDevice)([][]byte, error) {
+func MapMemoryBuffers(dev StreamingDevice) ([][]byte, error) {
 	bufCount := int(dev.BufferCount())
 	buffers := make([][]byte, bufCount)
 	for i := 0; i < bufCount; i++ {

+ 1 - 1
v4l2/types.go

@@ -36,4 +36,4 @@ type StreamingDevice interface {
 //type OutputDevice interface {
 //	StreamingDevice
 //	StartOutput(context.Context, chan<- []byte) error
-//}
+//}

+ 6 - 6
v4l2/version.go

@@ -8,16 +8,16 @@ type VersionInfo struct {
 	value uint32
 }
 
-func (v VersionInfo) Major() uint32{
+func (v VersionInfo) Major() uint32 {
 	return v.value >> 16
 }
 
-func (v VersionInfo) Minor() uint32{
-	return (v.value>>8)&0xff
+func (v VersionInfo) Minor() uint32 {
+	return (v.value >> 8) & 0xff
 }
 
-func (v VersionInfo) Patch() uint32{
-	return v.value&0xff
+func (v VersionInfo) Patch() uint32 {
+	return v.value & 0xff
 }
 
 // Value returns the raw numeric version value
@@ -27,4 +27,4 @@ func (v VersionInfo) Value() uint32 {
 
 func (v VersionInfo) String() string {
 	return fmt.Sprintf("v%d.%d.%d", v.Major(), v.Minor(), v.Patch())
-}
+}

+ 1 - 1
v4l2/video_info.go

@@ -17,7 +17,7 @@ type InputStatus = uint32
 var (
 	InputStatusNoPower  InputStatus = C.V4L2_IN_ST_NO_POWER
 	InputStatusNoSignal InputStatus = C.V4L2_IN_ST_NO_SIGNAL
-	InputStatusNoColor  InputStatus  = C.V4L2_IN_ST_NO_COLOR
+	InputStatusNoColor  InputStatus = C.V4L2_IN_ST_NO_COLOR
 )
 
 var InputStatuses = map[InputStatus]string{