浏览代码

feat[kmpp_frame]: Add KmppFrame module

1. Sync kmpp_obj_func.h and kmpp_obj_helper.h from kernel.
2. Add more kmpp_obj function from kernel.
3. Add KmppFrame module.
4. Fix kmpp_obj_check failure.

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: Ib333370eb36c7b63ef50d3e52cf7fd753c9e5af1
Herman Chen 3 周之前
父节点
当前提交
ca334adda0

+ 1 - 0
kmpp/base/CMakeLists.txt

@@ -5,6 +5,7 @@
 # ----------------------------------------------------------------------------
 add_library(kmpp_base STATIC
     kmpp_obj.c
+    kmpp_frame.c
     kmpp_venc_cfg.c
     )
 

+ 53 - 0
kmpp/base/inc/kmpp_frame.h

@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: Apache-2.0 OR MIT */
+/*
+ * Copyright (c) 2025 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef __KMPP_FRAME_H__
+#define __KMPP_FRAME_H__
+
+#include "mpp_frame.h"
+
+typedef void* KmppFrame;
+
+#define KMPP_FRAME_ENTRY_TABLE(ENTRY, prefix) \
+    ENTRY(prefix, u32, rk_u32, width) \
+    ENTRY(prefix, u32, rk_u32, height) \
+    ENTRY(prefix, u32, rk_u32, hor_stride) \
+    ENTRY(prefix, u32, rk_u32, ver_stride) \
+    ENTRY(prefix, u32, rk_u32, hor_stride_pixel) \
+    ENTRY(prefix, u32, rk_u32, offset_x) \
+    ENTRY(prefix, u32, rk_u32, offset_y) \
+    ENTRY(prefix, u32, rk_u32, poc) \
+    ENTRY(prefix, s64, rk_s64, pts) \
+    ENTRY(prefix, s64, rk_s64, dts) \
+    ENTRY(prefix, u32, rk_u32, eos) \
+    ENTRY(prefix, u32, rk_u32, color_range) \
+    ENTRY(prefix, u32, rk_u32, color_primaries) \
+    ENTRY(prefix, u32, rk_u32, color_trc) \
+    ENTRY(prefix, u32, rk_u32, colorspace) \
+    ENTRY(prefix, u32, rk_u32, chroma_location) \
+    ENTRY(prefix, u32, rk_u32, fmt) \
+    ENTRY(prefix, u32, rk_u32, buf_size) \
+    ENTRY(prefix, u32, rk_u32, is_gray)
+
+#define KMPP_FRAME_STRUCT_TABLE(ENTRY, prefix) \
+    ENTRY(prefix, shm, KmppShmPtr, meta) \
+    ENTRY(prefix, shm, KmppShmPtr, buffer) \
+    ENTRY(prefix, st,  MppFrameRational, sar)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define KMPP_OBJ_NAME           kmpp_frame
+#define KMPP_OBJ_INTF_TYPE      KmppFrame
+#define KMPP_OBJ_ENTRY_TABLE    KMPP_FRAME_ENTRY_TABLE
+#define KMPP_OBJ_STRUCT_TABLE   KMPP_FRAME_STRUCT_TABLE
+#include "kmpp_obj_func.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__KMPP_FRAME_H__*/

+ 86 - 0
kmpp/base/inc/kmpp_frame_impl.h

@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: Apache-2.0 OR MIT */
+/*
+ * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef __KMPP_FRAME_IMPL_H__
+#define __KMPP_FRAME_IMPL_H__
+
+#include "kmpp_obj.h"
+#include "kmpp_frame.h"
+
+typedef struct KmppFrameImpl_t {
+    const char *name;
+    KmppObj obj;
+
+    /*
+     * dimension parameter for display
+     */
+    rk_u32 width;
+    rk_u32 height;
+    rk_u32 hor_stride;
+    rk_u32 ver_stride;
+    rk_u32 hor_stride_pixel;
+    rk_u32 offset_x;
+    rk_u32 offset_y;
+
+    /*
+     * poc - picture order count
+     */
+    rk_u32 poc;
+    /*
+     * pts - display time stamp
+     * dts - decode time stamp
+     */
+    rk_s64 pts;
+    rk_s64 dts;
+
+    /*
+        * eos - end of stream
+        * info_change - set when buffer resized or frame infomation changed
+        */
+    rk_u32 eos;
+    MppFrameColorRange color_range;
+    MppFrameColorPrimaries color_primaries;
+    MppFrameColorTransferCharacteristic color_trc;
+
+    /**
+     * YUV colorspace type.
+     * It must be accessed using av_frame_get_colorspace() and
+     * av_frame_set_colorspace().
+     * - encoding: Set by user
+     * - decoding: Set by libavcodec
+     */
+    MppFrameColorSpace colorspace;
+    MppFrameChromaLocation chroma_location;
+
+    MppFrameFormat fmt;
+
+    MppFrameRational sar;
+
+    /*
+     * buffer information
+     * NOTE: buf_size only access internally
+     */
+    KmppShmPtr buffer;
+    size_t buf_size;
+    /*
+     * frame buffer compression (FBC) information
+     *
+     * NOTE: some constraint on fbc data
+     * 1. FBC config need two addresses but only one buffer.
+     *    The second address should be represented by base + offset form.
+     * 2. FBC has header address and payload address
+     *    Both addresses should be 4K aligned.
+     * 3. The header section size is default defined by:
+     *    header size = aligned(aligned(width, 16) * aligned(height, 16) / 16, 4096)
+     * 4. The stride in header section is defined by:
+     *    stride = aligned(width, 16)
+     */
+    rk_u32 fbc_offset;
+    rk_u32 is_gray;
+
+    KmppShmPtr meta;
+} KmppFrameImpl;
+
+#endif /* __KMPP_FRAME_IMPL_H__ */

+ 19 - 7
kmpp/base/inc/kmpp_obj.h

