refactor[mpp_cfg_io]: Change cfg to trie interface

1. Change the trie setup function name.
2. Fix trie leak issue.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I417973c1d9c15639ec044cf0e95a07f8593a1762
This commit is contained in:
Herman Chen 2025-05-06 15:34:58 +08:00
parent 095fdce624
commit c4732853fa
2 changed files with 41 additions and 37 deletions

View file

@ -70,12 +70,13 @@ rk_s32 mpp_cfg_del(MppCfgObj obj);
/* attach MppCfgInfo for access location */
rk_s32 mpp_cfg_set_info(MppCfgObj obj, MppCfgInfo *info);
/* all MppCfgObject ready and build trie for string access */
rk_s32 mpp_cfg_build_trie(MppCfgObj obj, MppTrie *trie);
void mpp_cfg_dump(MppCfgObj obj, const char *func);
#define mpp_cfg_dump_f(obj) mpp_cfg_dump(obj, __FUNCTION__)
/* mark all MppCfgObject ready and build trie for string access */
MppTrie mpp_cfg_to_trie(MppCfgObj obj);
/* mpp_cfg output to string and input from string */
rk_s32 mpp_cfg_to_string(MppCfgObj obj, MppCfgStrFmt fmt, char **buf);
rk_s32 mpp_cfg_from_string(MppCfgObj *obj, MppCfgStrFmt fmt, const char *buf);

View file

@ -372,6 +372,11 @@ rk_s32 mpp_cfg_put_all(MppCfgObj obj)
return rk_nok;
}
if (impl->trie) {
mpp_trie_deinit(impl->trie);
impl->trie = NULL;
}
root = impl->parent;
do {
mpp_cfg_put_all_child(impl);
@ -507,7 +512,8 @@ typedef struct MppCfgFullNameCtx_t {
static void add_obj_info(MppCfgIoImpl *impl, void *data)
{
if (impl->info.data_type < CFG_FUNC_TYPE_BUTT) {
/* NOTE: skip the root object and the invalid object */
if (impl->info.data_type < CFG_FUNC_TYPE_BUTT && impl->parent) {
MppCfgFullNameCtx *ctx = (MppCfgFullNameCtx *)data;
get_full_name(impl, ctx->buf, ctx->buf_size);
@ -515,48 +521,47 @@ static void add_obj_info(MppCfgIoImpl *impl, void *data)
}
}
rk_s32 mpp_cfg_build_trie(MppCfgObj obj, MppTrie *trie)
MppTrie mpp_cfg_to_trie(MppCfgObj obj)
{
MppCfgIoImpl *impl = (MppCfgIoImpl *)obj;
MppCfgFullNameCtx ctx;
MppTrie p = NULL;
rk_s32 ret = rk_nok;
char name[256];
if (!impl || !trie) {
mpp_loge_f("invalid param obj %p trie %p\n", impl, trie);
return ret;
}
do {
MppCfgFullNameCtx ctx;
rk_s32 ret = rk_nok;
char name[256];
*trie = NULL;
if (!impl) {
mpp_loge_f("invalid param obj\n", impl);
break;
}
if (impl->parent) {
mpp_loge_f("invalid param obj %p not root\n", impl);
return ret;
}
if (impl->parent) {
mpp_loge_f("invalid param obj %p not root\n", impl);
break;
}
if (impl->trie) {
*trie = impl->trie;
return rk_ok;
}
if (impl->trie) {
p = impl->trie;
break;
}
ret = mpp_trie_init(&p, impl->name);
if (ret || !p) {
mpp_loge_f("failed to init obj %s trie\n", impl->name);
return ret;
}
ret = mpp_trie_init(&p, impl->name);
if (ret || !p) {
mpp_loge_f("failed to init obj %s trie\n", impl->name);
break;
}
ctx.trie = p;
ctx.buf = name;
ctx.buf_size = sizeof(name) - 1;
ctx.trie = p;
ctx.buf = name;
ctx.buf_size = sizeof(name) - 1;
loop_all_children(impl, add_obj_info, &ctx);
mpp_trie_add_info(p, NULL, NULL, 0);
impl->trie = p;
loop_all_children(impl, add_obj_info, &ctx);
mpp_trie_add_info(p, NULL, NULL, 0);
impl->trie = p;
} while (0);
*trie = p;
return ret;
return p;
}
/* check valid len, get offset position */
@ -1519,15 +1524,13 @@ rk_s32 mpp_cfg_to_struct(MppCfgObj obj, MppCfgObj type, void *st)
impl = (MppCfgIoImpl *)obj;
orig = (MppCfgIoImpl *)type;
trie = NULL;
trie = mpp_cfg_to_trie(orig);
str.buf = name;
str.buf_size = sizeof(name) - 1;
str.offset = 0;
str.depth = 0;
mpp_cfg_build_trie(orig, &trie);
write_struct(impl, trie, &str, st + orig->info.data_offset);
return rk_ok;