| 1820 | } |
| 1821 | |
| 1822 | static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) |
| 1823 | { |
| 1824 | NvencContext *ctx = avctx->priv_data; |
| 1825 | NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs; |
| 1826 | NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs; |
| 1827 | |
| 1828 | NV_ENC_PRESET_CONFIG preset_config = { 0 }; |
| 1829 | NVENCSTATUS nv_status = NV_ENC_SUCCESS; |
| 1830 | AVCPBProperties *cpb_props; |
| 1831 | int res = 0; |
| 1832 | int dw, dh; |
| 1833 | |
| 1834 | ctx->encode_config.version = NV_ENC_CONFIG_VER; |
| 1835 | ctx->init_encode_params.version = NV_ENC_INITIALIZE_PARAMS_VER; |
| 1836 | |
| 1837 | ctx->init_encode_params.encodeHeight = avctx->height; |
| 1838 | ctx->init_encode_params.encodeWidth = avctx->width; |
| 1839 | |
| 1840 | ctx->init_encode_params.encodeConfig = &ctx->encode_config; |
| 1841 | |
| 1842 | preset_config.version = NV_ENC_PRESET_CONFIG_VER; |
| 1843 | preset_config.presetCfg.version = NV_ENC_CONFIG_VER; |
| 1844 | |
| 1845 | #ifdef NVENC_HAVE_NEW_PRESETS |
| 1846 | ctx->init_encode_params.tuningInfo = ctx->tuning_info; |
| 1847 | |
| 1848 | if (ctx->flags & NVENC_LOSSLESS) |
| 1849 | ctx->init_encode_params.tuningInfo = NV_ENC_TUNING_INFO_LOSSLESS; |
| 1850 | else if (ctx->flags & NVENC_LOWLATENCY) |
| 1851 | ctx->init_encode_params.tuningInfo = NV_ENC_TUNING_INFO_LOW_LATENCY; |
| 1852 | |
| 1853 | nv_status = p_nvenc->nvEncGetEncodePresetConfigEx(ctx->nvencoder, |
| 1854 | ctx->init_encode_params.encodeGUID, |
| 1855 | ctx->init_encode_params.presetGUID, |
| 1856 | ctx->init_encode_params.tuningInfo, |
| 1857 | &preset_config); |
| 1858 | #else |
| 1859 | nv_status = p_nvenc->nvEncGetEncodePresetConfig(ctx->nvencoder, |
| 1860 | ctx->init_encode_params.encodeGUID, |
| 1861 | ctx->init_encode_params.presetGUID, |
| 1862 | &preset_config); |
| 1863 | #endif |
| 1864 | if (nv_status != NV_ENC_SUCCESS) |
| 1865 | return nvenc_print_error(avctx, nv_status, "Cannot get the preset configuration"); |
| 1866 | |
| 1867 | memcpy(&ctx->encode_config, &preset_config.presetCfg, sizeof(ctx->encode_config)); |
| 1868 | |
| 1869 | ctx->encode_config.version = NV_ENC_CONFIG_VER; |
| 1870 | |
| 1871 | compute_dar(avctx, &dw, &dh); |
| 1872 | ctx->init_encode_params.darHeight = dh; |
| 1873 | ctx->init_encode_params.darWidth = dw; |
| 1874 | |
| 1875 | if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { |
| 1876 | ctx->init_encode_params.frameRateNum = avctx->framerate.num; |
| 1877 | ctx->init_encode_params.frameRateDen = avctx->framerate.den; |
| 1878 | } else { |
| 1879 | ctx->init_encode_params.frameRateNum = avctx->time_base.den; |
no test coverage detected