]> git.sesse.net Git - nageru/blobdiff - nageru/x264_encoder.cpp
IWYU-fix nageru/*.cpp.
[nageru] / nageru / x264_encoder.cpp
index 6c46c98c689dbdd99e16275e9d3466a883e8dd9e..014d7d17a3126d9c4bafc8d9920ca5258765b099 100644 (file)
@@ -1,16 +1,24 @@
 #include "x264_encoder.h"
 
 #include <assert.h>
+#include <atomic>
+#include <cstdint>
 #include <dlfcn.h>
+#include <functional>
+#include <inttypes.h>
+#include <math.h>
+#include <memory>
+#include <movit/image_format.h>
+#include <mutex>
+#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <string>
+#include <thread>
 #include <unistd.h>
+#include <vector>
 #include <x264.h>
-#include <atomic>
-#include <cstdint>
-#include <functional>
-#include <mutex>
 
 #include "defs.h"
 #include "flags.h"
@@ -22,7 +30,7 @@
 #include "x264_speed_control.h"
 
 extern "C" {
-#include <libavcodec/avcodec.h>
+#include <libavcodec/packet.h>
 #include <libavformat/avformat.h>
 }
 
@@ -60,16 +68,8 @@ 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;
-       }
+       param->rc.i_vbv_buffer_size = param->rc.i_bitrate;  // One-second VBV.
+       param->rc.i_vbv_max_bitrate = param->rc.i_bitrate;  // CBR.
 }
 
 }  // namespace
@@ -212,16 +212,11 @@ void X264Encoder::init_x264()
        } else {
                param.rc.i_rc_method = X264_RC_ABR;
                param.rc.i_bitrate = bitrate;
-       }
-       if (!use_separate_disk_params) {
-               update_vbv_settings(&param);
-       }
-       if (param.rc.i_vbv_max_bitrate > 0) {
-               // If the user wants VBV control to cap the max rate, it is
-               // also reasonable to assume that they are fine with the stream
-               // constantly being around that rate even for very low-complexity
-               // content; the obvious and extreme example being a static
-               // black picture.
+
+               // If the user wants to cap the max rate, it is also reasonable
+               // to assume that they are fine with the stream constantly
+               // being around that rate even for very low-complexity content;
+               // the obvious and extreme example being a static black picture.
                //
                // One would think it's fine to have low-complexity content use
                // less bitrate, but it seems to cause problems in practice;
@@ -243,6 +238,9 @@ void X264Encoder::init_x264()
                // thus ignores the parameter.)
                param.rc.b_filler = 1;
        }
+       if (!use_separate_disk_params) {
+               update_vbv_settings(&param);
+       }
 
        // Occasionally players have problem with extremely low quantizers;
        // be on the safe side. Shouldn't affect quality in any meaningful way.