uvc

package module
v0.0.0-...-b9a5b96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

github.com/kevmo314/go-uvc

An almost-pure-Go library for accessing UVC devices. The library currently depends on libusb via cgo but not libuvc. One day this may change but libusb is much more complex.

The non-Go equivalent of this library is libuvc.

image

Features

  • UVC 1.5 support
    • Input terminals (recording from cameras)
    • Output terminals (displaying images on a device)
  • Isochronous and bulk transfer support
  • Android support
  • Video decoding API
  • Camera controls
  • UAC Audio support

Demo

go-uvc includes a debugging tool (the screenshot above) to connect to and debug cameras. To use it,

go run github.com/kevmo314/go-uvc/cmd/inspect -path /dev/bus/usb/001/002

Usage

A minimal example of how you might use go-uvc.

package main

import (
	"image/jpeg"
	"fmt"
	"log"
	"syscall"

	"github.com/kevmo314/go-uvc"
	"github.com/kevmo314/go-uvc/pkg/descriptors"
)

func main() {
	fd, err := syscall.Open("/dev/bus/usb/001/002", syscall.O_RDWR, 0)
	if err != nil {
		panic(err)
	}

	ctx, err := uvc.NewUVCDevice(uintptr(fd))
	if err != nil {
		panic(err)
	}

	info, err := ctx.DeviceInfo()
	if err != nil {
		panic(err)
	}

	for _, iface := range info.StreamingInterfaces {
		for i, desc := range iface.Descriptors {
			fd, ok := desc.(*descriptors.MJPEGFormatDescriptor)
			if !ok {
				continue
			}
			frd := iface.Descriptors[i+1].(*descriptors.MJPEGFrameDescriptor)

			resp, err := iface.ClaimFrameReader(fd.Index(), frd.Index())
			if err != nil {
   				panic(err)
			}

			for i := 0; ; i++ {
				fr, err := resp.ReadFrame()
				if err != nil {
   					panic(err)
				}
				img, err := jpeg.Decode(fr)
				if err != nil {
					continue
				}
    				// do something with img
			}
		}
	}
}

Documentation

Index

Constants

View Source
const (
	EndpointDescriptorSubtypeUndefined EndpointDescriptorSubtype = 0x00
	EndpointDescriptorSubtypeGeneral                             = 0x01
	EndpointDescriptorSubtypeEndpoint                            = 0x02
	EndpointDescriptorSubtypeInterrupt                           = 0x03
)
View Source
const (
	RequestCodesUndefined RequestCodes = 0x00
	RequestCodesSetCur                 = 0x01
	RequestCodesSetCurAll              = 0x11
	RequestCodesGetCur                 = 0x81
	RequestCodesGetMin                 = 0x82
	RequestCodesGetMax                 = 0x83
	RequestCodesGetRes                 = 0x84
	RequestCodesGetLen                 = 0x85
	RequestCodesGetInfo                = 0x86
	RequestCodesGetDef                 = 0x87
	RequestCodesGetCurAll              = 0x91
	RequestCodesGetMinAll              = 0x92
	RequestCodesGetMaxAll              = 0x93
	RequestCodesGetResAll              = 0x94
	RequestCodesGetDefAll              = 0x97
)
View Source
const (
	InterfaceControlSelectorUndefined               InterfaceControlSelector = 0x00
	InterfaceControlSelectorVideoPowerModeControl                            = 0x01
	InterfaceControlSelectorRequestErrorCodeControl                          = 0x02
)
View Source
const (
	EncodingUnitControlSelectorUndefined                 EncodingUnitControlSelector = 0x00
	EncodingUnitControlSelectorSelectLayerControl                                    = 0x01
	EncodingUnitControlSelectorProfileToolsetControl                                 = 0x02
	EncodingUnitControlSelectorVideoResolutionControl                                = 0x03
	EncodingUnitControlSelectorMinFrameIntervalControl                               = 0x04
	EncodingUnitControlSelectorSliceModeControl                                      = 0x05
	EncodingUnitControlSelectorRateControlModeControl                                = 0x06
	EncodingUnitControlSelectorAverageBitrateControl                                 = 0x07
	EncodingUnitControlSelectorCPBSizeControl                                        = 0x08
	EncodingUnitControlSelectorPeakBitRateControl                                    = 0x09
	EncodingUnitControlSelectorQuantizationParamsControl                             = 0x0A
	EncodingUnitControlSelectorSyncRefFrameControl                                   = 0x0B
	EncodingUnitControlSelectorLTRBufferControl                                      = 0x0C
	EncodingUnitControlSelectorLTRPictureControl                                     = 0x0D
	EncodingUnitControlSelectorLTRValidationControl                                  = 0x0E
	EncodingUnitControlSelectorLevelIDCControl                                       = 0x0F
	EncodingUnitControlSelectorSEIPayloadTypeControl                                 = 0x10
	EncodingUnitControlSelectorQPRangeControl                                        = 0x11
	EncodingUnitControlSelectorPriorityControl                                       = 0x12
	EncodingUnitControlSelectorStartOrStopLayerControl                               = 0x13
	EncodingUnitControlSelectorErrorResiliencyControl                                = 0x14
)

