aboutsummaryrefslogtreecommitdiff
path: root/libvpx/vp9/vp9_cx_iface.c
diff options
context:
space:
mode:
Diffstat (limited to 'libvpx/vp9/vp9_cx_iface.c')
-rw-r--r--libvpx/vp9/vp9_cx_iface.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/libvpx/vp9/vp9_cx_iface.c b/libvpx/vp9/vp9_cx_iface.c
index 48d555532..05ac9e169 100644
--- a/libvpx/vp9/vp9_cx_iface.c
+++ b/libvpx/vp9/vp9_cx_iface.c
@@ -15,7 +15,6 @@
#include "vpx/vpx_encoder.h"
#include "vpx/vpx_ext_ratectrl.h"
#include "vpx_dsp/psnr.h"
-#include "vpx_ports/vpx_once.h"
#include "vpx_ports/static_assert.h"
#include "vpx_ports/system_state.h"
#include "vpx_util/vpx_timestamp.h"
@@ -66,7 +65,11 @@ typedef struct vp9_extracfg {
} vp9_extracfg;
static struct vp9_extracfg default_extra_cfg = {
- 0, // cpu_used
+#if CONFIG_REALTIME_ONLY
+ 5, // cpu_used
+#else
+ 0, // cpu_used
+#endif
1, // enable_auto_alt_ref
0, // noise_sensitivity
0, // sharpness
@@ -381,8 +384,8 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
case VPX_IMG_FMT_I440:
if (ctx->cfg.g_profile != (unsigned int)PROFILE_1) {
ERROR(
- "Invalid image format. I422, I444, I440, NV12 images are "
- "not supported in profile.");
+ "Invalid image format. I422, I444, I440 images are not supported "
+ "in profile.");
}
break;
case VPX_IMG_FMT_I42216:
@@ -397,8 +400,8 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
break;
default:
ERROR(
- "Invalid image format. Only YV12, I420, I422, I444 images are "
- "supported.");
+ "Invalid image format. Only YV12, I420, I422, I444, I440, NV12 "
+ "images are supported.");
break;
}
@@ -523,8 +526,9 @@ static vpx_codec_err_t set_encoder_config(
raw_target_rate =
(unsigned int)((int64_t)oxcf->width * oxcf->height * oxcf->bit_depth * 3 *
oxcf->init_framerate / 1000);
- // Cap target bitrate to raw rate
- cfg->rc_target_bitrate = VPXMIN(raw_target_rate, cfg->rc_target_bitrate);
+ // Cap target bitrate to raw rate or 1000Mbps, whichever is less
+ cfg->rc_target_bitrate =
+ VPXMIN(VPXMIN(raw_target_rate, cfg->rc_target_bitrate), 1000000);
// Convert target bandwidth from Kbit/s to Bit/s
oxcf->target_bandwidth = 1000 * (int64_t)cfg->rc_target_bitrate;
@@ -780,7 +784,7 @@ static vpx_codec_err_t set_twopass_params_from_config(
static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
const vpx_codec_enc_cfg_t *cfg) {
vpx_codec_err_t res;
- int force_key = 0;
+ volatile int force_key = 0;
if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) {
if (cfg->g_lag_in_frames > 1 || cfg->g_pass != VPX_RC_ONE_PASS)
@@ -799,19 +803,28 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
ERROR("Cannot increase lag_in_frames");
res = validate_config(ctx, cfg, &ctx->extra_cfg);
+ if (res != VPX_CODEC_OK) return res;
- if (res == VPX_CODEC_OK) {
- ctx->cfg = *cfg;
- set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
- set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
- // On profile change, request a key frame
- force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
- vp9_change_config(ctx->cpi, &ctx->oxcf);
+ if (setjmp(ctx->cpi->common.error.jmp)) {
+ const vpx_codec_err_t codec_err =
+ update_error_state(ctx, &ctx->cpi->common.error);
+ ctx->cpi->common.error.setjmp = 0;
+ vpx_clear_system_state();
+ assert(codec_err != VPX_CODEC_OK);
+ return codec_err;
}
+ ctx->cfg = *cfg;
+ set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
+ set_twopass_params_from_config(&ctx->cfg, ctx->cpi);
+ // On profile change, request a key frame
+ force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
+ vp9_change_config(ctx->cpi, &ctx->oxcf);
+
if (force_key) ctx->next_frame_flags |= VPX_EFLAG_FORCE_KF;
- return res;
+ ctx->cpi->common.error.setjmp = 0;
+ return VPX_CODEC_OK;
}
static vpx_codec_err_t ctrl_get_quantizer(vpx_codec_alg_priv_t *ctx,
@@ -1095,7 +1108,7 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
}
priv->extra_cfg = default_extra_cfg;
- once(vp9_initialize_enc);
+ vp9_initialize_enc();
res = validate_config(priv, &priv->cfg, &priv->extra_cfg);
@@ -2143,6 +2156,7 @@ static vp9_extracfg get_extra_cfg() {
VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
vpx_rational_t frame_rate,
int target_bitrate, int encode_speed,
+ int target_level,
vpx_enc_pass enc_pass) {
/* This function will generate the same VP9EncoderConfig used by the
* vpxenc command given below.
@@ -2154,6 +2168,7 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
* FPS: frame_rate
* BITRATE: target_bitrate
* CPU_USED:encode_speed
+ * TARGET_LEVEL: target_level
*
* INPUT, OUTPUT, LIMIT will not affect VP9EncoderConfig
*
@@ -2166,6 +2181,7 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
* FPS=30/1
* LIMIT=150
* CPU_USED=0
+ * TARGET_LEVEL=0
* ./vpxenc --limit=$LIMIT --width=$WIDTH --height=$HEIGHT --fps=$FPS
* --lag-in-frames=25 \
* --codec=vp9 --good --cpu-used=CPU_USED --threads=0 --profile=0 \
@@ -2174,7 +2190,7 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
* --minsection-pct=0 --maxsection-pct=150 --arnr-maxframes=7 --psnr \
* --arnr-strength=5 --sharpness=0 --undershoot-pct=100 --overshoot-pct=100 \
* --frame-parallel=0 --tile-columns=0 --cpu-used=0 --end-usage=vbr \
- * --target-bitrate=$BITRATE -o $OUTPUT $INPUT
+ * --target-bitrate=$BITRATE --target-level=0 -o $OUTPUT $INPUT
*/
VP9EncoderConfig oxcf;
@@ -2192,6 +2208,7 @@ VP9EncoderConfig vp9_get_encoder_config(int frame_width, int frame_height,
oxcf.frame_parallel_decoding_mode = 0;
oxcf.two_pass_vbrmax_section = 150;
oxcf.speed = abs(encode_speed);
+ oxcf.target_level = target_level;
return oxcf;
}