TinyUVC 0.1.0
Header-only USB Video Class (UVC) device: turn an MCU into a USB webcam
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
tinyuvc::UVCVideoOutput Class Reference

VideoOutput that sends every frame (write() calls up to flush()) to a UVCDevice. Two frame buffers are used: one is sent while the next one is written. More...

#include <AudioTools.h>

Inheritance diagram for tinyuvc::UVCVideoOutput:
Inheritance graph
[legend]
Collaboration diagram for tinyuvc::UVCVideoOutput:
Collaboration graph
[legend]

Public Member Functions

 UVCVideoOutput (UVCDevice &uvc, PixelFormat format=PixelFormat::MJPEG)
 
void setPixelFormat (PixelFormat format)
 Pixel format of the frames written to this output.
 
PixelFormat pixelFormat () const
 
bool setVideoFormat (audio_tools::VideoFormat format)
 Same with an audio-tools VideoFormat; false if not supported.
 
void setTimeout (uint32_t ms)
 
void setMaxFrameSize (size_t size)
 Max frame size: bigger frames are dropped (default 512 KB)
 
void setMemoryType (UVCMemoryType type)
 
bool reserve (size_t size)
 
void release ()
 
void setPacing (bool pacing)
 
void setFlushOnWrite (bool flushOnWrite)
 Every write() is a complete frame (for writers that never call flush())
 
size_t write (const uint8_t *data, size_t len) override
 
void flush () override
 Completes the frame and hands it to the UVC device.
 
bool hadOutput () const override
 
bool isCompleteJpeg (const uint8_t *data, size_t len) const
 true if data is a whole JPEG image (SOI ... EOI)
 
uint32_t frames () const
 Frames handed to the device / dropped.
 
uint32_t dropped () const
 

Protected Attributes

UVCDevice & uvc_
 
PixelFormat format_
 
UVCFrameBuffer buffers_ [2]
 
int fill_ = 0
 
size_t maxFrameSize_ = 512 * 1024
 
uint32_t timeoutMs_ = 0
 
bool pacing_ = false
 
bool flushOnWrite_ = false
 
bool sent_ = false
 
uint32_t lastUs_ = 0
 
bool overflow_ = false
 
bool hadOutput_ = false
 
uint32_t frames_ = 0
 
uint32_t dropped_ = 0
 

Detailed Description

VideoOutput that sends every frame (write() calls up to flush()) to a UVCDevice. Two frame buffers are used: one is sent while the next one is written.

The frame buffers grow to the size of the biggest frame and are taken from PSRAM where the board has it (see setMemoryType(), reserve()).

Writers that deliver one complete frame per write() without calling flush() (e.g. MJPEGEncoder) are supported as well: a complete JPEG written in one call is sent right away, for other formats use setFlushOnWrite(true).

MJPEGEncoder encoder(out); // RGB565 -> JPEG -> webcam
USB Video Class (UVC 1.1) device - a USB webcam.
Definition UVCDevice.h:95
TinyGPU DisplayDriver that sends the written surfaces as webcam frames to the USB host: uncompressed ...
Definition TinyGPU.h:110
VideoOutput that sends every frame (write() calls up to flush()) to a UVCDevice. Two frame buffers ar...
Definition AudioTools.h:79
@ MJPEG
one complete JPEG image (for UVCFormat::MJPEG)

Constructor & Destructor Documentation

◆ UVCVideoOutput()

tinyuvc::UVCVideoOutput::UVCVideoOutput ( UVCDevice &  uvc,
PixelFormat  format = PixelFormat::MJPEG 
)
inlineexplicit

Member Function Documentation

◆ dropped()

uint32_t tinyuvc::UVCVideoOutput::dropped ( ) const
inline

◆ flush()

void tinyuvc::UVCVideoOutput::flush ( )
inlineoverride

Completes the frame and hands it to the UVC device.

◆ frames()

uint32_t tinyuvc::UVCVideoOutput::frames ( ) const
inline

Frames handed to the device / dropped.

◆ hadOutput()

bool tinyuvc::UVCVideoOutput::hadOutput ( ) const
inlineoverride

