v4l

package module
Version: v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: GPL-3.0 Imports: 5 Imported by: 14

README

https://pkg.go.dev/github.com/korandiz/v4l

Documentation

Overview

Package v4l is a facade to the Video4Linux video capture interface.

Index

Constants

View Source
const (
	// Integer controls
	CtrlBrightness            = 0x00980900
	CtrlContrast              = 0x00980901
	CtrlSaturation            = 0x00980902
	CtrlHue                   = 0x00980903
	CtrlGamma                 = 0x00980910
	CtrlExposure              = 0x00980911
	CtrlGain                  = 0x00980913
	CtrlWhiteBalance          = 0x0098091a
	CtrlSharpness             = 0x0098091b
	CtrlBacklightCompensation = 0x0098091c

	// Boolean controls
	CtrlHFlip            = 0x00980914
	CtrlVFlip            = 0x00980915
	CtrlAutoWhiteBalance = 0x0098090c
	CtrlAutoGain         = 0x00980912
	CtrlAutoHue          = 0x00980919
	CtrlAutoBrightness   = 0x00980920

	// Enums
	CtrlPowerLineFreq     = 0x00980918
	PowerLineFreqDisabled = 0
	PowerLineFreq50Hz     = 1
	PowerLineFreq60Hz     = 2
	PowerLineFreqAuto     = 3

	// Buttons
	CtrlDoWhiteBalance = 0x0098090d
)

Control IDs. Devices may have other controls than these, including custom (driver specific) ones.

