[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) {
mpp_frame_deinit(&entry->frame);
slot_ops_with_log(impl, entry, SLOT_CLR_FRAME);
} else {
if (entry->buffer)
mpp_buffer_put(entry->buffer);
}
if (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);
}
}
@@ -831,11 +832,11 @@ MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type
slot_assert(impl, NULL == slot->frame);
mpp_buffer_put(slot->buffer);
}
mpp_buffer_inc_ref(buffer);
slot->buffer = buffer;
if (slot->frame)
mpp_frame_set_buffer(slot->frame, buffer);
mpp_buffer_inc_ref(buffer);
} break;
default : {
} break;

View File

@@ -93,6 +93,32 @@ MPP_RET mpp_frame_set_next(MppFrame frame, MppFrame next)
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)
{
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(MppFrameChromaLocation, chroma_location)
MPP_FRAME_ACCESSORS(MppFrameFormat, fmt)
MPP_FRAME_ACCESSORS(MppBuffer, buffer)
MPP_FRAME_ACCESSORS(size_t, buf_size)
MPP_FRAME_ACCESSORS(RK_U32, errinfo)

View File

@@ -233,12 +233,14 @@ void mpp_packet_set_buffer(MppPacket packet, MppBuffer buffer)
return ;
MppPacketImpl *p = (MppPacketImpl *)packet;
if (p->buffer) {
mpp_buffer_put(p->buffer);
}
p->buffer = buffer;
if (buffer) {
mpp_buffer_inc_ref(buffer);
if (p->buffer != buffer) {
if (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);
}
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);
task->status.dec_pkt_copy_rdy = 0;
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);
if (NULL == hal_buf_in) {
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_buffer_put(hal_buf_in);
}
} else {
MppBufferImpl *buf = (MppBufferImpl *)hal_buf_in;
mpp_assert(buf->info.size >= stream_size);
@@ -526,11 +523,6 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task)
mpp->mTaskPutCount++;
task->hnd = NULL;
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);
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_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_log("mpp_dec_parser_thread exit ok");
@@ -673,7 +663,6 @@ void *mpp_dec_hal_thread(void *data)
MppThread *hal = mpp->mThreadHal;
MppDec *dec = mpp->mDec;
HalTaskGroup tasks = dec->tasks;
MppBuffer buffer = NULL;
MppBufSlots frame_slots = dec->frame_slots;
MppBufSlots packet_slots = dec->packet_slots;
@@ -751,11 +740,6 @@ 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_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);
// TODO: may have risk here

View File

@@ -175,17 +175,16 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
if (ret || NULL == mframe) {
aDecOut->size = 0;
} else {
MppBuffer buf = NULL;
RK_U64 pts = 0;
RK_U32 fd = 0;
RK_U32 mode = 0;
void* ptr = NULL;
MppBuffer buf = mpp_frame_get_buffer(mframe);
RK_U64 pts = mpp_frame_get_pts(mframe);
RK_U32 mode = mpp_frame_get_mode(mframe);
RK_S32 fd = -1;
aDecOut->size = sizeof(VPU_FRAME);
vframe->DisplayWidth = mpp_frame_get_width(mframe);
vframe->DisplayHeight = mpp_frame_get_height(mframe);
vframe->FrameWidth = mpp_frame_get_hor_stride(mframe);
vframe->FrameHeight = mpp_frame_get_ver_stride(mframe);
mode = mpp_frame_get_mode(mframe);
if (mode == MPP_FRAME_FLAG_FRAME)
vframe->FrameType = 0;
else {
@@ -198,11 +197,9 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
vframe->FrameType = 4;
}
vframe->ErrorInfo = mpp_frame_get_errinfo(mframe) | mpp_frame_get_discard(mframe);
pts = mpp_frame_get_pts(mframe);
aDecOut->timeUs = pts;
vframe->ShowTime.TimeHigh = (RK_U32)(pts >> 32);
vframe->ShowTime.TimeLow = (RK_U32)pts;
buf = mpp_frame_get_buffer(mframe);
switch (mpp_frame_get_fmt(mframe)) {
case MPP_FMT_YUV420SP: {
vframe->ColorType = VPU_OUTPUT_FORMAT_YUV420_SEMIPLANAR;
@@ -230,12 +227,16 @@ RK_S32 VpuApiLegacy:: decode_getoutframe(DecoderOut_t *aDecOut)
break;
}
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);
vframe->FrameBusAddr[0] = fd;
vframe->FrameBusAddr[1] = fd;
vframe->vpumem.vir_addr = (RK_U32*)ptr;
frame_count++;
//!< Dump yuv
if (fp && !vframe->ErrorInfo) {
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;
}
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_frame_get_poc(mframe), mpp_frame_get_errinfo(mframe), mpp_frame_get_discard(mframe), mpp_frame_get_eos(mframe), vframe->ErrorInfo);
mpp_log("get one frame pts %lld, fd 0x%x, poc %d, errinfo %x, discard %d, eos %d, verr %d",
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)) {
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.
* 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.
*/
mpp_frame_set_buffer(mframe, NULL);
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)
{
mpp_log_f("in\n");
RK_S32 ret = MPP_OK;
if (!init_ok) {
return VPU_API_ERR_VPU_CODEC_INIT;
}
(void)ctx;
(void)aEncInStrm;
(void)aEncOut;
mpp_log_f("ok\n");
return 0;
return ret;
}
RK_S32 VpuApiLegacy::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm)