[FFmpeg-devel] [PATCH 18/25] avcodec/v4l2_context: expose timeout for dequeue_frame

Aman Gupta ffmpeg at tmm1.net
Tue Sep 3 04:02:23 EEST 2019


From: Aman Gupta <aman at tmm1.net>

Signed-off-by: Aman Gupta <aman at tmm1.net>
---
 libavcodec/v4l2_context.c | 6 +++---
 libavcodec/v4l2_context.h | 3 ++-
 libavcodec/v4l2_m2m_dec.c | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 32246cf564..26e06273be 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -616,16 +616,16 @@ int ff_v4l2_context_enqueue_packet(V4L2Context* ctx, const AVPacket* pkt)
     return ff_v4l2_buffer_enqueue(avbuf);
 }
 
-int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* frame)
+int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* frame, int timeout)
 {
     V4L2Buffer* avbuf = NULL;
 
     /*
-     * blocks until:
+     * timeout=-1 blocks until:
      *  1. decoded frame available
      *  2. an input buffer is 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 f9d02b748f..64c53d07b5 100644
--- a/libavcodec/v4l2_context.h
+++ b/libavcodec/v4l2_context.h
@@ -160,9 +160,10 @@ int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt);
  * The frame must be non NULL.
  * @param[in] ctx The V4L2Context to dequeue from.
  * @param[inout] f The AVFrame to dequeue to.
+ * @param[in] timeout The timeout for dequeue (-1 to block, 0 to return immediately or milliseconds)
  * @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_frame(V4L2Context* ctx, AVFrame* f);
+int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, AVFrame* f, int timeout);
 
 /**
  * Enqueues a buffer to a V4L2Context from an AVPacket
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 6b73d2ffd9..b37b6ac7d9 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -172,7 +172,7 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 
 dequeue:
     av_packet_unref(&avpkt);
-    return ff_v4l2_context_dequeue_frame(capture, frame);
+    return ff_v4l2_context_dequeue_frame(capture, frame, -1);
 }
 
 static av_cold int v4l2_decode_init(AVCodecContext *avctx)
-- 
2.20.1



More information about the ffmpeg-devel mailing list