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 | Protected Attributes | List of all members
tinyuvc::UVCCamera Class Reference

Connects a TinyCamera to a UVCDevice. More...

#include <TinyCamera.h>

Collaboration diagram for tinyuvc::UVCCamera:
Collaboration graph
[legend]

Classes

struct  Size
 A camera frame size offered to the host. More...
 

Public Member Functions

 UVCCamera (UVCDevice &uvc)
 
bool addFrameSize (framesize_t size)
 
void setFps (std::initializer_list< uint8_t > fps)
 
void setFps (uint8_t fps)
 
void setFormats (bool mjpeg, bool yuy2)
 
void setRawPixelFormat (pixformat_t fmt)
 
void setRgb565BigEndian (bool bigEndian)
 
void setMaxJpegSize (uint32_t size)
 Max JPEG size reported to the host (0 = width * height * 2)
 
bool begin (const camera_config_t &config, bool startDevice=true)
 
void end ()
 Stops the camera.
 
bool copy ()
 
tiny_camera::TinyCamera & camera ()
 The camera (e.g. for sensor settings: camera().sensor())
 
uint32_t frames () const
 Number of frames sent.
 

Protected Member Functions

bool configure (framesize_t size, pixformat_t fmt)
 (Re)starts the camera with the frame size and pixel format if needed
 
bool applySettings (const UVCStreamSettings &s)
 
bool toPixelFormat (pixformat_t in, PixelFormat &out) const
 

Protected Attributes

UVCDevice & uvc_
 
tiny_camera::TinyCamera camera_
 
tiny_camera::TinyCameraFrame frame_
 
camera_config_t config_ {}
 
Size sizes_ [6]
 
int sizeCount_ = 0
 
uint8_t fps_ [4] = {}
 
int fpsCount_ = 0
 
bool mjpeg_ = false
 
bool yuy2_ = true
 
bool formatsSet_ = false
 
pixformat_t raw_ = PIXFORMAT_RGB565
 
bool rgb565BE_ = false
 
uint32_t maxJpegSize_ = 0
 
uint32_t generation_ = 0
 
uint32_t lastFrameUs_ = 0
 
bool sentOnce_ = false
 
uint32_t frames_ = 0
 
bool configured_ = false
 
framesize_t curSize_ {}
 
pixformat_t curFormat_ {}
 

Detailed Description

Connects a TinyCamera to a UVCDevice.

Offers MJPEG if the camera config uses PIXFORMAT_JPEG (sensors with a JPEG encoder), otherwise YUY2, which is converted on the fly from the camera's RGB565 (or YUV422 / grayscale) frames. When the host selects a different resolution or format, the camera is reconfigured.

void setup() {
camera_config_t cfg = TinyCamera::defaultConfig();
camera.addFrameSize(FRAMESIZE_QVGA);
camera.addFrameSize(FRAMESIZE_VGA);
camera.begin(cfg); // also starts uvc
}
void loop() { camera.copy(); }
Connects a TinyCamera to a UVCDevice.
Definition TinyCamera.h:37
tiny_camera::TinyCamera & camera()
The camera (e.g. for sensor settings: camera().sensor())
Definition TinyCamera.h:169
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

Constructor & Destructor Documentation

◆ UVCCamera()

tinyuvc::UVCCamera::UVCCamera ( UVCDevice &  uvc)
inlineexplicit

Member Function Documentation

◆ addFrameSize()

bool tinyuvc::UVCCamera::addFrameSize ( framesize_t  size)
inline

Offers an additional frame size (call before begin()). Without any call, the frame size of the camera config is offered.

◆ applySettings()

bool tinyuvc::UVCCamera::applySettings ( const UVCStreamSettings &  s)
inlineprotected

◆ begin()

bool tinyuvc::UVCCamera::begin ( const camera_config_t &  config,
bool  startDevice = true 
)
inline

Starts the camera, determines the offered resolutions (one probe capture per frame size) and starts the UVC device (unless startDevice is false: then call uvc.begin() yourself)

◆ camera()

tiny_camera::TinyCamera & tinyuvc::UVCCamera::camera ( )
inline

The camera (e.g. for sensor settings: camera().sensor())

◆ configure()

