[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
This commit is contained in:
ChenHengming
2008-01-29 22:47:09 +00:00
parent 533661dd0e
commit 34779b7d74
8 changed files with 108 additions and 24 deletions

View File

@@ -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,

View File

@@ -72,7 +72,6 @@ struct MppDec_t {
const MppDecParser *parser_api;
void *parser_ctx;
const MppHalApi *hal_api;
MppHal hal_ctx;
// common resource

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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,
};
};