[PATCH 08/18] media: coda: Add log to finish_encode if buffer is too small

Sergey Khimich posted 18 patches 9 months, 1 week ago
[PATCH 08/18] media: coda: Add log to finish_encode if buffer is too small
Posted by Sergey Khimich 9 months, 1 week ago
From: Vladimir Yakovlev <vovchkir@gmail.com>

CODA_RET_ENC_PIC_FLAG flag means that bitstream buffer size
is not enough to save one frame data when buffer reset mode is used.
If this flag is set, currently encoded bitstream is corrupted.

Co-developed-by: Sergey Khimich <serghox@gmail.com>
Signed-off-by: Sergey Khimich <serghox@gmail.com>
Signed-off-by: Vladimir Yakovlev <vovchkir@gmail.com>
---
 drivers/media/platform/chips-media/coda/coda-bit.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/chips-media/coda/coda-bit.c b/drivers/media/platform/chips-media/coda/coda-bit.c
index 3e3bb3d64ec9..515eb8be4b86 100644
--- a/drivers/media/platform/chips-media/coda/coda-bit.c
+++ b/drivers/media/platform/chips-media/coda/coda-bit.c
@@ -1641,6 +1641,7 @@ static void coda_finish_encode(struct coda_ctx *ctx)
 	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	struct coda_dev *dev = ctx->dev;
 	u32 wr_ptr, start_ptr;
+	int val;
 
 	if (ctx->aborting)
 		return;
@@ -1674,7 +1675,12 @@ static void coda_finish_encode(struct coda_ctx *ctx)
 	coda_dbg(1, ctx, "frame size = %u\n", wr_ptr - start_ptr);
 
 	coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM);
-	coda_read(dev, CODA_RET_ENC_PIC_FLAG);
+	val = coda_read(dev, CODA_RET_ENC_PIC_FLAG);
+	if (val > 0) {
+		v4l2_err(&dev->v4l2_dev,
+			 "Encode fail. Encode buffer is too small\n");
+		// TODO what to do next?
+	}
 
 	dst_buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
 			    V4L2_BUF_FLAG_PFRAME |
-- 
2.30.2
Re: [PATCH 08/18] media: coda: Add log to finish_encode if buffer is too small
Posted by Nicolas Dufresne 6 months, 3 weeks ago
Hi,

Le vendredi 14 mars 2025 à 18:29 +0300, Sergey Khimich a écrit :
> From: Vladimir Yakovlev <vovchkir@gmail.com>
> 
> CODA_RET_ENC_PIC_FLAG flag means that bitstream buffer size
> is not enough to save one frame data when buffer reset mode is used.
> If this flag is set, currently encoded bitstream is corrupted.
> 
> Co-developed-by: Sergey Khimich <serghox@gmail.com>
> Signed-off-by: Sergey Khimich <serghox@gmail.com>
> Signed-off-by: Vladimir Yakovlev <vovchkir@gmail.com>
> ---
>  drivers/media/platform/chips-media/coda/coda-bit.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/chips-media/coda/coda-bit.c b/drivers/media/platform/chips-media/coda/coda-bit.c
> index 3e3bb3d64ec9..515eb8be4b86 100644
> --- a/drivers/media/platform/chips-media/coda/coda-bit.c
> +++ b/drivers/media/platform/chips-media/coda/coda-bit.c
> @@ -1641,6 +1641,7 @@ static void coda_finish_encode(struct coda_ctx *ctx)
>  	struct vb2_v4l2_buffer *src_buf, *dst_buf;
>  	struct coda_dev *dev = ctx->dev;
>  	u32 wr_ptr, start_ptr;
> +	int val;
>  
>  	if (ctx->aborting)
>  		return;
> @@ -1674,7 +1675,12 @@ static void coda_finish_encode(struct coda_ctx *ctx)
>  	coda_dbg(1, ctx, "frame size = %u\n", wr_ptr - start_ptr);
>  
>  	coda_read(dev, CODA_RET_ENC_PIC_SLICE_NUM);
> -	coda_read(dev, CODA_RET_ENC_PIC_FLAG);
> +	val = coda_read(dev, CODA_RET_ENC_PIC_FLAG);
> +	if (val > 0) {
> +		v4l2_err(&dev->v4l2_dev,
> +			 "Encode fail. Encode buffer is too small\n");
> +		// TODO what to do next?

Lower in the same function, you should still copy the metadata but replace
VB2_BUF_STATE_DONE with VB2_BUF_STATE_ERROR. Perhaps introduce a state
variable and set it accordingly.

Nicolas

> +	}
>  
>  	dst_buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
>  			    V4L2_BUF_FLAG_PFRAME |