liuyang
liuyang

Reputation: 11

Why do I get a stack overflow error when running librtmp on esp32

I'm currently using esp32 to stream audio, using librtmp, idf-v4.3 library. librtmp works fine when I use espressif/arduino-esp32 library, but get a lot of stack overflow errors when using espressif/esp-idf , whether to put librtmp in Internal SRAM or External SRAM.

I found through debugging that the problem probably occurred in the socket send() function:

int RTMPSockBuf_Send(RTMPSockBuf *sb, const char *buf, int len)
{
    int rc;

#ifdef _DEBUG
    fwrite(buf, 1, len, netstackdump);
#endif

#if defined(CRYPTO) && !defined(NO_SSL)
    if (sb->sb_ssl)
    {
        rc = TLS_write(sb->sb_ssl, buf, len);
    }
    else
#endif
    {
        printf("socket send:%p len:%d heap:%d\n", buf, len, esp_get_free_internal_heap_size());
        rc = send(sb->sb_socket, buf, len, 0);
        printf("socket send return\n");
    }
    return rc;
}

The error is as follows:

I (559) wifi:wifi driver task: 3ffc0744, prio:23, stack:6656, core=0
I (639) wifi_init: tcp mss: 1440
I (639) wifi_init: WiFi IRAM OP enabled
I (639) wifi_init: WiFi RX IRAM OP enabled
I (649) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (759) wifi:mode : sta (34:ab:95:77:59:e0)
I (759) wifi:enable tsf
I (759) wifi station: wifi_init_sta finished.
I (799) wifi:new:<6,1>, old:<1,0>, ap:<255,255>, sta:<6,1>, prof:1
I (799) wifi:state: init -> auth (b0)
I (809) wifi:state: auth -> assoc (0)
I (809) wifi:state: assoc -> run (10)
I (939) wifi:connected with TIMO_1, aid = 2, channel 6, 40U, bssid = 88:25:93:1a:41:64
I (939) wifi:security: WPA2-PSK, phy: bgn, rssi: -59
I (939) wifi:pm start, type: 1

W (949) wifi:<ba-add>idx:0 (ifx:0, 88:25:93:1a:41:64), tid:0, ssn:0, winSize:64
I (999) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (1549) esp_netif_handlers: sta ip: 192.168.0.102, mask: 255.255.255.0, gw: 192.168.0.1
I (1549) wifi station: got ip:192.168.0.102
I (1549) wifi station: connected to ap SSID:TIMO_1 password:********
into rtmp_connect
into RTMP_Connect0
into RTMP_Connect1
socket send:0x3ffb9e99 len:1537 heap:216508

***ERROR*** A stack overflow in task main has been detected.


Backtrace:0x400819e6:0x3ffb9b000x40088341:0x3ffb9b20 0x4008b802:0x3ffb9b40 0x40089fc6:0x3ffb9bc0 0x40088440:0x3ffb9be0 0x400883f2:0x0000000c  |<-CORRUPTED
0x400819e6: panic_abort at C:/Users/q1004/esp/esp-idf/components/esp_system/panic.c:402

0x40088341: esp_system_abort at C:/Users/q1004/esp/esp-idf/components/esp_system/esp_system.c:121

0x4008b802: vApplicationStackOverflowHook at C:/Users/q1004/esp/esp-idf/components/freertos/port/xtensa/port.c:394

0x40089fc6: vTaskSwitchContext at C:/Users/q1004/esp/esp-idf/components/freertos/tasks.c:3505

0x40088440: _frxt_dispatch at C:/Users/q1004/esp/esp-idf/components/freertos/port/xtensa/portasm.S:436

0x400883f2: _frxt_int_exit at C:/Users/q1004/esp/esp-idf/components/freertos/port/xtensa/portasm.S:231

Has anyone had the same problem, I will put the whole project on github. help.

Upvotes: 0

Views: 1480

Answers (1)

rustyx
rustyx

Reputation: 85491

Looks like you're getting a stack overflow in the main task.

Try increasing the main task stack size:

make menuconfig -> Component Config -> ESP System settings -> Main task stack size

The relevant sdkconfig setting is CONFIG_ESP_MAIN_TASK_STACK_SIZE (formerly CONFIG_MAIN_TASK_STACK_SIZE).

Also important to read: Reducing Stack Sizes.

Upvotes: 1

Related Questions