Commit da45ad48 authored by Jorge Ramirez-Ortiz's avatar Jorge Ramirez-Ortiz Committed by Aman Gupta

avcodec/v4l2m2m: fix error handling during buffer init

Signed-off-by: 's avatarJorge Ramirez-Ortiz <jramirez@baylibre.com>
Signed-off-by: 's avatarAman Gupta <aman@tmm1.net>
parent 1d36b7b4
...@@ -267,6 +267,12 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout) ...@@ -267,6 +267,12 @@ static V4L2Buffer* v4l2_dequeue_v4l2buf(V4L2Context *ctx, int timeout)
/* if we are draining and there are no more capture buffers queued in the driver we are done */ /* 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) { if (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx_to_m2mctx(ctx)->draining) {
for (i = 0; i < ctx->num_buffers; i++) { for (i = 0; i < ctx->num_buffers; i++) {
/* capture buffer initialization happens during decode hence
* detection happens at runtime
*/
if (!ctx->buffers)
break;
if (ctx->buffers[i].status == V4L2BUF_IN_DRIVER) if (ctx->buffers[i].status == V4L2BUF_IN_DRIVER)
goto start; goto start;
} }
...@@ -698,9 +704,8 @@ int ff_v4l2_context_init(V4L2Context* ctx) ...@@ -698,9 +704,8 @@ int ff_v4l2_context_init(V4L2Context* ctx)
ctx->buffers[i].context = ctx; ctx->buffers[i].context = ctx;
ret = ff_v4l2_buffer_initialize(&ctx->buffers[i], i); ret = ff_v4l2_buffer_initialize(&ctx->buffers[i], i);
if (ret < 0) { if (ret < 0) {
av_log(logger(ctx), AV_LOG_ERROR, "%s buffer initialization (%s)\n", ctx->name, av_err2str(ret)); av_log(logger(ctx), AV_LOG_ERROR, "%s buffer[%d] initialization (%s)\n", ctx->name, i, av_err2str(ret));
av_free(ctx->buffers); goto error;
return ret;
} }
} }
...@@ -713,4 +718,12 @@ int ff_v4l2_context_init(V4L2Context* ctx) ...@@ -713,4 +718,12 @@ int ff_v4l2_context_init(V4L2Context* ctx)
V4L2_TYPE_IS_MULTIPLANAR(ctx->type) ? ctx->format.fmt.pix_mp.plane_fmt[0].bytesperline : ctx->format.fmt.pix.bytesperline); V4L2_TYPE_IS_MULTIPLANAR(ctx->type) ? ctx->format.fmt.pix_mp.plane_fmt[0].bytesperline : ctx->format.fmt.pix.bytesperline);
return 0; return 0;
error:
v4l2_release_buffers(ctx);
av_free(ctx->buffers);
ctx->buffers = NULL;
return ret;
} }
...@@ -86,8 +86,8 @@ static int v4l2_try_start(AVCodecContext *avctx) ...@@ -86,8 +86,8 @@ static int v4l2_try_start(AVCodecContext *avctx)
if (!capture->buffers) { if (!capture->buffers) {
ret = ff_v4l2_context_init(capture); ret = ff_v4l2_context_init(capture);
if (ret) { if (ret) {
av_log(avctx, AV_LOG_DEBUG, "can't request output buffers\n"); av_log(avctx, AV_LOG_ERROR, "can't request capture buffers\n");
return ret; return AVERROR(ENOMEM);
} }
} }
...@@ -151,6 +151,11 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) ...@@ -151,6 +151,11 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
ret = v4l2_try_start(avctx); ret = v4l2_try_start(avctx);
if (ret) { if (ret) {
av_packet_unref(&avpkt); av_packet_unref(&avpkt);
/* cant recover */
if (ret == AVERROR(ENOMEM))
return ret;
return 0; return 0;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment