+ input_pic = &pic;
+
+ frames_being_encoded[qf.pts] = qf.received_ts;
+ }
+
+ unsigned new_rate = new_bitrate_kbit.load(); // Can be 0 for no change.
+ if (speed_control) {
+ speed_control->set_config_override_function(bind(&speed_control_override_func, new_rate, qf.ycbcr_coefficients, _1));
+ } else {
+ x264_param_t param;
+ dyn.x264_encoder_parameters(x264, ¶m);
+ speed_control_override_func(new_rate, qf.ycbcr_coefficients, ¶m);
+ dyn.x264_encoder_reconfig(x264, ¶m);
+ }
+
+ if (speed_control) {
+ float queue_fill_ratio;
+ {
+ lock_guard<mutex> lock(mu);
+ queue_fill_ratio = float(free_frames.size()) / X264_QUEUE_LENGTH;
+ }
+ speed_control->before_frame(queue_fill_ratio, X264_QUEUE_LENGTH, 1e6 * qf.duration / TIMEBASE);
+ }
+ dyn.x264_encoder_encode(x264, &nal, &num_nal, input_pic, &pic);
+ if (speed_control) {
+ speed_control->after_frame();
+ }
+
+ if (num_nal == 0) return;
+
+ if (IS_X264_TYPE_I(pic.i_type)) {
+ ++metric_x264_output_frames_i;
+ } else if (IS_X264_TYPE_B(pic.i_type)) {
+ ++metric_x264_output_frames_b;
+ } else {
+ ++metric_x264_output_frames_p;
+ }
+
+ metric_x264_crf.count_event(pic.prop.f_crf_avg);
+
+ if (frames_being_encoded.count(pic.i_pts)) {
+ ReceivedTimestamps received_ts = frames_being_encoded[pic.i_pts];
+ frames_being_encoded.erase(pic.i_pts);
+
+ static int frameno = 0;
+ print_latency("Current x264 latency (video inputs → network mux):",
+ received_ts, (pic.i_type == X264_TYPE_B || pic.i_type == X264_TYPE_BREF),
+ &frameno, &x264_latency_histogram);