From e026395d22eb217623ae16d3e5592c1e1a2c9336 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 6 Jul 2023 18:11:24 +0200 Subject: [PATCH] lavc/encode: shorten code by using a local variable --- libavcodec/encode.c | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 15f6eb11d0..fd182007cc 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -574,6 +574,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; @@ -583,20 +584,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; } @@ -649,6 +650,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)) { @@ -657,28 +659,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); @@ -689,12 +691,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)