Skip to content

Commit

Permalink
Use heap_caps_malloc_prefer instead of switching allocator by CONFIG_…
Browse files Browse the repository at this point in the history
…SPIRAM.
  • Loading branch information
ciniml committed Jan 9, 2025
1 parent 5649b50 commit 1bf974c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/webrtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ static void oai_onconnectionstatechange_task(PeerConnectionState state,
#endif
} else if (state == PEER_CONNECTION_CONNECTED) {
#ifndef LINUX_BUILD
#if CONFIG_SPIRAM
constexpr size_t stack_size = 20000;
StackType_t *stack_memory = (StackType_t *)heap_caps_malloc(
20000 * sizeof(StackType_t), MALLOC_CAP_SPIRAM);
#else // CONFIG_SPIRAM
constexpr size_t stack_size = 20000;
StackType_t *stack_memory = (StackType_t *)malloc(stack_size * sizeof(StackType_t));
#endif // CONFIG_SPIRAM
// Allocate the stack memory from the PSRAM if available. Otherwise, allocate from the internal memory.
StackType_t *stack_memory = (StackType_t *)heap_caps_malloc_prefer(
stack_size * sizeof(StackType_t), 2,
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT,
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (stack_memory == nullptr) {
ESP_LOGE(LOG_TAG, "Failed to allocate stack memory for audio publisher.");
esp_restart();
Expand Down

0 comments on commit 1bf974c

Please sign in to comment.