From patchwork Wed Oct 4 19:04:16 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: 5412 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.76 with SMTP id m12csp1196087jah; Wed, 4 Oct 2017 12:04:29 -0700 (PDT) X-Received: by 10.28.2.2 with SMTP id 2mr12400138wmc.128.1507143869042; Wed, 04 Oct 2017 12:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507143869; cv=none; d=google.com; s=arc-20160816; b=h3rQiwdtukHyDw2+B1Ehgf/ZXGrJaCl3F9OrIK90M9oTgaH8jix9GTBEokcGFIpSsx +dN7f8RVXySIZ0lROF/5mtFo6VqGe8yYzSfGFbyOjJH9lrCcDgkBPVsMyL1XRXqceZ9x x3HuNhU1SL1hbVRrOMmwvDM+XrHXpKYcrZJK0V59FbSWyOndDzrofzGEEogM/4U4BGry 6PasMW/Me/82/25m15itOqMZqDH5K/j1CnLB/f+xz4qKP9f4sC3fU2OCydMcV74IBveg GOER/QunidnP7OXsKncN3AV+M7YWnb1v7B83F8GsBLu9zH5T4Jpi/nCEL7PL/64jDCxn 6YVA== 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=16yKAKqxWxxVuVujFKAS4IpI4UaZizj4t7mLkiYlmiA=; b=p5dwHJU7PfKKd9N4tqjX5H4AXOeQUL5qU6oj79dIi0dPW7YsLIMul0aFPmFLsitm5T y+wcFGJ+ir63DoDjlXYyqwC0XnFPti94LabwVVbHAgrRdsweTuMtPj8WlSo4fCAzipZx tfUXLZB7Lm9BT0nMmdTrG/uHHjSfttyuX1c8ZHTi4fuTO4EktwSD0U+7PKrk8p0unXr2 BA+i7tIWZSIp23xXE3yDp0KYXwjV1kHVN0JX25e/pJIvBSHDJtSHwVbq5dj3RWM/TeyY IyPchUaiQZECfvSj0w4wePR+zsdaDFvpqDRFQaY7iZWGoIn/Zl72XKYYWqWTfv0wJfY2 7qrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hqqGVSdv; 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 e2si14095695wrd.449.2017.10.04.12.04.28; Wed, 04 Oct 2017 12:04:29 -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=hqqGVSdv; 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 8D86568A32E; Wed, 4 Oct 2017 22:04:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 062A468A21F for ; Wed, 4 Oct 2017 22:04:06 +0300 (EEST) Received: by mail-wr0-f179.google.com with SMTP id b21so9321934wrg.7 for ; Wed, 04 Oct 2017 12:04:21 -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=+gGMjirmAHBIp0/zg3WW7Rn1aZsA5+0doVakYJ8f57s=; b=hqqGVSdvFPoREbV79G6gMb9vY+0KgCry90OnlAW+6+AavLAXqt3tZaaSeU3CaP4YTT 8fBte+pnUnHov2f95u6F1h9rWdv5wZjf8aP90TrHiXiOm1KFL7BmlL8p2lDuobIqpcWZ 48BaP57uniH3WN6xAteFG3mZ3dJruIMv9R7Ew= 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=+gGMjirmAHBIp0/zg3WW7Rn1aZsA5+0doVakYJ8f57s=; b=U8L3mq04WPcRzOUOacwOHx9F15igjoPkj1VNWASTkDQRL4LGR72PZYHE7YJyuXdyg5 6S4Ks8XfBS9zYk0MkKtJywvgFT/wjDi2egWpz/ZWXFutjr8jKlr8OaAJxcIhGMFHzBOJ FWozU3oF4PAgbpZdIRqYVDb4Ae5MhZ8EZKOskLhn3VEOw0PPaiXXC8ykhbxKgLiRKuer qQHGZCDBe7RqyBSJMYMDdH0v2Auo3sl6hJlUhW57Zy1Y8SEo1PQONZHPGQ+YaySbhEbE xYxA7Ef/piBGcve3of9XNWXkYm0yNK618YiJSmvY+ZqNLhvKErlXcL/XAu+X0kaz5BB9 9s7Q== X-Gm-Message-State: AMCzsaVhj34uExFAL90jIFsgu1RPfhXffeILYbN5M0tSckU8CGCFKh4t YJc9vGe7ouq5XWpSCw9QPY3Ryg== X-Google-Smtp-Source: AOwi7QDUlWsRMvzRGGqfBGx1dE+lWVn0GrFePbulgWJWDvW3Bv2XP/nIqg3KUCFjmvCB83ENySNq+w== X-Received: by 10.223.174.89 with SMTP id u25mr6620390wrd.275.1507143860778; Wed, 04 Oct 2017 12:04:20 -0700 (PDT) Received: from localhost.localdomain (113.red-81-47-150.staticip.rima-tde.net. [81.47.150.113]) by smtp.gmail.com with ESMTPSA id 25sm25653907wrv.8.2017.10.04.12.04.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 12:04:19 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, ffmpeg-devel@ffmpeg.org Date: Wed, 4 Oct 2017 21:04:16 +0200 Message-Id: <1507143856-12284-1-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCHv3] 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 | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c index 297792f..9f3b56d 100644 --- a/libavcodec/v4l2_context.c +++ b/libavcodec/v4l2_context.c @@ -90,6 +90,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 = FFALIGN(height, 32) * FFALIGN(width, 32) * 3 / 2 / 2; + return FFALIGN(size, SZ_4K); +} + static inline void v4l2_save_to_context(V4L2Context* ctx, struct v4l2_format_update *fmt) { ctx->format.type = ctx->type; @@ -101,13 +115,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); + } } }