+ // See if we have a new bitrate to change to.
+ unsigned new_rate = new_bitrate_kbit.exchange(0); // Read and clear.
+ if (new_rate != 0) {
+ if (speed_control) {
+ speed_control->set_config_override_function([new_rate](x264_param_t *param) {
+ param->rc.i_bitrate = new_rate;
+ update_vbv_settings(param);
+ });
+ } else {
+ x264_param_t param;
+ x264_encoder_parameters(x264, ¶m);
+ param.rc.i_bitrate = new_rate;
+ update_vbv_settings(¶m);
+ x264_encoder_reconfig(x264, ¶m);
+ }
+ }
+