X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=x264_encoder.h;h=8adb42ae19102808b2f35d3395aeb3a83e50d9e0;hb=7a074a020aad29723e028acab76b9edfdd6c5223;hp=c71cba2f373e7bc3864a23224a734a17ffeb9ead;hpb=cf7b9ee186d4ef8e5da0531b75854c97b821be44;p=nageru diff --git a/x264_encoder.h b/x264_encoder.h index c71cba2..8adb42a 100644 --- a/x264_encoder.h +++ b/x264_encoder.h @@ -16,20 +16,25 @@ #ifndef _X264ENCODE_H #define _X264ENCODE_H 1 +#include #include #include #include +#include #include #include #include #include #include #include +#include extern "C" { #include } +#include "print_latency.h" + class Mux; class X264SpeedControl; @@ -46,9 +51,14 @@ public: // 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); + void add_frame(int64_t pts, int64_t duration, const uint8_t *data, const ReceivedTimestamps &received_ts); - std::string get_global_headers() const { return global_headers; } + std::string get_global_headers() const { + while (!x264_init_done) { + sched_yield(); + } + return global_headers; + } void change_bitrate(unsigned rate_kbit) { new_bitrate_kbit = rate_kbit; @@ -58,6 +68,7 @@ private: struct QueuedFrame { int64_t pts, duration; uint8_t *data; + ReceivedTimestamps received_ts; }; void encoder_thread_func(); void init_x264(); @@ -75,6 +86,7 @@ private: std::string buffered_sei; // Will be output before first frame, if any. std::thread encoder_thread; + std::atomic x264_init_done{false}; std::atomic should_quit{false}; x264_t *x264; std::unique_ptr speed_control; @@ -94,6 +106,9 @@ private: // Whenever the state of changes. std::condition_variable queued_frames_nonempty; + + // Key is the pts of the frame. + std::unordered_map frames_being_encoded; }; #endif // !defined(_X264ENCODE_H)