Variables

View Source
var (
	ErrInvalidDescriptor = errors.New("invalid descriptor")
)

Functions

This section is empty.

Types

type CameraTerminal

type CameraTerminal struct {
	CameraDescriptor *descriptors.CameraTerminalDescriptor
	// contains filtered or unexported fields
}

func (*CameraTerminal) Get

func (*CameraTerminal) GetSupportedControls

func (ct *CameraTerminal) GetSupportedControls() []descriptors.CameraTerminalControlDescriptor

func (*CameraTerminal) IsControlRequestSupported

func (ct *CameraTerminal) IsControlRequestSupported(desc descriptors.CameraTerminalControlDescriptor) bool

func (*CameraTerminal) Set

type ControlInterface

type ControlInterface struct {
	CameraTerminal *CameraTerminal
	ProcessingUnit *ProcessingUnit
	Descriptor     descriptors.ControlInterface
}

type DeviceInfo

type DeviceInfo struct {
	ControlInterfaces   []*ControlInterface
	StreamingInterfaces []*transfers.StreamingInterface
	// contains filtered or unexported fields
}

func (*DeviceInfo) Close

func (d *DeviceInfo) Close() error

type EncodingUnitControlSelector

type EncodingUnitControlSelector int

type EndpointDescriptorSubtype

type EndpointDescriptorSubtype int

type ExtensionUnitControlSelector

type ExtensionUnitControlSelector int
const (
	ExtensionUnitControlSelectorUndefined ExtensionUnitControlSelector = 0x00
)

type InterfaceControlSelector

type InterfaceControlSelector int

type ProcessingUnit

type ProcessingUnit struct {
	UnitDescriptor *descriptors.ProcessingUnitDescriptor
	// contains filtered or unexported fields
}

func (*ProcessingUnit) Get

func (*ProcessingUnit) GetSupportedControls

func (pu *ProcessingUnit) GetSupportedControls() []descriptors.ProcessingUnitControlDescriptor

func (*ProcessingUnit) IsControlRequestSupported

func (pu *ProcessingUnit) IsControlRequestSupported(desc descriptors.ProcessingUnitControlDescriptor) bool

func (*ProcessingUnit) Set

type RequestCodes

type RequestCodes int

type SelectorUnitControlSelector

type SelectorUnitControlSelector int
const (
	SelectorUnitControlSelectorUndefined SelectorUnitControlSelector = 0x00
	SelectorUnitInputSelectControl                                   = 0x01
)

type TerminalControlSelector

type TerminalControlSelector int
const (
	TerminalControlSelectorUndefined TerminalControlSelector = 0x00
)

type UVCDevice

type UVCDevice struct {
	// contains filtered or unexported fields
}

func NewUVCDevice

func NewUVCDevice(fd uintptr) (*UVCDevice, error)

func (*UVCDevice) Close

func (d *UVCDevice) Close() error

func (*UVCDevice) DeviceInfo

func (d *UVCDevice) DeviceInfo() (*DeviceInfo, error)

func (*UVCDevice) IsTISCamera

func (d *UVCDevice) IsTISCamera() (bool, error)

Directories

Path Synopsis
cmd
pkg
descriptors
This file implements the descriptors as defined in the UVC spec 1.5, section 3.6.
This file implements the descriptors as defined in the UVC spec 1.5, section 3.6.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL