Skip to content

Commit 1e315ca

Browse files
committed
Merge branch 'bugfix/fix_some_bugs_in_gmf_dec_and_enc' into 'main'
Fix some bug in gmf_dec and gmf_enc See merge request adf/multimedia/esp-gmf!56
2 parents ef38721 + e862ea1 commit 1e315ca

File tree

5 files changed

+44
-42
lines changed

5 files changed

+44
-42
lines changed

gmf_elements/gmf_audio/CHANGELOG.md

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

3-
## *Unreleased*
3+
## v0.6.3
44

55
### Bug Fixes
66

7-
- Fixed decoder and encoder not releasing input port on failure
8-
7+
- Fixed decoder not releasing input port on failure
8+
- Fixed missing input size check in gmf_audio_enc when input is insufficient to encode a frame and stream has ended
9+
- Fixed missing zero size check for acquire_in in gmf_audio_dec
10+
- Fixed unmatched sub_cfg when reconfigured by esp_gmf_audio_helper_reconfig_dec_by_uri
911

1012
## v0.6.2
1113

gmf_elements/gmf_audio/esp_gmf_audio_dec.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,23 @@ static esp_gmf_job_err_t esp_gmf_audio_dec_process(esp_gmf_audio_element_handle_
127127
audio_dec->in_data.consumed = 0;
128128
audio_dec->in_data.eos = audio_dec->in_load->is_done;
129129
}
130+
if ((audio_dec->in_data.len == 0) && (audio_dec->in_load->is_done != true)) {
131+
out_len = ESP_GMF_JOB_ERR_CONTINUE;
132+
ESP_LOGD(TAG, "Return Continue, size:%d", audio_dec->in_load->valid_size);
133+
goto __aud_proc_release;
134+
}
130135
ESP_LOGV(TAG, "Read, in_len: %ld, done: %d\r\n", audio_dec->in_data.len, audio_dec->in_load ? audio_dec->in_load->is_done : -1);
131136
load_ret = esp_gmf_port_acquire_out(out, &out_load, audio_dec->buf_size, ESP_GMF_MAX_DELAY);
132137
ESP_GMF_PORT_ACQUIRE_OUT_CHECK(TAG, load_ret, out_len, {goto __aud_proc_release;});
133138
out_load->valid_size = 0;
134139
audio_dec->out_data.buffer = out_load->buf;
135140
audio_dec->out_data.len = out_load->buf_length;
141+
if ((audio_dec->in_data.len == 0) && (audio_dec->in_load->is_done == true)) {
142+
out_len = ESP_GMF_JOB_ERR_DONE;
143+
out_load->is_done = audio_dec->in_load->is_done;
144+
ESP_LOGD(TAG, "Return done, line:%d", __LINE__);
145+
goto __aud_proc_release;
146+
}
136147
while (1) {
137148
ret = esp_audio_simple_dec_process(audio_dec->dec_hd, &audio_dec->in_data, &audio_dec->out_data);
138149
if (ret != ESP_AUDIO_ERR_OK && ret != ESP_AUDIO_ERR_BUFF_NOT_ENOUGH) {

gmf_elements/gmf_audio/esp_gmf_audio_enc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ static esp_gmf_job_err_t esp_gmf_audio_enc_process(esp_gmf_audio_element_handle_
191191
out_len = ESP_GMF_JOB_ERR_FAIL;
192192
goto __audio_enc_release;
193193
}
194-
194+
// Insufficient data to encode full frame; skipping and finalizing pipeline
195+
if ((in_load->valid_size != ESP_GMF_ELEMENT_GET(audio_enc)->in_attr.data_size) && (in_load->is_done == true)) {
196+
out_len = ESP_GMF_JOB_ERR_DONE;
197+
out_load->valid_size = 0;
198+
out_load->is_done = in_load->is_done;
199+
ESP_LOGD(TAG, "Return done, line:%d", __LINE__);
200+
goto __audio_enc_release;
201+
}
195202
enc_in_frame.buffer = in_load->buf;
196203
enc_in_frame.len = in_load->valid_size;
197204
enc_out_frame.buffer = out_load->buf;
@@ -222,7 +229,7 @@ static esp_gmf_job_err_t esp_gmf_audio_enc_process(esp_gmf_audio_element_handle_
222229
out_len = ESP_GMF_JOB_ERR_FAIL;
223230
}
224231
}
225-
if ((out_len == ESP_GMF_JOB_ERR_FAIL) || ((origin_in_load != NULL) && (out_len != ESP_GMF_JOB_ERR_TRUNCATE))) {
232+
if ((origin_in_load != NULL) && (out_len != ESP_GMF_JOB_ERR_TRUNCATE)) {
226233
load_ret = esp_gmf_port_release_in(in_port, origin_in_load, in_port->wait_ticks);
227234
if ((load_ret < ESP_GMF_IO_OK) && (load_ret != ESP_GMF_IO_ABORT)) {
228235
ESP_LOGE(TAG, "IN port release error, ret:%d", load_ret);

gmf_elements/gmf_audio/esp_gmf_audio_helper.c

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,22 @@ esp_gmf_err_t esp_gmf_audio_helper_get_audio_type_by_uri(const char *uri, esp_au
203203

204204
esp_gmf_err_t esp_gmf_audio_helper_reconfig_dec_by_uri(const char *uri, esp_gmf_info_sound_t *info, esp_audio_simple_dec_cfg_t *dec_cfg)
205205
{
206+
// free sub cfg first
207+
if (dec_cfg->dec_cfg) {
208+
esp_gmf_oal_free(dec_cfg->dec_cfg);
209+
dec_cfg->dec_cfg = NULL;
210+
dec_cfg->cfg_size = 0;
211+
}
206212
if (strstr(uri, ".aac")) {
207213
dec_cfg->dec_type = ESP_AUDIO_SIMPLE_DEC_TYPE_AAC;
208214
esp_aac_dec_cfg_t aac_cfg = {
209215
.no_adts_header = false,
210216
.aac_plus_enable = true,
211217
};
212-
if ((dec_cfg->dec_cfg == NULL)
213-
|| (dec_cfg->cfg_size != sizeof(esp_aac_dec_cfg_t))) {
214-
if (dec_cfg->dec_cfg) {
215-
esp_gmf_oal_free(dec_cfg->dec_cfg);
216-
dec_cfg->dec_cfg = NULL;
217-
dec_cfg->cfg_size = 0;
218-
}
219-
dec_cfg->dec_cfg = esp_gmf_oal_calloc(1, sizeof(esp_aac_dec_cfg_t));
220-
ESP_GMF_MEM_CHECK(TAG, dec_cfg->dec_cfg, return ESP_GMF_ERR_MEMORY_LACK;);
221-
dec_cfg->cfg_size = sizeof(esp_aac_dec_cfg_t);
222-
memcpy(dec_cfg->dec_cfg, &aac_cfg, dec_cfg->cfg_size);
223-
}
218+
dec_cfg->dec_cfg = esp_gmf_oal_calloc(1, sizeof(esp_aac_dec_cfg_t));
219+
ESP_GMF_MEM_CHECK(TAG, dec_cfg->dec_cfg, return ESP_GMF_ERR_MEMORY_LACK;);
220+
dec_cfg->cfg_size = sizeof(esp_aac_dec_cfg_t);
221+
memcpy(dec_cfg->dec_cfg, &aac_cfg, dec_cfg->cfg_size);
224222
} else if (strstr(uri, ".mp3")) {
225223
dec_cfg->dec_type = ESP_AUDIO_SIMPLE_DEC_TYPE_MP3;
226224
} else if (strstr(uri, ".amrwb")) {
@@ -240,33 +238,17 @@ esp_gmf_err_t esp_gmf_audio_helper_reconfig_dec_by_uri(const char *uri, esp_gmf_
240238
esp_opus_dec_cfg_t opus_cfg = ESP_OPUS_DEC_CONFIG_DEFAULT();
241239
opus_cfg.channel = info->channels;
242240
opus_cfg.sample_rate = info->sample_rates;
243-
if ((dec_cfg->dec_cfg == NULL)
244-
|| (dec_cfg->cfg_size != sizeof(esp_opus_dec_cfg_t))) {
245-
if (dec_cfg->dec_cfg) {
246-
esp_gmf_oal_free(dec_cfg->dec_cfg);
247-
dec_cfg->dec_cfg = NULL;
248-
dec_cfg->cfg_size = 0;
249-
}
250-
dec_cfg->dec_cfg = esp_gmf_oal_calloc(1, sizeof(esp_opus_dec_cfg_t));
251-
ESP_GMF_MEM_CHECK(TAG, dec_cfg->dec_cfg, return ESP_GMF_ERR_MEMORY_LACK;);
252-
dec_cfg->cfg_size = sizeof(esp_opus_dec_cfg_t);
253-
memcpy(dec_cfg->dec_cfg, &opus_cfg, dec_cfg->cfg_size);
254-
}
241+
dec_cfg->dec_cfg = esp_gmf_oal_calloc(1, sizeof(esp_opus_dec_cfg_t));
242+
ESP_GMF_MEM_CHECK(TAG, dec_cfg->dec_cfg, return ESP_GMF_ERR_MEMORY_LACK;);
243+
dec_cfg->cfg_size = sizeof(esp_opus_dec_cfg_t);
244+
memcpy(dec_cfg->dec_cfg, &opus_cfg, dec_cfg->cfg_size);
255245
} else if (strstr(uri, ".pcm")) {
256246
dec_cfg->dec_type = ESP_AUDIO_SIMPLE_DEC_TYPE_PCM;
257247
esp_pcm_dec_cfg_t *cfg = dec_cfg->dec_cfg;
258-
if ((dec_cfg->dec_cfg == NULL)
259-
|| (dec_cfg->cfg_size != sizeof(esp_pcm_dec_cfg_t))) {
260-
if (dec_cfg->dec_cfg) {
261-
esp_gmf_oal_free(dec_cfg->dec_cfg);
262-
dec_cfg->dec_cfg = NULL;
263-
dec_cfg->cfg_size = 0;
264-
}
265-
cfg = esp_gmf_oal_calloc(1, sizeof(esp_pcm_dec_cfg_t));
266-
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_MEMORY_LACK;);
267-
dec_cfg->cfg_size = sizeof(esp_pcm_dec_cfg_t);
268-
dec_cfg->dec_cfg = cfg;
269-
}
248+
cfg = esp_gmf_oal_calloc(1, sizeof(esp_pcm_dec_cfg_t));
249+
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_MEMORY_LACK;);
250+
dec_cfg->cfg_size = sizeof(esp_pcm_dec_cfg_t);
251+
dec_cfg->dec_cfg = cfg;
270252
cfg->sample_rate = info->sample_rates;
271253
cfg->channel = info->channels;
272254
cfg->bits_per_sample = info->bits;

gmf_elements/gmf_audio/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.6.2"
1+
version: "0.6.3"
22
description: Espressif GMF Elements Audio Module
33
url: https://github.com/espressif/esp-gmf/tree/main/gmf_elements/gmf_audio
44
documentation: "https://github.com/espressif/esp-gmf/blob/main/gmf_elements/gmf_audio/README.md"

0 commit comments

Comments
 (0)