mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-05 17:16:50 +08:00
chore[mpp_enc]: Encoder changes to cacheable buffer
Signed-off-by: Herman Chen <herman.chen@rock-chips.com> Change-Id: I8df399ff708e354f8e3017da41e1424cba4999ee
This commit is contained in:
@@ -19,12 +19,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "mpp_mem.h"
|
||||||
#include "mpp_common.h"
|
#include "mpp_common.h"
|
||||||
|
#include "mpp_dmabuf.h"
|
||||||
|
#include "mpp_packet_impl.h"
|
||||||
|
|
||||||
#include "mpp_enc_cfg.h"
|
#include "mpp_enc_cfg.h"
|
||||||
#include "mpp_enc_refs.h"
|
#include "mpp_enc_refs.h"
|
||||||
#include "mpp_mem.h"
|
|
||||||
#include "hal_h264e_debug.h"
|
#include "hal_h264e_debug.h"
|
||||||
#include "hal_h264e_stream_amend.h"
|
#include "hal_h264e_stream_amend.h"
|
||||||
|
|
||||||
#include "h264e_sps.h"
|
#include "h264e_sps.h"
|
||||||
#include "h264e_pps.h"
|
#include "h264e_pps.h"
|
||||||
#include "h264e_slice.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 final_len = 0;
|
||||||
RK_S32 last_slice = 0;
|
RK_S32 last_slice = 0;
|
||||||
const MppPktSeg *seg = mpp_packet_get_segment_info(pkt);
|
const MppPktSeg *seg = mpp_packet_get_segment_info(pkt);
|
||||||
|
|
||||||
if (seg) {
|
if (seg) {
|
||||||
while (seg && seg->type != 1 && seg->type != 5) {
|
while (seg && seg->type != 1 && seg->type != 5) {
|
||||||
seg = seg->next;
|
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;
|
RK_S32 more_buf = 0;
|
||||||
while (len > ctx->buf_size - 16) {
|
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 base = ctx->buf_base;
|
||||||
RK_S32 len = ctx->old_length;
|
RK_S32 len = ctx->old_length;
|
||||||
RK_U8 *p = mpp_packet_get_pos(pkt) + base;
|
RK_U8 *p = mpp_packet_get_pos(pkt) + base;
|
||||||
RK_U8 val = p[4];
|
RK_U8 val = 0;
|
||||||
RK_S32 hw_nal_ref_idc = (val >> 5) & 0x3;
|
RK_S32 hw_nal_ref_idc = 0;
|
||||||
RK_S32 sw_nal_ref_idc = slice->nal_reference_idc;
|
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)
|
if (hw_nal_ref_idc == sw_nal_ref_idc)
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
|
@@ -140,6 +140,23 @@ MPP_RET mpp_enc_hal_check_part_mode(MppEncHal ctx)
|
|||||||
return MPP_NOK;
|
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) \
|
#define MPP_ENC_HAL_TASK_FUNC(func) \
|
||||||
MPP_RET mpp_enc_hal_##func(void *hal, HalEncTask *task) \
|
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(get_task)
|
||||||
MPP_ENC_HAL_TASK_FUNC(gen_regs)
|
MPP_ENC_HAL_TASK_FUNC(gen_regs)
|
||||||
MPP_ENC_HAL_TASK_FUNC(start)
|
|
||||||
MPP_ENC_HAL_TASK_FUNC(wait)
|
MPP_ENC_HAL_TASK_FUNC(wait)
|
||||||
MPP_ENC_HAL_TASK_FUNC(part_start)
|
MPP_ENC_HAL_TASK_FUNC(part_start)
|
||||||
MPP_ENC_HAL_TASK_FUNC(part_wait)
|
MPP_ENC_HAL_TASK_FUNC(part_wait)
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "mpp_common.h"
|
#include "mpp_common.h"
|
||||||
#include "mpp_frame_impl.h"
|
#include "mpp_frame_impl.h"
|
||||||
#include "mpp_packet_impl.h"
|
#include "mpp_packet_impl.h"
|
||||||
|
#include "mpp_dmabuf.h"
|
||||||
|
|
||||||
#include "hal_h265e_debug.h"
|
#include "hal_h265e_debug.h"
|
||||||
#include "h265e_syntax_new.h"
|
#include "h265e_syntax_new.h"
|
||||||
@@ -3026,8 +3027,10 @@ MPP_RET hal_h265e_v580_wait(void *hal, HalEncTask *task)
|
|||||||
param.length = slice_len;
|
param.length = slice_len;
|
||||||
|
|
||||||
if (finish_cnt > 0) {
|
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);
|
memcpy(ptr + seg_offset, tile1_ptr + tile1_offset, slice_len);
|
||||||
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 (!ctx->cfg->split.split_out) {
|
||||||
if (i) { //copy tile 1 stream
|
if (i) { //copy tile 1 stream
|
||||||
RK_U32 len = fb->out_strm_size - stream_len;
|
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);
|
memcpy(ptr + stream_len + offset, tile1_ptr, len);
|
||||||
}
|
}
|
||||||
stream_len = fb->out_strm_size;
|
stream_len = fb->out_strm_size;
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "mpp_common.h"
|
#include "mpp_common.h"
|
||||||
#include "mpp_mem.h"
|
#include "mpp_mem.h"
|
||||||
#include "mpp_platform.h"
|
#include "mpp_platform.h"
|
||||||
|
#include "mpp_dmabuf.h"
|
||||||
|
|
||||||
#include "mpp_enc_hal.h"
|
#include "mpp_enc_hal.h"
|
||||||
#include "vcodec_service.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);
|
mpp_err_f("poll cmd failed %d\n", ret);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
RK_S32 fd = mpp_buffer_get_fd(task->output);
|
||||||
|
|
||||||
val = regs[109];
|
val = regs[109];
|
||||||
hal_jpege_dbg_output("hw_status %08x\n", val);
|
hal_jpege_dbg_output("hw_status %08x\n", val);
|
||||||
feedback->hw_status = val & 0x70;
|
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);
|
hal_jpege_dbg_detail("partion len = %d", hw_bit / 8);
|
||||||
task->length = feedback->stream_length;
|
task->length = feedback->stream_length;
|
||||||
task->hw_length = task->length - ctx->hal_start_pos;
|
task->hw_length = task->length - ctx->hal_start_pos;
|
||||||
|
|
||||||
|
mpp_dmabuf_sync_partial_begin(fd, 1, 0, task->length, __FUNCTION__);
|
||||||
} else {
|
} else {
|
||||||
void *stream_ptr = mpp_buffer_get_ptr(task->output);
|
void *stream_ptr = mpp_buffer_get_ptr(task->output);
|
||||||
void *partion_ptr = mpp_buffer_get_ptr(ctx_ext->partions_buf[i - 1]);
|
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;
|
RK_U32 partion_len = 0;
|
||||||
|
|
||||||
val = regs[109];
|
val = regs[109];
|
||||||
hal_jpege_dbg_output("hw_status %08x\n", val);
|
hal_jpege_dbg_output("hw_status %08x\n", val);
|
||||||
feedback->hw_status = val & 0x70;
|
feedback->hw_status = val & 0x70;
|
||||||
partion_len = regs[53] / 8;
|
partion_len = regs[53] / 8;
|
||||||
|
|
||||||
hal_jpege_dbg_detail("partion_len = %d", partion_len);
|
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);
|
memcpy(stream_ptr + feedback->stream_length, partion_ptr, partion_len);
|
||||||
feedback->stream_length += partion_len;
|
feedback->stream_length += partion_len;
|
||||||
task->length = feedback->stream_length;
|
task->length = feedback->stream_length;
|
||||||
|
17
mpp/mpp.cpp
17
mpp/mpp.cpp
@@ -733,6 +733,8 @@ RET:
|
|||||||
|
|
||||||
MPP_RET Mpp::get_packet(MppPacket *packet)
|
MPP_RET Mpp::get_packet(MppPacket *packet)
|
||||||
{
|
{
|
||||||
|
MppPacket pkt = NULL;
|
||||||
|
|
||||||
if (!mInitDone)
|
if (!mInitDone)
|
||||||
return MPP_ERR_INIT;
|
return MPP_ERR_INIT;
|
||||||
|
|
||||||
@@ -766,12 +768,21 @@ MPP_RET Mpp::get_packet(MppPacket *packet)
|
|||||||
goto RET;
|
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
|
// dump output
|
||||||
mpp_ops_enc_get_pkt(mDump, *packet);
|
mpp_ops_enc_get_pkt(mDump, pkt);
|
||||||
|
|
||||||
ret = enqueue(MPP_PORT_OUTPUT, task);
|
ret = enqueue(MPP_PORT_OUTPUT, task);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@@ -716,10 +716,11 @@ void *enc_test_input(void *arg)
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if (p->cam_ctx == NULL) {
|
if (p->cam_ctx == NULL) {
|
||||||
ret = fill_image((RK_U8 *)buf, p->width, p->height, p->hor_stride,
|
ret = MPP_OK;
|
||||||
p->ver_stride, p->fmt, p->frm_cnt_in);
|
// ret = fill_image((RK_U8 *)buf, p->width, p->height, p->hor_stride,
|
||||||
if (ret)
|
// p->ver_stride, p->fmt, p->frm_cnt_in);
|
||||||
break;
|
// if (ret)
|
||||||
|
// break;
|
||||||
} else {
|
} else {
|
||||||
cam_frm_idx = camera_source_get_frame(p->cam_ctx);
|
cam_frm_idx = camera_source_get_frame(p->cam_ctx);
|
||||||
mpp_assert(cam_frm_idx >= 0);
|
mpp_assert(cam_frm_idx >= 0);
|
||||||
@@ -1058,6 +1059,7 @@ int enc_test_mt(MpiEncTestArgs* cmd, const char *name)
|
|||||||
mpp_log("*******************************************\n");
|
mpp_log("*******************************************\n");
|
||||||
|
|
||||||
getc(stdin);
|
getc(stdin);
|
||||||
|
mpp_log_f("loop_end start");
|
||||||
for (i = 0; i < cmd->nthreads; i++)
|
for (i = 0; i < cmd->nthreads; i++)
|
||||||
ctxs[i].ctx.loop_end = 1;
|
ctxs[i].ctx.loop_end = 1;
|
||||||
}
|
}
|
||||||
|
@@ -596,6 +596,7 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info)
|
|||||||
RK_U32 eoi = 1;
|
RK_U32 eoi = 1;
|
||||||
|
|
||||||
if (p->fp_input) {
|
if (p->fp_input) {
|
||||||
|
mpp_buffer_sync_begin(p->frm_buf);
|
||||||
ret = read_image(buf, p->fp_input, p->width, p->height,
|
ret = read_image(buf, p->fp_input, p->width, p->height,
|
||||||
p->hor_stride, p->ver_stride, p->fmt);
|
p->hor_stride, p->ver_stride, p->fmt);
|
||||||
if (ret == MPP_NOK || feof(p->fp_input)) {
|
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));
|
mpp_log_q(quiet, "chn %d found last frame. feof %d\n", chn, feof(p->fp_input));
|
||||||
} else if (ret == MPP_ERR_VALUE)
|
} else if (ret == MPP_ERR_VALUE)
|
||||||
goto RET;
|
goto RET;
|
||||||
|
mpp_buffer_sync_end(p->frm_buf);
|
||||||
} else {
|
} else {
|
||||||
if (p->cam_ctx == NULL) {
|
if (p->cam_ctx == NULL) {
|
||||||
|
mpp_buffer_sync_begin(p->frm_buf);
|
||||||
ret = fill_image(buf, p->width, p->height, p->hor_stride,
|
ret = fill_image(buf, p->width, p->height, p->hor_stride,
|
||||||
p->ver_stride, p->fmt, p->frame_count);
|
p->ver_stride, p->fmt, p->frame_count);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto RET;
|
goto RET;
|
||||||
|
mpp_buffer_sync_end(p->frm_buf);
|
||||||
} else {
|
} else {
|
||||||
cam_frm_idx = camera_source_get_frame(p->cam_ctx);
|
cam_frm_idx = camera_source_get_frame(p->cam_ctx);
|
||||||
mpp_assert(cam_frm_idx >= 0);
|
mpp_assert(cam_frm_idx >= 0);
|
||||||
@@ -877,7 +881,7 @@ void *enc_test(void *arg)
|
|||||||
goto MPP_TEST_OUT;
|
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) {
|
if (ret) {
|
||||||
mpp_err_f("failed to get mpp buffer group ret %d\n", ret);
|
mpp_err_f("failed to get mpp buffer group ret %d\n", ret);
|
||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
|
@@ -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)
|
MppBuffer camera_frame_to_buf(CamSource *ctx, RK_S32 idx)
|
||||||
{
|
{
|
||||||
if (idx < 0)
|
MppBuffer buf = NULL;
|
||||||
return 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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user