From patchwork Fri Apr 5 18:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 47861 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:24a8:b0:1a3:b6bb:3029 with SMTP id m40csp1157658pzd; Fri, 5 Apr 2024 11:57:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW4apwIHfeFA2XenU/dI+lDg1MLaMxYotB4ZVLUJH+9ZfUo5MiEE3xi59LNJX2E+iUtjzsFCPsYEU1/ULkcnZWvMnCCqmxvxOeW3g== X-Google-Smtp-Source: AGHT+IEINlKTuTB1D+xj0BQjVhHHUF58/eU3pb5spSC591sbaZSsIfrzB1yRBv3lxpjm9lH2tMd4 X-Received: by 2002:a17:907:72c2:b0:a4e:8508:d807 with SMTP id du2-20020a17090772c200b00a4e8508d807mr2095334ejc.0.1712343468932; Fri, 05 Apr 2024 11:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712343468; cv=none; d=google.com; s=arc-20160816; b=tIiVuQuSrKMSV8IOk7ri68U0B4ecCJiy3ubBs7JRSHRvYqVH0V0SmrOT8wJFJxI3p4 VWKbTXd00FQAzAPYIpduKocvhPnN3SN4Pr+VVpKO0BxYbcYHFwDH6Bdr+08+UpKXq1P1 cWGaqPPrhY4r1ejiCojtcZaqmd61O0Ulby8ThxAOuy5UxJGmONgkYx7S/kgIfqnwKYMC nIlozQIPiBtsfQZWT/7uBX6TphYxLLIAS5wMctL+xNDWKxAzhOQp9qIfXrFC9n4upnXi bRXpGt2y+XdrXsvw8Ps915H5deqzV6VSMIuj0iAgnC8DJGUPdmNf0u7dNue2qWrd22dE BuWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=2Y202rhFJHCGUXWaGV5maD7cdvir070NX1QUL4qfv6Q=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=blrR1rK1xNpRDOvFhbVw3AwcqFjN/zI6aXdfXH+hI1sK2q7k0mdLnnVd+ELOFJ19Mg ZwIUtLskOZP3okVRsVInWN0abslQmsPlwRqeBsaw/bEjet1pkkjz2Sn6+RHxXHlID+WJ YFCyTLW8yTuRWIEKl3MqrA4WQ5AP60PtuHNPqTIySxTBgEwxKYZVgP6gqAbbglx33oiW D0qANBa31m/juHck06LfbLnvjyvk5TJVGyVwBP+XX9UfAp4TuCaJYvpR+K+756rDQc1E biIO5CHRRE6+2+FV5Xw5Ozj1G8x1Z6sCkB/nQ4sTSAmlAdGQv9f7ImpFDYZ7kBoYLTw2 8BdA==; 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="lyny/sUD"; 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 u15-20020a170906408f00b00a519056b86dsi928901ejj.381.2024.04.05.11.57.48; Fri, 05 Apr 2024 11:57:48 -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="lyny/sUD"; 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 936F868D16C; Fri, 5 Apr 2024 21:57:34 +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 6545468D095 for ; Fri, 5 Apr 2024 21:57:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1712343446; bh=M05+RXa7tCLEcr/XD9YkzRUNJQEklDILgd6nsZaiGNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lyny/sUDoghHhXsBt9oVhWsm935o3ok06s1WwzUals+q+bU/itufFmQzUvsePihDY ItnhQZ+lUt1KhN9b+eWs7xFzl5Axz4bdWYuIVlWt0pEeNfJDC1JbWVoh9z7RUigH+f 14GX6W1kYmMmclTnm33Qb/TiyoCmlKCzk6DgwAbc= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2199D4255D; Fri, 5 Apr 2024 20:57:26 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Apr 2024 20:57:12 +0200 Message-ID: <20240405185721.111072-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405185721.111072-1-ffmpeg@haasn.xyz> References: <20240405185721.111072-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/11] 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: L1yAF1/KdGZ5 From: Niklas Haas --- libavcodec/encode.c | 88 ++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 34658d13d0c..d0e79379048 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; 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); + if (ret < 0) + return ret; + + if (pix_fmts) { + for (i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++) + if (avctx->pix_fmt == pix_fmts[i]) break; - if (c->pix_fmts[i] == AV_PIX_FMT_NONE) { + if (pix_fmts[i] == AV_PIX_FMT_NONE) { 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; if (!av_get_sample_fmt_name(avctx->sample_fmt)) { av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n", @@ -659,53 +668,66 @@ 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); + if (ret < 0) + return ret; + if (sample_fmts) { + for (i = 0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; 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 (sample_fmts[i] == AV_SAMPLE_FMT_NONE) { 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); + if (ret < 0) + return ret; + if (supported_samplerates) { + for (i = 0; supported_samplerates[i] != 0; i++) + if (avctx->sample_rate == supported_samplerates[i]) break; - if (c->supported_samplerates[i] == 0) { + if (supported_samplerates[i] == 0) { 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); + if (ret < 0) + return ret; + if (ch_layouts) { + for (i = 0; ch_layouts[i].nb_channels; i++) { + if (!av_channel_layout_compare(&avctx->ch_layout, &ch_layouts[i])) break; } - if (!c->ch_layouts[i].nb_channels) { + if (!ch_layouts[i].nb_channels) { char buf[512]; int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); av_log(avctx, AV_LOG_ERROR, @@ -713,8 +735,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);