View Source
const (
	// ErrWrongDevice is returned by Open when attempting to open a file that is
	// not a V4L capture device.
	ErrWrongDevice = Error("not a V4L capture device")

	// ErrUnsupported indicates that an operation failed due to a limitation of
	// this library.
	ErrUnsupported = Error("unsupported device or operation")

	// ErrBufferGone is returned by methods of Buffer when the contents of the
	// buffer is no longer available.
	ErrBufferGone = Error("buffer contents not available")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

A Buffer holds the raw image data of a frame captured from a Device. It implements io.Reader, io.ByteReader, io.ReaderAt, and io.Seeker. A call to Capture, Close, or TurnOff on the corresponding Device may cause the contents of the buffer to go away.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of unread bytes in the buffer. If the data is no longer available, it returns 0.

func (*Buffer) Read

func (b *Buffer) Read(dst []byte) (int, error)

Read reads up to len(dst) bytes into dst, and returns the number of bytes read, along with any error encountered.

func (*Buffer) ReadAt

func (b *Buffer) ReadAt(dst []byte, offset int64) (int, error)

ReadAt reads up to len(dst) bytes into dst starting at the specified offset, and returns the number of bytes read, along with any error encountered. The seek offset is unaffected by ReadAt.

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (byte, error)

ReadByte returns the next byte in the buffer.

func (*Buffer) Seek

func (b *Buffer) Seek(offset int64, whence int) (int64, error)

Seek sets the seek offset.

func (*Buffer) SeqNum

func (b *Buffer) SeqNum() uint32

SeqNum returns the sequence number of the frame in the buffer as reported by the kernel.

func (*Buffer) Size

func (b *Buffer) Size() int64

Size returns the total number of bytes in the buffer. As long as the data is available, the return value is constant and unaffected by calls to the methods of Buffer. If the data is no longer available, it returns 0.

type BufferInfo

type BufferInfo struct {
	// BufferSize is the number of bytes required to hold an image. For variable
	// length compressed formats, it's the maximum size an image may take up.
	BufferSize int

	// ImageStride is the distance in bytes between the leftmost pixels of
	// adjacent lines.
	ImageStride int
}

A BufferInfo provides information about how image data is laid out in a buffer.

type ControlInfo

type ControlInfo struct {
	// CID is the identifier of the control. (e.g. 0x00980900)
	CID uint32

	// Name is the name of the control. (e.g. "Brightness")
	Name string

	// Type tells what kind of control this is. It's one of "int", "bool",
	// "enum", "int-enum", or "button".
	//   - The valid values of an integer control are determined by Min, Max,
	//     and Step.
	//   - A boolean control can only have the values 0 and 1, where 0 means
	//     "disabled" and 1 means "enabled".
	//   - Enums can only take values from a predefined set. The values are
	//     identifiers which select one of a few named options. (see Options)
	//   - An "int-enum" is similar to an enum, except that, the options are
	//     64-bit unsigned integers, rather than strings.
	//   - Buttons perform some action when pushed, and they don't have a value.
	//     Reading the value of a button fails, while setting it to any value is
	//     interpreted as a push.
	Type string

	// Min and Max specify the range of values the control can take, and Step is
	// the smallest change actually affecting the hardware. They are only
	// meaningful for integer type controls.
	Min  int32
	Max  int32
	Step int32

	// Default is the default value of the control.
	Default int32

	// Options is the list of valid values of an enum or int-enum type control.
	// For other types it's nil.
	Options []struct {
		// Value is the identifier of this option. (e.g. 0, 1, 2, etc)
		Value int32

		// Name is the label of this option. Only valid for enum type controls.
		// (e.g. "50 Hz", "60 Hz", "Auto")
		Name string

		// Int64 is the integer value of this option. Only valid for int-enum
		// type controls. (e.g. 0, 333, 667)
		Int64 int64
	}
}

A ControlInfo provides information about a control.

type Device

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

A Device represents a V4L capture device.

func Open

func Open(path string) (*Device, error)

Open opens the capture device named by path. If the file is not a capture device, it fails with ErrWrongDevice.

func (*Device) BufferInfo

func (d *Device) BufferInfo() (BufferInfo, error)

BufferInfo returns information about how image data is laid out in a buffer. For the same device configuration it always returns the same value.

func (*Device) Capture

func (d *Device) Capture() (*Buffer, error)

Capture grabs the next frame, and returns a new Buffer holding the raw image data. The device must be turned on for Capture to succeed. A call to Capture may render the contents of previously captured buffers unavailable.

func (*Device) Close

func (d *Device) Close()

Close closes the device, freeing all native resources associated with it. It stops any capture session in progress, and it may also render the contents of previously captured buffers unavailable.

func (*Device) ControlInfo

func (d *Device) ControlInfo(cid uint32) (ControlInfo, error)

ControlInfo returns information about a control.

func (*Device) DeviceInfo

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

DeviceInfo returns information about the device.

func (*Device) GetConfig

func (d *Device) GetConfig() (DeviceConfig, error)

GetConfig returns the current configuration of the device.

func (*Device) GetControl

func (d *Device) GetControl(cid uint32) (int32, error)

GetControl returns the current value of a control.

func (*Device) ListConfigs

func (d *Device) ListConfigs() ([]DeviceConfig, error)

ListConfigs returns the configurations supported by the device.

func (*Device) ListControls

func (d *Device) ListControls() ([]ControlInfo, error)

ListControls returns the ControlInfo for every control the device has.

func (*Device) SetConfig

func (d *Device) SetConfig(cfg DeviceConfig) error

SetConfig configures the device according to cfg. The configuration actually applied may be different from what was requested, as drivers are allowed to adjust the parameters against hardware capabilities (or even completely ignore them). The configuration cannot be changed while the device is turned on.

func (*Device) SetControl

func (d *Device) SetControl(cid uint32, value int32) error

SetControl sets the value of a control.

func (*Device) TurnOff

func (d *Device) TurnOff()

TurnOff ends the capture session in progress. It does not close the device, so it can be reused for another session.

func (*Device) TurnOn

func (d *Device) TurnOn() error

TurnOn initiates a capture session with the device. It may fail with ErrUnsupported. While the device is turned on, its configuration cannot be changed.

type DeviceConfig

type DeviceConfig struct {
	// Format is the four-character code (FourCC) of the pixel format, with the
	// first character at the lowest byte.
	Format uint32

	// Width and Height specify the image dimensions.
	Width  int
	Height int

	// FPS specifies the frame rate.
	FPS Frac
}

A DeviceConfig encapsulates the configuration of a capture device.

type DeviceInfo

type DeviceInfo struct {
	// Path is the device path. (e.g. /dev/video0)
	Path string

	// DeviceName is the name of the device. (e.g. "Yoyodyne TV/FM")
	DeviceName string

	// BusInfo is the location of the device in the system.
	// (e.g. "PCI:0000:05:06.0")
	BusInfo string

	// DriverName is the name of the driver. (e.g. "bttv")
	DriverName string

	// DriverVersion contains the three components of the driver's version
	// number. (e.g. [3]int{1, 2, 3} for version 1.2.3)
	DriverVersion [3]int

	// Camera tells if the device is a camera. If false, then this is some other
	// kind of capture device, e.g. an analog TV tuner.
	Camera bool
}

A DeviceInfo provides information about a capture device.

func FindDevices

func FindDevices() []DeviceInfo

FindDevices returns the DeviceInfo for every capture device found in the system. The paths are always returned in absolute form.

type Error

type Error string

An Error is simply an error message.

func (Error) Error

func (e Error) Error() string

Error returns e as a string.

type Frac

type Frac struct {
	N uint32
	D uint32
}

A Frac represents the fractional number N/D.

func (Frac) Cmp

func (f Frac) Cmp(g Frac) int

Cmp returns -1, 0, or 1 if f is less then, equal to, or greater than g, respectively.

func (Frac) Reduce

func (f Frac) Reduce() Frac

Reduce returns f reduced to lowest terms.

Directories

Path Synopsis
demos
streamcam Module
viewcam Module
fmt
mjpeg
Package mjpeg just defines the FourCC of the MJPEG format.
Package mjpeg just defines the FourCC of the MJPEG format.
yuyv
Package yuyv provides support for the YUYV format.
Package yuyv provides support for the YUYV format.

Jump to

Keyboard shortcuts

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