Skip to content

Commit 61bcb02

Browse files
committed
gmf_element: Update element methods function logical
1 parent 531a6ac commit 61bcb02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1158
-1930
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Each ESP-GMF functional module exists as a component, currently including [GMF-C
1616
| Component Name | Function | Dependent Components |
1717
| :------------: | :------------: | :------------ |
1818
| [gmf_core](./gmf_core) | Core framework for GMF | None |
19-
| [esp_gmf_audio](./gmf_elements/gmf_audio) | Elements for audio encoding, decoding,<br>and sound effects processing | - `esp_gmf_core`<br>- `esp_audio_effects`<br>- `esp_audio_codec` |
19+
| [esp_gmf_audio](./gmf_elements/gmf_audio) | Elements for audio encoding, decoding,<br>and sound effects processing | - `gmf_core`<br>- `esp_audio_effects`<br>- `esp_audio_codec` |
2020
| [esp_gmf_misc](./gmf_elements/gmf_misc) | Utility elements | None |
21-
| esp_gmf_image | Elements for image encoding, decoding,<br>and image effects processing | - `esp_gmf_core`<br>- `esp_new_jpeg` |
22-
| [esp_gmf_io](./gmf_elements/gmf_io) | Input/output for files, flash, and HTTP | - `esp_gmf_core`<br>- `esp_codec_dev` |
21+
| esp_gmf_image | Elements for image encoding, decoding,<br>and image effects processing | - `gmf_core`<br>- `esp_new_jpeg` |
22+
| [esp_gmf_io](./gmf_elements/gmf_io) | Input/output for files, flash, and HTTP | - `gmf_core`<br>- `esp_codec_dev` |
2323

2424
When developing a project, it is recommended to use the elements and IOs components from the official GMF-Elements repository. You can also create your own elements and IO components to extend its application scenarios.
2525

README_CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ ESP-GMF 各个功能模块以组件的形式存在,目前包含 [GMF-Core](./g
1616
| 组件名称 | 功能 | 依赖的组件 |
1717
| :------------: | :------------:|:------------ |
1818
| [gmf_core](./gmf_core) | GMF 基础框架 ||
19-
| [esp_gmf_audio](./gmf_elements/gmf_audio) | GMF 音频编解码和<br>音效处理 element | - `esp_gmf_core`<br>- `esp_audio_effects`<br> - `esp_audio_codec` |
19+
| [esp_gmf_audio](./gmf_elements/gmf_audio) | GMF 音频编解码和<br>音效处理 element | - `gmf_core`<br>- `esp_audio_effects`<br> - `esp_audio_codec` |
2020
| [esp_gmf_misc](./gmf_elements/gmf_misc) | 工具类 element ||
21-
| esp_gmf_image | GMF 图像编解码和<br>图像效果处理 element | - `esp_gmf_core`<br>- `esp_new_jpeg` |
22-
| [esp_gmf_io](./gmf_elements/gmf_io) | 文件、flash、HTTP 输入输出 | - `esp_gmf_core`<br>- `esp_codec_dev` |
21+
| esp_gmf_image | GMF 图像编解码和<br>图像效果处理 element | - `gmf_core`<br>- `esp_new_jpeg` |
22+
| [esp_gmf_io](./gmf_elements/gmf_io) | 文件、flash、HTTP 输入输出 | - `gmf_core`<br>- `esp_codec_dev` |
2323

2424
在开发项目时,推荐使用官方 GMF-Elements 仓库的 elements 和 IOs 组件进行开发,也可以自行创建 element 和 IO 组件来扩展其应用场景。
2525

examples/esp_audio_simple_player/test_apps/main/aud_simp_player_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ TEST_CASE("Play, Advance API run and stop", "Simple_Player")
256256
alc_cfg.channel = 2;
257257
esp_gmf_element_handle_t alc_hd = NULL;
258258
esp_gmf_alc_init(&alc_cfg, &alc_hd);
259-
esp_gmf_alc_cast(&alc_cfg, alc_hd);
260259
esp_audio_simple_player_register_el(handle, alc_hd);
261260

262261

gmf_core/test_apps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
44

55
set(EXTRA_COMPONENT_DIRS ${EXTRA_COMPONENT_DIRS} "../../gmf_core")
66

7-
project(test_esp_gmf_core)
7+
project(test_gmf_core)

gmf_core/test_apps/main/cases/gmf_caps_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ TEST_CASE("GMF Element CAPS test", "ESP_GMF_CAPS")
434434
fake_cfg.cb = element_event;
435435
esp_gmf_element_handle_t fake_dec_el = NULL;
436436
fake_dec_init(&fake_cfg, &fake_dec_el);
437-
fake_dec_cast(&fake_cfg, fake_dec_el);
438437

439438
const esp_gmf_cap_t *caps = NULL;
440439
esp_gmf_element_get_caps(fake_dec_el, &caps);

gmf_core/test_apps/main/cases/gmf_element_test.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ TEST_CASE("Register and unregister port for GMF ELEMENT", "ESP_GMF_ELEMENT")
3737
cfg.dir = ESP_GMF_IO_DIR_READER;
3838
esp_gmf_io_handle_t reader = NULL;
3939
fake_io_init(&cfg, &reader);
40-
fake_io_cast(&cfg, reader);
4140
TEST_ASSERT_NOT_NULL(reader);
4241
esp_gmf_io_set_uri(reader, "test.mp3");
4342
ESP_GMF_MEM_SHOW(TAG);
4443

4544
esp_gmf_io_handle_t writer = NULL;
4645
cfg.dir = ESP_GMF_IO_DIR_WRITER;
4746
fake_io_init(&cfg, &writer);
48-
fake_io_cast(&cfg, writer);
4947
TEST_ASSERT_NOT_NULL(writer);
5048

5149
fake_dec_cfg_t fake_cfg = DEFAULT_FAKE_DEC_CONFIG();

gmf_core/test_apps/main/cases/gmf_io_test.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ TEST_CASE("GMF IO read and write", "ESP_GMF_IO")
2020
cfg.dir = ESP_GMF_IO_DIR_READER;
2121
esp_gmf_io_handle_t reader = NULL;
2222
fake_io_init(&cfg, &reader);
23-
fake_io_cast(&cfg, reader);
2423
TEST_ASSERT_NOT_NULL(reader);
2524
ESP_GMF_MEM_SHOW(TAG);
2625

@@ -41,7 +40,6 @@ TEST_CASE("GMF IO read and write", "ESP_GMF_IO")
4140
esp_gmf_io_handle_t writer = NULL;
4241
fake_io_init(&cfg, &writer);
4342
TEST_ASSERT_NOT_NULL(writer);
44-
fake_io_cast(&cfg, writer);
4543

4644
esp_gmf_io_set_uri(writer, "test1.mp3");
4745
char *wr_uri = NULL;

gmf_core/test_apps/main/cases/gmf_method_test.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ TEST_CASE("Test basic arithmetic type arguments description", "ESP_GMF_METHOD")
6262
fake_dec_cfg_t cfg = DEFAULT_FAKE_DEC_CONFIG();
6363
esp_gmf_obj_handle_t dec = NULL;
6464
fake_dec_init(&cfg, &dec);
65-
fake_dec_cast(&cfg, dec);
6665

6766
esp_gmf_port_handle_t out_port = NEW_ESP_GMF_PORT_OUT_BYTE(NULL, NULL, NULL, NULL, 1000, ESP_GMF_MAX_DELAY);
6867
esp_gmf_element_register_out_port((esp_gmf_element_handle_t)dec, out_port);
@@ -170,7 +169,6 @@ TEST_CASE("Test structure description", "ESP_GMF_METHOD")
170169
fake_dec_cfg_t cfg = DEFAULT_FAKE_DEC_CONFIG();
171170
esp_gmf_obj_handle_t dec = NULL;
172171
fake_dec_init(&cfg, &dec);
173-
fake_dec_cast(&cfg, dec);
174172

175173
esp_gmf_port_handle_t out_port = NEW_ESP_GMF_PORT_OUT_BYTE(NULL, NULL, NULL, NULL, 1000, ESP_GMF_MAX_DELAY);
176174
esp_gmf_element_register_out_port((esp_gmf_element_handle_t)dec, out_port);

gmf_core/test_apps/main/cases/gmf_pool_test.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,6 @@ TEST_CASE("Un-shared port, [port callback -> dec -> port callback]", "[ELEMENT_P
657657
esp_gmf_element_handle_t fake_dec = NULL;
658658
fake_dec_init(&fake_dec_cfg, &fake_dec);
659659
obj_hd = fake_dec;
660-
fake_dec_cast(&fake_dec_cfg, obj_hd);
661660
TEST_ASSERT_NOT_NULL(fake_dec);
662661
// Print obj tag
663662
ESP_LOGE(TAG, "%s-%d,obj_hd:%p", (OBJ_GET_TAG(obj_hd)), __LINE__, obj_hd);
@@ -702,7 +701,6 @@ TEST_CASE("Shared port, [port callback -> dec -> port callback]", "[ELEMENT_POOL
702701
esp_gmf_element_handle_t fake_dec = NULL;
703702
fake_dec_init(&fake_dec_cfg, &fake_dec);
704703
obj_hd = fake_dec;
705-
fake_dec_cast(&fake_dec_cfg, obj_hd);
706704
TEST_ASSERT_NOT_NULL(fake_dec);
707705
// Print obj tag
708706
ESP_LOGE(TAG, "%s-%d,obj_hd:%p", (OBJ_GET_TAG(obj_hd)), __LINE__, obj_hd);

gmf_core/test_apps/main/common/gmf_fake_dec.c

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -120,60 +120,12 @@ static esp_err_t fake_dec_new(void *cfg, esp_gmf_obj_handle_t *handle)
120120
if (ret != ESP_OK) {
121121
return ret;
122122
}
123-
ret = fake_dec_cast(fake_cfg, new_obj);
124-
if (ret != ESP_OK) {
125-
return ret;
126-
}
127123
*handle = (void *)new_obj;
128124
ESP_LOGI(TAG, "New an object,%s-%p", OBJ_GET_TAG(new_obj), new_obj);
129125

130126
return ESP_OK;
131127
}
132128

133-
esp_err_t fake_dec_init(fake_dec_cfg_t *config, esp_gmf_obj_handle_t *handle)
134-
{
135-
ESP_GMF_MEM_CHECK(TAG, handle, return ESP_ERR_INVALID_ARG);
136-
fake_decoder_t *fake = esp_gmf_oal_calloc(1, sizeof(fake_decoder_t));
137-
ESP_GMF_MEM_CHECK(TAG, fake, return ESP_ERR_NO_MEM);
138-
esp_gmf_obj_t *obj = (esp_gmf_obj_t *)fake;
139-
esp_gmf_err_t ret = ESP_GMF_ERR_OK;
140-
ret = esp_gmf_obj_set_tag(obj, "fake_dec");
141-
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto WAV_DEC_FAIL, "Failed set OBJ tag");
142-
if (config) {
143-
fake_dec_cfg_t *cfg = esp_gmf_oal_calloc(1, sizeof(*config));
144-
ESP_GMF_MEM_CHECK(TAG, cfg, {esp_gmf_oal_free(fake); return ESP_GMF_ERR_MEMORY_LACK;});
145-
memcpy(cfg, config, sizeof(*config));
146-
esp_gmf_obj_set_config(obj, cfg, sizeof(*cfg));
147-
if (config->name) {
148-
ret = esp_gmf_obj_set_tag(obj, cfg->name);
149-
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto WAV_DEC_FAIL, "Failed set OBJ tag");
150-
}
151-
}
152-
153-
obj->new_obj = fake_dec_new;
154-
obj->del_obj = fake_dec_destroy;
155-
*handle = obj;
156-
157-
esp_gmf_element_cfg_t el_cfg = {
158-
.cb = config->cb,
159-
.in_attr.cap = ESP_GMF_EL_PORT_CAP_SINGLE,
160-
.out_attr.cap = ESP_GMF_EL_PORT_CAP_SINGLE,
161-
.in_attr.port.type = ESP_GMF_PORT_TYPE_BLOCK | ESP_GMF_PORT_TYPE_BYTE,
162-
.out_attr.port.type = ESP_GMF_PORT_TYPE_BLOCK | ESP_GMF_PORT_TYPE_BYTE,
163-
.in_attr.data_size = config->in_buf_size,
164-
.out_attr.data_size = config->out_buf_size,
165-
};
166-
ret = esp_gmf_audio_el_init(fake, &el_cfg);
167-
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto WAV_DEC_FAIL, "Failed Initialize audio el");
168-
ESP_LOGI(TAG, "Create fake dec,%s-%p, in:%d, out:%d", OBJ_GET_TAG(obj), obj, config->in_buf_size, config->out_buf_size);
169-
return ESP_OK;
170-
171-
WAV_DEC_FAIL:
172-
esp_gmf_obj_delete(obj);
173-
esp_gmf_oal_free(fake);
174-
return ret;
175-
}
176-
177129
static esp_gmf_err_t __set_para(esp_gmf_element_handle_t handle, esp_gmf_args_desc_t *arg_desc, uint8_t *buf, int buf_len)
178130
{
179131
fake_decoder_t *el = (fake_decoder_t *)handle;
@@ -428,23 +380,50 @@ static esp_gmf_err_t _load_methods_func(esp_gmf_element_handle_t handle)
428380
return ESP_GMF_ERR_OK;
429381
}
430382

