mirror of
https://github.com/nyanmisaka/mpp.git
synced 2026-01-24 01:10:39 +01:00
feat[mpp_meta]: Use trie to index the meta key
Signed-off-by: Herman Chen <herman.chen@rock-chips.com> Change-Id: I634d447223e6e9d268642798a4fb0d11ad32cfb0
This commit is contained in:
parent
5b0f01d582
commit
f0ff240b87
4 changed files with 97 additions and 91 deletions
|
|
@ -42,21 +42,6 @@
|
|||
* 2. Flow control metadata
|
||||
*
|
||||
*/
|
||||
typedef enum MppMetaDataType_e {
|
||||
/*
|
||||
* mpp meta data of data flow
|
||||
* reference counter will be used for these meta data type
|
||||
*/
|
||||
TYPE_FRAME = FOURCC_META('m', 'f', 'r', 'm'),
|
||||
TYPE_PACKET = FOURCC_META('m', 'p', 'k', 't'),
|
||||
TYPE_BUFFER = FOURCC_META('m', 'b', 'u', 'f'),
|
||||
|
||||
/* mpp meta data of normal data type */
|
||||
TYPE_S32 = FOURCC_META('s', '3', '2', ' '),
|
||||
TYPE_S64 = FOURCC_META('s', '6', '4', ' '),
|
||||
TYPE_PTR = FOURCC_META('p', 't', 'r', ' '),
|
||||
} MppMetaType;
|
||||
|
||||
typedef enum MppMetaKey_e {
|
||||
/* data flow key */
|
||||
KEY_INPUT_FRAME = FOURCC_META('i', 'f', 'r', 'm'),
|
||||
|
|
|
|||
|
|
@ -22,11 +22,6 @@
|
|||
#include "mpp_list.h"
|
||||
#include "mpp_meta.h"
|
||||
|
||||
typedef struct MppMetaDef_t {
|
||||
MppMetaKey key;
|
||||
MppMetaType type;
|
||||
} MppMetaDef;
|
||||
|
||||
typedef struct MppMetaVal_t {
|
||||
RK_U32 state;
|
||||
union {
|
||||
|
|
@ -36,6 +31,7 @@ typedef struct MppMetaVal_t {
|
|||
MppFrame frame;
|
||||
MppPacket packet;
|
||||
MppBuffer buffer;
|
||||
RK_U64 val_kptr; /* kernel object userspace address */
|
||||
};
|
||||
} MppMetaVal;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "mpp_lock.h"
|
||||
|
||||
#include "mpp_meta_impl.h"
|
||||
#include "mpp_trie.h"
|
||||
|
||||
#define META_VAL_INVALID (0x00000000)
|
||||
#define META_VAL_VALID (0x00000001)
|
||||
|
|
@ -31,62 +32,87 @@
|
|||
#define WRITE_ONCE(x, val) ((*(volatile typeof(x) *) &(x)) = (val))
|
||||
#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
|
||||
|
||||
static MppMetaDef meta_defs[] = {
|
||||
typedef enum MppMetaDataType_e {
|
||||
/* mpp meta data of normal data type */
|
||||
TYPE_S32,
|
||||
TYPE_S64,
|
||||
TYPE_PTR,
|
||||
TYPE_FRAME,
|
||||
TYPE_PACKET,
|
||||
TYPE_BUFFER,
|
||||
TYPE_KPTR,
|
||||
TYPE_BUTT,
|
||||
} MppMetaType;
|
||||
|
||||
#define META_KEY_TO_U64(key, type) ((RK_U64)((RK_U32)key) | ((RK_U64)type << 32))
|
||||
|
||||
static const char *meta_type_name[] = {
|
||||
"TYPE_S32",
|
||||
"TYPE_S64",
|
||||
"TYPE_PTR",
|
||||
"TYPE_FRAME",
|
||||
"TYPE_PACKET",
|
||||
"TYPE_BUFFER",
|
||||
"TYPE_KPTR",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static RK_U64 meta_defs[] = {
|
||||
/* categorized by type */
|
||||
/* data flow type */
|
||||
{ KEY_INPUT_FRAME, TYPE_FRAME, },
|
||||
{ KEY_OUTPUT_FRAME, TYPE_FRAME, },
|
||||
{ KEY_INPUT_PACKET, TYPE_PACKET, },
|
||||
{ KEY_OUTPUT_PACKET, TYPE_PACKET, },
|
||||
META_KEY_TO_U64(KEY_INPUT_FRAME, TYPE_FRAME),
|
||||
META_KEY_TO_U64(KEY_OUTPUT_FRAME, TYPE_FRAME),
|
||||
META_KEY_TO_U64(KEY_INPUT_PACKET, TYPE_PACKET),
|
||||
META_KEY_TO_U64(KEY_OUTPUT_PACKET, TYPE_PACKET),
|
||||
/* buffer for motion detection */
|
||||
{ KEY_MOTION_INFO, TYPE_BUFFER, },
|
||||
META_KEY_TO_U64(KEY_MOTION_INFO, TYPE_BUFFER),
|
||||
/* buffer storing the HDR information for current frame*/
|
||||
{ KEY_HDR_INFO, TYPE_BUFFER, },
|
||||
META_KEY_TO_U64(KEY_HDR_INFO, TYPE_BUFFER),
|
||||
/* the offset of HDR meta data in frame buffer */
|
||||
{ KEY_HDR_META_OFFSET, TYPE_S32, },
|
||||
{ KEY_HDR_META_SIZE, TYPE_S32, },
|
||||
META_KEY_TO_U64(KEY_HDR_META_OFFSET, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_HDR_META_SIZE, TYPE_S32),
|
||||
|
||||
{ KEY_OUTPUT_INTRA, TYPE_S32, },
|
||||
{ KEY_INPUT_BLOCK, TYPE_S32, },
|
||||
{ KEY_OUTPUT_BLOCK, TYPE_S32, },
|
||||
{ KEY_INPUT_IDR_REQ, TYPE_S32, },
|
||||
META_KEY_TO_U64(KEY_OUTPUT_INTRA, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_INPUT_BLOCK, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_OUTPUT_BLOCK, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_INPUT_IDR_REQ, TYPE_S32),
|
||||
|
||||
/* extra information for tsvc */
|
||||
{ KEY_TEMPORAL_ID, TYPE_S32, },
|
||||
{ KEY_LONG_REF_IDX, TYPE_S32, },
|
||||
{ KEY_ENC_AVERAGE_QP, TYPE_S32, },
|
||||
{ KEY_ENC_START_QP, TYPE_S32, },
|
||||
{ KEY_ENC_BPS_RT, TYPE_S32, },
|
||||
META_KEY_TO_U64(KEY_TEMPORAL_ID, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LONG_REF_IDX, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_AVERAGE_QP, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_START_QP, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_BPS_RT, TYPE_S32),
|
||||
|
||||
{ KEY_ROI_DATA, TYPE_PTR, },
|
||||
{ KEY_ROI_DATA2, TYPE_PTR, },
|
||||
{ KEY_OSD_DATA, TYPE_PTR, },
|
||||
{ KEY_OSD_DATA2, TYPE_PTR, },
|
||||
{ KEY_USER_DATA, TYPE_PTR, },
|
||||
{ KEY_USER_DATAS, TYPE_PTR, },
|
||||
{ KEY_QPMAP0, TYPE_BUFFER, },
|
||||
{ KEY_MV_LIST, TYPE_PTR, },
|
||||
META_KEY_TO_U64(KEY_ROI_DATA, TYPE_PTR),
|
||||
META_KEY_TO_U64(KEY_ROI_DATA2, TYPE_PTR),
|
||||
META_KEY_TO_U64(KEY_OSD_DATA, TYPE_PTR),
|
||||
META_KEY_TO_U64(KEY_OSD_DATA2, TYPE_PTR),
|
||||
META_KEY_TO_U64(KEY_USER_DATA, TYPE_PTR),
|
||||
META_KEY_TO_U64(KEY_USER_DATAS, TYPE_PTR),
|
||||
META_KEY_TO_U64(KEY_QPMAP0, TYPE_BUFFER),
|
||||
META_KEY_TO_U64(KEY_MV_LIST, TYPE_PTR),
|
||||
|
||||
{ KEY_LVL64_INTER_NUM, TYPE_S32, },
|
||||
{ KEY_LVL32_INTER_NUM, TYPE_S32, },
|
||||
{ KEY_LVL16_INTER_NUM, TYPE_S32, },
|
||||
{ KEY_LVL8_INTER_NUM, TYPE_S32, },
|
||||
{ KEY_LVL32_INTRA_NUM, TYPE_S32, },
|
||||
{ KEY_LVL16_INTRA_NUM, TYPE_S32, },
|
||||
{ KEY_LVL8_INTRA_NUM, TYPE_S32, },
|
||||
{ KEY_LVL4_INTRA_NUM, TYPE_S32, },
|
||||
{ KEY_INPUT_PSKIP, TYPE_S32, },
|
||||
{ KEY_OUTPUT_PSKIP, TYPE_S32, },
|
||||
{ KEY_ENC_SSE, TYPE_S64, },
|
||||
META_KEY_TO_U64(KEY_LVL64_INTER_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL32_INTER_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL16_INTER_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL8_INTER_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL32_INTRA_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL16_INTRA_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL8_INTRA_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_LVL4_INTRA_NUM, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_INPUT_PSKIP, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_OUTPUT_PSKIP, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_SSE, TYPE_S64),
|
||||
|
||||
{ KEY_ENC_MARK_LTR, TYPE_S32, },
|
||||
{ KEY_ENC_USE_LTR, TYPE_S32, },
|
||||
{ KEY_ENC_FRAME_QP, TYPE_S32, },
|
||||
{ KEY_ENC_BASE_LAYER_PID, TYPE_S32, },
|
||||
META_KEY_TO_U64(KEY_ENC_MARK_LTR, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_USE_LTR, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_FRAME_QP, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_ENC_BASE_LAYER_PID, TYPE_S32),
|
||||
|
||||
{ KEY_DEC_TBN_EN, TYPE_S32, },
|
||||
{ KEY_DEC_TBN_Y_OFFSET, TYPE_S32, },
|
||||
{ KEY_DEC_TBN_UV_OFFSET, TYPE_S32, },
|
||||
META_KEY_TO_U64(KEY_DEC_TBN_EN, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_DEC_TBN_Y_OFFSET, TYPE_S32),
|
||||
META_KEY_TO_U64(KEY_DEC_TBN_UV_OFFSET, TYPE_S32),
|
||||
};
|
||||
|
||||
class MppMetaService
|
||||
|
|
@ -100,6 +126,7 @@ private:
|
|||
|
||||
spinlock_t mLock;
|
||||
struct list_head mlist_meta;
|
||||
MppTrie mTrie;
|
||||
|
||||
RK_U32 meta_id;
|
||||
RK_S32 meta_count;
|
||||
|
|
@ -111,12 +138,6 @@ public:
|
|||
return &instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_index_of_key does two things:
|
||||
* 1. Check the key / type pair is correct or not.
|
||||
* If failed on check return negative value
|
||||
* 2. Compare all exsisting meta data defines to find the non-negative index
|
||||
*/
|
||||
RK_S32 get_index_of_key(MppMetaKey key, MppMetaType type);
|
||||
|
||||
MppMetaImpl *get_meta(const char *tag, const char *caller);
|
||||
|
|
@ -128,8 +149,16 @@ MppMetaService::MppMetaService()
|
|||
meta_count(0),
|
||||
finished(0)
|
||||
{
|
||||
RK_U32 i;
|
||||
|
||||
mpp_spinlock_init(&mLock);
|
||||
INIT_LIST_HEAD(&mlist_meta);
|
||||
|
||||
mpp_trie_init(&mTrie, "MppMetaDef");
|
||||
for (i = 0; i < MPP_ARRAY_ELEMS(meta_defs); i++) {
|
||||
mpp_trie_add_info(mTrie, (const char *)&meta_defs[i], NULL, 0);
|
||||
}
|
||||
mpp_trie_add_info(mTrie, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
MppMetaService::~MppMetaService()
|
||||
|
|
@ -144,21 +173,21 @@ MppMetaService::~MppMetaService()
|
|||
}
|
||||
}
|
||||
|
||||
if (mTrie) {
|
||||
mpp_trie_deinit(mTrie);
|
||||
mTrie = NULL;
|
||||
}
|
||||
|
||||
mpp_assert(meta_count == 0);
|
||||
finished = 1;
|
||||
}
|
||||
|
||||
RK_S32 MppMetaService::get_index_of_key(MppMetaKey key, MppMetaType type)
|
||||
{
|
||||
RK_S32 i = 0;
|
||||
RK_S32 num = MPP_ARRAY_ELEMS(meta_defs);
|
||||
RK_U64 val = META_KEY_TO_U64(key, type);
|
||||
MppTrieInfo *info = mpp_trie_get_info(mTrie, (const char *)&val);
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
if ((meta_defs[i].key == key) && (meta_defs[i].type == type))
|
||||
break;
|
||||
}
|
||||
|
||||
return (i < num) ? (i) : (-1);
|
||||
return info ? info->index : -1;
|
||||
}
|
||||
|
||||
MppMetaImpl *MppMetaService::get_meta(const char *tag, const char *caller)
|
||||
|
|
@ -280,12 +309,10 @@ MPP_RET mpp_meta_dump(MppMeta meta)
|
|||
if (!impl->vals[i].state)
|
||||
continue;
|
||||
|
||||
const char *key = (const char *)&meta_defs[i].key;
|
||||
const char *type = (const char *)&meta_defs[i].type;
|
||||
const char *key = (const char *)&meta_defs[i];
|
||||
const char *type = (const char *)&meta_type_name[(meta_defs[i] >> 32)];
|
||||
|
||||
mpp_log("key %c%c%c%c type %c%c%c%c\n",
|
||||
key[3], key[2], key[1], key[0],
|
||||
type[3], type[2], type[1], type[0]);
|
||||
mpp_log("key %c%c%c%c type %s\n", key[3], key[2], key[1], key[0], type);
|
||||
}
|
||||
|
||||
return MPP_OK;
|
||||
|
|
@ -298,8 +325,7 @@ MPP_RET mpp_meta_dump(MppMeta meta)
|
|||
mpp_err_f("found NULL input\n"); \
|
||||
return MPP_ERR_NULL_PTR; \
|
||||
} \
|
||||
MppMetaService *service = MppMetaService::get_inst(); \
|
||||
RK_S32 index = service->get_index_of_key(key, key_type); \
|
||||
RK_S32 index = MppMetaService::get_inst()->get_index_of_key(key, key_type); \
|
||||
if (index < 0) \
|
||||
return MPP_NOK; \
|
||||
MppMetaImpl *impl = (MppMetaImpl *)meta; \
|
||||
|
|
@ -316,8 +342,7 @@ MPP_RET mpp_meta_dump(MppMeta meta)
|
|||
mpp_err_f("found NULL input\n"); \
|
||||
return MPP_ERR_NULL_PTR; \
|
||||
} \
|
||||
MppMetaService *service = MppMetaService::get_inst(); \
|
||||
RK_S32 index = service->get_index_of_key(key, key_type); \
|
||||
RK_S32 index = MppMetaService::get_inst()->get_index_of_key(key, key_type); \
|
||||
if (index < 0) \
|
||||
return MPP_NOK; \
|
||||
MppMetaImpl *impl = (MppMetaImpl *)meta; \
|
||||
|
|
@ -336,8 +361,7 @@ MPP_RET mpp_meta_dump(MppMeta meta)
|
|||
mpp_err_f("found NULL input\n"); \
|
||||
return MPP_ERR_NULL_PTR; \
|
||||
} \
|
||||
MppMetaService *service = MppMetaService::get_inst(); \
|
||||
RK_S32 index = service->get_index_of_key(key, key_type); \
|
||||
RK_S32 index = MppMetaService::get_inst()->get_index_of_key(key, key_type); \
|
||||
if (index < 0) \
|
||||
return MPP_NOK; \
|
||||
MppMetaImpl *impl = (MppMetaImpl *)meta; \
|
||||
|
|
|
|||
|
|
@ -112,10 +112,11 @@ void *meta_test(void *param)
|
|||
ret |= mpp_meta_put(meta);
|
||||
}
|
||||
|
||||
mpp_log("meta setting and getting, ret %d\n", ret);
|
||||
|
||||
time_end = mpp_time();
|
||||
|
||||
if (ret)
|
||||
mpp_log("meta setting and getting, ret %d\n", ret);
|
||||
|
||||
*((RK_S64 *)param) = (time_end - time_start) / loop_max;
|
||||
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue