aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/v4l2_m2m_enc.c
diff options
context:
space:
mode:
authorMing Qian <ming.qian@nxp.com>2020-04-01 10:38:45 +0800
committerAndriy Gelman <andriy.gelman@gmail.com>2020-04-14 23:42:05 -0400
commit8ac8e905e934aaae3f3ad3a0e2f2066b55b1c560 (patch)
tree7db7cdefff36d8b1e1ef30c9492e58fae44e8591 /libavcodec/v4l2_m2m_enc.c
parent0607f1bcb0f6ed04b7bb3a5b3d951fd9b1554561 (diff)
downloadffmpeg-8ac8e905e934aaae3f3ad3a0e2f2066b55b1c560.tar.gz
avcodec/v4l2_m2m: handle v4l2 end of stream event
When flushing the capture buffers, the driver may send a V4L2_EVENT_EOS to notify that draining is completed. Currently, v4l2_m2m does not subscribe to this event, which can cause some devices (i.e. imx8qm) to hang at the end of encoding/decoding. Support for handling the event is added in this commit. Some devices may not signal V4L2_EVENT_EOS. This is logged as a warning message during initialization and not treated as a fatal error. Signed-off-by: Ming Qian <ming.qian@nxp.com> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Diffstat (limited to 'libavcodec/v4l2_m2m_enc.c')
-rw-r--r--libavcodec/v4l2_m2m_enc.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 84de63ec9d..a025860126 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -155,6 +155,17 @@ static int v4l2_check_b_frame_support(V4L2m2mContext *s)
return AVERROR_PATCHWELCOME;
}
+static inline void v4l2_subscribe_eos_event(V4L2m2mContext *s)
+{
+ struct v4l2_event_subscription sub;
+
+ memset(&sub, 0, sizeof(sub));
+ sub.type = V4L2_EVENT_EOS;
+ if (ioctl(s->fd, VIDIOC_SUBSCRIBE_EVENT, &sub) < 0)
+ av_log(s->avctx, AV_LOG_WARNING,
+ "the v4l2 driver does not support end of stream VIDIOC_SUBSCRIBE_EVENT\n");
+}
+
static int v4l2_prepare_encoder(V4L2m2mContext *s)
{
AVCodecContext *avctx = s->avctx;
@@ -164,6 +175,8 @@ static int v4l2_prepare_encoder(V4L2m2mContext *s)
/**
* requirements
*/
+ v4l2_subscribe_eos_event(s);
+
ret = v4l2_check_b_frame_support(s);
if (ret)
return ret;