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

TinyGPU DisplayDriver that sends the written surfaces as webcam frames to the USB host: uncompressed (YUY2), or compressed with TinyJPEG (MJPEG) - whichever format the host selected. More...

#include <TinyGPU.h>

Inheritance diagram for tinyuvc::UVCDisplayDriver< RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for tinyuvc::UVCDisplayDriver< RGB_T >:
Collaboration graph
[legend]

Classes

struct  JpegSink
 Output of fmt2jpg_cb() into a frame buffer. More...
 
struct  Size
 A resolution with the max frame size reported to the host. More...
 

Public Member Functions

 UVCDisplayDriver (UVCDevice &uvc)
 
 ~UVCDisplayDriver () override
 
bool addResolution (UVCFormat format, uint16_t width, uint16_t height, std::initializer_list< uint8_t > fps, uint32_t maxJpegSize=0)
 
bool addResolution (UVCFormat format, uint16_t width, uint16_t height, uint8_t fps, uint32_t maxJpegSize=0)
 
bool addResolution (uint16_t width, uint16_t height, uint8_t fps)
 Uncompressed (YUY2) resolution.
 
bool addResolution (uint16_t width, uint16_t height, std::initializer_list< uint8_t > fps)
 
bool begin () override
 Starts the UVC device (if it is not running yet)
 
void end () override
 
void setPacing (bool pacing)
 Wait for the frame interval the host selected (default true)
 
void setTimeout (uint32_t ms)
 How long writeData() waits for the previous frame (default 1000 ms)
 
void setJpegQuality (uint8_t quality)
 JPEG quality 1..100 (default 80)
 
void setMemoryType (UVCMemoryType type)
 Where the frame buffers are allocated (default: PSRAM if available)
 
bool writeData (tinygpu::ISurface< RGB_T > &surface) override
 
bool writeData (tinygpu::ISurface< RGB_T > &surface, size_t x, size_t y) override
 
bool flush ()
 Sends the frame composed with writeData(surface, x, y)
 
size_t width () const override
 
size_t height () const override
 
bool sizeChanged (size_t width, size_t height) const
 true when the host selected a different size than width x height
 
bool isJpeg () const
 true if the host selected MJPEG
 
bool waitSent (uint32_t timeoutMs)
 Waits until the device finished reading the previous frame.
 
uint32_t frames () const
 
uint32_t dropped () const
 
uint32_t mismatched () const
 Surfaces that were rejected because of their size.
 
size_t lastJpegSize () const
 Size of the last JPEG.
 
UVCDevice & device ()
 

Protected Member Functions

Size selected () const
 The resolution the host selected, or the first one.
 
size_t rawBytes () const
 
UVCFrameBuffer * nextBuffer (size_t bytes)
 
bool sendJpeg (const uint8_t *pixels)
 
bool send (UVCFrameBuffer &buf, size_t len, PixelFormat format)
 
bool setAddressWindow (size_t, size_t, size_t, size_t) override
 

Static Protected Member Functions

static constexpr bool useEsp32Jpeg ()
 esp32-camera's encoder: RGB565 only (in TinyGPU's byte order)
 
static size_t jpegSinkWrite (void *arg, size_t index, const void *data, size_t len)
 

Protected Attributes

UVCDevice & uvc_
 
UVCFrameBuffer buffers_ [2]
 frames handed to the device: one is sent while the next is prepared
 
int next_ = 0
 
UVCFrameBuffer work_
 frames composed by partial writes
 
size_t workBytes_ = 0
 size of the frame in work_ (0: none)
 
UVCFrameBuffer swap_
 RGB565 in TinyJPEG's byte order.
 
uint8_t quality_ = 80
 
bool pacing_ = true
 
bool dirty_ = false
 
bool sent_ = false
 
uint32_t timeoutMs_ = 1000
 
uint32_t lastUs_ = 0
 
uint32_t frames_ = 0
 
uint32_t dropped_ = 0
 
uint32_t mismatched_ = 0
 
size_t lastJpegSize_ = 0
 

Detailed Description

template<typename RGB_T = tinygpu::RGB565>
class tinyuvc::UVCDisplayDriver< RGB_T >

TinyGPU DisplayDriver that sends the written surfaces as webcam frames to the USB host: uncompressed (YUY2), or compressed with TinyJPEG (MJPEG) - whichever format the host selected.

The surface is copied (YUY2) or compressed (MJPEG) into a frame buffer, from PSRAM where available (see UVCMemory), so the sketch can render the next frame while the previous one is still being sent. writeData() waits until the device can take a new frame and, with pacing (default), until the frame interval the host selected has passed: the render loop then runs at the frame rate of the webcam.

