Skip to content

Commit 62bb1cd

Browse files
committed
Merge branch 'bugfix/add_el_if_test_case_and_fix_some_bugs' into 'main'
Add element interface test cases and fix some bugs See merge request adf/multimedia/esp-gmf!51
2 parents ce2390f + 46947d1 commit 62bb1cd

35 files changed

+400
-52
lines changed

examples/system_common/esp_gmf_setup_peripheral.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ static void setup_periph_new_play_codec()
157157
gpio_if->set(ESP_GMF_AMP_IO_NUM, 1);
158158
#else
159159
audio_codec_i2c_cfg_t i2c_ctrl_cfg = {.addr = ES8311_CODEC_DEFAULT_ADDR, .port = 0, .bus_handle = i2c_handle};
160-
out_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_ctrl_cfg);
160+
if (out_ctrl_if == NULL) {
161+
out_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_ctrl_cfg);
162+
}
161163
if (gpio_if == NULL) {
162164
gpio_if = audio_codec_new_gpio();
163165
}
@@ -169,7 +171,9 @@ static void setup_periph_new_play_codec()
169171
.pa_pin = ESP_GMF_AMP_IO_NUM,
170172
.use_mclk = true,
171173
};
172-
out_codec_if = es8311_codec_new(&es8311_cfg);
174+
if (out_codec_if == NULL) {
175+
out_codec_if = es8311_codec_new(&es8311_cfg);
176+
}
173177
#endif /* CONFIG_IDF_TARGET_ESP32C3 */
174178
}
175179

