]> git.sesse.net Git - nageru/blobdiff - x264_encoder.h
Do not use the timing of dropped frames as part of the video master clock.
[nageru] / x264_encoder.h
index e146cd2b2b6a3044a5ab20d3d9195fa05f831e32..bb9f1dc066dd43b0b544b744452a1c93251a56da 100644 (file)
 
 extern "C" {
 #include "x264.h"
+#include <libavformat/avformat.h>
 }
 
 class Mux;
+class X264SpeedControl;
 
 class X264Encoder {
 public:
-       X264Encoder(Mux *httpd);  // Does not take ownership.
+       X264Encoder(AVOutputFormat *oformat);  // Does not take ownership.
 
        // Called after the last frame. Will block; once this returns,
        // the last data is flushed.
        ~X264Encoder();
 
+       // Must be called before first frame. Does not take ownership.
+       void set_mux(Mux *mux) { this->mux = mux; }
+
        // <data> is taken to be raw NV12 data of WIDTHxHEIGHT resolution.
        // Does not block.
        void add_frame(int64_t pts, int64_t duration, const uint8_t *data);
 
+       std::string get_global_headers() const { return global_headers; }
+
+       void change_bitrate(unsigned rate_kbit) {
+               new_bitrate_kbit = rate_kbit;
+       }
+
 private:
        struct QueuedFrame {
                int64_t pts, duration;
@@ -58,10 +69,17 @@ private:
        std::unique_ptr<uint8_t[]> frame_pool;
 
        Mux *mux = nullptr;
+       bool wants_global_headers;
+
+       std::string global_headers;
+       std::string buffered_sei;  // Will be output before first frame, if any.
 
        std::thread encoder_thread;
        std::atomic<bool> should_quit{false};
        x264_t *x264;
+       std::unique_ptr<X264SpeedControl> speed_control;
+
+       std::atomic<unsigned> new_bitrate_kbit{0};  // 0 for no change.
 
        // Protects everything below it.
        std::mutex mu;