Crash using HTTP Source + Opus Decoder

nathan_swidget
Posts: 5
Joined: Thu Nov 09, 2023 6:13 pm

Crash using HTTP Source + Opus Decoder

Postby nathan_swidget » Fri May 31, 2024 3:39 pm

Hey, I'm working on an application using the Lyrat Devkit, it's an audio pipeline that plays an opus file from the internet.
The clip is only a couple of seconds long: https://spades-test-public-access.s3.am ... pload.opus

Occasionally, the application will crash during playback. This does not happen every time, but about 1/3 of the time.

Log of crash:

Code: Select all


I (92090) I2S: APLL expected frequency is 24576000 Hz, real frequency is 24575996 Hz
I (92091) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (92093) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (92100) I2S: I2S0, MCLK output by GPIO0
I (92107) AUDIO_PIPELINE: link el->rb, el:0x3f814c0c, tag:http, rb:0x3f814df4
I (92112) AUDIO_PIPELINE: link el->rb, el:0x3f80fd98, tag:dec, rb:0x3f819e6c
I (92121) AUDIO_THREAD: The dec task allocate stack on external memory
I (92154) AUDIO_ELEMENT: [dec-0x3f80fd98] Element task created
I (92157) AUDIO_THREAD: The i2s task allocate stack on internal memory
I (92157) AUDIO_ELEMENT: [i2s-0x3f814a34] Element task created
I (92163) AUDIO_THREAD: The http task allocate stack on external memory
I (92170) AUDIO_ELEMENT: [http-0x3f814c0c] Element task created
I (92173) AUDIO_PIPELINE: Func:audio_pipeline_run, Line:359, MEM Total:4075303 Bytes, Inter:117683 Bytes, Dram:65159 Bytes
I (92185) AUDIO_ELEMENT: [dec] AEL_MSG_CMD_RESUME,state:1
I (92190) OPUS_DECODER: OPUS codec
I (92191) AUDIO_ELEMENT: [i2s] AEL_MSG_CMD_RESUME,state:1
I (92199) I2S_STREAM: AUDIO_STREAM_WRITER
I (92203) CODEC_ELEMENT_HELPER: The element is 0x3f80fd98. The reserve data 2 is 0.
I (92211) OPUS_DECODER: a new song playing
I (92220) AUDIO_ELEMENT: [http] AEL_MSG_CMD_RESUME,state:1
I (92222) AUDIO_PIPELINE: Pipeline started
I (93930) HTTP_STREAM: total_bytes=19310
I (94074) AUDIO_ELEMENT: [i2s] AEL_MSG_CMD_PAUSE
I (94075) I2S: APLL expected frequency is 24576000 Hz, real frequency is 24575996 Hz
I (94076) I2S: DMA Malloc info, datalen=blocksize=600, dma_buf_count=3
I (94082) I2S: DMA Malloc info, datalen=blocksize=600, dma_buf_count=3
I (94088) AUDIO_ELEMENT: [i2s] AEL_MSG_CMD_RESUME,state:4
I (94093) I2S_STREAM: AUDIO_STREAM_WRITER
W (94387) HTTP_STREAM: No more data,errno:0, total_bytes:lu, rlen = 19310
I (94388) AUDIO_ELEMENT: IN-[http] AEL_IO_DONE,0

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40144790  PS      : 0x00060c30  A0      : 0x80145500  A1      : 0x3f824840  
0x40144790: quant_band at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/bands.c:1127

A2      : 0x00000000  A3      : 0x3f8254d0  A4      : 0x00000008  A5      : 0x000000f1  
A6      : 0x00000001  A7      : 0x00000000  A8      : 0x0000a5ff  A9      : 0x00000000  
A10     : 0x00000001  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x3ffbb730  
A14     : 0x00000003  A15     : 0x00060023  SAR     : 0x0000001d  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4021d508  LEND    : 0x4021d528  LCOUNT  : 0x00000000  
0x4021d508: ec_read_byte_from_end at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/entdec.c:96
 (inlined by) ec_dec_bits at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/entdec.c:233

0x4021d528: ec_dec_bits at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/entdec.c:234



Backtrace: 0x4014478d:0x3f824840 0x401454fd:0x3f824890 0x4013c157:0x3f825480 0x40132eb2:0x3f825fc0 0x4013365a:0x3f826080 0x4012b67c:0x3f826140 0x4012b74e:0x3f829e10 0x401267e2:0x3f829e30 0x401268b1:0x3f829eb0 0x401221c5:0x3f829ed0
0x4014478d: quant_band at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/bands.c:1114

