@@ -37,20 +37,20 @@ static void oai_onconnectionstatechange_task(PeerConnectionState state,
37
37
#endif
38
38
} else if (state == PEER_CONNECTION_CONNECTED) {
39
39
#ifndef LINUX_BUILD
40
- #if CONFIG_SPIRAM
41
40
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);
48
47
if (stack_memory == nullptr ) {
49
48
ESP_LOGE (LOG_TAG, " Failed to allocate stack memory for audio publisher." );
50
49
esp_restart ();
51
50
}
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 );
54
54
#endif
55
55
}
56
56
}
0 commit comments