container_of(ctx, V4L2m2mContext, capture);
}
-static inline AVClass *logger(V4L2Context *ctx)
+static inline AVCodecContext *logger(V4L2Context *ctx)
{
- return ctx_to_m2mctx(ctx)->priv;
+ return ctx_to_m2mctx(ctx)->avctx;
}
static inline unsigned int v4l2_get_width(struct v4l2_format *fmt)
}
/**
+ * handle resolution change event and end of stream event
* returns 1 if reinit was successful, negative if it failed
* returns 0 if reinit was not executed
*/
return 0;
}
+ if (evt.type == V4L2_EVENT_EOS) {
+ ctx->done = 1;
+ return 0;
+ }
+
if (evt.type != V4L2_EVENT_SOURCE_CHANGE)
return 0;
};
int i, ret;
+ if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx->buffers) {
+ for (i = 0; i < ctx->num_buffers; i++) {
+ if (ctx->buffers[i].status == V4L2BUF_IN_DRIVER)
+ break;
+ }
+ if (i == ctx->num_buffers)
+ av_log(logger(ctx), AV_LOG_WARNING, "All capture buffers returned to "
+ "userspace. Increase num_capture_buffers "
+ "to prevent device deadlock or dropped "
+ "packets/frames.\n");
+ }
+
/* if we are draining and there are no more capture buffers queued in the driver we are done */
if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx_to_m2mctx(ctx)->draining) {
for (i = 0; i < ctx->num_buffers; i++) {
return NULL;
}
+ if (ctx_to_m2mctx(ctx)->draining && !V4L2_TYPE_IS_OUTPUT(ctx->type)) {
+ int bytesused = V4L2_TYPE_IS_MULTIPLANAR(buf.type) ?
+ buf.m.planes[0].bytesused : buf.bytesused;
+ if (bytesused == 0) {
+ ctx->done = 1;
+ return NULL;
+ }
+#ifdef V4L2_BUF_FLAG_LAST
+ if (buf.flags & V4L2_BUF_FLAG_LAST)
+ ctx->done = 1;
+#endif
+ }
+
avbuf = &ctx->buffers[buf.index];
avbuf->status = V4L2BUF_AVAILABLE;
avbuf->buf = buf;
avbuf = v4l2_getfree_v4l2buf(ctx);
if (!avbuf)
- return AVERROR(ENOMEM);
+ return AVERROR(EAGAIN);
ret = ff_v4l2_buffer_avframe_to_buf(frame, avbuf);
if (ret)
if (ret)
av_log(logger(ctx), AV_LOG_WARNING, "V4L2 failed to unmap the %s buffers\n", ctx->name);
- av_free(ctx->buffers);
- ctx->buffers = NULL;
+ av_freep(&ctx->buffers);
}
int ff_v4l2_context_init(V4L2Context* ctx)
error:
v4l2_release_buffers(ctx);
- av_free(ctx->buffers);
- ctx->buffers = NULL;
+ av_freep(&ctx->buffers);
return ret;
}