[buf_slot]: add change buffer slot interface

1. rename set/clr ref to set/clr dpb_ref
2. rename set/clr decoding to set/clr hw_dst
3. add inc/dec hw_ref for hal task done

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@243 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-09-08 21:57:11 +00:00
parent e537d6d41a
commit 63135dea1c
4 changed files with 166 additions and 99 deletions

View File

@@ -119,7 +119,7 @@ MPP_RET dummy_dec_parse(void *dec, MppPacket pkt, HalDecTask *task)
mpp_frame_init(&frame);
mpp_frame_set_pts(frame, pts);
mpp_buf_slot_get_unused(p->slots, &output);
mpp_buf_slot_set_decoding(p->slots, output, frame);
mpp_buf_slot_set_hw_dst(p->slots, output, frame);
mpp_buf_slot_set_display(p->slots, output);
mpp_frame_deinit(&frame);
mpp_assert(NULL == frame);

View File

@@ -81,15 +81,15 @@
* typical buffer status transfer
*
* -> unused initial
* -> set_decoding by parser
* -> set_hw_dst by parser
* -> set_buffer by mpp - do alloc buffer here / info change here
* -> clr_decoding by hal()
* -> clr_hw_dst by hal()
*
* next four step can be different order
* -> set_ref by parser
* -> set_dpb_ref by parser
* -> set_display by parser - slot ready to display, can be output
* -> clr_display by mpp - output buffer struct
* -> clr_ref by parser
* -> clr_dpb_ref by parser
*
* -> set_unused automatic clear and dec buffer ref
*
@@ -132,22 +132,25 @@ RK_U32 mpp_buf_slot_get_size(MppBufSlots slots);
* mpp_buf_slot_get_unused
* - parser need a new slot ffor output, on field mode alloc one buffer for two field
*
* mpp_buf_slot_set_ref
* - mark a slot to be used as reference
* mpp_buf_slot_set_dpb_ref
* - mark a slot to be used as reference frame in dpb
*
* mpp_buf_slot_clr_ref
* - mark a slot to be unused as reference
* mpp_buf_slot_clr_dpb_ref
* - mark a slot to be unused as reference frame and remove from dpb
*
* mpp_buf_slot_set_decoding
* mpp_buf_slot_set_hw_dst
* - mark a slot to be output destination buffer
* - NOTE: the frame information MUST be set here
*
* mpp_buf_slot_set_display
* - mark a slot to be can be display
*
* mpp_buf_slot_inc_hw_ref
* - MUST be called once when one slot is used in hardware decoding as reference frame
*
* called by mpp
*
* mpp_buf_slot_get_decoding
* mpp_buf_slot_get_hw_dst
* - mpp_dec need to get the output slot index to check buffer status
*
* mpp_buf_slot_clr_display
@@ -156,18 +159,25 @@ RK_U32 mpp_buf_slot_get_size(MppBufSlots slots);
*
* called by hal
*
* mpp_buf_slot_clr_decoding
* mpp_buf_slot_clr_hw_dst
* - mark a slot's buffer is already decoded by hardware
* NOTE: this call will clear used as output flag
*
* mpp_buf_slot_dec_hw_ref
* - when hal finished on hardware decoding it MUST be called once for each used slot
*/
MPP_RET mpp_buf_slot_get_unused(MppBufSlots slots, RK_U32 *index);
MPP_RET mpp_buf_slot_set_ref(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_clr_ref(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_set_decoding(MppBufSlots slots, RK_U32 index, MppFrame frame);
MPP_RET mpp_buf_slot_clr_decoding(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_get_decoding(MppBufSlots slots, RK_U32 *index);
MPP_RET mpp_buf_slot_set_dpb_ref(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_clr_dpb_ref(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_set_display(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_set_hw_dst(MppBufSlots slots, RK_U32 index, MppFrame frame);
MPP_RET mpp_buf_slot_clr_hw_dst(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_get_hw_dst(MppBufSlots slots, RK_U32 *index);
MPP_RET mpp_buf_slot_inc_hw_ref(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_dec_hw_ref(MppBufSlots slots, RK_U32 index);
/*
* mpp_buf_slot_set_buffer
* - called by dec thread when find a output index has not buffer
@@ -179,7 +189,7 @@ MPP_RET mpp_buf_slot_set_display(MppBufSlots slots, RK_U32 index);
* - called by hal thread to output a display slot's frame info
*/
MPP_RET mpp_buf_slot_set_buffer(MppBufSlots slots, RK_U32 index, MppBuffer buffer);
MppBuffer mpp_buf_slot_get_buffer(const MppBufSlots slots, RK_U32 index);
MppBuffer mpp_buf_slot_get_buffer(MppBufSlots slots, RK_U32 index);
MPP_RET mpp_buf_slot_get_display(MppBufSlots slots, MppFrame *frame);
#ifdef __cplusplus

View File

@@ -44,16 +44,28 @@ static RK_U32 buf_slot_debug = 0;
#define MPP_SLOT_UNUSED (0x00000000)
#define MPP_SLOT_USED (0x00000001)
#define MPP_SLOT_USED_AS_REFER (0x00000002)
#define MPP_SLOT_USED_AS_DECODING (0x00000004)
#define MPP_SLOT_USED_AS_DISPLAY (0x00000008)
#define MPP_SLOT_USED (0x00010000)
#define MPP_SLOT_USED_AS_DPB_REF (0x00020000)
#define MPP_SLOT_USED_AS_DISPLAY (0x00040008)
#define MPP_SLOT_USED_AS_HW_DST (0x00080000)
#define MPP_SLOT_USED_IN_HW_MASK (0x0000ffff)
#define GET_HW_REF(slot) ((MppBufSlotEntry*)(slot)->status&MPP_SLOT_USED_IN_HW_MASK)
#define INC_HW_REF(slot) ((MppBufSlotEntry*)(slot)->status++)
#define DEC_HW_REF(slot) ((MppBufSlotEntry*)(slot)->status--)
typedef struct MppBufSlotEntry_t {
struct list_head list;
RK_U32 status;
RK_S32 index;
MppFrame frame;
/*
* used_on_decoding
* - count that indicates slot used in hardware decoding
* will be increased in parser ans decreased in hal when hardware is done
*/
RK_U32 used_on_decoding;
} MppBufSlotEntry;
#define SLOT_OPS_MAX_COUNT 1024
@@ -62,12 +74,14 @@ typedef enum MppBufSlotOps_e {
SLOT_INIT,
SLOT_SET_USED,
SLOT_CLR_USED,
SLOT_SET_REFER,
SLOT_CLR_REFER,
SLOT_SET_DECODING,
SLOT_CLR_DECODING,
SLOT_SET_DPB_REF,
SLOT_CLR_DPB_REF,
SLOT_SET_DISPLAY,
SLOT_CLR_DISPLAY,
SLOT_SET_HW_DST,
SLOT_CLR_HW_DST,
SLOT_INC_HW_REF,
SLOT_DEC_HW_REF,
SLOT_SET_BUFFER,
} MppBufSlotOps;
@@ -135,17 +149,11 @@ static void slot_ops_with_log(mpp_list *logs, MppBufSlotEntry *slot, MppBufSlotO
case SLOT_CLR_USED : {
status &= ~MPP_SLOT_USED;
} break;
case SLOT_SET_REFER : {
status |= MPP_SLOT_USED_AS_REFER;
case SLOT_SET_DPB_REF : {
status |= MPP_SLOT_USED_AS_DPB_REF;
} break;
case SLOT_CLR_REFER : {
status &= ~MPP_SLOT_USED_AS_REFER;
} break;
case SLOT_SET_DECODING : {
status |= MPP_SLOT_USED_AS_DECODING;
} break;
case SLOT_CLR_DECODING : {
status &= ~MPP_SLOT_USED_AS_DECODING;
case SLOT_CLR_DPB_REF : {
status &= ~MPP_SLOT_USED_AS_DPB_REF;
} break;
case SLOT_SET_DISPLAY : {
status |= MPP_SLOT_USED_AS_DISPLAY;
@@ -153,6 +161,18 @@ static void slot_ops_with_log(mpp_list *logs, MppBufSlotEntry *slot, MppBufSlotO
case SLOT_CLR_DISPLAY : {
status &= ~MPP_SLOT_USED_AS_DISPLAY;
} break;
case SLOT_SET_HW_DST : {
status |= MPP_SLOT_USED_AS_HW_DST;
} break;
case SLOT_CLR_HW_DST : {
status &= ~MPP_SLOT_USED_AS_HW_DST;
} break;
case SLOT_INC_HW_REF : {
status++;
} break;
case SLOT_DEC_HW_REF : {
status--;
} break;
case SLOT_SET_BUFFER : {
} break;
default : {
@@ -175,8 +195,8 @@ static void dump_slots(MppBufSlotsImpl *impl)
for (i = 0; i < impl->count; i++, slot++) {
RK_U32 used = (slot->status & MPP_SLOT_USED) ? (1) : (0);
RK_U32 refer = (slot->status & MPP_SLOT_USED_AS_REFER) ? (1) : (0);
RK_U32 decoding = (slot->status & MPP_SLOT_USED_AS_DECODING) ? (1) : (0);
RK_U32 refer = (slot->status & MPP_SLOT_USED_AS_DPB_REF) ? (1) : (0);
RK_U32 decoding = (slot->status & MPP_SLOT_USED_AS_HW_DST) ? (1) : (0);
RK_U32 display = (slot->status & MPP_SLOT_USED_AS_DISPLAY) ? (1) : (0);
RK_U32 pos = 0;
@@ -192,12 +212,14 @@ static void dump_slots(MppBufSlotsImpl *impl)
"init ",
"set used ",
"clr used ",
"set refer ",
"clr refer ",
"set decoding",
"clr decoding",
"set dpb ref ",
"clr dpb ref ",
"set display ",
"clr display ",
"set hw dst ",
"clr hw dst ",
"inc hw ref ",
"dec hw ref ",
"set buffer ",
};
while (logs->list_size()) {
@@ -395,7 +417,7 @@ MPP_RET mpp_buf_slot_get_unused(MppBufSlots slots, RK_U32 *index)
return MPP_NOK;
}
MPP_RET mpp_buf_slot_set_ref(MppBufSlots slots, RK_U32 index)
MPP_RET mpp_buf_slot_set_dpb_ref(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");
@@ -405,11 +427,11 @@ MPP_RET mpp_buf_slot_set_ref(MppBufSlots slots, RK_U32 index)
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
slot_ops_with_log(impl->logs, &impl->slots[index], SLOT_SET_REFER);
slot_ops_with_log(impl->logs, &impl->slots[index], SLOT_SET_DPB_REF);
return MPP_OK;
}
MPP_RET mpp_buf_slot_clr_ref(MppBufSlots slots, RK_U32 index)
MPP_RET mpp_buf_slot_clr_dpb_ref(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");
@@ -420,62 +442,12 @@ MPP_RET mpp_buf_slot_clr_ref(MppBufSlots slots, RK_U32 index)
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_CLR_REFER);
slot_ops_with_log(impl->logs, slot, SLOT_CLR_DPB_REF);
impl->unrefer_count++;
check_entry_unused(impl->logs, slot);
return MPP_OK;
}
MPP_RET mpp_buf_slot_set_decoding(MppBufSlots slots, RK_U32 index, MppFrame frame)
{
if (NULL == slots || NULL == frame) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_SET_DECODING);
if (NULL == slot->frame)
mpp_frame_init(&slot->frame);
memcpy(slot->frame, frame, sizeof(MppFrameImpl));
impl->output = index;
return MPP_OK;
}
MPP_RET mpp_buf_slot_clr_decoding(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_CLR_DECODING);
impl->unrefer_count++;
check_entry_unused(impl->logs, slot);
return MPP_OK;
}
MPP_RET mpp_buf_slot_get_decoding(MppBufSlots slots, RK_U32 *index)
{
if (NULL == slots || NULL == index) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
*index = impl->output;
return MPP_OK;
}
MPP_RET mpp_buf_slot_set_display(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
@@ -495,6 +467,86 @@ MPP_RET mpp_buf_slot_set_display(MppBufSlots slots, RK_U32 index)
return MPP_OK;
}
MPP_RET mpp_buf_slot_set_hw_dst(MppBufSlots slots, RK_U32 index, MppFrame frame)
{
if (NULL == slots || NULL == frame) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_SET_HW_DST);
if (NULL == slot->frame)
mpp_frame_init(&slot->frame);
memcpy(slot->frame, frame, sizeof(MppFrameImpl));
impl->output = index;
return MPP_OK;
}
MPP_RET mpp_buf_slot_clr_hw_dst(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_CLR_HW_DST);
impl->unrefer_count++;
check_entry_unused(impl->logs, slot);
return MPP_OK;
}
MPP_RET mpp_buf_slot_get_hw_dst(MppBufSlots slots, RK_U32 *index)
{
if (NULL == slots || NULL == index) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
*index = impl->output;
return MPP_OK;
}
MPP_RET mpp_buf_slot_inc_hw_ref(MppBufSlots slots, RK_U32 index)\
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_INC_HW_REF);
return MPP_OK;
}
MPP_RET mpp_buf_slot_dec_hw_ref(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");
return MPP_ERR_NULL_PTR;
}
MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots;
Mutex::Autolock auto_lock(impl->lock);
mpp_assert(index < impl->count);
MppBufSlotEntry *slot = &impl->slots[index];
slot_ops_with_log(impl->logs, slot, SLOT_DEC_HW_REF);
return MPP_OK;
}
MPP_RET mpp_buf_slot_set_buffer(MppBufSlots slots, RK_U32 index, MppBuffer buffer)
{
if (NULL == slots || NULL == buffer) {
@@ -513,7 +565,7 @@ MPP_RET mpp_buf_slot_set_buffer(MppBufSlots slots, RK_U32 index, MppBuffer buffe
return MPP_OK;
}
MppBuffer mpp_buf_slot_get_buffer(const MppBufSlots slots, RK_U32 index)
MppBuffer mpp_buf_slot_get_buffer(MppBufSlots slots, RK_U32 index)
{
if (NULL == slots) {
mpp_err_f("found NULL input\n");

View File

@@ -161,7 +161,7 @@ void *mpp_dec_parser_thread(void *data)
* frame to hal loop.
*/
RK_U32 output;
mpp_buf_slot_get_decoding(slots, &output);
mpp_buf_slot_get_hw_dst(slots, &output);
if (NULL == mpp_buf_slot_get_buffer(slots, output)) {
MppBuffer buffer = NULL;
RK_U32 size = mpp_buf_slot_get_size(slots);
@@ -248,7 +248,12 @@ void *mpp_dec_hal_thread(void *data)
* 2. use get_display to get a new frame with buffer
* 3. add frame to output list
*/
mpp_buf_slot_clr_decoding(slots, task_dec->output);
mpp_buf_slot_clr_hw_dst(slots, task_dec->output);
for (RK_S32 i = 0; i < MPP_ARRAY_ELEMS(task_dec->refer); i++) {
RK_S32 index = task_dec->refer[i];
if (index >= 0)
mpp_buf_slot_dec_hw_ref(slots, index);
}
MppFrame frame = NULL;
while (MPP_OK == mpp_buf_slot_get_display(slots, &frame)) {