diff options
author | Andriy Gelman <andriy.gelman@gmail.com> | 2020-05-09 19:34:41 -0400 |
---|---|---|
committer | Andriy Gelman <andriy.gelman@gmail.com> | 2020-05-09 19:34:41 -0400 |
commit | e3b49aaa4eed7955e243b110e1209960ba5aaf74 (patch) | |
tree | b93d0223dac52485da9ca66cd9b6f7e2a7d66e0d | |
parent | 785f194cd4f7d8cd9a1742c73c10a09f6006f890 (diff) | |
download | ffmpeg-e3b49aaa4eed7955e243b110e1209960ba5aaf74.tar.gz |
avcodec/v4l2_context: Drop empty packet while draining
v4l2_m2m devices may send an empty packet/frame while draining
to indicate that all capture buffers have been flushed.
Currently, the empty packet/frame is not handled correctly:
When encoding, the empty packet is forwarded to the muxer, usually
creating warnings.
When decoding, a reference to the memory is created anyway. Since in
the past this memory contained a decoded frame, it results in an extra
frame being decoded.
This commit discards the empty packet/frame.
References:
linux/Documentation/media/uapi/v4l/dev-decoder.rst:
"The last buffer may be empty (with :c:type:`v4l2_buffer` bytesused = 0)
and in that case it must be ignored by the client, as it does not
contain a decoded frame."
linux/Documentation/media/uapi/media/v4l/vidioc-encoder-cmd.rst:
"...This buffer may be empty, indicated by the
driver setting the ``bytesused`` field to 0."
Reviewed-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
-rw-r--r-- | libavcodec/v4l2_context.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c index f70e151ec8..52dedb119f 100644 --- a/libavcodec/v4l2_context.c +++ b/libavcodec/v4l2_context.c @@ -405,6 +405,15 @@ dequeue: return NULL; } + if (ctx_to_m2mctx(ctx)->draining && !V4L2_TYPE_IS_OUTPUT(ctx->type)) { + int bytesused = V4L2_TYPE_IS_MULTIPLANAR(buf.type) ? + buf.m.planes[0].bytesused : buf.bytesused; + if (bytesused == 0) { + ctx->done = 1; + return NULL; + } + } + avbuf = &ctx->buffers[buf.index]; avbuf->status = V4L2BUF_AVAILABLE; avbuf->buf = buf; |