Skip to content

Commit 16060f7

Browse files
Tiffany Linmchehab
authored andcommitted
[media] vcodec:mediatek: Add timestamp and timecode copy for V4L2 Encoder
This patch add copying timestamp and timecode from src buffer to dst buffer Signed-off-by: Tiffany Lin <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 91ae0e1 commit 16060f7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ static int mtk_venc_encode_header(void *priv)
868868
{
869869
struct mtk_vcodec_ctx *ctx = priv;
870870
int ret;
871-
struct vb2_buffer *dst_buf;
871+
struct vb2_buffer *src_buf, *dst_buf;
872+
struct vb2_v4l2_buffer *dst_vb2_v4l2, *src_vb2_v4l2;
872873
struct mtk_vcodec_mem bs_buf;
873874
struct venc_done_result enc_result;
874875

@@ -901,6 +902,15 @@ static int mtk_venc_encode_header(void *priv)
901902
mtk_v4l2_err("venc_if_encode failed=%d", ret);
902903
return -EINVAL;
903904
}
905+
src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
906+
if (src_buf) {
907+
src_vb2_v4l2 = to_vb2_v4l2_buffer(src_buf);
908+
dst_vb2_v4l2 = to_vb2_v4l2_buffer(dst_buf);
909+
dst_buf->timestamp = src_buf->timestamp;
910+
dst_vb2_v4l2->timecode = src_vb2_v4l2->timecode;
911+
} else {
912+
mtk_v4l2_err("No timestamp for the header buffer.");
913+
}
904914

905915
ctx->state = MTK_STATE_HEADER;
906916
dst_buf->planes[0].bytesused = enc_result.bs_size;
@@ -993,7 +1003,7 @@ static void mtk_venc_worker(struct work_struct *work)
9931003
struct mtk_vcodec_mem bs_buf;
9941004
struct venc_done_result enc_result;
9951005
int ret, i;
996-
struct vb2_v4l2_buffer *vb2_v4l2;
1006+
struct vb2_v4l2_buffer *dst_vb2_v4l2, *src_vb2_v4l2;
9971007

9981008
/* check dst_buf, dst_buf may be removed in device_run
9991009
* to stored encdoe header so we need check dst_buf and
@@ -1033,9 +1043,14 @@ static void mtk_venc_worker(struct work_struct *work)
10331043
ret = venc_if_encode(ctx, VENC_START_OPT_ENCODE_FRAME,
10341044
&frm_buf, &bs_buf, &enc_result);
10351045

1036-
vb2_v4l2 = container_of(dst_buf, struct vb2_v4l2_buffer, vb2_buf);
1046+
src_vb2_v4l2 = to_vb2_v4l2_buffer(src_buf);
1047+
dst_vb2_v4l2 = to_vb2_v4l2_buffer(dst_buf);
1048+
1049+
dst_buf->timestamp = src_buf->timestamp;
1050+
dst_vb2_v4l2->timecode = src_vb2_v4l2->timecode;
1051+
10371052
if (enc_result.is_key_frm)
1038-
vb2_v4l2->flags |= V4L2_BUF_FLAG_KEYFRAME;
1053+
dst_vb2_v4l2->flags |= V4L2_BUF_FLAG_KEYFRAME;
10391054

10401055
if (ret) {
10411056
v4l2_m2m_buf_done(to_vb2_v4l2_buffer(src_buf),

0 commit comments

Comments
 (0)