width()/height() report the resolution the host selected; resize your surface when it changes (see the TinyGPUWireframeWebcam example). Supported color types: RGB565 and RGB888.

Constructor & Destructor Documentation

◆ UVCDisplayDriver()

template<typename RGB_T = tinygpu::RGB565>
tinyuvc::UVCDisplayDriver< RGB_T >::UVCDisplayDriver ( UVCDevice &  uvc)
inlineexplicit

◆ ~UVCDisplayDriver()

template<typename RGB_T = tinygpu::RGB565>
tinyuvc::UVCDisplayDriver< RGB_T >::~UVCDisplayDriver ( )
inlineoverride

Member Function Documentation

◆ addResolution() [1/4]

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::addResolution ( uint16_t  width,
uint16_t  height,
std::initializer_list< uint8_t >  fps 
)
inline

◆ addResolution() [2/4]

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::addResolution ( uint16_t  width,
uint16_t  height,
uint8_t  fps 
)
inline

Uncompressed (YUY2) resolution.

◆ addResolution() [3/4]

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::addResolution ( UVCFormat  format,
uint16_t  width,
uint16_t  height,
std::initializer_list< uint8_t >  fps,
uint32_t  maxJpegSize = 0 
)
inline

Offers a resolution to the host. Call before begin(). MJPEG needs a JPEG encoder (see TINYUVC_HAS_JPEG); maxJpegSize is the biggest JPEG the host has to expect (0: width * height bytes).

◆ addResolution() [4/4]

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::addResolution ( UVCFormat  format,
uint16_t  width,
uint16_t  height,
uint8_t  fps,
uint32_t  maxJpegSize = 0 
)
inline

◆ begin()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::begin ( )
inlineoverride

Starts the UVC device (if it is not running yet)

◆ device()

template<typename RGB_T = tinygpu::RGB565>
UVCDevice & tinyuvc::UVCDisplayDriver< RGB_T >::device ( )
inline

◆ dropped()

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::dropped ( ) const
inline

◆ end()

template<typename RGB_T = tinygpu::RGB565>
void tinyuvc::UVCDisplayDriver< RGB_T >::end ( )
inlineoverride

◆ flush()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::flush ( )
inline

Sends the frame composed with writeData(surface, x, y)

◆ frames()

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::frames ( ) const
inline

◆ height()

template<typename RGB_T = tinygpu::RGB565>
size_t tinyuvc::UVCDisplayDriver< RGB_T >::height ( ) const
inlineoverride

◆ isJpeg()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::isJpeg ( ) const
inline

true if the host selected MJPEG

◆ jpegSinkWrite()

template<typename RGB_T = tinygpu::RGB565>
static size_t tinyuvc::UVCDisplayDriver< RGB_T >::jpegSinkWrite ( void *  arg,
size_t  index,
const void *  data,
size_t  len 
)
inlinestaticprotected

◆ lastJpegSize()

template<typename RGB_T = tinygpu::RGB565>
size_t tinyuvc::UVCDisplayDriver< RGB_T >::lastJpegSize ( ) const
inline

Size of the last JPEG.

◆ mismatched()

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::mismatched ( ) const
inline

Surfaces that were rejected because of their size.

◆ nextBuffer()

template<typename RGB_T = tinygpu::RGB565>
UVCFrameBuffer * tinyuvc::UVCDisplayDriver< RGB_T >::nextBuffer ( size_t  bytes)
inlineprotected

The buffer for the next frame. The device takes a frame only when the previous one is done, so at most the other buffer is still being sent.

◆ rawBytes()

template<typename RGB_T = tinygpu::RGB565>
size_t tinyuvc::UVCDisplayDriver< RGB_T >::rawBytes ( ) const
inlineprotected

◆ selected()

template<typename RGB_T = tinygpu::RGB565>
Size tinyuvc::UVCDisplayDriver< RGB_T >::selected ( ) const
inlineprotected

The resolution the host selected, or the first one.

◆ send()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::send ( UVCFrameBuffer &  buf,
size_t  len,
PixelFormat  format 
)
inlineprotected

◆ sendJpeg()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::sendJpeg ( const uint8_t *  pixels)
inlineprotected

◆ setAddressWindow()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::setAddressWindow ( size_t  ,
size_t  ,
size_t  ,
size_t   
)
inlineoverrideprotected

◆ setJpegQuality()

template<typename RGB_T = tinygpu::RGB565>
void tinyuvc::UVCDisplayDriver< RGB_T >::setJpegQuality ( uint8_t  quality)
inline