bool tinyuvc::UVCCamera::configure ( framesize_t  size,
pixformat_t  fmt 
)
inlineprotected

(Re)starts the camera with the frame size and pixel format if needed

◆ copy()

bool tinyuvc::UVCCamera::copy ( )
inline

Call in loop(): reconfigures the camera when the host (re)starts a stream, and captures and sends a frame when the device is ready and the frame interval selected by the host has passed. Returns true if a frame was sent.

◆ end()

void tinyuvc::UVCCamera::end ( )
inline

Stops the camera.

◆ frames()

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

Number of frames sent.

◆ setFormats()

void tinyuvc::UVCCamera::setFormats ( bool  mjpeg,
bool  yuy2 
)
inline

Selects the formats offered to the host. Default: MJPEG if the camera config uses PIXFORMAT_JPEG, YUY2 otherwise. With both, the camera is restarted when the host switches between them.

◆ setFps() [1/2]

void tinyuvc::UVCCamera::setFps ( std::initializer_list< uint8_t >  fps)
inline

Frame rates offered for every size (call before begin()); the first is the default. Default: 15 fps.

◆ setFps() [2/2]

void tinyuvc::UVCCamera::setFps ( uint8_t  fps)
inline

◆ setMaxJpegSize()

void tinyuvc::UVCCamera::setMaxJpegSize ( uint32_t  size)
inline

Max JPEG size reported to the host (0 = width * height * 2)

◆ setRawPixelFormat()

void tinyuvc::UVCCamera::setRawPixelFormat ( pixformat_t  fmt)
inline

Camera pixel format used for YUY2 streams: PIXFORMAT_RGB565 (default), PIXFORMAT_YUV422 or PIXFORMAT_GRAYSCALE (not on STM32)

◆ setRgb565BigEndian()

void tinyuvc::UVCCamera::setRgb565BigEndian ( bool  bigEndian)
inline

Byte order of RGB565 frames. Default: big endian on ESP32 with esp32-camera, little endian everywhere else.

◆ toPixelFormat()

bool tinyuvc::UVCCamera::toPixelFormat ( pixformat_t  in,
PixelFormat &  out 
) const
inlineprotected

Member Data Documentation

◆ camera_

tiny_camera::TinyCamera tinyuvc::UVCCamera::camera_
protected

◆ config_

camera_config_t tinyuvc::UVCCamera::config_ {}
protected

◆ configured_

bool tinyuvc::UVCCamera::configured_ = false
protected

◆ curFormat_

pixformat_t tinyuvc::UVCCamera::curFormat_ {}
protected

◆ curSize_

framesize_t tinyuvc::UVCCamera::curSize_ {}
protected

◆ formatsSet_

bool tinyuvc::UVCCamera::formatsSet_ = false
protected

◆ fps_

uint8_t tinyuvc::UVCCamera::fps_[4] = {}
protected

◆ fpsCount_

int tinyuvc::UVCCamera::fpsCount_ = 0
protected

◆ frame_

tiny_camera::TinyCameraFrame tinyuvc::UVCCamera::frame_
protected

◆ frames_

uint32_t tinyuvc::UVCCamera::frames_ = 0
protected

◆ generation_

uint32_t tinyuvc::UVCCamera::generation_ = 0
protected

◆ lastFrameUs_

uint32_t tinyuvc::UVCCamera::lastFrameUs_ = 0
protected

◆ maxJpegSize_

uint32_t tinyuvc::UVCCamera::maxJpegSize_ = 0
protected

◆ mjpeg_

bool tinyuvc::UVCCamera::mjpeg_ = false
protected

◆ raw_

pixformat_t tinyuvc::UVCCamera::raw_ = PIXFORMAT_RGB565
protected

◆ rgb565BE_

bool tinyuvc::UVCCamera::rgb565BE_ = false
protected

◆ sentOnce_

bool tinyuvc::UVCCamera::sentOnce_ = false
protected

◆ sizeCount_

int tinyuvc::UVCCamera::sizeCount_ = 0
protected

◆ sizes_

Size tinyuvc::UVCCamera::sizes_[6]
protected

◆ uvc_

UVCDevice& tinyuvc::UVCCamera::uvc_
protected

◆ yuy2_

bool tinyuvc::UVCCamera::yuy2_ = true
protected

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