* [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format [not found] <20211008100423.739462-1-wenst@chromium.org> @ 2021-10-08 10:04 ` Chen-Yu Tsai 2021-10-08 15:48 ` Nicolas Dufresne 2021-10-13 14:23 ` Ezequiel Garcia 2021-10-08 10:04 ` [PATCH 2/2] media: rkvdec: Support dynamic resolution changes Chen-Yu Tsai 1 sibling, 2 replies; 6+ messages in thread From: Chen-Yu Tsai @ 2021-10-08 10:04 UTC (permalink / raw) To: Ezequiel Garcia, Mauro Carvalho Chehab Cc: Chen-Yu Tsai, linux-media, linux-rockchip, linux-staging, linux-kernel, Greg Kroah-Hartman, Andrzej Pietrasiewicz, stable The rkvdec H.264 decoder currently overrides sizeimage for the output format. This causes issues when userspace requires and requests a larger buffer, but ends up with one of insufficient size. Instead, only provide a default size if none was requested. This fixes the video_decode_accelerator_tests from Chromium failing on the first frame due to insufficient buffer space. It also aligns the behavior of the rkvdec driver with the Hantro and Cedrus drivers. Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") Cc: <stable@vger.kernel.org> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> --- drivers/staging/media/rkvdec/rkvdec-h264.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c index 76e97cbe2512..951e19231da2 100644 --- a/drivers/staging/media/rkvdec/rkvdec-h264.c +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c @@ -1015,8 +1015,9 @@ static int rkvdec_h264_adjust_fmt(struct rkvdec_ctx *ctx, struct v4l2_pix_format_mplane *fmt = &f->fmt.pix_mp; fmt->num_planes = 1; - fmt->plane_fmt[0].sizeimage = fmt->width * fmt->height * - RKVDEC_H264_MAX_DEPTH_IN_BYTES; + if (!fmt->plane_fmt[0].sizeimage) + fmt->plane_fmt[0].sizeimage = fmt->width * fmt->height * + RKVDEC_H264_MAX_DEPTH_IN_BYTES; return 0; } -- 2.33.0.882.g93a45727a2-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format 2021-10-08 10:04 ` [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format Chen-Yu Tsai @ 2021-10-08 15:48 ` Nicolas Dufresne 2021-10-13 14:23 ` Ezequiel Garcia 1 sibling, 0 replies; 6+ messages in thread From: Nicolas Dufresne @ 2021-10-08 15:48 UTC (permalink / raw) To: Chen-Yu Tsai, Ezequiel Garcia, Mauro Carvalho Chehab Cc: linux-media, linux-rockchip, linux-staging, linux-kernel, Greg Kroah-Hartman, Andrzej Pietrasiewicz, stable Le vendredi 08 octobre 2021 à 18:04 +0800, Chen-Yu Tsai a écrit : > The rkvdec H.264 decoder currently overrides sizeimage for the output > format. This causes issues when userspace requires and requests a larger > buffer, but ends up with one of insufficient size. > > Instead, only provide a default size if none was requested. This fixes > the video_decode_accelerator_tests from Chromium failing on the first > frame due to insufficient buffer space. It also aligns the behavior > of the rkvdec driver with the Hantro and Cedrus drivers. > > Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") > Cc: <stable@vger.kernel.org> > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> > --- > drivers/staging/media/rkvdec/rkvdec-h264.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > index 76e97cbe2512..951e19231da2 100644 > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > @@ -1015,8 +1015,9 @@ static int rkvdec_h264_adjust_fmt(struct rkvdec_ctx *ctx, > struct v4l2_pix_format_mplane *fmt = &f->fmt.pix_mp; > > fmt->num_planes = 1; > - fmt->plane_fmt[0].sizeimage = fmt->width * fmt->height * > - RKVDEC_H264_MAX_DEPTH_IN_BYTES; > + if (!fmt->plane_fmt[0].sizeimage) > + fmt->plane_fmt[0].sizeimage = fmt->width * fmt->height * > + RKVDEC_H264_MAX_DEPTH_IN_BYTES; Note that the test is more strict then the spec, since this behaviour is within spec. But in general, the application may have more information about the incoming stream, the maximum encoded frame size would even be encoded in the container (which is parsed in userspace). So I agree it will be more flexible to accept userspace desired size. If that size is too small, userspace will fail at filling it in the first place, and decoding won't be possible, that's all. Perhaps we could make a recommendation in that sense in the spec ? Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > return 0; > } > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format 2021-10-08 10:04 ` [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format Chen-Yu Tsai 2021-10-08 15:48 ` Nicolas Dufresne @ 2021-10-13 14:23 ` Ezequiel Garcia 1 sibling, 0 replies; 6+ messages in thread From: Ezequiel Garcia @ 2021-10-13 14:23 UTC (permalink / raw) To: Chen-Yu Tsai Cc: Mauro Carvalho Chehab, linux-media, linux-rockchip, linux-staging, linux-kernel, Greg Kroah-Hartman, Andrzej Pietrasiewicz, stable Hi Chen-Yu, On Fri, Oct 08, 2021 at 06:04:22PM +0800, Chen-Yu Tsai wrote: > The rkvdec H.264 decoder currently overrides sizeimage for the output > format. This causes issues when userspace requires and requests a larger > buffer, but ends up with one of insufficient size. > > Instead, only provide a default size if none was requested. This fixes > the video_decode_accelerator_tests from Chromium failing on the first > frame due to insufficient buffer space. It also aligns the behavior > of the rkvdec driver with the Hantro and Cedrus drivers. > > Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") > Cc: <stable@vger.kernel.org> > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> Thanks for taking care of this! Ezequiel > --- > drivers/staging/media/rkvdec/rkvdec-h264.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > index 76e97cbe2512..951e19231da2 100644 > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > @@ -1015,8 +1015,9 @@ static int rkvdec_h264_adjust_fmt(struct rkvdec_ctx *ctx, > struct v4l2_pix_format_mplane *fmt = &f->fmt.pix_mp; > > fmt->num_planes = 1; > - fmt->plane_fmt[0].sizeimage = fmt->width * fmt->height * > - RKVDEC_H264_MAX_DEPTH_IN_BYTES; > + if (!fmt->plane_fmt[0].sizeimage) > + fmt->plane_fmt[0].sizeimage = fmt->width * fmt->height * > + RKVDEC_H264_MAX_DEPTH_IN_BYTES; > return 0; > } > > -- > 2.33.0.882.g93a45727a2-goog > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] media: rkvdec: Support dynamic resolution changes [not found] <20211008100423.739462-1-wenst@chromium.org> 2021-10-08 10:04 ` [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format Chen-Yu Tsai @ 2021-10-08 10:04 ` Chen-Yu Tsai 2021-10-08 15:54 ` Nicolas Dufresne 2021-10-13 14:27 ` Ezequiel Garcia 1 sibling, 2 replies; 6+ messages in thread From: Chen-Yu Tsai @ 2021-10-08 10:04 UTC (permalink / raw) To: Ezequiel Garcia, Mauro Carvalho Chehab Cc: Chen-Yu Tsai, linux-media, linux-rockchip, linux-staging, linux-kernel, Greg Kroah-Hartman, Andrzej Pietrasiewicz, stable The mem-to-mem stateless decoder API specifies support for dynamic resolution changes. In particular, the decoder should accept format changes on the OUTPUT queue even when buffers have been allocated, as long as it is not streaming. Relax restrictions for S_FMT as described in the previous paragraph, and as long as the codec format remains the same. This aligns it with the Hantro and Cedrus decoders. This change was mostly based on commit ae02d49493b5 ("media: hantro: Fix s_fmt for dynamic resolution changes"). Since rkvdec_s_fmt() is now just a wrapper around the output/capture variants without any additional shared functionality, drop the wrapper and call the respective functions directly. Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") Cc: <stable@vger.kernel.org> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> --- drivers/staging/media/rkvdec/rkvdec.c | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c index 7131156c1f2c..3f3f96488d74 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -280,31 +280,20 @@ static int rkvdec_try_output_fmt(struct file *file, void *priv, return 0; } -static int rkvdec_s_fmt(struct file *file, void *priv, - struct v4l2_format *f, - int (*try_fmt)(struct file *, void *, - struct v4l2_format *)) +static int rkvdec_s_capture_fmt(struct file *file, void *priv, + struct v4l2_format *f) { struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); struct vb2_queue *vq; + int ret; - if (!try_fmt) - return -EINVAL; - - vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); + /* Change not allowed if queue is busy */ + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); if (vb2_is_busy(vq)) return -EBUSY; - return try_fmt(file, priv, f); -} - -static int rkvdec_s_capture_fmt(struct file *file, void *priv, - struct v4l2_format *f) -{ - struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); - int ret; - - ret = rkvdec_s_fmt(file, priv, f, rkvdec_try_capture_fmt); + ret = rkvdec_try_capture_fmt(file, priv, f); if (ret) return ret; @@ -319,9 +308,20 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; const struct rkvdec_coded_fmt_desc *desc; struct v4l2_format *cap_fmt; - struct vb2_queue *peer_vq; + struct vb2_queue *peer_vq, *vq; int ret; + /* + * In order to support dynamic resolution change, the decoder admits + * a resolution change, as long as the pixelformat remains. Can't be + * done if streaming. + */ + vq = v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); + if (vb2_is_streaming(vq) || + (vb2_is_busy(vq) && + f->fmt.pix_mp.pixelformat != ctx->coded_fmt.fmt.pix_mp.pixelformat)) + return -EBUSY; + /* * Since format change on the OUTPUT queue will reset the CAPTURE * queue, we can't allow doing so when the CAPTURE queue has buffers @@ -331,7 +331,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, if (vb2_is_busy(peer_vq)) return -EBUSY; - ret = rkvdec_s_fmt(file, priv, f, rkvdec_try_output_fmt); + ret = rkvdec_try_output_fmt(file, priv, f); if (ret) return ret; -- 2.33.0.882.g93a45727a2-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: rkvdec: Support dynamic resolution changes 2021-10-08 10:04 ` [PATCH 2/2] media: rkvdec: Support dynamic resolution changes Chen-Yu Tsai @ 2021-10-08 15:54 ` Nicolas Dufresne 2021-10-13 14:27 ` Ezequiel Garcia 1 sibling, 0 replies; 6+ messages in thread From: Nicolas Dufresne @ 2021-10-08 15:54 UTC (permalink / raw) To: Chen-Yu Tsai, Ezequiel Garcia, Mauro Carvalho Chehab Cc: linux-media, linux-rockchip, linux-staging, linux-kernel, Greg Kroah-Hartman, Andrzej Pietrasiewicz, stable Le vendredi 08 octobre 2021 à 18:04 +0800, Chen-Yu Tsai a écrit : > The mem-to-mem stateless decoder API specifies support for dynamic > resolution changes. In particular, the decoder should accept format > changes on the OUTPUT queue even when buffers have been allocated, > as long as it is not streaming. As commented in the code, it also requires the CAPTURE side not to be busy, not sure if its worth clarifying, I don't really mind. > > Relax restrictions for S_FMT as described in the previous paragraph, > and as long as the codec format remains the same. This aligns it with > the Hantro and Cedrus decoders. This change was mostly based on commit > ae02d49493b5 ("media: hantro: Fix s_fmt for dynamic resolution changes"). > > Since rkvdec_s_fmt() is now just a wrapper around the output/capture > variants without any additional shared functionality, drop the wrapper > and call the respective functions directly. > > Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") > Cc: <stable@vger.kernel.org> > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > drivers/staging/media/rkvdec/rkvdec.c | 40 +++++++++++++-------------- > 1 file changed, 20 insertions(+), 20 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c > index 7131156c1f2c..3f3f96488d74 100644 > --- a/drivers/staging/media/rkvdec/rkvdec.c > +++ b/drivers/staging/media/rkvdec/rkvdec.c > @@ -280,31 +280,20 @@ static int rkvdec_try_output_fmt(struct file *file, void *priv, > return 0; > } > > -static int rkvdec_s_fmt(struct file *file, void *priv, > - struct v4l2_format *f, > - int (*try_fmt)(struct file *, void *, > - struct v4l2_format *)) > +static int rkvdec_s_capture_fmt(struct file *file, void *priv, > + struct v4l2_format *f) > { > struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); > struct vb2_queue *vq; > + int ret; > > - if (!try_fmt) > - return -EINVAL; > - > - vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); > + /* Change not allowed if queue is busy */ > + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, > + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); > if (vb2_is_busy(vq)) > return -EBUSY; > > - return try_fmt(file, priv, f); > -} > - > -static int rkvdec_s_capture_fmt(struct file *file, void *priv, > - struct v4l2_format *f) > -{ > - struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); > - int ret; > - > - ret = rkvdec_s_fmt(file, priv, f, rkvdec_try_capture_fmt); > + ret = rkvdec_try_capture_fmt(file, priv, f); > if (ret) > return ret; > > @@ -319,9 +308,20 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, > struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; > const struct rkvdec_coded_fmt_desc *desc; > struct v4l2_format *cap_fmt; > - struct vb2_queue *peer_vq; > + struct vb2_queue *peer_vq, *vq; > int ret; > > + /* > + * In order to support dynamic resolution change, the decoder admits > + * a resolution change, as long as the pixelformat remains. Can't be > + * done if streaming. > + */ > + vq = v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); > + if (vb2_is_streaming(vq) || > + (vb2_is_busy(vq) && > + f->fmt.pix_mp.pixelformat != ctx->coded_fmt.fmt.pix_mp.pixelformat)) > + return -EBUSY; > + > /* > * Since format change on the OUTPUT queue will reset the CAPTURE > * queue, we can't allow doing so when the CAPTURE queue has buffers > @@ -331,7 +331,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, > if (vb2_is_busy(peer_vq)) > return -EBUSY; > > - ret = rkvdec_s_fmt(file, priv, f, rkvdec_try_output_fmt); > + ret = rkvdec_try_output_fmt(file, priv, f); > if (ret) > return ret; > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] media: rkvdec: Support dynamic resolution changes 2021-10-08 10:04 ` [PATCH 2/2] media: rkvdec: Support dynamic resolution changes Chen-Yu Tsai 2021-10-08 15:54 ` Nicolas Dufresne @ 2021-10-13 14:27 ` Ezequiel Garcia 1 sibling, 0 replies; 6+ messages in thread From: Ezequiel Garcia @ 2021-10-13 14:27 UTC (permalink / raw) To: Chen-Yu Tsai Cc: Mauro Carvalho Chehab, linux-media, linux-rockchip, linux-staging, linux-kernel, Greg Kroah-Hartman, Andrzej Pietrasiewicz, stable Hi Chen-Yu, On Fri, Oct 08, 2021 at 06:04:23PM +0800, Chen-Yu Tsai wrote: > The mem-to-mem stateless decoder API specifies support for dynamic > resolution changes. In particular, the decoder should accept format > changes on the OUTPUT queue even when buffers have been allocated, > as long as it is not streaming. > > Relax restrictions for S_FMT as described in the previous paragraph, > and as long as the codec format remains the same. This aligns it with > the Hantro and Cedrus decoders. This change was mostly based on commit > ae02d49493b5 ("media: hantro: Fix s_fmt for dynamic resolution changes"). > > Since rkvdec_s_fmt() is now just a wrapper around the output/capture > variants without any additional shared functionality, drop the wrapper > and call the respective functions directly. > > Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") > Cc: <stable@vger.kernel.org> > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> Seems we forgot to port Hantro changes over here, so thanks a lot for picking this up. Ezequiel > --- > drivers/staging/media/rkvdec/rkvdec.c | 40 +++++++++++++-------------- > 1 file changed, 20 insertions(+), 20 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c > index 7131156c1f2c..3f3f96488d74 100644 > --- a/drivers/staging/media/rkvdec/rkvdec.c > +++ b/drivers/staging/media/rkvdec/rkvdec.c > @@ -280,31 +280,20 @@ static int rkvdec_try_output_fmt(struct file *file, void *priv, > return 0; > } > > -static int rkvdec_s_fmt(struct file *file, void *priv, > - struct v4l2_format *f, > - int (*try_fmt)(struct file *, void *, > - struct v4l2_format *)) > +static int rkvdec_s_capture_fmt(struct file *file, void *priv, > + struct v4l2_format *f) > { > struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); > struct vb2_queue *vq; > + int ret; > > - if (!try_fmt) > - return -EINVAL; > - > - vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); > + /* Change not allowed if queue is busy */ > + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, > + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); > if (vb2_is_busy(vq)) > return -EBUSY; > > - return try_fmt(file, priv, f); > -} > - > -static int rkvdec_s_capture_fmt(struct file *file, void *priv, > - struct v4l2_format *f) > -{ > - struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); > - int ret; > - > - ret = rkvdec_s_fmt(file, priv, f, rkvdec_try_capture_fmt); > + ret = rkvdec_try_capture_fmt(file, priv, f); > if (ret) > return ret; > > @@ -319,9 +308,20 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, > struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; > const struct rkvdec_coded_fmt_desc *desc; > struct v4l2_format *cap_fmt; > - struct vb2_queue *peer_vq; > + struct vb2_queue *peer_vq, *vq; > int ret; > > + /* > + * In order to support dynamic resolution change, the decoder admits > + * a resolution change, as long as the pixelformat remains. Can't be > + * done if streaming. > + */ > + vq = v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); > + if (vb2_is_streaming(vq) || > + (vb2_is_busy(vq) && > + f->fmt.pix_mp.pixelformat != ctx->coded_fmt.fmt.pix_mp.pixelformat)) > + return -EBUSY; > + > /* > * Since format change on the OUTPUT queue will reset the CAPTURE > * queue, we can't allow doing so when the CAPTURE queue has buffers > @@ -331,7 +331,7 @@ static int rkvdec_s_output_fmt(struct file *file, void *priv, > if (vb2_is_busy(peer_vq)) > return -EBUSY; > > - ret = rkvdec_s_fmt(file, priv, f, rkvdec_try_output_fmt); > + ret = rkvdec_try_output_fmt(file, priv, f); > if (ret) > return ret; > > -- > 2.33.0.882.g93a45727a2-goog > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-10-13 14:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20211008100423.739462-1-wenst@chromium.org>
2021-10-08 10:04 ` [PATCH 1/2] media: rkvdec: Do not override sizeimage for output format Chen-Yu Tsai
2021-10-08 15:48 ` Nicolas Dufresne
2021-10-13 14:23 ` Ezequiel Garcia
2021-10-08 10:04 ` [PATCH 2/2] media: rkvdec: Support dynamic resolution changes Chen-Yu Tsai
2021-10-08 15:54 ` Nicolas Dufresne
2021-10-13 14:27 ` Ezequiel Garcia
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox