gizhw:v4l2
the Linux backend of gizhw:camera. Video capture devices (V4L2, /dev/videoN): the capability and formats, and streaming through buffers the kernel maps. The ioctl numbers and the layouts are the kernel's (linux/videodev2.h, checked against it). Every call is on a Handle of gizhw:device.
import * as V4l2 from "gizhw:v4l2";Types
Capability
type Capability = { driver: string; card: string; bus: string; version: i64; capabilities: i64; deviceCaps: i64; }A device's capability: its driver and card names, bus, version and capability bits.
driver:stringcard:stringbus:stringversion:i64capabilities:i64deviceCaps:i64
FormatDesc
type FormatDesc = { index: i64; description: string; fourcc: i64; flags: i64; }One format a capture device offers: its index, description, fourcc code, and flags.
index:i64description:stringfourcc:i64flags:i64
Format
type Format = { width: i64; height: i64; fourcc: i64; bytesPerLine: i64; sizeImage: i64; }A capture format: width and height in pixels, fourcc code, bytes per line and the size of one frame.
width:i64height:i64fourcc:i64bytesPerLine:i64sizeImage:i64
Camera
type Camera = { handle: Device.Handle; buffers: Vec<u64>; lengths: Vec<i64>; format: Format; }An open capture stream: the handle, each buffer's mapped address and length, and the format the device set.
handle:M7.Handlebuffers:Vec<u64>lengths:Vec<i64>format:M17.Format
Buffer
type Buffer = { index: i64; bytesUsed: i64; sequence: i64; offset: i64; length: i64; }A buffer the kernel reports: its index, bytes used by the frame, sequence number, and its mapping (offset and length).
index:i64bytesUsed:i64sequence:i64offset:i64length:i64
Functions
parseCapability
function parseCapability(data: bytes): CapabilityThe capability from the reply to VIDIOC_QUERYCAP.
Effects: fail.
fmtDescRequest
function fmtDescRequest(index: i64): bytesThe request for VIDIOC_ENUM_FMT: the format at index of the capture type.
Effects: fail.
parseFmtDesc
function parseFmtDesc(data: bytes): FormatDescThe format the reply to VIDIOC_ENUM_FMT describes.
Effects: fail.
formatRequest
function formatRequest(width: i64, height: i64, fourcc: i64): bytesThe request for VIDIOC_S_FMT: a capture format of the given size and fourcc, fields in no order.
Effects: fail.
parseFormat
function parseFormat(data: bytes): FormatThe format the reply to VIDIOC_S_FMT holds (the driver may change the size it was asked for).
Effects: fail.
requestBuffersRequest
function requestBuffersRequest(count: i64): bytesThe request for VIDIOC_REQBUFS: count mmap buffers of the capture type.
Effects: fail.
parseRequestBuffers
function parseRequestBuffers(data: bytes): i64The number of buffers the driver granted (the reply to VIDIOC_REQBUFS).
Effects: fail.
bufferRequest
function bufferRequest(index: i64): bytesThe request for a buffer: VIDIOC_QUERYBUF fills it, VIDIOC_QBUF and DQBUF use it. index is the buffer.
Effects: fail.
parseBuffer
function parseBuffer(data: bytes): BufferThe buffer from the reply to a buffer request.
Effects: fail.
streamType
function streamType(): bytesThe 4-byte argument of VIDIOC_STREAMON and STREAMOFF: the capture buffer type.
Effects: fail.
capability
function capability(h: Device.Handle): Capability throws stringThe capability of the capture device behind h.
Effects: fail, io.
formats
function formats(h: Device.Handle): Vec<FormatDesc>Every format the capture device offers, in its order.
Effects: fail, io.
setFormat
function setFormat(h: Device.Handle, width: i64, height: i64, fourcc: i64): Format throws stringAsks the device for a capture format; gives the format it set.
Effects: fail, io.
open
function open(sys: System, node: string, width: i64, height: i64, fourcc: i64, count: i64): Camera throws stringThe camera behind node (/dev/videoN): streaming capture at width x height in fourcc, with count mapped
buffers, already queued and streaming. A device that cannot stream capture is an error.
Effects: fail, io.
frame
function frame(cam: Camera): bytes throws stringThe next frame: waits for a filled buffer, copies its bytes out, and queues the buffer again.
Effects: fail, io.
close
function close(cam: Camera): voidStops streaming, unmaps the buffers and closes the device.
Effects: fail, io.
cameras
function cameras(sys: System): Vec<Device.Device> throws IoErrorThe capture devices of the video class (videoN with a node).
Effects: fail, io.