[FFmpeg-devel] [PATCH v4 3/3] avcodec/v4l2_m2m_dec: setup capture queue before enqueue the first frame

Ming Qian ming.qian at nxp.com
Thu Aug 19 11:55:33 EEST 2021


there are two proper ways to setup capture queue.
1. client wait the source change event,
   then setup the capture queue and streamon
2. client setup the capture queue in advance,
   but to avoid time issues, client should start
   the capture queue before it enqueue the sequence
   header to decoder driver through output queue.
   and the sequence header is always in the first
   frame, so client should start capture before
   enqueue the first frame.

ffmpeg use the method 2 to setup capture queue,
but currently ffmpeg enqueue the first frame
before starting the capture queue.
so in driver side, there are time issues.
when driver has parsed the resolution from sequence header,
but the client may not finished setup the capture.
so driver can't decide whether to notify a source change event to
client. and the following flow may be chaotic.

And it's OK that client setup capture queue first, then enqueue the
first frame.

Signed-off-by: Ming Qian <ming.qian at nxp.com>
---
 libavcodec/v4l2_m2m_dec.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 224eb3d5e7be..6b936b6df2a9 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -149,6 +149,14 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
     if (s->draining)
         goto dequeue;
 
+    ret = v4l2_try_start(avctx);
+    if (ret) {
+        /* can't recover */
+        if (ret != AVERROR(ENOMEM))
+            ret = 0;
+        goto fail;
+    }
+
     ret = ff_v4l2_context_enqueue_packet(output, &s->buf_pkt);
     if (ret < 0 && ret != AVERROR(EAGAIN))
         goto fail;
@@ -157,16 +165,6 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
     if (ret != AVERROR(EAGAIN))
         av_packet_unref(&s->buf_pkt);
 
-    if (!s->draining) {
-        ret = v4l2_try_start(avctx);
-        if (ret) {
-            /* cant recover */
-            if (ret != AVERROR(ENOMEM))
-                ret = 0;
-            goto fail;
-        }
-    }
-
 dequeue:
     return ff_v4l2_context_dequeue_frame(capture, frame, -1);
 fail:
-- 
2.32.0



More information about the ffmpeg-devel mailing list