Skip to content

Commit 6dc1c73

Browse files
Add video frame queue management and flushing mechanism
1 parent 592d1cd commit 6dc1c73

File tree

2 files changed

+227
-61
lines changed

2 files changed

+227
-61
lines changed

devices/YarpRobotLoggerDevice/include/BipedalLocomotion/YarpRobotLoggerDevice.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#define BIPEDAL_LOCOMOTION_FRAMEWORK_YARP_ROBOT_LOGGER_DEVICE_H
88

99
#include <atomic>
10+
#include <condition_variable>
11+
#include <deque>
1012
#include <memory>
1113
#include <mutex>
1214
#include <string>
@@ -145,17 +147,36 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
145147
std::filesystem::path framesPath;
146148
};
147149

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+
148160
std::shared_ptr<ImageSaver> rgb;
149161
std::shared_ptr<ImageSaver> depth;
150162
int depthScale{1};
151163

152164
std::thread videoThread;
165+
std::thread flushThread;
153166
std::atomic<bool> recordVideoIsRunning{false};
154167
int fps{-1};
155168
std::atomic<unsigned int> frameIndex{0};
156169
std::atomic<bool> resetIndex{false};
157170
std::atomic<bool> paused{false};
158171
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};
159180
};
160181

161182
std::string m_videoCodecCode{"mp4v"};
@@ -237,6 +258,7 @@ class YarpRobotLoggerDevice : public yarp::dev::DeviceDriver,
237258

238259
bool hasSubstring(const std::string& str, const std::vector<std::string>& substrings) const;
239260
void recordVideo(const std::string& cameraName, VideoWriter& writer);
261+
void flushVideoQueue(const std::string& cameraName, VideoWriter& writer);
240262
void saveExogenousImages(const std::string& signalName,
241263
VideoWriter& writer,
242264
ExogenousSignal<yarp::sig::ImageOf<yarp::sig::PixelRgb>>& signal);

0 commit comments

Comments
 (0)