@@ -182,6 +182,7 @@ extern "C" {
 rk_s32 kmpp_objdef_get(KmppObjDef *def, const char *name);
 rk_s32 kmpp_objdef_put(KmppObjDef def);
 
+rk_s32 kmpp_objdef_get_entry(KmppObjDef def, const char *name, KmppEntry **tbl);
 rk_s32 kmpp_objdef_dump(KmppObjDef def);
 
 /* mpp objcet internal element set / get function */
@@ -190,12 +191,19 @@ rk_s32 kmpp_objdef_get_entry_size(KmppObjDef def);
 MppTrie kmpp_objdef_get_trie(KmppObjDef def);
 
 /* import kernel object ref */
-rk_s32 kmpp_obj_get(KmppObj *obj, KmppObjDef def);
-rk_s32 kmpp_obj_get_by_name(KmppObj *obj, const char *name);
-rk_s32 kmpp_obj_get_by_sptr(KmppObj *obj, KmppShmPtr *sptr);
-rk_s32 kmpp_obj_put(KmppObj obj);
+rk_s32 kmpp_obj_get(KmppObj *obj, KmppObjDef def, const char *caller);
+rk_s32 kmpp_obj_get_by_name(KmppObj *obj, const char *name, const char *caller);
+rk_s32 kmpp_obj_get_by_sptr(KmppObj *obj, KmppShmPtr *sptr, const char *caller);
+rk_s32 kmpp_obj_put(KmppObj obj, const char *caller);
 rk_s32 kmpp_obj_check(KmppObj obj, const char *caller);
-rk_s32 kmpp_obj_ioctl(KmppObj obj, rk_s32 cmd, KmppObj in, KmppObj out);
+rk_s32 kmpp_obj_ioctl(KmppObj obj, rk_s32 cmd, KmppObj in, KmppObj out, const char *caller);
+
+#define kmpp_obj_get_f(obj, def)                kmpp_obj_get(obj, def, __FUNCTION__)
+#define kmpp_obj_get_by_name_f(obj, name)       kmpp_obj_get_by_name(obj, name, __FUNCTION__)
+#define kmpp_obj_get_by_sptr_f(obj, sptr)       kmpp_obj_get_by_sptr(obj, sptr, __FUNCTION__)
+#define kmpp_obj_put_f(obj)                     kmpp_obj_put(obj, __FUNCTION__)
+#define kmpp_obj_check_f(obj)                   kmpp_obj_check(obj, __FUNCTION__)
+#define kmpp_obj_ioctl_f(obj, cmd, in, out)     kmpp_obj_ioctl(obj, cmd, in, out, __FUNCTION__)
 
 /* KmppShmPtr is the kernel share object userspace base address for kernel ioctl */
 KmppShmPtr *kmpp_obj_to_shm(KmppObj obj);
@@ -206,9 +214,9 @@ const char *kmpp_obj_get_name(KmppObj obj);
  * entry is the userspace address for kernel share object body
  * entry = KmppShmPtr->uaddr + entry_offset
  */
-void *kmpp_obj_get_entry(KmppObj obj);
+void *kmpp_obj_to_entry(KmppObj obj);
 /* offset is the entry offset from kernel share object body */
-rk_s32 kmpp_obj_get_offset(KmppObj obj, const char *name);
+rk_s32 kmpp_obj_to_offset(KmppObj obj, const char *name);
 
 /* value access function */
 rk_s32 kmpp_obj_set_s32(KmppObj obj, const char *name, rk_s32 val);
@@ -256,6 +264,10 @@ rk_s32 kmpp_obj_tbl_get_shm(KmppObj obj, KmppEntry *tbl, KmppShmPtr *val);
 rk_s32 kmpp_obj_set_shm_obj(KmppObj obj, const char *name, KmppObj val);
 rk_s32 kmpp_obj_get_shm_obj(KmppObj obj, const char *name, KmppObj *val);
 
+/* update flag check function */
+rk_s32 kmpp_obj_test(KmppObj obj, const char *name);
+rk_s32 kmpp_obj_tbl_test(KmppObj obj, KmppEntry *tbl);
+
 /* run a callback function */
 rk_s32 kmpp_obj_run(KmppObj obj, const char *name);
 /* dump by userspace */

+ 103 - 13
kmpp/base/inc/kmpp_obj_func.h

@@ -3,29 +3,119 @@
  * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
  */
 
-#ifndef KMPP_OBJ_FUNC_PREFIX
-#error "KMPP_OBJ_FUNC_PREFIX must be defined on using kmpp_idef_begin.h"
+#ifndef KMPP_OBJ_NAME
+#error "KMPP_OBJ_NAME must be defined on using kmpp_obj_func.h"
 #endif
 
 #ifndef KMPP_OBJ_INTF_TYPE
-#error "KMPP_OBJ_INTF_TYPE must be defined on using kmpp_idef_begin.h"
+#error "KMPP_OBJ_INTF_TYPE must be defined on using kmpp_obj_func.h"
 #endif
 
-#ifndef KMPP_OBJ_ENTRY_TABLE
-#error "KMPP_OBJ_ENTRY_TABLE must be defined on using kmpp_idef_begin.h"
+#ifndef KMPP_OBJ_CONCAT2
+#define KMPP_OBJ_CONCAT2(a, b)          a##_##b
+#endif
+#ifndef KMPP_OBJ_CONCAT3
+#define KMPP_OBJ_CONCAT3(a, b, c)       a##_##b##_##c
+#endif
+#ifndef KMPP_OBJ_CONCAT4
+#define KMPP_OBJ_CONCAT4(a, b, c, d)    a##_##b##_##c##_##d
 #endif
 
-#define KMPP_OBJ_FUNC(x, y, z)  x##y##z
+#define KMPP_OBJ_FUNC_DEFINE(prefix) \
+rk_s32 KMPP_OBJ_CONCAT2(prefix, size)(void); \
+rk_s32 KMPP_OBJ_CONCAT2(prefix, get)(KMPP_OBJ_INTF_TYPE *p); \
+rk_s32 KMPP_OBJ_CONCAT2(prefix, put)(KMPP_OBJ_INTF_TYPE p); \
+rk_s32 KMPP_OBJ_CONCAT2(prefix, dump)(KMPP_OBJ_INTF_TYPE p, const char *caller);
 
-#define ENTRY_TO_DECLARE(ftype, type, f1) \
-    rk_s32 KMPP_OBJ_FUNC(KMPP_OBJ_FUNC_PREFIX, _set_, f1)(KMPP_OBJ_INTF_TYPE p, type  val); \
-    rk_s32 KMPP_OBJ_FUNC(KMPP_OBJ_FUNC_PREFIX, _get_, f1)(KMPP_OBJ_INTF_TYPE p, type* val);
+KMPP_OBJ_FUNC_DEFINE(KMPP_OBJ_NAME)
 
-KMPP_OBJ_ENTRY_TABLE(ENTRY_TO_DECLARE)
+/* simple entry access funcitons */
+#ifdef KMPP_OBJ_ENTRY_TABLE
+#define ENTRY_TO_DECLARE(prefix, ftype, type, f1, ...) \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, set, f1)(KMPP_OBJ_INTF_TYPE p, type  val); \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, get, f1)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, test, f1)(KMPP_OBJ_INTF_TYPE p);
+
+KMPP_OBJ_ENTRY_TABLE(ENTRY_TO_DECLARE, KMPP_OBJ_NAME)
 
-#undef KMPP_OBJ_FUNC_PREFIX
-#undef KMPP_OBJ_INTF_TYPE
 #undef KMPP_OBJ_ENTRY_TABLE
+#undef ENTRY_TO_DECLARE
+#endif
+
+/* simple entry read-only access funcitons */
+#ifdef KMPP_OBJ_ENTRY_RO_TABLE
+#define ENTRY_TO_DECLARE(prefix, ftype, type, f1, ...) \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, get, f1)(KMPP_OBJ_INTF_TYPE p, type* val);
 
+KMPP_OBJ_ENTRY_RO_TABLE(ENTRY_TO_DECLARE, KMPP_OBJ_NAME)
+
+#undef KMPP_OBJ_ENTRY_RO_TABLE
 #undef ENTRY_TO_DECLARE
-#undef KMPP_OBJ_FUNC
+#endif
+
+/* structure entry access funcitons */
+#ifdef KMPP_OBJ_STRUCT_TABLE
+#define STRUCT_TO_DECLARE(prefix, ftype, type, f1, ...) \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, set, f1)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, get, f1)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, test, f1)(KMPP_OBJ_INTF_TYPE p);
+
+KMPP_OBJ_STRUCT_TABLE(STRUCT_TO_DECLARE, KMPP_OBJ_NAME)
+
+#undef KMPP_OBJ_STRUCT_TABLE
+#undef STRUCT_TO_DECLARE
+#endif
+
+/* simple entry hook access funcitons */
+#ifdef KMPP_OBJ_ENTRY_HOOK
+#define STRUCT_TO_DECLARE(prefix, ftype, type, f1, ...) \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, set, f1)(KMPP_OBJ_INTF_TYPE p, type val); \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, get, f1)(KMPP_OBJ_INTF_TYPE p, type* val);
+
+KMPP_OBJ_ENTRY_HOOK(STRUCT_TO_DECLARE, KMPP_OBJ_NAME)
+
+#undef KMPP_OBJ_ENTRY_HOOK
+#undef STRUCT_TO_DECLARE
+#endif
+
+/* structure entry hook access funcitons */
+#ifdef KMPP_OBJ_STRUCT_HOOK
+#define STRUCT_TO_DECLARE(prefix, ftype, type, f1, ...) \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, set, f1)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT3(prefix, get, f1)(KMPP_OBJ_INTF_TYPE p, type* val);
+
+KMPP_OBJ_STRUCT_HOOK(STRUCT_TO_DECLARE, KMPP_OBJ_NAME)
+
+#undef KMPP_OBJ_STRUCT_HOOK
+#undef STRUCT_TO_DECLARE
+#endif
+
+/* internal structure simple entry access funcitons */
+#ifdef KMPP_OBJ_ENTRY_TABLE2
+#define ENTRY_TO_DECLARE(prefix, ftype, type, f1, f2, ...) \
+    rk_s32 KMPP_OBJ_CONCAT4(prefix, set, f1, f2)(KMPP_OBJ_INTF_TYPE p, type  val); \
+    rk_s32 KMPP_OBJ_CONCAT4(prefix, get, f1, f2)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT4(prefix, test, f1, f2)(KMPP_OBJ_INTF_TYPE p);
+
+KMPP_OBJ_ENTRY_TABLE2(ENTRY_TO_DECLARE, KMPP_OBJ_NAME)
+
+#undef KMPP_OBJ_ENTRY_TABLE2
+#undef ENTRY_TO_DECLARE
+#endif
+
+/* internal structure entry access funcitons */
+#ifdef KMPP_OBJ_STRUCT_TABLE2
+#define ENTRY_TO_DECLARE(prefix, ftype, type, f1, f2, ...) \
+    rk_s32 KMPP_OBJ_CONCAT4(prefix, set, f1, f2)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT4(prefix, get, f1, f2)(KMPP_OBJ_INTF_TYPE p, type* val); \
+    rk_s32 KMPP_OBJ_CONCAT4(prefix, test, f1, f2)(KMPP_OBJ_INTF_TYPE p);
+
+KMPP_OBJ_STRUCT_TABLE2(ENTRY_TO_DECLARE, KMPP_OBJ_NAME)
+
+#undef KMPP_OBJ_STRUCT_TABLE2
+#undef ENTRY_TO_DECLARE
+#endif
+
+#undef KMPP_OBJ_NAME
+#undef KMPP_OBJ_INTF_TYPE
+#undef KMPP_OBJ_FUNC_DEFINE

+ 258 - 54
kmpp/base/inc/kmpp_obj_helper.h

@@ -3,80 +3,284 @@
  * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
  */
 
-#if defined(KMPP_OBJ_HERLPER_EXIST)
-#error "can not include kmpp_obj_helper.h twice"
+#ifndef __KMPP_OBJ_HERLPER_H__
+#define __KMPP_OBJ_HERLPER_H__
+
+#if !defined(KMPP_OBJ_NAME) || \
+    !defined(KMPP_OBJ_INTF_TYPE) || \
+    !defined(KMPP_OBJ_IMPL_TYPE)
+
+#warning "When using kmpp_obj_helper.h The following macro must be defined:"
+#warning "KMPP_OBJ_NAME                 - object name"
+#warning "KMPP_OBJ_INTF_TYPE            - object interface type"
+#warning "KMPP_OBJ_IMPL_TYPE            - object implement type"
+#warning "option macro:"
+#warning "KMPP_OBJ_ENTRY_TABLE          - object element value / pointer entry table"
+#warning "KMPP_OBJ_STRUCT_TABLE         - object element structure / array / share memory table"
+#warning "KMPP_OBJ_ENTRY_TABLE2         - object element value / pointer entry 2 level table"
+#warning "KMPP_OBJ_STRUCT_TABLE2        - object element structure / array / share memory 2 level table"
+#warning "KMPP_OBJ_FUNC_IOCTL           - object element ioctl cmd and function table"
+#warning "KMPP_OBJ_FUNC_STUB_ENABLE     - enable function stub mode by define empty function"
+
+#ifndef KMPP_OBJ_NAME
+#error "KMPP_OBJ_NAME not defined"
+#endif
+#ifndef KMPP_OBJ_INTF_TYPE
+#error "KMPP_OBJ_INTF_TYPE not defined"
+#endif
+#ifndef KMPP_OBJ_IMPL_TYPE
+#error "KMPP_OBJ_IMPL_TYPE not defined"
 #endif
 
-#define KMPP_OBJ_HERLPER_EXIST
+#else /* all input macro defined */
 
-#if defined(KMPP_OBJ_IMPL_TYPE) && defined(KMPP_OBJ_IMPL_DEF)
+#include <linux/stddef.h>
 
-/*
- * macro for register structure fiedl to trie
- * type     -> struct base type
- * f1       -> struct:field1        name segment 1 the field1 part
- * f2       -> struct:field1:field2 name segment 2 the field2 part
- * ftype    -> field type as EntryType
- */
-#define FIELD_TO_LOCTBL_FLAG1(f1, ftype, field_flag, flag_value) \
+#define KMPP_OBJ_TO_STR(x)      #x
+#define KMPP_OBJ_DEF(x)         x##_def
+#define KMPP_OBJ_DEF_NAME(x)    KMPP_OBJ_TO_STR(x)
+
+#ifndef KMPP_OBJ_ENTRY_TABLE
+#define KMPP_OBJ_ENTRY_TABLE(ENTRY, prefix)
+#endif
+#ifndef KMPP_OBJ_ENTRY_RO_TABLE
+#define KMPP_OBJ_ENTRY_RO_TABLE(ENTRY, prefix)
+#endif
+#ifndef KMPP_OBJ_STRUCT_TABLE
+#define KMPP_OBJ_STRUCT_TABLE(ENTRY, prefix)
+#endif
+#ifndef KMPP_OBJ_ENTRY_TABLE2
+#define KMPP_OBJ_ENTRY_TABLE2(ENTRY, prefix)
+#endif
+#ifndef KMPP_OBJ_STRUCT_TABLE2
+#define KMPP_OBJ_STRUCT_TABLE2(ENTRY, prefix)
+#endif
+
+#define ENTRY_QUERY(prefix, ftype, type, f1, ...) \
+    do { \
+        kmpp_objdef_get_entry(KMPP_OBJ_DEF(prefix), #f1, &tbl_##prefix##_##f1); \
+    } while (0);
+
+#define ENTRY_QUERY2(prefix, ftype, type, f1, f2, ...) \
+    do { \
+        kmpp_objdef_get_entry(KMPP_OBJ_DEF(prefix), #f1":"#f2, &tbl_##prefix##_##f1##_##f2); \
+    } while (0);
+
+#define KMPP_OBJ_FUNC2(a, b)        a##_##b
+#define KMPP_OBJ_FUNC3(a, b, c)     a##_##b##_##c
+#define KMPP_OBJ_FUNC4(a, b, c, d)  a##_##b##_##c##_##d
+
+#if defined(KMPP_OBJ_FUNC_IOCTL)
+#define KMPP_OBJ_ADD_IOCTL(x)       kmpp_objdef_add_ioctl(KMPP_OBJ_DEF(x), &KMPP_OBJ_FUNC_IOCTL)
+#else
+#define KMPP_OBJ_ADD_IOCTL(x)
+#endif
+
+#include <string.h>
+#include "mpp_debug.h"
+
+#define KMPP_OBJ_ENTRY_FUNC(prefix, ftype, type, field, ...) \
+    static KmppEntry *tbl_##prefix##_##field = NULL; \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, get, field)(KMPP_OBJ_INTF_TYPE s, type *v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##field) \
+            ret = kmpp_obj_tbl_get_##ftype(s, tbl_##prefix##_##field, v); \
+        else \
+            *v = ((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->field; \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, set, field)(KMPP_OBJ_INTF_TYPE s, type v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##field) \
+            ret = kmpp_obj_tbl_set_##ftype(s, tbl_##prefix##_##field, v); \
+        else \
+            ((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->field = v; \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, test, field)(KMPP_OBJ_INTF_TYPE s) \
     { \
-        .data_offset = offsetof(KMPP_OBJ_IMPL_TYPE, f1), \
-        .data_size = sizeof(((KMPP_OBJ_IMPL_TYPE *)0)->f1), \
-        .data_type = ENTRY_TYPE_##ftype, \
-        .flag_offset = offsetof(KMPP_OBJ_IMPL_TYPE, field_flag), \
-        .flag_value = flag_value, \
+        if (kmpp_obj_check(s, __FUNCTION__)) return 0; \
+        return kmpp_obj_tbl_test(s, tbl_##prefix##_##field); \
     }
 
-#define FIELD_TO_LOCTBL_ACCESS1(f1, ftype) \
+#define KMPP_OBJ_ENTRY_RO_FUNC(prefix, ftype, type, field, ...) \
+    static KmppEntry *tbl_##prefix##_##field = NULL; \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, get, field)(KMPP_OBJ_INTF_TYPE s, type *v) \
     { \
-        .data_offset = offsetof(KMPP_OBJ_IMPL_TYPE, f1), \
-        .data_size = sizeof(((KMPP_OBJ_IMPL_TYPE *)0)->f1), \
-        .data_type = ENTRY_TYPE_##ftype, \
-        .flag_offset = 0, \
-        .flag_value = 0, \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##field) \
+            ret = kmpp_obj_tbl_get_##ftype(s, tbl_##prefix##_##field, v); \
+        else \
+            *v = ((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->field; \
+        return ret; \
     }
 
-#define ENTRY_TO_TRIE1(ftype, type, f1) \
-    do { \
-        KmppEntry tbl = FIELD_TO_LOCTBL_ACCESS1(f1, ftype); \
-        kmpp_objdef_add_entry(KMPP_OBJ_IMPL_DEF, #f1, &tbl); \
-    } while (0);
+#define KMPP_OBJ_STRUCT_FUNC(prefix, ftype, type, field, ...) \
+    static KmppEntry *tbl_##prefix##_##field = NULL; \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, get, field)(KMPP_OBJ_INTF_TYPE s, type *v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##field) \
+            ret = kmpp_obj_tbl_get_##ftype(s, tbl_##prefix##_##field, v); \
+        else \
+            memcpy(v, &((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->field, \
+                   sizeof(((KMPP_OBJ_IMPL_TYPE*)0)->field)); \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, set, field)(KMPP_OBJ_INTF_TYPE s, type *v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##field) \
+            ret = kmpp_obj_tbl_set_##ftype(s, tbl_##prefix##_##field, v); \
+        else \
+            memcpy(&((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->field, v, \
+                   sizeof(((KMPP_OBJ_IMPL_TYPE*)0)->field)); \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC3(prefix, test, field)(KMPP_OBJ_INTF_TYPE s) \
+    { \
+        if (kmpp_obj_check(s, __FUNCTION__)) return 0; \
+        return kmpp_obj_tbl_test(s, tbl_##prefix##_##field); \
+    }
 
-#define FIELD_TO_LOCTBL_FLAG2(f1, f2, ftype, field_flag, flag_value) \
+#define KMPP_OBJ_ENTRY_FUNC2(prefix, ftype, type, f1, f2, ...) \
+    static KmppEntry *tbl_##prefix##_##f1##_##f2 = NULL; \
+    rk_s32 KMPP_OBJ_FUNC4(prefix, get, f1, f2)(KMPP_OBJ_INTF_TYPE s, type *v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##f1##_##f2) \
+            ret = kmpp_obj_tbl_get_##ftype(s, tbl_##prefix##_##f1##_##f2, v); \
+        else \
+            *v = ((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->f1.f2; \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC4(prefix, set, f1, f2)(KMPP_OBJ_INTF_TYPE s, type v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##f1##_##f2) \
+            ret = kmpp_obj_tbl_set_##ftype(s, tbl_##prefix##_##f1##_##f2, v); \
+        else \
+            ((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->f1.f2 = v; \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC4(prefix, test, f1, f2)(KMPP_OBJ_INTF_TYPE s) \
     { \
-        .data_offset = offsetof(KMPP_OBJ_IMPL_TYPE, f1.f2), \
-        .data_size = sizeof(((KMPP_OBJ_IMPL_TYPE *)0)->f1.f2), \
-        .data_type = ENTRY_TYPE_##ftype, \
-        .flag_offset = offsetof(KMPP_OBJ_IMPL_TYPE, field_flag), \
-        .flag_value = flag_value, \
+        if (kmpp_obj_check(s, __FUNCTION__)) return 0; \
+        return kmpp_obj_tbl_test(s, tbl_##prefix##_##f1##_##f2); \
     }
 
-#define FIELD_TO_LOCTBL_ACCESS2(f1, f2, ftype) \
+#define KMPP_OBJ_STRUCT_FUNC2(prefix, ftype, type, f1, f2, ...) \
+    static KmppEntry *tbl_##prefix##_##f1##_##f2 = NULL; \
+    rk_s32 KMPP_OBJ_FUNC4(prefix, get, f1, f2)(KMPP_OBJ_INTF_TYPE s, type *v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##f1##_##f2) \
+            ret = kmpp_obj_tbl_get_##ftype(s, tbl_##prefix##_##f1##_##f2, v); \
+        else \
+            memcpy(v, &((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->f1.f2, \
+                   sizeof(((KMPP_OBJ_IMPL_TYPE*)0)->f1.f2)); \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC4(prefix, set, f1, f2)(KMPP_OBJ_INTF_TYPE s, type *v) \
+    { \
+        rk_s32 ret = kmpp_obj_check(s, __FUNCTION__); \
+        if (ret) return ret; \
+        if (tbl_##prefix##_##f1##_##f2) \
+            ret = kmpp_obj_tbl_set_##ftype(s, tbl_##prefix##_##f1##_##f2, v); \
+        else \
+            memcpy(&((KMPP_OBJ_IMPL_TYPE*)kmpp_obj_to_entry(s))->f1.f2, v, \
+                   sizeof(((KMPP_OBJ_IMPL_TYPE*)0)->f1.f2)); \
+        return ret; \
+    } \
+    rk_s32 KMPP_OBJ_FUNC4(prefix, test, f1, f2)(KMPP_OBJ_INTF_TYPE s) \
     { \
-        .data_offset = offsetof(KMPP_OBJ_IMPL_TYPE, f1.f2), \
-        .data_size = sizeof(((KMPP_OBJ_IMPL_TYPE *)0)->f1.f2), \
-        .data_type = ENTRY_TYPE_##ftype, \
-        .flag_offset = 0, \
-        .flag_value = 0, \
+        if (kmpp_obj_check(s, __FUNCTION__)) return 0; \
+        return kmpp_obj_tbl_test(s, tbl_##prefix##_##f1##_##f2); \
     }
 
-#define ENTRY_TO_TRIE2(ftype, type, f1, f2) \
-    do { \
-        KmppEntry tbl = FIELD_TO_LOCTBL_ACCESS2(KMPP_OBJ_IMPL_TYPE, f1, f2, ftype); \
-        kmpp_objdef_add_entry(KMPP_OBJ_IMPL_DEF, #f1":"#f2, &tbl); \
-    } while (0);
+#define KMPP_OBJS_USAGE_SET(prefix) \
+static KmppObjDef KMPP_OBJ_DEF(prefix) = NULL; \
+KMPP_OBJ_ENTRY_TABLE(KMPP_OBJ_ENTRY_FUNC, prefix) \
+KMPP_OBJ_ENTRY_RO_TABLE(KMPP_OBJ_ENTRY_RO_FUNC, prefix) \
+KMPP_OBJ_STRUCT_TABLE(KMPP_OBJ_STRUCT_FUNC, prefix) \
+KMPP_OBJ_ENTRY_TABLE2(KMPP_OBJ_ENTRY_FUNC2, prefix) \
+KMPP_OBJ_STRUCT_TABLE2(KMPP_OBJ_STRUCT_FUNC2, prefix) \
+rk_s32 KMPP_OBJ_FUNC2(prefix, init)(void) __attribute__((constructor)); \
+rk_s32 KMPP_OBJ_FUNC2(prefix, init)(void) \
+{ \
+    kmpp_objdef_get(&KMPP_OBJ_DEF(prefix), KMPP_OBJ_DEF_NAME(KMPP_OBJ_INTF_TYPE)); \
+    if (!KMPP_OBJ_DEF(prefix)) { \
+        mpp_loge_f(#prefix " init failed\n"); \
+        return rk_nok; \
+    } \
+    KMPP_OBJ_ADD_IOCTL(prefix); \
+    KMPP_OBJ_ENTRY_TABLE(ENTRY_QUERY, prefix) \
+    KMPP_OBJ_ENTRY_RO_TABLE(ENTRY_QUERY, prefix) \
+    KMPP_OBJ_STRUCT_TABLE(ENTRY_QUERY, prefix) \
+    KMPP_OBJ_ENTRY_TABLE2(ENTRY_QUERY2, prefix) \
+    KMPP_OBJ_STRUCT_TABLE2(ENTRY_QUERY2, prefix) \
+    return rk_ok; \
+} \
+rk_s32 KMPP_OBJ_FUNC2(prefix, deinit)(void) __attribute__((destructor)); \
+rk_s32 KMPP_OBJ_FUNC2(prefix, deinit)(void) \
+{ \
+    KmppObjDef def = __sync_fetch_and_and(&KMPP_OBJ_DEF(prefix), NULL); \
+    return kmpp_objdef_put(def); \
+} \
+rk_s32 KMPP_OBJ_FUNC2(prefix, size)(void) \
+{ \
+    return kmpp_objdef_get_entry_size(KMPP_OBJ_DEF(prefix)); \
+} \
+rk_s32 KMPP_OBJ_FUNC2(prefix, get)(KMPP_OBJ_INTF_TYPE *obj) \
+{ \
+    return kmpp_obj_get_f((KmppObj *)obj, KMPP_OBJ_DEF(prefix)); \
+} \
+rk_s32 KMPP_OBJ_FUNC2(prefix, put)(KMPP_OBJ_INTF_TYPE obj) \
+{ \
+    return kmpp_obj_put_f(obj); \
+} \
+rk_s32 KMPP_OBJ_FUNC2(prefix, dump)(KMPP_OBJ_INTF_TYPE obj, const char *caller) \
+{ \
+    return kmpp_obj_udump_f(obj, caller); \
+}
 
-#else
+KMPP_OBJS_USAGE_SET(KMPP_OBJ_NAME);
+
+#undef KMPP_OBJ_TO_STR
+#undef KMPP_OBJ_DEF
+
+#undef KMPP_OBJ_NAME
+#undef KMPP_OBJ_INTF_TYPE
+#undef KMPP_OBJ_IMPL_TYPE
+#undef KMPP_OBJ_ENTRY_TABLE
+#undef KMPP_OBJ_ENTRY_RO_TABLE
+#undef KMPP_OBJ_STRUCT_TABLE
+#undef KMPP_OBJ_ENTRY_TABLE2
+#undef KMPP_OBJ_STRUCT_TABLE2
+#undef KMPP_OBJ_FUNC_IOCTL
 
-#define FIELD_TO_LOCTBL_FLAG1(f1, ftype, field_flag, flag_value)
-#define FIELD_TO_LOCTBL_ACCESS1(f1, ftype)
-#define ENTRY_TO_TRIE1(ftype, type, f1)
-#define FIELD_TO_LOCTBL_FLAG2(f1, f2, ftype, field_flag, flag_value)
-#define FIELD_TO_LOCTBL_ACCESS2(f1, f2, ftype)
-#define ENTRY_TO_TRIE2(ftype, type, f1, f2)
+#undef KMPP_OBJ_FUNC2
+#undef KMPP_OBJ_FUNC3
+#undef KMPP_OBJ_FUNC4
+#undef KMPP_OBJ_ENTRY_FUNC
+#undef KMPP_OBJ_ENTRY_RO_FUNC
+#undef KMPP_OBJ_ENTRY_FUNC2
+#undef KMPP_OBJ_STRUCT_FUNC
+#undef KMPP_OBJ_STRUCT_FUNC2
+#undef KMPP_OBJ_ADD_IOCTL
 
-#error "use kmpp_obj_helper.h need macro KMPP_OBJ_IMPL_TYPE and KMPP_OBJ_IMPL_DEF as input"
+#undef __KMPP_OBJ_HERLPER_H__
 
 #endif
 
-#undef KMPP_OBJ_HERLPER_EXIST
+#endif /* __KMPP_OBJ_HERLPER_H__ */

+ 19 - 0
kmpp/base/kmpp_frame.c

@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: Apache-2.0 OR MIT */
+/*
+ * Copyright (c) 2025 Rockchip Electronics Co., Ltd.
+ */
+
+#define MODULE_TAG "kmpp_frame"
+
+#include "kmpp_frame_impl.h"
+
+#define KMPP_OBJ_NAME               kmpp_frame
+#define KMPP_OBJ_INTF_TYPE          KmppFrame
+#define KMPP_OBJ_IMPL_TYPE          KmppFrameImpl
+#define KMPP_OBJ_ENTRY_TABLE        KMPP_FRAME_ENTRY_TABLE
+#define KMPP_OBJ_STRUCT_TABLE       KMPP_FRAME_STRUCT_TABLE
+#define KMPP_OBJ_FUNC_INIT          kmpp_frame_impl_init
+#define KMPP_OBJ_FUNC_DEINIT        kmpp_frame_impl_deinit
+#define KMPP_OBJ_FUNC_EXPORT_ENABLE
+#define KMPP_OBJ_SHARE_ENABLE
+#include "kmpp_obj_helper.h"

+ 133 - 78
kmpp/base/kmpp_obj.c

@@ -98,12 +98,11 @@ typedef struct KmppObjDefImpl_t {
     rk_s32 index;
     rk_s32 ref_cnt;
     rk_s32 entry_size;
-    const char *name_check;            /* for object name address check */
     const char *name;
 } KmppObjDefImpl;
 
 typedef struct KmppObjImpl_t {
-    const char *name_check;
+    const char *name;
     /* class infomation link */
     KmppObjDefImpl *def;
     /* trie for fast access */
@@ -169,7 +168,7 @@ const char *strof_entry_type(EntryType type)
                 obj_dbg_set("%p + %x set " #type " keep   " #log_str "\n", entry, tbl->tbl.elem_offset, old); \
             } \
         } \
-        return MPP_OK; \
+        return rk_ok; \
     } \
     rk_s32 kmpp_obj_impl_get_##type(KmppEntry *tbl, void *entry, base_type *val) \
     { \
@@ -177,9 +176,9 @@ const char *strof_entry_type(EntryType type)
             base_type *src = ENTRY_TO_##type##_PTR(tbl, entry); \
             obj_dbg_get("%p + %x get " #type " value  " #log_str "\n", entry, tbl->tbl.elem_offset, src[0]); \
             val[0] = src[0]; \
-            return MPP_OK; \
+            return rk_ok; \
         } \
-        return MPP_NOK; \
+        return rk_nok; \
     }
 
 MPP_OBJ_ACCESS_IMPL(s32, rk_s32, % d)
@@ -198,7 +197,7 @@ MPP_OBJ_ACCESS_IMPL(fp, void *, % p)
             /* simple copy */ \
             obj_dbg_set("%p + %x set " #type " size %d change %p -> %p\n", entry, tbl->tbl.elem_offset, tbl->tbl.elem_size, dst, val); \
             memcpy(dst, val, tbl->tbl.elem_size); \
-            return MPP_OK; \
+            return rk_ok; \
         } \
         /* copy with flag check and updata */ \
         if (memcmp(dst, val, tbl->tbl.elem_size)) { \
@@ -209,7 +208,7 @@ MPP_OBJ_ACCESS_IMPL(fp, void *, % p)
         } else { \
             obj_dbg_set("%p + %x set " #type " size %d keep   %p\n", entry, tbl->tbl.elem_offset, tbl->tbl.elem_size, dst); \
         } \
-        return MPP_OK; \
+        return rk_ok; \
     } \
     rk_s32 kmpp_obj_impl_get_##type(KmppEntry *tbl, void *entry, base_type *val) \
     { \
@@ -217,9 +216,9 @@ MPP_OBJ_ACCESS_IMPL(fp, void *, % p)
             void *src = ENTRY_TO_##type##_PTR(tbl, entry); \
             obj_dbg_get("%p + %x get " #type " size %d value  " #log_str "\n", entry, tbl->tbl.elem_offset, tbl->tbl.elem_size, src); \
             memcpy(val, src, tbl->tbl.elem_size); \
-            return MPP_OK; \
+            return rk_ok; \
         } \
-        return MPP_NOK; \
+        return rk_nok; \
     }
 
 MPP_OBJ_STRUCT_ACCESS_IMPL(st, void, % p)
@@ -381,7 +380,7 @@ __failed:
 rk_s32 kmpp_objdef_put(KmppObjDef def)
 {
     KmppObjDefImpl *impl = (KmppObjDefImpl *)def;
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (impl) {
         impl->ref_cnt--;
@@ -393,7 +392,7 @@ rk_s32 kmpp_objdef_put(KmppObjDef def)
             }
         }
 
-        ret = MPP_OK;
+        ret = rk_ok;
     }
 
     return ret;
@@ -406,7 +405,7 @@ rk_s32 kmpp_objdef_get(KmppObjDef *def, const char *name)
 
     if (!def || !name || !p) {
         mpp_loge_f("invalid param def %p name %p objs %p\n", def, name, p);
-        return MPP_NOK;
+        return rk_nok;
     }
 
     *def = NULL;
@@ -414,7 +413,7 @@ rk_s32 kmpp_objdef_get(KmppObjDef *def, const char *name)
     info = mpp_trie_get_info(p->trie, name);
     if (!info) {
         mpp_loge_f("failed to get objdef %s\n", name);
-        return MPP_NOK;
+        return rk_nok;
     }
 
     if (p->count > 0 && info->index < (RK_U32)p->count) {
@@ -423,13 +422,34 @@ rk_s32 kmpp_objdef_get(KmppObjDef *def, const char *name)
         impl->ref_cnt++;
         *def = impl;
 
-        return MPP_OK;
+        return rk_ok;
     }
 
     mpp_loge_f("failed to get objdef %s index %d max %d\n",
                name, info->index, p->count);
 
-    return MPP_NOK;
+    return rk_nok;
+}
+
+rk_s32 kmpp_objdef_get_entry(KmppObjDef def, const char *name, KmppEntry **tbl)
+{
+    KmppObjDefImpl *impl = (KmppObjDefImpl *)def;
+    rk_s32 ret = rk_nok;
+
+    if (impl->trie) {
+        MppTrieInfo *info = mpp_trie_get_info(impl->trie, name);
+
+        if (info) {
+            *tbl = (KmppEntry *)mpp_trie_info_ctx(info);
+            ret = rk_ok;
+        }
+    }
+
+    if (ret)
+        mpp_loge_f("class %s get entry %s failed ret %d\n",
+                   impl ? impl->name : NULL, name, ret);
+
+    return ret;
 }
 
 rk_s32 kmpp_objdef_dump(KmppObjDef def)
@@ -474,10 +494,10 @@ rk_s32 kmpp_objdef_dump(KmppObjDef def)
             info = mpp_trie_get_info_next(trie, info);
         }
 
-        return MPP_OK;
+        return rk_ok;
     }
 
-    return MPP_NOK;
+    return rk_nok;
 }
 
 const char *kmpp_objdef_get_name(KmppObjDef def)
@@ -501,16 +521,16 @@ MppTrie kmpp_objdef_get_trie(KmppObjDef def)
     return impl ? impl->trie : NULL;
 }
 
-rk_s32 kmpp_obj_get(KmppObj *obj, KmppObjDef def)
+rk_s32 kmpp_obj_get(KmppObj *obj, KmppObjDef def, const char *caller)
 {
     KmppObjImpl *impl;
     KmppObjDefImpl *def_impl;
     KmppObjIocArg *ioc;
     rk_u64 uaddr;
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (!obj || !def) {
-        mpp_loge_f("invalid param obj %p def %p\n", obj, def);
+        mpp_loge_f("invalid param obj %p def %p at %s\n", obj, def, caller);
         return ret;
     }
 
@@ -518,7 +538,7 @@ rk_s32 kmpp_obj_get(KmppObj *obj, KmppObjDef def)
     def_impl = (KmppObjDefImpl *)def;
     impl = mpp_calloc(KmppObjImpl, 1);
     if (!impl) {
-        mpp_loge_f("malloc obj impl %d failed\n", sizeof(KmppObjImpl));
+        mpp_loge_f("malloc obj impl %d failed at %s\n", sizeof(KmppObjImpl), caller);
         return ret;
     }
 
@@ -530,66 +550,71 @@ rk_s32 kmpp_obj_get(KmppObj *obj, KmppObjDef def)
 
     ret = ioctl(objs->fd, KMPP_SHM_IOC_GET_SHM, ioc);
     if (ret) {
-        mpp_err("%s fd %d ioctl KMPP_SHM_IOC_GET_SHM failed\n",
-                def_impl->name, objs->fd);
+        mpp_err("%s fd %d ioctl KMPP_SHM_IOC_GET_SHM failed at %s\n",
+                def_impl->name, objs->fd, caller);
         mpp_free(impl);
         return ret;
     }
 
     uaddr = ioc->obj_sptr[0].uaddr;
-    impl->name_check = def_impl->name_check;
+    impl->name = def_impl->name;
     impl->def = def;
     impl->trie = def_impl->trie;
     impl->need_free = 1;
     impl->shm = U64_TO_PTR(uaddr);
     impl->entry = U64_TO_PTR(uaddr + objs->entry_offset);
 
+    obj_dbg_flow("get obj %s - %p entry [u:k] %llx:%llx at %s\n", def_impl->name,
+                 impl, uaddr, ioc->obj_sptr[0].kaddr, caller);
+
     /* write userspace object address to share memory userspace private value */
     *(RK_U64 *)U64_TO_PTR(uaddr + objs->priv_offset) = (RK_U64)(intptr_t)impl;
 
     *obj = impl;
 
-    return MPP_OK;
+    return rk_ok;
 }
 
-rk_s32 kmpp_obj_get_by_name(KmppObj *obj, const char *name)
+rk_s32 kmpp_obj_get_by_name(KmppObj *obj, const char *name, const char *caller)
 {
     KmppObjs *p = objs;
     MppTrieInfo *info = NULL;
 
     if (!obj || !name || !p) {
-        mpp_loge_f("invalid param obj %p name %p objs %p\n", obj, name, p);
-        return MPP_NOK;
+        mpp_loge_f("invalid param obj %p name %p objs %p at %s\n",
+                   obj, name, p, caller);
+        return rk_nok;
     }
 
     info = mpp_trie_get_info(p->trie, name);
     if (!info) {
-        mpp_loge_f("failed to get objdef %s\n", name);
-        return MPP_NOK;
+        mpp_loge_f("failed to get objdef %s at %s\n", name, caller);
+        return rk_nok;
     }
 
     if (p->count > 0 && info->index < (RK_U32)p->count) {
         KmppObjDefImpl *impl = &p->defs[info->index];
 
         /* NOTE: do NOT increase ref_cnt here */
-        return kmpp_obj_get(obj, impl);
+        return kmpp_obj_get(obj, impl, caller);
     }
 
-    mpp_loge_f("failed to get objdef %s index %d max %d\n",
-               name, info->index, p->count);
+    mpp_loge_f("failed to get objdef %s index %d max %d at %s\n",
+               name, info->index, p->count, caller);
 
-    return MPP_NOK;
+    return rk_nok;
 }
 
-rk_s32 kmpp_obj_get_by_sptr(KmppObj *obj, KmppShmPtr *sptr)
+rk_s32 kmpp_obj_get_by_sptr(KmppObj *obj, KmppShmPtr *sptr, const char *caller)
 {
     KmppObjImpl *impl;
     KmppObjDefImpl *def;
     rk_u8 *uptr = sptr ? sptr->uptr : NULL;
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (!obj || !sptr || !uptr) {
-        mpp_loge_f("invalid param obj %p sptr %p uptr %p\n", obj, sptr, uptr);
+        mpp_loge_f("invalid param obj %p sptr %p uptr %p at %s\n",
+                   obj, sptr, uptr, caller);
         return ret;
     }
 
@@ -600,46 +625,50 @@ rk_s32 kmpp_obj_get_by_sptr(KmppObj *obj, KmppShmPtr *sptr)
         char *p;
 
         if (!val) {
-            mpp_loge_f("invalid obj name offset %d\n", val);
+            mpp_loge_f("invalid obj name offset %d at %s\n", val, caller);
             return ret;
         }
 
         p = (char *)objs->root + val;
         kmpp_objdef_get((KmppObjDef *)&def, p);
         if (!def) {
-            mpp_loge_f("failed to get objdef %p - %s\n", p, p);
+            mpp_loge_f("failed to get objdef %p - %s at %s\n", p, p, caller);
             return ret;
         }
     }
 
     impl = mpp_calloc(KmppObjImpl, 1);
     if (!impl) {
-        mpp_loge_f("malloc obj impl %d failed\n", sizeof(KmppObjImpl));
+        mpp_loge_f("malloc obj impl %d failed at %s\n", sizeof(KmppObjImpl), caller);
         return ret;
     }
 
-    impl->name_check = def->name_check;
+    impl->name = def->name;
     impl->def = def;
     impl->trie = def->trie;
     impl->need_free = 1;
     impl->shm = (KmppShmPtr *)uptr;
     impl->entry = uptr + objs->entry_offset;
 
+    obj_dbg_flow("get obj %s - %p by sptr [u:k] %llx:%llx at %s\n", def->name,
+                 impl, sptr->uaddr, sptr->kaddr, caller);
+
     /* write userspace object address to share memory userspace private value */
     *(RK_U64 *)U64_TO_PTR(sptr->uaddr + objs->priv_offset) = (RK_U64)(intptr_t)impl;
 
     *obj = impl;
 
-    return MPP_OK;
+    return rk_ok;
 }
 
-rk_s32 kmpp_obj_put(KmppObj obj)
+rk_s32 kmpp_obj_put(KmppObj obj, const char *caller)
 {
     if (obj) {
         KmppObjImpl *impl = (KmppObjImpl *)obj;
 
         if (impl->shm) {
             KmppObjIocArg *ioc = alloca(sizeof(KmppObjIocArg) + sizeof(KmppShmPtr));
+            KmppObjDefImpl *def = impl->def;
             rk_s32 ret;
 
             ioc->count = 1;
@@ -647,9 +676,12 @@ rk_s32 kmpp_obj_put(KmppObj obj)
             ioc->obj_sptr[0].uaddr = impl->shm->uaddr;
             ioc->obj_sptr[0].kaddr = impl->shm->kaddr;
 
+            obj_dbg_flow("put obj %s - %p entry [u:k] %llx:%llx at %s\n", def ? def->name : NULL,
+                         impl, impl->shm->uaddr, impl->shm->kaddr, caller);
+
             ret = ioctl(objs->fd, KMPP_SHM_IOC_PUT_SHM, ioc);
             if (ret)
-                mpp_err("ioctl KMPP_SHM_IOC_PUT_SHM failed ret %d\n", ret);
+                mpp_err("ioctl KMPP_SHM_IOC_PUT_SHM failed ret %d at %s\n", ret, caller);
 
             impl->shm = NULL;
         }
@@ -657,10 +689,10 @@ rk_s32 kmpp_obj_put(KmppObj obj)
         if (impl->need_free)
             mpp_free(impl);
 
-        return MPP_OK;
+        return rk_ok;
     }
 
-    return MPP_NOK;
+    return rk_nok;
 }
 
 rk_s32 kmpp_obj_check(KmppObj obj, const char *caller)
@@ -669,20 +701,19 @@ rk_s32 kmpp_obj_check(KmppObj obj, const char *caller)
 
     if (!impl) {
         mpp_loge_f("from %s failed for NULL arg\n", caller);
-        return MPP_NOK;
+        return rk_nok;
     }
 
-    if (!impl->name_check || !impl->def ||
-        impl->name_check != impl->def->name_check) {
+    if (!impl->name || !impl->def || impl->name != impl->def->name) {
         mpp_loge_f("from %s failed for name check %s but %s\n", caller,
-                   impl->def ? impl->def->name_check : NULL, impl->name_check);
-        return MPP_NOK;
+                   impl->def ? impl->def->name : NULL, impl->name);
+        return rk_nok;
     }
 
-    return MPP_OK;
+    return rk_ok;
 }
 
-rk_s32 kmpp_obj_ioctl(KmppObj obj, rk_s32 cmd, KmppObj in, KmppObj out)
+rk_s32 kmpp_obj_ioctl(KmppObj obj, rk_s32 cmd, KmppObj in, KmppObj out, const char *caller)
 {
     KmppObjIocArg *ioc_arg;
     KmppObjImpl *ioc = NULL;
@@ -690,16 +721,16 @@ rk_s32 kmpp_obj_ioctl(KmppObj obj, rk_s32 cmd, KmppObj in, KmppObj out)
     rk_s32 ret;
     rk_s32 fd;
 
-    ret = kmpp_obj_get_by_name((KmppObj *)&ioc, "KmppIoc");
+    ret = kmpp_obj_get_by_name((KmppObj *)&ioc, "KmppIoc", caller);
     if (ret) {
         mpp_loge("failed to get KmppIoc ret %d\n", ret);
-        return MPP_NOK;
+        return rk_nok;
     }
 
     fd = open("/dev/kmpp_ioctl", O_RDWR);
     if (fd < 0) {
         mpp_loge("failed to open /dev/kmpp_ioctl ret %d\n", fd);
-        return MPP_NOK;
+        return rk_nok;
     }
 
     ioc_arg = alloca(sizeof(KmppObjIocArg) + sizeof(KmppShmPtr));
@@ -735,7 +766,7 @@ rk_s32 kmpp_obj_ioctl(KmppObj obj, rk_s32 cmd, KmppObj in, KmppObj out)
 
     ret = ioctl(fd, 0, ioc_arg);
 
-    kmpp_obj_put(ioc);
+    kmpp_obj_put(ioc, caller);
 
     close(fd);
 
@@ -770,14 +801,14 @@ const char *kmpp_obj_get_name(KmppObj obj)
     return NULL;
 }
 
-void *kmpp_obj_get_entry(KmppObj obj)
+void *kmpp_obj_to_entry(KmppObj obj)
 {
     KmppObjImpl *impl = (KmppObjImpl *)obj;
 
     return impl ? impl->entry : NULL;
 }
 
-rk_s32 kmpp_obj_get_offset(KmppObj obj, const char *name)
+rk_s32 kmpp_obj_to_offset(KmppObj obj, const char *name)
 {
     KmppObjImpl *impl = (KmppObjImpl *)obj;
 
@@ -806,7 +837,7 @@ rk_s32 kmpp_obj_get_offset(KmppObj obj, const char *name)
     rk_s32 kmpp_obj_set_##type(KmppObj obj, const char *name, base_type val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl->trie) { \
             MppTrieInfo *info = mpp_trie_get_info(impl->trie, name); \
             if (info) { \
@@ -822,7 +853,7 @@ rk_s32 kmpp_obj_get_offset(KmppObj obj, const char *name)
     rk_s32 kmpp_obj_get_##type(KmppObj obj, const char *name, base_type *val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl->trie) { \
             MppTrieInfo *info = mpp_trie_get_info(impl->trie, name); \
             if (info) { \
@@ -848,7 +879,7 @@ MPP_OBJ_ACCESS(fp, void *)
     rk_s32 kmpp_obj_set_##type(KmppObj obj, const char *name, base_type *val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl->trie) { \
             MppTrieInfo *info = mpp_trie_get_info(impl->trie, name); \
             if (info) { \
@@ -864,7 +895,7 @@ MPP_OBJ_ACCESS(fp, void *)
     rk_s32 kmpp_obj_get_##type(KmppObj obj, const char *name, base_type *val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl->trie) { \
             MppTrieInfo *info = mpp_trie_get_info(impl->trie, name); \
             if (info) { \
@@ -885,7 +916,7 @@ MPP_OBJ_STRUCT_ACCESS(shm, KmppShmPtr)
     rk_s32 kmpp_obj_tbl_set_##type(KmppObj obj, KmppEntry *tbl, base_type val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl) \
             ret = kmpp_obj_impl_set_##type(tbl, impl->entry, val); \
         if (ret) \
@@ -896,7 +927,7 @@ MPP_OBJ_STRUCT_ACCESS(shm, KmppShmPtr)
     rk_s32 kmpp_obj_tbl_get_##type(KmppObj obj, KmppEntry *tbl, base_type *val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl) \
             ret = kmpp_obj_impl_get_##type(tbl, impl->entry, val); \
         if (ret) \
@@ -917,7 +948,7 @@ MPP_OBJ_TBL_ACCESS(fp, void *)
     rk_s32 kmpp_obj_tbl_set_##type(KmppObj obj, KmppEntry *tbl, base_type *val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl) \
             ret = kmpp_obj_impl_set_##type(tbl, impl->entry, val); \
         if (ret) \
@@ -928,7 +959,7 @@ MPP_OBJ_TBL_ACCESS(fp, void *)
     rk_s32 kmpp_obj_tbl_get_##type(KmppObj obj, KmppEntry *tbl, base_type *val) \
     { \
         KmppObjImpl *impl = (KmppObjImpl *)obj; \
-        rk_s32 ret = MPP_NOK; \
+        rk_s32 ret = rk_nok; \
         if (impl) \
             ret = kmpp_obj_impl_get_##type(tbl, impl->entry, val); \
         if (ret) \
@@ -942,7 +973,7 @@ MPP_OBJ_STRUCT_TBL_ACCESS(shm, KmppShmPtr)
 
 rk_s32 kmpp_obj_set_shm_obj(KmppObj obj, const char *name, KmppObj val)
 {
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (!obj || !name || !val) {
         mpp_loge_f("obj %p set shm obj %s to %p failed invalid param\n",
@@ -962,7 +993,7 @@ rk_s32 kmpp_obj_set_shm_obj(KmppObj obj, const char *name, KmppObj val)
 
 rk_s32 kmpp_obj_get_shm_obj(KmppObj obj, const char *name, KmppObj *val)
 {
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (!obj || !name || !val) {
         mpp_loge_f("obj %p get shm obj %s to %p failed invalid param\n",
@@ -977,13 +1008,37 @@ rk_s32 kmpp_obj_get_shm_obj(KmppObj obj, const char *name, KmppObj *val)
         if (ret || !sptr.uptr) {
             mpp_loge_f("obj %p get shm %s failed ret %d\n", impl, name, ret);
         } else {
-            ret = kmpp_obj_get_by_sptr(val, &sptr);
+            ret = kmpp_obj_get_by_sptr(val, &sptr, __FUNCTION__);
         }
     }
 
     return ret;
 }
 
+rk_s32 kmpp_obj_test(KmppObj obj, const char *name)
+{
+    KmppObjImpl *impl = (KmppObjImpl *)obj;
+
+    if (impl && impl->trie) {
+        MppTrieInfo *info = mpp_trie_get_info(impl->trie, name);
+
+        if (info) {
+            KmppEntry *tbl = (KmppEntry *)mpp_trie_info_ctx(info);
+
+            return ENTRY_TEST_FLAG(tbl, impl->entry);;
+        }
+    }
+
+    return 0;
+}
+
+rk_s32 kmpp_obj_tbl_test(KmppObj obj, KmppEntry *tbl)
+{
+    KmppObjImpl *impl = (KmppObjImpl *)obj;
+
+    return (impl && tbl) ? ENTRY_TEST_FLAG(tbl, impl->entry) : 0;
+}
+
 static rk_s32 kmpp_obj_impl_run(rk_s32 (*run)(void *ctx), void *ctx)
 {
     return run(ctx);
@@ -992,7 +1047,7 @@ static rk_s32 kmpp_obj_impl_run(rk_s32 (*run)(void *ctx), void *ctx)
 rk_s32 kmpp_obj_run(KmppObj obj, const char *name)
 {
     KmppObjImpl *impl = (KmppObjImpl *)obj;
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (impl->trie) {
         MppTrieInfo *info = mpp_trie_get_info(impl->trie, name);
@@ -1018,12 +1073,12 @@ rk_s32 kmpp_obj_udump_f(KmppObj obj, const char *caller)
     MppTrie trie = NULL;
     MppTrieInfo *info = NULL;
     const char *name = NULL;
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
     RK_S32 i = 0;
 
     if (!impl || !def) {
         mpp_loge_f("invalid obj %p def %p\n", impl, def);
-        return MPP_NOK;
+        return rk_nok;
     }
 
     trie = impl->trie;
@@ -1188,25 +1243,25 @@ rk_s32 kmpp_obj_udump_f(KmppObj obj, const char *caller)
             } break;
             default : {
                 mpp_loge("%-2d - %-16s found invalid type %d\n", idx, name, tbl->tbl.elem_type);
-                ret = MPP_NOK;
+                ret = rk_nok;
             } break;
             }
         }
         info = mpp_trie_get_info_next(trie, info);
     }
 
-    return ret ? MPP_NOK : MPP_OK;
+    return ret ? rk_nok : rk_ok;
 }
 
 rk_s32 kmpp_obj_kdump_f(KmppObj obj, const char *caller)
 {
     KmppObjImpl *impl = (KmppObjImpl *)obj;
     KmppObjDefImpl *def = impl ? impl->def : NULL;
-    rk_s32 ret = MPP_NOK;
+    rk_s32 ret = rk_nok;
 
     if (!impl || !def) {
         mpp_loge_f("invalid obj %p def %p\n", impl, def);
-        return MPP_NOK;
+        return rk_nok;
     }
 
     mpp_logi("dump obj %-12s - %p at %s by kernel\n", def->name, impl, caller);
@@ -1215,5 +1270,5 @@ rk_s32 kmpp_obj_kdump_f(KmppObj obj, const char *caller)
     if (ret)
         mpp_err("ioctl KMPP_SHM_IOC_DUMP failed ret %d\n", ret);
 
-    return ret ? MPP_NOK : MPP_OK;
+    return ret ? rk_nok : rk_ok;
 }

+ 3 - 5
kmpp/base/kmpp_venc_cfg.c

@@ -96,7 +96,7 @@ MPP_RET kmpp_venc_cfg_init(KmppVenccfg *cfg, MppVencKcfgType type)
     }
     pthread_mutex_unlock(&lock);
 
-    kmpp_obj_get(&obj, kcfg_defs[type]);
+    kmpp_obj_get_f(&obj, kcfg_defs[type]);
 
     *cfg = obj;
 
@@ -128,7 +128,7 @@ MPP_RET kmpp_venc_cfg_init_by_name(KmppVenccfg *cfg, const char *name)
 
     mpp_env_get_u32("venc_kcfg_debug", &venc_kcfg_debug, 0);
 
-    kmpp_obj_get(&obj, kcfg_defs[type]);
+    kmpp_obj_get_f(&obj, kcfg_defs[type]);
 
     *cfg = obj;
 
@@ -144,9 +144,7 @@ MPP_RET kmpp_venc_cfg_deinit(KmppVenccfg cfg)
         return MPP_ERR_NULL_PTR;
     }
 
-    kmpp_obj_put(obj);
-
-    return MPP_OK;
+    return kmpp_obj_put_f(obj);
 }
 
 #define KMPP_VENC_CFG_ACCESS(set_type, get_type, cfg_type) \

+ 12 - 12
kmpp/base/test/kmpp_obj_test.c

@@ -42,7 +42,7 @@ static rk_s32 kmpp_obj_std_test(const char *name, rk_u32 flag)
     if (flag & TEST_DEF_DUMP)
         kmpp_objdef_dump(def);
 
-    ret = kmpp_obj_get(&obj, def);
+    ret = kmpp_obj_get_f(&obj, def);
     if (ret) {
         mpp_log("kmpp_obj_get %s failed ret %d\n", name, ret);
         goto done;
@@ -53,7 +53,7 @@ static rk_s32 kmpp_obj_std_test(const char *name, rk_u32 flag)
     if (flag & TEST_OBJ_KDUMP)
         kmpp_obj_kdump(obj);
 
-    ret = kmpp_obj_put(obj);
+    ret = kmpp_obj_put_f(obj);
     if (ret) {
         mpp_log("kmpp_obj_put %s failed\n", name);
         goto done;
@@ -69,7 +69,7 @@ static rk_s32 kmpp_obj_std_test(const char *name, rk_u32 flag)
 
 done:
     if (obj)
-        kmpp_obj_put(obj);
+        kmpp_obj_put_f(obj);
     if (def)
         kmpp_objdef_put(def);
 
@@ -81,7 +81,7 @@ static rk_s32 kmpp_obj_by_name_test(const char *name, rk_u32 flag)
     KmppObj obj = NULL;
     MPP_RET ret = MPP_NOK;
 
-    ret = kmpp_obj_get_by_name(&obj, name);
+    ret = kmpp_obj_get_by_name_f(&obj, name);
     if (ret) {
         mpp_log("kmpp_obj_get_by_name %s failed ret %d\n", name, ret);
         goto done;
@@ -92,7 +92,7 @@ static rk_s32 kmpp_obj_by_name_test(const char *name, rk_u32 flag)
     if (flag & TEST_OBJ_KDUMP)
         kmpp_obj_kdump(obj);
 
-    ret = kmpp_obj_put(obj);
+    ret = kmpp_obj_put_f(obj);
     if (ret) {
         mpp_log("kmpp_obj_put %s failed\n", name);
         goto done;
@@ -101,7 +101,7 @@ static rk_s32 kmpp_obj_by_name_test(const char *name, rk_u32 flag)
 
 done:
     if (obj)
-        kmpp_obj_put(obj);
+        kmpp_obj_put_f(obj);
 
     return ret;
 }
@@ -116,7 +116,7 @@ static rk_s32 kmpp_buffer_test(const char *name, rk_u32 flag)
     MPP_RET ret = MPP_NOK;
     rk_u32 val = 0;
 
-    ret = kmpp_obj_get_by_name(&grp, "KmppBufGrp");
+    ret = kmpp_obj_get_by_name_f(&grp, "KmppBufGrp");
     if (ret) {
         mpp_log("buf grp get obj failed ret %d\n", ret);
         goto done;
@@ -188,12 +188,12 @@ static rk_s32 kmpp_buffer_test(const char *name, rk_u32 flag)
     test_detail("object %s write parameters ready\n", kmpp_obj_get_name(grp_cfg));
 
     /* enable KmppBufGrpCfg by ioctl */
-    ret = kmpp_obj_ioctl(grp, 0, grp, NULL);
+    ret = kmpp_obj_ioctl_f(grp, 0, grp, NULL);
 
     test_detail("object %s ioctl ret %d\n", kmpp_obj_get_name(grp), ret);
 
     /* get KmppBuffer for buffer allocation */
-    ret = kmpp_obj_get_by_name(&buf, "KmppBuffer");
+    ret = kmpp_obj_get_by_name_f(&buf, "KmppBuffer");
     if (ret) {
         mpp_log("kmpp_obj_get_by_name failed ret %d\n", ret);
         goto done;
@@ -224,7 +224,7 @@ static rk_s32 kmpp_buffer_test(const char *name, rk_u32 flag)
     }
 
     /* enable KmppBufferCfg by ioctl */
-    ret = kmpp_obj_ioctl(buf, 0, buf, NULL);
+    ret = kmpp_obj_ioctl_f(buf, 0, buf, NULL);
 
     test_detail("object %s ioctl ret %d\n", kmpp_obj_get_name(buf), ret);
 
@@ -234,10 +234,10 @@ static rk_s32 kmpp_buffer_test(const char *name, rk_u32 flag)
 
 done:
     if (grp)
-        kmpp_obj_put(grp);
+        kmpp_obj_put_f(grp);
 
     if (buf)
-        kmpp_obj_put(buf);
+        kmpp_obj_put_f(buf);
 
     return ret;
 }