Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -563,7 +563,8 @@ static int encode_preinit_video(AVCodecContext *avctx) · 562 unmodified lines | ||
| 563 | 563 | { |
| 564 | 564 | const AVCodec *c = avctx->codec; |
| 565 | 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 | 569 | if (!av_get_pix_fmt_name(avctx->pix_fmt)) { |
| 569 | 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 | 572 | return AVERROR(EINVAL); |
| 572 | 573 | } |
| 573 | 574 | |
| 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]) | |
| 577 | 583 | break; |
| 578 | − if (c->pix_fmts[i] == AV_PIX_FMT_NONE) { | |
| 584 | + if (i == num_pix_fmts) { | |
| 579 | 585 | av_log(avctx, AV_LOG_ERROR, |
| 580 | 586 | "Specified pixel format %s is not supported by the %s encoder.\n", |
| 581 | 587 | av_get_pix_fmt_name(avctx->pix_fmt), c->name); |
| 582 | 588 | |
| 583 | 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 | 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 | 595 | return AVERROR(EINVAL); |
| 590 | 596 | } |
| 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) | |
| 596 | 602 | avctx->color_range = AVCOL_RANGE_JPEG; |
| 597 | 603 | } |
| 598 | 604 | |
| @@ -646,7 +652,10 @@ FF_ENABLE_DEPRECATION_WARNINGS · 47 unmodified lines | ||
| 646 | 652 | static int encode_preinit_audio(AVCodecContext *avctx) |
| 647 | 653 | { |
| 648 | 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 | 660 | if (!av_get_sample_fmt_name(avctx->sample_fmt)) { |
| 652 | 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 | 668 | return AVERROR(EINVAL); |
| 660 | 669 | } |
| 661 | 670 | |
| 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]) | |
| 665 | 679 | break; |
| 666 | 680 | if (avctx->ch_layout.nb_channels == 1 && |
| 667 | 681 | 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]; | |
| 670 | 684 | break; |
| 671 | 685 | } |
| 672 | 686 | } |
| 673 | − if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { | |
| 687 | + if (i == num_sample_fmts) { | |
| 674 | 688 | av_log(avctx, AV_LOG_ERROR, |
| 675 | 689 | "Specified sample format %s is not supported by the %s encoder\n", |
| 676 | 690 | av_get_sample_fmt_name(avctx->sample_fmt), c->name); |
| 677 | 691 | |
| 678 | 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 | 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 | 698 | return AVERROR(EINVAL); |
| 685 | 699 | } |
| 686 | 700 | } |
| 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]) | |
| 690 | 710 | break; |
| 691 | − if (c->supported_samplerates[i] == 0) { | |
| 711 | + if (i == num_samplerates) { | |
| 692 | 712 | av_log(avctx, AV_LOG_ERROR, |
| 693 | 713 | "Specified sample rate %d is not supported by the %s encoder\n", |
| 694 | 714 | avctx->sample_rate, c->name); |
| 695 | 715 | |
| 696 | 716 | 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]); | |
| 699 | 719 | |
| 700 | 720 | return AVERROR(EINVAL); |
| 701 | 721 | } |
| 702 | 722 | } |
| 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])) | |
| 706 | 730 | break; |
| 707 | 731 | } |
| 708 | − if (!c->ch_layouts[i].nb_channels) { | |
| 732 | + if (i == num_ch_layouts) { | |
| 709 | 733 | char buf[512]; |
| 710 | 734 | int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf)); |
| 711 | 735 | av_log(avctx, AV_LOG_ERROR, |
| @@ -713,8 +737,8 @@ static int encode_preinit_audio(AVCodecContext *avctx) · 1 unmodified line | ||
| 713 | 737 | ret > 0 ? buf : "?", c->name); |
| 714 | 738 | |
| 715 | 739 | 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)); | |
| 718 | 742 | av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?"); |
| 719 | 743 | } |
| 720 | 744 | return AVERROR(EINVAL); |