0x401454fd: quant_all_bands at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/bands.c:1649 (discriminator 8)

0x4013c157: celt_decode_with_ec at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/celt/celt_decoder.c:1051 (discriminator 4)

0x40132eb2: opus_decode_frame at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/src/opus_decoder.c:490 (discriminator 4)

0x4013365a: opus_decode_native at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/src/opus_decoder.c:692

0x4012b67c: opus_multistream_decode_native at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/src/opus_multistream_decoder.c:252

0x4012b74e: opus_multistream_decode at /builds/adf/esp-adf-libs-source/esp_codec/esp-opus/src/opus_multistream_decoder.c:375

0x401267e2: opus_decoder_process at /builds/adf/esp-adf-libs-source/esp_processing/esp-wrapper/opus_decoder.c:590 (discriminator 2)

0x401268b1: _opus_decoder_process at /builds/adf/esp-adf-libs-source/esp_processing/esp-wrapper/opus_decoder.c:672

0x401221c5: audio_element_process_running at /home/spades/projects/esp32/esp-adf/components/audio_pipeline/audio_element.c:336
 (inlined by) audio_element_task at /home/spades/projects/esp32/esp-adf/components/audio_pipeline/audio_element.c:483
Log of Success:

Code: Select all

I (171977) I2S: APLL expected frequency is 24576000 Hz, real frequency is 24575996 Hz
I (171984) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (171988) I2S: DMA Malloc info, datalen=blocksize=1200, dma_buf_count=3
I (171995) I2S: I2S0, MCLK output by GPIO0
I (172001) AUDIO_PIPELINE: link el->rb, el:0x3f814cd8, tag:http, rb:0x3f814e60
I (172006) AUDIO_PIPELINE: link el->rb, el:0x3f810178, tag:dec, rb:0x3f819ed8
I (172015) AUDIO_THREAD: The dec task allocate stack on external memory
I (172049) AUDIO_ELEMENT: [dec-0x3f810178] Element task created
I (172054) AUDIO_THREAD: The i2s task allocate stack on internal memory
I (172055) AUDIO_ELEMENT: [i2s-0x3f8102f4] Element task created
I (172059) AUDIO_THREAD: The http task allocate stack on external memory
I (172068) AUDIO_ELEMENT: [http-0x3f814cd8] Element task created
I (172072) AUDIO_PIPELINE: Func:audio_pipeline_run, Line:359, MEM Total:4073919 Bytes, Inter:118019 Bytes, Dram:65495 Bytes
I (172083) AUDIO_ELEMENT: [dec] AEL_MSG_CMD_RESUME,state:1
I (172088) OPUS_DECODER: OPUS codec
I (172089) AUDIO_ELEMENT: [i2s] AEL_MSG_CMD_RESUME,state:1
I (172097) I2S_STREAM: AUDIO_STREAM_WRITER
I (172101) CODEC_ELEMENT_HELPER: The element is 0x3f810178. The reserve data 2 is 0.
I (172109) OPUS_DECODER: a new song playing
I (172118) AUDIO_ELEMENT: [http] AEL_MSG_CMD_RESUME,state:1
I (172121) AUDIO_PIPELINE: Pipeline started
I (173619) HTTP_STREAM: total_bytes=19310
I (173744) AUDIO_ELEMENT: [i2s] AEL_MSG_CMD_PAUSE
I (173745) I2S: APLL expected frequency is 24576000 Hz, real frequency is 24575996 Hz
I (173746) I2S: DMA Malloc info, datalen=blocksize=600, dma_buf_count=3
I (173752) I2S: DMA Malloc info, datalen=blocksize=600, dma_buf_count=3
I (173758) AUDIO_ELEMENT: [i2s] AEL_MSG_CMD_RESUME,state:4
I (173763) I2S_STREAM: AUDIO_STREAM_WRITER
W (174082) HTTP_STREAM: No more data,errno:0, total_bytes:lu, rlen = 19310
I (174083) AUDIO_ELEMENT: IN-[http] AEL_IO_DONE,0
I (175831) AUDIO_ELEMENT: IN-[dec] AEL_IO_DONE,-2
I (176131) OPUS_DECODER: Closed
I (176176) AUDIO_ELEMENT: IN-[i2s] AEL_IO_DONE,-2
W (176251) AUDIO_ELEMENT: [dec] Element already stopped
W (176252) AUDIO_ELEMENT: [i2s] Element already stopped
W (176253) AUDIO_ELEMENT: [http] Element already stopped
W (176261) AUDIO_PIPELINE: There are no listener registered
I (176269) AUDIO_PIPELINE: audio_pipeline_unlinked
W (176272) AUDIO_ELEMENT: [http] Element has not create when AUDIO_ELEMENT_TERMINATE
W (176280) AUDIO_ELEMENT: [i2s] Element has not create when AUDIO_ELEMENT_TERMINATE
I (176288) I2S: DMA queue destroyed
I (176290) I2S: DMA queue destroyed
W (176294) AUDIO_ELEMENT: [dec] Element has not create when AUDIO_ELEMENT_TERMINATE
I (176301) CODEC_ELEMENT_HELPER: The element is 0x3f810178. The reserve data 2 is 0.
Source Code:

