Skip to content

Commit

Permalink
[esp32] Build with usrsctp
Browse files Browse the repository at this point in the history
  • Loading branch information
sepfy committed Jul 28, 2024
1 parent 5c2eddf commit 6a87554
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions examples/esp32/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
components/srtp
components/usrsctp
build
dependencies.lock
managed_components
Expand Down
1 change: 1 addition & 0 deletions examples/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ cd libpeer/examples/esp32
$ idf.py add-dependency "espressif/esp32-camera^2.0.4"
$ idf.py add-dependency "mdns"
$ git clone --recursive https://github.com/sepfy/esp_ports.git components/srtp
$ git clone -b components https://github.com/sepfy/usrsctp-esp32.git components/usrtsctp
```

### Configure
Expand Down
2 changes: 1 addition & 1 deletion examples/esp32/components/peer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ file(GLOB CODES "${PEER_PROJECT_PATH}/src/*.c")
idf_component_register(
SRCS ${CODES} ${HTTP_SOURCES} ${MQTT_SOURCES} ${MQTT_SERIALIZER_SOURCES}
INCLUDE_DIRS "${PEER_PROJECT_PATH}/src" ${HTTP_INCLUDE_PUBLIC_DIRS} ${MQTT_INCLUDE_PUBLIC_DIRS}
REQUIRES mbedtls srtp json mdns
REQUIRES mbedtls srtp json usrsctp mdns
)

add_definitions("-DESP32 -DHTTP_DO_NOT_USE_CUSTOM_CONFIG -DMQTT_DO_NOT_USE_CUSTOM_CONFIG")
Expand Down
23 changes: 13 additions & 10 deletions examples/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.2.2 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_ESP32S3_XIAO_SENSE=y
CONFIG_EXAMPLE_CONNECT_IPV6=n
CONFIG_ESP_PHY_REDUCE_TX_POWER=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8102
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_ESP_MAIN_TASK_STACK_SIZE=35840
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
CONFIG_ESP_IPC_TASK_STACK_SIZE=2048
CONFIG_LWIP_IPV6_AUTOCONFIG=y
CONFIG_LWIP_IPV6_DHCP6=y
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
CONFIG_LWIP_TCP_WND_DEFAULT=5744
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=8192
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
CONFIG_MBEDTLS_SSL_DTLS_SRTP=y
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
CONFIG_MDNS_TASK_STACK_SIZE=2048
CONFIG_MDNS_NETWORKING_SOCKET=y
CONFIG_PTHREAD_TASK_PRIO_DEFAULT=15
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192
CONFIG_PTHREAD_STACK_MIN=16
CONFIG_PTHREAD_DEFAULT_CORE_1=y
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#define SCTP_MTU (1200)
#define CONFIG_MTU (1300)
#define RSA_KEY_LENGTH 1024
#define HAVE_USRSCTP

#ifdef ESP32
#define VIDEO_RB_DATA_LENGTH (CONFIG_MTU * 64)
#define AUDIO_RB_DATA_LENGTH (CONFIG_MTU * 64)
#define DATA_RB_DATA_LENGTH (SCTP_MTU * 128)
#define AUDIO_LATENCY 40 // ms
#else
#define HAVE_USRSCTP
#define VIDEO_RB_DATA_LENGTH (CONFIG_MTU * 256)
#define AUDIO_RB_DATA_LENGTH (CONFIG_MTU * 256)
#define DATA_RB_DATA_LENGTH (SCTP_MTU * 128)
Expand Down
5 changes: 3 additions & 2 deletions src/ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ int ports_resolve_mdns_host(const char *host, Address *addr) {
return ret;
}
LOGE("Query Failed: %s", esp_err_to_name(err));
return ret;
return ret;
}

addr->family = AF_INET;
memcpy(addr->ipv4, &esp_addr.addr, 4);
return ret;
return 0;
#else
return ports_resolve_addr(host, addr);
#endif
Expand Down
14 changes: 7 additions & 7 deletions src/sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static int sctp_handle_incoming_data(Sctp *sctp, char *data, size_t len, uint32_
case DATA_CHANNEL_PPID_DOMSTRING_PARTIAL:
case DATA_CHANNEL_PPID_BINARY_PARTIAL:

LOGD("Got message (size = %ld)", len);
LOGD("Got message (size = %d)", len);
if(sctp->onmessage) {
sctp->onmessage(data, len, sctp->userdata, sid);
}
Expand Down Expand Up @@ -464,12 +464,12 @@ static void sctp_process_notification(Sctp *sctp, union sctp_notification *notif
static int sctp_incoming_data_cb(struct socket *sock, union sctp_sockstore addr,
void *data, size_t len, struct sctp_rcvinfo recv_info, int flags, void *userdata) {
Sctp *sctp = (Sctp*)userdata;
LOGD("Data of length %u received on stream %u with SSN %u, TSN %u, PPID %u",
(uint32_t)len,
recv_info.rcv_sid,
recv_info.rcv_ssn,
recv_info.rcv_tsn,
ntohl(recv_info.rcv_ppid));
LOGD("Data of length %d received on stream %"PRIu16" with SSN %"PRIu16", TSN %"PRIu32", PPID %"PRIu32"",
len,
recv_info.rcv_sid,
recv_info.rcv_ssn,
recv_info.rcv_tsn,
ntohl(recv_info.rcv_ppid));
if(flags & MSG_NOTIFICATION) {
sctp_process_notification(sctp, (union sctp_notification *)data, len);
} else {
Expand Down

0 comments on commit 6a87554

Please sign in to comment.