diff --git a/mpp/codec/mpp_buf_slot.cpp b/mpp/codec/mpp_buf_slot.cpp index d88077e0..d4a98ec7 100644 --- a/mpp/codec/mpp_buf_slot.cpp +++ b/mpp/codec/mpp_buf_slot.cpp @@ -27,9 +27,8 @@ #define MPP_SLOT_UNUSED (0x00000000) #define MPP_SLOT_USED (0x00000001) #define MPP_SLOT_USED_AS_REF (0x00000002) -#define MPP_SLOT_USED_AS_OUTPUT (0x00000004) +#define MPP_SLOT_USED_AS_DECODING (0x00000004) #define MPP_SLOT_USED_AS_DISPLAY (0x00000008) -#define MPP_SLOT_HW_READY (0x00000010) typedef struct { MppBuffer buffer; @@ -44,6 +43,17 @@ typedef struct { MppBufSlotEntry *slots; } MppBufSlotsImpl; +/* + * only called on unref / displayed / decoded + */ +static void check_entry_unused(MppBufSlotEntry *entry) +{ + if (entry->status == MPP_SLOT_USED) { + entry->status = MPP_SLOT_UNUSED; + mpp_buffer_put(entry->buffer); + } +} + MPP_RET mpp_buf_slot_init(MppBufSlots *slots, RK_U32 count) { if (NULL == slots) { @@ -121,7 +131,7 @@ MPP_RET mpp_buf_slot_set_ref(MppBufSlots slots, RK_U32 index) return MPP_OK; } -MPP_RET mpp_buf_slot_set_unref(MppBufSlots slots, RK_U32 index) +MPP_RET mpp_buf_slot_clr_ref(MppBufSlots slots, RK_U32 index) { if (NULL == slots) { mpp_err("%s found NULL input\n\n", __FUNCTION__); @@ -133,10 +143,11 @@ MPP_RET mpp_buf_slot_set_unref(MppBufSlots slots, RK_U32 index) mpp_assert(index < impl->count); Mutex::Autolock auto_lock(impl->lock); slot[index].status &= ~MPP_SLOT_USED_AS_REF; + check_entry_unused(&slot[index]); return MPP_OK; } -MPP_RET mpp_buf_slot_set_output(MppBufSlots slots, RK_U32 index) +MPP_RET mpp_buf_slot_set_decoding(MppBufSlots slots, RK_U32 index) { if (NULL == slots) { mpp_err("%s found NULL input\n\n", __FUNCTION__); @@ -147,7 +158,24 @@ MPP_RET mpp_buf_slot_set_output(MppBufSlots slots, RK_U32 index) MppBufSlotEntry *slot = impl->slots; mpp_assert(index < impl->count); Mutex::Autolock auto_lock(impl->lock); - slot[index].status |= MPP_SLOT_USED_AS_OUTPUT; + slot[index].status |= MPP_SLOT_USED_AS_DECODING; + return MPP_OK; +} + +MPP_RET mpp_buf_slot_clr_decoding(MppBufSlots slots, RK_U32 index) +{ + if (NULL == slots) { + mpp_err("%s found NULL input\n\n", __FUNCTION__); + return MPP_ERR_NULL_PTR; + } + + MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots; + MppBufSlotEntry *slot = impl->slots; + mpp_assert(index < impl->count); + Mutex::Autolock auto_lock(impl->lock); + slot[index].status &= ~MPP_SLOT_USED_AS_DECODING; + impl->decode_count++; + check_entry_unused(&slot[index]); return MPP_OK; } @@ -166,7 +194,7 @@ MPP_RET mpp_buf_slot_set_display(MppBufSlots slots, RK_U32 index) return MPP_OK; } -MPP_RET mpp_buf_slot_set_hw_ready(MppBufSlots slots, RK_U32 index) +MPP_RET mpp_buf_slot_clr_display(MppBufSlots slots, RK_U32 index) { if (NULL == slots) { mpp_err("%s found NULL input\n\n", __FUNCTION__); @@ -177,25 +205,9 @@ MPP_RET mpp_buf_slot_set_hw_ready(MppBufSlots slots, RK_U32 index) MppBufSlotEntry *slot = impl->slots; mpp_assert(index < impl->count); Mutex::Autolock auto_lock(impl->lock); - slot[index].status |= MPP_SLOT_HW_READY; - slot[index].status &= ~MPP_SLOT_USED_AS_OUTPUT; - impl->decode_count++; - return MPP_OK; -} - -MPP_RET mpp_buf_slot_set_unused(MppBufSlots slots, RK_U32 index) -{ - if (NULL == slots) { - mpp_err("%s found NULL input\n\n", __FUNCTION__); - return MPP_ERR_NULL_PTR; - } - - MppBufSlotsImpl *impl = (MppBufSlotsImpl *)slots; - MppBufSlotEntry *slot = impl->slots; - mpp_assert(index < impl->count); - Mutex::Autolock auto_lock(impl->lock); - slot[index].status = MPP_SLOT_UNUSED; + slot[index].status &= ~MPP_SLOT_USED_AS_DISPLAY; impl->display_count++; + check_entry_unused(&slot[index]); return MPP_OK; } @@ -211,6 +223,7 @@ MPP_RET mpp_buf_slot_set_buffer(MppBufSlots slots, RK_U32 index, MppBuffer buffe mpp_assert(index < impl->count); Mutex::Autolock auto_lock(impl->lock); slot[index].buffer = buffer; + mpp_buffer_inc_ref(buffer); return MPP_OK; } diff --git a/mpp/codec/mpp_buf_slot.h b/mpp/codec/mpp_buf_slot.h index 534b37e1..cdccf95b 100644 --- a/mpp/codec/mpp_buf_slot.h +++ b/mpp/codec/mpp_buf_slot.h @@ -78,6 +78,21 @@ * | | output frame information | * + + + * + * typical buffer status transfer + * + * -> unused initial + * -> set_decoding by parser + * -> set_buffer by mpp - do alloc buffer here / info change here + * -> clr_decoding by hal() + * + * next four step can be different order + * -> set_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 + * + * -> set_unused automatic clear and dec buffer ref + * */ typedef void* MppBufSlots; @@ -101,36 +116,34 @@ MPP_RET mpp_buf_slot_deinit(MppBufSlots slots); * mpp_buf_slot_set_ref * - mark a slot to be used as reference * - * mpp_buf_slot_set_unref + * mpp_buf_slot_clr_ref * - mark a slot to be unused as reference * - * mpp_buf_slot_set_output + * mpp_buf_slot_set_decoding * - mark a slot to be output destination buffer * * mpp_buf_slot_set_display * - mark a slot to be can be display * + * called by mpp + * + * mpp_buf_slot_clr_display + * - mark a slot has been send out to display + * + * called by hal + * + * mpp_buf_slot_clr_decoding + * - mark a slot's buffer is already decoded by hardware + * NOTE: this call will clear used as output flag */ 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_set_unref(MppBufSlots slots, RK_U32 index); -MPP_RET mpp_buf_slot_set_output(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_set_display(MppBufSlots slots, RK_U32 index); +MPP_RET mpp_buf_slot_clr_display(MppBufSlots slots, RK_U32 index); -/* - * called by hal - * - * mpp_buf_slot_set_hw_ready - * - mark a slot's buffer is already decoded by hardware - * NOTE: this call will clear used as output flag - * - * called by mpp context display loop - * - * mpp_buf_slot_set_unused - * - mark a slot's buffer is unused when this buffer is outputed from mpp - */ -MPP_RET mpp_buf_slot_set_hw_ready(MppBufSlots slots, RK_U32 index); -MPP_RET mpp_buf_slot_set_unused(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(const MppBufSlots slots, RK_U32 index);