Skip to content

Commit 41d0610

Browse files
committed
Merge branch 'bugfix/fix_missing_store_vid_src_info' into 'main'
gmf_video: Fix video processing stability and logging issues See merge request adf/multimedia/esp-gmf!91
2 parents b00db1d + 2b048c3 commit 41d0610

File tree

6 files changed

+137
-10
lines changed

6 files changed

+137
-10
lines changed

elements/gmf_video/esp_gmf_video_color_convert.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ static esp_gmf_job_err_t video_cc_el_open(esp_gmf_element_handle_t self, void *p
3131
esp_gmf_color_convert_hd_t *video_el = (esp_gmf_color_convert_hd_t *)self;
3232
// Get and check configuration
3333
esp_imgfx_color_convert_cfg_t *cfg = (esp_imgfx_color_convert_cfg_t *)OBJ_GET_CFG(self);
34-
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_INVALID_ARG);
34+
ESP_GMF_CHECK(TAG, cfg, return ESP_GMF_JOB_ERR_FAIL, "Failed to get color convert config");
3535
// Open color convert module
3636
esp_imgfx_color_convert_open(cfg, &video_el->hd);
37-
ESP_GMF_MEM_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL);
37+
ESP_GMF_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL, "Failed to create color convert handle");
3838
// Get video size
3939
esp_imgfx_get_image_size(cfg->in_pixel_fmt, &cfg->in_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->in_attr.data_size));
4040
esp_imgfx_get_image_size(cfg->out_pixel_fmt, &cfg->in_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->out_attr.data_size));
@@ -232,6 +232,7 @@ static esp_gmf_err_t video_cc_el_received_event_handler(esp_gmf_event_pkt_t *evt
232232
esp_gmf_event_state_t state = ESP_GMF_EVENT_STATE_NONE;
233233
esp_gmf_element_get_state(self, &state);
234234
esp_gmf_info_video_t *info = (esp_gmf_info_video_t *)evt->payload;
235+
esp_gmf_video_el_set_src_info(self, info);
235236
esp_imgfx_color_convert_cfg_t *config = (esp_imgfx_color_convert_cfg_t *)OBJ_GET_CFG(self);
236237
esp_gmf_color_convert_hd_t *video_el = (esp_gmf_color_convert_hd_t *)self;
237238
GMF_VIDEO_UPDATE_CONFIG(config, info, video_el->need_recfg);

elements/gmf_video/esp_gmf_video_crop.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ static esp_gmf_job_err_t video_crop_el_open(esp_gmf_element_handle_t self, void
3232
esp_gmf_crop_hd_t *video_el = (esp_gmf_crop_hd_t *)self;
3333
// Get and check config
3434
esp_imgfx_crop_cfg_t *cfg = (esp_imgfx_crop_cfg_t *)OBJ_GET_CFG(self);
35-
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_INVALID_ARG);
35+
ESP_GMF_CHECK(TAG, cfg, return ESP_GMF_JOB_ERR_FAIL, "Failed to get crop config");
3636
// Open crop module
3737
esp_imgfx_crop_open(cfg, &video_el->hd);
38-
ESP_GMF_MEM_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL);
38+
ESP_GMF_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL, "Failed to create crop handle");
3939
// Get video size
4040
esp_imgfx_get_image_size(cfg->in_pixel_fmt, &cfg->in_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->in_attr.data_size));
4141
esp_imgfx_get_image_size(cfg->in_pixel_fmt, &cfg->cropped_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->out_attr.data_size));
@@ -240,6 +240,7 @@ static esp_gmf_err_t video_crop_el_received_event_handler(esp_gmf_event_pkt_t *e
240240
esp_gmf_event_state_t state = ESP_GMF_EVENT_STATE_NONE;
241241
esp_gmf_element_get_state(self, &state);
242242
esp_gmf_info_video_t *info = (esp_gmf_info_video_t *)evt->payload;
243+
esp_gmf_video_el_set_src_info(self, info);
243244
esp_imgfx_crop_cfg_t *config = (esp_imgfx_crop_cfg_t *)OBJ_GET_CFG(self);
244245
esp_gmf_crop_hd_t *video_el = (esp_gmf_crop_hd_t *)self;
245246
GMF_VIDEO_UPDATE_CONFIG(config, info, video_el->need_recfg);

elements/gmf_video/esp_gmf_video_rotate.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ static esp_gmf_job_err_t video_rotate_el_open(esp_gmf_element_handle_t self, voi
3131
esp_gmf_rotate_hd_t *video_el = (esp_gmf_rotate_hd_t *)self;
3232
// Get and check config
3333
esp_imgfx_rotate_cfg_t *cfg = (esp_imgfx_rotate_cfg_t *)OBJ_GET_CFG(self);
34-
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_INVALID_ARG);
34+
ESP_GMF_CHECK(TAG, cfg, return ESP_GMF_JOB_ERR_FAIL, "Failed to get rotate config");
3535
// Open rotate module
3636
esp_imgfx_rotate_open(cfg, &video_el->hd);
37-
ESP_GMF_MEM_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL);
37+
ESP_GMF_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL, "Failed to create rotate handle");
3838
// Get video size
3939
esp_imgfx_get_image_size(cfg->in_pixel_fmt, &cfg->in_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->in_attr.data_size));
4040
esp_imgfx_resolution_t res;
@@ -235,6 +235,7 @@ static esp_gmf_err_t video_rotate_el_received_event_handler(esp_gmf_event_pkt_t
235235
esp_gmf_event_state_t state = ESP_GMF_EVENT_STATE_NONE;
236236
esp_gmf_element_get_state(self, &state);
237237
esp_gmf_info_video_t *info = (esp_gmf_info_video_t *)evt->payload;
238+
esp_gmf_video_el_set_src_info(self, info);
238239
esp_imgfx_rotate_cfg_t *config = (esp_imgfx_rotate_cfg_t *)OBJ_GET_CFG(self);
239240
esp_gmf_rotate_hd_t *video_el = (esp_gmf_rotate_hd_t *)self;
240241
GMF_VIDEO_UPDATE_CONFIG(config, info, video_el->need_recfg);

elements/gmf_video/esp_gmf_video_scale.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ static esp_gmf_job_err_t video_scale_el_open(esp_gmf_element_handle_t self, void
3232
esp_gmf_scale_hd_t *video_el = (esp_gmf_scale_hd_t *)self;
3333
// Get and check config
3434
esp_imgfx_scale_cfg_t *cfg = (esp_imgfx_scale_cfg_t *)OBJ_GET_CFG(self);
35-
ESP_GMF_MEM_CHECK(TAG, cfg, return ESP_GMF_ERR_INVALID_ARG);
35+
ESP_GMF_CHECK(TAG, cfg, return ESP_GMF_JOB_ERR_FAIL, "Failed to get scale config");
3636
// Open scale module
3737
esp_imgfx_scale_open(cfg, &video_el->hd);
38-
ESP_GMF_MEM_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL);
38+
ESP_GMF_CHECK(TAG, video_el->hd, return ESP_GMF_JOB_ERR_FAIL, "Failed to create scale handle");
3939
// Get video size
4040
esp_imgfx_get_image_size(cfg->in_pixel_fmt, &cfg->in_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->in_attr.data_size));
4141
esp_imgfx_get_image_size(cfg->in_pixel_fmt, &cfg->scale_res, (uint32_t *)&(ESP_GMF_ELEMENT_GET(video_el)->out_attr.data_size));
@@ -235,6 +235,7 @@ static esp_gmf_err_t video_scale_el_received_event_handler(esp_gmf_event_pkt_t *
235235
esp_gmf_event_state_t state = ESP_GMF_EVENT_STATE_NONE;
236236
esp_gmf_element_get_state(self, &state);
237237
esp_gmf_info_video_t *info = (esp_gmf_info_video_t *)evt->payload;
238+
esp_gmf_video_el_set_src_info(self, info);
238239
esp_imgfx_scale_cfg_t *config = (esp_imgfx_scale_cfg_t *)OBJ_GET_CFG(self);
239240
esp_gmf_scale_hd_t *video_el = (esp_gmf_scale_hd_t *)self;
240241
GMF_VIDEO_UPDATE_CONFIG(config, info, video_el->need_recfg);

elements/gmf_video/private_include/gmf_video_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static inline esp_gmf_job_err_t video_el_acquire_payload(esp_gmf_port_handle_t i
115115
if (load_ret == ESP_GMF_IO_ABORT) {
116116
return ESP_GMF_JOB_ERR_OK;
117117
}
118-
ESP_LOGE("Imgfx_el", "Acquire size: %ld-%d on in port, ret: %d", in_wanted_size, (*in_load)->valid_size, load_ret);
118+
ESP_LOGE("Imgfx_el", "Acquire size: %ld on in port, ret: %d", in_wanted_size, load_ret);
119119
return ESP_GMF_JOB_ERR_FAIL;
120120
}
121121
if (((*in_load)->valid_size) < (in_wanted_size)) {

elements/test_apps/main/elements/gmf_image_effects_test.c

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "freertos/FreeRTOS.h"
99
#include "freertos/event_groups.h"
1010
#include "esp_gmf_data_bus.h"
11+
#include "esp_gmf_video_element.h"
1112
#include "esp_gmf_video_scale.h"
1213
#include "esp_gmf_video_crop.h"
1314
#include "esp_gmf_video_rotate.h"
@@ -67,6 +68,55 @@ static esp_gmf_err_t esp_gmf_create_obj_cfg_pool()
6768
return ret;
6869
}
6970

71+
static esp_gmf_err_t event_cb(esp_gmf_event_pkt_t *evt, void *ctx)
72+
{
73+
ESP_GMF_NULL_CHECK(TAG, ctx, return ESP_GMF_ERR_INVALID_ARG);
74+
ESP_GMF_NULL_CHECK(TAG, evt, return ESP_GMF_ERR_INVALID_ARG);
75+
if ((evt->type != ESP_GMF_EVT_TYPE_REPORT_INFO)
76+
|| (evt->sub != ESP_GMF_INFO_VIDEO)
77+
|| (evt->payload == NULL)) {
78+
return ESP_GMF_ERR_OK;
79+
}
80+
esp_gmf_info_video_t *info = (esp_gmf_info_video_t *)evt->payload;
81+
// Check received info
82+
esp_gmf_info_video_t get_info = {0};
83+
esp_gmf_video_el_get_src_info(ctx, &get_info);
84+
TEST_ASSERT_EQUAL(info->fps, get_info.fps);
85+
TEST_ASSERT_EQUAL(info->bitrate, get_info.bitrate);
86+
const char *tag = OBJ_GET_TAG(ctx);
87+
if (strcmp(tag, "imgfx_scale") == 0) {
88+
esp_imgfx_scale_cfg_t *cfg = (esp_imgfx_scale_cfg_t *)OBJ_GET_CFG(ctx);
89+
TEST_ASSERT_EQUAL(info->width, cfg->scale_res.width);
90+
TEST_ASSERT_EQUAL(info->height, cfg->scale_res.height);
91+
TEST_ASSERT_EQUAL(info->format_id, cfg->in_pixel_fmt);
92+
} else if (strcmp(tag, "imgfx_crop") == 0) {
93+
esp_imgfx_crop_cfg_t *cfg = (esp_imgfx_crop_cfg_t *)OBJ_GET_CFG(ctx);
94+
TEST_ASSERT_EQUAL(info->width, cfg->cropped_res.width);
95+
TEST_ASSERT_EQUAL(info->height, cfg->cropped_res.height);
96+
TEST_ASSERT_EQUAL(info->format_id, cfg->in_pixel_fmt);
97+
} else if (strcmp(tag, "imgfx_rotate") == 0) {
98+
esp_imgfx_rotate_cfg_t *cfg = (esp_imgfx_rotate_cfg_t *)OBJ_GET_CFG(ctx);
99+
if (cfg->degree % 90 == 0
100+
|| cfg->degree % 270 == 0) {
101+
TEST_ASSERT_EQUAL(info->width, cfg->in_res.height);
102+
TEST_ASSERT_EQUAL(info->height, cfg->in_res.width);
103+
} else {
104+
TEST_ASSERT_EQUAL(info->width, cfg->in_res.width);
105+
TEST_ASSERT_EQUAL(info->height, cfg->in_res.height);
106+
}
107+
TEST_ASSERT_EQUAL(info->format_id, cfg->in_pixel_fmt);
108+
} else if (strcmp(tag, "imgfx_color_convert") == 0) {
109+
esp_imgfx_color_convert_cfg_t *cfg = (esp_imgfx_color_convert_cfg_t *)OBJ_GET_CFG(ctx);
110+
TEST_ASSERT_EQUAL(info->width, cfg->in_res.width);
111+
TEST_ASSERT_EQUAL(info->height, cfg->in_res.height);
112+
TEST_ASSERT_EQUAL(info->format_id, cfg->out_pixel_fmt);
113+
} else {
114+
return ESP_GMF_ERR_FAIL;
115+
}
116+
ESP_LOGI(TAG, "Event callback");
117+
return ESP_GMF_ERR_OK;
118+
}
119+
70120
static esp_gmf_err_io_t imgfx_acquire_read(void *handle, esp_gmf_data_bus_block_t *blk, int wanted_size, int block_ticks)
71121
{
72122
blk->buf = test_buffer;
@@ -101,6 +151,20 @@ TEST_CASE("Test for all software video effects", "[ESP_GMF_Effects]")
101151
esp_gmf_port_handle_t in_port = NULL;
102152
esp_gmf_port_handle_t out_port = NULL;
103153
esp_gmf_obj_handle_t obj_hd = {NULL};
154+
esp_gmf_info_video_t info = {
155+
.fps = 30,
156+
.width = 640,
157+
.height = 480,
158+
.format_id = ESP_IMGFX_PIXEL_FMT_RGB888,
159+
.bitrate = 1000000,
160+
};
161+
esp_gmf_event_pkt_t event_pkt = {
162+
.from = NULL,
163+
.type = ESP_GMF_EVT_TYPE_REPORT_INFO,
164+
.sub = ESP_GMF_INFO_VIDEO,
165+
.payload = &info,
166+
.payload_size = sizeof(info),
167+
};
104168
// Create obj handle and cfg pool
105169
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_create_obj_cfg_pool());
106170
test_buffer = (uint8_t *)malloc(TEST_MAX_IMG_LENGTH);
@@ -121,9 +185,21 @@ TEST_CASE("Test for all software video effects", "[ESP_GMF_Effects]")
121185
esp_gmf_element_register_in_port(obj_hd, in_port);
122186
esp_gmf_element_register_out_port(obj_hd, out_port);
123187
for (size_t i = 0; i < 4; i++) {
188+
// set event callback
189+
esp_gmf_element_set_event_func(obj_hd, event_cb, obj_hd);
190+
// report info
191+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_element_receive_event(obj_hd, &event_pkt, NULL));
124192
// Open obj
125193
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_element_process_open(obj_hd, NULL));
126-
// Run obj
194+
// Check received info
195+
esp_gmf_info_video_t get_info = {0};
196+
esp_gmf_video_el_get_src_info(obj_hd, &get_info);
197+
TEST_ASSERT_EQUAL(info.fps, get_info.fps);
198+
TEST_ASSERT_EQUAL(info.width, get_info.width);
199+
TEST_ASSERT_EQUAL(info.height, get_info.height);
200+
TEST_ASSERT_EQUAL(info.format_id, get_info.format_id);
201+
TEST_ASSERT_EQUAL(info.bitrate, get_info.bitrate);
202+
// Run
127203
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_element_process_running(obj_hd, NULL));
128204
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_element_process_running(obj_hd, NULL));
129205
// Close obj
@@ -140,3 +216,50 @@ TEST_CASE("Test for all software video effects", "[ESP_GMF_Effects]")
140216
esp_gmf_destory_obj_cfg_pool();
141217
ESP_GMF_MEM_SHOW(TAG);
142218
}
219+
220+
TEST_CASE("ERROR: Input load is NULL", "[ESP_GMF_Effects]")
221+
{
222+
esp_log_level_set("*", ESP_LOG_INFO);
223+
ESP_GMF_MEM_SHOW(TAG);
224+
esp_gmf_port_handle_t in_port = NULL;
225+
esp_gmf_port_handle_t out_port = NULL;
226+
esp_gmf_obj_handle_t obj_hd = {NULL};
227+
// Create obj handle and cfg pool
228+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_create_obj_cfg_pool());
229+
test_buffer = (uint8_t *)malloc(TEST_MAX_IMG_LENGTH);
230+
TEST_ASSERT_NOT_EQUAL(NULL, test_buffer);
231+
test_buffer1 = (uint8_t *)malloc(TEST_MAX_IMG_LENGTH);
232+
TEST_ASSERT_NOT_EQUAL(NULL, test_buffer1);
233+
234+
for (size_t el_index = 0; el_index < TEST_MAX_EL_NUM; el_index++) {
235+
// New obj
236+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_obj_dupl(obj_hd_pool[el_index], &obj_hd));
237+
// Print obj tag
238+
ESP_LOGE(TAG, "%s-%d,obj_hd:%p", (OBJ_GET_TAG(obj_hd)), __LINE__, obj_hd);
239+
// Create in/out port
240+
in_port = NEW_ESP_GMF_PORT_IN_BLOCK(NULL, NULL, NULL, NULL, TEST_MAX_IMG_LENGTH, TEST_TICK_DELAY);
241+
out_port = NEW_ESP_GMF_PORT_OUT_BLOCK(NULL, NULL, NULL, NULL, TEST_MAX_IMG_LENGTH, TEST_TICK_DELAY);
242+
243+
uint32_t fake_reader_handle;
244+
esp_gmf_port_set_writer(in_port, (void *)&fake_reader_handle);
245+
// Register in/out port
246+
esp_gmf_element_register_in_port(obj_hd, in_port);
247+
esp_gmf_element_register_out_port(obj_hd, out_port);
248+
for (size_t i = 0; i < 4; i++) {
249+
// Open obj
250+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_element_process_open(obj_hd, NULL));
251+
// Run obj
252+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_FAIL, esp_gmf_element_process_running(obj_hd, NULL));
253+
// Close obj
254+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_element_process_close(obj_hd, NULL));
255+
}
256+
// Delete obj: port will be deleted when obj handle pool is destroyed
257+
TEST_ASSERT_EQUAL(ESP_GMF_ERR_OK, esp_gmf_obj_delete(obj_hd));
258+
}
259+
// free buffer
260+
free(test_buffer);
261+
free(test_buffer1);
262+
// Destroy obj handle and cfg pool
263+
esp_gmf_destory_obj_cfg_pool();
264+
ESP_GMF_MEM_SHOW(TAG);
265+
}

0 commit comments

Comments
 (0)