History

avcodec/encode: switch to avcodec_get_supported_config()

Niklas Haas committed 2 years ago

Commit 13cec7b1 parent 33057671 file · +57 −33Browse files

Unified · Split

libavcodec/encode.c+57−33
@@ -563,7 +563,8 @@ static int encode_preinit_video(AVCodecContext *avctx) · 562 unmodified lines
563563 {
564564 const AVCodec *c = avctx->codec;
565565 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
566− int i;
566+ const enum AVPixelFormat *pix_fmts;
567+ int ret, i, num_pix_fmts;
567568
568569 if (!av_get_pix_fmt_name(avctx->pix_fmt)) {
569570 av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n",
@@ -571,28 +572,33 @@ static int encode_preinit_video(AVCodecContext *avctx) · 1 unmodified line
571572 return AVERROR(EINVAL);
572573 }
573574
574− if (c->pix_fmts) {
575− for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
576− if (avctx->pix_fmt == c->pix_fmts[i])
575+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT,
576+ 0, (const void **) &pix_fmts, &num_pix_fmts);
577+ if (ret < 0)
578+ return ret;
579+
580+ if (pix_fmts) {
581+ for (i = 0; i < num_pix_fmts; i++)
582+ if (avctx->pix_fmt == pix_fmts[i])
577583 break;
578− if (c->pix_fmts[i] == AV_PIX_FMT_NONE) {
584+ if (i == num_pix_fmts) {
579585 av_log(avctx, AV_LOG_ERROR,
580586 "Specified pixel format %s is not supported by the %s encoder.\n",
581587 av_get_pix_fmt_name(avctx->pix_fmt), c->name);
582588
583589 av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n");
584− for (int p = 0; c->pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
590+ for (int p = 0; pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
585591 av_log(avctx, AV_LOG_ERROR, " %s\n",
586− av_get_pix_fmt_name(c->pix_fmts[p]));
592+ av_get_pix_fmt_name(pix_fmts[p]));
587593 }
588594
589595 return AVERROR(EINVAL);
590596 }
591− if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
592− c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
593− c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
594− c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
595− c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
597+ if (pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
598+ pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
599+ pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
600+ pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
601+ pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
596602 avctx->color_range = AVCOL_RANGE_JPEG;
597603 }
598604
@@ -646,7 +652,10 @@ FF_ENABLE_DEPRECATION_WARNINGS · 47 unmodified lines
646652 static int encode_preinit_audio(AVCodecContext *avctx)
647653 {
648654 const AVCodec *c = avctx->codec;
649− int i;
655+ const enum AVSampleFormat *sample_fmts;
656+ const int *supported_samplerates;
657+ const AVChannelLayout *ch_layouts;
658+ int ret, i, num_sample_fmts, num_samplerates, num_ch_layouts;
650659
651660 if (!av_get_sample_fmt_name(avctx->sample_fmt)) {
652661 av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n",
@@ -659,53 +668,68 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 6 unmodified lines
659668 return AVERROR(EINVAL);
660669 }
661670
662− if (c->sample_fmts) {
663− for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
664− if (avctx->sample_fmt == c->sample_fmts[i])
671+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT,
672+ 0, (const void **) &sample_fmts,
673+ &num_sample_fmts);
674+ if (ret < 0)
675+ return ret;
676+ if (sample_fmts) {
677+ for (i = 0; i < num_sample_fmts; i++) {
678+ if (avctx->sample_fmt == sample_fmts[i])
665679 break;
666680 if (avctx->ch_layout.nb_channels == 1 &&
667681 av_get_planar_sample_fmt(avctx->sample_fmt) ==
668− av_get_planar_sample_fmt(c->sample_fmts[i])) {
669− avctx->sample_fmt = c->sample_fmts[i];
682+ av_get_planar_sample_fmt(sample_fmts[i])) {
683+ avctx->sample_fmt = sample_fmts[i];
670684 break;
671685 }
672686 }
673− if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
687+ if (i == num_sample_fmts) {
674688 av_log(avctx, AV_LOG_ERROR,
675689 "Specified sample format %s is not supported by the %s encoder\n",
676690 av_get_sample_fmt_name(avctx->sample_fmt), c->name);
677691
678692 av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n");
679− for (int p = 0; c->sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
693+ for (int p = 0; sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
680694 av_log(avctx, AV_LOG_ERROR, " %s\n",
681− av_get_sample_fmt_name(c->sample_fmts[p]));
695+ av_get_sample_fmt_name(sample_fmts[p]));
682696 }
683697
684698 return AVERROR(EINVAL);
685699 }
686700 }
687− if (c->supported_samplerates) {
688− for (i = 0; c->supported_samplerates[i] != 0; i++)
689− if (avctx->sample_rate == c->supported_samplerates[i])
701+
702+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_RATE,
703+ 0, (const void **) &supported_samplerates,
704+ &num_samplerates);
705+ if (ret < 0)
706+ return ret;
707+ if (supported_samplerates) {
708+ for (i = 0; i < num_samplerates; i++)
709+ if (avctx->sample_rate == supported_samplerates[i])
690710 break;
691− if (c->supported_samplerates[i] == 0) {
711+ if (i == num_samplerates) {
692712 av_log(avctx, AV_LOG_ERROR,
693713 "Specified sample rate %d is not supported by the %s encoder\n",
694714 avctx->sample_rate, c->name);
695715
696716 av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n");
697− for (int p = 0; c->supported_samplerates[p]; p++)
698− av_log(avctx, AV_LOG_ERROR, " %d\n", c->supported_samplerates[p]);
717+ for (int p = 0; supported_samplerates[p]; p++)
718+ av_log(avctx, AV_LOG_ERROR, " %d\n", supported_samplerates[p]);
699719
700720 return AVERROR(EINVAL);
701721 }
702722 }
703− if (c->ch_layouts) {
704− for (i = 0; c->ch_layouts[i].nb_channels; i++) {
705− if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i]))
723+ ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_CHANNEL_LAYOUT,
724+ 0, (const void **) &ch_layouts, &num_ch_layouts);
725+ if (ret < 0)
726+ return ret;
727+ if (ch_layouts) {
728+ for (i = 0; i < num_ch_layouts; i++) {
729+ if (!av_channel_layout_compare(&avctx->ch_layout, &ch_layouts[i]))
706730 break;
707731 }
708− if (!c->ch_layouts[i].nb_channels) {
732+ if (i == num_ch_layouts) {
709733 char buf[512];
710734 int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
711735 av_log(avctx, AV_LOG_ERROR,
@@ -713,8 +737,8 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 1 unmodified line
713737 ret > 0 ? buf : "?", c->name);
714738
715739 av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n");
716− for (int p = 0; c->ch_layouts[p].nb_channels; p++) {
717− ret = av_channel_layout_describe(&c->ch_layouts[p], buf, sizeof(buf));
740+ for (int p = 0; ch_layouts[p].nb_channels; p++) {
741+ ret = av_channel_layout_describe(&ch_layouts[p], buf, sizeof(buf));
718742 av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?");
719743 }
720744 return AVERROR(EINVAL);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t