27 bool withPts =
false, uint32_t pts = 0) {
39 outLen_ = (len / srcPairBytes_) * 4;
49 size_t fill(uint8_t *buf,
size_t maxLen) {
50 if (!active_)
return 0;
52 if (maxLen <= (
size_t)hdr + 4)
return 0;
53 size_t space = maxLen - hdr;
54 size_t remaining = outLen_ - pos_;
56 if (srcPairBytes_ == 0) {
57 n = remaining < space ? remaining : space;
58 memcpy(buf + hdr, data_ + pos_, n);
61 n = remaining < space ? remaining : space;
62 const uint8_t *src = data_ + (pos_ / 4) * srcPairBytes_;
66 const bool last = pos_ >= outLen_;
71 if (last) active_ =
false;
76 bool active()
const {
return active_; }
78 void abort() { active_ =
false; }
83 const uint8_t *data_ =
nullptr;
87 uint8_t srcPairBytes_ = 0;
89 bool withPts_ =
false;
Conversion of raw pixel formats to YUY2 (YUV 4:2:2, Y0 U Y1 V), pixel pair by pixel pair,...
USB Video Class 1.1 constants and the basic TinyUVC data types.
static void toYUY2(PixelFormat fmt, const uint8_t *src, uint8_t *dst, size_t pairs)
Definition UVCConvert.h:18
Produces the UVC payloads of one frame. Each payload starts with a 2 byte header (6 bytes with a pres...
Definition UVCPayload.h:21
bool active() const
true while the frame still has data to send
Definition UVCPayload.h:76
void abort()
Aborts the current frame.
Definition UVCPayload.h:78
size_t fill(uint8_t *buf, size_t maxLen)
Definition UVCPayload.h:49
size_t outputLength() const
Size of the frame data as it is sent (after any conversion)
Definition UVCPayload.h:80
void begin(const uint8_t *data, size_t len, PixelFormat fmt, bool fid, bool withPts=false, uint32_t pts=0)
Definition UVCPayload.h:26
uint8_t headerLength() const
Header length in bytes.
Definition UVCPayload.h:45
void put32(uint8_t *p, uint32_t v)
Definition UVCDefs.h:229
constexpr uint8_t HDR_EOF
Definition UVCDefs.h:62
constexpr uint8_t HDR_EOH
Definition UVCDefs.h:67
constexpr uint8_t HDR_PTS
Definition UVCDefs.h:63
constexpr uint8_t HDR_FID
Definition UVCDefs.h:61
TinyUVC: USB Video Class (UVC) device for Arduino and the desktop.
constexpr uint8_t bytesPerPixel(PixelFormat fmt)
Bytes per pixel of a raw pixel format (0 for JPEG)
Definition UVCDefs.h:103
PixelFormat
Pixel format of the frame data handed to UVCDevice::writeFrame(). MJPEG (a JPEG image) is sent as is....
Definition UVCDefs.h:92
@ MJPEG
one complete JPEG image (for UVCFormat::MJPEG)
@ YUY2
packed YUV 4:2:2, byte order Y0 U Y1 V