add support to stateless decoder
Subsystems (6)
v4 cover add support to stateless decoder
main changes from v2:
- fixes according to the review.
- patch 5: new bugfix
- patches 16, 17, 18: new documentation
Dafna Hirschfeld (18):
media: vicodec: selection api should only check single buffer types
media: vicodec: upon release, call m2m release before freeing ctrl
handler
media: v4l2-ctrl: v4l2_ctrl_request_setup returns with error upon
failure
media: vicodec: change variable name for the return value of
v4l2_fwht_encode
media: vicodec: bugfix - call v4l2_m2m_buf_copy_metadata also if
decoding fails
media: vicodec: bugfix: free compressed_frame upon device release
media: vicodec: Move raw frame preparation code to a function
media: vicodec: add field 'buf' to fwht_raw_frame
media: vicodec: keep the ref frame according to the format in decoder
media: vicodec: Validate version dependent header values in a separate
function
media: vicodec: rename v4l2_fwht_default_fmt to v4l2_fwht_find_nth_fmt
media: vicodec: add struct for encoder/decoder instance
media: vicodec: add documentation to V4L2_CID_FWHT_I/P_FRAME_QP
media: vicodec: add documentation to V4L2_CID_MPEG_VIDEO_FWHT_PARAMS
media: vicodec: add documentation to V4L2_PIX_FMT_FWHT_STATELESS
media: vicodec: Introducing stateless fwht defs and structs
media: vicodec: Register another node for stateless decoder
media: vicodec: Add support for stateless decoder.
Hans Verkuil (3):
vb2: add requires_requests bit for stateless codecs videodev2.h: add V4L2_BUF_CAP_REQUIRES_REQUESTS
cedrus: set requires_requests
.../media/uapi/v4l/ext-ctrls-codec.rst | 66 ++ .../media/uapi/v4l/pixfmt-compressed.rst | 5 + .../media/uapi/v4l/vidioc-reqbufs.rst | 4 + .../media/common/videobuf2/videobuf2-core.c | 5 +- .../media/common/videobuf2/videobuf2-v4l2.c | 6 + drivers/media/platform/vicodec/codec-fwht.c | 83 ++- drivers/media/platform/vicodec/codec-fwht.h | 12 +- .../media/platform/vicodec/codec-v4l2-fwht.c | 420 ++++------- .../media/platform/vicodec/codec-v4l2-fwht.h | 7 +- drivers/media/platform/vicodec/vicodec-core.c | 665 +++++++++++++----- drivers/media/v4l2-core/v4l2-ctrls.c | 28 +- .../staging/media/sunxi/cedrus/cedrus_video.c | 1 + include/media/fwht-ctrls.h | 32 + include/media/v4l2-ctrls.h | 6 +- include/media/videobuf2-core.h | 3 + include/uapi/linux/v4l2-controls.h | 3 + include/uapi/linux/videodev2.h | 2 + 17 files changed, 822 insertions(+), 526 deletions(-) create mode 100644 include/media/fwht-ctrls.h
Signature · 1 line
2.17.1
PATCH v4 1/21 vb2: add requires_requests bit for stateless codecs
From: Hans Verkuil <[email protected]>
Stateless codecs require the use of the Request API as opposed of it being optional.
So add a bit to indicate this and let vb2 check for this.
--- drivers/media/common/videobuf2/videobuf2-core.c | 5 ++++- drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 ++++++ include/media/videobuf2-core.h | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/media/common/videobuf2/videobuf2-core.c +4 -1
@@ -1518,7 +1518,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,if ((req && q->uses_qbuf) || (!req && vb->state !=VB2_BUF_STATE_IN_REQUEST && - q->uses_requests)) { + (q->uses_requests || q->requires_requests))) {dprintk (1 ,"queue in wrong mode (qbuf vs requests)\n" );return -EBUSY ; }
@@ -2247,6 +2247,9 @@ int vb2_core_queue_init(struct vb2_queue *q) WARN_ON(!q->ops->buf_queue))return -EINVAL ; +if (WARN_ON (q->requires_requests && !q->supports_requests)) +return -EINVAL ; +INIT_LIST_HEAD (&q->queued_list);INIT_LIST_HEAD (&q->done_list);spin_lock_init (&q->done_lock);
drivers/media/common/videobuf2/videobuf2-v4l2.c +6 -0
@@ -385,6 +385,10 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mddprintk (1 ,"%s: queue uses requests\n" , opname);return -EBUSY ; } +if (q->requires_requests) { +dprintk (1 ,"%s: queue requires requests\n" , opname); +return -EACCES ; + }return 0 ; }else if (!q->supports_requests) {dprintk (1 ,"%s: queue does not support requests\n" , opname);
@@ -658,6 +662,8 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps)#ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API if (q->supports_requests) *caps |=V4L2_BUF_CAP_SUPPORTS_REQUESTS ; +if (q->requires_requests) + *caps |=V4L2_BUF_CAP_REQUIRES_REQUESTS ;#endif }
include/media/videobuf2-core.h +3 -0
@@ -484,6 +484,8 @@ struct vb2_buf_ops {* has not been called. This is a vb1 idiom that has been adopted * also by vb2. * @supports_requests: this queue supports the Request API. +* @requires_requests: this queue requires the Request API. If this is set to 1, +* then supports_requests must be set to 1 as well. * @uses_qbuf: qbuf was used directly for this queue. Set to 1 the first * time this is called. Set to 0 when the queue is canceled. * If this is 1, then you cannot queue buffers from a request.
@@ -558,6 +560,7 @@ struct vb2_queue { unsigned allow_zero_bytesused:1; unsigned quirk_poll_must_check_waiting_for_buffers:1; unsigned supports_requests:1; + unsigned requires_requests:1; unsigned uses_qbuf:1; unsigned uses_requests:1;
Signature · 1 line
2.17.1
PATCH v4 2/21 videodev2.h: add V4L2_BUF_CAP_REQUIRES_REQUESTS
In reply to Dafna HirschfeldFrom: Hans Verkuil <[email protected]>
Add capability to indicate that requests are required instead of merely supported.
--- Documentation/media/uapi/v4l/vidioc-reqbufs.rst | 4 ++++ include/uapi/linux/videodev2.h | 1 + 2 files changed, 5 insertions(+)
Documentation/media/uapi/v4l/vidioc-reqbufs.rst +4 -0
@@ -125,6 +125,7 @@ aborting or finishing any DMA in progress, an implicit .. _V4L2-BUF-CAP-SUPPORTS-DMABUF: .. _V4L2-BUF-CAP-SUPPORTS-REQUESTS: .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS: +.. _V4L2-BUF-CAP-REQUIRES-REQUESTS: .. cssclass:: longtable
@@ -150,6 +151,9 @@ aborting or finishing any DMA in progress, an implicit - The kernel allows calling :ref:`VIDIOC_REQBUFS` while buffers are still mapped or exported via DMABUF. These orphaned buffers will be freed when they are unmapped or when the exported DMABUF fds are closed. + * - ``V4L2_BUF_CAP_REQUIRES_REQUESTS`` + - 0x00000020 + - This buffer type requires the use of :ref:`requests <media-request-api>`. Return Value ============
include/uapi/linux/videodev2.h +1 -0
@@ -895,6 +895,7 @@ struct v4l2_requestbuffers {#define V4L2_BUF_CAP_SUPPORTS_DMABUF (1 << 2)#define V4L2_BUF_CAP_SUPPORTS_REQUESTS (1 << 3)#define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4) +#define V4L2_BUF_CAP_REQUIRES_REQUESTS (1 << 5)/** * struct v4l2_plane - plane info for multi-planar buffers
Signature · 1 line
2.17.1
PATCH v4 3/21 cedrus: set requires_requests
In reply to Dafna HirschfeldFrom: Hans Verkuil <[email protected]>
The cedrus stateless decoder requires the use of request, so indicate this by setting requires_requests to 1.
--- drivers/staging/media/sunxi/cedrus/cedrus_video.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/media/sunxi/cedrus/cedrus_video.c +1 -0
@@ -536,6 +536,7 @@ int cedrus_queue_init(void *priv, struct vb2_queue *src_vq, src_vq->lock = &ctx->dev->dev_mutex; src_vq->dev = ctx->dev->dev; src_vq->supports_requests = true; + src_vq->requires_requests = true; ret =vb2_queue_init (src_vq);if (ret)
Signature · 1 line
2.17.1
PATCH v4 4/21 media: vicodec: selection api should only check single buffer types
In reply to Dafna HirschfeldThe selection api should check only single buffer types because multiplanar types are converted to single in drivers/media/v4l2-core/v4l2-ioctl.c
--- drivers/media/platform/vicodec/vicodec-core.c | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-)
drivers/media/platform/vicodec/vicodec-core.c +3 -17
@@ -945,16 +945,6 @@ static int vidioc_g_selection(struct file *file, void *priv, {struct vicodec_ctx *ctx =file2ctx (file);struct vicodec_q_data *q_data; -enum v4l2_buf_type valid_cap_type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; -enum v4l2_buf_type valid_out_type =V4L2_BUF_TYPE_VIDEO_OUTPUT ; - -if (multiplanar) { - valid_cap_type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; - valid_out_type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; - } - -if (s->type != valid_cap_type && s->type != valid_out_type) -return -EINVAL ; q_data =get_q_data (ctx, s->type);if (!q_data)
@@ -963,8 +953,8 @@ static int vidioc_g_selection(struct file *file, void *priv,* encoder supports only cropping on the OUTPUT buffer * decoder supports only composing on the CAPTURE buffer */ -if ((ctx->is_enc && s->type == valid_out_type) || - (!ctx->is_enc && s->type == valid_cap_type)) { +if ((ctx->is_enc && s->type ==V4L2_BUF_TYPE_VIDEO_OUTPUT ) || + (!ctx->is_enc && s->type ==V4L2_BUF_TYPE_VIDEO_CAPTURE )) {switch (s->target) {case V4L2_SEL_TGT_COMPOSE :case V4L2_SEL_TGT_CROP :
@@ -992,12 +982,8 @@ static int vidioc_s_selection(struct file *file, void *priv, {struct vicodec_ctx *ctx =file2ctx (file);struct vicodec_q_data *q_data; -enum v4l2_buf_type out_type =V4L2_BUF_TYPE_VIDEO_OUTPUT ; - -if (multiplanar) - out_type =V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ; -if (s->type != out_type) +if (s->type !=V4L2_BUF_TYPE_VIDEO_OUTPUT )return -EINVAL ; q_data =get_q_data (ctx, s->type);
Signature · 1 line
2.17.1
PATCH v4 5/21 media: vicodec: upon release, call m2m release before freeing ctrl handler
In reply to Dafna Hirschfeld'v4l2_m2m_ctx_release' calls request complete so it should be called before 'v4l2_ctrl_handler_free'.
--- drivers/media/platform/vicodec/vicodec-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/vicodec/vicodec-core.c +3 -3
@@ -1606,12 +1606,12 @@ static int vicodec_release(struct file *file)struct video_device *vfd =video_devdata (file);struct vicodec_ctx *ctx =file2ctx (file); -v4l2_fh_del (&ctx->fh); -v4l2_fh_exit (&ctx->fh); -v4l2_ctrl_handler_free (&ctx->hdl);mutex_lock (vfd->lock);v4l2_m2m_ctx_release (ctx->fh.m2m_ctx);mutex_unlock (vfd->lock); +v4l2_fh_del (&ctx->fh); +v4l2_fh_exit (&ctx->fh); +v4l2_ctrl_handler_free (&ctx->hdl);kfree (ctx);return 0 ;
Signature · 1 line
2.17.1
PATCH v4 6/21 media: v4l2-ctrl: v4l2_ctrl_request_setup returns with error upon failure
In reply to Dafna HirschfeldIf one of the controls fails to set,
then 'v4l2_ctrl_request_setup'
immediately returns with the error code.
--- drivers/media/v4l2-core/v4l2-ctrls.c | 18 +++++++++++------- include/media/v4l2-ctrls.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +11 -7
@@ -3899,18 +3899,19 @@ void v4l2_ctrl_request_complete(struct media_request *req, }EXPORT_SYMBOL (v4l2_ctrl_request_complete); -void v4l2_ctrl_request_setup (struct media_request *req, +int v4l2_ctrl_request_setup (struct media_request *req,struct v4l2_ctrl_handler *main_hdl) {struct media_request_object *obj;struct v4l2_ctrl_handler *hdl;struct v4l2_ctrl_ref *ref; +int ret =0 ;if (!req || !main_hdl) -return ; +return 0 ;if (WARN_ON (req->state !=MEDIA_REQUEST_STATE_QUEUED )) -return ; +return -EBUSY ;/* * Note that it is valid if nothing was found. It means
@@ -3919,10 +3920,10 @@ void v4l2_ctrl_request_setup(struct media_request *req,*/ obj =media_request_object_find (req, &req_ops, main_hdl);if (!obj) -return ; +return 0 ;if (obj->completed) {media_request_object_put (obj); -return ; +return -EBUSY ; } hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);
@@ -3990,12 +3991,15 @@ void v4l2_ctrl_request_setup(struct media_request *req,update_from_auto_cluster (master); } -try_or_set_cluster (NULL , master, true,0 ); - + ret =try_or_set_cluster (NULL , master, true,0 );v4l2_ctrl_unlock (master); + +if (ret) +break ; }media_request_object_put (obj); +return ret; }EXPORT_SYMBOL (v4l2_ctrl_request_setup);
include/media/v4l2-ctrls.h +1 -1
@@ -1127,7 +1127,7 @@ __poll_t v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);* applying control values in a request is only applicable to memory-to-memory * devices. */ -void v4l2_ctrl_request_setup (struct media_request *req, +int v4l2_ctrl_request_setup (struct media_request *req,struct v4l2_ctrl_handler *parent);/**
Signature · 1 line
2.17.1
PATCH v4 7/21 media: vicodec: change variable name for the return value of v4l2_fwht_encode
In reply to Dafna Hirschfeldv4l2_fwht_encode returns either an error code on failure or the size of the compressed frame on success. So change the var assigned to it from 'ret' to 'comp_sz_or_errcode' to clarify that.
--- drivers/media/platform/vicodec/vicodec-core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/platform/vicodec/vicodec-core.c +5 -4
@@ -178,13 +178,14 @@ static int device_process(struct vicodec_ctx *ctx,if (ctx->is_enc) {struct vicodec_q_data *q_src; +int comp_sz_or_errcode; q_src =get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT ); state->info = q_src->info; - ret =v4l2_fwht_encode (state, p_src, p_dst); -if (ret <0 ) -return ret; -vb2_set_plane_payload (&dst_vb->vb2_buf,0 , ret); + comp_sz_or_errcode =v4l2_fwht_encode (state, p_src, p_dst); +if (comp_sz_or_errcode <0 ) +return comp_sz_or_errcode; +vb2_set_plane_payload (&dst_vb->vb2_buf,0 , comp_sz_or_errcode); }else {unsigned int comp_frame_size =ntohl (ctx->state.header.size);
Signature · 1 line
2.17.1
PATCH v4 8/21 media: vicodec: bugfix - call v4l2_m2m_buf_copy_metadata also if decoding fails
In reply to Dafna HirschfeldThe function 'v4l2_m2m_buf_copy_metadata' should be called even if decoding/encoding ends with status VB2_BUF_STATE_ERROR, so that the metadata is copied from the source buffer to the dest buffer.
--- drivers/media/platform/vicodec/vicodec-core.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/media/platform/vicodec/vicodec-core.c +9 -8
@@ -159,12 +159,10 @@ static int device_process(struct vicodec_ctx *ctx, struct vb2_v4l2_buffer *dst_vb) {struct vicodec_dev *dev = ctx->dev; -struct vicodec_q_data *q_dst;struct v4l2_fwht_state *state = &ctx->state;u8 *p_src, *p_dst;int ret; - q_dst =get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE );if (ctx->is_enc) p_src =vb2_plane_vaddr (&src_vb->vb2_buf,0 );else
@@ -187,8 +185,10 @@ static int device_process(struct vicodec_ctx *ctx,return comp_sz_or_errcode;vb2_set_plane_payload (&dst_vb->vb2_buf,0 , comp_sz_or_errcode); }else { +struct vicodec_q_data *q_dst;unsigned int comp_frame_size =ntohl (ctx->state.header.size); + q_dst =get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE );if (comp_frame_size > ctx->comp_max_size)return -EINVAL ; state->info = q_dst->info;
@@ -197,11 +197,6 @@ static int device_process(struct vicodec_ctx *ctx,return ret;vb2_set_plane_payload (&dst_vb->vb2_buf,0 , q_dst->sizeimage); } - - dst_vb->sequence = q_dst->sequence++; - dst_vb->flags &= ~V4L2_BUF_FLAG_LAST ; -v4l2_m2m_buf_copy_metadata (src_vb, dst_vb, !ctx->is_enc); -return 0 ; }
@@ -275,16 +270,22 @@ static void device_run(void *priv)struct vicodec_ctx *ctx = priv;struct vicodec_dev *dev = ctx->dev;struct vb2_v4l2_buffer *src_buf, *dst_buf; -struct vicodec_q_data *q_src; +struct vicodec_q_data *q_src, *q_dst;u32 state; src_buf =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); dst_buf =v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); q_src =get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT ); + q_dst =get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE ); state =VB2_BUF_STATE_DONE ;if (device_process (ctx, src_buf, dst_buf)) state =VB2_BUF_STATE_ERROR ; +else + dst_buf->sequence = q_dst->sequence++; + dst_buf->flags &= ~V4L2_BUF_FLAG_LAST ; +v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, !ctx->is_enc); + ctx->last_dst_buf = dst_buf;spin_lock (ctx->lock);
Signature · 1 line
2.17.1
PATCH v4 9/21 media: vicodec: bugfix: free compressed_frame upon device release
In reply to Dafna HirschfeldFree compressed_frame buffer upon device release.
--- drivers/media/platform/vicodec/vicodec-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/vicodec/vicodec-core.c +1 -0
@@ -1614,6 +1614,7 @@ static int vicodec_release(struct file *file)v4l2_fh_del (&ctx->fh);v4l2_fh_exit (&ctx->fh);v4l2_ctrl_handler_free (&ctx->hdl); +kvfree (ctx->state.compressed_frame);kfree (ctx);return 0 ;
Signature · 1 line
2.17.1