From 7cc4ef34d1ae6b3f694deae21d1c11104e1314db 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 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/webrtc.cpp b/src/webrtc.cpp index e71f17e..cde4c55 100644 --- a/src/webrtc.cpp +++ b/src/webrtc.cpp @@ -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 } }