@@ -351,29 +351,14 @@ static esp_gmf_err_t _load_caps_func(esp_gmf_cap_t **caps)
351351 return ESP_GMF_ERR_OK ;
352352}
353353
354- esp_err_t fake_dec_cast ( fake_dec_cfg_t * config , esp_gmf_obj_handle_t handle )
354+ static esp_gmf_err_t _load_methods_func ( esp_gmf_method_t * * method )
355355{
356- ESP_GMF_MEM_CHECK (TAG , config , return ESP_ERR_INVALID_ARG );
357- ESP_GMF_MEM_CHECK (TAG , handle , return ESP_ERR_INVALID_ARG );
358- esp_gmf_audio_element_t * fake_el = (esp_gmf_audio_element_t * )handle ;
359- fake_el -> base .ops .open = fake_dec_open ;
360- fake_el -> base .ops .process = fake_dec_process ;
361- fake_el -> base .ops .close = fake_dec_close ;
362- fake_el -> base .ops .load_caps = _load_caps_func ;
363-
364- fake_dec_cfg_t * cfg = esp_gmf_oal_calloc (1 , sizeof (* config ));
365- ESP_GMF_MEM_CHECK (TAG , cfg , return ESP_GMF_ERR_MEMORY_LACK );
366- memcpy (cfg , config , sizeof (* config ));
367- // Free memory before overwriting
368- esp_gmf_oal_free (OBJ_GET_CFG (handle ));
369- esp_gmf_obj_set_config (handle , cfg , sizeof (* config ));
370-
356+ ESP_GMF_MEM_CHECK (TAG , method , return ESP_ERR_INVALID_ARG );
371357 esp_gmf_args_desc_t * set_args = NULL ;
372358 esp_gmf_args_desc_t * pointer_args = NULL ;
373359 esp_gmf_args_desc_t * get_args = NULL ;
374360
375361 //// Register structure, two parameters, one for in, one for out
376-
377362 esp_gmf_args_desc_append (& pointer_args , "filter_type" , ESP_GMF_ARGS_TYPE_UINT32 , sizeof (uint32_t ), offsetof(mock_para_t , type ));
378363 esp_gmf_args_desc_append (& pointer_args , "fc" , ESP_GMF_ARGS_TYPE_UINT32 , sizeof (uint32_t ), offsetof(mock_para_t , fc ));
379364 esp_gmf_args_desc_append (& pointer_args , "q" , ESP_GMF_ARGS_TYPE_FLOAT , sizeof (float ), offsetof(mock_para_t , q ));
@@ -382,11 +367,12 @@ esp_err_t fake_dec_cast(fake_dec_cfg_t *config, esp_gmf_obj_handle_t handle)
382367
383368 esp_gmf_args_desc_append (& set_args , "index" , ESP_GMF_ARGS_TYPE_UINT8 , sizeof (uint8_t ), 0 );
384369 esp_gmf_args_desc_append_array (& set_args , "para" , pointer_args , sizeof (mock_para_t ), sizeof (uint8_t ));
385- esp_gmf_element_register_method (fake_el , "set_para" , __set_para , set_args );
370+ int ret = esp_gmf_method_append (method , "set_para" , __set_para , set_args );
371+ ESP_GMF_RET_ON_ERROR (TAG , ret , {return ret ;}, "Failed to register %s method" , "set_para" );
386372 ESP_GMF_ARGS_DESC_PRINT (set_args );
387373
388374 esp_gmf_args_desc_copy (set_args , & get_args );
389- esp_gmf_element_register_method ( fake_el , "get_para" , __get_para , get_args );
375+ ret = esp_gmf_method_append ( method , "get_para" , __get_para , get_args );
390376 ESP_GMF_ARGS_DESC_PRINT (get_args );
391377
392378 //// Register nested structure
@@ -409,12 +395,12 @@ esp_err_t fake_dec_cast(fake_dec_cfg_t *config, esp_gmf_obj_handle_t handle)
409395 ESP_GMF_ARGS_DESC_PRINT (nested_args );
410396
411397 esp_gmf_args_desc_append_array (& set_args , "desc" , nested_args , sizeof (mock_dec_desc_t ), offsetof(mock_dec_el_args_t , desc ));
412- esp_gmf_args_desc_append (& set_args , "label" , ESP_GMF_ARGS_TYPE_INT8 , sizeof ((( fake_decoder_t * ) fake_el ) -> args . label ) , offsetof(mock_dec_el_args_t , label ));
413- esp_gmf_element_register_method ( fake_el , "set_args" , __set_args , set_args );
398+ esp_gmf_args_desc_append (& set_args , "label" , ESP_GMF_ARGS_TYPE_INT8 , 16 , offsetof(mock_dec_el_args_t , label ));
399+ ret = esp_gmf_method_append ( method , "set_args" , __set_args , set_args );
414400 ESP_GMF_ARGS_DESC_PRINT (set_args );
415401
416402 esp_gmf_args_desc_copy (set_args , & get_args );
417- esp_gmf_element_register_method ( fake_el , "get_args" , __get_args , get_args );
403+ ret = esp_gmf_method_append ( method , "get_args" , __get_args , get_args );
418404 ESP_GMF_ARGS_DESC_PRINT (get_args );
419405
420406 // Register integer parameters
@@ -423,34 +409,55 @@ esp_err_t fake_dec_cast(fake_dec_cfg_t *config, esp_gmf_obj_handle_t handle)
423409 esp_gmf_args_desc_append (& set_args , "ch" , ESP_GMF_ARGS_TYPE_UINT16 , sizeof (uint16_t ), sizeof (uint32_t ));
424410 esp_gmf_args_desc_append (& set_args , "bits" , ESP_GMF_ARGS_TYPE_UINT16 , sizeof (uint16_t ), sizeof (uint16_t ) + sizeof (uint32_t ));
425411 esp_gmf_args_desc_copy (set_args , & get_args );
426- esp_gmf_element_register_method ( fake_el , "set_info" , __set_info , set_args );
412+ ret = esp_gmf_method_append ( method , "set_info" , __set_info , set_args );
427413 ESP_GMF_ARGS_DESC_PRINT (get_args );
428- esp_gmf_element_register_method ( fake_el , "get_info" , __get_info , get_args );
414+ ret = esp_gmf_method_append ( method , "get_info" , __get_info , get_args );
429415
430416 // Register string parameters
431417 set_args = NULL ;
432- esp_gmf_args_desc_append (& set_args , "dec_name" , ESP_GMF_ARGS_TYPE_INT8 , sizeof ((( fake_decoder_t * ) fake_el ) -> fake_name ) , 0 );
418+ esp_gmf_args_desc_append (& set_args , "dec_name" , ESP_GMF_ARGS_TYPE_INT8 , 32 , 0 );
433419 esp_gmf_args_desc_copy (set_args , & get_args );
434- esp_gmf_element_register_method ( fake_el , "set_name" , __set_name , set_args );
420+ ret = esp_gmf_method_append ( method , "set_name" , __set_name , set_args );
435421 ESP_GMF_ARGS_DESC_PRINT (get_args );
436- esp_gmf_element_register_method ( fake_el , "get_name" , __get_name , get_args );
422+ ret = esp_gmf_method_append ( method , "get_name" , __get_name , get_args );
437423
438424 // Register 64bits integer parameters
439425 set_args = NULL ;
440- esp_gmf_args_desc_append (& set_args , "size" , ESP_GMF_ARGS_TYPE_UINT64 , sizeof ((( fake_decoder_t * ) fake_el ) -> data_size ) , 0 );
426+ esp_gmf_args_desc_append (& set_args , "size" , ESP_GMF_ARGS_TYPE_UINT64 , 8 , 0 );
441427 esp_gmf_args_desc_copy (set_args , & get_args );
442428 ESP_GMF_ARGS_DESC_PRINT (set_args );
443- esp_gmf_element_register_method ( fake_el , "set_size" , __set_size , set_args );
444- esp_gmf_element_register_method ( fake_el , "get_size" , __get_size , get_args );
429+ ret = esp_gmf_method_append ( method , "set_size" , __set_size , set_args );
430+ ret = esp_gmf_method_append ( method , "get_size" , __get_size , get_args );
445431
446432 // Register two parameters, one for in, one for out
447433 set_args = NULL ;
448434 esp_gmf_args_desc_append (& set_args , "index" , ESP_GMF_ARGS_TYPE_UINT8 , sizeof (uint8_t ), 0 );
449- esp_gmf_args_desc_append (& set_args , "filter" , ESP_GMF_ARGS_TYPE_UINT64 , sizeof ((( fake_decoder_t * ) fake_el ) -> filter [ 0 ]) , sizeof (uint8_t ));
435+ esp_gmf_args_desc_append (& set_args , "filter" , ESP_GMF_ARGS_TYPE_UINT64 , 8 , sizeof (uint8_t ));
450436 esp_gmf_args_desc_copy (set_args , & get_args );
451437 ESP_GMF_ARGS_DESC_PRINT (set_args );
452- esp_gmf_element_register_method (fake_el , "set_filter" , __set_filter , set_args );
453- esp_gmf_element_register_method (fake_el , "get_filter" , __get_filter , get_args );
438+ ret = esp_gmf_method_append (method , "set_filter" , __set_filter , set_args );
439+ ret = esp_gmf_method_append (method , "get_filter" , __get_filter , get_args );
440+
441+ return ESP_GMF_ERR_OK ;
442+ }
443+
444+ esp_err_t fake_dec_cast (fake_dec_cfg_t * config , esp_gmf_obj_handle_t handle )
445+ {
446+ ESP_GMF_MEM_CHECK (TAG , config , return ESP_ERR_INVALID_ARG );
447+ ESP_GMF_MEM_CHECK (TAG , handle , return ESP_ERR_INVALID_ARG );
448+ esp_gmf_audio_element_t * fake_el = (esp_gmf_audio_element_t * )handle ;
449+ fake_el -> base .ops .open = fake_dec_open ;
450+ fake_el -> base .ops .process = fake_dec_process ;
451+ fake_el -> base .ops .close = fake_dec_close ;
452+ fake_el -> base .ops .load_caps = _load_caps_func ;
453+ fake_el -> base .ops .load_methods = _load_methods_func ;
454+
455+ fake_dec_cfg_t * cfg = esp_gmf_oal_calloc (1 , sizeof (* config ));
456+ ESP_GMF_MEM_CHECK (TAG , cfg , return ESP_GMF_ERR_MEMORY_LACK );
457+ memcpy (cfg , config , sizeof (* config ));
458+ // Free memory before overwriting
459+ esp_gmf_oal_free (OBJ_GET_CFG (handle ));
460+ esp_gmf_obj_set_config (handle , cfg , sizeof (* config ));
454461
455462 return ESP_OK ;
456463}
0 commit comments