1

media: amphion: Report the average QP of current encoded frame

Report the average QP value of the current encoded frame via the
V4L2_CID_MPEG_VIDEO_AVERAGE_QP control, the value applies to the last
dequeued capture buffer.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
Ming Qian 2024-05-06 17:49:18 +09:00 committed by Hans Verkuil
parent 065927b51e
commit 1034ead1a7
6 changed files with 25 additions and 0 deletions

View File

@ -678,6 +678,9 @@ static int venc_ctrl_init(struct vpu_inst *inst)
~(1 << V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME), ~(1 << V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME),
V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME); V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME);
v4l2_ctrl_new_std(&inst->ctrl_handler, NULL,
V4L2_CID_MPEG_VIDEO_AVERAGE_QP, 0, 51, 1, 0);
if (inst->ctrl_handler.error) { if (inst->ctrl_handler.error) {
ret = inst->ctrl_handler.error; ret = inst->ctrl_handler.error;
v4l2_ctrl_handler_free(&inst->ctrl_handler); v4l2_ctrl_handler_free(&inst->ctrl_handler);
@ -817,6 +820,7 @@ static int venc_get_one_encoded_frame(struct vpu_inst *inst,
vbuf->field = inst->cap_format.field; vbuf->field = inst->cap_format.field;
vbuf->flags |= frame->info.pic_type; vbuf->flags |= frame->info.pic_type;
vpu_set_buffer_state(vbuf, VPU_BUF_STATE_IDLE); vpu_set_buffer_state(vbuf, VPU_BUF_STATE_IDLE);
vpu_set_buffer_average_qp(vbuf, frame->info.average_qp);
dev_dbg(inst->dev, "[%d][OUTPUT TS]%32lld\n", inst->id, vbuf->vb2_buf.timestamp); dev_dbg(inst->dev, "[%d][OUTPUT TS]%32lld\n", inst->id, vbuf->vb2_buf.timestamp);
v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE); v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE);
venc->ready_count++; venc->ready_count++;

View File

@ -306,6 +306,7 @@ struct vpu_vb2_buffer {
dma_addr_t chroma_v; dma_addr_t chroma_v;
unsigned int state; unsigned int state;
u32 tag; u32 tag;
u32 average_qp;
}; };
void vpu_writel(struct vpu_dev *vpu, u32 reg, u32 val); void vpu_writel(struct vpu_dev *vpu, u32 reg, u32 val);

View File

@ -114,6 +114,7 @@ struct vpu_enc_pic_info {
u32 wptr; u32 wptr;
u32 crc; u32 crc;
s64 timestamp; s64 timestamp;
u32 average_qp;
}; };
struct vpu_dec_codec_info { struct vpu_dec_codec_info {

View File

@ -63,6 +63,13 @@ unsigned int vpu_get_buffer_state(struct vb2_v4l2_buffer *vbuf)
return vpu_buf->state; return vpu_buf->state;
} }
void vpu_set_buffer_average_qp(struct vb2_v4l2_buffer *vbuf, u32 qp)
{
struct vpu_vb2_buffer *vpu_buf = to_vpu_vb2_buffer(vbuf);
vpu_buf->average_qp = qp;
}
void vpu_v4l2_set_error(struct vpu_inst *inst) void vpu_v4l2_set_error(struct vpu_inst *inst)
{ {
vpu_inst_lock(inst); vpu_inst_lock(inst);
@ -539,6 +546,15 @@ static void vpu_vb2_buf_finish(struct vb2_buffer *vb)
struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue); struct vpu_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_queue *q = vb->vb2_queue; struct vb2_queue *q = vb->vb2_queue;
if (V4L2_TYPE_IS_CAPTURE(vb->type)) {
struct vpu_vb2_buffer *vpu_buf = to_vpu_vb2_buffer(vbuf);
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&inst->ctrl_handler,
V4L2_CID_MPEG_VIDEO_AVERAGE_QP);
if (ctrl)
v4l2_ctrl_s_ctrl(ctrl, vpu_buf->average_qp);
}
if (vbuf->flags & V4L2_BUF_FLAG_LAST) if (vbuf->flags & V4L2_BUF_FLAG_LAST)
vpu_notify_eos(inst); vpu_notify_eos(inst);

View File

@ -12,6 +12,7 @@ void vpu_inst_lock(struct vpu_inst *inst);
void vpu_inst_unlock(struct vpu_inst *inst); void vpu_inst_unlock(struct vpu_inst *inst);
void vpu_set_buffer_state(struct vb2_v4l2_buffer *vbuf, unsigned int state); void vpu_set_buffer_state(struct vb2_v4l2_buffer *vbuf, unsigned int state);
unsigned int vpu_get_buffer_state(struct vb2_v4l2_buffer *vbuf); unsigned int vpu_get_buffer_state(struct vb2_v4l2_buffer *vbuf);
void vpu_set_buffer_average_qp(struct vb2_v4l2_buffer *vbuf, u32 qp);
int vpu_v4l2_open(struct file *file, struct vpu_inst *inst); int vpu_v4l2_open(struct file *file, struct vpu_inst *inst);
int vpu_v4l2_close(struct file *file); int vpu_v4l2_close(struct file *file);

View File

@ -499,6 +499,7 @@ struct windsor_pic_info {
u32 proc_dacc_rng_wr_cnt; u32 proc_dacc_rng_wr_cnt;
s32 tv_s; s32 tv_s;
u32 tv_ns; u32 tv_ns;
u32 average_qp;
}; };
u32 vpu_windsor_get_data_size(void) u32 vpu_windsor_get_data_size(void)
@ -734,6 +735,7 @@ static void vpu_windsor_unpack_pic_info(struct vpu_rpc_event *pkt, void *data)
info->wptr = get_ptr(windsor->str_buff_wptr); info->wptr = get_ptr(windsor->str_buff_wptr);
info->crc = windsor->frame_crc; info->crc = windsor->frame_crc;
info->timestamp = timespec64_to_ns(&ts); info->timestamp = timespec64_to_ns(&ts);
info->average_qp = windsor->average_qp;
} }
static void vpu_windsor_unpack_mem_req(struct vpu_rpc_event *pkt, void *data) static void vpu_windsor_unpack_mem_req(struct vpu_rpc_event *pkt, void *data)