[FFmpeg-devel] [PATCH 2/2] avcodec/v4l2_m2m_enc: add a dequeue_timeout parameter
Ming Qian
ming.qian at nxp.com
Thu Mar 24 08:14:13 EET 2022
For the reason similar to decoder,
Set a reasonable timeout instead of -1
to avoid dead waiting in some case.
Signed-off-by: Ming Qian <ming.qian at nxp.com>
---
libavcodec/v4l2_context.c | 4 ++--
libavcodec/v4l2_context.h | 2 +-
libavcodec/v4l2_m2m_enc.c | 5 ++++-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 8910ae08d3a5..1122e68f9a97 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -644,7 +644,7 @@ int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* frame, int timeout)
return ff_v4l2_buffer_buf_to_avframe(frame, avbuf);
}
-int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt)
+int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt, int timeout)
{
V4L2Buffer *avbuf;
@@ -653,7 +653,7 @@ int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt)
* 1. encoded packet available
* 2. an input buffer ready to be dequeued
*/
- avbuf = v4l2_dequeue_v4l2buf(ctx, -1);
+ avbuf = v4l2_dequeue_v4l2buf(ctx, timeout);
if (!avbuf) {
if (ctx->done)
return AVERROR_EOF;
diff --git a/libavcodec/v4l2_context.h b/libavcodec/v4l2_context.h
index 6f7460c89a9d..b385bccc82a9 100644
--- a/libavcodec/v4l2_context.h
+++ b/libavcodec/v4l2_context.h
@@ -148,7 +148,7 @@ int ff_v4l2_context_set_status(V4L2Context* ctx, uint32_t cmd);
* @param[inout] pkt The AVPacket to dequeue to.
* @return 0 in case of success, AVERROR(EAGAIN) if no buffer was ready, another negative error in case of error.
*/
-int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt);
+int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt, int timeout);
/**
* Dequeues a buffer from a V4L2Context to an AVFrame.
diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 1d90de2b9d14..7eae121cf33f 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -290,6 +290,7 @@ static int v4l2_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
V4L2Context *const capture = &s->capture;
V4L2Context *const output = &s->output;
AVFrame *frame = s->frame;
+ int timeout = ((V4L2m2mPriv*)avctx->priv_data)->dequeue_timeout;
int ret;
if (s->draining)
@@ -328,7 +329,9 @@ static int v4l2_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
}
dequeue:
- return ff_v4l2_context_dequeue_packet(capture, avpkt);
+ if (s->draining)
+ timeout = -1;
+ return ff_v4l2_context_dequeue_packet(capture, avpkt, timeout);
}
static av_cold int v4l2_encode_init(AVCodecContext *avctx)
--
2.33.0
More information about the ffmpeg-devel
mailing list