431-
esp_err_t fake_dec_cast(fake_dec_cfg_t *config, esp_gmf_obj_handle_t handle)
383+
esp_err_t fake_dec_init(fake_dec_cfg_t *config, esp_gmf_obj_handle_t *handle)
432384
{
433-
ESP_GMF_MEM_CHECK(TAG, config, return ESP_ERR_INVALID_ARG);
434385
ESP_GMF_MEM_CHECK(TAG, handle, return ESP_ERR_INVALID_ARG);
435-
esp_gmf_audio_element_t *fake_el = (esp_gmf_audio_element_t *)handle;
436-
fake_el->base.ops.open = fake_dec_open;
437-
fake_el->base.ops.process = fake_dec_process;
438-
fake_el->base.ops.close = fake_dec_close;
439-
fake_el->base.ops.load_caps = _load_caps_func;
440-
fake_el->base.ops.load_methods = _load_methods_func;
441-
442-
fake_dec_cfg_t *cfg = esp_gmf_oal_calloc(1, sizeof(*config));
443-
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_MEMORY_LACK);
444-
memcpy(cfg, config, sizeof(*config));
445-
// Free memory before overwriting
446-
esp_gmf_oal_free(OBJ_GET_CFG(handle));
447-
esp_gmf_obj_set_config(handle, cfg, sizeof(*config));
386+
fake_decoder_t *fake = esp_gmf_oal_calloc(1, sizeof(fake_decoder_t));
387+
ESP_GMF_MEM_CHECK(TAG, fake, return ESP_ERR_NO_MEM);
388+
esp_gmf_obj_t *obj = (esp_gmf_obj_t *)fake;
389+
esp_gmf_err_t ret = ESP_GMF_ERR_OK;
390+
ret = esp_gmf_obj_set_tag(obj, "fake_dec");
391+
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto FAKE_DEC_FAIL, "Failed set OBJ tag");
392+
if (config) {
393+
fake_dec_cfg_t *cfg = esp_gmf_oal_calloc(1, sizeof(*config));
394+
ESP_GMF_MEM_CHECK(TAG, cfg, {esp_gmf_oal_free(fake); return ESP_GMF_ERR_MEMORY_LACK;});
395+
memcpy(cfg, config, sizeof(*config));
396+
esp_gmf_obj_set_config(obj, cfg, sizeof(*cfg));
397+
if (config->name) {
398+
ret = esp_gmf_obj_set_tag(obj, cfg->name);
399+
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto FAKE_DEC_FAIL, "Failed set OBJ tag");
400+
}
401+
}
448402

