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+
70120static 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