mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-11 12:00:07 +08:00
[mpp_dec]: add hal flow detail to mpp_hal thread
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@225 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -103,7 +103,10 @@ MPP_RET dummy_dec_parse(void *dec, MppPacket pkt, HalDecTask *task)
|
||||
/*
|
||||
* set slots information
|
||||
* 1. output index MUST be set
|
||||
* 2. if one frame can be display, it SHOULD be set display
|
||||
* 2. get unused index for output if needed
|
||||
* 3. set output index as decoding
|
||||
* 4. set pts to output index
|
||||
* 5. if one frame can be display, it SHOULD be set display
|
||||
*/
|
||||
if (!p->slots_inited) {
|
||||
mpp_buf_slot_setup(p->slots, DUMMY_DEC_FRAME_COUNT, DUMMY_DEC_FRAME_SIZE, 0);
|
||||
@@ -111,7 +114,10 @@ MPP_RET dummy_dec_parse(void *dec, MppPacket pkt, HalDecTask *task)
|
||||
}
|
||||
|
||||
RK_S32 output = -1;
|
||||
RK_S64 pts = mpp_packet_get_pts(pkt);
|
||||
mpp_buf_slot_get_unused(p->slots, &output);
|
||||
mpp_buf_slot_set_decoding(p->slots, output);
|
||||
mpp_buf_slot_set_pts(p->slots, output, pts);
|
||||
mpp_buf_slot_set_display(p->slots, output);
|
||||
|
||||
/*
|
||||
|
@@ -50,14 +50,14 @@ static MPP_RET mpp_dec_parse(MppDec *dec, MppPacket pkt, HalDecTask *task)
|
||||
void *mpp_dec_parser_thread(void *data)
|
||||
{
|
||||
Mpp *mpp = (Mpp*)data;
|
||||
MppThread *parser = mpp->mTheadCodec;
|
||||
MppThread *parser = mpp->mThreadCodec;
|
||||
MppDec *dec = mpp->mDec;
|
||||
MppBufSlots slots = dec->slots;
|
||||
MppPacketImpl packet;
|
||||
HalTaskHnd task_hnd = NULL;
|
||||
|
||||
/*
|
||||
* parser thread need to wait at three cases:
|
||||
* parser thread need to wait at cases below:
|
||||
* 1. no task slot for output
|
||||
* 2. no packet for parsing
|
||||
* 3. info change on progress
|
||||
@@ -197,10 +197,18 @@ void *mpp_dec_hal_thread(void *data)
|
||||
Mpp *mpp = (Mpp*)data;
|
||||
MppThread *hal = mpp->mThreadHal;
|
||||
MppDec *dec = mpp->mDec;
|
||||
MppBufSlots slots = dec->slots;
|
||||
mpp_list *frames = mpp->mFrames;
|
||||
HalTaskHnd task_hnd = NULL;
|
||||
|
||||
/*
|
||||
* hal thread need to wait at cases below:
|
||||
* 1. no task slot for work
|
||||
*/
|
||||
RK_U32 wait_on_task = 0;
|
||||
|
||||
HalTask task_local;
|
||||
HalDecTask *task_dec = &task_local.dec;
|
||||
memset(&task_local, 0, sizeof(task_local));
|
||||
|
||||
while (MPP_THREAD_RUNNING == hal->get_status()) {
|
||||
@@ -208,33 +216,64 @@ void *mpp_dec_hal_thread(void *data)
|
||||
* hal thread wait for dxva interface intput firt
|
||||
*/
|
||||
hal->lock();
|
||||
if (hal_task_get_hnd(dec->tasks, 1, &task_hnd))
|
||||
if (wait_on_task)
|
||||
hal->wait();
|
||||
hal->unlock();
|
||||
|
||||
// get_config
|
||||
// register genertation
|
||||
// get hw task first
|
||||
if (NULL == task_hnd)
|
||||
hal_task_get_hnd(dec->tasks, 1, &task_hnd);
|
||||
|
||||
if (NULL == task_hnd)
|
||||
wait_on_task = (NULL == task_hnd);
|
||||
if (wait_on_task)
|
||||
continue;
|
||||
|
||||
mpp->mTaskGetCount++;
|
||||
|
||||
hal_task_get_info(dec->tasks, &task_local);
|
||||
// hal->mpp_hal_reg_gen(current);
|
||||
hal_task_set_used(task_hnd, 0);
|
||||
hal_task_get_info(task_hnd, &task_local);
|
||||
|
||||
// register genertation
|
||||
mpp_hal_reg_gen(dec->hal_ctx, &task_local);
|
||||
|
||||
/*
|
||||
* wait previous register set done
|
||||
*/
|
||||
// hal->mpp_hal_hw_wait(previous);
|
||||
//mpp_hal_hw_wait(dec->hal_ctx, &task_local);
|
||||
|
||||
/*
|
||||
* send current register set to hardware
|
||||
*/
|
||||
// hal->mpp_hal_hw_start(current);
|
||||
//mpp_hal_hw_start(dec->hal_ctx, &task_local);
|
||||
|
||||
mpp_hal_hw_start(dec->hal_ctx, &task_local);
|
||||
mpp_hal_hw_wait(dec->hal_ctx, &task_local);
|
||||
|
||||
/*
|
||||
* when hardware decoding is done:
|
||||
* 1. clear decoding flag
|
||||
* 2. create a new frame structure
|
||||
* 3. get pts and set to frame
|
||||
* 4. get buffer and set to frame
|
||||
* 5. add frame to output list
|
||||
* 6. clear display flag
|
||||
*/
|
||||
RK_S32 output = task_dec->output;
|
||||
|
||||
mpp_buf_slot_clr_decoding(slots, output);
|
||||
|
||||
MppFrame frame;
|
||||
mpp_frame_init(&frame);
|
||||
|
||||
RK_S64 pts = mpp_buf_slot_get_pts(slots, output);
|
||||
mpp_frame_set_pts(frame, pts);
|
||||
|
||||
MppBuffer buffer = mpp_buf_slot_get_buffer(slots, output);
|
||||
mpp_frame_set_buffer(frame, buffer);
|
||||
|
||||
frames->add_at_tail(&frame, sizeof(frame));
|
||||
mpp->mFramePutCount++;
|
||||
|
||||
mpp_buf_slot_clr_display(slots, output);
|
||||
|
||||
/*
|
||||
* mark previous buffer is complete
|
||||
@@ -243,16 +282,8 @@ void *mpp_dec_hal_thread(void *data)
|
||||
// signal()
|
||||
// mark frame in output queue
|
||||
// wait up output thread to get a output frame
|
||||
|
||||
// for test
|
||||
MppBuffer buffer;
|
||||
mpp_buffer_get(mpp->mFrameGroup, &buffer, MPP_TEST_FRAME_SIZE);
|
||||
|
||||
MppFrame frame;
|
||||
mpp_frame_init(&frame);
|
||||
mpp_frame_set_buffer(frame, buffer);
|
||||
frames->add_at_tail(&frame, sizeof(frame));
|
||||
mpp->mFramePutCount++;
|
||||
hal_task_set_used(task_hnd, 0);
|
||||
mpp->mThreadCodec->signal();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@@ -30,7 +30,7 @@
|
||||
void *mpp_enc_control_thread(void *data)
|
||||
{
|
||||
Mpp *mpp = (Mpp*)data;
|
||||
MppThread *thd_enc = mpp->mTheadCodec;
|
||||
MppThread *thd_enc = mpp->mThreadCodec;
|
||||
mpp_list *packets = mpp->mPackets;
|
||||
mpp_list *frames = mpp->mFrames;
|
||||
MppFrameImpl frame;
|
||||
|
@@ -73,7 +73,7 @@ MPP_RET hal_dummy_dec_control(void *hal, RK_S32 cmd_type, void *param)
|
||||
}
|
||||
|
||||
const MppHalApi hal_api_dummy_dec = {
|
||||
"dummy_dec",
|
||||
"dummy_hw_dec",
|
||||
MPP_CTX_DEC,
|
||||
MPP_VIDEO_CodingUnused,
|
||||
0,
|
||||
|
@@ -73,7 +73,7 @@ MPP_RET hal_dummy_enc_control(void *hal, RK_S32 cmd_type, void *param)
|
||||
}
|
||||
|
||||
const MppHalApi hal_api_dummy_enc = {
|
||||
"dummy_enc_rkdec",
|
||||
"dummy_hw_enc",
|
||||
MPP_CTX_ENC,
|
||||
MPP_VIDEO_CodingUnused,
|
||||
0,
|
||||
|
@@ -30,6 +30,7 @@ struct HalTaskImpl_t {
|
||||
struct list_head list;
|
||||
HalTaskGroupImpl *group;
|
||||
RK_U32 used;
|
||||
RK_U32 index;
|
||||
HalTask task;
|
||||
};
|
||||
|
||||
@@ -38,8 +39,8 @@ struct HalTaskGroupImpl_t {
|
||||
struct list_head list_used;
|
||||
RK_U32 count_unused;
|
||||
RK_U32 count_used;
|
||||
Mutex *lock;
|
||||
MppCtxType type;
|
||||
Mutex *lock;
|
||||
HalTaskImpl *node;
|
||||
};
|
||||
|
||||
@@ -63,7 +64,7 @@ MPP_RET hal_task_group_init(HalTaskGroup *group, MppCtxType type, RK_U32 count)
|
||||
mpp_err_f("malloc group failed\n");
|
||||
return MPP_NOK;
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
memset(p, 0, sizeof(*p) + count * sizeof(HalTaskImpl));
|
||||
INIT_LIST_HEAD(&p->list_unused);
|
||||
INIT_LIST_HEAD(&p->list_used);
|
||||
p->lock = new Mutex();
|
||||
@@ -73,6 +74,8 @@ MPP_RET hal_task_group_init(HalTaskGroup *group, MppCtxType type, RK_U32 count)
|
||||
RK_U32 i;
|
||||
for (i = 0; i < count; i++) {
|
||||
p->node[i].group = p;
|
||||
p->node[i].used = 0;
|
||||
p->node[i].index = i;
|
||||
list_add_tail(&p->node[i].list, &p->list_unused);
|
||||
}
|
||||
p->count_unused = count;
|
||||
|
@@ -104,6 +104,7 @@ MPP_RET mpp_hal_deinit(MppHal ctx)
|
||||
}
|
||||
|
||||
MppHalImpl *p = (MppHalImpl*)ctx;
|
||||
p->api->deinit(p->ctx);
|
||||
mpp_free(p->ctx);
|
||||
if (p->tasks)
|
||||
hal_task_group_deinit(p->tasks);
|
||||
|
24
mpp/mpp.cpp
24
mpp/mpp.cpp
@@ -46,7 +46,7 @@ Mpp::Mpp(MppCtxType type, MppCodingType coding)
|
||||
mInternalGroup(NULL),
|
||||
mPacketGroup(NULL),
|
||||
mFrameGroup(NULL),
|
||||
mTheadCodec(NULL),
|
||||
mThreadCodec(NULL),
|
||||
mThreadHal(NULL),
|
||||
mType(type),
|
||||
mCoding(coding),
|
||||
@@ -61,7 +61,7 @@ Mpp::Mpp(MppCtxType type, MppCodingType coding)
|
||||
mTasks = new mpp_list((node_destructor)NULL);
|
||||
|
||||
mpp_dec_init(&mDec, coding);
|
||||
mTheadCodec = new MppThread(mpp_dec_parser_thread, this);
|
||||
mThreadCodec = new MppThread(mpp_dec_parser_thread, this);
|
||||
mThreadHal = new MppThread(mpp_dec_hal_thread, this);
|
||||
|
||||
mpp_buffer_group_normal_get(&mInternalGroup, MPP_BUFFER_TYPE_ION);
|
||||
@@ -75,7 +75,7 @@ Mpp::Mpp(MppCtxType type, MppCodingType coding)
|
||||
mTasks = new mpp_list((node_destructor)NULL);
|
||||
|
||||
mpp_dec_init(&mDec, coding);
|
||||
mTheadCodec = new MppThread(mpp_enc_control_thread, this);
|
||||
mThreadCodec = new MppThread(mpp_enc_control_thread, this);
|
||||
mThreadHal = new MppThread(mpp_dec_hal_thread, this);
|
||||
|
||||
mpp_buffer_group_normal_get(&mInternalGroup, MPP_BUFFER_TYPE_ION);
|
||||
@@ -89,9 +89,9 @@ Mpp::Mpp(MppCtxType type, MppCodingType coding)
|
||||
|
||||
if (mFrames && mPackets &&
|
||||
(mDec || mEnc) &&
|
||||
mTheadCodec && mThreadHal &&
|
||||
mThreadCodec && mThreadHal &&
|
||||
mPacketGroup && mFrameGroup) {
|
||||
mTheadCodec->start();
|
||||
mThreadCodec->start();
|
||||
mThreadHal->start();
|
||||
} else
|
||||
clear();
|
||||
@@ -106,14 +106,14 @@ Mpp::~Mpp ()
|
||||
|
||||
void Mpp::clear()
|
||||
{
|
||||
if (mTheadCodec)
|
||||
mTheadCodec->stop();
|
||||
if (mThreadCodec)
|
||||
mThreadCodec->stop();
|
||||
if (mThreadHal)
|
||||
mThreadHal->stop();
|
||||
|
||||
if (mTheadCodec) {
|
||||
delete mTheadCodec;
|
||||
mTheadCodec = NULL;
|
||||
if (mThreadCodec) {
|
||||
delete mThreadCodec;
|
||||
mThreadCodec = NULL;
|
||||
}
|
||||
if (mThreadHal) {
|
||||
delete mThreadHal;
|
||||
@@ -158,7 +158,7 @@ MPP_RET Mpp::put_packet(MppPacket packet)
|
||||
if (mPackets->list_size() < 4) {
|
||||
mPackets->add_at_tail(packet, sizeof(MppPacketImpl));
|
||||
mPacketPutCount++;
|
||||
mTheadCodec->signal();
|
||||
mThreadCodec->signal();
|
||||
return MPP_OK;
|
||||
}
|
||||
return MPP_NOK;
|
||||
@@ -180,7 +180,7 @@ MPP_RET Mpp::put_frame(MppFrame frame)
|
||||
Mutex::Autolock autoLock(&mFrameLock);
|
||||
if (mFrames->list_size() < 4) {
|
||||
mFrames->add_at_tail(frame, sizeof(MppFrameImpl));
|
||||
mTheadCodec->signal();
|
||||
mThreadCodec->signal();
|
||||
mFramePutCount++;
|
||||
return MPP_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user