2022-07-11 21:28:45

by Ezequiel Garcia

[permalink] [raw]
Subject: [PATCH v2 0/8] videobuf2: Replace vb2_find_timestamp() with vb2_find_buffer()

All users of vb2_find_timestamp() combine it with vb2_get_buffer()
to retrieve a videobuf2 buffer, given a u64 timestamp.

Therefore, this series removes vb2_find_timestamp() and instead
introduces a vb2_find_buffer, which is more suitable, making
videobuf2 API slightly cleaner.

Changes from v1:

* Introduce API in its final shape, to make review easier.
* Prefix cedrus_write_ref_buf_addr and move to common cedrus.c

Ezequiel Garcia (8):
videobuf2: Introduce vb2_find_buffer()
mediatek: vcodec: Use vb2_find_buffer
tegra-vde: Use vb2_find_buffer
vicodec: Use vb2_find_buffer
hantro: Use vb2_find_buffer
rkvdec: Use vb2_find_buffer
cedrus: Use vb2_find_buffer
videobuf2: Remove vb2_find_timestamp()

.../media/common/videobuf2/videobuf2-v4l2.c | 11 +++--
.../vcodec/vdec/vdec_h264_req_common.c | 7 ++-
.../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 7 ++-
.../vcodec/vdec/vdec_vp9_req_lat_if.c | 8 ++--
.../media/platform/nvidia/tegra-vde/h264.c | 9 ++--
.../media/test-drivers/vicodec/vicodec-core.c | 8 +---
drivers/staging/media/hantro/hantro_drv.c | 6 +--
.../staging/media/hantro/hantro_g2_vp9_dec.c | 10 ++---
drivers/staging/media/rkvdec/rkvdec-h264.c | 41 ++++++------------
drivers/staging/media/rkvdec/rkvdec-vp9.c | 10 ++---
drivers/staging/media/sunxi/cedrus/cedrus.h | 24 ++++++-----
.../staging/media/sunxi/cedrus/cedrus_h264.c | 16 +++----
.../staging/media/sunxi/cedrus/cedrus_h265.c | 16 +++----
.../staging/media/sunxi/cedrus/cedrus_mpeg2.c | 28 ++++--------
.../staging/media/sunxi/cedrus/cedrus_vp8.c | 43 ++++---------------
include/media/videobuf2-v4l2.h | 12 ++----
16 files changed, 96 insertions(+), 160 deletions(-)

--
2.34.3


2022-07-11 21:30:24

by Ezequiel Garcia

[permalink] [raw]
Subject: [PATCH v2 2/8] mediatek: vcodec: Use vb2_find_buffer

Use the newly introduced vb2_find_buffer API to get a vb2_buffer
given a buffer timestamp.

Cc: Tiffany Lin <[email protected]>
Cc: Andrew-CT Chen <[email protected]>
Cc: Yunfei Dong <[email protected]>
Signed-off-by: Ezequiel Garcia <[email protected]>
Acked-by: Tomasz Figa <[email protected]>
---
.../platform/mediatek/vcodec/vdec/vdec_h264_req_common.c | 7 +++----
.../media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c | 7 +++----
.../platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 8 ++++----
3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
index ca628321d272..580ce979e2a3 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
@@ -51,7 +51,7 @@ void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx,
struct vb2_queue *vq;
struct vb2_buffer *vb;
struct vb2_v4l2_buffer *vb2_v4l2;
- int index, vb2_index;
+ int index;

vq = v4l2_m2m_get_vq(ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);

@@ -62,8 +62,8 @@ void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx,
continue;
}

