[FFmpeg-devel,3/3] avcodec: v4l2_m2m: context: fix raising warning on POLLERR

Submitted by Jorge Ramirez-Ortiz on Jan. 9, 2018, 5:06 p.m.

Details

Message ID 1515517573-27292-3-git-send-email-jorge.ramirez.ortiz@gmail.com
State New
Headers show

Commit Message

Jorge Ramirez-Ortiz Jan. 9, 2018, 5:06 p.m.
From: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>

During the initialization stage, the codec attempts to get free
buffers from the driver before any have been queued (this is to keep
the code simple and generic)

When the kernel driver detects this situation, it returns POLLERR in
revents and ffmpeg therefore raises a warning.

This commit disables the warning since no buffers were queued to the
driver yet.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
---
 libavcodec/v4l2_context.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Jorge Ramirez-Ortiz Jan. 9, 2018, 10:08 p.m.
On 01/09/2018 06:06 PM, Jorge Ramirez-Ortiz wrote:
> From: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
>
> During the initialization stage, the codec attempts to get free
> buffers from the driver before any have been queued (this is to keep
> the code simple and generic)
>
> When the kernel driver detects this situation, it returns POLLERR in
> revents and ffmpeg therefore raises a warning.
>
> This commit disables the warning since no buffers were queued to the
> driver yet.
>
> Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
> ---
>   libavcodec/v4l2_context.c | 16 ++++++++++++++--
>   1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
> index fb482cf..5bacaaf 100644
> --- a/libavcodec/v4l2_context.c
> +++ b/libavcodec/v4l2_context.c
> @@ -258,7 +258,7 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout)
>           .events =  POLLIN | POLLRDNORM | POLLPRI | POLLOUT | POLLWRNORM, /* default blocking capture */
>           .fd = ctx_to_m2mctx(ctx)->fd,
>       };
> -    int ret;
> +    int i, ret;
>   
>       if (V4L2_TYPE_IS_OUTPUT(ctx->type))
>           pfd.events =  POLLOUT | POLLWRNORM;
> @@ -279,7 +279,19 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout)
>   
>       /* 0. handle errors */
>       if (pfd.revents & POLLERR) {
> -        av_log(logger(ctx), AV_LOG_WARNING, "%s POLLERR\n", ctx->name);
> +	    /* if we are trying to get free buffers but none have been queued yet
> +	       no need to raise a warning */

sorry about the linux tabs (my editor messed it up, my fault)
will fix.

> +	    if (timeout == 0 ) {
> +		for (i = 0; i < ctx->num_buffers; i++) {
> +			if (ctx->buffers[i].status != V4L2BUF_AVAILABLE) {
> +				av_log(logger(ctx), AV_LOG_WARNING, "%s POLLERR\n", ctx->name);
> +				return NULL;
> +			}
> +		}
> +	    }
> +	    else
> +		    av_log(logger(ctx), AV_LOG_WARNING, "%s POLLERR\n", ctx->name);
> +
>           return NULL;
>       }
>

Patch hide | download patch | download mbox

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index fb482cf..5bacaaf 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -258,7 +258,7 @@  static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout)
         .events =  POLLIN | POLLRDNORM | POLLPRI | POLLOUT | POLLWRNORM, /* default blocking capture */
         .fd = ctx_to_m2mctx(ctx)->fd,
     };
-    int ret;
+    int i, ret;
 
     if (V4L2_TYPE_IS_OUTPUT(ctx->type))
         pfd.events =  POLLOUT | POLLWRNORM;
@@ -279,7 +279,19 @@  static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout)
 
     /* 0. handle errors */
     if (pfd.revents & POLLERR) {
-        av_log(logger(ctx), AV_LOG_WARNING, "%s POLLERR\n", ctx->name);
+	    /* if we are trying to get free buffers but none have been queued yet
+	       no need to raise a warning */
+	    if (timeout == 0 ) {
+		for (i = 0; i < ctx->num_buffers; i++) {
+			if (ctx->buffers[i].status != V4L2BUF_AVAILABLE) {
+				av_log(logger(ctx), AV_LOG_WARNING, "%s POLLERR\n", ctx->name);
+				return NULL;
+			}
+		}
+	    }
+	    else
+		    av_log(logger(ctx), AV_LOG_WARNING, "%s POLLERR\n", ctx->name);
+
         return NULL;
     }