@@ -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;
@@ -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.
@@ -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)
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(-)