From patchwork Fri Jul 7 09:48:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42475 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp7161700pzh; Fri, 7 Jul 2023 02:49:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlH0EdjsDOqJZN1IAw65sU1UdkbAk0IrxuZlA1+vhMduRSozGktCH0MJ/z4B3E9+KzgyAer/ X-Received: by 2002:a17:907:d30d:b0:965:6075:d100 with SMTP id vg13-20020a170907d30d00b009656075d100mr4340878ejc.39.1688723354766; Fri, 07 Jul 2023 02:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688723354; cv=none; d=google.com; s=arc-20160816; b=nnNv6aW9HCh18eEeyVndWUtsmim1/kyyEdrjxRtoxQGl+NmCUA9/qsd2+ip2El5RrI adomWYTBAilcETjgWbC3Ut0RzuWU2mycGgBXboDKq4Od5V90LIzG9+XmhjyVBaU+RWbL pHNtpDwVW/ktija8Wzmm6PFELCv5k//cn3tVcyEdK/HJEeYlDmHl5OPwTZC0SHs9XWrr QGpWkMMGO7jGnxud6uzQU+QTnaK4bRmIaLn1kohpWZSJA0x1Gmce18DI61qkhIMtE90d o65xHbML87XqwRTiOyQmPLRZlcjNztbBD7jw1w06d0TcrhJnGmeTZexVFaDUat7oK3q6 DHUQ== 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:delivered-to; bh=SSr7TEaqwEFbDKUP7ohNRY/ZdepYBC3V43yxvw0IfEg=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=J/VmnOrIP4n43A7YGWIpEtW/dpt53VpHvKpwzFtnY1DVY+/MfYbNoH5xgxJX508cuO CglWW6qdXas/NVd//MvJSGopFF/kEo9N0NB7evMMYt0RicQQJrybsUCEUWN8MKoaqh31 J2g1i0jlz16bGbv/RlnbIfUgAscWPPzv1GPR+VO22atlqFteLoW/BYQX4kMGUF8bBVLZ H24syH+ZcytXhDW1g0Bnr/6RwOpihFYK1bDqCDigVXRfy+yCTyTiyncALAPUe4joMSsW IupTXQSgpSIh8MbbD1ECHOD9UPnHTVmKHyDXn5puxOAmF3RhPEBYn1RKXDGY3EYgxfPA 2Ewg== 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 v18-20020a17090606d200b00993b3881ecbsi1922279ejb.682.2023.07.07.02.49.14; Fri, 07 Jul 2023 02:49:14 -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 8D41868C7C3; Fri, 7 Jul 2023 12:49:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1615468C7A9 for ; Fri, 7 Jul 2023 12:49:02 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7C531240D1C for ; Fri, 7 Jul 2023 11:49:01 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WjNIE7VyskC7 for ; Fri, 7 Jul 2023 11:49:00 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id BEF0E2404EC for ; Fri, 7 Jul 2023 11:49:00 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 47B9F3A0F81 for ; Fri, 7 Jul 2023 11:48:54 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jul 2023 11:48:27 +0200 Message-Id: <20230707094847.25324-2-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230707094847.25324-1-anton@khirnov.net> References: <20230707094847.25324-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/22] lavc/encode: shorten code by using a local variable 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: +hqt2zXV7ho7 --- libavcodec/encode.c | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 2da9f6ba23..0d44f70ee9 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -550,6 +550,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * static int encode_preinit_video(AVCodecContext *avctx) { + const AVCodec *c = avctx->codec; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); int i; @@ -559,20 +560,20 @@ static int encode_preinit_video(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (avctx->codec->pix_fmts) { - for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++) - if (avctx->pix_fmt == avctx->codec->pix_fmts[i]) + if (c->pix_fmts) { + for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++) + if (avctx->pix_fmt == c->pix_fmts[i]) break; - if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) { + if (c->pix_fmts[i] == AV_PIX_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is not supported\n", av_get_pix_fmt_name(avctx->pix_fmt)); return AVERROR(EINVAL); } - if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P || - avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P) + if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P || + c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P || + c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P || + c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P || + c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P) avctx->color_range = AVCOL_RANGE_JPEG; } @@ -625,6 +626,7 @@ FF_ENABLE_DEPRECATION_WARNINGS static int encode_preinit_audio(AVCodecContext *avctx) { + const AVCodec *c = avctx->codec; int i; if (!av_get_sample_fmt_name(avctx->sample_fmt)) { @@ -633,28 +635,28 @@ static int encode_preinit_audio(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (avctx->codec->sample_fmts) { - for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { - if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) + if (c->sample_fmts) { + for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { + if (avctx->sample_fmt == c->sample_fmts[i]) break; if (avctx->ch_layout.nb_channels == 1 && av_get_planar_sample_fmt(avctx->sample_fmt) == - av_get_planar_sample_fmt(avctx->codec->sample_fmts[i])) { - avctx->sample_fmt = avctx->codec->sample_fmts[i]; + av_get_planar_sample_fmt(c->sample_fmts[i])) { + avctx->sample_fmt = c->sample_fmts[i]; break; } } - if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { + if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is not supported\n", av_get_sample_fmt_name(avctx->sample_fmt)); return AVERROR(EINVAL); } } - if (avctx->codec->supported_samplerates) { - for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) - if (avctx->sample_rate == avctx->codec->supported_samplerates[i]) + if (c->supported_samplerates) { + for (i = 0; c->supported_samplerates[i] != 0; i++) + if (avctx->sample_rate == c->supported_samplerates[i]) break; - if (avctx->codec->supported_samplerates[i] == 0) { + if (c->supported_samplerates[i] == 0) { av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n", avctx->sample_rate); return AVERROR(EINVAL); @@ -665,12 +667,12 @@ static int encode_preinit_audio(AVCodecContext *avctx) avctx->sample_rate); return AVERROR(EINVAL); } - if (avctx->codec->ch_layouts) { - for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) { - if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i])) + if (c->ch_layouts) { + for (i = 0; c->ch_layouts[i].nb_channels; i++) { + if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i])) break; } - if (!avctx->codec->ch_layouts[i].nb_channels) { + if (!c->ch_layouts[i].nb_channels) { char buf[512]; int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); if (ret > 0)