How to swap pipelines correctly

spacebiker
Posts: 11
Joined: Mon May 24, 2021 10:23 am

How to swap pipelines correctly

Postby spacebiker » 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:

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;         
}
It works, but only once after inserting. After removing there is no sound in bluetooth headphones and there is log:

Code: Select all

W (93740) AUDIO_PIPELINE: Pipeline already started, state:3
After changing like this:

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;
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!

Who is online

Users browsing this forum: Bing [Bot] and 21 guests