]> git.sesse.net Git - nageru/blobdiff - ffmpeg_capture.h
Make some more sleeps interruptable.
[nageru] / ffmpeg_capture.h
index daf353eec6bdad339dc5e1ddbf87a4d36709726c..24e6b5b40d3f9b780e71facdb7fb0dc347e5723c 100644 (file)
@@ -19,7 +19,6 @@
 //
 // There is currently no audio support. There is also no support for changing
 // the video underway (unlike images), although there really should be.
-// Finally, there is currently no support for controlling the video from Lua.
 
 #include <assert.h>
 #include <stdint.h>
@@ -32,6 +31,7 @@
 #include <thread>
 
 #include "bmusb/bmusb.h"
+#include "quittable_sleeper.h"
 
 class FFmpegCapture : public bmusb::CaptureInterface
 {
@@ -55,6 +55,12 @@ public:
                command_queue.push_back(QueuedCommand { QueuedCommand::REWIND });
        }
 
+       void change_rate(double new_rate)
+       {
+               std::lock_guard<std::mutex> lock(queue_mu);
+               command_queue.push_back(QueuedCommand { QueuedCommand::CHANGE_RATE, new_rate });
+       }
+
        // CaptureInterface.
        void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override
        {
@@ -152,12 +158,13 @@ private:
        std::unique_ptr<bmusb::FrameAllocator> owned_audio_frame_allocator;
        bmusb::frame_callback_t frame_callback = nullptr;
 
-       std::atomic<bool> producer_thread_should_quit{false};
+       QuittableSleeper producer_thread_should_quit;
        std::thread producer_thread;
 
        std::mutex queue_mu;
        struct QueuedCommand {
-               enum Command { REWIND } command;
+               enum Command { REWIND, CHANGE_RATE } command;
+               double new_rate;  // For CHANGE_RATE.
        };
        std::vector<QueuedCommand> command_queue;  // Protected by <queue_mu>.
 };