mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-12-26 11:17:44 +01:00
feat[mpp]: Use macro to create mpp_cfg
1. Create mpp_cfg when define KMPP_OBJ_HIERARCHY_ENABLE 2. Add kmpp_objdef_get_cfg_root function 3. Fix mpp_cfg update flag judgment logic 4. Add mpp_enc_cfg extract and apply interface from configure file Signed-off-by: xiaoxu.chen <xiaoxu.chen@rock-chips.com> Change-Id: I3a02e7bbddd20a78c3284589fc9513a1c49cac18
This commit is contained in:
parent
647da8e0d1
commit
425552cb3d
10 changed files with 122 additions and 20 deletions
|
|
@ -6,8 +6,7 @@
|
|||
#ifndef __RK_VENC_CFG_H__
|
||||
#define __RK_VENC_CFG_H__
|
||||
|
||||
#include "rk_type.h"
|
||||
#include "mpp_err.h"
|
||||
#include "rk_mpp_cfg.h"
|
||||
|
||||
typedef void* MppEncCfg;
|
||||
|
||||
|
|
@ -37,6 +36,8 @@ MPP_RET mpp_enc_cfg_get_ptr(MppEncCfg cfg, const char *name, void **val);
|
|||
MPP_RET mpp_enc_cfg_get_st(MppEncCfg cfg, const char *name, void *val);
|
||||
|
||||
void mpp_enc_cfg_show(void);
|
||||
MPP_RET mpp_enc_cfg_extract(MppEncCfg cfg, MppCfgStrFmt fmt, char **buf);
|
||||
MPP_RET mpp_enc_cfg_apply(MppEncCfg cfg, MppCfgStrFmt fmt, char *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ rk_s32 kmpp_objdef_put(KmppObjDef def);
|
|||
|
||||
/* userspace objdef add MppCfgObj root */
|
||||
rk_s32 kmpp_objdef_add_cfg_root(KmppObjDef def, MppCfgObj root);
|
||||
/* userspace objdef get MppCfgObj root */
|
||||
MppCfgObj kmpp_objdef_get_cfg_root(KmppObjDef def);
|
||||
/* userspace objdef add KmppEntry table */
|
||||
rk_s32 kmpp_objdef_add_entry(KmppObjDef def, const char *name, KmppEntry *tbl);
|
||||
/* userspace object init function register default object is all zero */
|
||||
|
|
|
|||
|
|
@ -57,6 +57,33 @@
|
|||
#endif
|
||||
|
||||
#ifdef KMPP_OBJ_IMPL_TYPE
|
||||
#ifdef KMPP_OBJ_HIERARCHY_ENABLE
|
||||
|
||||
#define MPP_CFG_TYPE_ptr MPP_CFG_TYPE_OBJECT
|
||||
#define MPP_CFG_TYPE_st MPP_CFG_TYPE_OBJECT
|
||||
|
||||
#define ENTRY_TO_TRIE(prefix, ftype, type, name, flag, ...) \
|
||||
do { \
|
||||
KmppEntry tbl = { \
|
||||
.tbl.elem_offset = ((size_t)&(((KMPP_OBJ_IMPL_TYPE *)0)->CONCAT_DOT(__VA_ARGS__))), \
|
||||
.tbl.elem_size = sizeof(((KMPP_OBJ_IMPL_TYPE *)0)->CONCAT_DOT(__VA_ARGS__)), \
|
||||
.tbl.elem_type = ELEM_TYPE_##ftype, \
|
||||
.tbl.flag_offset = FLAG_TYPE_TO_OFFSET(name, flag, #flag), \
|
||||
}; \
|
||||
MppCfgInfo info = { \
|
||||
.data_type = CFG_FUNC_TYPE_##ftype, \
|
||||
.flag_offset = tbl.tbl.flag_offset, \
|
||||
.data_offset = tbl.tbl.elem_offset, \
|
||||
.data_size = tbl.tbl.elem_size, \
|
||||
}; \
|
||||
MppCfgObj CONCAT_US(obj, name) = NULL; \
|
||||
kmpp_objdef_add_entry(KMPP_OBJ_DEF(prefix), ENTRY_TO_NAME_START(name), &tbl); \
|
||||
mpp_cfg_get_object(&CONCAT_US(obj, name), TO_STR(name), MPP_CFG_TYPE_##ftype, NULL); \
|
||||
mpp_cfg_set_info(CONCAT_US(obj, name), &info); \
|
||||
mpp_cfg_add(__parent, CONCAT_US(obj, name)); \
|
||||
ENTRY_TO_NAME_END(name); \
|
||||
} while (0);
|
||||
#else
|
||||
#define ENTRY_TO_TRIE(prefix, ftype, type, name, flag, ...) \
|
||||
do { \
|
||||
KmppEntry tbl = { \
|
||||
|
|
@ -68,9 +95,10 @@
|
|||
kmpp_objdef_add_entry(KMPP_OBJ_DEF(prefix), ENTRY_TO_NAME_START(name), &tbl); \
|
||||
ENTRY_TO_NAME_END(name); \
|
||||
} while (0);
|
||||
#endif /* KMPP_OBJ_HIERARCHY_ENABLE */
|
||||
#else
|
||||
#define ENTRY_TO_TRIE(prefix, ftype, type, name, flag, ...)
|
||||
#endif
|
||||
#endif /* KMPP_OBJ_IMPL_TYPE */
|
||||
|
||||
#if !defined(KMPP_OBJ_ACCESS_DISABLE)
|
||||
#define VAL_ENTRY_TBL(prefix, ftype, type, name, flag, ...) \
|
||||
|
|
@ -280,19 +308,40 @@ KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_NAME, VAL_ENTRY_TBL, VAL_ENTRY_TBL,
|
|||
{ \
|
||||
char str_buf[256] = {0}; \
|
||||
rk_s32 str_pos = 0; \
|
||||
rk_s32 str_size = sizeof(str_buf) - 1;
|
||||
rk_s32 str_size = sizeof(str_buf) - 1; \
|
||||
MppCfgObj root = NULL; \
|
||||
MppCfgObj __parent = NULL; \
|
||||
if (once) { \
|
||||
mpp_cfg_get_object(&root, NULL, MPP_CFG_TYPE_OBJECT, NULL); \
|
||||
__parent = root; \
|
||||
}
|
||||
|
||||
#define CFG_DEF_END(...) \
|
||||
{ \
|
||||
if (once) { \
|
||||
kmpp_objdef_add_cfg_root(KMPP_OBJ_DEF(KMPP_OBJ_NAME), root); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define STRUCT_START(...) \
|
||||
{ \
|
||||
rk_s32 CONCAT_US(pos, __VA_ARGS__, root) = str_pos; \
|
||||
str_pos += snprintf(str_buf + str_pos, str_size - str_pos, str_pos ? ":%s" : "%s", CONCAT_STR(__VA_ARGS__));
|
||||
MppCfgObj CONCAT_US(obj, __VA_ARGS__) = NULL; \
|
||||
MppCfgObj CONCAT_US(__parent, __VA_ARGS__) = __parent; \
|
||||
if (once) { \
|
||||
str_pos += snprintf(str_buf + str_pos, str_size - str_pos, \
|
||||
str_pos ? ":%s" : "%s", CONCAT_STR(__VA_ARGS__)); \
|
||||
mpp_cfg_get_object(&CONCAT_US(obj, __VA_ARGS__), CONCAT_STR(__VA_ARGS__), MPP_CFG_TYPE_OBJECT, NULL); \
|
||||
mpp_cfg_add(CONCAT_US(__parent, __VA_ARGS__), CONCAT_US(obj, __VA_ARGS__)); \
|
||||
__parent = CONCAT_US(obj, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define STRUCT_END(...) \
|
||||
str_pos = CONCAT_US(pos, __VA_ARGS__, root); \
|
||||
str_buf[str_pos] = '\0'; \
|
||||
if (__parent) \
|
||||
__parent = CONCAT_US(__parent, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define ENTRY_TO_NAME_START(name, ...) \
|
||||
|
|
@ -308,6 +357,8 @@ KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_NAME, VAL_ENTRY_TBL, VAL_ENTRY_TBL,
|
|||
|
||||
static void CONCAT_US(KMPP_OBJ_NAME, register)(void)
|
||||
{
|
||||
rk_u32 once = 1;
|
||||
|
||||
mpp_env_get_u32(TO_STR(CONCAT_US(KMPP_OBJ_NAME, debug)), &KMPP_OBJ_DEF_DEUBG(KMPP_OBJ_NAME), 0);
|
||||
|
||||
KMPP_OBJ_DBG_LOG("register enter\n");
|
||||
|
|
@ -340,6 +391,7 @@ static void CONCAT_US(KMPP_OBJ_NAME, register)(void)
|
|||
KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_NAME, ENTRY_TO_TRIE, ENTRY_TO_TRIE,
|
||||
ENTRY_TO_TRIE, ENTRY_TO_TRIE, ENTRY_TO_TRIE)
|
||||
kmpp_objdef_add_entry(KMPP_OBJ_DEF(KMPP_OBJ_NAME), NULL, NULL);
|
||||
once = 0;
|
||||
#else
|
||||
KMPP_OBJ_DBG_LOG(TO_STR(KMPP_OBJ_NAME) " has no implementation\n");
|
||||
return;
|
||||
|
|
@ -588,6 +640,8 @@ extern "C" {
|
|||
#undef VAL_HOOK_IDX
|
||||
#undef ENTRY_QUERY
|
||||
#undef HOOK_QUERY
|
||||
#undef MPP_CFG_TYPE_ptr
|
||||
#undef MPP_CFG_TYPE_st
|
||||
|
||||
#undef __OBJECT_HERLPER_H__
|
||||
|
||||
|
|
|
|||
|
|
@ -521,8 +521,6 @@ rk_s32 kmpp_objdef_put(KmppObjDef def)
|
|||
if (impl->cfg) {
|
||||
mpp_cfg_put_all(impl->cfg);
|
||||
impl->cfg = NULL;
|
||||
/* When init with MppCfgObj the trie is associated to the MppCfgObj */
|
||||
impl->trie = NULL;
|
||||
}
|
||||
release = 1;
|
||||
}
|
||||
|
|
@ -681,13 +679,19 @@ rk_s32 kmpp_objdef_add_cfg_root(KmppObjDef def, MppCfgObj root)
|
|||
|
||||
if (impl) {
|
||||
impl->cfg = root;
|
||||
impl->trie = mpp_cfg_to_trie(root);
|
||||
ret = rk_ok;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
MppCfgObj kmpp_objdef_get_cfg_root(KmppObjDef def)
|
||||
{
|
||||
KmppObjDefImpl *impl = (KmppObjDefImpl *)def;
|
||||
|
||||
return impl ? impl->cfg : NULL;
|
||||
}
|
||||
|
||||
rk_s32 kmpp_objdef_add_entry(KmppObjDef def, const char *name, KmppEntry *tbl)
|
||||
{
|
||||
KmppObjDefImpl *impl = (KmppObjDefImpl *)def;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,13 @@
|
|||
#define CFG_TO_u64_PTR(info, cfg) ((RK_U64 *)CFG_TO_PTR(info, cfg))
|
||||
#define CFG_TO_ptr_PTR(info, cfg) ((void **)CFG_TO_PTR(info, cfg))
|
||||
|
||||
#define CFG_TO_FLAG_PTR(info, cfg) ((RK_U32 *)((char *)cfg + info->flag_offset))
|
||||
/* 32bit unsigned long pointer */
|
||||
#define ELEM_FLAG_U32_POS(offset) (((offset) & (~31)) / 8)
|
||||
#define ELEM_FLAG_BIT_POS(offset) ((offset) & 31)
|
||||
#define CFG_TO_FLAG_PTR(info, cfg) ((rk_ul *)((rk_u8 *)cfg + ELEM_FLAG_U32_POS(info->flag_offset)))
|
||||
|
||||
#define CFG_SET_FLAG(info, cfg) \
|
||||
*CFG_TO_FLAG_PTR(info, cfg) |= 1ul << (ELEM_FLAG_BIT_POS(info->flag_offset))
|
||||
|
||||
static RK_U32 mpp_cfg_debug = 0;
|
||||
|
||||
|
|
@ -58,7 +64,7 @@ static MPP_RET mpp_cfg_set(MppCfgInfo *info, void *cfg, void *val)
|
|||
{
|
||||
if (memcmp((char *)cfg + info->data_offset, val, info->data_size)) {
|
||||
memcpy((char *)cfg + info->data_offset, val, info->data_size);
|
||||
*((RK_U32 *)((char *)cfg + info->flag_offset)) |= info->flag_value;
|
||||
CFG_SET_FLAG(info, cfg);
|
||||
}
|
||||
return MPP_OK;
|
||||
}
|
||||
|
|
@ -75,13 +81,13 @@ static MPP_RET mpp_cfg_get(MppCfgInfo *info, void *cfg, void *val)
|
|||
base_type *dst = CFG_TO_##type##_PTR(info, cfg); \
|
||||
base_type old = dst[0]; \
|
||||
dst[0] = val; \
|
||||
if (!info->flag_value) { \
|
||||
if (!info->flag_offset) { \
|
||||
mpp_cfg_dbg_set("%p + %d set " #type " change %d -> %d\n", cfg, info->data_offset, old, val); \
|
||||
} else { \
|
||||
if (old != val) { \
|
||||
mpp_cfg_dbg_set("%p + %d set " #type " update %d -> %d flag %d|%x\n", \
|
||||
cfg, info->data_offset, old, val, info->flag_offset, info->flag_value); \
|
||||
CFG_TO_FLAG_PTR(info, cfg)[0] |= info->flag_value; \
|
||||
mpp_cfg_dbg_set("%p + %d set " #type " update %d -> %d flag %d\n", \
|
||||
cfg, info->data_offset, old, val, info->flag_offset); \
|
||||
CFG_SET_FLAG(info, cfg); \
|
||||
} else { \
|
||||
mpp_cfg_dbg_set("%p + %d set " #type " keep %d\n", cfg, info->data_offset, old); \
|
||||
} \
|
||||
|
|
|
|||
|
|
@ -633,9 +633,9 @@ MppTrie mpp_cfg_to_trie(MppCfgObj obj)
|
|||
break;
|
||||
}
|
||||
|
||||
ret = mpp_trie_init(&p, impl->name);
|
||||
ret = mpp_trie_init(&p, impl->name ? impl->name : "cfg_io");
|
||||
if (ret || !p) {
|
||||
mpp_loge_f("failed to init obj %s trie\n", impl->name);
|
||||
mpp_loge_f("failed to init obj %s trie\n", impl->name ? impl->name : "cfg_io");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "mpp_debug.h"
|
||||
#include "mpp_common.h"
|
||||
#include "mpp_singleton.h"
|
||||
#include "mpp_internal.h"
|
||||
|
||||
#include "mpp_trie.h"
|
||||
#include "mpp_cfg.h"
|
||||
|
|
|
|||
|
|
@ -16,9 +16,11 @@
|
|||
#include "mpp_debug.h"
|
||||
#include "mpp_common.h"
|
||||
#include "mpp_singleton.h"
|
||||
#include "mpp_internal.h"
|
||||
|
||||
#include "mpp_cfg.h"
|
||||
#include "mpp_trie.h"
|
||||
#include "mpp_cfg_io.h"
|
||||
#include "mpp_enc_cfg.h"
|
||||
|
||||
#define ENC_CFG_DBG_FUNC (0x00000001)
|
||||
|
|
@ -60,7 +62,7 @@
|
|||
ALIAS(prefix, s32, rk_s32, fps_out_denom, FLAG_PREV, rc, fps_out_denom) \
|
||||
ENTRY(prefix, s32, rk_s32, fps_chg_no_idr, FLAG_PREV, rc, fps_chg_no_idr) \
|
||||
ENTRY(prefix, s32, rk_s32, gop, FLAG_INCR, rc, gop) \
|
||||
ENTRY(prefix, kptr, void *, ref_cfg, FLAG_INCR, rc, ref_cfg) \
|
||||
ENTRY(prefix, ptr, void *, ref_cfg, FLAG_INCR, rc, ref_cfg) \
|
||||
ENTRY(prefix, u32, rk_u32, max_reenc_times, FLAG_INCR, rc, max_reenc_times) \
|
||||
ENTRY(prefix, u32, rk_u32, priority, FLAG_INCR, rc, rc_priority) \
|
||||
ENTRY(prefix, u32, rk_u32, drop_mode, FLAG_INCR, rc, drop_mode) \
|
||||
|
|
@ -482,3 +484,37 @@ GET_ENC_CFG_CHANGE(h264)
|
|||
GET_ENC_CFG_CHANGE(h265)
|
||||
GET_ENC_CFG_CHANGE(jpeg)
|
||||
GET_ENC_CFG_CHANGE(vp8)
|
||||
|
||||
MPP_RET mpp_enc_cfg_extract(MppEncCfg cfg, MppCfgStrFmt fmt, char **buf)
|
||||
{
|
||||
MppEncCfgSet *cfg_impl = kmpp_obj_to_entry(cfg);
|
||||
MppCfgObj obj = NULL;
|
||||
MppCfgObj root = NULL;
|
||||
|
||||
root = kmpp_objdef_get_cfg_root(mpp_enc_cfg_def);
|
||||
|
||||
mpp_cfg_from_struct(&obj, root, cfg_impl);
|
||||
if (obj) {
|
||||
mpp_cfg_to_string(obj, fmt, buf);
|
||||
mpp_cfg_put_all(obj);
|
||||
}
|
||||
|
||||
return MPP_OK;
|
||||
}
|
||||
|
||||
MPP_RET mpp_enc_cfg_apply(MppEncCfg cfg, MppCfgStrFmt fmt, char *buf)
|
||||
{
|
||||
MppEncCfgSet *cfg_impl = kmpp_obj_to_entry(cfg);
|
||||
MppCfgObj obj = NULL;
|
||||
MppCfgObj root = NULL;
|
||||
|
||||
root = kmpp_objdef_get_cfg_root(mpp_enc_cfg_def);
|
||||
|
||||
mpp_cfg_from_string(&obj, fmt, buf);
|
||||
if (obj) {
|
||||
mpp_cfg_to_struct(obj, root, cfg_impl);
|
||||
mpp_cfg_put_all(obj);
|
||||
}
|
||||
|
||||
return MPP_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ static RK_U32 mpp_sys_cfg_debug = 0;
|
|||
MppCfgInfo tmp = { \
|
||||
CFG_FUNC_TYPE_##cfg_type, \
|
||||
(RK_U32)((long)&(((MppSysCfgSet *)0)->field_change.change)), \
|
||||
flag, \
|
||||
(RK_U32)((long)&(((MppSysCfgSet *)0)->field_change.field_data)), \
|
||||
sizeof((((MppSysCfgSet *)0)->field_change.field_data)), \
|
||||
}; \
|
||||
|
|
@ -647,7 +646,7 @@ MPP_RET mpp_sys_cfg_ioctl(MppSysCfg cfg)
|
|||
if (CHECK_CFG_INFO(info, name, CFG_FUNC_TYPE_##cfg_type)) { \
|
||||
return MPP_NOK; \
|
||||
} \
|
||||
if (!info->flag_value) { \
|
||||
if (!info->flag_offset) { \
|
||||
mpp_log_f("can not set readonly cfg %s\n", mpp_trie_info_name(node)); \
|
||||
return MPP_NOK; \
|
||||
} \
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ typedef struct MppCfgInfo_t {
|
|||
CfgType data_type;
|
||||
/* update flag info 32bit */
|
||||
RK_U32 flag_offset;
|
||||
RK_U32 flag_value;
|
||||
/* data access info */
|
||||
RK_U32 data_offset;
|
||||
RK_S32 data_size;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue