+using namespace std::chrono;
+using namespace std::placeholders;
+
+namespace {
+
+// X264Encoder can be restarted if --record-x264-video is set, so make these
+// metrics global.
+atomic<int64_t> metric_x264_queued_frames{0};
+atomic<int64_t> metric_x264_max_queued_frames{X264_QUEUE_LENGTH};
+atomic<int64_t> metric_x264_dropped_frames{0};
+atomic<int64_t> metric_x264_output_frames_i{0};
+atomic<int64_t> metric_x264_output_frames_p{0};
+atomic<int64_t> metric_x264_output_frames_b{0};
+Histogram metric_x264_crf;
+LatencyHistogram x264_latency_histogram;
+once_flag x264_metrics_inited;
+
+void update_vbv_settings(x264_param_t *param)
+{
+ if (global_flags.x264_bitrate == -1) {
+ return;
+ }
+ if (global_flags.x264_vbv_buffer_size < 0) {
+ param->rc.i_vbv_buffer_size = param->rc.i_bitrate; // One-second VBV.
+ } else {
+ param->rc.i_vbv_buffer_size = global_flags.x264_vbv_buffer_size;
+ }
+ if (global_flags.x264_vbv_max_bitrate < 0) {
+ param->rc.i_vbv_max_bitrate = param->rc.i_bitrate; // CBR.
+ } else {
+ param->rc.i_vbv_max_bitrate = global_flags.x264_vbv_max_bitrate;
+ }
+}
+
+} // namespace