From patchwork Sat Aug 4 00:40:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Rusak X-Patchwork-Id: 9882 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp726383jad; Fri, 3 Aug 2018 17:41:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdgs4JaC+CH0/I1tAKQMeEm4tIT0zMa7R+DjwDYWsTT8qeoli2sEAZi1Xf+BtdDo/VbS8+7 X-Received: by 2002:a1c:b984:: with SMTP id j126-v6mr5888888wmf.25.1533343265805; Fri, 03 Aug 2018 17:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533343265; cv=none; d=google.com; s=arc-20160816; b=dk63Wv0STDIKSQF/S18f11n1MO1w1MaroJjZihUsITJrXsIMRe9AErdpcqc8VVpO6B zn/XH2koIzupcA/ITx8eEMWTcbkEhJl67AVV98pa71DQ1lo1vJt+RdtU/hcrfNZiicvK YqAQwMQjPEX15JZ3VdPiCnQrQkV4WSf2AmQOU4x9lYY8s9eJw6VnE/Oa7CIWF7jD8wKY +mhT3mFx6/RmcEUkZLc8BftFKmtO5144yETSFtzH5mfFJtuNt+Q56KBrVzJnOfBzShrJ +IUls07rS63VrHW9a+vz/5lH3++/lK1uIS0Abej5YpSi00RiDVZBdJhpH4QbLgw4Jyml T4AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=iVHWDPt+icwnx9YjVOfWD2AEfFgzL/qof3sIIpo35qM=; b=rpkxCVaAkcPSo5K/Xc9fenC9sSjmc5w9pGHGv+bbOsnn4UOgun8aVgLSbZ8/wUZ74b mFVWxfzVEEe/HNZXb9g0RYSWwTFBT5UhefzECIp+aeqPvcHdKgNewv5kZfQk0CaEB1gA ADTnjOIrw2wicip+ljfPfGvf6CKQR4+PAQX+hXz/MKS8p0g/bl4glNeZtevA0O9tKLSE pEMCgMlOle0XLs6t++lIkEA6UXnaTs7joruCUK3/80z+stxITG0oxKDbbcJHSgbRnydu yVUDOT1ahC5d5a3EM2un6dGSfbXlPRbro6QrUhzS5Mev2AVv7yOgErvdQuHoQXm+aj0c eXXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oHjXzkrY; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z11-v6si3994019wrs.172.2018.08.03.17.41.05; Fri, 03 Aug 2018 17:41:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=oHjXzkrY; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ADA4F689FDB; Sat, 4 Aug 2018 03:40:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D6E0C689D89 for ; Sat, 4 Aug 2018 03:40:20 +0300 (EEST) Received: by mail-pf1-f181.google.com with SMTP id j26-v6so4054335pfi.10 for ; Fri, 03 Aug 2018 17:40:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DbIwEown2qEC7aiSCGRYKWIA/VT7Z5WFbxMRE3YK3Lk=; b=oHjXzkrY/4ecAoxUA6E/7hHCRPSnvPHtY2SDoo6ETYeiHF5rV9Dpe2TaR2Ast4IU+k 8mZVtk2C+PrjV0Qx/2jSCokQRhlXLdtzF+1Uq+e6QwvF1dPM6Ebg1MVQTTioeiPFRimI NHAdLP/LF0A+15K/MHUDdQyj+hEgGhyp1GVxZMGMhOy+li4QvyL1evRGwiI2dW9y5g7K 1nZ5xy1rrbYXB3AvnLkuU8auKa2W7jA/sQD8KvhzmYd8o84ofhzLMtDF1UAD3oE/RrqR hR8v9FODQqSIhFPhspRNp66N5YFhmSoxl96kM87o7f8yE3GwNgBXpv1cpLp2AvRiD6up SS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DbIwEown2qEC7aiSCGRYKWIA/VT7Z5WFbxMRE3YK3Lk=; b=CSLUMlTgk/eomU6luKJF3Mrnfceo4a2WYwXwBtZ1r8oSQxmn4oic+gVYlnRY8Mnn0q 0yV3VZNBLHqcYGDHr7qH17RIPaJGOQUFooYIjbrADjs3OgLo/ttC+bz2SeUnWXIeCDOF t71+eFisITa5xJbFp+7vnavqQU602aVtv9ZSR5wmA+9NJCPaLr7qdLLP/FH5KiHthyz7 csbFBZuElnedX2Ci/9Gxi1ySrRGP0LemVZ8pesRHTEzTHQNsdWmqmdrO+T3+A4qWoNEh Y8Os7cCz1RnMxTAElbUTzYbnLsLVbFXKIk+Nrf4MKtB1BGf7+vFhjVvuToS2+qN72dY7 1uAQ== X-Gm-Message-State: AOUpUlGayEptpbKy2VsSODW/+N5CZ2AXjFoZDqaKngHkQyIGffC62Bu/ 4hNypwBmlZztJ72qrQsdlpnRaB/8 X-Received: by 2002:a62:d693:: with SMTP id a19-v6mr6744411pfl.248.1533343237916; Fri, 03 Aug 2018 17:40:37 -0700 (PDT) Received: from localhost.localdomain (d154-20-200-72.bchsia.telus.net. [154.20.200.72]) by smtp.gmail.com with ESMTPSA id e8-v6sm1107265pfj.16.2018.08.03.17.40.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 17:40:36 -0700 (PDT) From: Lukas Rusak To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Aug 2018 17:40:31 -0700 Message-Id: <20180804004031.12143-4-lorusak@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180804004031.12143-1-lorusak@gmail.com> References: <20180804004031.12143-1-lorusak@gmail.com> Subject: [FFmpeg-devel] [PATCH 4/4] libavcodec: v4l2m2m: fix error handling during buffer init X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Jorge Ramirez-Ortiz Signed-off-by: Jorge Ramirez-Ortiz --- libavcodec/v4l2_context.c | 19 ++++++++++++++++--- libavcodec/v4l2_m2m_dec.c | 9 +++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c index 9457fadb1e..fd3161ce2f 100644 --- a/libavcodec/v4l2_context.c +++ b/libavcodec/v4l2_context.c @@ -263,6 +263,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 (!V4L2_TYPE_IS_OUTPUT(ctx->type) && ctx_to_m2mctx(ctx)->draining) { for (i = 0; i < ctx->num_buffers; i++) { + /* catpture buffer initialization happens during decode hence + * detection happens at runtime + */ + if (!ctx->buffers) + break; + if (ctx->buffers[i].status == V4L2BUF_IN_DRIVER) goto start; } @@ -724,9 +730,8 @@ int ff_v4l2_context_init(V4L2Context* ctx) ctx->buffers[i].context = ctx; ret = ff_v4l2_buffer_initialize(&ctx->buffers[i], i); if (ret < 0) { - av_log(logger(ctx), AV_LOG_ERROR, "%s buffer initialization (%s)\n", ctx->name, av_err2str(ret)); - av_free(ctx->buffers); - return ret; + av_log(logger(ctx), AV_LOG_ERROR, "%s buffer[%d] initialization (%s)\n", ctx->name, i, av_err2str(ret)); + goto error; } } @@ -739,4 +744,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); return 0; + +error: + v4l2_release_buffers(ctx); + + av_free(ctx->buffers); + ctx->buffers = NULL; + + return ret; } diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c index 29d894492f..c4f4f7837f 100644 --- a/libavcodec/v4l2_m2m_dec.c +++ b/libavcodec/v4l2_m2m_dec.c @@ -92,8 +92,8 @@ static int v4l2_try_start(AVCodecContext *avctx) if (!capture->buffers) { ret = ff_v4l2_context_init(capture); if (ret) { - av_log(avctx, AV_LOG_DEBUG, "can't request output buffers\n"); - return ret; + av_log(avctx, AV_LOG_ERROR, "can't request capture buffers\n"); + return AVERROR(ENOMEM); } } @@ -157,6 +157,11 @@ static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame) ret = v4l2_try_start(avctx); if (ret) { av_packet_unref(&avpkt); + + /* cant recover */ + if (ret == AVERROR(ENOMEM)) + return ret; + return 0; } }