18#if defined(ARDUINO_ARCH_ESP32)
20#include "esp_heap_caps.h"
21#elif defined(ARDUINO_ARCH_RP2040)
40#if defined(ARDUINO_ARCH_ESP32)
42#elif defined(ARDUINO_ARCH_RP2040) && defined(RP2350_PSRAM_CS)
43 return rp2040.getPSRAMSize() > 0;
52 if (size == 0)
return nullptr;
60 static void free(
void *p) {
67#if defined(ARDUINO_ARCH_ESP32)
68 if (!psramFound())
return nullptr;
69 return (uint8_t *)heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
70#elif defined(ARDUINO_ARCH_RP2040) && defined(RP2350_PSRAM_CS)
71 if (rp2040.getPSRAMSize() == 0)
return nullptr;
72 return (uint8_t *)pmalloc(size);
80#if defined(ARDUINO_ARCH_ESP32)
82 return (uint8_t *)heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
84 return (uint8_t *)malloc(size);
109 if (p ==
nullptr)
return false;
119 const size_t needed =
size_ + len;
124 if (cap < needed) cap = needed;
125 if (cap < 4096) cap = 4096;
A growing byte buffer for one frame, allocated with UVCMemory (so in PSRAM where available)....
Definition UVCMemory.h:95
bool reserve(size_t size)
Makes sure that size bytes fit without a new allocation.
Definition UVCMemory.h:106
~UVCFrameBuffer()
Definition UVCMemory.h:100
UVCMemoryType type_
Definition UVCMemory.h:152
size_t capacity() const
Definition UVCMemory.h:145
void release()
Frees the memory.
Definition UVCMemory.h:136
const uint8_t * data() const
Definition UVCMemory.h:143
size_t capacity_
Definition UVCMemory.h:151
void setMemoryType(UVCMemoryType type)
Definition UVCMemory.h:102
UVCFrameBuffer(const UVCFrameBuffer &)=delete
uint8_t * data_
Definition UVCMemory.h:149
UVCMemoryType memoryType() const
Definition UVCMemory.h:103
size_t size() const
Definition UVCMemory.h:144
UVCFrameBuffer & operator=(const UVCFrameBuffer &)=delete
uint8_t * data()
Definition UVCMemory.h:142
bool append(const uint8_t *data, size_t len)
Appends data; false if no memory is left (the buffer is unchanged)
Definition UVCMemory.h:118
void clear()
Definition UVCMemory.h:133
size_t size_
Definition UVCMemory.h:150
bool empty() const
Definition UVCMemory.h:146
Allocates frame sized buffers in PSRAM or RAM (see UVCMemoryType)
Definition UVCMemory.h:36
static uint8_t * allocPSRAM(size_t size)
Definition UVCMemory.h:66
static uint8_t * allocRAM(size_t size)
Definition UVCMemory.h:79
static bool hasPSRAM()
true if PSRAM is available
Definition UVCMemory.h:39
static uint8_t * alloc(size_t size, UVCMemoryType type=UVCMemoryType::Auto)
Definition UVCMemory.h:51
static void free(void *p)
Definition UVCMemory.h:60
TinyUVC: USB Video Class (UVC) device for Arduino and the desktop.
UVCMemoryType
Definition UVCMemory.h:29
@ RAMOnly
internal RAM only
@ Auto
PSRAM if the board has it, else RAM.
@ PSRAMOnly
PSRAM only: the allocation fails without PSRAM.