Skip to content

Commit

Permalink
Fix that stack memory allocation fails when SPIRAM is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
ciniml committed Dec 25, 2024
1 parent 655d7d8 commit 5649b50
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/webrtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ 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);
xTaskCreateStaticPinnedToCore(oai_send_audio_task, "audio_publisher", 20000,
#else // CONFIG_SPIRAM
constexpr size_t stack_size = 20000;
StackType_t *stack_memory = (StackType_t *)malloc(stack_size * sizeof(StackType_t));
#endif // CONFIG_SPIRAM
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);
#endif
}
Expand Down

0 comments on commit 5649b50

Please sign in to comment.