From: Ming Qian <ming.qian@nxp.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/v4l2_m2m_dec: add a dequeue_timeout parameter Date: Thu, 24 Mar 2022 14:14:12 +0800 Message-ID: <d7263f8fa822307371cbef7e4b41ad03b7bc19ea.1648101782.git.ming.qian@nxp.com> (raw) In-Reply-To: <cover.1648101782.git.ming.qian@nxp.com> the dequeue of capture queue will be blocked until decoded frame available or an input buffer is ready to be dequeued. but it may cause death waiting in some case. For example, it has enqueued the first input frame, and then blocks at ff_v4l2_context_dequeue_frame. For some reason, the decoder can't decode the first frame, also it can't return the input buffer. The decoder needs more input data to decode, so the decoder is just waiting. This creates some kind of deadlock. And in linux/Documentation/userspace-api/media/v4l/dev-decoder.rst, there are some descriptor like below: The client must not assume any direct relationship between CAPTURE and OUTPUT buffers and any specific timing of buffers becoming available to dequeue. Specifically: [snip] - a buffer queued to OUTPUT may result in a buffer being produced on CAPTURE later into decode process, and/or after processing further OUTPUT buffers, or be returned out of order, e.g. if display reordering is used, And I meet a similar case, there are 16 output buffers, but only one buffer is queued to driver, then blocks at ff_v4l2_context_dequeue_frame. But the decoder need more frame data, otherwise it won't decode it. So I think the client should keep processing OUTPUT buffers if there are available buffers until the end. To resolve it, I think we can set a reasonable timeout instead of -1. So I add a parameter dequeue_timeout, and it works on my side. Signed-off-by: Ming Qian <ming.qian@nxp.com> --- libavcodec/v4l2_m2m.h | 5 ++++- libavcodec/v4l2_m2m_dec.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h index 16e0a6d6b90f..5c7e7c955383 100644 --- a/libavcodec/v4l2_m2m.h +++ b/libavcodec/v4l2_m2m.h @@ -38,7 +38,9 @@ #define V4L_M2M_DEFAULT_OPTS \ { "num_output_buffers", "Number of buffers in the output context",\ - OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, INT_MAX, FLAGS } + OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, INT_MAX, FLAGS }, \ + { "dequeue_timeout", "timeout of dequeue in the capture context",\ + OFFSET(dequeue_timeout), AV_OPT_TYPE_INT, { .i64 = 32 }, -1, INT_MAX, FLAGS } typedef struct V4L2m2mContext { char devname[PATH_MAX]; @@ -76,6 +78,7 @@ typedef struct V4L2m2mPriv { int num_output_buffers; int num_capture_buffers; + int dequeue_timeout; } V4L2m2mPriv; /** diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c index 4c521eba343c..e386e09e3e1e 100644 --- a/libavcodec/v4l2_m2m_dec.c +++ b/libavcodec/v4l2_m2m_dec.c @@ -138,6 +138,7 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context; V4L2Context *const capture = &s->capture; V4L2Context *const output = &s->output; + int timeout = ((V4L2m2mPriv*)avctx->priv_data)->dequeue_timeout; int ret; if (!s->buf_pkt.size) { @@ -172,7 +173,9 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) } dequeue: - return ff_v4l2_context_dequeue_frame(capture, frame, -1); + if (s->draining) + timeout = -1; + return ff_v4l2_context_dequeue_frame(capture, frame, timeout); fail: av_packet_unref(&s->buf_pkt); return ret; -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next parent reply other threads:[~2022-03-24 6:14 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <cover.1648101782.git.ming.qian@nxp.com> 2022-03-24 6:14 ` Ming Qian [this message] 2022-03-24 11:22 ` Lynne 2022-03-24 6:14 ` [FFmpeg-devel] [PATCH 2/2] avcodec/v4l2_m2m_enc: " Ming Qian
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=d7263f8fa822307371cbef7e4b41ad03b7bc19ea.1648101782.git.ming.qian@nxp.com \ --to=ming.qian@nxp.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git