◆ isCompleteJpeg()

bool tinyuvc::UVCVideoOutput::isCompleteJpeg ( const uint8_t *  data,
size_t  len 
) const
inline

true if data is a whole JPEG image (SOI ... EOI)

◆ pixelFormat()

PixelFormat tinyuvc::UVCVideoOutput::pixelFormat ( ) const
inline

◆ release()

void tinyuvc::UVCVideoOutput::release ( )
inline

Frees the frame buffers; they are allocated again by the next frame. The frame that is still being sent keeps its buffer.

◆ reserve()

bool tinyuvc::UVCVideoOutput::reserve ( size_t  size)
inline

Allocates both frame buffers for frames of up to size bytes now, instead of growing them with the first frames. False if there is not enough memory.

◆ setFlushOnWrite()

void tinyuvc::UVCVideoOutput::setFlushOnWrite ( bool  flushOnWrite)
inline

Every write() is a complete frame (for writers that never call flush())

◆ setMaxFrameSize()

void tinyuvc::UVCVideoOutput::setMaxFrameSize ( size_t  size)
inline

Max frame size: bigger frames are dropped (default 512 KB)

◆ setMemoryType()

void tinyuvc::UVCVideoOutput::setMemoryType ( UVCMemoryType  type)
inline

Where the two frame buffers are allocated: UVCMemoryType::Auto (default: PSRAM if available, else RAM), PSRAMOnly or RAMOnly. Call it before the first frame or reserve().

◆ setPacing()

void tinyuvc::UVCVideoOutput::setPacing ( bool  pacing)
inline

flush() waits until the frame interval selected by the host has passed since the previous frame: plays files (e.g. from DemuxerAVI) at their frame rate instead of as fast as USB allows. Implies waiting for the device (see setTimeout()).

◆ setPixelFormat()

void tinyuvc::UVCVideoOutput::setPixelFormat ( PixelFormat  format)
inline

Pixel format of the frames written to this output.

◆ setTimeout()

void tinyuvc::UVCVideoOutput::setTimeout ( uint32_t  ms)
inline

How long flush() waits for the previous frame to be sent. 0 (default): drop the frame if the device is busy, which keeps live sources live.

◆ setVideoFormat()

bool tinyuvc::UVCVideoOutput::setVideoFormat ( audio_tools::VideoFormat  format)
inline

Same with an audio-tools VideoFormat; false if not supported.

◆ write()

size_t tinyuvc::UVCVideoOutput::write ( const uint8_t *  data,
size_t  len 
)
inlineoverride

Member Data Documentation

◆ buffers_

UVCFrameBuffer tinyuvc::UVCVideoOutput::buffers_[2]
protected

◆ dropped_

uint32_t tinyuvc::UVCVideoOutput::dropped_ = 0
protected

◆ fill_

int tinyuvc::UVCVideoOutput::fill_ = 0
protected

◆ flushOnWrite_

bool tinyuvc::UVCVideoOutput::flushOnWrite_ = false
protected

◆ format_

PixelFormat tinyuvc::UVCVideoOutput::format_
protected

◆ frames_

uint32_t tinyuvc::UVCVideoOutput::frames_ = 0
protected

◆ hadOutput_

bool tinyuvc::UVCVideoOutput::hadOutput_ = false
protected

◆ lastUs_

uint32_t tinyuvc::UVCVideoOutput::lastUs_ = 0
protected

◆ maxFrameSize_

size_t tinyuvc::UVCVideoOutput::maxFrameSize_ = 512 * 1024
protected

◆ overflow_

bool tinyuvc::UVCVideoOutput::overflow_ = false
protected

◆ pacing_

bool tinyuvc::UVCVideoOutput::pacing_ = false
protected

◆ sent_

bool tinyuvc::UVCVideoOutput::sent_ = false
protected

◆ timeoutMs_

uint32_t tinyuvc::UVCVideoOutput::timeoutMs_ = 0
protected

◆ uvc_

UVCDevice& tinyuvc::UVCVideoOutput::uvc_
protected

The documentation for this class was generated from the following file: