From 72a6118b99214bfa98c98170ec17a5bd668de7a4 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Wed, 9 Mar 2022 11:08:11 +0800 Subject: [PATCH] [mpp_meta]: Add mpp_meta_get with default value Change-Id: I2285ace50341792b1979130d19a3ec642346e4bc Signed-off-by: Herman Chen --- inc/mpp_meta.h | 7 +++++++ mpp/base/mpp_meta.cpp | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/inc/mpp_meta.h b/inc/mpp_meta.h index aa43eec2..47b8efb1 100644 --- a/inc/mpp_meta.h +++ b/inc/mpp_meta.h @@ -158,6 +158,13 @@ MPP_RET mpp_meta_get_frame (MppMeta meta, MppMetaKey key, MppFrame *frame); MPP_RET mpp_meta_get_packet(MppMeta meta, MppMetaKey key, MppPacket *packet); MPP_RET mpp_meta_get_buffer(MppMeta meta, MppMetaKey key, MppBuffer *buffer); +MPP_RET mpp_meta_get_s32_d(MppMeta meta, MppMetaKey key, RK_S32 *val, RK_S32 def); +MPP_RET mpp_meta_get_s64_d(MppMeta meta, MppMetaKey key, RK_S64 *val, RK_S64 def); +MPP_RET mpp_meta_get_ptr_d(MppMeta meta, MppMetaKey key, void **val, void *def); +MPP_RET mpp_meta_get_frame_d(MppMeta meta, MppMetaKey key, MppFrame *frame, MppFrame def); +MPP_RET mpp_meta_get_packet_d(MppMeta meta, MppMetaKey key, MppPacket *packet, MppPacket def); +MPP_RET mpp_meta_get_buffer_d(MppMeta meta, MppMetaKey key, MppBuffer *buffer, MppBuffer def); + #ifdef __cplusplus } #endif diff --git a/mpp/base/mpp_meta.cpp b/mpp/base/mpp_meta.cpp index f9451908..57be0b79 100644 --- a/mpp/base/mpp_meta.cpp +++ b/mpp/base/mpp_meta.cpp @@ -307,6 +307,28 @@ MPP_RET mpp_meta_dump(MppMeta meta) ret = MPP_OK; \ } \ return ret; \ + } \ + MPP_RET mpp_meta_get_##func_type##_d(MppMeta meta, MppMetaKey key, arg_type *val, arg_type def) \ + { \ + if (NULL == 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); \ + if (index < 0) \ + return MPP_NOK; \ + MppMetaImpl *impl = (MppMetaImpl *)meta; \ + MppMetaVal *meta_val = &impl->vals[index]; \ + MPP_RET ret = MPP_NOK; \ + if (MPP_BOOL_CAS(&meta_val->state, META_VAL_VALID | META_VAL_READY, META_VAL_INVALID)) { \ + *val = meta_val->key_field; \ + MPP_FETCH_SUB(&impl->node_count, 1); \ + ret = MPP_OK; \ + } else { \ + *val = def; \ + } \ + return ret; \ } MPP_META_ACCESSOR(s32, RK_S32, TYPE_S32, val_s32)