feat: migrate all large MCP server allocations and MP3 buffers to PSRAM (SPIRAM)
This commit is contained in:
@@ -28,6 +28,14 @@ namespace tt::mcp {
|
||||
|
||||
static const auto LOGGER = Logger("McpSystem");
|
||||
|
||||
static void* psram_malloc(size_t size) {
|
||||
void* ptr = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (ptr != nullptr) {
|
||||
return ptr;
|
||||
}
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
#define AUDIO_SAMPLE_RATE 16000
|
||||
#define AUDIO_BITS_PER_SAMPLE 16
|
||||
#define AUDIO_CHUNK_SAMPLES 512
|
||||
@@ -342,7 +350,7 @@ std::string getScreenshotPbmBase64() {
|
||||
size_t header_size = 32;
|
||||
size_t payload_size = row_bytes * state.drawHeight;
|
||||
size_t pbm_size = header_size + payload_size;
|
||||
uint8_t* pbm = (uint8_t*)malloc(pbm_size);
|
||||
uint8_t* pbm = (uint8_t*)psram_malloc(pbm_size);
|
||||
if (pbm == NULL) {
|
||||
return "";
|
||||
}
|
||||
@@ -921,8 +929,8 @@ bool playMp3Memory(const uint8_t* data, size_t size, int volume, std::string& er
|
||||
|
||||
bool success = false;
|
||||
bool decoded_audio = false;
|
||||
mp3dec_t* decoder = (mp3dec_t*)malloc(sizeof(mp3dec_t));
|
||||
mp3d_sample_t* pcm = (mp3d_sample_t*)malloc(
|
||||
mp3dec_t* decoder = (mp3dec_t*)psram_malloc(sizeof(mp3dec_t));
|
||||
mp3d_sample_t* pcm = (mp3d_sample_t*)psram_malloc(
|
||||
MINIMP3_MAX_SAMPLES_PER_FRAME * sizeof(mp3d_sample_t)
|
||||
);
|
||||
int configured_rate = 0;
|
||||
@@ -1000,14 +1008,14 @@ bool playMp3File(const std::string& filename, int volume, std::string& error) {
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t* input = (uint8_t*)malloc(MP3_INPUT_BUFFER_SIZE);
|
||||
uint8_t* input = (uint8_t*)psram_malloc(MP3_INPUT_BUFFER_SIZE);
|
||||
if (input == NULL) {
|
||||
set_error(error, "Out of memory for MP3 decoding");
|
||||
goto done;
|
||||
}
|
||||
|
||||
mp3dec_t* decoder = (mp3dec_t*)malloc(sizeof(mp3dec_t));
|
||||
mp3d_sample_t* pcm = (mp3d_sample_t*)malloc(
|
||||
mp3dec_t* decoder = (mp3dec_t*)psram_malloc(sizeof(mp3dec_t));
|
||||
mp3d_sample_t* pcm = (mp3d_sample_t*)psram_malloc(
|
||||
MINIMP3_MAX_SAMPLES_PER_FRAME * sizeof(mp3d_sample_t)
|
||||
);
|
||||
if (decoder == NULL || pcm == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user