diff mbox series

[FFmpeg-devel,2/2] avcodec/v4l2_m2m_enc: add a dequeue_timeout parameter

Message ID b8f43d5ff274afdef8c2fc3440970a4c27d2bf9c.1648101782.git.ming.qian@nxp.com
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/v4l2_m2m_dec: add a dequeue_timeout parameter | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Ming Qian March 24, 2022, 6:14 a.m. UTC
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@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 mbox series

Patch

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)