From patchwork Mon Sep 10 22:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 10291 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp2995918jap; Mon, 10 Sep 2018 15:58:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaC0jsutFnv3sxN8ACdAO3BVqYRGjHUg6XWDUrb0qkcWvCZNBn+xDaqLUu2bpFRtLx0u3+a X-Received: by 2002:a1c:8587:: with SMTP id h129-v6mr2208803wmd.105.1536620286279; Mon, 10 Sep 2018 15:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536620286; cv=none; d=google.com; s=arc-20160816; b=H1jNcoW9cMyhZA0rNx8l+rnh0gT9Xn0/AEaUiABeM39ZsK6DmJ4T3jnk7CFV3V7ywd ye126gfehe+czFNw6KF0ovUmDzZNvWHn2Db5bqm6YErEo+l7tO7UL7HAgnDc9wVmeDws ryobUOU1ZYMNwtbPyrgOMCGpHeJL/dcHK4QGTn0dEwiBGqT6e/bra2o6RgsEvbSVeoDV GuUqrTpcEQvmI2yum1Pou6B+/t3QIhY+BiM1Oy8tFFB3/2ob3rYtm3Cl7yKZ9r4+qDKA VSPl88CwgKnHF46iaFbLjHU1+KpIvMpuM6ViJwrP1dSc+hLiQ18oHDBDU5fvgzbwcczS 8Plg== 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:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=MYg4bMa7sDZBOtqTVq3CcjnA//8mQzPzYj6r23xo2CI=; b=qVLz2jXdh5XfzqO8k/XJUGJEc3aPyvzAN7TByhC8RY2UY35j8D1Y8zwYgbiP0vNKIA 34yHo6FSOqCv+Xh7LTJMQg9xGmwEsK+2v9mB6xy66/gr+BtkdTT6I241QHNIJyVtYFgB tEUOvgBLUq0l8SOoz1+NCqWSJ0FNn0scod8eyqZr4XQfanbcitJT6uhXBx1frAQy9Ynw 517WBNIhIHOI942Y8tjNrZr5oxhj0YYMLWpoblB/m/n75y2eeQ9RvGxqF5bFQBOVo1YB 5fRIS3qiynhlvFzYCkooO4kAyGjLGddG6AzpNQGeZgu7xRkeyRp5K3/m97gj8INmqqHl rKAw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j1-v6si16688620wro.92.2018.09.10.15.58.05; Mon, 10 Sep 2018 15:58:06 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 20F5D68A3ED; Tue, 11 Sep 2018 01:57:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-1.mx.upcmail.net (vie01a-qmta-pe02-1.mx.upcmail.net [62.179.121.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8FE6A68A37E for ; Tue, 11 Sep 2018 01:57:47 +0300 (EEST) Received: from [172.31.218.42] (helo=vie01a-dmta-pe04-3.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fzV80-00011E-S9 for ffmpeg-devel@ffmpeg.org; Tue, 11 Sep 2018 00:57:56 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fzV7u-000237-7v for ffmpeg-devel@ffmpeg.org; Tue, 11 Sep 2018 00:57:50 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id Zyxj1y00F0S5wYM01yxknx; Tue, 11 Sep 2018 00:57:45 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 11 Sep 2018 00:57:11 +0200 Message-Id: <20180910225711.13391-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.18.0 Subject: [FFmpeg-devel] [PATCH] avutil/frame: Simplify the video allocation 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 Cc: Luca Barbato MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Luca Barbato Merged-by: James Almer Padding-Remixed-by: Michael Niedermayer Signed-off-by: Michael Niedermayer --- libavutil/frame.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index deb9b6f334..6147c61259 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -211,7 +211,8 @@ void av_frame_free(AVFrame **frame) static int get_video_buffer(AVFrame *frame, int align) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); - int ret, i; + int ret, i, padded_height; + int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align); if (!desc) return AVERROR(EINVAL); @@ -236,23 +237,22 @@ static int get_video_buffer(AVFrame *frame, int align) frame->linesize[i] = FFALIGN(frame->linesize[i], align); } - for (i = 0; i < 4 && frame->linesize[i]; i++) { - int h = FFALIGN(frame->height, 32); - if (i == 1 || i == 2) - h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h); + padded_height = FFALIGN(frame->height, 32); + if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height, + NULL, frame->linesize)) < 0) + return ret; - frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16 + 16/*STRIDE_ALIGN*/ - 1); - if (!frame->buf[i]) - goto fail; + frame->buf[0] = av_buffer_alloc(ret + 4*plane_padding); + if (!frame->buf[0]) + goto fail; - frame->data[i] = frame->buf[i]->data; - } - if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & FF_PSEUDOPAL) { - av_buffer_unref(&frame->buf[1]); - frame->buf[1] = av_buffer_alloc(AVPALETTE_SIZE); - if (!frame->buf[1]) - goto fail; - frame->data[1] = frame->buf[1]->data; + if (av_image_fill_pointers(frame->data, frame->format, padded_height, + frame->buf[0]->data, frame->linesize) < 0) + goto fail; + + for (i = 0; i < 4; i++) { + if (frame->data[i]) + frame->data[i] += i*plane_padding; } frame->extended_data = frame->data;