|
TinyUVC 0.1.0
Header-only USB Video Class (UVC) device: turn an MCU into a USB webcam
|
USB Video Class (UVC 1.1) device - a USB webcam. More...
#include <UVCDevice.h>

Public Types | |
| using | XferFn = bool(*)(uint8_t ep, uint8_t *buf, uint16_t len) |
| Transfer function: starts an IN transfer, returns false on error. | |
Public Member Functions | |
| UVCDevice ()=default | |
| ~UVCDevice () | |
| UVCDevice (const UVCDevice &)=delete | |
| UVCDevice & | operator= (const UVCDevice &)=delete |
| bool | addResolution (UVCFormat format, uint16_t width, uint16_t height, uint8_t fps, uint32_t maxFrameSize=0) |
| bool | addResolution (UVCFormat format, uint16_t width, uint16_t height, std::initializer_list< uint8_t > fpsList, uint32_t maxFrameSize=0) |
| Adds a resolution with several frame rates; the first is the default. | |
| bool | addResolution (UVCFormat format, uint16_t width, uint16_t height, const uint8_t *fpsList, size_t fpsCount, uint32_t maxFrameSize=0) |
| Adds a resolution with fpsCount frame rates; the first is the default. | |
| void | clearResolutions () |
| Removes all formats/resolutions (before begin()) | |
| void | setName (const char *name) |
| const char * | name () const |
| void | setPayloadSize (uint32_t size) |
| uint32_t | payloadSize () const |
| void | setTimestamps (bool enabled) |
| Adds a presentation time stamp (PTS, microseconds) to every payload. | |
| void | setStreamCallback (void(*cb)(bool streaming, const UVCStreamSettings &settings, void *ref), void *ref=nullptr) |
| bool | begin () |
| void | end () |
| Stops the camera function. | |
| bool | isActive () const |
| true if begin() succeeded | |
| bool | isStreaming () const |
| true while the host is streaming (between commit and stop) | |
| bool | isReady () const |
| bool | isSending () const |
| UVCStreamSettings | settings () const |
| Format, resolution and frame rate the host selected. | |
| uint32_t | streamGeneration () const |
| Incremented whenever the host starts or stops a stream. | |
| bool | writeFrame (const uint8_t *data, size_t len, PixelFormat fmt) |
| Sends a frame. Returns false (and the frame is not sent) if the device is not ready or the frame does not fit the format the host selected: | |
| bool | waitReady (uint32_t timeoutMs) |
| Waits until isReady() (true) or the timeout or end of streaming (false) | |
| uint32_t | framesSent () const |
| Number of frames that were completely sent. | |
| uint32_t | framesDropped () const |
| Number of frames that were rejected or aborted. | |
| const UVCFormatSpec * | formats () const |
| Formats as defined with addResolution() | |
| uint8_t | formatCount () const |
| uint16_t | descriptorLength () const |
| Length of the function descriptors. | |
| uint16_t | buildDescriptor (uint8_t *buf, uint16_t bufLen, uint8_t controlItf, uint8_t endpointIn, uint16_t maxPacketSize, uint8_t stringIndex) |
| uint8_t | controlInterface () const |
| uint8_t | streamingInterface () const |
| uint8_t | endpoint () const |
| void | usbOpened (XferFn xfer, uint16_t maxPacketSize) |
| The host configured the device: the bulk endpoint is open. | |
| void | usbReset () |
| Bus reset / unconfigured. | |
| UVCControlResult | handleControlSetup (const UVCRequest &r, uint8_t *&data, uint16_t &len) |
| Handles the setup stage of a request to our interfaces/endpoint. | |
| bool | handleControlData (const UVCRequest &r, uint16_t len) |
| void | usbTransferComplete (bool ok) |
| A transfer on our endpoint completed. | |
Static Public Member Functions | |
| static UVCDevice *& | instance () |
| The active device. | |
Protected Member Functions | |
| UVCFormatSpec * | findFormat (UVCFormat format) |
| UVCControlResult | stall (uint8_t error) |
| UVCControlResult | reply (const void *src, uint16_t n, const UVCRequest &r, uint8_t *&data, uint16_t &len) |
| UVCControlResult | replyProbe (const UVCProbeCommit &pc, const UVCRequest &r, uint8_t *&data, uint16_t &len) |
| UVCControlResult | handleStandard (const UVCRequest &r, uint8_t *&data, uint16_t &len) |
| UVCProbeCommit | negotiate (const UVCProbeCommit &in) const |
| Validates/completes a probe or commit structure from the host. | |
| UVCProbeCommit | limit (bool max) const |
| GET_MIN / GET_MAX values. | |
| void | startStream (const UVCProbeCommit &pc) |
| void | stopStream () |
| void | finishFrame (bool complete) |
| bool | startTransfer () |
| void | kick () |
| Starts a transfer if none is in flight (callable from any context) | |
Static Protected Member Functions | |
| static uint32_t | effectivePayloadSize (uint32_t requested, uint16_t mps) |
USB Video Class (UVC 1.1) device - a USB webcam.
Declare the formats/resolutions/frame rates you can deliver, call begin(), then hand over frames with writeFrame() whenever isReady():
The frame data must stay valid until isReady() is true again (it is copied payload by payload into the transfer buffer while it is sent). Frames are sent over a bulk endpoint, which all major operating systems support (Linux, Windows, macOS).
Only one UVCDevice can be active.
Transfer function: starts an IN transfer, returns false on error.
|
default |
|
inline |
|
inline |
Adds a resolution with fpsCount frame rates; the first is the default.
|
inline |
Adds a resolution with several frame rates; the first is the default.
|
inline |
Adds a resolution with one frame rate. The format is created on first use; the first resolution of a format is the host's default. maxFrameSize: max bytes of one frame (0 = width * height * 2).
|
inline |
Registers the camera with the USB stack. See the README for the platform specific requirements (USB stack / USB mode menu settings).
|
inline |
Builds the function descriptors and remembers the assigned interface number and endpoint
|
inline |
Removes all formats/resolutions (before begin())
|
inline |
|
inline |
Length of the function descriptors.
|
inlinestaticprotected |
Payload size actually used: a multiple of the max packet size, and at most 32 packets. Linux (uvcvideo) reads bulk endpoints with URBs of at most 32 packets: a full payload that ends inside a URB has no short packet that terminates it, so the next payload would be glued to it.
|
inline |
Stops the camera function.
|
inline |
|
inlineprotected |
|
inline |
|
inline |
Formats as defined with addResolution()
|
inline |
Number of frames that were rejected or aborted.
|
inline |
Number of frames that were completely sent.
|
inline |
Handles the data of a SET request (received into the buffer that handleControlSetup() returned); false = stall
|
inline |
Handles the setup stage of a request to our interfaces/endpoint.
|
inlineprotected |
|
inline |
true if a new frame can be written: streaming and the previous frame was completely handed to the USB stack
|
inline |
true while the device still reads the data passed to writeFrame(): the data must not be changed or freed before this is false
|
inline |
true while the host is streaming (between commit and stop)
|
inlineprotected |
Starts a transfer if none is in flight (callable from any context)
|
inlineprotected |
GET_MIN / GET_MAX values.
|
inlineprotected |
Validates/completes a probe or commit structure from the host.
|
inline |
|
inlineprotected |
|
inlineprotected |
Name shown by the host (function and interface string); the string must stay valid
Size of one payload transfer (see TINYUVC_PAYLOAD_SIZE); call before begin()
|
inline |
Callback invoked from the USB task when the host starts (streaming = true) or stops a stream. Keep it short.
Adds a presentation time stamp (PTS, microseconds) to every payload.
|
inline |
Format, resolution and frame rate the host selected.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
Starts the next transfer if there is something to send; the caller owns inFlight_. Returns false if nothing was started.
|
inlineprotected |
|
inline |
Incremented whenever the host starts or stops a stream.
|
inline |
The host configured the device: the bulk endpoint is open.
|
inline |
Bus reset / unconfigured.
A transfer on our endpoint completed.
Waits until isReady() (true) or the timeout or end of streaming (false)
|
inline |
Sends a frame. Returns false (and the frame is not sent) if the device is not ready or the frame does not fit the format the host selected:
The data must stay valid until isReady() is true again.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |