From 34779b7d74e70e72d307d54fb70c7191eeccb05c Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Tue, 29 Jan 2008 22:47:09 +0000 Subject: [PATCH] [mpp_hal]: add hal_h264d_api to mpp_hal git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@207 6e48237b-75ef-9749-8fc9-41990f28c85a --- mpp/codec/dec/h264/h264d_api.c | 2 +- mpp/codec/inc/mpp_dec.h | 1 - mpp/codec/mpp_dec.cpp | 2 +- mpp/hal/hal_task.cpp | 33 +++++++++++++++ mpp/hal/inc/hal_h264d_api.h | 2 +- mpp/hal/inc/mpp_hal.h | 5 ++- mpp/hal/mpp_hal.cpp | 63 ++++++++++++++++++++++------- mpp/hal/rkdec/h264d/hal_h264d_api.c | 24 +++++++++-- 8 files changed, 108 insertions(+), 24 deletions(-) diff --git a/mpp/codec/dec/h264/h264d_api.c b/mpp/codec/dec/h264/h264d_api.c index 43b57206..34b6a1a4 100644 --- a/mpp/codec/dec/h264/h264d_api.c +++ b/mpp/codec/dec/h264/h264d_api.c @@ -65,7 +65,7 @@ MPP_RET h264d_parser(void *decoder, MppPacket pkt, HalDecTask *task) } const MppDecParser api_h264d_parser = { - "h264d", + "h264d_parser", MPP_VIDEO_CodingAVC, 0, 0, diff --git a/mpp/codec/inc/mpp_dec.h b/mpp/codec/inc/mpp_dec.h index b6c0379f..2de2fbd6 100644 --- a/mpp/codec/inc/mpp_dec.h +++ b/mpp/codec/inc/mpp_dec.h @@ -72,7 +72,6 @@ struct MppDec_t { const MppDecParser *parser_api; void *parser_ctx; - const MppHalApi *hal_api; MppHal hal_ctx; // common resource diff --git a/mpp/codec/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp index 7d7b033d..8dc9aa1e 100644 --- a/mpp/codec/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -160,7 +160,7 @@ void *mpp_dec_hal_thread(void *data) * hal thread wait for dxva interface intput firt */ hal->lock(); - if (0 == hal_task_get_hnd(dec->tasks, 1, &task_hnd)) + if (hal_task_get_hnd(dec->tasks, 1, &task_hnd)) hal->wait(); hal->unlock(); diff --git a/mpp/hal/hal_task.cpp b/mpp/hal/hal_task.cpp index b45acdf7..d639cc03 100644 --- a/mpp/hal/hal_task.cpp +++ b/mpp/hal/hal_task.cpp @@ -36,6 +36,8 @@ struct HalTaskImpl_t { struct HalTaskGroupImpl_t { struct list_head list_unused; struct list_head list_used; + RK_U32 count_unused; + RK_U32 count_used; Mutex *lock; MppCtxType type; HalTaskImpl *node; @@ -48,6 +50,11 @@ static size_t get_task_size(HalTaskGroupImpl *group) MPP_RET hal_task_group_init(HalTaskGroup *group, MppCtxType type, RK_U32 count) { + if (NULL == group || 0 == count) { + mpp_err_f("found invalid input group %p count %d\n", group, count); + return MPP_ERR_UNKNOW; + } + HalTaskGroupImpl *p = mpp_malloc_size(HalTaskGroupImpl, sizeof(HalTaskGroupImpl) + count * sizeof(HalTaskImpl)); if (NULL == p) { @@ -67,12 +74,18 @@ MPP_RET hal_task_group_init(HalTaskGroup *group, MppCtxType type, RK_U32 count) p->node[i].group = p; list_add_tail(&p->node[i].list, &p->list_unused); } + p->count_unused = count; *group = p; return MPP_OK; } MPP_RET hal_task_group_deinit(HalTaskGroup group) { + if (NULL == group) { + mpp_err_f("found NULL input group\n"); + return MPP_ERR_NULL_PTR; + } + HalTaskGroupImpl *p = (HalTaskGroupImpl *)group; if (p->lock) { delete p->lock; @@ -84,6 +97,11 @@ MPP_RET hal_task_group_deinit(HalTaskGroup group) MPP_RET hal_task_get_hnd(HalTaskGroup group, RK_U32 used, HalTaskHnd *hnd) { + if (NULL == group || NULL == hnd) { + mpp_err_f("found NULL input group %p hnd %d\n", group, hnd); + return MPP_ERR_NULL_PTR; + } + HalTaskGroupImpl *p = (HalTaskGroupImpl *)group; Mutex::Autolock auto_lock(p->lock); struct list_head *head = (used) ? (&p->list_used) : (&p->list_unused); @@ -99,12 +117,27 @@ MPP_RET hal_task_get_hnd(HalTaskGroup group, RK_U32 used, HalTaskHnd *hnd) MPP_RET hal_task_set_used(HalTaskHnd hnd, RK_U32 used) { + if (NULL == hnd) { + mpp_err_f("found NULL input\n"); + return MPP_ERR_NULL_PTR; + } + HalTaskImpl *impl = (HalTaskImpl *)hnd; HalTaskGroupImpl *group = impl->group; Mutex::Autolock auto_lock(group->lock); struct list_head *head = (used) ? (&group->list_used) : (&group->list_unused); list_del_init(&impl->list); list_add_tail(&impl->list, head); + if (impl->used) + group->count_used--; + else + group->count_unused--; + if (used) + group->count_used++; + else + group->count_unused++; + + impl->used = used; return MPP_OK; } diff --git a/mpp/hal/inc/hal_h264d_api.h b/mpp/hal/inc/hal_h264d_api.h index 472bbaf2..80f0158a 100644 --- a/mpp/hal/inc/hal_h264d_api.h +++ b/mpp/hal/inc/hal_h264d_api.h @@ -332,7 +332,7 @@ extern "C" { extern const MppHalApi api_h264d_hal; -MPP_RET hal_h264d_init (void **hal, MppHalCfg *cfg); +MPP_RET hal_h264d_init (void *hal, MppHalCfg *cfg); MPP_RET hal_h264d_deinit (void *hal); MPP_RET hal_h264d_gen_regs(void *hal, HalTask *task); MPP_RET hal_h264d_start (void *hal, HalTask *task); diff --git a/mpp/hal/inc/mpp_hal.h b/mpp/hal/inc/mpp_hal.h index 3ecbf096..58b022ca 100644 --- a/mpp/hal/inc/mpp_hal.h +++ b/mpp/hal/inc/mpp_hal.h @@ -33,7 +33,10 @@ typedef struct MppHalCfg_t { } MppHalCfg; typedef struct { - RK_U32 ctx_size; + char *name; + MppCodingType coding; + RK_U32 ctx_size; + RK_U32 flag; MPP_RET (*init)(void *ctx, MppHalCfg *cfg); MPP_RET (*deinit)(void *ctx); diff --git a/mpp/hal/mpp_hal.cpp b/mpp/hal/mpp_hal.cpp index b6c48032..4b99ad5c 100644 --- a/mpp/hal/mpp_hal.cpp +++ b/mpp/hal/mpp_hal.cpp @@ -18,21 +18,33 @@ #include "mpp_mem.h" #include "mpp_log.h" +#include "mpp_common.h" #include "mpp.h" #include "mpp_hal.h" #include "mpp_frame_impl.h" -typedef struct { - MppCodingType mCoding; +#include "hal_h264d_api.h" - void *mHalCtx; - MppHalApi *api; +/* + * all hardware api static register here + */ +static const MppHalApi *hw_apis[] = { + &api_h264d_hal, +}; + +typedef struct { + MppCtxType type; + MppCodingType coding; + + void *ctx; + const MppHalApi *api; HalTaskGroup tasks; RK_U32 task_count; } MppHalImpl; + MPP_RET mpp_hal_init(MppHal *ctx, MppHalCfg *cfg) { if (NULL == ctx || NULL == cfg) { @@ -47,18 +59,36 @@ MPP_RET mpp_hal_init(MppHal *ctx, MppHalCfg *cfg) return MPP_ERR_MALLOC; } - cfg->task_count = 2; - MPP_RET ret = hal_task_group_init(&cfg->tasks, cfg->type, cfg->task_count); - if (ret) { - mpp_err_f("hal_task_group_init failed ret %d\n", ret); - mpp_free(p); - return MPP_ERR_MALLOC; + RK_U32 i; + for (i = 0; i < MPP_ARRAY_ELEMS(hw_apis); i++) { + if (cfg->coding == hw_apis[i]->coding) { + // TODO: task count should be considered according to hardware feature + cfg->task_count = 2; + p->type = cfg->type; + p->coding = cfg->coding; + p->api = hw_apis[i]; + p->task_count = cfg->task_count; + p->ctx = mpp_malloc_size(void, p->api->ctx_size); + p->api->init(p->ctx, cfg); + + MPP_RET ret = hal_task_group_init(&p->tasks, p->type, p->task_count); + if (ret) { + mpp_err_f("hal_task_group_init failed ret %d\n", ret); + break; + } + + cfg->tasks = p->tasks; + *ctx = p; + return MPP_OK; + } } - p->tasks = cfg->tasks; - p->task_count = cfg->task_count; - *ctx = p; - return MPP_OK; + mpp_err_f("could not found coding type %d\n", cfg->coding); + if (p->ctx) + mpp_free(p->ctx); + mpp_free(p); + + return MPP_NOK; } MPP_RET mpp_hal_deinit(MppHal ctx) @@ -69,7 +99,10 @@ MPP_RET mpp_hal_deinit(MppHal ctx) } MppHalImpl *p = (MppHalImpl*)ctx; - hal_task_group_deinit(p->tasks); + if (p->ctx) + mpp_free(p->ctx); + if (p->tasks) + hal_task_group_deinit(p->tasks); mpp_free(p); return MPP_OK; } diff --git a/mpp/hal/rkdec/h264d/hal_h264d_api.c b/mpp/hal/rkdec/h264d/hal_h264d_api.c index 7395720e..63906a5c 100644 --- a/mpp/hal/rkdec/h264d/hal_h264d_api.c +++ b/mpp/hal/rkdec/h264d/hal_h264d_api.c @@ -19,48 +19,63 @@ #include "hal_h264d_api.h" -MPP_RET hal_h264d_init(void **hal, MppHalCfg *cfg) +MPP_RET hal_h264d_init(void *hal, MppHalCfg *cfg) { + (void)hal; + (void)cfg; return MPP_OK; } MPP_RET hal_h264d_deinit(void *hal) { + (void)hal; return MPP_OK; } MPP_RET hal_h264d_gen_regs(void *hal, HalTask *task) { + (void)hal; + (void)task; return MPP_OK; } MPP_RET hal_h264d_start(void *hal, HalTask *task) { + (void)hal; + (void)task; return MPP_OK; } MPP_RET hal_h264d_wait(void *hal, HalTask *task) { + (void)hal; + (void)task; return MPP_OK; } MPP_RET hal_h264d_reset(void *hal) { + (void)hal; return MPP_OK; } MPP_RET hal_h264d_flush(void *hal) { + (void)hal; return MPP_OK; } MPP_RET hal_h264d_control(void *hal, RK_S32 cmd_type, void *param) { + (void)hal; + (void)cmd_type; + (void)param; return MPP_OK; } - - const MppHalApi api_h264d_hal = { + "h264d_rkdec", + MPP_VIDEO_CodingAVC, + 0, 0, hal_h264d_init, hal_h264d_deinit, @@ -70,4 +85,5 @@ const MppHalApi api_h264d_hal = { hal_h264d_reset, hal_h264d_flush, hal_h264d_control, -}; \ No newline at end of file +}; +