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 13, 2025
1 parent 3c19aa4 commit 7cc4ef3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/webrtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ 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();
}
xTaskCreateStaticPinnedToCore(oai_send_audio_task, "audio_publisher", stack_size,
NULL, 7, stack_memory, &task_buffer, 0);
xTaskCreateStaticPinnedToCore(oai_send_audio_task, "audio_publisher",
stack_size, NULL, 7, stack_memory,
&task_buffer, 0);
#endif
}
}
Expand Down

0 comments on commit 7cc4ef3

Please sign in to comment.