I solved the crash issue by using audio_pipeline_relink() instead of audio_pipelink_link().
Here is exact APIs call sequence I am using:
Code: Select all
...
else if (cx_handle->work_mode == BT_MODE) {
ESP_LOGI(TAG, "[ * ] Enter WIFI mode");
cx_handle->work_mode = WIFI_MODE;
...
periph_bt_pause(cx_handle->bt_periph);
audio_pipeline_pause(pipeline);
audio_pipeline_stop(pipeline);
audio_pipeline_wait_for_stop(pipeline);
vTaskDelay(300 / portTICK_RATE_MS);
audio_pipeline_unlink(pipeline);
}
if (g_wifi_connect_state == true) {
const char *link_tag[4] = {"http", "mp3", "filter", "i2s"};
audio_pipeline_relink(pipeline, &link_tag[0], 4);
audio_pipeline_run(pipeline);
}
} else if (cx_handle->work_mode == WIFI_MODE) {
ESP_LOGI(TAG, "[ * ] Enter BT mode");
cx_handle->work_mode = BT_MODE;
audio_pipeline_pause(pipeline);
audio_pipeline_stop(pipeline);
audio_pipeline_wait_for_stop(pipeline);
if (g_a2dp_connect_state == true) {
audio_pipeline_unlink(pipeline);
const char *link_tag[3] = {"bt", "filter", "i2s"};
audio_pipeline_relink(pipeline, &link_tag[0], 3);
audio_pipeline_run(pipeline);
periph_bt_play(cx_handle->bt_periph);
}
This switches the pipeline successfully from BT to WiFi but I am experiencing another issue when switching back to BT from WiFi mode. I get this error continuously. There is no audio when it is printing this error.
Code: Select all
W (110849) A2DP_STREAM: discard a2dp(0x3ffe5ec4) sink pkt, A2DP_STREAM_QUEUE_SIZE value needs to be expanded
W (110869) A2DP_STREAM: discard a2dp(0x3ffe5ec4) sink pkt, A2DP_STREAM_QUEUE_SIZE value needs to be expanded
W (110889) A2DP_STREAM: discard a2dp(0x3ffe5ec4) sink pkt, A2DP_STREAM_QUEUE_SIZE value needs to be expanded
W (110919) A2DP_STREAM: discard a2dp(0x3ffe5ec4) sink pkt, A2DP_STREAM_QUEUE_SIZE value needs to be expanded
And when I switch back to WiFi mode, it shows
Code: Select all
W (31089) AUDIO_EVT: There is no space in external queue
***ERROR*** A stack overflow in task input_key_servi has been detected.
So now my approach is deinitialize and free the whole pipeline and its elements and reinitialise it upon Mode switch from BT to WiFi or vice versa