Skip to content

Commit dbebaf3

Browse files
committed
Merge branch 'bugfix/element_pause_resume' into 'master'
Bugfix/element pause resume See merge request adf/esp-adf-internal!328
2 parents 81902c2 + f47b2cf commit dbebaf3

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

components/audio_pipeline/audio_element.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ static esp_err_t audio_element_on_cmd(audio_event_iface_msg_t *msg, void *contex
227227
el->close(el);
228228
el->is_open = false;
229229
}
230-
audio_element_abort_output_ringbuf(el);
231-
audio_element_abort_input_ringbuf(el);
232230
el->state = AEL_STATE_STOPPED;
233231
audio_event_iface_set_cmd_waiting_timeout(el->iface_event, portMAX_DELAY);
234232
audio_element_report_status(el, AEL_STATUS_STATE_STOPPED);
@@ -607,6 +605,18 @@ esp_err_t audio_element_report_status(audio_element_handle_t el, audio_element_s
607605
return audio_element_msg_sendout(el, &msg);
608606
}
609607

608+
esp_err_t audio_element_finish_state(audio_element_handle_t el)
609+
{
610+
if (el->task_stack < 0) {
611+
el->state = AEL_STATE_FINISHED;
612+
audio_element_report_status(el, AEL_STATUS_STATE_FINISHED);
613+
el->is_running = false;
614+
xEventGroupSetBits(el->state_event, STOPPED_BIT);
615+
return ESP_OK;
616+
}
617+
return ESP_FAIL;
618+
}
619+
610620
esp_err_t audio_element_reset_input_ringbuf(audio_element_handle_t el)
611621
{
612622
if (el->read_type != IO_TYPE_RB) {
@@ -951,6 +961,7 @@ esp_err_t audio_element_run(audio_element_handle_t el)
951961
el->task_run = true;
952962
el->is_running = true;
953963
audio_element_force_set_state(el, AEL_STATE_RUNNING);
964+
audio_element_report_status(el, AEL_STATUS_STATE_RUNNING);
954965
}
955966
ESP_LOGI(TAG, "[%s] Element task created", el->tag);
956967
return ret;
@@ -1062,6 +1073,7 @@ esp_err_t audio_element_stop(audio_element_handle_t el)
10621073
audio_event_iface_set_cmd_waiting_timeout(el->iface_event, 0);
10631074
}
10641075
if (el->is_running == false) {
1076+
xEventGroupSetBits(el->state_event, STOPPED_BIT);
10651077
ESP_LOGD(TAG, "[%s] Element already stoped", el->tag);
10661078
return ESP_OK;
10671079
}
@@ -1070,6 +1082,8 @@ esp_err_t audio_element_stop(audio_element_handle_t el)
10701082
return ESP_OK;
10711083
}
10721084
el->stopping = true;
1085+
audio_element_abort_output_ringbuf(el);
1086+
audio_element_abort_input_ringbuf(el);
10731087
if (audio_element_cmd_send(el, AEL_MSG_CMD_STOP) != ESP_OK) {
10741088
el->stopping = false;
10751089
return ESP_FAIL;
@@ -1080,7 +1094,8 @@ esp_err_t audio_element_stop(audio_element_handle_t el)
10801094

10811095
esp_err_t audio_element_wait_for_stop_ms(audio_element_handle_t el, TickType_t ticks_to_wait)
10821096
{
1083-
if (el->state == AEL_STATE_STOPPED) {
1097+
if (el->state == AEL_STATE_STOPPED
1098+
|| el->state == AEL_STATE_INIT) {
10841099
ESP_LOGD(TAG, "[%s] Element already stoped, return without waiting", el->tag);
10851100
return ESP_OK;
10861101
}

components/audio_pipeline/audio_pipeline.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,22 @@ esp_err_t audio_pipeline_stop(audio_pipeline_handle_t pipeline)
354354
{
355355
audio_element_item_t *el_item;
356356
ESP_LOGD(TAG, "audio_element_stop");
357+
bool type = false;
358+
STAILQ_FOREACH(el_item, &pipeline->el_list, next) {
359+
if (el_item->linked
360+
&& el_item->el_state == AEL_STATUS_STATE_FINISHED) {
361+
type = true;
362+
ESP_LOGW(TAG, "audio_element_stop type is finished");
363+
break;
364+
}
365+
}
357366
STAILQ_FOREACH(el_item, &pipeline->el_list, next) {
358367
if (el_item->linked) {
359-
audio_element_stop(el_item->el);
368+
if (type) {
369+
audio_element_set_ringbuf_done(el_item->el);
370+
} else {
371+
audio_element_stop(el_item->el);
372+
}
360373
}
361374
}
362375
return ESP_OK;

components/audio_pipeline/include/audio_element.h

+11
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,17 @@ esp_err_t audio_element_set_output_timeout(audio_element_handle_t el, TickType_t
579579
*/
580580
esp_err_t audio_element_reset_input_ringbuf(audio_element_handle_t el);
581581

582+
/**
583+
* @brief Set element finish state
584+
*
585+
* @param[in] el The audio element handle
586+
*
587+
* @return
588+
* - ESP_OK
589+
* - ESP_FAIL
590+
*/
591+
esp_err_t audio_element_finish_state(audio_element_handle_t el);
592+
582593
/**
583594
* @brief Reset outputbuffer.
584595
*

components/audio_stream/i2s_stream.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static esp_err_t _i2s_open(audio_element_handle_t self)
132132
ESP_LOGI(TAG, "AUDIO_STREAM_WRITER");
133133
}
134134
i2s->is_open = true;
135-
if (i2s->use_alc){
135+
if (i2s->use_alc) {
136136
i2s->volume_handle = alc_volume_setup_open();
137137
if (i2s->volume_handle == NULL) {
138138
ESP_LOGE(TAG, "i2s create the handle for setting volume failed, in line(%d)", __LINE__);
@@ -158,11 +158,11 @@ static esp_err_t _i2s_close(audio_element_handle_t self)
158158
uint8_t *buf = audio_calloc(1, i2s->config.i2s_config.dma_buf_len * 4);
159159

160160
AUDIO_MEM_CHECK(TAG, buf, return ESP_ERR_NO_MEM);
161+
if ((i2s->config.i2s_config.mode & I2S_MODE_DAC_BUILT_IN) != 0) {
162+
memset(buf, 0x80, i2s->config.i2s_config.dma_buf_len * 4);
163+
}
161164

162165
while (index--) {
163-
if ((i2s->config.i2s_config.mode & I2S_MODE_DAC_BUILT_IN) != 0) {
164-
memset(buf, 0x80, i2s->config.i2s_config.dma_buf_len * 4);
165-
}
166166
i2s_write(i2s->config.i2s_port, (char *)buf, i2s->config.i2s_config.dma_buf_len * 4, &bytes_written, portMAX_DELAY);
167167
}
168168
if (buf) {
@@ -175,7 +175,7 @@ static esp_err_t _i2s_close(audio_element_handle_t self)
175175
info.byte_pos = 0;
176176
audio_element_setinfo(self, &info);
177177
}
178-
if (i2s->use_alc){
178+
if (i2s->use_alc) {
179179
if (i2s->volume_handle != NULL) {
180180
alc_volume_setup_close(i2s->volume_handle);
181181
}
@@ -224,7 +224,12 @@ static int _i2s_process(audio_element_handle_t self, char *in_buffer, int in_len
224224
int w_size = 0;
225225
size_t bytes_written = 0;
226226
if (r_size == AEL_IO_TIMEOUT) {
227-
memset(in_buffer, 0, in_len);
227+
i2s_stream_t *i2s = (i2s_stream_t *)audio_element_getdata(self);
228+
if ((i2s->config.i2s_config.mode & I2S_MODE_DAC_BUILT_IN) != 0) {
229+
memset(in_buffer, 0x80, in_len);
230+
} else {
231+
memset(in_buffer, 0x00, in_len);
232+
}
228233
r_size = in_len;
229234
}
230235
if ((r_size > 0)) {
@@ -239,9 +244,11 @@ static int _i2s_process(audio_element_handle_t self, char *in_buffer, int in_len
239244
i2s_stream_t *i2s = (i2s_stream_t *)audio_element_getdata(self);
240245
int index = i2s->config.i2s_config.dma_buf_count;
241246
uint8_t *buf = audio_calloc(1, i2s->config.i2s_config.dma_buf_len * 4);
242-
243247
AUDIO_MEM_CHECK(TAG, buf, return ESP_FAIL);
244248

249+
if ((i2s->config.i2s_config.mode & I2S_MODE_DAC_BUILT_IN) != 0) {
250+
memset(buf, 0x80, i2s->config.i2s_config.dma_buf_len * 4);
251+
}
245252
while (index--) {
246253
i2s_write(i2s->config.i2s_port, (char *)buf, i2s->config.i2s_config.dma_buf_len * 4, &bytes_written, portMAX_DELAY);
247254
}
@@ -290,7 +297,7 @@ int i2s_alc_volume_set(audio_element_handle_t i2s_stream, int volume)
290297
}
291298
}
292299

293-
int i2s_alc_volume_get(audio_element_handle_t i2s_stream, int* volume)
300+
int i2s_alc_volume_get(audio_element_handle_t i2s_stream, int *volume)
294301
{
295302
i2s_stream_t *i2s = (i2s_stream_t *)audio_element_getdata(i2s_stream);
296303
if (i2s->use_alc) {

0 commit comments

Comments
 (0)