From patchwork Fri Dec 17 00:12:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: rcombs X-Patchwork-Id: 32674 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp1002244iog; Thu, 16 Dec 2021 16:13:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQ+Qw/iXaSwO5UmYeNr95qfwaU8YuUQCbabcmBNEF3EX2PpkjwZ9/I3IouVE5sheDG/5r3 X-Received: by 2002:a17:907:2da0:: with SMTP id gt32mr406277ejc.711.1639700012693; Thu, 16 Dec 2021 16:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639700012; cv=none; d=google.com; s=arc-20160816; b=Em5Y3hWmPC0CPDOHd51C6mPdr/FlCf0ZnBGFSZUPZo6ef439sYPdGv0aRRwwal4hM0 8oud0CHh5QFSmKBgF+/DPwS8uvs49CHMzONcfDH+mreyDD2uwCmW6rCiaB2ihoNWsZOE serwMwb/0LqVIlFYNbZYrKHTxvsWMnCkd3WvIl+zuNaVYDrgV4KEaOYKUwYiRh4pF+eb OhcN/WWydT3oYfBYO96FomXQWqiRF+O2BAnK8jinJNO4OSlInAPUoUN3ijEwstmH3LXS DRkLbXSfav/i5lhu7bVMYkL2VAzez+S5aAN4kVHOscVF1PTES2RccPtLub+x1q4c36za WA4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=zMeGMv/MgvGkzFqdHuoQv9qiNwLCPellGxsRjqytC/Y=; b=QbDRkJbkak00tjqFWU/Q2RPsm3ck5Mo7MuQU1K4jrvlEPO7hPy6QYlqy1Sj0gkPRsl SFarddXC0ZNiGDQHr0+xIqcOlfD25NZ8+zEGmJ1yIPlPJlW/xV4a+qTz/fGy+241lJAA aHhpvCPIyWpikCTz1Gp7+SW9fFLYoxlgPrrIwNM4+NVPjpdhBt1McvqKhyF9DrbJyqlg PZT11cI4YQniTeECcUZ2AVJi0/N1q178YmKjUvuoCnqIkJ7tJex4wc7tt9WGj2A7iNgr 8WzvQ7j9J2NKtWdc88IQ2yThJBH7XVTtUE/9/b0f9oEASOI7upHB8S9znkGaZxvGIakN MlDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=K1DrHAly; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s3si4377907eji.349.2021.12.16.16.13.32; Thu, 16 Dec 2021 16:13:32 -0800 (PST) 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=@rcombs.me header.s=google header.b=K1DrHAly; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=rcombs.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 508B268B003; Fri, 17 Dec 2021 02:12:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A64568AFDE for ; Fri, 17 Dec 2021 02:12:25 +0200 (EET) Received: by mail-io1-f43.google.com with SMTP id 14so750571ioe.2 for ; Thu, 16 Dec 2021 16:12:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lcK/svsQRKORVvm33/JTt4tCzVC0fXTgguAGt/zvo+A=; b=K1DrHAlyFkATc5TWH7hMWSBQn0OiyOKqUmLffONyGq7PBihXmKZQtSXB+11S+8To2O dMJm4+xySs7A4xY67vDHRYTFXOgjgICLS5rK2VQoIKvB3wv5Cxhv5xUh8sxJSeFGQG0Q BGpLfw5V+gqHN391tYYC6Ge09wgpQEhE9qUqYltKD113mu0A1uP/pOS5KFhMKEG2E0d2 PnJ+QuqR2JOZFdBdiIRzXYLRy3eJHahFASouJwmpup2zb9uXiFAImOchtFON5ut1BPvM c5wWuLXzqI44xYkYWEhZdvNNpEOrIu5XWu7hCW9stNPps/MgKYzsiAMlcR5m8MwMaKjc Er8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lcK/svsQRKORVvm33/JTt4tCzVC0fXTgguAGt/zvo+A=; b=mUlrXWpRput8I/VjKjDRor3pga83UdpiLUtMDfD+8odcXSLp0OcevQzVYrEfKdEiuR KYFG6GNVNWqRzJuUqwFvzpcBMzcZL3o6XVNX7EvYf3Kq/Vw0kutjnUvKS7Q509GFULP1 VlAyci1ybWLE4ZdiNLrAu22VF5tK6SPKvc6L3TXKmcJ+bTGThTJNJbX3vC6nxP0tg+EZ OguRXa2ZQr/RsgeEdUUu8eKyceecNKzm+6KJobmRiO4yen0o9ubPxhQ7OV5POYp+VzHB Lym6TScIPC22KP9nnHeUH484WxsgpxbhSzntbAsm8/zQR2PkBpxuDlGz+3xClLN5eAFk umTA== X-Gm-Message-State: AOAM5337+30LH1LpoMC/zHsFwDYir5hLToZRrtgLQ2QtZTrmgzYhrzTl PCnpS3/Pwz6ICaYuub5XXwV+6xLtFblYmV0= X-Received: by 2002:a05:6638:4183:: with SMTP id az3mr271108jab.56.1639699943683; Thu, 16 Dec 2021 16:12:23 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:1163:bda5:7473:fab3]) by smtp.gmail.com with ESMTPSA id z13sm1571257iln.43.2021.12.16.16.12.22 for (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Dec 2021 16:12:23 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Dec 2021 18:12:11 -0600 Message-Id: <20211217001215.75135-7-rcombs@rcombs.me> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211217001215.75135-1-rcombs@rcombs.me> References: <20211217001215.75135-1-rcombs@rcombs.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/10] lavc/videotoolboxenc: vastly simplify get_cv_pixel_info X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cIcaBfLdKLFY No longer requires per-format switch cases. The frame==0 path was unused (and would've crashed anyway). --- libavcodec/videotoolboxenc.c | 69 +++++++----------------------------- 1 file changed, 13 insertions(+), 56 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index b66d44f6b7..82e01fbe29 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -2034,6 +2034,7 @@ static int get_cv_pixel_info( size_t *strides, size_t *contiguous_buf_size) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); VTEncContext *vtctx = avctx->priv_data; int av_format = frame->format; int av_color_range = frame->color_range; @@ -2041,6 +2042,9 @@ static int get_cv_pixel_info( int range_guessed; int status; + if (!desc) + return AVERROR(EINVAL); + status = get_cv_pixel_format(avctx, av_format, av_color_range, color, &range_guessed); if (status) { av_log(avctx, @@ -2065,63 +2069,16 @@ static int get_cv_pixel_info( } } - switch (av_format) { - case AV_PIX_FMT_NV12: - *plane_count = 2; - - widths [0] = avctx->width; - heights[0] = avctx->height; - strides[0] = frame ? frame->linesize[0] : avctx->width; - - widths [1] = (avctx->width + 1) / 2; - heights[1] = (avctx->height + 1) / 2; - strides[1] = frame ? frame->linesize[1] : (avctx->width + 1) & -2; - break; - - case AV_PIX_FMT_YUV420P: - *plane_count = 3; - - widths [0] = avctx->width; - heights[0] = avctx->height; - strides[0] = frame ? frame->linesize[0] : avctx->width; - - widths [1] = (avctx->width + 1) / 2; - heights[1] = (avctx->height + 1) / 2; - strides[1] = frame ? frame->linesize[1] : (avctx->width + 1) / 2; - - widths [2] = (avctx->width + 1) / 2; - heights[2] = (avctx->height + 1) / 2; - strides[2] = frame ? frame->linesize[2] : (avctx->width + 1) / 2; - break; + *plane_count = av_pix_fmt_count_planes(avctx->pix_fmt); - case AV_PIX_FMT_BGRA: - *plane_count = 1; - - widths [0] = avctx->width; - heights[0] = avctx->height; - strides[0] = frame ? frame->linesize[0] : avctx->width * 4; - break; - - case AV_PIX_FMT_P010LE: - *plane_count = 2; - widths[0] = avctx->width; - heights[0] = avctx->height; - strides[0] = frame ? frame->linesize[0] : (avctx->width * 2 + 63) & -64; - - widths[1] = (avctx->width + 1) / 2; - heights[1] = (avctx->height + 1) / 2; - strides[1] = frame ? frame->linesize[1] : ((avctx->width + 1) / 2 + 63) & -64; - break; - - default: - av_log( - avctx, - AV_LOG_ERROR, - "Could not get frame format info for color %d range %d.\n", - av_format, - av_color_range); - - return AVERROR(EINVAL); + for (i = 0; i < desc->nb_components; i++) { + int p = desc->comp[i].plane; + int chroma = (p != 0) && (!(desc->flags & AV_PIX_FMT_FLAG_ALPHA) || p + 1 != *plane_count); + int shiftw = chroma ? desc->log2_chroma_w : 0; + int shifth = chroma ? desc->log2_chroma_h : 0; + widths[p] = (avctx->width + ((1 << shiftw) >> 1)) >> shiftw; + heights[p] = (avctx->height + ((1 << shifth) >> 1)) >> shifth; + strides[p] = frame->linesize[p]; } *contiguous_buf_size = 0;