Code: Select all

audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline_cfg.rb_size = 16 * 1024;
pipeline = audio_pipeline_init(&pipeline_cfg);
mem_assert(pipeline);

audio_element_handle_t decoder;
opus_decoder_cfg_t opus_dec_cfg = DEFAULT_OPUS_DECODER_CONFIG();
opus_dec_cfg.out_rb_size = 4 * 1024;
opus_dec_cfg.task_stack = 60 * 1024;
decoder = decoder_opus_init(&opus_dec_cfg);
audio_pipeline_register(pipeline, decoder, "dec");

i2s_stream_cfg_t i2s_cfg = getDefaultI2CConfig();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2sWriter = i2s_stream_init(&i2s_cfg);
audio_pipeline_register(pipeline, i2sWriter, "i2s");

audio_element_handle_t http_stream_reader;
http_stream_cfg_t http_cfg = HTTP_STREAM_CFG_DEFAULT();
http_cfg.type = AUDIO_STREAM_READER;
http_stream_reader = http_stream_init(&http_cfg);
audio_element_set_uri(http_stream_reader, url.c_str());
audio_pipeline_register(pipeline, http_stream_reader, "http");

const char *link_tag[3] = {"http",  "dec", "i2s"};
audio_pipeline_link(pipeline, &link_tag[0], 3);

audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG();
eventHandle = audio_event_iface_init(&evt_cfg);
audio_pipeline_set_listener(pipeline, eventHandle);
audio_hal_set_volume(board_handle->audio_hal, volume);
audio_pipeline_run(pipeline);

while(1) {

    audio_event_iface_msg_t msg;
    esp_err_t ret = audio_event_iface_listen(eventHandle, &msg, portMAX_DELAY);
    if (ret != ESP_OK) continue;
    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && msg.source == (void *) decoder
        && msg.cmd == AEL_MSG_CMD_REPORT_MUSIC_INFO) {
        audio_element_info_t music_info = {0};
        audio_element_getinfo(decoder, &music_info);
        i2s_stream_set_clk(i2sWriter, music_info.sample_rates, music_info.bits, music_info.channels);
        continue;
    }

    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && msg.source == (void *) i2sWriter
        && msg.cmd == AEL_MSG_CMD_REPORT_STATUS) {
        if ((int)msg.data == AEL_STATUS_STATE_FINISHED || (int)msg.data == AEL_STATUS_STATE_STOPPED) {
            // playback done
            break;
        }
    }
    
}

audio_pipeline_stop(pipeline);
audio_pipeline_wait_for_stop(pipeline);
audio_pipeline_terminate(pipeline);
audio_pipeline_unregister(pipeline, http_stream_reader);
audio_pipeline_unregister(pipeline, decoder);
audio_pipeline_unregister(pipeline, i2sWriter);
audio_pipeline_remove_listener(pipeline);
audio_event_iface_destroy(eventHandle);
audio_pipeline_deinit(pipeline);
audio_element_deinit(http_stream_reader);
audio_element_deinit(i2sWriter);
audio_element_deinit(decoder);
The code is pretty much taken as-is from one of the examples, with some of the buffer size's increased in an attempt to fix the issue.
Please let me know how I can resolve this issue,
Thanks!

Who is online

Users browsing this forum: No registered users and 17 guests