diff --git a/mpp/codec/inc/mpp_buf_slot.h b/mpp/codec/inc/mpp_buf_slot.h index 55739583..2cc1df3e 100644 --- a/mpp/codec/inc/mpp_buf_slot.h +++ b/mpp/codec/inc/mpp_buf_slot.h @@ -146,6 +146,9 @@ RK_U32 mpp_buf_slot_get_size(MppBufSlots slots); * * called by mpp * + * mpp_buf_slot_get_decoding + * - mpp_dec need to get the output slot index to check buffer status + * * mpp_buf_slot_clr_display * - mark a slot has been send out to display * @@ -160,6 +163,7 @@ 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); 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_display(MppBufSlots slots, RK_U32 index); MPP_RET mpp_buf_slot_clr_display(MppBufSlots slots, RK_U32 index); diff --git a/mpp/codec/mpp_buf_slot.cpp b/mpp/codec/mpp_buf_slot.cpp index 751c3fe0..92676729 100644 --- a/mpp/codec/mpp_buf_slot.cpp +++ b/mpp/codec/mpp_buf_slot.cpp @@ -33,6 +33,7 @@ typedef struct MppBufSlotEntry_t { MppBuffer buffer; RK_U32 status; + RK_S32 index; RK_S64 pts; } MppBufSlotEntry; @@ -50,6 +51,9 @@ typedef struct MppBufSlotsImpl_t { RK_U32 new_count; RK_U32 new_size; + // to record current output slot index + RK_S32 output; + MppBufSlotEntry *slots; } MppBufSlotsImpl; @@ -61,6 +65,7 @@ static void check_entry_unused(MppBufSlotEntry *entry) if (entry->status == MPP_SLOT_USED) { entry->status = MPP_SLOT_UNUSED; mpp_buffer_put(entry->buffer); + entry->buffer = NULL; } } @@ -109,6 +114,9 @@ MPP_RET mpp_buf_slot_setup(MppBufSlots slots, RK_U32 count, RK_U32 size, RK_U32 impl->slots = mpp_calloc(MppBufSlotEntry, count); impl->count = count; impl->size = size; + for (RK_U32 i = 0; i < count; i++) { + impl->slots[i].index = i; + } } else { // need to check info change or not if (!changed) { @@ -116,6 +124,9 @@ MPP_RET mpp_buf_slot_setup(MppBufSlots slots, RK_U32 count, RK_U32 size, RK_U32 if (count > impl->count) { mpp_realloc(impl->slots, MppBufSlotEntry, count); memset(&impl->slots[impl->count], 0, sizeof(MppBufSlotEntry) * (count - impl->count)); + for (RK_U32 i = 0; i < count; i++) { + impl->slots[i].index = i; + } } } else { // info changed, even size is the same we still need to wait for new configuration @@ -159,6 +170,9 @@ MPP_RET mpp_buf_slot_ready(MppBufSlots slots) if (impl->new_count > impl->count) { memset(&impl->slots[impl->count], 0, sizeof(MppBufSlotEntry) * (impl->new_count - impl->count)); } + for (RK_U32 i = 0; i < impl->new_count; i++) { + impl->slots[i].index = i; + } } impl->count = impl->new_count; return MPP_OK; @@ -243,6 +257,7 @@ MPP_RET mpp_buf_slot_set_decoding(MppBufSlots slots, RK_U32 index) MppBufSlotEntry *slot = impl->slots; mpp_assert(index < impl->count); slot[index].status |= MPP_SLOT_USED_AS_DECODING; + impl->output = index; return MPP_OK; } @@ -263,6 +278,18 @@ MPP_RET mpp_buf_slot_clr_decoding(MppBufSlots slots, RK_U32 index) 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) { diff --git a/mpp/codec/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp index 2b7a695d..b10294d4 100644 --- a/mpp/codec/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -163,7 +163,8 @@ void *mpp_dec_parser_thread(void *data) * - need buffer in different side, need to send a info change * frame to hal loop. */ - RK_S32 output = task_local.dec.output; + RK_U32 output; + mpp_buf_slot_get_decoding(slots, &output); if (NULL == mpp_buf_slot_get_buffer(slots, output)) { MppBuffer buffer = NULL; RK_U32 size = mpp_buf_slot_get_size(slots); @@ -257,7 +258,7 @@ void *mpp_dec_hal_thread(void *data) * 5. add frame to output list * 6. clear display flag */ - RK_S32 output = task_dec->output; + RK_U32 output = task_dec->output; mpp_buf_slot_clr_decoding(slots, output); @@ -270,11 +271,11 @@ void *mpp_dec_hal_thread(void *data) MppBuffer buffer = mpp_buf_slot_get_buffer(slots, output); mpp_frame_set_buffer(frame, buffer); + mpp_buf_slot_clr_display(slots, output); + frames->add_at_tail(&frame, sizeof(frame)); mpp->mFramePutCount++; - mpp_buf_slot_clr_display(slots, output); - /* * mark previous buffer is complete */ diff --git a/mpp/hal/inc/hal_task.h b/mpp/hal/inc/hal_task.h index 11110fd3..9bdfe4e5 100644 --- a/mpp/hal/inc/hal_task.h +++ b/mpp/hal/inc/hal_task.h @@ -71,6 +71,7 @@ typedef struct HalDecTask_t { // current tesk protocol syntax information MppSyntax syntax; + // for test purpose // current tesk output slot index RK_S32 output; // current task reference slot index, -1 for unused