Skip to content

Commit 3e919b5

Browse files
committed
Use heap_caps_malloc_prefer instead of switching allocator by CONFIG_SPIRAM.
1 parent 5649b50 commit 3e919b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: src/webrtc.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ static void oai_onconnectionstatechange_task(PeerConnectionState state,
3737
#endif
3838
} else if (state == PEER_CONNECTION_CONNECTED) {
3939
#ifndef LINUX_BUILD
40-
#if CONFIG_SPIRAM
4140
constexpr size_t stack_size = 20000;
42-
StackType_t *stack_memory = (StackType_t *)heap_caps_malloc(
43-
20000 * sizeof(StackType_t), MALLOC_CAP_SPIRAM);
44-
#else // CONFIG_SPIRAM
45-
constexpr size_t stack_size = 20000;
46-
StackType_t *stack_memory = (StackType_t *)malloc(stack_size * sizeof(StackType_t));
47-
#endif // CONFIG_SPIRAM
41+
// Allocate the stack memory from the PSRAM if available. Otherwise,
42+
// allocate from the internal memory.
43+
StackType_t *stack_memory = (StackType_t *)heap_caps_malloc_prefer(
44+
stack_size * sizeof(StackType_t), 2,
45+
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT,
46+
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
4847
if (stack_memory == nullptr) {
4948
ESP_LOGE(LOG_TAG, "Failed to allocate stack memory for audio publisher.");
5049
esp_restart();
5150
}
52-
xTaskCreateStaticPinnedToCore(oai_send_audio_task, "audio_publisher", stack_size,
53-
NULL, 7, stack_memory, &task_buffer, 0);
51+
xTaskCreateStaticPinnedToCore(oai_send_audio_task, "audio_publisher",
52+
stack_size, NULL, 7, stack_memory,
53+
&task_buffer, 0);
5454
#endif
5555
}
5656
}

0 commit comments

Comments
 (0)