Unified · Split
| @@ -563,7 +563,8 @@ static int encode_preinit_video(AVCodecContext *avctx) · 562 unmodified lines | |||
| 563 | { | 563 | { |
| 564 | const AVCodec *c = avctx->codec; | 564 | const AVCodec *c = avctx->codec; |
| 565 | const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt); | 565 | 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; | ||
| 567 | 568 | ||
| 568 | if (!av_get_pix_fmt_name(avctx->pix_fmt)) { | 569 | if (!av_get_pix_fmt_name(avctx->pix_fmt)) { |
| 569 | av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n", | 570 | 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 | |||
| 571 | return AVERROR(EINVAL); | 572 | return AVERROR(EINVAL); |
| 572 | } | 573 | } |
| 573 | 574 | ||
| 574 | if (c->pix_fmts) { | 575 | ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_PIX_FORMAT, |
| 575 | for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++) | 576 | 0, (const void **) &pix_fmts, &num_pix_fmts); |
| 576 | if (avctx->pix_fmt == c->pix_fmts[i]) | 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]) | ||
| 577 | break; | 583 | break; |
| 578 | if (c->pix_fmts[i] == AV_PIX_FMT_NONE) { | 584 | if (i == num_pix_fmts) { |
| 579 | av_log(avctx, AV_LOG_ERROR, | 585 | av_log(avctx, AV_LOG_ERROR, |
| 580 | "Specified pixel format %s is not supported by the %s encoder.\n", | 586 | "Specified pixel format %s is not supported by the %s encoder.\n", |
| 581 | av_get_pix_fmt_name(avctx->pix_fmt), c->name); | 587 | av_get_pix_fmt_name(avctx->pix_fmt), c->name); |
| 582 | 588 | ||
| 583 | av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n"); | 589 | 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++) { |
| 585 | av_log(avctx, AV_LOG_ERROR, " %s\n", | 591 | 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])); |
| 587 | } | 593 | } |
| 588 | 594 | ||
| 589 | return AVERROR(EINVAL); | 595 | return AVERROR(EINVAL); |
| 590 | } | 596 | } |
| 591 | if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P || | 597 | if (pix_fmts[i] == AV_PIX_FMT_YUVJ420P || |
| 592 | c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P || | 598 | pix_fmts[i] == AV_PIX_FMT_YUVJ411P || |
| 593 | c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P || | 599 | pix_fmts[i] == AV_PIX_FMT_YUVJ422P || |
| 594 | c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P || | 600 | pix_fmts[i] == AV_PIX_FMT_YUVJ440P || |
| 595 | c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P) | 601 | pix_fmts[i] == AV_PIX_FMT_YUVJ444P) |
| 596 | avctx->color_range = AVCOL_RANGE_JPEG; | 602 | avctx->color_range = AVCOL_RANGE_JPEG; |
| 597 | } | 603 | } |
| 598 | 604 | ||
| @@ -646,7 +652,10 @@ FF_ENABLE_DEPRECATION_WARNINGS · 47 unmodified lines | |||
| 646 | static int encode_preinit_audio(AVCodecContext *avctx) | 652 | static int encode_preinit_audio(AVCodecContext *avctx) |
| 647 | { | 653 | { |
| 648 | const AVCodec *c = avctx->codec; | 654 | 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; | ||
| 650 | 659 | ||
| 651 | if (!av_get_sample_fmt_name(avctx->sample_fmt)) { | 660 | if (!av_get_sample_fmt_name(avctx->sample_fmt)) { |
| 652 | av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n", | 661 | 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 | |||
| 659 | return AVERROR(EINVAL); | 668 | return AVERROR(EINVAL); |
| 660 | } | 669 | } |
| 661 | 670 | ||
| 662 | if (c->sample_fmts) { | 671 | ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT, |
| 663 | for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) { | 672 | 0, (const void **) &sample_fmts, |
| 664 | if (avctx->sample_fmt == c->sample_fmts[i]) | 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]) | ||
| 665 | break; | 679 | break; |
| 666 | if (avctx->ch_layout.nb_channels == 1 && | 680 | if (avctx->ch_layout.nb_channels == 1 && |
| 667 | av_get_planar_sample_fmt(avctx->sample_fmt) == | 681 | av_get_planar_sample_fmt(avctx->sample_fmt) == |
| 668 | av_get_planar_sample_fmt(c->sample_fmts[i])) { | 682 | av_get_planar_sample_fmt(sample_fmts[i])) { |
| 669 | avctx->sample_fmt = c->sample_fmts[i]; | 683 | avctx->sample_fmt = sample_fmts[i]; |
| 670 | break; | 684 | break; |
| 671 | } | 685 | } |
| 672 | } | 686 | } |
| 673 | if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { | 687 | if (i == num_sample_fmts) { |
| 674 | av_log(avctx, AV_LOG_ERROR, | 688 | av_log(avctx, AV_LOG_ERROR, |
| 675 | "Specified sample format %s is not supported by the %s encoder\n", | 689 | "Specified sample format %s is not supported by the %s encoder\n", |
| 676 | av_get_sample_fmt_name(avctx->sample_fmt), c->name); | 690 | av_get_sample_fmt_name(avctx->sample_fmt), c->name); |
| 677 | 691 | ||
| 678 | av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n"); | 692 | 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++) { |
| 680 | av_log(avctx, AV_LOG_ERROR, " %s\n", | 694 | 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])); |
| 682 | } | 696 | } |
| 683 | 697 | ||
| 684 | return AVERROR(EINVAL); | 698 | return AVERROR(EINVAL); |
| 685 | } | 699 | } |
| 686 | } | 700 | } |
| 687 | if (c->supported_samplerates) { | 701 | |
| 688 | for (i = 0; c->supported_samplerates[i] != 0; i++) | 702 | ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_SAMPLE_RATE, |
| 689 | if (avctx->sample_rate == c->supported_samplerates[i]) | 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]) | ||
| 690 | break; | 710 | break; |
| 691 | if (c->supported_samplerates[i] == 0) { | 711 | if (i == num_samplerates) { |
| 692 | av_log(avctx, AV_LOG_ERROR, | 712 | av_log(avctx, AV_LOG_ERROR, |
| 693 | "Specified sample rate %d is not supported by the %s encoder\n", | 713 | "Specified sample rate %d is not supported by the %s encoder\n", |
| 694 | avctx->sample_rate, c->name); | 714 | avctx->sample_rate, c->name); |
| 695 | 715 | ||
| 696 | av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n"); | 716 | av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n"); |
| 697 | for (int p = 0; c->supported_samplerates[p]; p++) | 717 | for (int p = 0; supported_samplerates[p]; p++) |
| 698 | av_log(avctx, AV_LOG_ERROR, " %d\n", c->supported_samplerates[p]); | 718 | av_log(avctx, AV_LOG_ERROR, " %d\n", supported_samplerates[p]); |
| 699 | 719 | ||
| 700 | return AVERROR(EINVAL); | 720 | return AVERROR(EINVAL); |
| 701 | } | 721 | } |
| 702 | } | 722 | } |
| 703 | if (c->ch_layouts) { | 723 | ret = avcodec_get_supported_config(avctx, NULL, AV_CODEC_CONFIG_CHANNEL_LAYOUT, |
| 704 | for (i = 0; c->ch_layouts[i].nb_channels; i++) { | 724 | 0, (const void **) &ch_layouts, &num_ch_layouts); |
| 705 | if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i])) | 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])) | ||
| 706 | break; | 730 | break; |
| 707 | } | 731 | } |
| 708 | if (!c->ch_layouts[i].nb_channels) { | 732 | if (i == num_ch_layouts) { |
| 709 | char buf[512]; | 733 | char buf[512]; |
| 710 | int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); | 734 | int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); |
| 711 | av_log(avctx, AV_LOG_ERROR, | 735 | av_log(avctx, AV_LOG_ERROR, |
| @@ -713,8 +737,8 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 1 unmodified line | |||
| 713 | ret > 0 ? buf : "?", c->name); | 737 | ret > 0 ? buf : "?", c->name); |
| 714 | 738 | ||
| 715 | av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n"); | 739 | av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n"); |
| 716 | for (int p = 0; c->ch_layouts[p].nb_channels; p++) { | 740 | for (int p = 0; ch_layouts[p].nb_channels; p++) { |
| 717 | ret = av_channel_layout_describe(&c->ch_layouts[p], buf, sizeof(buf)); | 741 | ret = av_channel_layout_describe(&ch_layouts[p], buf, sizeof(buf)); |
| 718 | av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?"); | 742 | av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?"); |
| 719 | } | 743 | } |
| 720 | return AVERROR(EINVAL); | 744 | return AVERROR(EINVAL); |