From b9ad64241793c70cceffc7eea77b87949a50ea59 Mon Sep 17 00:00:00 2001 From: sepfy Date: Sun, 8 Sep 2024 16:22:16 +0800 Subject: [PATCH] [esp32] Enable usrsctp option --- examples/esp32/CMakeLists.txt | 2 ++ examples/esp32/main/app_main.c | 22 +++++++--------------- examples/esp32/sdkconfig.defaults | 3 ++- idf_component.yml | 1 + 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/esp32/CMakeLists.txt b/examples/esp32/CMakeLists.txt index 7149a78..9537525 100644 --- a/examples/esp32/CMakeLists.txt +++ b/examples/esp32/CMakeLists.txt @@ -5,3 +5,5 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(esp32-peer) +# Uncomment if using usrsctp. +#idf_build_set_property(COMPILE_OPTIONS "-DHAVE_USRSCTP" APPEND) diff --git a/examples/esp32/main/app_main.c b/examples/esp32/main/app_main.c index f73549d..a45377f 100644 --- a/examples/esp32/main/app_main.c +++ b/examples/esp32/main/app_main.c @@ -22,7 +22,6 @@ static const char* TAG = "webrtc"; static TaskHandle_t xPcTaskHandle = NULL; -static TaskHandle_t xPsTaskHandle = NULL; static TaskHandle_t xCameraTaskHandle = NULL; static TaskHandle_t xAudioTaskHandle = NULL; @@ -64,16 +63,6 @@ void onopen(void* userdata) { static void onclose(void* userdata) { } -void peer_signaling_task(void* arg) { - ESP_LOGI(TAG, "peer_signaling_task started"); - - for (;;) { - peer_signaling_loop(); - - vTaskDelay(pdMS_TO_TICKS(10)); - } -} - void peer_connection_task(void* arg) { ESP_LOGI(TAG, "peer_connection_task started"); @@ -144,19 +133,22 @@ void app_main(void) { peer_signaling_join_channel(deviceid, g_pc); #if defined(CONFIG_ESP32S3_XIAO_SENSE) - xTaskCreatePinnedToCore(audio_task, "audio", 8192, NULL, 7, &xAudioTaskHandle, 0); + StackType_t* stack_memory = (StackType_t*)heap_caps_malloc(8192 * sizeof(StackType_t), MALLOC_CAP_SPIRAM); + StaticTask_t task_buffer; + if (stack_memory) { + xAudioTaskHandle = xTaskCreateStaticPinnedToCore(audio_task, "audio", 8192, NULL, 7, stack_memory, &task_buffer, 0); + } #endif xTaskCreatePinnedToCore(camera_task, "camera", 4096, NULL, 8, &xCameraTaskHandle, 1); xTaskCreatePinnedToCore(peer_connection_task, "peer_connection", 8192, NULL, 5, &xPcTaskHandle, 1); - xTaskCreatePinnedToCore(peer_signaling_task, "peer_signaling", 8192, NULL, 6, &xPsTaskHandle, 1); - ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); ESP_LOGI(TAG, "open https://sepfy.github.io/webrtc?deviceId=%s", deviceid); while (1) { - vTaskDelay(pdMS_TO_TICKS(1000)); + peer_signaling_loop(); + vTaskDelay(pdMS_TO_TICKS(10)); } } diff --git a/examples/esp32/sdkconfig.defaults b/examples/esp32/sdkconfig.defaults index c6537a9..531431e 100644 --- a/examples/esp32/sdkconfig.defaults +++ b/examples/esp32/sdkconfig.defaults @@ -14,7 +14,7 @@ CONFIG_SPIRAM=y CONFIG_SPIRAM_MODE_OCT=y CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=8102 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n CONFIG_ESP_IPC_TASK_STACK_SIZE=2048 CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=16 @@ -26,3 +26,4 @@ CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 CONFIG_LWIP_TCP_WND_DEFAULT=5744 CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y CONFIG_MBEDTLS_SSL_PROTO_DTLS=y +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192 diff --git a/idf_component.yml b/idf_component.yml index 285e218..a011f9d 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,5 +1,6 @@ dependencies: sepfy/srtp: ^2.0.4 + sepfy/usrsctp: ^0.9.5 description: libpeer license: MIT url: https://github.com/sepfy/libpeer