[frame/packet]: increase mpp_buffer reference count when mpp_buffer is set to mpp_frame or mpp_packet

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1045 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2016-07-19 10:40:26 +00:00
parent 135041f771
commit 781c812ce5
5 changed files with 67 additions and 46 deletions

View File

@@ -448,12 +448,13 @@ static void check_entry_unused(MppBufSlotsImpl *impl, MppBufSlotEntry *entry)
if (entry->frame) { if (entry->frame) {
mpp_frame_deinit(&entry->frame); mpp_frame_deinit(&entry->frame);
slot_ops_with_log(impl, entry, SLOT_CLR_FRAME); slot_ops_with_log(impl, entry, SLOT_CLR_FRAME);
} else { }
if (entry->buffer) if (entry->buffer) {
mpp_buffer_put(entry->buffer); mpp_buffer_put(entry->buffer);
entry->buffer = NULL;
slot_ops_with_log(impl, entry, SLOT_CLR_BUFFER);
} }
slot_ops_with_log(impl, entry, SLOT_CLR_BUFFER);
slot_ops_with_log(impl, entry, SLOT_CLR_ON_USE); slot_ops_with_log(impl, entry, SLOT_CLR_ON_USE);
} }
} }
@@ -831,11 +832,11 @@ MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type
slot_assert(impl, NULL == slot->frame); slot_assert(impl, NULL == slot->frame);
mpp_buffer_put(slot->buffer); mpp_buffer_put(slot->buffer);
} }
mpp_buffer_inc_ref(buffer);
slot->buffer = buffer; slot->buffer = buffer;
if (slot->frame) if (slot->frame)
mpp_frame_set_buffer(slot->frame, buffer); mpp_frame_set_buffer(slot->frame, buffer);
mpp_buffer_inc_ref(buffer);
} break; } break;
default : { default : {
} break; } break;

View File

