How to swap pipelines correctly
Posted: Fri Jun 18, 2021 12:08 pm
I have inited two pipelines: i2s -> bt and i2s_r -> i2s_w. When wire headphones are inserted I want to stop first pipeline and start the second. I wrote the code below:
It works, but only once after inserting. After removing there is no sound in bluetooth headphones and there is log:
After changing like this:
I can hear a few seconds of sound in wireless headphones , but only few seconds. Log is empty
What am I doing wrong? Why doesn't it stop?
Thank you!
Code: Select all
if(event->cmd == JACK_INSERTED)
{
ESP_LOGW("_periph_event_handle", "Change pipeline to i2s");
audio_pipeline_terminate(pipeline);
audio_pipeline_run(pipeline_i2s);
switched_to_i2s = true;
}
else if(event->cmd == JACK_REMOVED && switched_to_i2s)
{
ESP_LOGW("_periph_event_handle", "Change pipeline to bt");
audio_pipeline_terminate(pipeline_i2s);
audio_pipeline_run(pipeline);
switched_to_i2s = false;
}
Code: Select all
W (93740) AUDIO_PIPELINE: Pipeline already started, state:3
Code: Select all
ESP_LOGW("_periph_event_handle", "Change pipeline to bt");
audio_pipeline_stop(pipeline_i2s);
audio_pipeline_reset_ringbuffer(pipeline);
audio_pipeline_reset_elements(pipeline);
audio_pipeline_change_state(pipeline, AEL_STATE_INIT);
audio_pipeline_run(pipeline);
switched_to_i2s = false;
What am I doing wrong? Why doesn't it stop?
Thank you!