403+
obj->new_obj = fake_dec_new;
404+
obj->del_obj = fake_dec_destroy;
405+
406+
esp_gmf_element_cfg_t el_cfg = {
407+
.cb = config->cb,
408+
.in_attr.cap = ESP_GMF_EL_PORT_CAP_SINGLE,
409+
.out_attr.cap = ESP_GMF_EL_PORT_CAP_SINGLE,
410+
.in_attr.port.type = ESP_GMF_PORT_TYPE_BLOCK | ESP_GMF_PORT_TYPE_BYTE,
411+
.out_attr.port.type = ESP_GMF_PORT_TYPE_BLOCK | ESP_GMF_PORT_TYPE_BYTE,
412+
.in_attr.data_size = config->in_buf_size,
413+
.out_attr.data_size = config->out_buf_size,
414+
};
415+
ret = esp_gmf_audio_el_init(fake, &el_cfg);
416+
ESP_GMF_RET_ON_NOT_OK(TAG, ret, goto FAKE_DEC_FAIL, "Failed Initialize audio el");
417+
ESP_GMF_ELEMENT_GET(fake)->ops.open = fake_dec_open;
418+
ESP_GMF_ELEMENT_GET(fake)->ops.process = fake_dec_process;
419+
ESP_GMF_ELEMENT_GET(fake)->ops.close = fake_dec_close;
420+
ESP_GMF_ELEMENT_GET(fake)->ops.load_caps = _load_caps_func;
421+
ESP_GMF_ELEMENT_GET(fake)->ops.load_methods = _load_methods_func;
422+
*handle = obj;
423+
ESP_LOGI(TAG, "Create fake dec,%s-%p, in:%d, out:%d", OBJ_GET_TAG(obj), obj, config->in_buf_size, config->out_buf_size);
449424
return ESP_OK;
425+
426+
FAKE_DEC_FAIL:
427+
fake_dec_destroy(obj);
428+
return ret;
450429
}

0 commit comments

Comments
 (0)