From 1bf974cef0175718417dd180ac335ba21ac0a74f Mon Sep 17 00:00:00 2001 From: Kenta IDA Date: Fri, 10 Jan 2025 06:59:30 +0900 Subject: [PATCH] Use heap_caps_malloc_prefer instead of switching allocator by CONFIG_SPIRAM. --- src/webrtc.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/webrtc.cpp b/src/webrtc.cpp index adde06c..94d9069 100644 --- a/src/webrtc.cpp +++ b/src/webrtc.cpp @@ -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();