@@ -264,7 +268,6 @@ static void setup_periph_record_codec(esp_gmf_setup_periph_aud_info *aud_info, v
264268
void teardown_periph_play_codec(void *play_dev)
265269
{
266270
esp_codec_dev_close(play_dev);
267-
play_dev = NULL;
268271
esp_codec_dev_delete(play_dev);
269272
play_dev = NULL;
270273
audio_codec_delete_codec_if(out_codec_if);

gmf_elements/gmf_audio/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.6.1
4+
5+
- Added missing #include "esp_gmf_audio_element.h" across all audio elements
6+
- Fixed out-of-range parameter handling for mixer and EQ elements
7+
- Resolved rate/bit/channel converter bypass errors caused by asynchronous modification of obj->cfg between set/event callbacks and process functions
8+
- Deleted one unreasonable log from esp_gmf_audio_helper.c
9+
310
## v0.6.0
411

512
### Features

gmf_elements/gmf_audio/esp_gmf_alc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "esp_log.h"
1010
#include "esp_gmf_oal_mem.h"
1111
#include "esp_gmf_oal_mutex.h"
12-
#include "esp_gmf_audio_element.h"
1312
#include "esp_gmf_node.h"
1413
#include "esp_gmf_alc.h"
1514
#include "esp_gmf_args_desc.h"
@@ -18,7 +17,7 @@
1817
#include "esp_gmf_cap.h"
1918
#include "esp_gmf_caps_def.h"
2019

21-
#define GMF_DEFAULT_MAX_CHANNLE 2
20+
#define GMF_ALC_DEFAULT_MAX_CHANNEL 2
2221
/**
2322
* @brief Audio ALC context in GMF
2423
*/
@@ -255,7 +254,7 @@ esp_gmf_err_t esp_gmf_alc_set_gain(esp_gmf_audio_element_handle_t handle, uint8_
255254
{
256255
ESP_GMF_NULL_CHECK(TAG, handle, { return ESP_GMF_ERR_INVALID_ARG;});
257256
esp_gmf_alc_t *alc = (esp_gmf_alc_t *)handle;
258-
if(idx > alc->max_ch) {
257+
if (idx >= alc->max_ch) {
259258
ESP_LOGE(TAG, "Gain index %d is out of range", idx);
260259
return ESP_GMF_ERR_INVALID_ARG;
261260
}
@@ -301,15 +300,16 @@ esp_gmf_err_t esp_gmf_alc_init(esp_ae_alc_cfg_t *config, esp_gmf_obj_handle_t *h
301300
esp_gmf_obj_t *obj = (esp_gmf_obj_t *)alc;
302301
obj->new_obj = esp_gmf_alc_new;
303302
obj->del_obj = esp_gmf_alc_destroy;
303+
alc->max_ch = GMF_ALC_DEFAULT_MAX_CHANNEL;
304304
if (config) {
305305
esp_ae_alc_cfg_t *cfg = esp_gmf_oal_calloc(1, sizeof(*config));
306306
ESP_GMF_MEM_VERIFY(TAG, cfg, {ret = ESP_GMF_ERR_MEMORY_LACK; goto ALC_INIT_FAIL;}, "alc configuration", sizeof(*config));
307-
alc->max_ch = config->channel > 0 ? config->channel : GMF_DEFAULT_MAX_CHANNLE;
308-
alc->gain = esp_gmf_oal_calloc(1, alc->max_ch * sizeof(*alc->gain));
309-
ESP_GMF_MEM_VERIFY(TAG, alc->gain, goto ALC_INIT_FAIL, "alc gain", alc->max_ch * sizeof(*alc->gain));
307+
alc->max_ch = config->channel > 0 ? config->channel : GMF_ALC_DEFAULT_MAX_CHANNEL;
310308
memcpy(cfg, config, sizeof(*config));
311309
esp_gmf_obj_set_config(obj, cfg, sizeof(*config));
312310
}
311+
alc->gain = esp_gmf_oal_calloc(1, alc->max_ch * sizeof(int8_t));
312+
ESP_GMF_MEM_VERIFY(TAG, alc->gain, goto ALC_INIT_FAIL, "alc gain", alc->max_ch * sizeof(int8_t));
313313
ret = esp_gmf_obj_set_tag(obj, "alc");
314314
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto ALC_INIT_FAIL, "Failed to set obj tag");
315315
esp_gmf_element_cfg_t el_cfg = {0};

gmf_elements/gmf_audio/esp_gmf_audio_enc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "esp_gmf_node.h"
1111
#include "esp_gmf_oal_mem.h"
1212
#include "esp_gmf_oal_mutex.h"
13-
#include "esp_gmf_audio_element.h"
1413
#include "esp_gmf_audio_enc.h"
1514
#include "esp_audio_enc_default.h"
1615
#include "esp_gmf_cache.h"

gmf_elements/gmf_audio/esp_gmf_audio_helper.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ esp_gmf_err_t esp_gmf_audio_helper_reconfig_dec_by_uri(const char *uri, esp_gmf_
251251
ESP_GMF_MEM_CHECK(TAG, dec_cfg->dec_cfg, return ESP_GMF_ERR_MEMORY_LACK;);
252252
dec_cfg->cfg_size = sizeof(esp_opus_dec_cfg_t);
253253
memcpy(dec_cfg->dec_cfg, &opus_cfg, dec_cfg->cfg_size);
254-
ESP_LOGE(TAG, "IS HERE, %s", uri);
255254
}
256255
} else if (strstr(uri, ".pcm")) {
257256
dec_cfg->dec_type = ESP_AUDIO_SIMPLE_DEC_TYPE_PCM;

gmf_elements/gmf_audio/esp_gmf_bit_cvt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
#include "esp_gmf_node.h"
1111
#include "esp_gmf_oal_mem.h"
1212
#include "esp_gmf_oal_mutex.h"
13-
#include "esp_gmf_audio_element.h"
1413
#include "esp_gmf_bit_cvt.h"
1514
#include "gmf_audio_common.h"
1615
#include "esp_gmf_audio_methods_def.h"
1716
#include "esp_gmf_cap.h"
1817
#include "esp_gmf_caps_def.h"
1918

2019
/**
21-
* @brief Audio bit conversion context in GMF
20+
* @brief Audio bit conversion context in GMF
2221
*/
2322
typedef struct {
2423
esp_gmf_audio_element_t parent; /*!< The GMF bit cvt handle */
2524
esp_ae_bit_cvt_handle_t bit_hd; /*!< The audio effects bit cvt handle */
2625
uint8_t in_bytes_per_sample; /*!< Source bytes number of per sampling point */
2726
uint8_t out_bytes_per_sample; /*!< Dest bytes number of per sampling point */
28-
bool need_reopen; /*!< Whether need to reopen.
27+
bool need_reopen : 1; /*!< Whether need to reopen.
2928
True: Execute the close function first, then execute the open function
3029
False: Do nothing */
30+
bool bypass : 1; /*!< Whether bypass. True: need bypass. False: needn't bypass */
3131
} esp_gmf_bit_cvt_t;
3232

3333
static const char *TAG = "ESP_GMF_BIT_CVT";
@@ -58,6 +58,7 @@ static esp_gmf_job_err_t esp_gmf_bit_cvt_open(esp_gmf_audio_element_handle_t sel
5858
ESP_LOGD(TAG, "Open, rate: %ld, channel: %d, src_bits: %d, dest_bits: %d",
5959
bit_info->sample_rate, bit_info->channel, bit_info->src_bits, bit_info->dest_bits);
6060
bit_cvt->need_reopen = false;
61+
bit_cvt->bypass = (bit_info->src_bits == bit_info->dest_bits);
6162
return ESP_GMF_JOB_ERR_OK;
6263
}
6364

@@ -98,8 +99,7 @@ static esp_gmf_job_err_t esp_gmf_bit_cvt_process(esp_gmf_audio_element_handle_t
9899
out_len = ESP_GMF_JOB_ERR_FAIL;
99100
goto __bit_release;
100101
}
101-
esp_ae_bit_cvt_cfg_t *bit_cvt_info = (esp_ae_bit_cvt_cfg_t *)OBJ_GET_CFG(self);
102-
if ((bit_cvt_info->src_bits == bit_cvt_info->dest_bits) && (in_port->is_shared == 1)) {
102+
if ((bit_cvt->bypass) && (in_port->is_shared == 1)) {
103103
// This case bit conversion is do bypass
104104
out_load = in_load;
105105
}

gmf_elements/gmf_audio/esp_gmf_ch_cvt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
#include "esp_gmf_node.h"
1111
#include "esp_gmf_oal_mem.h"
1212
#include "esp_gmf_oal_mutex.h"
13-
#include "esp_gmf_audio_element.h"
1413
#include "esp_gmf_ch_cvt.h"
1514
#include "gmf_audio_common.h"
1615
#include "esp_gmf_audio_methods_def.h"
1716
#include "esp_gmf_cap.h"
1817
#include "esp_gmf_caps_def.h"
1918

2019
/**
21-
* @brief Audio channel conversion context in GMF
20+
* @brief Audio channel conversion context in GMF
2221
*/
2322
typedef struct {
2423
esp_gmf_audio_element_t parent; /*!< The GMF channel cvt handle */
2524
esp_ae_ch_cvt_handle_t ch_hd; /*!< The audio effects channel cvt handle */
2625
uint8_t in_bytes_per_sample; /*!< Source bytes number of per sampling point */
2726
uint8_t out_bytes_per_sample; /*!< Dest bytes number of per sampling point */
28-
bool need_reopen; /*!< Whether need to reopen.
27+
bool need_reopen : 1; /*!< Whether need to reopen.
2928
True: Execute the close function first, then execute the open function
3029
False: Do nothing */
30+
bool bypass : 1; /*!< Whether bypass. True: need bypass. False: needn't bypass */
3131
} esp_gmf_ch_cvt_t;
3232

3333
static const char *TAG = "ESP_GMF_CH_CVT";
@@ -86,6 +86,7 @@ static esp_gmf_job_err_t esp_gmf_ch_cvt_open(esp_gmf_audio_element_handle_t self
8686
ESP_LOGD(TAG, "Open, rate: %ld, bits: %d, src_channel: %d, dest_channel: %d",
8787
ch_info->sample_rate, ch_info->bits_per_sample, ch_info->src_ch, ch_info->dest_ch);
8888
ch_cvt->need_reopen = false;
89+
ch_cvt->bypass = ch_info->src_ch == ch_info->dest_ch;
8990
return ESP_GMF_JOB_ERR_OK;
9091
}
9192

@@ -126,8 +127,7 @@ static esp_gmf_job_err_t esp_gmf_ch_cvt_process(esp_gmf_audio_element_handle_t s
126127
out_len = ESP_GMF_JOB_ERR_FAIL;
127128
goto __ch_release;
128129
}
129-
esp_ae_ch_cvt_cfg_t *ch_info = (esp_ae_ch_cvt_cfg_t *)OBJ_GET_CFG(self);
130-
if ((ch_info->src_ch == ch_info->dest_ch) && (in_port->is_shared == true)) {
130+
if (ch_cvt->bypass && (in_port->is_shared == true)) {
131131
// This case channel conversion is do bypass
132132
out_load = in_load;
133133
}

gmf_elements/gmf_audio/esp_gmf_deinterleave.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "esp_log.h"
1010
#include "esp_gmf_oal_mem.h"
1111
#include "esp_gmf_oal_mutex.h"
12-
#include "esp_gmf_audio_element.h"
1312
#include "esp_gmf_node.h"
1413
#include "esp_gmf_deinterleave.h"
1514
#include "esp_ae_data_weaver.h"

gmf_elements/gmf_audio/esp_gmf_eq.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "esp_log.h"
1010
#include "esp_gmf_oal_mem.h"
1111
#include "esp_gmf_oal_mutex.h"
12-
#include "esp_gmf_audio_element.h"
1312
#include "esp_gmf_node.h"
1413
#include "esp_gmf_eq.h"
1514
#include "esp_gmf_args_desc.h"
@@ -370,6 +369,11 @@ esp_gmf_err_t esp_gmf_eq_enable_filter(esp_gmf_audio_element_handle_t handle, ui
370369
{
371370
ESP_GMF_NULL_CHECK(TAG, handle, { return ESP_GMF_ERR_INVALID_ARG;});
372371
esp_gmf_eq_t *eq = (esp_gmf_eq_t *)handle;
372+
esp_ae_eq_cfg_t *cfg = (esp_ae_eq_cfg_t *)OBJ_GET_CFG(handle);
373+
if (idx >= cfg->filter_num) {
374+
ESP_LOGE(TAG, "Filter index %d overlimit %d hd:%p", idx, cfg->filter_num, eq);
375+
return ESP_GMF_ERR_INVALID_ARG;
376+
}
373377
if (eq->eq_hd) {
374378
esp_gmf_oal_mutex_lock(((esp_gmf_audio_element_t *)handle)->lock);
375379
esp_ae_err_t ret = 0;

gmf_elements/gmf_audio/esp_gmf_fade.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "esp_log.h"
1010
#include "esp_gmf_oal_mem.h"
1111
#include "esp_gmf_oal_mutex.h"
12-
#include "esp_gmf_audio_element.h"
1312
#include "esp_gmf_node.h"
1413
#include "esp_gmf_fade.h"
1514
#include "gmf_audio_common.h"

0 commit comments

Comments
 (0)