- vb2_index = vb2_find_timestamp(vq, dpb->reference_ts, 0);
- if (vb2_index < 0) {
+ vb = vb2_find_buffer(vq, dpb->reference_ts);
+ if (!vb) {
dev_err(&ctx->dev->plat_dev->dev,
"Reference invalid: dpb_index(%d) reference_ts(%lld)",
index, dpb->reference_ts);
@@ -76,7 +76,6 @@ void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx,
else
h264_dpb_info[index].reference_flag = 2;

- vb = vq->bufs[vb2_index];
vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf);
h264_dpb_info[index].field = vb2_v4l2->field;

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
index eef102f3f4f3..e1fe2603e92e 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
@@ -237,7 +237,7 @@ static int vdec_vp8_slice_get_decode_parameters(struct vdec_vp8_slice_inst *inst
struct vb2_queue *vq;
struct vb2_buffer *vb;
u64 referenct_ts;
- int index, vb2_index;
+ int index;

frame_header = vdec_vp8_slice_get_ctrl_ptr(inst->ctx, V4L2_CID_STATELESS_VP8_FRAME);
if (IS_ERR(frame_header))
@@ -246,8 +246,8 @@ static int vdec_vp8_slice_get_decode_parameters(struct vdec_vp8_slice_inst *inst
vq = v4l2_m2m_get_vq(ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
for (index = 0; index < 3; index++) {
referenct_ts = vdec_vp8_slice_get_ref_by_ts(frame_header, index);
- vb2_index = vb2_find_timestamp(vq, referenct_ts, 0);
- if (vb2_index < 0) {
+ vb = vb2_find_buffer(vq, referenct_ts);
+ if (!vb) {
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(frame_header))
mtk_vcodec_err(inst, "reference invalid: index(%d) ts(%lld)",
index, referenct_ts);
@@ -256,7 +256,6 @@ static int vdec_vp8_slice_get_decode_parameters(struct vdec_vp8_slice_inst *inst
}
inst->vsi->vp8_dpb_info[index].reference_flag = 1;

- vb = vq->bufs[vb2_index];
inst->vsi->vp8_dpb_info[index].y_dma_addr =
vb2_dma_contig_plane_dma_addr(vb, 0);
if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 2)
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
index 81de876d5126..fb1c36a3592d 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
@@ -1672,7 +1672,6 @@ static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst
struct vdec_vp9_slice_reference *ref;
int plane;
int size;
- int idx;
int w;
int h;
int i;
@@ -1715,15 +1714,16 @@ static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst
*/
for (i = 0; i < 3; i++) {
ref = &vsi->frame.ref[i];
- idx = vb2_find_timestamp(vq, pfc->ref_idx[i], 0);
- if (idx < 0) {
+ vb = vb2_find_buffer(vq, pfc->ref_idx[i]);
+ if (!vb) {
ref->frame_width = w;
ref->frame_height = h;
memset(&vsi->ref[i], 0, sizeof(vsi->ref[i]));
} else {
+ int idx = vb->index;
+
ref->frame_width = instance->dpb[idx].width;
ref->frame_height = instance->dpb[idx].height;
- vb = vq->bufs[idx];
vsi->ref[i].y.dma_addr =
vb2_dma_contig_plane_dma_addr(vb, 0);
if (plane == 1)
--
2.34.3

2022-07-11 21:34:56

by Ezequiel Garcia

[permalink] [raw]
Subject: [PATCH v2 4/8] vicodec: Use vb2_find_buffer

Use the newly introduced vb2_find_buffer API to get a vb2_buffer
given a buffer timestamp.

Cc: Hans Verkuil <[email protected]>
Signed-off-by: Ezequiel Garcia <[email protected]>
Acked-by: Tomasz Figa <[email protected]>
---
drivers/media/test-drivers/vicodec/vicodec-core.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c
index be43f7d32df9..1d1bee111732 100644
--- a/drivers/media/test-drivers/vicodec/vicodec-core.c
+++ b/drivers/media/test-drivers/vicodec/vicodec-core.c
@@ -280,17 +280,13 @@ static int device_process(struct vicodec_ctx *ctx,
*/
if (!(ntohl(ctx->state.header.flags) & V4L2_FWHT_FL_I_FRAME)) {
struct vb2_buffer *ref_vb2_buf;
- int ref_buf_idx;
struct vb2_queue *vq_cap =
v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
V4L2_BUF_TYPE_VIDEO_CAPTURE);

- ref_buf_idx = vb2_find_timestamp(vq_cap,
- ctx->state.ref_frame_ts, 0);
- if (ref_buf_idx < 0)
+ ref_vb2_buf = vb2_find_buffer(vq_cap, ctx->state.ref_frame_ts);
+ if (!ref_vb2_buf)
return -EINVAL;
-
- ref_vb2_buf = vq_cap->bufs[ref_buf_idx];
if (ref_vb2_buf->state == VB2_BUF_STATE_ERROR)
ret = -EINVAL;
ctx->state.ref_frame.buf =
--
2.34.3

2022-07-11 21:35:38

by Ezequiel Garcia

[permalink] [raw]
Subject: [PATCH v2 3/8] tegra-vde: Use vb2_find_buffer

Use the newly introduced vb2_find_buffer API to get a vb2_buffer
given a buffer timestamp.

Cc: Dmitry Osipenko <[email protected]>
Signed-off-by: Ezequiel Garcia <[email protected]>
Acked-by: Tomasz Figa <[email protected]>
---
drivers/media/platform/nvidia/tegra-vde/h264.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/nvidia/tegra-vde/h264.c b/drivers/media/platform/nvidia/tegra-vde/h264.c
index 88f81a134ba0..204e474d57f7 100644
--- a/drivers/media/platform/nvidia/tegra-vde/h264.c
+++ b/drivers/media/platform/nvidia/tegra-vde/h264.c
@@ -659,20 +659,19 @@ static struct vb2_buffer *get_ref_buf(struct tegra_ctx *ctx,
{
const struct v4l2_h264_dpb_entry *dpb = ctx->h264.decode_params->dpb;
struct vb2_queue *cap_q = &ctx->fh.m2m_ctx->cap_q_ctx.q;
- int buf_idx = -1;
+ struct vb2_buffer *vb = NULL;

if (dpb[dpb_idx].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
- buf_idx = vb2_find_timestamp(cap_q,
- dpb[dpb_idx].reference_ts, 0);
+ vb = vb2_find_buffer(cap_q, dpb[dpb_idx].reference_ts);

/*
* If a DPB entry is unused or invalid, address of current destination
* buffer is returned.
*/
- if (buf_idx < 0)
+ if (!vb)
return &dst->vb2_buf;

- return vb2_get_buffer(cap_q, buf_idx);
+ return vb;
}

static int tegra_vde_validate_vb_size(struct tegra_ctx *ctx,
--
2.34.3

2022-07-11 21:43:13

by Ezequiel Garcia

[permalink] [raw]
Subject: [PATCH v2 8/8] videobuf2: Remove vb2_find_timestamp()

Now that we've transitioned all users to vb2_find_buffer API,
remove the unused vb2_find_timestamp().

Signed-off-by: Ezequiel Garcia <[email protected]>
Acked-by: Tomasz Figa <[email protected]>
---
drivers/media/common/videobuf2/videobuf2-v4l2.c | 13 -------------
include/media/videobuf2-v4l2.h | 16 ----------------
2 files changed, 29 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index f26cb8586bd4..4e84a0e1aca2 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -625,19 +625,6 @@ static const struct vb2_buf_ops v4l2_buf_ops = {
.copy_timestamp = __copy_timestamp,
};

-int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp,
- unsigned int start_idx)
-{
- unsigned int i;
-
- for (i = start_idx; i < q->num_buffers; i++)
- if (q->bufs[i]->copied_timestamp &&
- q->bufs[i]->timestamp == timestamp)
- return i;
- return -1;
-}
-EXPORT_SYMBOL_GPL(vb2_find_timestamp);
-
struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp)
{
unsigned int i;
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index 76e405c0b003..5a845887850b 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -62,22 +62,6 @@ struct vb2_v4l2_buffer {
#define to_vb2_v4l2_buffer(vb) \
container_of(vb, struct vb2_v4l2_buffer, vb2_buf)

-/**
- * vb2_find_timestamp() - Find buffer with given timestamp in the queue
- *
- * @q: pointer to &struct vb2_queue with videobuf2 queue.
- * @timestamp: the timestamp to find.
- * @start_idx: the start index (usually 0) in the buffer array to start
- * searching from. Note that there may be multiple buffers
- * with the same timestamp value, so you can restart the search
- * by setting @start_idx to the previously found index + 1.
- *
- * Returns the buffer index of the buffer with the given @timestamp, or
- * -1 if no buffer with @timestamp was found.
- */
-int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp,
- unsigned int start_idx);
-
/**
* vb2_find_buffer() - Find a buffer with given timestamp
*
--
2.34.3

2022-07-14 19:19:15

by Dmitry Osipenko

[permalink] [raw]
Subject: Re: [PATCH v2 3/8] tegra-vde: Use vb2_find_buffer

12.07.2022 00:11, Ezequiel Garcia пишет:
> Use the newly introduced vb2_find_buffer API to get a vb2_buffer
> given a buffer timestamp.
>
> Cc: Dmitry Osipenko <[email protected]>
> Signed-off-by: Ezequiel Garcia <[email protected]>
> Acked-by: Tomasz Figa <[email protected]>
> ---
> drivers/media/platform/nvidia/tegra-vde/h264.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/platform/nvidia/tegra-vde/h264.c b/drivers/media/platform/nvidia/tegra-vde/h264.c
> index 88f81a134ba0..204e474d57f7 100644
> --- a/drivers/media/platform/nvidia/tegra-vde/h264.c
> +++ b/drivers/media/platform/nvidia/tegra-vde/h264.c
> @@ -659,20 +659,19 @@ static struct vb2_buffer *get_ref_buf(struct tegra_ctx *ctx,
> {
> const struct v4l2_h264_dpb_entry *dpb = ctx->h264.decode_params->dpb;
> struct vb2_queue *cap_q = &ctx->fh.m2m_ctx->cap_q_ctx.q;
> - int buf_idx = -1;
> + struct vb2_buffer *vb = NULL;
>
> if (dpb[dpb_idx].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
> - buf_idx = vb2_find_timestamp(cap_q,
> - dpb[dpb_idx].reference_ts, 0);
> + vb = vb2_find_buffer(cap_q, dpb[dpb_idx].reference_ts);
>
> /*
> * If a DPB entry is unused or invalid, address of current destination
> * buffer is returned.
> */
> - if (buf_idx < 0)
> + if (!vb)
> return &dst->vb2_buf;
>
> - return vb2_get_buffer(cap_q, buf_idx);
> + return vb;
> }
>
> static int tegra_vde_validate_vb_size(struct tegra_ctx *ctx,

Acked-by: Dmitry Osipenko <[email protected]>