| 751 | }; |
| 752 | |
| 753 | static av_cold int aom_init(AVCodecContext *avctx, |
| 754 | const struct aom_codec_iface *iface) |
| 755 | { |
| 756 | AOMContext *ctx = avctx->priv_data; |
| 757 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); |
| 758 | struct aom_codec_enc_cfg enccfg = { 0 }; |
| 759 | aom_codec_flags_t flags = |
| 760 | (avctx->flags & AV_CODEC_FLAG_PSNR) ? AOM_CODEC_USE_PSNR : 0; |
| 761 | int res; |
| 762 | aom_img_fmt_t img_fmt; |
| 763 | aom_codec_caps_t codec_caps = aom_codec_get_caps(iface); |
| 764 | |
| 765 | av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str()); |
| 766 | av_log(avctx, AV_LOG_VERBOSE, "%s\n", aom_codec_build_config()); |
| 767 | |
| 768 | if ((res = aom_codec_enc_config_default(iface, &enccfg, ctx->usage)) != AOM_CODEC_OK) { |
| 769 | av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n", |
| 770 | aom_codec_err_to_string(res)); |
| 771 | return AVERROR(EINVAL); |
| 772 | } |
| 773 | |
| 774 | if (set_pix_fmt(avctx, codec_caps, &enccfg, &flags, &img_fmt)) |
| 775 | return AVERROR(EINVAL); |
| 776 | |
| 777 | if(!avctx->bit_rate) |
| 778 | if(avctx->rc_max_rate || avctx->rc_buffer_size || avctx->rc_initial_buffer_occupancy) { |
| 779 | av_log( avctx, AV_LOG_ERROR, "Rate control parameters set without a bitrate\n"); |
| 780 | return AVERROR(EINVAL); |
| 781 | } |
| 782 | |
| 783 | dump_enc_cfg(avctx, &enccfg, AV_LOG_DEBUG); |
| 784 | |
| 785 | enccfg.g_w = avctx->width; |
| 786 | enccfg.g_h = avctx->height; |
| 787 | enccfg.g_timebase.num = avctx->time_base.num; |
| 788 | enccfg.g_timebase.den = avctx->time_base.den; |
| 789 | enccfg.g_threads = |
| 790 | FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 64); |
| 791 | |
| 792 | if (ctx->lag_in_frames >= 0) |
| 793 | enccfg.g_lag_in_frames = ctx->lag_in_frames; |
| 794 | |
| 795 | if (avctx->flags & AV_CODEC_FLAG_PASS1) |
| 796 | enccfg.g_pass = AOM_RC_FIRST_PASS; |
| 797 | else if (avctx->flags & AV_CODEC_FLAG_PASS2) |
| 798 | enccfg.g_pass = AOM_RC_LAST_PASS; |
| 799 | else |
| 800 | enccfg.g_pass = AOM_RC_ONE_PASS; |
| 801 | |
| 802 | if (avctx->rc_min_rate == avctx->rc_max_rate && |
| 803 | avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) { |
| 804 | enccfg.rc_end_usage = AOM_CBR; |
| 805 | } else if (ctx->crf >= 0) { |
| 806 | enccfg.rc_end_usage = AOM_CQ; |
| 807 | if (!avctx->bit_rate) |
| 808 | enccfg.rc_end_usage = AOM_Q; |
| 809 | } |
| 810 |
no test coverage detected