|
7 | 7 | #define BIPEDAL_LOCOMOTION_FRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_H |
8 | 8 |
|
9 | 9 | #include <atomic> |
| 10 | +#include <condition_variable> |
| 11 | +#include <deque> |
10 | 12 | #include <memory> |
11 | 13 | #include <mutex> |
12 | 14 | #include <string> |
@@ -145,17 +147,36 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver, |
145 | 147 | std::filesystem::path framesPath; |
146 | 148 | }; |
147 | 149 |
|
| 150 | + struct FrameBundle |
| 151 | + { |
| 152 | + unsigned int frameIndex{0}; |
| 153 | + double timestamp{0.0}; |
| 154 | + cv::Mat rgbFrame; |
| 155 | + cv::Mat depthFrame; |
| 156 | + bool hasRgb{false}; |
| 157 | + bool hasDepth{false}; |
| 158 | + }; |
| 159 | + |
148 | 160 | std::shared_ptr<ImageSaver> rgb; |
149 | 161 | std::shared_ptr<ImageSaver> depth; |
150 | 162 | int depthScale{1}; |
151 | 163 |
|
152 | 164 | std::thread videoThread; |
| 165 | + std::thread flushThread; |
153 | 166 | std::atomic<bool> recordVideoIsRunning{false}; |
154 | 167 | int fps{-1}; |
155 | 168 | std::atomic<unsigned int> frameIndex{0}; |
156 | 169 | std::atomic<bool> resetIndex{false}; |
157 | 170 | std::atomic<bool> paused{false}; |
158 | 171 | std::atomic<bool> requestPause{false}; |
| 172 | + |
| 173 | + std::condition_variable frameQueueCv; |
| 174 | + std::mutex frameQueueMutex; |
| 175 | + std::deque<FrameBundle> frameQueue; |
| 176 | + std::size_t maxBufferedBundles{0}; |
| 177 | + std::atomic<bool> flushThreadShouldRun{false}; |
| 178 | + std::atomic<bool> flushPaused{false}; |
| 179 | + std::atomic<bool> queueOverflowNotified{false}; |
159 | 180 | }; |
160 | 181 |
|
161 | 182 | std::string m_videoCodecCode{"mp4v"}; |
@@ -237,6 +258,7 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver, |
237 | 258 |
|
238 | 259 | bool hasSubstring(const std::string& str, const std::vector<std::string>& substrings) const; |
239 | 260 | void recordVideo(const std::string& cameraName, VideoWriter& writer); |
| 261 | + void flushVideoQueue(const std::string& cameraName, VideoWriter& writer); |
240 | 262 | void saveExogenousImages(const std::string& signalName, |
241 | 263 | VideoWriter& writer, |
242 | 264 | ExogenousSignal<yarp::sig::ImageOf<yarp::sig::PixelRgb>>& signal); |
|
0 commit comments