X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=x264_encoder.h;h=7a155e341bd0e64b0f0153b8a2977058cd001bf3;hp=8adb42ae19102808b2f35d3395aeb3a83e50d9e0;hb=fa54f2630c56a1df0046923d6a77b1bd58abf240;hpb=63a912898083c06cc75f336f8d9a367a707e378a diff --git a/x264_encoder.h b/x264_encoder.h index 8adb42a..7a155e3 100644 --- a/x264_encoder.h +++ b/x264_encoder.h @@ -3,15 +3,11 @@ // so a little under 100 MB at 720p), then have a separate thread pull out // those threads as fast as we can to give it to x264 for encoding. // -// TODO: We use x264's “speedcontrol” patch if available, so that quality is -// automatically scaled up or down to content and available CPU time. -// // The encoding threads are niced down because mixing is more important than // encoding; if we lose frames in mixing, we'll lose frames to disk _and_ // to the stream, as where if we lose frames in encoding, we'll lose frames // to the stream only, so the latter is strictly better. More importantly, -// this allows speedcontrol (when implemented) to do its thing without -// disturbing the mixer. +// this allows speedcontrol to do its thing without disturbing the mixer. #ifndef _X264ENCODE_H #define _X264ENCODE_H 1 @@ -28,12 +24,18 @@ #include #include #include +#include extern "C" { #include } +#include + +#include "defs.h" +#include "metrics.h" #include "print_latency.h" +#include "x264_dynamic.h" class Mux; class X264SpeedControl; @@ -47,11 +49,11 @@ public: ~X264Encoder(); // Must be called before first frame. Does not take ownership. - void set_mux(Mux *mux) { this->mux = mux; } + void add_mux(Mux *mux) { muxes.push_back(mux); } // 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, const ReceivedTimestamps &received_ts); + void add_frame(int64_t pts, int64_t duration, movit::YCbCrLumaCoefficients ycbcr_coefficients, const uint8_t *data, const ReceivedTimestamps &received_ts); std::string get_global_headers() const { while (!x264_init_done) { @@ -67,6 +69,7 @@ public: private: struct QueuedFrame { int64_t pts, duration; + movit::YCbCrLumaCoefficients ycbcr_coefficients; uint8_t *data; ReceivedTimestamps received_ts; }; @@ -79,7 +82,7 @@ private: // pool. std::unique_ptr frame_pool; - Mux *mux = nullptr; + std::vector muxes; bool wants_global_headers; std::string global_headers; @@ -88,9 +91,12 @@ private: std::thread encoder_thread; std::atomic x264_init_done{false}; std::atomic should_quit{false}; + X264Dynamic dyn; x264_t *x264; std::unique_ptr speed_control; + std::function bitrate_override_func; + std::atomic new_bitrate_kbit{0}; // 0 for no change. // Protects everything below it.