From patchwork Fri Aug 30 10:15:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 51233 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:4027:b0:48e:c0f8:d0de with SMTP id ky39csp299889vqb; Fri, 30 Aug 2024 03:24:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX/bRQSGZgB5OWiG47xMrNNM0Yr7nOugp/dpLI+LKW9w53J1DK+MWLTLRktzmliF4wLV+kDEnzLQ65vRo7NTPFB@gmail.com X-Google-Smtp-Source: AGHT+IFMsFieBpiGz9MdhiWjKkhtPEMffZfii6TIz9BIDpNS3eULw6ooMy59YPeEV6ZpEJ5c3/WT X-Received: by 2002:a05:6512:3188:b0:52e:f58b:65ee with SMTP id 2adb3069b0e04-53546bab08amr1326772e87.57.1725013494220; Fri, 30 Aug 2024 03:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725013494; cv=none; d=google.com; s=arc-20240605; b=EMkPba+YT8EWNVAoAZU3fBM97Va4nUe+R00k6cWiusZxJSnvkHY4TyB9CjAsgOCkV0 ViwpkeqWB6oJFL+LL2TStsbM8h3/6JfgqxTTCFTZWwSRCwzEFU/94Au7IlQxnCQ/h6mI NuA+f62pbJp4ocTRekEP0Ddli4cxmXl77ZOGK5YQhbkrEMGvqhARh7wz+eb+75GQdH+B dG0A77PGNST8kroH0lu0k8rddzsTMl6jZlVEJLnDZX00r9mE+VJZ+lJk1HI2XEVC0gAd 7VmPUNABDbP1TCsz9JHuybXcue7NHlEJWjlerFxOjeuWQJg0lThEs+zDVLTbXNIPyZ4A h7xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc: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=SIob+fQNlKEdzuxioQfeedCaczuZICR3bSU1CaidimM=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=CA8we8SCTSg/jKmm9hNCq33NcNwpV+DIEJOkeG0+0nrv1Rj00tnqmRdjRSM+AaExf0 nIenP/zA0G9oQbeGAuz89UNepvRBHB+ZqbzUQyLHp798lSvBsmk0vPVMeVjamyZ60c7N /p8zxTRzD/M1wxwt3H6PqEcsGFrD45HTAfsFm7a64WrOzC78/Z/0nEqRm2lU1Y1pE1CK bJC0vR9NQcRMrtHucRnMqpEfthQPvB8MxbPGzSNyu+EQLsp0F5e0zpHbpcHDOUJYMHVl PHKHKv6FojGolODpeoHJo3TU1uTGVqN+W1Kn+PD22D+2hyrmyQzz8qgcxJ0C84YL8sAs NFcw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=ELA44RJO; 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 a640c23a62f3a-a898912d6b5si281911366b.284.2024.08.30.03.24.53; Fri, 30 Aug 2024 03:24:54 -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=@haasn.xyz header.s=mail header.b=ELA44RJO; 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 56A2768DBF4; Fri, 30 Aug 2024 13:24:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D9B2168DB63 for ; Fri, 30 Aug 2024 13:24:08 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1725013448; bh=PL//jY9jmb91knPl0XVwBFqixbZJW+F+Ai/xxGO7Sag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELA44RJONO/feCw+21lrgWZm/ya3WpIscmuDIVuqbKfz7B2MQ9tV3vCWoz1fVZOKs IxuXgZz3kCoX1kedeN4nxFcJshyuGFiCGOCiyUxM/rhis3tNtE6q/JB9F6/pMgvIa6 u+NBfmMuN9pyl6OHo1g/7iF0gHDsrCjd7qnt4CKk= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 8C05542A6E; Fri, 30 Aug 2024 12:24:08 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Aug 2024 12:15:26 +0200 Message-ID: <20240830102402.18149-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240830102402.18149-1-ffmpeg@haasn.xyz> References: <20240830102402.18149-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 03/17] avcodec/encode: switch to avcodec_get_supported_config() 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: u7j5H8eNoKe3 From: Niklas Haas --- libavcodec/encode.c | 90 ++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 34658d13d0..bc5acf985d 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -563,7 +563,8 @@ 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; + const enum AVPixelFormat *pix_fmts; + int ret, i, num_pix_fmts; if (!av_get_pix_fmt_name(avctx->pix_fmt)) { av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n", @@ -571,28 +572,33 @@ static int encode_preinit_video(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (c->pix_fmts) { - for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++) - if (avctx->pix_fmt == c->pix_fmts[i]) + ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT, + 0, (const void **) &pix_fmts, &num_pix_fmts); + if (ret < 0) + return ret; + + if (pix_fmts) { + for (i = 0; i < num_pix_fmts; i++) + if (avctx->pix_fmt == pix_fmts[i]) break; - if (c->pix_fmts[i] == AV_PIX_FMT_NONE) { + if (i == num_pix_fmts) { av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is not supported by the %s encoder.\n", av_get_pix_fmt_name(avctx->pix_fmt), c->name); av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n"); - for (int p = 0; c->pix_fmts[p] != AV_PIX_FMT_NONE; p++) { + for (int p = 0; pix_fmts[p] != AV_PIX_FMT_NONE; p++) { av_log(avctx, AV_LOG_ERROR, " %s\n", - av_get_pix_fmt_name(c->pix_fmts[p])); + av_get_pix_fmt_name(pix_fmts[p])); } return AVERROR(EINVAL); } - 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) + if (pix_fmts[i] == AV_PIX_FMT_YUVJ420P || + pix_fmts[i] == AV_PIX_FMT_YUVJ411P || + pix_fmts[i] == AV_PIX_FMT_YUVJ422P || + pix_fmts[i] == AV_PIX_FMT_YUVJ440P || + pix_fmts[i] == AV_PIX_FMT_YUVJ444P) avctx->color_range = AVCOL_RANGE_JPEG; } @@ -646,7 +652,10 @@ FF_ENABLE_DEPRECATION_WARNINGS static int encode_preinit_audio(AVCodecContext *avctx) { const AVCodec *c = avctx->codec; - int i; + const enum AVSampleFormat *sample_fmts; + const int *supported_samplerates; + const AVChannelLayout *ch_layouts; + int ret, i, num_sample_fmts, num_samplerates, num_ch_layouts; if (!av_get_sample_fmt_name(avctx->sample_fmt)) { av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n", @@ -659,53 +668,68 @@ static int encode_preinit_audio(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (c->sample_fmts) { - for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { - if (avctx->sample_fmt == c->sample_fmts[i]) + ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT, + 0, (const void **) &sample_fmts, + &num_sample_fmts); + if (ret < 0) + return ret; + if (sample_fmts) { + for (i = 0; i < num_sample_fmts; i++) { + if (avctx->sample_fmt == sample_fmts[i]) break; if (avctx->ch_layout.nb_channels == 1 && av_get_planar_sample_fmt(avctx->sample_fmt) == - av_get_planar_sample_fmt(c->sample_fmts[i])) { - avctx->sample_fmt = c->sample_fmts[i]; + av_get_planar_sample_fmt(sample_fmts[i])) { + avctx->sample_fmt = sample_fmts[i]; break; } } - if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { + if (i == num_sample_fmts) { av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is not supported by the %s encoder\n", av_get_sample_fmt_name(avctx->sample_fmt), c->name); av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n"); - for (int p = 0; c->sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) { + for (int p = 0; sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) { av_log(avctx, AV_LOG_ERROR, " %s\n", - av_get_sample_fmt_name(c->sample_fmts[p])); + av_get_sample_fmt_name(sample_fmts[p])); } return AVERROR(EINVAL); } } - if (c->supported_samplerates) { - for (i = 0; c->supported_samplerates[i] != 0; i++) - if (avctx->sample_rate == c->supported_samplerates[i]) + + ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_RATE, + 0, (const void **) &supported_samplerates, + &num_samplerates); + if (ret < 0) + return ret; + if (supported_samplerates) { + for (i = 0; i < num_samplerates; i++) + if (avctx->sample_rate == supported_samplerates[i]) break; - if (c->supported_samplerates[i] == 0) { + if (i == num_samplerates) { av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported by the %s encoder\n", avctx->sample_rate, c->name); av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n"); - for (int p = 0; c->supported_samplerates[p]; p++) - av_log(avctx, AV_LOG_ERROR, " %d\n", c->supported_samplerates[p]); + for (int p = 0; supported_samplerates[p]; p++) + av_log(avctx, AV_LOG_ERROR, " %d\n", supported_samplerates[p]); return AVERROR(EINVAL); } } - 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])) + ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_CHANNEL_LAYOUT, + 0, (const void **) &ch_layouts, &num_ch_layouts); + if (ret < 0) + return ret; + if (ch_layouts) { + for (i = 0; i < num_ch_layouts; i++) { + if (!av_channel_layout_compare(&avctx->ch_layout, &ch_layouts[i])) break; } - if (!c->ch_layouts[i].nb_channels) { + if (i == num_ch_layouts) { char buf[512]; int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); av_log(avctx, AV_LOG_ERROR, @@ -713,8 +737,8 @@ static int encode_preinit_audio(AVCodecContext *avctx) ret > 0 ? buf : "?", c->name); av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n"); - for (int p = 0; c->ch_layouts[p].nb_channels; p++) { - ret = av_channel_layout_describe(&c->ch_layouts[p], buf, sizeof(buf)); + for (int p = 0; ch_layouts[p].nb_channels; p++) { + ret = av_channel_layout_describe(&ch_layouts[p], buf, sizeof(buf)); av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?"); } return AVERROR(EINVAL);