JPEG quality 1..100 (default 80)

◆ setMemoryType()

template<typename RGB_T = tinygpu::RGB565>
void tinyuvc::UVCDisplayDriver< RGB_T >::setMemoryType ( UVCMemoryType  type)
inline

Where the frame buffers are allocated (default: PSRAM if available)

◆ setPacing()

template<typename RGB_T = tinygpu::RGB565>
void tinyuvc::UVCDisplayDriver< RGB_T >::setPacing ( bool  pacing)
inline

Wait for the frame interval the host selected (default true)

◆ setTimeout()

template<typename RGB_T = tinygpu::RGB565>
void tinyuvc::UVCDisplayDriver< RGB_T >::setTimeout ( uint32_t  ms)
inline

How long writeData() waits for the previous frame (default 1000 ms)

◆ sizeChanged()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::sizeChanged ( size_t  width,
size_t  height 
) const
inline

true when the host selected a different size than width x height

◆ useEsp32Jpeg()

template<typename RGB_T = tinygpu::RGB565>
static constexpr bool tinyuvc::UVCDisplayDriver< RGB_T >::useEsp32Jpeg ( )
inlinestaticconstexprprotected

esp32-camera's encoder: RGB565 only (in TinyGPU's byte order)

◆ waitSent()

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::waitSent ( uint32_t  timeoutMs)
inline

Waits until the device finished reading the previous frame.

◆ width()

template<typename RGB_T = tinygpu::RGB565>
size_t tinyuvc::UVCDisplayDriver< RGB_T >::width ( ) const
inlineoverride

Width/height selected by the host (the first resolution while the host is not streaming)

◆ writeData() [1/2]

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::writeData ( tinygpu::ISurface< RGB_T > &  surface)
inlineoverride

Sends the surface as the next frame. Returns false if it was not sent: not streaming, the surface size does not match the host's selection, or the previous frame did not finish in time.

◆ writeData() [2/2]

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::writeData ( tinygpu::ISurface< RGB_T > &  surface,
size_t  x,
size_t  y 
)
inlineoverride

Copies the surface into the frame at x/y (e.g. for partial updates of GUI libraries) without sending it: call flush() when the frame is complete.

Member Data Documentation

◆ buffers_

template<typename RGB_T = tinygpu::RGB565>
UVCFrameBuffer tinyuvc::UVCDisplayDriver< RGB_T >::buffers_[2]
protected

frames handed to the device: one is sent while the next is prepared

◆ dirty_

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::dirty_ = false
protected

◆ dropped_

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::dropped_ = 0
protected

◆ frames_

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::frames_ = 0
protected

◆ lastJpegSize_

template<typename RGB_T = tinygpu::RGB565>
size_t tinyuvc::UVCDisplayDriver< RGB_T >::lastJpegSize_ = 0
protected

◆ lastUs_

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::lastUs_ = 0
protected

◆ mismatched_

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::mismatched_ = 0
protected

◆ next_

template<typename RGB_T = tinygpu::RGB565>
int tinyuvc::UVCDisplayDriver< RGB_T >::next_ = 0
protected

◆ pacing_

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::pacing_ = true
protected

◆ quality_

template<typename RGB_T = tinygpu::RGB565>
uint8_t tinyuvc::UVCDisplayDriver< RGB_T >::quality_ = 80
protected

◆ sent_

template<typename RGB_T = tinygpu::RGB565>
bool tinyuvc::UVCDisplayDriver< RGB_T >::sent_ = false
protected

◆ swap_

template<typename RGB_T = tinygpu::RGB565>
UVCFrameBuffer tinyuvc::UVCDisplayDriver< RGB_T >::swap_
protected

RGB565 in TinyJPEG's byte order.

◆ timeoutMs_

template<typename RGB_T = tinygpu::RGB565>
uint32_t tinyuvc::UVCDisplayDriver< RGB_T >::timeoutMs_ = 1000
protected

◆ uvc_

template<typename RGB_T = tinygpu::RGB565>
UVCDevice& tinyuvc::UVCDisplayDriver< RGB_T >::uvc_
protected

◆ work_

template<typename RGB_T = tinygpu::RGB565>
UVCFrameBuffer tinyuvc::UVCDisplayDriver< RGB_T >::work_
protected

frames composed by partial writes

◆ workBytes_

template<typename RGB_T = tinygpu::RGB565>
size_t tinyuvc::UVCDisplayDriver< RGB_T >::workBytes_ = 0
protected

size of the frame in work_ (0: none)


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