diff --git a/mpp/hal/common/h264/hal_h264e_stream_amend.c b/mpp/hal/common/h264/hal_h264e_stream_amend.c index 9bb29cc1..1276a354 100644 --- a/mpp/hal/common/h264/hal_h264e_stream_amend.c +++ b/mpp/hal/common/h264/hal_h264e_stream_amend.c @@ -19,12 +19,18 @@ #include #include #include + +#include "mpp_mem.h" #include "mpp_common.h" +#include "mpp_dmabuf.h" +#include "mpp_packet_impl.h" + #include "mpp_enc_cfg.h" #include "mpp_enc_refs.h" -#include "mpp_mem.h" + #include "hal_h264e_debug.h" #include "hal_h264e_stream_amend.h" + #include "h264e_sps.h" #include "h264e_pps.h" #include "h264e_slice.h" @@ -150,12 +156,20 @@ MPP_RET h264e_vepu_stream_amend_proc(HalH264eVepuStreamAmend *ctx, MppEncH264HwC RK_S32 final_len = 0; RK_S32 last_slice = 0; const MppPktSeg *seg = mpp_packet_get_segment_info(pkt); + if (seg) { while (seg && seg->type != 1 && seg->type != 5) { seg = seg->next; } } + { + MppBuffer buf = mpp_packet_get_buffer(pkt); + RK_S32 fd = mpp_buffer_get_fd(buf); + + mpp_dmabuf_sync_partial_begin(fd, 1, base, len, __FUNCTION__); + } + { RK_S32 more_buf = 0; while (len > ctx->buf_size - 16) { @@ -318,9 +332,20 @@ MPP_RET h264e_vepu_stream_amend_sync_ref_idc(HalH264eVepuStreamAmend *ctx) RK_S32 base = ctx->buf_base; RK_S32 len = ctx->old_length; RK_U8 *p = mpp_packet_get_pos(pkt) + base; - RK_U8 val = p[4]; - RK_S32 hw_nal_ref_idc = (val >> 5) & 0x3; - RK_S32 sw_nal_ref_idc = slice->nal_reference_idc; + RK_U8 val = 0; + RK_S32 hw_nal_ref_idc = 0; + RK_S32 sw_nal_ref_idc = 0; + + { + MppBuffer buf = mpp_packet_get_buffer(pkt); + RK_S32 fd = mpp_buffer_get_fd(buf); + + mpp_dmabuf_sync_partial_begin(fd, 1, base, len, __FUNCTION__); + } + + val = p[4]; + hw_nal_ref_idc = (val >> 5) & 0x3; + sw_nal_ref_idc = slice->nal_reference_idc; if (hw_nal_ref_idc == sw_nal_ref_idc) return MPP_OK; diff --git a/mpp/hal/mpp_enc_hal.cpp b/mpp/hal/mpp_enc_hal.cpp index b1e9703b..fefa79f2 100644 --- a/mpp/hal/mpp_enc_hal.cpp +++ b/mpp/hal/mpp_enc_hal.cpp @@ -140,6 +140,23 @@ MPP_RET mpp_enc_hal_check_part_mode(MppEncHal ctx) return MPP_NOK; } +MPP_RET mpp_enc_hal_start(void *hal, HalEncTask *task) +{ + if (NULL == hal || NULL == task) { + mpp_err_f("found NULL input ctx %p task %p\n", hal, task); + return MPP_ERR_NULL_PTR; + } + + MppEncHalImpl *p = (MppEncHalImpl*)hal; + if (!p->api || !p->api->start) + return MPP_OK; + + /* Add buffer sync process */ + mpp_buffer_sync_partial_end(task->output, 0, task->length); + + return p->api->start(p->ctx, task); +} + #define MPP_ENC_HAL_TASK_FUNC(func) \ MPP_RET mpp_enc_hal_##func(void *hal, HalEncTask *task) \ { \ @@ -157,7 +174,6 @@ MPP_RET mpp_enc_hal_check_part_mode(MppEncHal ctx) MPP_ENC_HAL_TASK_FUNC(get_task) MPP_ENC_HAL_TASK_FUNC(gen_regs) -MPP_ENC_HAL_TASK_FUNC(start) MPP_ENC_HAL_TASK_FUNC(wait) MPP_ENC_HAL_TASK_FUNC(part_start) MPP_ENC_HAL_TASK_FUNC(part_wait) diff --git a/mpp/hal/rkenc/h265e/hal_h265e_vepu580.c b/mpp/hal/rkenc/h265e/hal_h265e_vepu580.c index 362f9e20..45f44cfb 100644 --- a/mpp/hal/rkenc/h265e/hal_h265e_vepu580.c +++ b/mpp/hal/rkenc/h265e/hal_h265e_vepu580.c @@ -26,6 +26,7 @@ #include "mpp_common.h" #include "mpp_frame_impl.h" #include "mpp_packet_impl.h" +#include "mpp_dmabuf.h" #include "hal_h265e_debug.h" #include "h265e_syntax_new.h" @@ -3026,8 +3027,10 @@ MPP_RET hal_h265e_v580_wait(void *hal, HalEncTask *task) param.length = slice_len; if (finish_cnt > 0) { - void *tile1_ptr = mpp_buffer_get_ptr(ctx->hw_tile_stream[finish_cnt - 1]); + MppBuffer buf = ctx->hw_tile_stream[finish_cnt - 1]; + void *tile1_ptr = mpp_buffer_get_ptr(buf); + mpp_buffer_sync_ro_partial_begin(buf, tile1_offset, slice_len); memcpy(ptr + seg_offset, tile1_ptr + tile1_offset, slice_len); tile1_offset += slice_len; } @@ -3160,7 +3163,10 @@ MPP_RET hal_h265e_v580_ret_task(void *hal, HalEncTask *task) if (!ctx->cfg->split.split_out) { if (i) { //copy tile 1 stream RK_U32 len = fb->out_strm_size - stream_len; - void *tile1_ptr = mpp_buffer_get_ptr(ctx->hw_tile_stream[i - 1]); + MppBuffer buf = ctx->hw_tile_stream[i - 1]; + void *tile1_ptr = mpp_buffer_get_ptr(buf); + + mpp_buffer_sync_ro_partial_begin(buf, 0, len); memcpy(ptr + stream_len + offset, tile1_ptr, len); } stream_len = fb->out_strm_size; diff --git a/mpp/hal/vpu/jpege/hal_jpege_vepu2_v2.c b/mpp/hal/vpu/jpege/hal_jpege_vepu2_v2.c index 1d5c11b5..929f389a 100644 --- a/mpp/hal/vpu/jpege/hal_jpege_vepu2_v2.c +++ b/mpp/hal/vpu/jpege/hal_jpege_vepu2_v2.c @@ -22,6 +22,7 @@ #include "mpp_common.h" #include "mpp_mem.h" #include "mpp_platform.h" +#include "mpp_dmabuf.h" #include "mpp_enc_hal.h" #include "vcodec_service.h" @@ -777,6 +778,8 @@ static MPP_RET multi_core_wait(HalJpegeCtx *ctx, HalEncTask *task) mpp_err_f("poll cmd failed %d\n", ret); if (i == 0) { + RK_S32 fd = mpp_buffer_get_fd(task->output); + val = regs[109]; hal_jpege_dbg_output("hw_status %08x\n", val); feedback->hw_status = val & 0x70; @@ -787,17 +790,22 @@ static MPP_RET multi_core_wait(HalJpegeCtx *ctx, HalEncTask *task) hal_jpege_dbg_detail("partion len = %d", hw_bit / 8); task->length = feedback->stream_length; task->hw_length = task->length - ctx->hal_start_pos; + + mpp_dmabuf_sync_partial_begin(fd, 1, 0, task->length, __FUNCTION__); } else { void *stream_ptr = mpp_buffer_get_ptr(task->output); void *partion_ptr = mpp_buffer_get_ptr(ctx_ext->partions_buf[i - 1]); + RK_S32 partion_fd = mpp_buffer_get_fd(ctx_ext->partions_buf[i - 1]); RK_U32 partion_len = 0; val = regs[109]; hal_jpege_dbg_output("hw_status %08x\n", val); feedback->hw_status = val & 0x70; partion_len = regs[53] / 8; - hal_jpege_dbg_detail("partion_len = %d", partion_len); + + mpp_dmabuf_sync_partial_begin(partion_fd, 1, 0, partion_len, __FUNCTION__); + memcpy(stream_ptr + feedback->stream_length, partion_ptr, partion_len); feedback->stream_length += partion_len; task->length = feedback->stream_length; diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index 4f47c253..43179ddc 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -733,6 +733,8 @@ RET: MPP_RET Mpp::get_packet(MppPacket *packet) { + MppPacket pkt = NULL; + if (!mInitDone) return MPP_ERR_INIT; @@ -766,12 +768,21 @@ MPP_RET Mpp::get_packet(MppPacket *packet) goto RET; } - mpp_assert(*packet); + pkt = *packet; + if (!pkt) { + mpp_log_f("get invalid task without output packet\n"); + } else { + MppPacketImpl *impl = (MppPacketImpl *)pkt; + MppBuffer buf = impl->buffer; + RK_U32 offset = (RK_U32)((char *)impl->pos - (char *)impl->data); - mpp_dbg_pts("pts %lld\n", mpp_packet_get_pts(*packet)); + mpp_buffer_sync_ro_partial_begin(buf, offset, impl->length); + + mpp_dbg_pts("pts %lld\n", impl->pts); + } // dump output - mpp_ops_enc_get_pkt(mDump, *packet); + mpp_ops_enc_get_pkt(mDump, pkt); ret = enqueue(MPP_PORT_OUTPUT, task); if (ret) diff --git a/test/mpi_enc_mt_test.cpp b/test/mpi_enc_mt_test.cpp index 23b32be5..d82a75f9 100644 --- a/test/mpi_enc_mt_test.cpp +++ b/test/mpi_enc_mt_test.cpp @@ -716,10 +716,11 @@ void *enc_test_input(void *arg) break; } else { if (p->cam_ctx == NULL) { - ret = fill_image((RK_U8 *)buf, p->width, p->height, p->hor_stride, - p->ver_stride, p->fmt, p->frm_cnt_in); - if (ret) - break; + ret = MPP_OK; + // ret = fill_image((RK_U8 *)buf, p->width, p->height, p->hor_stride, + // p->ver_stride, p->fmt, p->frm_cnt_in); + // if (ret) + // break; } else { cam_frm_idx = camera_source_get_frame(p->cam_ctx); mpp_assert(cam_frm_idx >= 0); @@ -1058,6 +1059,7 @@ int enc_test_mt(MpiEncTestArgs* cmd, const char *name) mpp_log("*******************************************\n"); getc(stdin); + mpp_log_f("loop_end start"); for (i = 0; i < cmd->nthreads; i++) ctxs[i].ctx.loop_end = 1; } diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index faadaaa7..db1055b3 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -596,6 +596,7 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info) RK_U32 eoi = 1; if (p->fp_input) { + mpp_buffer_sync_begin(p->frm_buf); ret = read_image(buf, p->fp_input, p->width, p->height, p->hor_stride, p->ver_stride, p->fmt); if (ret == MPP_NOK || feof(p->fp_input)) { @@ -611,12 +612,15 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info) mpp_log_q(quiet, "chn %d found last frame. feof %d\n", chn, feof(p->fp_input)); } else if (ret == MPP_ERR_VALUE) goto RET; + mpp_buffer_sync_end(p->frm_buf); } else { if (p->cam_ctx == NULL) { + mpp_buffer_sync_begin(p->frm_buf); ret = fill_image(buf, p->width, p->height, p->hor_stride, p->ver_stride, p->fmt, p->frame_count); if (ret) goto RET; + mpp_buffer_sync_end(p->frm_buf); } else { cam_frm_idx = camera_source_get_frame(p->cam_ctx); mpp_assert(cam_frm_idx >= 0); @@ -877,7 +881,7 @@ void *enc_test(void *arg) goto MPP_TEST_OUT; } - ret = mpp_buffer_group_get_internal(&p->buf_grp, MPP_BUFFER_TYPE_DRM); + ret = mpp_buffer_group_get_internal(&p->buf_grp, MPP_BUFFER_TYPE_DRM | MPP_BUFFER_FLAGS_CACHABLE); if (ret) { mpp_err_f("failed to get mpp buffer group ret %d\n", ret); goto MPP_TEST_OUT; diff --git a/utils/camera_source.c b/utils/camera_source.c index cbd18174..9099eacd 100644 --- a/utils/camera_source.c +++ b/utils/camera_source.c @@ -428,8 +428,14 @@ MPP_RET camera_source_put_frame(CamSource *ctx, RK_S32 idx) MppBuffer camera_frame_to_buf(CamSource *ctx, RK_S32 idx) { - if (idx < 0) - return NULL; + MppBuffer buf = NULL; - return ctx->fbuf[idx].buffer; + if (idx < 0) + return buf; + + buf = ctx->fbuf[idx].buffer; + if (buf) + mpp_buffer_sync_end(buf); + + return buf; }