Skip to content

Commit 6e4b5a9

Browse files
committed
Merge branch 'bugfix/audio_player_thread_safe' into 'master'
Fix audio player APIs thread safe See merge request adf/esp-adf-internal!575
2 parents 79524e0 + f1422e0 commit 6e4b5a9

File tree

6 files changed

+268
-101
lines changed

6 files changed

+268
-101
lines changed

components/audio_sal/audio_thread.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static const char *TAG = "AUDIO_THREAD";
3535

3636
BaseType_t __attribute__((weak)) xTaskCreateRestrictedPinnedToCore(const TaskParameters_t *const pxTaskDefinition, TaskHandle_t *pxCreatedTask, const BaseType_t xCoreID)
3737
{
38-
ESP_LOGE(TAG, "Not found right %s. Please apply the $ADF_PATH/idf_patches/idf_v3.3_freertos.patch first", __func__);
38+
ESP_LOGE(TAG, "Not found right %s.\r\nPlease enter IDF-PATH with \"cd $IDF_PATH\" and apply the IDF patch with \"git apply $ADF_PATH/idf_patches/idf_v3.3_freertos.patch\" first\r\n", __func__);
3939
return pdFALSE;
4040
}
4141

examples/korvo_du1906/components/audio_player/audio_player.c

+6-68
Original file line numberDiff line numberDiff line change
@@ -136,94 +136,32 @@ audio_err_t audio_player_raw_waiting_finished(void)
136136

137137
audio_err_t audio_player_stop(void)
138138
{
139-
int ret = ESP_OK;
140-
ap_ops_t *cur_ops = ap_manager_get_cur_ops();
141-
if (cur_ops == NULL) {
142-
ESP_LOGW(TAG, "%s, not found the current operations", __func__);
143-
return ESP_ERR_AUDIO_NOT_FOUND_MEDIA_SRC;
144-
}
145-
if (cur_ops->stop) {
146-
ESP_LOGI(TAG, "stop, cur media type:%x", cur_ops->para.media_src);
147-
ret = cur_ops->stop(&cur_ops->attr, &cur_ops->para);
148-
}
149-
return ret;
139+
return ap_manager_stop();
150140
}
151141

152142
audio_err_t audio_player_pause(void)
153143
{
154-
int ret = ESP_OK;
155-
ap_ops_t *cur_ops = ap_manager_get_cur_ops();
156-
if (cur_ops == NULL) {
157-
ESP_LOGW(TAG, "%s, not found the current operations", __func__);
158-
return ESP_ERR_AUDIO_NOT_FOUND_MEDIA_SRC;
159-
}
160-
if (cur_ops->pause) {
161-
ESP_LOGI(TAG, "pause, cur media type:%x", cur_ops->para.media_src);
162-
ret = cur_ops->pause(&cur_ops->attr, &cur_ops->para);
163-
}
164-
return ret;
144+
return ap_manager_pause();
165145
}
166146

167147
audio_err_t audio_player_resume(void)
168148
{
169-
int ret = ESP_OK;
170-
ap_ops_t *cur_ops = ap_manager_get_cur_ops();
171-
if (cur_ops == NULL) {
172-
ESP_LOGW(TAG, "%s, not found the current operations", __func__);
173-
return ESP_ERR_AUDIO_NOT_FOUND_MEDIA_SRC;
174-
}
175-
ESP_LOGI(TAG, "resume, cur media type:%x", cur_ops->para.media_src);
176-
if (cur_ops->resume) {
177-
ESP_LOGI(TAG, "resume, cur media type:%x", cur_ops->para.media_src);
178-
ret = cur_ops->resume(&cur_ops->attr, &cur_ops->para);
179-
}
180-
return ret;
149+
return ap_manager_resume();
181150
}
182151

183152
audio_err_t audio_player_next(void)
184153
{
185-
int ret = ESP_OK;
186-
ap_ops_t *cur_ops = ap_manager_get_cur_ops();
187-
if (cur_ops == NULL) {
188-
ESP_LOGW(TAG, "%s, not found the current operations", __func__);
189-
return ESP_ERR_AUDIO_NOT_FOUND_MEDIA_SRC;
190-
}
191-
if (cur_ops->next) {
192-
ESP_LOGI(TAG, "next, cur media type:%x", cur_ops->para.media_src);
193-
ret = cur_ops->next(&cur_ops->attr, &cur_ops->para);
194-
}
195-
return ret;
154+
return ap_manager_next();
196155
}
197156

198157
audio_err_t audio_player_prev(void)
199158
{
200-
int ret = ESP_OK;
201-
ap_ops_t *cur_ops = ap_manager_get_cur_ops();
202-
if (cur_ops == NULL) {
203-
ESP_LOGW(TAG, "%s, not found the current operations", __func__);
204-
return ESP_ERR_AUDIO_NOT_FOUND_MEDIA_SRC;
205-
}
206-
if (cur_ops->prev) {
207-
ESP_LOGI(TAG, "prev, cur media type:%x", cur_ops->para.media_src);
208-
ret = cur_ops->prev(&cur_ops->attr, &cur_ops->para);
209-
}
210-
return ret;
159+
return ap_manager_prev();
211160
}
212161

213162
audio_err_t audio_player_seek(int seek_time_sec)
214163
{
215-
audio_err_t ret = ESP_OK;
216-
ap_ops_t *cur_ops = ap_manager_get_cur_ops();
217-
if (cur_ops == NULL) {
218-
ESP_LOGW(TAG, "%s, not found the current operations", __func__);
219-
return ESP_ERR_AUDIO_NOT_FOUND_MEDIA_SRC;
220-
}
221-
if (cur_ops->seek) {
222-
cur_ops->para.seek_time_sec = seek_time_sec;
223-
ESP_LOGI(TAG, "prev, cur media type:%x", cur_ops->para.media_src);
224-
ret = cur_ops->seek(&cur_ops->attr, &cur_ops->para);
225-
}
226-
return ret;
164+
return ap_manager_seek(seek_time_sec);
227165
}
228166

229167
audio_err_t audio_player_duration_get(int *duration)

0 commit comments

Comments
 (0)