From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 441C1400B6 for ; Sun, 19 Dec 2021 16:26:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 99ECA68AEEB; Sun, 19 Dec 2021 18:26:18 +0200 (EET) Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B236F68A2EC for ; Sun, 19 Dec 2021 18:26:12 +0200 (EET) Received: by mail-ua1-f41.google.com with SMTP id n7so13507616uaq.12 for ; Sun, 19 Dec 2021 08:26:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=E/OpPxxqp8K8eMBmojaGbFLE4Vm0zFxB0ZyoqwYURT8=; b=WBoemC0Pt06fy7YnxkAfkAbIfBf/UtZthOnTJP4ZAXJ3D+V6givNhGqqlnksKqmH6N HOdmEfupc5fOWJzeltjgsRtoIItmueVh1PX0ktc+1N9vW9uYqlo3CYqfrH+5W8jGNuLe YvfIJV1+lw4mZHu25GrX9k+7a2/q+VGZNZy3fxu79m066NHBVbi4opMnmz/YB2HqmwBU ORoM5P+TXOyMhd74L0mqcvjOcSHB5pxWzvIeQoDLfry6716NSpXfCGn+wgxwPIHP3M+C CUby7rgV9pT92W+wqx40MiBRh43LJlyURtI3D67imMajOwNPD/bnIRpOsOZ+CE+EzcxZ fung== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=E/OpPxxqp8K8eMBmojaGbFLE4Vm0zFxB0ZyoqwYURT8=; b=YXcxQLzkv9HiIJvoZvLCsHIhrxT9EKbGmg2XvluMnv/CRTA/VZcJCxTkQJ9EQOigBg y1bBpk3F+i5Nn8h/jOxUgOK+1W0jqjRfwVuqQUOq6Y1wc42F5ea9eE6Jb3qZSAdHjaJp ma3FuaRfZ6LA+Z8Tl714vtDhf3qA+0+JZddkd+oxPnPjMIbEx/C1mueNInsYj6gDSKtu peh3cFEfwpDCtHc0/oeuW4IRfHtuTj2lIrm++I7itHZr6BQNwIWpMRw6FOnUgWYrMpI+ dyVNHWRceeFOQ2Iv2bVJOpIwEdLuZ03Z/kU0o4/QpJSkodbICN13GXT+BlkMw4cT+cLr o63g== X-Gm-Message-State: AOAM531pwYup/bOqwk22m7hRfle+YfLEdWstLkZ6HrSFYmpPw08s0VcA nZ+totkojrxUllVEtQ/iwVJk15NvDH4ZWbz4fYMIsYfyPSg= X-Google-Smtp-Source: ABdhPJw5RX4PuWIrtKb0s0wWkxEy9/u+IJOXQY0OIjlC+c/4xsEjWcpjVEuFKGsVfG97rTAqM/nuBDi++SDiEPvrWtQ= X-Received: by 2002:ab0:1322:: with SMTP id g31mr3764300uae.120.1639931170568; Sun, 19 Dec 2021 08:26:10 -0800 (PST) MIME-Version: 1.0 References: <20211217001215.75135-1-rcombs@rcombs.me> <20211217001215.75135-7-rcombs@rcombs.me> In-Reply-To: <20211217001215.75135-7-rcombs@rcombs.me> From: Rick Kern Date: Sun, 19 Dec 2021 11:25:58 -0500 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Thu, Dec 16, 2021 at 7:13 PM rcombs wrote: > 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); > This could be broken out into more variables to make the logic clearer. It took me a while to parse this. > + 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; > -- > 2.33.1 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".