From patchwork Wed Oct 4 16:50:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Ramirez-Ortiz X-Patchwork-Id: 5411 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.76 with SMTP id m12csp1075352jah; Wed, 4 Oct 2017 09:50:47 -0700 (PDT) X-Received: by 10.28.137.193 with SMTP id l184mr10252296wmd.24.1507135847310; Wed, 04 Oct 2017 09:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507135847; cv=none; d=google.com; s=arc-20160816; b=nQMkVyvocWguZjLDiuV/sdC+GHkkjbesSoUIIXaIFEI3HUgXBJ8HiQMDYV87PrVtRW LJA3OTVPFuprDwGHOZsZ/c6WnZDx6SJw943vM4vGFTSMwEcBhHfrxKyRJNDhqRdtlLJu Sw2qbZ1iFs78l7ZcvweZjwZZtXEEfmyG/Lu5yX1MxdGvWEJnBUjFHk60ImC+k37fn2pr 7Rggi4foqsGH2OEJt2ZPRMK+DGDCRv5sDbLhfG2GGOB2AmEGCQ/lprpEhoPJYphcQwPE gdeT5Lo6G2VxzvuLj9Fkn8uRYS642XAqU9+JXEQjEv9zLWpmOutE4+bdJlbGSLCk1ftP RvFg== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=W3LTjKFfKYqAHADOV6Szg0e8QfMqnv1r1Uqu820InSs=; b=r17IjXz33hfAJGK1fG4hmNgI/xhhPjKQ4auwreEqtXUif48UJk1VJPsc9gzAACKFin FsBStA4Z9wcXs9ds/hjbWrvetmokIC8dPF8EUxiFkifoGNIqTngzzmRaN45HW4jgIBkA EjKWaPgpoHfqzqya5zSH2FKDyoeClA2AHMtOOMQud7dtRuK0dvouWup2iaHkBbeLWGJf 9zNUOcbxs5QXNaxu02veSDkhJzZXioHTmDKLOQiXhXoCjs8rW1smSeCIMzc8+EXFih0t Ptj82G/Q43y/7EDcFR00HISq85pP2jt826yYqGArqw2Kgjahzmli1ZrcZ8KoXyDEfixh gkoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Vth/Q7u1; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x195si8423807wme.232.2017.10.04.09.50.46; Wed, 04 Oct 2017 09:50:47 -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=@linaro.org header.s=google header.b=Vth/Q7u1; 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=NONE dis=NONE) header.from=linaro.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F2380689C98; Wed, 4 Oct 2017 19:50:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D7FF468A16D for ; Wed, 4 Oct 2017 19:50:22 +0300 (EEST) Received: by mail-wm0-f42.google.com with SMTP id i82so21973031wmd.3 for ; Wed, 04 Oct 2017 09:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=EZLkcIcRqbMcpPu4L42mhGpHRxBpMidCcXjYFlN3F4Y=; b=Vth/Q7u1lD+92ByrXCPWgKlaMV7QWsI4dmXCamtZ/sVE+jJOINkddhYyUzNUmSD2jZ pHMnALCMvdecKAp9zBeEVlYK1RQhU3EEG5+NKIupszoZ1xKJEGZSNuMQpQLXKdV9N1JE e0Vm852LLfV+h2gbD26Lde2sXJMCj42JzvnBM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=EZLkcIcRqbMcpPu4L42mhGpHRxBpMidCcXjYFlN3F4Y=; b=tWnImMvCPXnLRVtLccuUTqTNJ1Mq4V8hU1OOSudFldanribkj1qW/66E4xgs3xgJKV FfRZ+PB0rIAwpvkqPhY4J9w8iMC65iMMwaqDUIUfgdw5FAkGDks57r3Yc3c90IA3XSbE lchJeiCQz2wIj8Eot3AVVRN9kFTNATvuJHifa07wqx4OFUK6sXNS6CQqpskDgSOjAUVO CN1J9UUX2HNiUSxsRAI7jkndKY8YBYZbl2e/Qd42VtLb6XmhEGsloZ8kwlId9XmFYeAN BAjLkJRSlkB9Au5Kah6HlSAX3Kj67r2cP1Z+kusc+q6kHxE991zE4Cd9LNnFmTbEmBCJ sZPw== X-Gm-Message-State: AMCzsaWsaoZroak9LSIFIMe0mKMC7gjON2dwM0uXdiruZSKK+iQyJ1tD 0mPN4AGZhjW4ElG74N9zPoGOGw== X-Google-Smtp-Source: AOwi7QA9tjQW4Gmc5nj/Q+Zirwor4vSpnulR1SfnLABLaPGdPk2O41iI9PbbYkujQa3ZBOXwZn/ajw== X-Received: by 10.28.9.145 with SMTP id 139mr5650777wmj.20.1507135837620; Wed, 04 Oct 2017 09:50:37 -0700 (PDT) Received: from localhost.localdomain (51.red-88-3-176.dynamicip.rima-tde.net. [88.3.176.51]) by smtp.gmail.com with ESMTPSA id e134sm15009457wma.31.2017.10.04.09.50.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 09:50:36 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, ffmpeg-devel@ffmpeg.org Date: Wed, 4 Oct 2017 18:50:31 +0200 Message-Id: <1507135831-7715-1-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCHv2] avcodec/v4l2: set sizeimage param for non-raw buffers [fixes #6716] 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" Some V4L2 drivers fail to allocate buffers when sizeimage is not set to a max value. This is indeed the case for s5p-mfc [1] Most drivers should be able to calculate this value from the frame dimensions and format - or at least have their own default. However since this work around should not impact those drivers doing the "right thing" this commit just provides such a default. The calculations were extracted from the v4l2 driver used to develop the ffmpeg v4l2_m2m support [2]. See venc.c and vdec.c [1] linux.git/drivers/media/platform/s5p-mfc [2] linux.git/drivers/media/platform/qcom/venus/ --- libavcodec/v4l2_context.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c index 297792f..312cde5 100644 --- a/libavcodec/v4l2_context.c +++ b/libavcodec/v4l2_context.c @@ -33,6 +33,8 @@ #include "v4l2_fmt.h" #include "v4l2_m2m.h" +#define ALIGN(x, a) ((x) + (a - 1)) & (~(a - 1)) + struct v4l2_format_update { uint32_t v4l2_fmt; int update_v4l2; @@ -90,6 +92,20 @@ static inline int v4l2_type_supported(V4L2Context *ctx) ctx->type == V4L2_BUF_TYPE_VIDEO_OUTPUT; } +static inline int v4l2_get_framesize_compressed(V4L2Context* ctx, int width, int height) +{ + V4L2m2mContext *s = ctx_to_m2mctx(ctx); + const int SZ_4K = 0x1000; + int size; + + if (av_codec_is_decoder(s->avctx->codec)) + return ((width * height * 3 / 2) / 2) + 128; + + /* encoder */ + size = ALIGN(height, 32) * ALIGN(width, 32) * 3 / 2 / 2; + return ALIGN(size, SZ_4K); +} + static inline void v4l2_save_to_context(V4L2Context* ctx, struct v4l2_format_update *fmt) { ctx->format.type = ctx->type; @@ -101,13 +117,23 @@ static inline void v4l2_save_to_context(V4L2Context* ctx, struct v4l2_format_upd /* update the sizes to handle the reconfiguration of the capture stream at runtime */ ctx->format.fmt.pix_mp.height = ctx->height; ctx->format.fmt.pix_mp.width = ctx->width; - if (fmt->update_v4l2) + if (fmt->update_v4l2) { ctx->format.fmt.pix_mp.pixelformat = fmt->v4l2_fmt; + + /* s5p-mfc requires the user to specify a buffer size */ + ctx->format.fmt.pix_mp.plane_fmt[0].sizeimage = + v4l2_get_framesize_compressed(ctx, ctx->width, ctx->height); + } } else { ctx->format.fmt.pix.height = ctx->height; ctx->format.fmt.pix.width = ctx->width; - if (fmt->update_v4l2) + if (fmt->update_v4l2) { ctx->format.fmt.pix.pixelformat = fmt->v4l2_fmt; + + /* s5p-mfc requires the user to specify a buffer size */ + ctx->format.fmt.pix.sizeimage = + v4l2_get_framesize_compressed(ctx, ctx->width, ctx->height); + } } }