]> git.sesse.net Git - nageru/blobdiff - ffmpeg_capture.h
Add support for changing the playback rate.
[nageru] / ffmpeg_capture.h
index 8c75b4f705c25691bb2a967fc68c11b6d6ebeac0..3787bd7a468408de6a573ed9f91b6d94e260aa9f 100644 (file)
@@ -26,6 +26,7 @@
 #include <functional>
 #include <map>
 #include <memory>
+#include <mutex>
 #include <set>
 #include <string>
 #include <thread>
@@ -48,6 +49,18 @@ public:
                return card_index;
        }
 
+       void rewind()
+       {
+               std::lock_guard<std::mutex> lock(queue_mu);
+               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
        {
@@ -147,6 +160,13 @@ private:
 
        std::atomic<bool> producer_thread_should_quit{false};
        std::thread producer_thread;
+
+       std::mutex queue_mu;
+       struct QueuedCommand {
+               enum Command { REWIND, CHANGE_RATE } command;
+               double new_rate;  // For CHANGE_RATE.
+       };
+       std::vector<QueuedCommand> command_queue;  // Protected by <queue_mu>.
 };
 
 #endif  // !defined(_FFMPEG_CAPTURE_H)