]> git.sesse.net Git - nageru/blobdiff - x264encode.h
Make X264Encoder possible to shut down.
[nageru] / x264encode.h
index 83c5e8be88d83729706a102bec8b893e14176e9b..6f0d6a54210725b39d851e778d93291967c39a20 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdint.h>
 
+#include <atomic>
 #include <condition_variable>
 #include <memory>
 #include <mutex>
@@ -33,16 +34,15 @@ class Mux;
 class X264Encoder {
 public:
        X264Encoder(Mux *httpd);  // Does not take ownership.
+
+       // Called after the last frame. Will block; once this returns,
+       // the last data is flushed.
        ~X264Encoder();
 
        // <data> is taken to be raw NV12 data of WIDTHxHEIGHT resolution.
        // Does not block.
        void add_frame(int64_t pts, const uint8_t *data);
 
-       // Called after the last frame. Will block; once this returns,
-       // the last data is flushed.
-       void end_encoding();
-
 private:
        struct QueuedFrame {
                int64_t pts;
@@ -60,6 +60,7 @@ private:
        Mux *mux = nullptr;
 
        std::thread encoder_thread;
+       std::atomic<bool> should_quit{false};
        x264_t *x264;
 
        // Protects everything below it.