@@ -93,6 +93,32 @@ MPP_RET mpp_frame_set_next(MppFrame frame, MppFrame next)
return MPP_OK; return MPP_OK;
} }
MppBuffer mpp_frame_get_buffer(MppFrame frame)
{
if (check_is_mpp_frame(frame))
return NULL;
MppFrameImpl *p = (MppFrameImpl *)frame;
return (MppFrame)p->buffer;
}
void mpp_frame_set_buffer(MppFrame frame, MppBuffer buffer)
{
if (check_is_mpp_frame(frame))
return ;
MppFrameImpl *p = (MppFrameImpl *)frame;
if (p->buffer != buffer) {
if (buffer)
mpp_buffer_inc_ref(buffer);
if (p->buffer)
mpp_buffer_put(p->buffer);
p->buffer = buffer;
}
}
MPP_RET mpp_frame_copy(MppFrame dst, MppFrame src) MPP_RET mpp_frame_copy(MppFrame dst, MppFrame src)
{ {
if (NULL == dst || check_is_mpp_frame(src)) { if (NULL == dst || check_is_mpp_frame(src)) {
@@ -163,6 +189,5 @@ MPP_FRAME_ACCESSORS(MppFrameColorTransferCharacteristic, color_trc)
MPP_FRAME_ACCESSORS(MppFrameColorSpace, colorspace) MPP_FRAME_ACCESSORS(MppFrameColorSpace, colorspace)
MPP_FRAME_ACCESSORS(MppFrameChromaLocation, chroma_location) MPP_FRAME_ACCESSORS(MppFrameChromaLocation, chroma_location)
MPP_FRAME_ACCESSORS(MppFrameFormat, fmt) MPP_FRAME_ACCESSORS(MppFrameFormat, fmt)
MPP_FRAME_ACCESSORS(MppBuffer, buffer)
MPP_FRAME_ACCESSORS(size_t, buf_size) MPP_FRAME_ACCESSORS(size_t, buf_size)
MPP_FRAME_ACCESSORS(RK_U32, errinfo) MPP_FRAME_ACCESSORS(RK_U32, errinfo)

View File

@@ -233,12 +233,14 @@ void mpp_packet_set_buffer(MppPacket packet, MppBuffer buffer)
return ; return ;
MppPacketImpl *p = (MppPacketImpl *)packet; MppPacketImpl *p = (MppPacketImpl *)packet;
if (p->buffer) { if (p->buffer != buffer) {
mpp_buffer_put(p->buffer); if (buffer)
}
p->buffer = buffer;
if (buffer) {
mpp_buffer_inc_ref(buffer); mpp_buffer_inc_ref(buffer);
if (p->buffer)
mpp_buffer_put(p->buffer);
p->buffer = buffer;
} }
} }

View File

@@ -205,11 +205,6 @@ static RK_U32 reset_dec_task(Mpp *mpp, DecTask *task)
mpp_buf_slot_clr_flag(frame_slots, index, SLOT_QUEUE_USE); mpp_buf_slot_clr_flag(frame_slots, index, SLOT_QUEUE_USE);
} }
if (task->status.dec_pkt_copy_rdy) { if (task->status.dec_pkt_copy_rdy) {
mpp_buf_slot_get_prop(packet_slots, task_dec->input, SLOT_BUFFER, &task->hal_pkt_buf_in);
if (task->hal_pkt_buf_in) {
mpp_buffer_put(task->hal_pkt_buf_in);
task->hal_pkt_buf_in = NULL;
}
mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT); mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
task->status.dec_pkt_copy_rdy = 0; task->status.dec_pkt_copy_rdy = 0;
task_dec->input = -1; task_dec->input = -1;
@@ -400,8 +395,10 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
mpp_buf_slot_get_prop(packet_slots, task->hal_pkt_idx_in, SLOT_BUFFER, &hal_buf_in); mpp_buf_slot_get_prop(packet_slots, task->hal_pkt_idx_in, SLOT_BUFFER, &hal_buf_in);
if (NULL == hal_buf_in) { if (NULL == hal_buf_in) {
mpp_buffer_get(mpp->mPacketGroup, &hal_buf_in, stream_size); mpp_buffer_get(mpp->mPacketGroup, &hal_buf_in, stream_size);
if (hal_buf_in) if (hal_buf_in) {
mpp_buf_slot_set_prop(packet_slots, task->hal_pkt_idx_in, SLOT_BUFFER, hal_buf_in); mpp_buf_slot_set_prop(packet_slots, task->hal_pkt_idx_in, SLOT_BUFFER, hal_buf_in);
mpp_buffer_put(hal_buf_in);
}
} else { } else {
MppBufferImpl *buf = (MppBufferImpl *)hal_buf_in; MppBufferImpl *buf = (MppBufferImpl *)hal_buf_in;
mpp_assert(buf->info.size >= stream_size); mpp_assert(buf->info.size >= stream_size);
@@ -526,11 +523,6 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
mpp->mTaskPutCount++; mpp->mTaskPutCount++;
task->hnd = NULL; task->hnd = NULL;
if (task->status.dec_pkt_copy_rdy) { if (task->status.dec_pkt_copy_rdy) {
mpp_buf_slot_get_prop(packet_slots, task_dec->input, SLOT_BUFFER, &task->hal_pkt_buf_in);
if (task->hal_pkt_buf_in) {
mpp_buffer_put(task->hal_pkt_buf_in);
task->hal_pkt_buf_in = NULL;
}
mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT); mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
task->status.dec_pkt_copy_rdy = 0; task->status.dec_pkt_copy_rdy = 0;
} }
@@ -659,8 +651,6 @@ void *mpp_dec_parser_thread(void *data)
mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_CODEC_READY); mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_CODEC_READY);
mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT); mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT); mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
if (task.hal_pkt_buf_in)
mpp_buffer_put(task.hal_pkt_buf_in);
} }
mpp_buffer_group_clear(mpp->mPacketGroup); mpp_buffer_group_clear(mpp->mPacketGroup);
mpp_log("mpp_dec_parser_thread exit ok"); mpp_log("mpp_dec_parser_thread exit ok");
@@ -673,7 +663,6 @@ void *mpp_dec_hal_thread(void *data)
MppThread *hal = mpp->mThreadHal; MppThread *hal = mpp->mThreadHal;
MppDec *dec = mpp->mDec; MppDec *dec = mpp->mDec;
HalTaskGroup tasks = dec->tasks; HalTaskGroup tasks = dec->tasks;
MppBuffer buffer = NULL;
MppBufSlots frame_slots = dec->frame_slots; MppBufSlots frame_slots = dec->frame_slots;
MppBufSlots packet_slots = dec->packet_slots; MppBufSlots packet_slots = dec->packet_slots;
@@ -751,11 +740,6 @@ void *mpp_dec_hal_thread(void *data)
* 3. add frame to output list * 3. add frame to output list
* repeat 2 and 3 until not frame can be output * repeat 2 and 3 until not frame can be output
*/ */
mpp_buf_slot_get_prop(packet_slots, task_dec->input, SLOT_BUFFER, &buffer);
if (buffer) {
mpp_buffer_put(buffer);
buffer = NULL;
}
mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT); mpp_buf_slot_clr_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
// TODO: may have risk here // TODO: may have risk here

