diff --git a/mpp/codec/dec/dummy/dummy_dec_api.c b/mpp/codec/dec/dummy/dummy_dec_api.c index a41149c9..03ff3af7 100644 --- a/mpp/codec/dec/dummy/dummy_dec_api.c +++ b/mpp/codec/dec/dummy/dummy_dec_api.c @@ -139,7 +139,8 @@ MPP_RET dummy_dec_prepare(void *dec, MppPacket pkt, HalDecTask *task) mpp_frame_init(&frame); mpp_frame_set_pts(frame, mpp_packet_get_pts(pkt)); mpp_buf_slot_get_unused(slots, &output); - mpp_buf_slot_set_hw_dst(slots, output, frame); + mpp_buf_slot_set_hw_use(slots, output); + mpp_buf_slot_set_frame(slots, output, frame); mpp_frame_deinit(&frame); mpp_assert(NULL == frame); diff --git a/mpp/codec/dec/h265/h265d_refs.c b/mpp/codec/dec/h265/h265d_refs.c index f74472ad..24947697 100644 --- a/mpp/codec/dec/h265/h265d_refs.c +++ b/mpp/codec/dec/h265/h265d_refs.c @@ -156,7 +156,8 @@ int mpp_hevc_set_new_ref(HEVCContext *s, MppFrame *mframe, int poc) ref->flags = HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_SHORT_REF; mpp_buf_slot_set_dpb_ref(s->slots, ref->slot_index); - mpp_buf_slot_set_hw_dst(s->slots, ref->slot_index, ref->frame); + mpp_buf_slot_set_hw_use(s->slots, ref->slot_index); + mpp_buf_slot_set_frame(s->slots, ref->slot_index, ref->frame); s->task->output = ref->slot_index; ref->sequence = s->seq_decode; diff --git a/mpp/codec/dec/h265/test/h265d_parser_test.c b/mpp/codec/dec/h265/test/h265d_parser_test.c index cc554fbd..ef6db408 100644 --- a/mpp/codec/dec/h265/test/h265d_parser_test.c +++ b/mpp/codec/dec/h265/test/h265d_parser_test.c @@ -245,7 +245,7 @@ static RK_S32 poll_task(void *hal, MppBufSlots slots, HalDecTask *dec) syn.dec = *dec; hal_h265d_wait(hal, &syn); mpp_err("dec->output = %d", dec->output); - mpp_buf_slot_clr_hw_dst(slots, dec->output); + mpp_buf_slot_clr_hw_use(slots, dec->output); for (i = 0; i < MPP_ARRAY_ELEMS(dec->refer); i++) { RK_S32 id; id = dec->refer[i]; @@ -383,7 +383,7 @@ RK_S32 hevc_parser_test(ParserDemoCmdContext_t *cmd) if (cutask->valid) { HalTaskInfo syn; syn.dec = *cutask; - mpp_buf_slot_get_hw_dst(slots, &index); + mpp_buf_slot_get_hw_use(slots, &index); if (NULL == mpp_buf_slot_get_buffer(slots, index)) { MppBuffer buffer = NULL; diff --git a/mpp/codec/inc/mpp_buf_slot.h b/mpp/codec/inc/mpp_buf_slot.h index 72b6388f..aef3a9ee 100644 --- a/mpp/codec/inc/mpp_buf_slot.h +++ b/mpp/codec/inc/mpp_buf_slot.h @@ -171,11 +171,10 @@ RK_U32 mpp_buf_slot_get_size(MppBufSlots slots); MPP_RET mpp_buf_slot_get_unused(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_set_hw_use(MppBufSlots slots, RK_U32 index); +MPP_RET mpp_buf_slot_clr_hw_use(MppBufSlots slots, RK_U32 index); +MPP_RET mpp_buf_slot_get_hw_use(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); @@ -194,6 +193,10 @@ MPP_RET mpp_buf_slot_dec_hw_ref(MppBufSlots slots, RK_U32 index); */ MPP_RET mpp_buf_slot_set_buffer(MppBufSlots slots, RK_U32 index, MppBuffer buffer); MppBuffer mpp_buf_slot_get_buffer(MppBufSlots slots, RK_U32 index); +MPP_RET mpp_buf_slot_set_frame(MppBufSlots slots, RK_U32 index, MppFrame frame); +MppFrame mpp_buf_slot_get_frame(MppBufSlots slots, RK_U32 index); + +MPP_RET mpp_buf_slot_set_display(MppBufSlots slots, RK_U32 index); MPP_RET mpp_buf_slot_get_display(MppBufSlots slots, MppFrame *frame); diff --git a/mpp/codec/mpp_buf_slot.cpp b/mpp/codec/mpp_buf_slot.cpp index ddeba72f..13b82944 100644 --- a/mpp/codec/mpp_buf_slot.cpp +++ b/mpp/codec/mpp_buf_slot.cpp @@ -54,7 +54,7 @@ static RK_U32 buf_slot_debug = 0; #define MPP_SLOT_NOT_FILLED (0x00010000) #define MPP_SLOT_USED_AS_DPB_REF (0x00020000) #define MPP_SLOT_USED_AS_DISPLAY (0x00040000) -#define MPP_SLOT_USED_AS_HW_DST (0x00080000) +#define MPP_SLOT_USED_AS_HW_USE (0x00080000) #define MPP_SLOT_WITH_FRAME (0x01000000) #define MPP_SLOT_WITH_BUFFER (0x02000000) #define MPP_SLOT_HW_REF_MASK (0x0000ffff) @@ -81,8 +81,8 @@ typedef enum MppBufSlotOps_e { SLOT_CLR_DPB_REF, SLOT_SET_DISPLAY, SLOT_CLR_DISPLAY, - SLOT_SET_HW_DST, - SLOT_CLR_HW_DST, + SLOT_SET_HW_USE, + SLOT_CLR_HW_USE, SLOT_INC_HW_REF, SLOT_DEC_HW_REF, SLOT_SET_FRAME, @@ -99,8 +99,8 @@ static const char op_string[][16] = { "clr dpb ref ", "set display ", "clr display ", - "set hw dst ", - "clr hw dst ", + "set hw use ", + "clr hw use ", "inc hw ref ", "dec hw ref ", "set frame ", @@ -132,7 +132,7 @@ typedef struct MppBufSlotsImpl_t { RK_U32 new_size; // to record current output slot index - RK_S32 output; + RK_S32 hw_use; // list for display struct list_head display; @@ -185,11 +185,11 @@ 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; + case SLOT_SET_HW_USE : { + status |= MPP_SLOT_USED_AS_HW_USE; } break; - case SLOT_CLR_HW_DST : { - status &= ~MPP_SLOT_USED_AS_HW_DST; + case SLOT_CLR_HW_USE : { + status &= ~MPP_SLOT_USED_AS_HW_USE; } break; case SLOT_INC_HW_REF : { status++; @@ -232,7 +232,7 @@ 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_DPB_REF) ? (1) : (0); - RK_U32 decoding = (slot->status & MPP_SLOT_USED_AS_HW_DST) ? (1) : (0); + RK_U32 decoding = (slot->status & MPP_SLOT_USED_AS_HW_USE) ? (1) : (0); RK_U32 display = (slot->status & MPP_SLOT_USED_AS_DISPLAY) ? (1) : (0); mpp_log("slot %2d used %d refer %d decoding %d display %d\n", @@ -493,30 +493,7 @@ 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); - slot_assert(impl, index < impl->count); - MppBufSlotEntry *slot = &impl->slots[index]; - slot_ops_with_log(impl->logs, slot, SLOT_SET_HW_DST); - - slot_assert(impl, slot->status & MPP_SLOT_NOT_FILLED); - if (NULL == slot->frame) - mpp_frame_init(&slot->frame); - - mpp_frame_copy(slot->frame, frame); - slot_ops_with_log(impl->logs, slot, SLOT_SET_FRAME); - impl->output = index; - return MPP_OK; -} - -MPP_RET mpp_buf_slot_clr_hw_dst(MppBufSlots slots, RK_U32 index) +MPP_RET mpp_buf_slot_set_hw_use(MppBufSlots slots, RK_U32 index) { if (NULL == slots) { mpp_err_f("found NULL input\n"); @@ -527,14 +504,30 @@ MPP_RET mpp_buf_slot_clr_hw_dst(MppBufSlots slots, RK_U32 index) Mutex::Autolock auto_lock(impl->lock); slot_assert(impl, index < impl->count); MppBufSlotEntry *slot = &impl->slots[index]; - slot_ops_with_log(impl->logs, slot, SLOT_CLR_HW_DST); + slot_ops_with_log(impl->logs, slot, SLOT_SET_HW_USE); + impl->hw_use = index; + return MPP_OK; +} + +MPP_RET mpp_buf_slot_clr_hw_use(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); + slot_assert(impl, index < impl->count); + MppBufSlotEntry *slot = &impl->slots[index]; + slot_ops_with_log(impl->logs, slot, SLOT_CLR_HW_USE); slot_ops_with_log(impl->logs, slot, SLOT_CLR_NOT_READY); impl->decode_count++; check_entry_unused(impl, slot); return MPP_OK; } -MPP_RET mpp_buf_slot_get_hw_dst(MppBufSlots slots, RK_U32 *index) +MPP_RET mpp_buf_slot_get_hw_use(MppBufSlots slots, RK_U32 *index) { if (NULL == slots || NULL == index) { mpp_err_f("found NULL input\n"); @@ -542,7 +535,7 @@ MPP_RET mpp_buf_slot_get_hw_dst(MppBufSlots slots, RK_U32 *index) } MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots; - *index = impl->output; + *index = impl->hw_use; return MPP_OK; } @@ -616,6 +609,40 @@ MppBuffer mpp_buf_slot_get_buffer(MppBufSlots slots, RK_U32 index) return slot->buffer; } +MPP_RET mpp_buf_slot_set_frame(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); + slot_assert(impl, index < impl->count); + MppBufSlotEntry *slot = &impl->slots[index]; + slot_assert(impl, slot->status & MPP_SLOT_NOT_FILLED); + if (NULL == slot->frame) + mpp_frame_init(&slot->frame); + + mpp_frame_copy(slot->frame, frame); + slot_ops_with_log(impl->logs, slot, SLOT_SET_FRAME); + return MPP_OK; +} + +MppFrame mpp_buf_slot_get_frame(MppBufSlots slots, RK_U32 index) +{ + if (NULL == slots) { + mpp_err_f("found NULL input\n"); + return NULL; + } + + MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots; + Mutex::Autolock auto_lock(impl->lock); + slot_assert(impl, index < impl->count); + MppBufSlotEntry *slot = &impl->slots[index]; + return slot->frame; +} + MPP_RET mpp_buf_slot_get_display(MppBufSlots slots, MppFrame *frame) { if (NULL == slots || NULL == frame) { diff --git a/mpp/codec/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp index 8aeac8db..e702f24d 100644 --- a/mpp/codec/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -35,6 +35,7 @@ void *mpp_dec_parser_thread(void *data) HalTaskGroup tasks = dec->tasks; MppPacket packet = NULL; MppBufSlots frame_slots = dec->frame_slots; + MppBufSlots packet_slots = dec->packet_slots; /* * parser thread need to wait at cases below: @@ -114,7 +115,6 @@ void *mpp_dec_parser_thread(void *data) * */ if (!curr_task_ready) { - hal_task_info_init(&task_local, MPP_CTX_DEC); parser_prepare(dec->parser, packet, task_dec); if (0 == mpp_packet_get_length(packet)) { mpp_free(mpp_packet_get_data(packet)); @@ -167,7 +167,7 @@ void *mpp_dec_parser_thread(void *data) * frame to hal loop. */ RK_U32 output; - mpp_buf_slot_get_hw_dst(frame_slots, &output); + mpp_buf_slot_get_hw_use(frame_slots, &output); if (NULL == mpp_buf_slot_get_buffer(frame_slots, output)) { MppBuffer buffer = NULL; RK_U32 size = mpp_buf_slot_get_size(frame_slots); @@ -208,6 +208,7 @@ void *mpp_dec_parser_thread(void *data) curr_task_ready = 0; curr_task_parsed = 0; prev_task_done = 0; + hal_task_info_init(&task_local, MPP_CTX_DEC); } return NULL; @@ -259,7 +260,7 @@ void *mpp_dec_hal_thread(void *data) * 3. add frame to output list * repeat 2 and 3 until not frame can be output */ - mpp_buf_slot_clr_hw_dst(frame_slots, task_dec->output); + mpp_buf_slot_clr_hw_use(frame_slots, task_dec->output); for (RK_U32 i = 0; i < MPP_ARRAY_ELEMS(task_dec->refer); i++) { RK_S32 index = task_dec->refer[i]; if (index >= 0)