MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_preinit_audio

Function encode_preinit_audio

libavcodec/encode.c:648–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

646}
647
648static int encode_preinit_audio(AVCodecContext *avctx)
649{
650 const AVCodec *c = avctx->codec;
651 const enum AVSampleFormat *sample_fmts;
652 const int *supported_samplerates;
653 const AVChannelLayout *ch_layouts;
654 int ret, i, num_sample_fmts, num_samplerates, num_ch_layouts;
655
656 if (!av_get_sample_fmt_name(avctx->sample_fmt)) {
657 av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n",
658 avctx->sample_fmt);
659 return AVERROR(EINVAL);
660 }
661
662 ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT,
663 0, (const void **) &sample_fmts,
664 &num_sample_fmts);
665 if (ret < 0)
666 return ret;
667 if (sample_fmts) {
668 for (i = 0; i < num_sample_fmts; i++) {
669 if (avctx->sample_fmt == sample_fmts[i])
670 break;
671 if (avctx->ch_layout.nb_channels == 1 &&
672 av_get_planar_sample_fmt(avctx->sample_fmt) ==
673 av_get_planar_sample_fmt(sample_fmts[i])) {
674 avctx->sample_fmt = sample_fmts[i];
675 break;
676 }
677 }
678 if (i == num_sample_fmts) {
679 av_log(avctx, AV_LOG_ERROR,
680 "Specified sample format %s is not supported by the %s encoder\n",
681 av_get_sample_fmt_name(avctx->sample_fmt), c->name);
682
683 av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n");
684 for (int p = 0; sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
685 av_log(avctx, AV_LOG_ERROR, " %s\n",
686 av_get_sample_fmt_name(sample_fmts[p]));
687 }
688
689 return AVERROR(EINVAL);
690 }
691 }
692
693 ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_RATE,
694 0, (const void **) &supported_samplerates,
695 &num_samplerates);
696 if (ret < 0)
697 return ret;
698 if (supported_samplerates) {
699 for (i = 0; i < num_samplerates; i++)
700 if (avctx->sample_rate == supported_samplerates[i])
701 break;
702 if (i == num_samplerates) {
703 av_log(avctx, AV_LOG_ERROR,
704 "Specified sample rate %d is not supported by the %s encoder\n",
705 avctx->sample_rate, c->name);

Callers 1

ff_encode_preinitFunction · 0.85

Calls 8

av_get_sample_fmt_nameFunction · 0.85
av_logFunction · 0.85
av_get_planar_sample_fmtFunction · 0.85
av_get_bytes_per_sampleFunction · 0.85

Tested by

no test coverage detected