View File

@@ -175,17 +175,16 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
if (ret || NULL == mframe) { if (ret || NULL == mframe) {
aDecOut->size = 0; aDecOut->size = 0;
} else { } else {
MppBuffer buf = NULL; MppBuffer buf = mpp_frame_get_buffer(mframe);
RK_U64 pts = 0; RK_U64 pts = mpp_frame_get_pts(mframe);
RK_U32 fd = 0; RK_U32 mode = mpp_frame_get_mode(mframe);
RK_U32 mode = 0; RK_S32 fd = -1;
void* ptr = NULL;
aDecOut->size = sizeof(VPU_FRAME); aDecOut->size = sizeof(VPU_FRAME);
vframe->DisplayWidth = mpp_frame_get_width(mframe); vframe->DisplayWidth = mpp_frame_get_width(mframe);
vframe->DisplayHeight = mpp_frame_get_height(mframe); vframe->DisplayHeight = mpp_frame_get_height(mframe);
vframe->FrameWidth = mpp_frame_get_hor_stride(mframe); vframe->FrameWidth = mpp_frame_get_hor_stride(mframe);
vframe->FrameHeight = mpp_frame_get_ver_stride(mframe); vframe->FrameHeight = mpp_frame_get_ver_stride(mframe);
mode = mpp_frame_get_mode(mframe);
if (mode == MPP_FRAME_FLAG_FRAME) if (mode == MPP_FRAME_FLAG_FRAME)
vframe->FrameType = 0; vframe->FrameType = 0;
else { else {
@@ -198,11 +197,9 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
vframe->FrameType = 4; vframe->FrameType = 4;
} }
vframe->ErrorInfo = mpp_frame_get_errinfo(mframe) | mpp_frame_get_discard(mframe); vframe->ErrorInfo = mpp_frame_get_errinfo(mframe) | mpp_frame_get_discard(mframe);
pts = mpp_frame_get_pts(mframe);
aDecOut->timeUs = pts; aDecOut->timeUs = pts;
vframe->ShowTime.TimeHigh = (RK_U32)(pts >> 32); vframe->ShowTime.TimeHigh = (RK_U32)(pts >> 32);
vframe->ShowTime.TimeLow = (RK_U32)pts; vframe->ShowTime.TimeLow = (RK_U32)pts;
buf = mpp_frame_get_buffer(mframe);
switch (mpp_frame_get_fmt(mframe)) { switch (mpp_frame_get_fmt(mframe)) {
case MPP_FMT_YUV420SP: { case MPP_FMT_YUV420SP: {
vframe->ColorType = VPU_OUTPUT_FORMAT_YUV420_SEMIPLANAR; vframe->ColorType = VPU_OUTPUT_FORMAT_YUV420_SEMIPLANAR;
@@ -230,12 +227,16 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
break; break;
} }
if (buf) { if (buf) {
ptr = mpp_buffer_get_ptr(buf); void* ptr = mpp_buffer_get_ptr(buf);
mpp_buffer_inc_ref(buf);
fd = mpp_buffer_get_fd(buf); fd = mpp_buffer_get_fd(buf);
vframe->FrameBusAddr[0] = fd; vframe->FrameBusAddr[0] = fd;
vframe->FrameBusAddr[1] = fd; vframe->FrameBusAddr[1] = fd;
vframe->vpumem.vir_addr = (RK_U32*)ptr; vframe->vpumem.vir_addr = (RK_U32*)ptr;
frame_count++; frame_count++;
//!< Dump yuv //!< Dump yuv
if (fp && !vframe->ErrorInfo) { if (fp && !vframe->ErrorInfo) {
if ((vframe->FrameWidth >= 1920) || (vframe->FrameHeight >= 1080)) { if ((vframe->FrameWidth >= 1920) || (vframe->FrameHeight >= 1080)) {
@@ -281,8 +282,11 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
vframe->vpumem.offset = (RK_U32*)buf; vframe->vpumem.offset = (RK_U32*)buf;
} }
if (vpu_api_debug & VPU_API_DBG_OUTPUT) { if (vpu_api_debug & VPU_API_DBG_OUTPUT) {
mpp_log("get one frame timeUs %lld, fd=0x%x, poc=%d, errinfo=%d, discard=%d, eos=%d, verr=%d", aDecOut->timeUs, fd, mpp_log("get one frame pts %lld, fd 0x%x, poc %d, errinfo %x, discard %d, eos %d, verr %d",
mpp_frame_get_poc(mframe), mpp_frame_get_errinfo(mframe), mpp_frame_get_discard(mframe), mpp_frame_get_eos(mframe), vframe->ErrorInfo); aDecOut->timeUs, fd, mpp_frame_get_poc(mframe),
mpp_frame_get_errinfo(mframe),
mpp_frame_get_discard(mframe),
mpp_frame_get_eos(mframe), vframe->ErrorInfo);
} }
if (mpp_frame_get_eos(mframe)) { if (mpp_frame_get_eos(mframe)) {
set_eos = 1; set_eos = 1;
@@ -292,12 +296,11 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
} }
/* /*
* IMPORTANT: mframe is malloced frome mpi->decode_get_frame * IMPORTANT: mframe is malloced from mpi->decode_get_frame
* So we need to deinit mframe here. But the buffer in the frame should not be free with mframe. * So we need to deinit mframe here. But the buffer in the frame should not be free with mframe.
* Because buffer need to be set to vframe->vpumem.offset and send to display. * Because buffer need to be set to vframe->vpumem.offset and send to display.
* The we have to clear the buffer pointer in mframe then release mframe. * The we have to clear the buffer pointer in mframe then release mframe.
*/ */
mpp_frame_set_buffer(mframe, NULL);
mpp_frame_deinit(&mframe); mpp_frame_deinit(&mframe);
} }
@@ -307,11 +310,17 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
RK_S32 VpuApiLegacy::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut) RK_S32 VpuApiLegacy::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut)
{ {
mpp_log_f("in\n"); mpp_log_f("in\n");
RK_S32 ret = MPP_OK;
if (!init_ok) {
return VPU_API_ERR_VPU_CODEC_INIT;
}
(void)ctx; (void)ctx;
(void)aEncInStrm; (void)aEncInStrm;
(void)aEncOut; (void)aEncOut;
mpp_log_f("ok\n"); mpp_log_f("ok\n");
return 0; return ret;
} }
RK_S32 VpuApiLegacy::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm) RK_S32 VpuApiLegacy::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm)